aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2017-02-01 17:08:46 -0500
committerAndrew Manning <tamanning@zoho.com>2017-02-01 17:08:46 -0500
commit61407ad6c833b67398736e04742f8e6ca0c17a2a (patch)
treec0290a76fea464e1e1bcf5aea1e3a99d82518420
parentd3d540a28b2dd0b4958d129cceeba162c271302b (diff)
parentec037abf92be6ac6495cabcd5d64821655f39e37 (diff)
downloadvolse-hubzilla-61407ad6c833b67398736e04742f8e6ca0c17a2a.tar.gz
volse-hubzilla-61407ad6c833b67398736e04742f8e6ca0c17a2a.tar.bz2
volse-hubzilla-61407ad6c833b67398736e04742f8e6ca0c17a2a.zip
Merge branch 'dev' of https://github.com/redmatrix/hubzilla into dev
-rw-r--r--Zotlabs/Module/Import.php81
-rw-r--r--Zotlabs/Module/Uexport.php17
-rw-r--r--Zotlabs/Render/Comanche.php11
-rw-r--r--doc/hook/get_default_export_sections10
-rw-r--r--doc/hook/identity_basic_export.bb9
-rw-r--r--doc/hooklist.bb3
-rw-r--r--doc/tags_and_mentions.bb4
-rw-r--r--include/Import/import_diaspora.php148
-rw-r--r--include/api_zot.php9
-rw-r--r--include/channel.php390
-rw-r--r--include/import.php707
-rw-r--r--include/text.php1
12 files changed, 682 insertions, 708 deletions
diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php
index 52835c685..ea8fbf4a2 100644
--- a/Zotlabs/Module/Import.php
+++ b/Zotlabs/Module/Import.php
@@ -112,12 +112,12 @@ class Import extends \Zotlabs\Web\Controller {
// print_r($data);
- if(array_key_exists('user',$data) && array_key_exists('version',$data)) {
- require_once('include/Import/import_diaspora.php');
- import_diaspora($data);
- return;
+ if(! array_key_exists('compatibility',$data)) {
+ call_hooks('import_foreign_channel_data',$data);
+ if($data['handled'])
+ return;
}
-
+
$moving = intval($_REQUEST['moving']);
if(array_key_exists('compatibility',$data) && array_key_exists('database',$data['compatibility'])) {
@@ -181,14 +181,15 @@ class Import extends \Zotlabs\Web\Controller {
if($completed < 3) {
- if($data['photo']) {
- require_once('include/photo/photo_driver.php');
- import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],$account_id,$channel['channel_id']);
- }
-
- if(is_array($data['profile']))
- import_profiles($channel,$data['profile']);
+ if(array_key_exists('channel',$data)) {
+ if($data['photo']) {
+ require_once('include/photo/photo_driver.php');
+ import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],$account_id,$channel['channel_id']);
+ }
+ if(is_array($data['profile']))
+ import_profiles($channel,$data['profile']);
+ }
logger('import step 3');
$_SESSION['import_step'] = 3;
}
@@ -207,31 +208,34 @@ class Import extends \Zotlabs\Web\Controller {
if($completed < 5) {
// create new hubloc for the new channel at this site
- $r = hubloc_store_lowlevel(
- [
- 'hubloc_guid' => $channel['channel_guid'],
- 'hubloc_guid_sig' => $channel['channel_guid_sig'],
- 'hubloc_hash' => $channel['channel_hash'],
- 'hubloc_addr' => channel_reddress($channel),
- 'hubloc_network' => 'zot',
- 'hubloc_primary' => (($seize) ? 1 : 0),
- 'hubloc_url' => z_root(),
- 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey'])),
- 'hubloc_host' => \App::get_hostname(),
- 'hubloc_callback' => z_root() . '/post',
- 'hubloc_sitekey' => get_config('system','pubkey'),
- 'hubloc_updated' => datetime_convert()
- ]
- );
+ if(array_key_exists('channel',$data)) {
+ $r = hubloc_store_lowlevel(
+ [
+ 'hubloc_guid' => $channel['channel_guid'],
+ 'hubloc_guid_sig' => $channel['channel_guid_sig'],
+ 'hubloc_hash' => $channel['channel_hash'],
+ 'hubloc_addr' => channel_reddress($channel),
+ 'hubloc_network' => 'zot',
+ 'hubloc_primary' => (($seize) ? 1 : 0),
+ 'hubloc_url' => z_root(),
+ 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey'])),
+ 'hubloc_host' => \App::get_hostname(),
+ 'hubloc_callback' => z_root() . '/post',
+ 'hubloc_sitekey' => get_config('system','pubkey'),
+ 'hubloc_updated' => datetime_convert()
+ ]
+ );
- // reset the original primary hubloc if it is being seized
+ // reset the original primary hubloc if it is being seized
- if($seize) {
- $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_url != '%s' ",
- dbesc($channel['channel_hash']),
- dbesc(z_root())
- );
+ if($seize) {
+ $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_url != '%s' ",
+ dbesc($channel['channel_hash']),
+ dbesc(z_root())
+ );
+ }
}
+
logger('import step 5');
$_SESSION['import_step'] = 5;
}
@@ -241,7 +245,7 @@ class Import extends \Zotlabs\Web\Controller {
// import xchans and contact photos
- if($seize) {
+ if(array_key_exists('channel',$data) && $seize) {
// replace any existing xchan we may have on this site if we're seizing control
@@ -327,9 +331,7 @@ class Import extends \Zotlabs\Web\Controller {
$_SESSION['import_step'] = 7;
}
-
-
-
+
// FIXME - ensure we have an xchan if somebody is trying to pull a fast one
if($completed < 8) {
@@ -478,6 +480,9 @@ class Import extends \Zotlabs\Web\Controller {
if(is_array($data['wiki']))
import_items($channel,$data['wiki'],false,$relocate);
+
+ if(is_array($data['webpages']))
+ import_items($channel,$data['webpages'],false,$relocate);
$addon = array('channel' => $channel,'data' => $data);
call_hooks('import_channel',$addon);
diff --git a/Zotlabs/Module/Uexport.php b/Zotlabs/Module/Uexport.php
index f36d77174..28c840ceb 100644
--- a/Zotlabs/Module/Uexport.php
+++ b/Zotlabs/Module/Uexport.php
@@ -9,10 +9,11 @@ class Uexport extends \Zotlabs\Web\Controller {
killme();
if(argc() > 1) {
+
+ $sections = (($_REQUEST['sections']) ? explode(',',$_REQUEST['sections']) : '');
+
$channel = \App::get_channel();
-
- require_once('include/channel.php');
-
+
if(argc() > 1 && intval(argv(1)) > 1900) {
$year = intval(argv(1));
}
@@ -30,15 +31,16 @@ class Uexport extends \Zotlabs\Web\Controller {
}
if(argc() > 1 && argv(1) === 'basic') {
- echo json_encode(identity_basic_export(local_channel()));
+ echo json_encode(identity_basic_export(local_channel(),$sections));
killme();
}
- // FIXME - this basically doesn't work in the wild with a channel more than a few months old due to memory and execution time limits.
- // It probably needs to be built at the CLI and offered to download as a tarball. Maybe stored in the members dav.
+ // Warning: this option may consume a lot of memory
if(argc() > 1 && argv(1) === 'complete') {
- echo json_encode(identity_basic_export(local_channel(),true));
+ $sections = get_default_export_sections();
+ $sections[] = 'items';
+ echo json_encode(identity_basic_export(local_channel(),$sections));
killme();
}
}
@@ -57,6 +59,7 @@ class Uexport extends \Zotlabs\Web\Controller {
'$basic' => t('Export your basic channel information to a file. This acts as a backup of your connections, permissions, profile and basic data, which can be used to import your data to a new server hub, but does not contain your content.'),
'$fulltitle' => t('Export Content'),
'$full' => t('Export your channel information and recent content to a JSON backup that can be restored or imported to another server hub. This backs up all of your connections, permissions, profile data and several months of posts. This file may be VERY large. Please be patient - it may take several minutes for this download to begin.'),
+
'$by_year' => t('Export your posts from a given year.'),
'$extra' => t('You may also export your posts and conversations for a particular year or month. Adjust the date in your browser location bar to select other dates. If the export fails (possibly due to memory exhaustion on your server hub), please try again selecting a more limited date range.'),
diff --git a/Zotlabs/Render/Comanche.php b/Zotlabs/Render/Comanche.php
index 048921670..5826063fd 100644
--- a/Zotlabs/Render/Comanche.php
+++ b/Zotlabs/Render/Comanche.php
@@ -99,6 +99,17 @@ class Comanche {
}
}
+ /**
+ * Currently supported condition variables:
+ *
+ * $config.xxx.yyy - get_config with cat = xxx and k = yyy
+ * $request - request uri for this page
+ * $observer.language - viewer's preferred language (closest match)
+ * $observer.address - xchan_addr or false
+ * $observer.name - xchan_name or false
+ * $observer - xchan_hash of observer or empty string
+ */
+
function get_condition_var($v) {
if($v) {
$x = explode('.',$v);
diff --git a/doc/hook/get_default_export_sections b/doc/hook/get_default_export_sections
new file mode 100644
index 000000000..09b146643
--- /dev/null
+++ b/doc/hook/get_default_export_sections
@@ -0,0 +1,10 @@
+[h3]get_default_export_sections[/h3]
+
+The get_default_export_sections call returns the basic functional groups of data to export using channel_export_basic().
+
+The hook is passed an array
+ [
+ 'sections' => [ 'channel', 'connections', 'config', 'apps', 'chatrooms', 'events', 'webpages', 'mail', 'wikis' ]
+ ]
+
+If you desire the export to contain three months of items, add 'items' to the 'sections' array
diff --git a/doc/hook/identity_basic_export.bb b/doc/hook/identity_basic_export.bb
index 3f4e88799..71329ba1e 100644
--- a/doc/hook/identity_basic_export.bb
+++ b/doc/hook/identity_basic_export.bb
@@ -1 +1,10 @@
[h2]identity_basic_export[/h2]
+
+Called when exporting data for a channel
+Passed array contains
+
+ [
+ 'channel_id' => channel_id being exported
+ 'sections' => array of functional export sections which are being exported
+ 'data' => the export data array which has been generated
+ ]
diff --git a/doc/hooklist.bb b/doc/hooklist.bb
index c965b7c44..59d370117 100644
--- a/doc/hooklist.bb
+++ b/doc/hooklist.bb
@@ -242,6 +242,9 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the
[zrl=[baseurl]/help/hook/get_best_language]get_best_language[/zrl]
called when choosing the preferred language for the page
+[zrl=[baseurl]/help/hook/get_default_export_sections]get_default_export_sections[/zrl]
+ Called to get the default list of functional data groups to export in identity_basic_export()
+
[zrl=[baseurl]/help/hook/get_features]get_features[/zrl]
Called when get_features() is called
diff --git a/doc/tags_and_mentions.bb b/doc/tags_and_mentions.bb
index 29dfe0fbe..c4f240631 100644
--- a/doc/tags_and_mentions.bb
+++ b/doc/tags_and_mentions.bb
@@ -49,6 +49,10 @@ Topical tags are indicated by preceding the tag name with the # character. This
Topical tags are also not linked if they are purely numeric, e.g. #1. If you wish to use a numeric hashtag, please add some descriptive text such as #[zrl=https://friendicared.net/search?tag=2012-elections]2012-elections[/zrl].
+[b]Bookmarks[/b]
+
+Bookmarks indicate a link which can be saved to your bookmark folder. They use the sequence #^ followed by the link. Often these are generatd automatically. If the 'bookmarker' addon is installed, this sequence will be converted to a bookmark icon when viewing the post or comment online and clicking the icon will save the bookmark. If the bookmarker addon is not installed, the post 'dropdown menu' contains a link for saving the bookmark or bookmarks.
+
[b]Spaces in Tags and Mentions[/b]
diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php
deleted file mode 100644
index c6dae0117..000000000
--- a/include/Import/import_diaspora.php
+++ /dev/null
@@ -1,148 +0,0 @@
-<?php
-
-require_once('include/bb2diaspora.php');
-require_once('include/group.php');
-require_once('include/follow.php');
-require_once('include/photo/photo_driver.php');
-
-function import_diaspora($data) {
-
- $account = App::get_account();
- if(! $account)
- return false;
-
- $address = escape_tags($data['user']['username']);
- if(! $address) {
- notice( t('No username found in import file.') . EOL);
- return false;
- }
-
- $r = q("select * from channel where channel_address = '%s' limit 1",
- dbesc($address)
- );
- if($r) {
- // try at most ten times to generate a unique address.
- $x = 0;
- $found_unique = false;
- do {
- $tmp = $address . mt_rand(1000,9999);
- $r = q("select * from channel where channel_address = '%s' limit 1",
- dbesc($tmp)
- );
- if(! $r) {
- $address = $tmp;
- $found_unique = true;
- break;
- }
- $x ++;
- } while ($x < 10);
- if(! $found_unique) {
- logger('import_diaspora: duplicate channel address. randomisation failed.');
- notice( t('Unable to create a unique channel address. Import failed.') . EOL);
- return;
- }
- }
-
-
- $c = create_identity(array(
- 'name' => escape_tags($data['user']['name']),
- 'nickname' => $address,
- 'account_id' => $account['account_id'],
- 'permissions_role' => 'social'
- ));
-
- if(! $c['success'])
- return;
-
- $channel_id = $c['channel']['channel_id'];
-
- // Hubzilla only: Turn on the Diaspora protocol so that follow requests will be sent.
-
- set_pconfig($channel_id,'system','diaspora_allowed','1');
-
- // todo - add auto follow settings, (and strip exif in hubzilla)
-
- $location = escape_tags($data['user']['profile']['location']);
- if(! $location)
- $location = '';
-
-
- q("update channel set channel_location = '%s' where channel_id = %d",
- dbesc($location),
- intval($channel_id)
- );
-
- if($data['user']['profile']['nsfw']) {
- q("update channel set channel_pageflags = (channel_pageflags | %d) where channel_id = %d",
- intval(PAGE_ADULT),
- intval($channel_id)
- );
- }
-
- if($data['user']['profile']['image_url']) {
- $p = z_fetch_url($data['user']['profile']['image_url'],true);
- if($p['success']) {
- $rawbytes = $p['body'];
- $type = guess_image_type('dummyfile',$p['header']);
- import_channel_photo($rawbytes,$type,$c['channel']['channel_account_id'],$channel_id);
- }
- }
-
- $gender = escape_tags($data['user']['profile']['gender']);
- $about = markdown_to_bb($data['user']['profile']['bio']);
- $publish = intval($data['user']['profile']['searchable']);
- if($data['user']['profile']['birthday'])
- $dob = datetime_convert('UTC','UTC',$data['user']['profile']['birthday'],'Y-m-d');
- else
- $dob = '0000-00-00';
-
- // we're relying on the fact that this channel was just created and will only
- // have the default profile currently
-
- $r = q("update profile set gender = '%s', about = '%s', dob = '%s', publish = %d where uid = %d",
- dbesc($gender),
- dbesc($about),
- dbesc($dob),
- dbesc($publish),
- intval($channel_id)
- );
-
- if($data['user']['aspects']) {
- foreach($data['user']['aspects'] as $aspect) {
- group_add($channel_id,escape_tags($aspect['name']),intval($aspect['contacts_visible']));
- }
- }
-
- // now add connections and send friend requests
-
-
- if($data['user']['contacts']) {
- foreach($data['user']['contacts'] as $contact) {
- $result = new_contact($channel_id, $contact['person_diaspora_handle'], $c['channel']);
- if($result['success']) {
- if($contact['aspects']) {
- foreach($contact['aspects'] as $aspect) {
- group_add_member($channel_id,$aspect['name'],$result['abook']['xchan_hash']);
- }
- }
- }
- }
- }
-
-
- // Then add items - note this can't be done until Diaspora adds guids to exported
- // items and comments
-
-
-
- // This will indirectly perform a refresh_all *and* update the directory
-
- proc_run('php', 'include/directory.php', $channel_id);
-
- notice( t('Import completed.') . EOL);
-
- change_channel($channel_id);
-
- goaway(z_root() . '/network' );
-
-} \ No newline at end of file
diff --git a/include/api_zot.php b/include/api_zot.php
index 0b10555a6..aaa9ee497 100644
--- a/include/api_zot.php
+++ b/include/api_zot.php
@@ -69,8 +69,13 @@
logger('api_export_basic: no user');
return false;
}
-
- json_return_and_die(identity_basic_export(api_user(),(($_REQUEST['posts']) ? intval($_REQUEST['posts']) : 0 )));
+ $sections = (($_REQUEST['sections']) ? explode(',',$_REQUEST['sections']) : '');
+ if($_REQUEST['posts']) {
+ $sections = get_default_export_sections();
+ $sections[] = 'items';
+ }
+
+ json_return_and_die(identity_basic_export(api_user(),$sections));
}
diff --git a/include/channel.php b/include/channel.php
index 10c38a5ac..bc36a5707 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -476,6 +476,16 @@ function set_default_login_identity($account_id, $channel_id, $force = true) {
}
}
+
+function get_default_export_sections() {
+ $sections = [ 'channel', 'connections', 'config', 'apps', 'chatrooms', 'events', 'webpages', 'mail', 'wikis' ];
+
+ $cb = [ 'sections' => $sections ];
+ call_hooks('get_default_export_sections', $cb);
+ return $cb['sections'];
+}
+
+
/**
* @brief Create an array representing the important channel information
* which would be necessary to create a nomadic identity clone. This includes
@@ -489,225 +499,279 @@ function set_default_login_identity($account_id, $channel_id, $force = true) {
* @returns array
* See function for details
*/
-function identity_basic_export($channel_id, $items = false) {
+function identity_basic_export($channel_id, $sections = null) {
/*
- * Red basic channel export
+ * basic channel export
*/
- $ret = array();
+ if(! $sections) {
+ $sections = get_default_export_sections();
+ }
+
+ $ret = [];
// use constants here as otherwise we will have no idea if we can import from a site
// with a non-standard platform and version.
- $ret['compatibility'] = array('project' => PLATFORM_NAME, 'version' => STD_VERSION, 'database' => DB_UPDATE_VERSION, 'server_role' => Zotlabs\Lib\System::get_server_role());
+
+ $ret['compatibility'] = [
+ 'project' => PLATFORM_NAME,
+ 'version' => STD_VERSION,
+ 'database' => DB_UPDATE_VERSION,
+ 'server_role' => Zotlabs\Lib\System::get_server_role()
+ ];
+
+ /*
+ * Process channel information regardless of it is one of the sections desired
+ * because we need the channel relocation information in all export files/streams.
+ */
$r = q("select * from channel where channel_id = %d limit 1",
intval($channel_id)
);
if($r) {
translate_channel_perms_outbound($r[0]);
- $ret['channel'] = $r[0];
$ret['relocate'] = [ 'channel_address' => $r[0]['channel_address'], 'url' => z_root()];
- }
-
- $r = q("select * from profile where uid = %d",
- intval($channel_id)
- );
- if($r)
- $ret['profile'] = $r;
-
- $xchans = array();
- $r = q("select * from abook where abook_channel = %d ",
- intval($channel_id)
- );
- if($r) {
- $ret['abook'] = $r;
-
- for($x = 0; $x < count($ret['abook']); $x ++) {
- $xchans[] = $ret['abook'][$x]['abook_xchan'];
- $abconfig = load_abconfig($channel_id,$ret['abook'][$x]['abook_xchan']);
- if($abconfig)
- $ret['abook'][$x]['abconfig'] = $abconfig;
- translate_abook_perms_outbound($ret['abook'][$x]);
+ if(in_array('channel',$sections)) {
+ $ret['channel'] = $r[0];
}
- stringify_array_elms($xchans);
}
- if($xchans) {
- $r = q("select * from xchan where xchan_hash in ( " . implode(',',$xchans) . " ) ");
+ if(in_array('channel',$sections)) {
+ $r = q("select * from profile where uid = %d",
+ intval($channel_id)
+ );
if($r)
- $ret['xchan'] = $r;
+ $ret['profile'] = $r;
- $r = q("select * from hubloc where hubloc_hash in ( " . implode(',',$xchans) . " ) ");
- if($r)
- $ret['hubloc'] = $r;
- }
- $r = q("select * from groups where uid = %d ",
- intval($channel_id)
- );
+ $r = q("select mimetype, content, os_storage from photo
+ where imgscale = 4 and photo_usage = %d and uid = %d limit 1",
+ intval(PHOTO_PROFILE),
+ intval($channel_id)
+ );
- if($r)
- $ret['group'] = $r;
+ if($r) {
+ $ret['photo'] = [
+ 'type' => $r[0]['mimetype'],
+ 'data' => (($r[0]['os_storage'])
+ ? base64url_encode(file_get_contents($r[0]['content'])) : base64url_encode($r[0]['content']))
+ ];
+ }
+ }
- $r = q("select * from group_member where uid = %d ",
- intval($channel_id)
- );
- if($r)
- $ret['group_member'] = $r;
+ if(in_array('connections',$sections)) {
+ $xchans = array();
+ $r = q("select * from abook where abook_channel = %d ",
+ intval($channel_id)
+ );
+ if($r) {
+ $ret['abook'] = $r;
+
+ for($x = 0; $x < count($ret['abook']); $x ++) {
+ $xchans[] = $ret['abook'][$x]['abook_xchan'];
+ $abconfig = load_abconfig($channel_id,$ret['abook'][$x]['abook_xchan']);
+ if($abconfig)
+ $ret['abook'][$x]['abconfig'] = $abconfig;
+ translate_abook_perms_outbound($ret['abook'][$x]);
+ }
+ stringify_array_elms($xchans);
+ }
- $r = q("select * from pconfig where uid = %d",
- intval($channel_id)
- );
- if($r)
- $ret['config'] = $r;
+ if($xchans) {
+ $r = q("select * from xchan where xchan_hash in ( " . implode(',',$xchans) . " ) ");
+ if($r)
+ $ret['xchan'] = $r;
- $r = q("select mimetype, content, os_storage from photo where imgscale = 4 and photo_usage = %d and uid = %d limit 1",
- intval(PHOTO_PROFILE),
- intval($channel_id)
- );
+ $r = q("select * from hubloc where hubloc_hash in ( " . implode(',',$xchans) . " ) ");
+ if($r)
+ $ret['hubloc'] = $r;
+ }
- if($r) {
- $ret['photo'] = array('type' => $r[0]['mimetype'], 'data' => (($r[0]['os_storage']) ? base64url_encode(file_get_contents($r[0]['content'])) : base64url_encode($r[0]['content'])));
- }
+ $r = q("select * from groups where uid = %d ",
+ intval($channel_id)
+ );
- // All other term types will be included in items, if requested.
+ if($r)
+ $ret['group'] = $r;
- $r = q("select * from term where ttype in (%d,%d) and uid = %d",
- intval(TERM_SAVEDSEARCH),
- intval(TERM_THING),
- intval($channel_id)
- );
- if($r)
- $ret['term'] = $r;
+ $r = q("select * from group_member where uid = %d ",
+ intval($channel_id)
+ );
+ if($r)
+ $ret['group_member'] = $r;
- // add psuedo-column obj_baseurl to aid in relocations
+ }
- $r = q("select obj.*, '%s' as obj_baseurl from obj where obj_channel = %d",
- dbesc(z_root()),
- intval($channel_id)
- );
+ if(in_array('config',$sections)) {
+ $r = q("select * from pconfig where uid = %d",
+ intval($channel_id)
+ );
+ if($r)
+ $ret['config'] = $r;
+
+ // All other term types will be included in items, if requested.
+
+ $r = q("select * from term where ttype in (%d,%d) and uid = %d",
+ intval(TERM_SAVEDSEARCH),
+ intval(TERM_THING),
+ intval($channel_id)
+ );
+ if($r)
+ $ret['term'] = $r;
- if($r)
- $ret['obj'] = $r;
+ // add psuedo-column obj_baseurl to aid in relocations
- $r = q("select * from app where app_channel = %d and app_system = 0",
- intval($channel_id)
- );
- if($r) {
- for($x = 0; $x < count($r); $x ++) {
- $r[$x]['term'] = q("select * from term where otype = %d and oid = %d",
- intval(TERM_OBJ_APP),
- intval($r[$x]['id'])
- );
- }
- $ret['app'] = $r;
- }
+ $r = q("select obj.*, '%s' as obj_baseurl from obj where obj_channel = %d",
+ dbesc(z_root()),
+ intval($channel_id)
+ );
- $r = q("select * from chatroom where cr_uid = %d",
- intval($channel_id)
- );
- if($r)
- $ret['chatroom'] = $r;
+ if($r)
+ $ret['obj'] = $r;
- $r = q("select * from event where uid = %d",
- intval($channel_id)
- );
- if($r)
- $ret['event'] = $r;
+ $r = q("select * from likes where channel_id = %d",
+ intval($channel_id)
+ );
+
+ if($r)
+ $ret['likes'] = $r;
- $r = q("select * from item where resource_type = 'event' and uid = %d",
- intval($channel_id)
- );
- if($r) {
- $ret['event_item'] = array();
- xchan_query($r);
- $r = fetch_post_tags($r,true);
- foreach($r as $rr)
- $ret['event_item'][] = encode_item($rr,true);
}
- $x = menu_list($channel_id);
- if($x) {
- $ret['menu'] = array();
- for($y = 0; $y < count($x); $y ++) {
- $m = menu_fetch($x[$y]['menu_name'],$channel_id,$ret['channel']['channel_hash']);
- if($m)
- $ret['menu'][] = menu_element($ret['channel'],$m);
+ if(in_array('apps',$sections)) {
+ $r = q("select * from app where app_channel = %d and app_system = 0",
+ intval($channel_id)
+ );
+ if($r) {
+ for($x = 0; $x < count($r); $x ++) {
+ $r[$x]['term'] = q("select * from term where otype = %d and oid = %d",
+ intval(TERM_OBJ_APP),
+ intval($r[$x]['id'])
+ );
+ }
+ $ret['app'] = $r;
}
}
- $addon = array('channel_id' => $channel_id,'data' => $ret);
- call_hooks('identity_basic_export',$addon);
- $ret = $addon['data'];
+ if(in_array('chatrooms',$sections)) {
+ $r = q("select * from chatroom where cr_uid = %d",
+ intval($channel_id)
+ );
+ if($r)
+ $ret['chatroom'] = $r;
+ }
- if(! $items)
- return $ret;
- $r = q("select * from likes where channel_id = %d",
- intval($channel_id)
- );
+ if(in_array('events',$sections)) {
+ $r = q("select * from event where uid = %d",
+ intval($channel_id)
+ );
+ if($r)
+ $ret['event'] = $r;
- if($r)
- $ret['likes'] = $r;
+ $r = q("select * from item where resource_type = 'event' and uid = %d",
+ intval($channel_id)
+ );
+ if($r) {
+ $ret['event_item'] = array();
+ xchan_query($r);
+ $r = fetch_post_tags($r,true);
+ foreach($r as $rr)
+ $ret['event_item'][] = encode_item($rr,true);
+ }
+ }
+ if(in_array('webpages',$sections)) {
+ $x = menu_list($channel_id);
+ if($x) {
+ $ret['menu'] = array();
+ for($y = 0; $y < count($x); $y ++) {
+ $m = menu_fetch($x[$y]['menu_name'],$channel_id,$ret['channel']['channel_hash']);
+ if($m)
+ $ret['menu'][] = menu_element($ret['channel'],$m);
+ }
+ }
+ $r = q("select * from item where item_type in ( "
+ . ITEM_TYPE_BLOCK . "," . ITEM_TYPE_PDL . "," . ITEM_TYPE_WEBPAGE . " ) and uid = %d",
+ intval($channel_id)
+ );
+ if($r) {
+ $ret['webpages'] = array();
+ xchan_query($r);
+ $r = fetch_post_tags($r,true);
+ foreach($r as $rr)
+ $ret['webpages'][] = encode_item($rr,true);
- $r = q("select * from conv where uid = %d",
- intval($channel_id)
- );
- if($r) {
- for($x = 0; $x < count($r); $x ++) {
- $r[$x]['subject'] = base64url_decode(str_rot47($r[$x]['subject']));
}
- $ret['conv'] = $r;
}
- $r = q("select * from mail where mail.uid = %d",
- intval($channel_id)
- );
- if($r) {
- $m = array();
- foreach($r as $rr) {
- xchan_mail_query($rr);
- $m[] = mail_encode($rr,true);
+ if(in_array('mail',$sections)) {
+ $r = q("select * from conv where uid = %d",
+ intval($channel_id)
+ );
+ if($r) {
+ for($x = 0; $x < count($r); $x ++) {
+ $r[$x]['subject'] = base64url_decode(str_rot47($r[$x]['subject']));
+ }
+ $ret['conv'] = $r;
}
- $ret['mail'] = $m;
- }
- $r = q("select * from item where resource_type like 'nwiki%%' and uid = %d order by created",
- intval($channel_id)
- );
- if($r) {
- $ret['wiki'] = array();
- xchan_query($r);
- $r = fetch_post_tags($r,true);
- foreach($r as $rv) {
- $ret['wiki'][] = encode_item($rv,true);
+ $r = q("select * from mail where mail.uid = %d",
+ intval($channel_id)
+ );
+ if($r) {
+ $m = array();
+ foreach($r as $rr) {
+ xchan_mail_query($rr);
+ $m[] = mail_encode($rr,true);
+ }
+ $ret['mail'] = $m;
}
}
- /** @warning this may run into memory limits on smaller systems */
+ if(in_array('wikis',$sections)) {
+ $r = q("select * from item where resource_type like 'nwiki%%' and uid = %d order by created",
+ intval($channel_id)
+ );
+ if($r) {
+ $ret['wiki'] = array();
+ xchan_query($r);
+ $r = fetch_post_tags($r,true);
+ foreach($r as $rv) {
+ $ret['wiki'][] = encode_item($rv,true);
+ }
+ }
+ }
+ if(in_array('items',$sections)) {
+ /** @warning this may run into memory limits on smaller systems */
- /** export three months of posts. If you want to export and import all posts you have to start with
- * the first year and export/import them in ascending order.
- *
- * Don't export linked resource items. we'll have to pull those out separately.
- */
+ /** export three months of posts. If you want to export and import all posts you have to start with
+ * the first year and export/import them in ascending order.
+ *
+ * Don't export linked resource items. we'll have to pull those out separately.
+ */
- $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d and created > %s - INTERVAL %s and resource_type = '' order by created",
- intval($channel_id),
- db_utcnow(),
- db_quoteinterval('3 MONTH')
- );
- if($r) {
- $ret['item'] = array();
- xchan_query($r);
- $r = fetch_post_tags($r,true);
- foreach($r as $rr)
- $ret['item'][] = encode_item($rr,true);
+ $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d
+ and created > %s - INTERVAL %s and resource_type = '' order by created",
+ intval($channel_id),
+ db_utcnow(),
+ db_quoteinterval('3 MONTH')
+ );
+ if($r) {
+ $ret['item'] = array();
+ xchan_query($r);
+ $r = fetch_post_tags($r,true);
+ foreach($r as $rr)
+ $ret['item'][] = encode_item($rr,true);
+ }
}
+ $addon = [ 'channel_id' => $channel_id, 'sections' => $sections, 'data' => $ret];
+ call_hooks('identity_basic_export',$addon);
+ $ret = $addon['data'];
+
return $ret;
}
@@ -782,7 +846,7 @@ function channel_export_items($channel_id, $start, $finish) {
$ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()];
}
- $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created < '%s' and resource_type = '' order by created",
+ $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created <= '%s' and resource_type = '' order by created",
intval(ITEM_TYPE_POST),
intval($channel_id),
dbesc($start),
diff --git a/include/import.php b/include/import.php
index d19d056b3..d48995a79 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1187,413 +1187,420 @@ function convert_oldfields(&$arr,$old,$new) {
}
function scan_webpage_elements($path, $type, $cloud = false) {
- $channel = \App::get_channel();
- $dirtoscan = $path;
- switch ($type) {
- case 'page':
- $dirtoscan .= '/pages/';
- $json_filename = 'page.json';
- break;
- case 'layout':
- $dirtoscan .= '/layouts/';
- $json_filename = 'layout.json';
- break;
- case 'block':
- $dirtoscan .= '/blocks/';
- $json_filename = 'block.json';
- break;
- default :
- return array();
- }
- if($cloud) {
- $dirtoscan = get_dirpath_by_cloudpath($channel, $dirtoscan);
- }
- $elements = [];
- if (is_dir($dirtoscan)) {
- $dirlist = scandir($dirtoscan);
- if ($dirlist) {
- foreach ($dirlist as $element) {
- if ($element === '.' || $element === '..') {
- continue;
+ $channel = \App::get_channel();
+ $dirtoscan = $path;
+ switch ($type) {
+ case 'page':
+ $dirtoscan .= '/pages/';
+ $json_filename = 'page.json';
+ break;
+ case 'layout':
+ $dirtoscan .= '/layouts/';
+ $json_filename = 'layout.json';
+ break;
+ case 'block':
+ $dirtoscan .= '/blocks/';
+ $json_filename = 'block.json';
+ break;
+ default :
+ return array();
+ }
+ if($cloud) {
+ $dirtoscan = get_dirpath_by_cloudpath($channel, $dirtoscan);
+ }
+ $elements = [];
+ if(is_dir($dirtoscan)) {
+ $dirlist = scandir($dirtoscan);
+ if($dirlist) {
+ foreach($dirlist as $element) {
+ if($element === '.' || $element === '..') {
+ continue;
+ }
+ $folder = $dirtoscan . '/' . $element;
+ if(is_dir($folder)) {
+ if($cloud) {
+ $jsonfilepath = $folder . '/' . get_filename_by_cloudname($json_filename, $channel, $folder);
}
- $folder = $dirtoscan . '/' . $element;
- if (is_dir($folder)) {
+ else {
+ $jsonfilepath = $folder . '/' . $json_filename;
+ }
+ if(is_file($jsonfilepath)) {
+ $metadata = json_decode(file_get_contents($jsonfilepath), true);
if($cloud) {
- $jsonfilepath = $folder . '/' . get_filename_by_cloudname($json_filename, $channel, $folder);
- } else {
- $jsonfilepath = $folder . '/' . $json_filename;
+ $contentfilename = get_filename_by_cloudname($metadata['contentfile'], $channel, $folder);
+ $metadata['path'] = $folder . '/' . $contentfilename;
+ }
+ else {
+ $contentfilename = $metadata['contentfile'];
+ $metadata['path'] = $folder . '/' . $contentfilename;
+ }
+ if($metadata['contentfile'] === '') {
+ logger('Invalid ' . $type . ' content file');
+ return false;
}
- if (is_file($jsonfilepath)) {
- $metadata = json_decode(file_get_contents($jsonfilepath), true);
- if($cloud) {
- $contentfilename = get_filename_by_cloudname($metadata['contentfile'], $channel, $folder);
- $metadata['path'] = $folder . '/' . $contentfilename;
- } else {
- $contentfilename = $metadata['contentfile'];
- $metadata['path'] = $folder . '/' . $contentfilename;
+ $content = file_get_contents($folder . '/' . $contentfilename);
+ if(!$content) {
+ if(is_readable($folder . '/' . $contentfilename)) {
+ $content = '';
}
- if ($metadata['contentfile'] === '') {
- logger('Invalid ' . $type . ' content file');
+ else {
+ logger('Failed to get file content for ' . $metadata['contentfile']);
return false;
}
- $content = file_get_contents($folder . '/' . $contentfilename);
- if (!$content) {
- if(is_readable($folder . '/' . $contentfilename)) {
- $content = '';
- } else {
- logger('Failed to get file content for ' . $metadata['contentfile']);
- return false;
- }
- }
- $elements[] = $metadata;
}
+ $elements[] = $metadata;
}
}
}
}
- return $elements;
}
+ return $elements;
+}
- function import_webpage_element($element, $channel, $type) {
+function import_webpage_element($element, $channel, $type) {
- $arr = array(); // construct information for the webpage element item table record
+ $arr = array(); // construct information for the webpage element item table record
- switch ($type) {
- //
- // PAGES
- //
- case 'page':
- $arr['item_type'] = ITEM_TYPE_WEBPAGE;
- $namespace = 'WEBPAGE';
- $name = $element['pagelink'];
- if($name) {
- require_once('library/urlify/URLify.php');
- $name = strtolower(\URLify::transliterate($name));
- }
- $arr['title'] = $element['title'];
- $arr['term'] = $element['term'];
- $arr['layout_mid'] = ''; // by default there is no layout associated with the page
- // If a layout was specified, find it in the database and get its info. If
- // it does not exist, leave layout_mid empty
- if($element['layout'] !== '') {
- $liid = q("select iid from iconfig where k = 'PDL' and v = '%s' and cat = 'system'",
- dbesc($element['layout'])
- );
- if($liid) {
- $linfo = q("select mid from item where id = %d",
- intval($liid[0]['iid'])
- );
- $arr['layout_mid'] = $linfo[0]['mid'];
- }
- }
- break;
- //
- // LAYOUTS
- //
- case 'layout':
- $arr['item_type'] = ITEM_TYPE_PDL;
- $namespace = 'PDL';
- $name = $element['name'];
- $arr['title'] = $element['description'];
- $arr['term'] = $element['term'];
- break;
- //
- // BLOCKS
- //
- case 'block':
- $arr['item_type'] = ITEM_TYPE_BLOCK;
- $namespace = 'BUILDBLOCK';
- $name = $element['name'];
- $arr['title'] = $element['title'];
+ switch($type) {
+ //
+ // PAGES
+ //
+ case 'page':
+ $arr['item_type'] = ITEM_TYPE_WEBPAGE;
+ $namespace = 'WEBPAGE';
+ $name = $element['pagelink'];
+ if($name) {
+ require_once('library/urlify/URLify.php');
+ $name = strtolower(\URLify::transliterate($name));
+ }
+ $arr['title'] = $element['title'];
+ $arr['term'] = $element['term'];
+ $arr['layout_mid'] = ''; // by default there is no layout associated with the page
+ // If a layout was specified, find it in the database and get its info. If
+ // it does not exist, leave layout_mid empty
+ if($element['layout'] !== '') {
+ $liid = q("select iid from iconfig where k = 'PDL' and v = '%s' and cat = 'system'",
+ dbesc($element['layout'])
+ );
+ if($liid) {
+ $linfo = q("select mid from item where id = %d",
+ intval($liid[0]['iid'])
+ );
+ $arr['layout_mid'] = $linfo[0]['mid'];
+ }
+ }
+ break;
+ //
+ // LAYOUTS
+ //
+ case 'layout':
+ $arr['item_type'] = ITEM_TYPE_PDL;
+ $namespace = 'PDL';
+ $name = $element['name'];
+ $arr['title'] = $element['description'];
+ $arr['term'] = $element['term'];
+ break;
+ //
+ // BLOCKS
+ //
+ case 'block':
+ $arr['item_type'] = ITEM_TYPE_BLOCK;
+ $namespace = 'BUILDBLOCK';
+ $name = $element['name'];
+ $arr['title'] = $element['title'];
- break;
- default :
- return null; // return null if invalid element type
- }
+ break;
+ default :
+ return null; // return null if invalid element type
+ }
- $arr['uid'] = $channel['channel_id'];
- $arr['aid'] = $channel['channel_account_id'];
+ $arr['uid'] = $channel['channel_id'];
+ $arr['aid'] = $channel['channel_account_id'];
- // Check if an item already exists based on the name
- $iid = q("select iid from iconfig where k = '" . $namespace . "' and v = '%s' and cat = 'system'",
- dbesc($name)
+ // Check if an item already exists based on the name
+ $iid = q("select iid from iconfig where k = '" . $namespace . "' and v = '%s' and cat = 'system'",
+ dbesc($name)
+ );
+ if($iid) { // If the item does exist, get the item metadata
+ $iteminfo = q("select mid,created,edited from item where id = %d",
+ intval($iid[0]['iid'])
);
- if($iid) { // If the item does exist, get the item metadata
- $iteminfo = q("select mid,created,edited from item where id = %d",
- intval($iid[0]['iid'])
- );
- $arr['mid'] = $arr['parent_mid'] = $iteminfo[0]['mid'];
- $arr['created'] = $iteminfo[0]['created'];
- } else { // otherwise, generate the creation times and unique id
- $arr['created'] = datetime_convert('UTC', 'UTC');
- $arr['mid'] = $arr['parent_mid'] = item_message_id();
- }
- // Update the edited time whether or not the element already exists
- $arr['edited'] = datetime_convert('UTC', 'UTC');
- // Import the actual element content
- $arr['body'] = file_get_contents($element['path']);
- // The element owner is the channel importing the elements
- $arr['owner_xchan'] = get_observer_hash();
- // The author is either the owner or whomever was specified
- $arr['author_xchan'] = (($element['author_xchan']) ? $element['author_xchan'] : get_observer_hash());
- // Import mimetype if it is a valid mimetype for the element
- $mimetypes = [ 'text/bbcode',
- 'text/html',
- 'text/markdown',
- 'text/plain',
- 'application/x-pdl',
- 'application/x-php'
- ];
- // Blocks and pages can have any of the valid mimetypes, but layouts must be text/bbcode
- if((in_array($element['mimetype'], $mimetypes)) && ($type === 'page' || $type === 'block') ) {
- $arr['mimetype'] = $element['mimetype'];
- } else {
- $arr['mimetype'] = 'text/bbcode';
- }
+ $arr['mid'] = $arr['parent_mid'] = $iteminfo[0]['mid'];
+ $arr['created'] = $iteminfo[0]['created'];
+ }
+ else { // otherwise, generate the creation times and unique id
+ $arr['created'] = datetime_convert('UTC', 'UTC');
+ $arr['mid'] = $arr['parent_mid'] = item_message_id();
+ }
+ // Update the edited time whether or not the element already exists
+ $arr['edited'] = datetime_convert('UTC', 'UTC');
+ // Import the actual element content
+ $arr['body'] = file_get_contents($element['path']);
+ // The element owner is the channel importing the elements
+ $arr['owner_xchan'] = get_observer_hash();
+ // The author is either the owner or whomever was specified
+ $arr['author_xchan'] = (($element['author_xchan']) ? $element['author_xchan'] : get_observer_hash());
+ // Import mimetype if it is a valid mimetype for the element
+ $mimetypes = [ 'text/bbcode',
+ 'text/html',
+ 'text/markdown',
+ 'text/plain',
+ 'application/x-pdl',
+ 'application/x-php'
+ ];
+ // Blocks and pages can have any of the valid mimetypes, but layouts must be text/bbcode
+ if((in_array($element['mimetype'], $mimetypes)) && ($type === 'page' || $type === 'block') ) {
+ $arr['mimetype'] = $element['mimetype'];
+ }
+ else {
+ $arr['mimetype'] = 'text/bbcode';
+ }
- // Verify ability to use html or php!!!
- $execflag = false;
- if ($arr['mimetype'] === 'application/x-php' || $arr['mimetype'] === 'text/html') {
- $z = q("select account_id, account_roles, channel_pageflags from account "
- . "left join channel on channel_account_id = account_id where channel_id = %d limit 1",
- intval(local_channel())
- );
+ // Verify ability to use html or php!!!
+ $execflag = false;
+ if($arr['mimetype'] === 'application/x-php' || $arr['mimetype'] === 'text/html') {
+ $z = q("select account_id, account_roles, channel_pageflags from account "
+ . "left join channel on channel_account_id = account_id where channel_id = %d limit 1",
+ intval(local_channel())
+ );
- if ($z && (($z[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($z[0]['channel_pageflags'] & PAGE_ALLOWCODE))) {
- $execflag = true;
- } else {
- logger('Unable to import element "' . $name .'" because AllowCode permission is denied.');
- notice( t('Unable to import element "' . $name .'" because AllowCode permission is denied.') . EOL);
- $element['import_success'] = 0;
- return $element;
- }
+ if($z && (($z[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($z[0]['channel_pageflags'] & PAGE_ALLOWCODE))) {
+ $execflag = true;
+ }
+ else {
+ logger('Unable to import element "' . $name .'" because AllowCode permission is denied.');
+ notice( t('Unable to import element "' . $name .'" because AllowCode permission is denied.') . EOL);
+ $element['import_success'] = 0;
+ return $element;
}
+ }
- $z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1",
- dbesc($name),
- dbesc($namespace)
- );
+ $z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1",
+ dbesc($name),
+ dbesc($namespace)
+ );
- $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1",
- dbesc($arr['mid']),
- intval(local_channel())
- );
- $remote_id = 0;
- if ($z && $i) {
- $remote_id = $z[0]['id'];
- $arr['id'] = $i[0]['id'];
- // don't update if it has the same timestamp as the original
- if ($arr['edited'] > $i[0]['edited'])
- $x = item_store_update($arr, $execflag);
- } else {
- if (($i) && (intval($i[0]['item_deleted']))) {
- // was partially deleted already, finish it off
- q("delete from item where mid = '%s' and uid = %d",
- dbesc($arr['mid']),
- intval(local_channel())
- );
- }
- $x = item_store($arr, $execflag);
- }
- if ($x['success']) {
- $item_id = $x['item_id'];
- update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']);
- $element['import_success'] = 1;
- } else {
- $element['import_success'] = 0;
+ $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1",
+ dbesc($arr['mid']),
+ intval(local_channel())
+ );
+ $remote_id = 0;
+ if($z && $i) {
+ $remote_id = $z[0]['id'];
+ $arr['id'] = $i[0]['id'];
+ // don't update if it has the same timestamp as the original
+ if($arr['edited'] > $i[0]['edited'])
+ $x = item_store_update($arr, $execflag);
+ }
+ else {
+ if(($i) && (intval($i[0]['item_deleted']))) {
+ // was partially deleted already, finish it off
+ q("delete from item where mid = '%s' and uid = %d",
+ dbesc($arr['mid']),
+ intval(local_channel())
+ );
}
+ $x = item_store($arr, $execflag);
+ }
+ if($x['success']) {
+ $item_id = $x['item_id'];
+ update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']);
+ $element['import_success'] = 1;
+ }
+ else {
+ $element['import_success'] = 0;
+ }
- return $element;
-
+ return $element;
}
function get_webpage_elements($channel, $type = 'all') {
- $elements = array();
- if(!$channel['channel_id']) {
- return null;
- }
- switch ($type) {
- case 'all':
- // If all, execute all the pages, layouts, blocks case statements
- case 'pages':
- $elements['pages'] = null;
- $owner = $channel['channel_id'];
+ $elements = array();
+ if(!$channel['channel_id']) {
+ return null;
+ }
+ switch($type) {
+ case 'all':
+ // If all, execute all the pages, layouts, blocks case statements
+ case 'pages':
+ $elements['pages'] = null;
+ $owner = $channel['channel_id'];
- $sql_extra = item_permissions_sql($owner);
+ $sql_extra = item_permissions_sql($owner);
- $r = q("select * from iconfig left join item on iconfig.iid = item.id
- where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item_type = %d
- $sql_extra order by item.created desc",
- intval($owner),
- intval(ITEM_TYPE_WEBPAGE)
- );
+ $r = q("select * from iconfig left join item on iconfig.iid = item.id
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item_type = %d
+ $sql_extra order by item.created desc",
+ intval($owner),
+ intval(ITEM_TYPE_WEBPAGE)
+ );
- $pages = null;
+ $pages = null;
- if($r) {
- $elements['pages'] = array();
- $pages = array();
- foreach($r as $rr) {
- unobscure($rr);
-
- //$lockstate = (($rr['allow_cid'] || $rr['allow_gid'] || $rr['deny_cid'] || $rr['deny_gid']) ? 'lock' : 'unlock');
-
- $element_arr = array(
- 'type' => 'webpage',
- 'title' => $rr['title'],
- 'body' => $rr['body'],
- 'created' => $rr['created'],
- 'edited' => $rr['edited'],
- 'mimetype' => $rr['mimetype'],
- 'pagetitle' => $rr['v'],
- 'mid' => $rr['mid'],
- 'layout_mid' => $rr['layout_mid']
- );
- $pages[$rr['iid']][] = array(
- 'url' => $rr['iid'],
- 'pagetitle' => $rr['v'],
- 'title' => $rr['title'],
- 'created' => datetime_convert('UTC',date_default_timezone_get(),$rr['created']),
- 'edited' => datetime_convert('UTC',date_default_timezone_get(),$rr['edited']),
- 'bb_element' => '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]',
- //'lockstate' => $lockstate
- );
- $elements['pages'][] = $element_arr;
- }
+ if($r) {
+ $elements['pages'] = array();
+ $pages = array();
+ foreach($r as $rr) {
+ unobscure($rr);
+
+ //$lockstate = (($rr['allow_cid'] || $rr['allow_gid'] || $rr['deny_cid'] || $rr['deny_gid']) ? 'lock' : 'unlock');
+
+ $element_arr = array(
+ 'type' => 'webpage',
+ 'title' => $rr['title'],
+ 'body' => $rr['body'],
+ 'created' => $rr['created'],
+ 'edited' => $rr['edited'],
+ 'mimetype' => $rr['mimetype'],
+ 'pagetitle' => $rr['v'],
+ 'mid' => $rr['mid'],
+ 'layout_mid' => $rr['layout_mid']
+ );
+ $pages[$rr['iid']][] = array(
+ 'url' => $rr['iid'],
+ 'pagetitle' => $rr['v'],
+ 'title' => $rr['title'],
+ 'created' => datetime_convert('UTC',date_default_timezone_get(),$rr['created']),
+ 'edited' => datetime_convert('UTC',date_default_timezone_get(),$rr['edited']),
+ 'bb_element' => '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]',
+ //'lockstate' => $lockstate
+ );
+ $elements['pages'][] = $element_arr;
+ }
- }
- if($type !== 'all') {
- break;
- }
+ }
+ if($type !== 'all') {
+ break;
+ }
- case 'layouts':
- $elements['layouts'] = null;
- $owner = $channel['channel_id'];
+ case 'layouts':
+ $elements['layouts'] = null;
+ $owner = $channel['channel_id'];
- $sql_extra = item_permissions_sql($owner);
+ $sql_extra = item_permissions_sql($owner);
- $r = q("select * from iconfig left join item on iconfig.iid = item.id
- where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' and item_type = %d
- $sql_extra order by item.created desc",
- intval($owner),
- intval(ITEM_TYPE_PDL)
- );
+ $r = q("select * from iconfig left join item on iconfig.iid = item.id
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' and item_type = %d
+ $sql_extra order by item.created desc",
+ intval($owner),
+ intval(ITEM_TYPE_PDL)
+ );
- $layouts = null;
+ $layouts = null;
- if($r) {
- $elements['layouts'] = array();
- $layouts = array();
- foreach($r as $rr) {
- unobscure($rr);
-
- $elements['layouts'][] = array(
- 'type' => 'layout',
- 'description' => $rr['title'], // description of the layout
- 'body' => $rr['body'],
- 'created' => $rr['created'],
- 'edited' => $rr['edited'],
- 'mimetype' => $rr['mimetype'],
- 'name' => $rr['v'], // name of reference for the layout
- 'mid' => $rr['mid'],
- );
- }
-
- }
+ if($r) {
+ $elements['layouts'] = array();
+ $layouts = array();
+ foreach($r as $rr) {
+ unobscure($rr);
+
+ $elements['layouts'][] = array(
+ 'type' => 'layout',
+ 'description' => $rr['title'], // description of the layout
+ 'body' => $rr['body'],
+ 'created' => $rr['created'],
+ 'edited' => $rr['edited'],
+ 'mimetype' => $rr['mimetype'],
+ 'name' => $rr['v'], // name of reference for the layout
+ 'mid' => $rr['mid'],
+ );
+ }
+ }
- if($type !== 'all') {
- break;
- }
+ if($type !== 'all') {
+ break;
+ }
- case 'blocks':
- $elements['blocks'] = null;
- $owner = $channel['channel_id'];
+ case 'blocks':
+ $elements['blocks'] = null;
+ $owner = $channel['channel_id'];
- $sql_extra = item_permissions_sql($owner);
+ $sql_extra = item_permissions_sql($owner);
- $r = q("select iconfig.iid, iconfig.k, iconfig.v, mid, title, body, mimetype, created, edited from iconfig
- left join item on iconfig.iid = item.id
- where uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK'
- and item_type = %d order by item.created desc",
- intval($owner),
- intval(ITEM_TYPE_BLOCK)
- );
+ $r = q("select iconfig.iid, iconfig.k, iconfig.v, mid, title, body, mimetype, created, edited from iconfig
+ left join item on iconfig.iid = item.id
+ where uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK'
+ and item_type = %d order by item.created desc",
+ intval($owner),
+ intval(ITEM_TYPE_BLOCK)
+ );
- $blocks = null;
+ $blocks = null;
- if($r) {
- $elements['blocks'] = array();
- $blocks = array();
- foreach($r as $rr) {
- unobscure($rr);
-
- $elements['blocks'][] = array(
- 'type' => 'block',
- 'title' => $rr['title'],
- 'body' => $rr['body'],
- 'created' => $rr['created'],
- 'edited' => $rr['edited'],
- 'mimetype' => $rr['mimetype'],
- 'name' => $rr['v'],
- 'mid' => $rr['mid']
- );
- }
+ if($r) {
+ $elements['blocks'] = array();
+ $blocks = array();
+ foreach($r as $rr) {
+ unobscure($rr);
+
+ $elements['blocks'][] = array(
+ 'type' => 'block',
+ 'title' => $rr['title'],
+ 'body' => $rr['body'],
+ 'created' => $rr['created'],
+ 'edited' => $rr['edited'],
+ 'mimetype' => $rr['mimetype'],
+ 'name' => $rr['v'],
+ 'mid' => $rr['mid']
+ );
+ }
- }
+ }
- if($type !== 'all') {
- break;
- }
+ if($type !== 'all') {
+ break;
+ }
- default:
- break;
- }
- return $elements;
+ default:
+ break;
+ }
+ return $elements;
}
/* creates a compressed zip file */
function create_zip_file($files = array(), $destination = '', $overwrite = false) {
- //if the zip file already exists and overwrite is false, return false
- if (file_exists($destination) && !$overwrite) {
- return false;
+ // if the zip file already exists and overwrite is false, return false
+ if(file_exists($destination) && !$overwrite) {
+ return false;
+ }
+ //vars
+ $valid_files = array();
+ // if files were passed in...
+ if(is_array($files)) {
+ // cycle through each file
+ foreach($files as $file) {
+ // make sure the file exists
+ if(file_exists($file)) {
+ $valid_files[] = $file;
+ }
}
- //vars
- $valid_files = array();
- //if files were passed in...
- if (is_array($files)) {
- //cycle through each file
- foreach ($files as $file) {
- //make sure the file exists
- if (file_exists($file)) {
- $valid_files[] = $file;
- }
- }
- }
-
- //if we have good files...
- if (count($valid_files)) {
- //create the archive
- $zip = new ZipArchive();
- if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
- return false;
- }
- //add the files
- foreach ($valid_files as $file) {
- $zip->addFile($file, $file);
- }
- //debug
- //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
- //close the zip -- done!
- $zip->close();
-
- //check to make sure the file exists
- return file_exists($destination);
- } else {
- return false;
+ }
+
+ // if we have good files...
+ if(count($valid_files)) {
+ //create the archive
+ $zip = new ZipArchive();
+ if($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
+ return false;
}
+ // add the files
+ foreach($valid_files as $file) {
+ $zip->addFile($file, $file);
+ }
+ //debug
+ //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
+ //close the zip -- done!
+ $zip->close();
+
+ // check to make sure the file exists
+ return file_exists($destination);
+ }
+ else {
+ return false;
+ }
}
diff --git a/include/text.php b/include/text.php
index 4f0dc869b..8c01ed1d2 100644
--- a/include/text.php
+++ b/include/text.php
@@ -3130,6 +3130,7 @@ function gen_link_id($mid) {
return $mid;
}
+
// callback for array_walk
function array_trim(&$v,$k) {