aboutsummaryrefslogtreecommitdiffstats
path: root/include/import.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2017-05-31 09:56:35 +0200
committerMario Vavti <mario@mariovavti.com>2017-05-31 09:56:35 +0200
commit47d55694a4c84b6c12c0db61a69bcac8b671b20e (patch)
treeb15e96f4ea67e2214a66a9d28dafaf53d25b98ec /include/import.php
parent087f9784e3c5a860ed2b86e7f9e8e9f312038546 (diff)
parentf0e615dee529e031663576286345141ad2996974 (diff)
downloadvolse-hubzilla-47d55694a4c84b6c12c0db61a69bcac8b671b20e.tar.gz
volse-hubzilla-47d55694a4c84b6c12c0db61a69bcac8b671b20e.tar.bz2
volse-hubzilla-47d55694a4c84b6c12c0db61a69bcac8b671b20e.zip
Merge branch '2.4RC'2.4
Diffstat (limited to 'include/import.php')
-rw-r--r--include/import.php633
1 files changed, 362 insertions, 271 deletions
diff --git a/include/import.php b/include/import.php
index eab47e2ee..3f4d84765 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1,8 +1,19 @@
<?php
+use Zotlabs\Lib\IConfig;
+
require_once('include/menu.php');
require_once('include/perm_upgrade.php');
+
+/**
+ * @brief Import a channel.
+ *
+ * @param array $channel
+ * @param int $account_id
+ * @param int $seize
+ * @return boolean|array
+ */
function import_channel($channel, $account_id, $seize) {
if(! array_key_exists('channel_system',$channel)) {
@@ -51,7 +62,7 @@ function import_channel($channel, $account_id, $seize) {
notice( t('Unable to create a unique channel address. Import failed.') . EOL);
return false;
}
- }
+ }
}
unset($channel['channel_id']);
@@ -66,12 +77,12 @@ function import_channel($channel, $account_id, $seize) {
// remove all the permissions related settings, we will import/upgrade them after the channel
// is created.
- $disallowed = [
- 'channel_id', 'channel_r_stream', 'channel_r_profile', 'channel_r_abook',
- 'channel_r_storage', 'channel_r_pages', 'channel_w_stream', 'channel_w_wall',
- 'channel_w_comment', 'channel_w_mail', 'channel_w_like', 'channel_w_tagwall',
- 'channel_w_chat', 'channel_w_storage', 'channel_w_pages', 'channel_a_republish',
- 'channel_a_delegate', 'perm_limits'
+ $disallowed = [
+ 'channel_id', 'channel_r_stream', 'channel_r_profile', 'channel_r_abook',
+ 'channel_r_storage', 'channel_r_pages', 'channel_w_stream', 'channel_w_wall',
+ 'channel_w_comment', 'channel_w_mail', 'channel_w_like', 'channel_w_tagwall',
+ 'channel_w_chat', 'channel_w_storage', 'channel_w_pages', 'channel_a_republish',
+ 'channel_a_delegate', 'perm_limits', 'channel_password', 'channel_salt'
];
$clean = array();
@@ -87,7 +98,7 @@ function import_channel($channel, $account_id, $seize) {
$r = q("select * from channel where channel_account_id = %d and channel_guid = '%s' limit 1",
intval($account_id),
- $channel['channel_guid'] // Already dbesc'd
+ dbesc($channel['channel_guid'])
);
if(! $r) {
logger('mod_import: channel not found. ' . print_r($channel,true));
@@ -108,24 +119,37 @@ function import_channel($channel, $account_id, $seize) {
set_default_login_identity($account_id,$channel['channel_id'],false);
logger('import step 1');
$_SESSION['import_step'] = 1;
- return $channel;
+ return $channel;
}
-function import_config($channel,$configs) {
+/**
+ * @brief Import pconfig for channel.
+ *
+ * @param array $channel
+ * @param array $configs
+ */
+function import_config($channel, $configs) {
if($channel && $configs) {
foreach($configs as $config) {
unset($config['id']);
$config['uid'] = $channel['channel_id'];
- create_table_from_array('pconfig',$config);
+
+ create_table_from_array('pconfig', $config);
}
+
load_pconfig($channel['channel_id']);
- }
+ }
}
-
-function import_profiles($channel,$profiles) {
+/**
+ * @brief Import profiles.
+ *
+ * @param array $channel
+ * @param array $profiles
+ */
+function import_profiles($channel, $profiles) {
if($channel && $profiles) {
foreach($profiles as $profile) {
@@ -138,19 +162,29 @@ function import_profiles($channel,$profiles) {
convert_oldfields($profile,'with','partner');
convert_oldfields($profile,'work','employment');
+ /**
+ * @TODO we are going to reset all profile photos to the original
+ * somebody will have to fix this later and put all the applicable
+ * photos into the export.
+ */
- // we are going to reset all profile photos to the original
- // somebody will have to fix this later and put all the applicable photos into the export
-
$profile['photo'] = z_root() . '/photo/profile/l/' . $channel['channel_id'];
$profile['thumb'] = z_root() . '/photo/profile/m/' . $channel['channel_id'];
- create_table_from_array('profile',$profile);
+
+ create_table_from_array('profile', $profile);
}
}
}
-
-function import_hublocs($channel,$hublocs,$seize,$moving = false) {
+/**
+ * @brief Import hublocs.
+ *
+ * @param array $channel
+ * @param array $hublocs
+ * @param unknown $seize
+ * @param boolean $moving (optional) default false
+ */
+function import_hublocs($channel, $hublocs, $seize, $moving = false) {
if($channel && $hublocs) {
foreach($hublocs as $hubloc) {
@@ -162,45 +196,49 @@ function import_hublocs($channel,$hublocs,$seize,$moving = false) {
}
if(! array_key_exists('hubloc_primary',$hubloc)) {
- $hubloc['hubloc_primary'] = (($hubloc['hubloc_flags'] & 0x0001) ? 1 : 0);
- $hubloc['hubloc_orphancheck'] = (($hubloc['hubloc_flags'] & 0x0004) ? 1 : 0);
- $hubloc['hubloc_error'] = (($hubloc['hubloc_status'] & 0x0003) ? 1 : 0);
- $hubloc['hubloc_deleted'] = (($hubloc['hubloc_flags'] & 0x1000) ? 1 : 0);
+ $hubloc['hubloc_primary'] = (($hubloc['hubloc_flags'] & 0x0001) ? 1 : 0);
+ $hubloc['hubloc_orphancheck'] = (($hubloc['hubloc_flags'] & 0x0004) ? 1 : 0);
+ $hubloc['hubloc_error'] = (($hubloc['hubloc_status'] & 0x0003) ? 1 : 0);
+ $hubloc['hubloc_deleted'] = (($hubloc['hubloc_flags'] & 0x1000) ? 1 : 0);
}
if($moving && $hubloc['hubloc_hash'] === $channel['channel_hash'] && $hubloc['hubloc_url'] !== z_root()) {
$hubloc['hubloc_deleted'] = 1;
}
- $arr = array(
- 'guid' => $hubloc['hubloc_guid'],
+ $arr = [
+ 'guid' => $hubloc['hubloc_guid'],
'guid_sig' => $hubloc['hubloc_guid_sig'],
- 'url' => $hubloc['hubloc_url'],
- 'url_sig' => $hubloc['hubloc_url_sig'],
- 'sitekey' => ((array_key_exists('hubloc_sitekey',$hubloc)) ? $hubloc['hubloc_sitekey'] : '')
- );
+ 'url' => $hubloc['hubloc_url'],
+ 'url_sig' => $hubloc['hubloc_url_sig'],
+ 'sitekey' => ((array_key_exists('hubloc_sitekey',$hubloc)) ? $hubloc['hubloc_sitekey'] : '')
+ ];
+
if(($hubloc['hubloc_hash'] === $channel['channel_hash']) && intval($hubloc['hubloc_primary']) && ($seize))
$hubloc['hubloc_primary'] = 0;
- if(($x = zot_gethub($arr,false)) === false) {
+ if(($x = zot_gethub($arr,false)) === false) {
unset($hubloc['hubloc_id']);
- create_table_from_array('hubloc',$hubloc);
+ create_table_from_array('hubloc', $hubloc);
}
else {
q("UPDATE hubloc set hubloc_primary = %d, hubloc_deleted = %d where hubloc_id = %d",
intval($hubloc['hubloc_primary']),
intval($hubloc['hubloc_deleted']),
intval($x['hubloc_id'])
- );
-
+ );
}
}
}
}
-
-
-function import_objs($channel,$objs) {
+/**
+ * @brief Import things.
+ *
+ * @param array $channel
+ * @param array $objs
+ */
+function import_objs($channel, $objs) {
if($channel && $objs) {
foreach($objs as $obj) {
@@ -215,21 +253,27 @@ function import_objs($channel,$objs) {
$obj['obj_channel'] = $channel['channel_id'];
- if($baseurl && (strpos($obj['obj_url'],$baseurl . '/thing/') !== false)) {
- $obj['obj_url'] = str_replace($baseurl,z_root(),$obj['obj_url']);
+ if($baseurl && (strpos($obj['obj_url'], $baseurl . '/thing/') !== false)) {
+ $obj['obj_url'] = str_replace($baseurl, z_root(), $obj['obj_url']);
}
if($obj['obj_imgurl']) {
- $x = import_xchan_photo($obj['obj_imgurl'],$channel['channel_hash'],true);
+ $x = import_xchan_photo($obj['obj_imgurl'], $channel['channel_hash'], true);
$obj['obj_imgurl'] = $x[0];
}
- create_table_from_array('obj',$obj);
+ create_table_from_array('obj', $obj);
}
}
}
-function sync_objs($channel,$objs) {
+/**
+ * @brief Import things.
+ *
+ * @param array $channel
+ * @param array $objs
+ */
+function sync_objs($channel, $objs) {
if($channel && $objs) {
foreach($objs as $obj) {
@@ -252,8 +296,8 @@ function sync_objs($channel,$objs) {
$obj['obj_channel'] = $channel['channel_id'];
- if($baseurl && (strpos($obj['obj_url'],$baseurl . '/thing/') !== false)) {
- $obj['obj_url'] = str_replace($baseurl,z_root(),$obj['obj_url']);
+ if($baseurl && (strpos($obj['obj_url'], $baseurl . '/thing/') !== false)) {
+ $obj['obj_url'] = str_replace($baseurl, z_root(), $obj['obj_url']);
}
$exists = false;
@@ -270,12 +314,12 @@ function sync_objs($channel,$objs) {
}
if($obj['obj_imgurl']) {
- $x = import_xchan_photo($obj['obj_imgurl'],$channel['channel_hash'],true);
+ $x = import_xchan_photo($obj['obj_imgurl'], $channel['channel_hash'], true);
$obj['obj_imgurl'] = $x[0];
}
$hash = $obj['obj_obj'];
-
+
if($exists) {
unset($obj['obj_obj']);
foreach($obj as $k => $v) {
@@ -287,23 +331,25 @@ function sync_objs($channel,$objs) {
);
}
}
- else {
- create_table_from_array('obj',$obj);
+ else {
+ create_table_from_array('obj', $obj);
}
}
}
}
-
-
-
-
-function import_apps($channel,$apps) {
+/**
+ * @brief Import apps.
+ *
+ * @param array $channel
+ * @param array $apps
+ */
+function import_apps($channel, $apps) {
if($channel && $apps) {
foreach($apps as $app) {
- $term = ((array_key_exists('term',$app) && is_array($app['term'])) ? $app['term'] : null);
+ $term = ((array_key_exists('term',$app) && is_array($app['term'])) ? $app['term'] : null);
unset($app['id']);
unset($app['app_channel']);
@@ -312,13 +358,13 @@ function import_apps($channel,$apps) {
$app['app_channel'] = $channel['channel_id'];
if($app['app_photo']) {
- $x = import_xchan_photo($app['app_photo'],$channel['channel_hash'],true);
+ $x = import_xchan_photo($app['app_photo'], $channel['channel_hash'], true);
$app['app_photo'] = $x[0];
}
$hash = $app['app_id'];
- create_table_from_array('app',$app);
+ create_table_from_array('app', $app);
if($term) {
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
@@ -329,20 +375,22 @@ function import_apps($channel,$apps) {
foreach($term as $t) {
if(array_key_exists('type',$t))
$t['ttype'] = $t['type'];
+
store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['ttype'],escape_tags($t['term']),escape_tags($t['url']));
}
}
}
-
-
-
}
}
}
-
-
-function sync_apps($channel,$apps) {
+/**
+ * @brief Sync apps.
+ *
+ * @param array $channel
+ * @param array $apps
+ */
+function sync_apps($channel, $apps) {
if($channel && $apps) {
foreach($apps as $app) {
@@ -357,20 +405,20 @@ function sync_apps($channel,$apps) {
if($x) {
$exists = $x[0];
}
-
+
if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) {
- q("delete from app where app_id = '%s' and app_channel = %d",
- dbesc($app['app_id']),
- intval($channel['channel_id'])
- );
+ q("delete from app where app_id = '%s' and app_channel = %d",
+ dbesc($app['app_id']),
+ intval($channel['channel_id'])
+ );
if($exists) {
q("delete from term where otype = %d and oid = %d",
intval(TERM_OBJ_APP),
intval($exists['id'])
- );
+ );
}
- continue;
- }
+ continue;
+ }
unset($app['id']);
unset($app['app_channel']);
@@ -380,7 +428,7 @@ function sync_apps($channel,$apps) {
q("delete from term where otype = %d and oid = %d",
intval(TERM_OBJ_APP),
intval($exists['id'])
- );
+ );
}
if((! $app['app_created']) || ($app['app_created'] <= NULL_DATE))
@@ -441,9 +489,13 @@ function sync_apps($channel,$apps) {
}
}
-
-
-function import_chatrooms($channel,$chatrooms) {
+/**
+ * @brief Import chatrooms.
+ *
+ * @param array $channel
+ * @param array $chatrooms
+ */
+function import_chatrooms($channel, $chatrooms) {
if($channel && $chatrooms) {
foreach($chatrooms as $chatroom) {
@@ -458,14 +510,18 @@ function import_chatrooms($channel,$chatrooms) {
$chatroom['cr_aid'] = $channel['channel_account_id'];
$chatroom['cr_uid'] = $channel['channel_id'];
- create_table_from_array('chatroom',$chatroom);
+ create_table_from_array('chatroom', $chatroom);
}
}
}
-
-
-function sync_chatrooms($channel,$chatrooms) {
+/**
+ * @brief Sync chatrooms.
+ *
+ * @param array $channel
+ * @param array $chatrooms
+ */
+function sync_chatrooms($channel, $chatrooms) {
if($channel && $chatrooms) {
foreach($chatrooms as $chatroom) {
@@ -474,13 +530,12 @@ function sync_chatrooms($channel,$chatrooms) {
continue;
if(array_key_exists('cr_deleted',$chatroom) && $chatroom['cr_deleted']) {
- q("delete from chatroom where cr_name = '%s' and cr_uid = %d",
- dbesc($chatroom['cr_name']),
- intval($channel['channel_id'])
- );
- continue;
- }
-
+ q("delete from chatroom where cr_name = '%s' and cr_uid = %d",
+ dbesc($chatroom['cr_name']),
+ intval($channel['channel_id'])
+ );
+ continue;
+ }
unset($chatroom['cr_id']);
unset($chatroom['cr_aid']);
@@ -503,6 +558,7 @@ function sync_chatrooms($channel,$chatrooms) {
if($x) {
if($x[0]['cr_edited'] >= $chatroom['cr_edited'])
continue;
+
$exists = true;
}
$name = $chatroom['cr_name'];
@@ -518,29 +574,28 @@ function sync_chatrooms($channel,$chatrooms) {
}
}
else {
- create_table_from_array('chatroom',$chatroom);
+ create_table_from_array('chatroom', $chatroom);
}
}
}
}
-
-function import_items($channel,$items,$sync = false,$relocate = null) {
+/**
+ * @brief Import items to channel.
+ *
+ * @param array $channel where to import to
+ * @param array $items
+ * @param boolean $sync default false
+ * @param array $relocate default null
+ */
+function import_items($channel, $items, $sync = false, $relocate = null) {
if($channel && $items) {
- $allow_code = false;
- $r = 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($channel['channel_id'])
- );
- if($r) {
- if(($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($r[0]['channel_pageflags'] & PAGE_ALLOWCODE)) {
- $allow_code = true;
- }
- }
- $deliver = false; // Don't deliver any messages or notifications when importing
+ $allow_code = channel_codeallowed($channel['channel_id']);
+
+ $deliver = false; // Don't deliver any messages or notifications when importing
foreach($items as $i) {
$item_result = false;
@@ -558,14 +613,14 @@ function import_items($channel,$items,$sync = false,$relocate = null) {
);
if($r) {
- // flags may have changed and we are probably relocating the post,
+ // flags may have changed and we are probably relocating the post,
// so force an update even if we have the same timestamp
if($item['edited'] >= $r[0]['edited']) {
$item['id'] = $r[0]['id'];
$item['uid'] = $channel['channel_id'];
$item_result = item_store_update($item,$allow_code,$deliver);
- }
+ }
}
else {
$item['aid'] = $channel['channel_account_id'];
@@ -587,14 +642,26 @@ function import_items($channel,$items,$sync = false,$relocate = null) {
}
}
-
-function sync_items($channel,$items,$relocate = null) {
- import_items($channel,$items,true,$relocate);
+/**
+ * @brief Sync items to channel.
+ *
+ * @see import_items
+ *
+ * @param array $channel where to import to
+ * @param array $items
+ * @param array $relocate default null
+ */
+function sync_items($channel, $items, $relocate = null) {
+ import_items($channel, $items, true, $relocate);
}
-
-
-function import_item_ids($channel,$itemids) {
+/**
+ * @brief
+ *
+ * @param array $channel A channel array.
+ * @param array $itemids
+ */
+function import_item_ids($channel, $itemids) {
if($channel && $itemids) {
foreach($itemids as $i) {
$r = q("select id from item where mid = '%s' and uid = %d limit 1",
@@ -603,20 +670,26 @@ function import_item_ids($channel,$itemids) {
);
if(! $r)
continue;
- $z = q("select * from iconfig where iconfig.cat = 'system' and iconfig.k = '%s'
+ $z = q("select * from iconfig where iconfig.cat = 'system' and iconfig.k = '%s'
and iconfig.v = '%s' and iid = %d limit 1",
dbesc($i['service']),
dbesc($i['sid']),
intval($r[0]['id'])
);
if(! $z) {
- \Zotlabs\Lib\IConfig::Set($r[0]['id'],'system',$i['service'],$i['sid'],true);
+ IConfig::Set($r[0]['id'],'system',$i['service'],$i['sid'],true);
}
}
}
}
-function import_events($channel,$events) {
+/**
+ * @brief Import events.
+ *
+ * @param array $channel
+ * @param array $events
+ */
+function import_events($channel, $events) {
if($channel && $events) {
foreach($events as $event) {
@@ -628,13 +701,18 @@ function import_events($channel,$events) {
convert_oldfields($event,'type','etype');
convert_oldfields($event,'ignore','dismissed');
- create_table_from_array('event',$event);
+ create_table_from_array('event', $event);
}
}
}
-
-function sync_events($channel,$events) {
+/**
+ * @brief Sync events.
+ *
+ * @param array $channel
+ * @param array $events
+ */
+function sync_events($channel, $events) {
if($channel && $events) {
foreach($events as $event) {
@@ -646,7 +724,7 @@ function sync_events($channel,$events) {
$r = q("delete from event where event_hash = '%s' and uid = %d",
dbesc($event['event_hash']),
intval($channel['channel_id'])
- );
+ );
continue;
}
@@ -659,7 +737,6 @@ function sync_events($channel,$events) {
convert_oldfields($event,'type','etype');
convert_oldfields($event,'ignore','dismissed');
-
$exists = false;
$x = q("select * from event where event_hash = '%s' and uid = %d limit 1",
@@ -669,6 +746,7 @@ function sync_events($channel,$events) {
if($x) {
if($x[0]['edited'] >= $event['edited'])
continue;
+
$exists = true;
}
@@ -683,15 +761,19 @@ function sync_events($channel,$events) {
}
}
else {
- create_table_from_array('event',$event);
+ create_table_from_array('event', $event);
}
}
}
}
-
-function import_menus($channel,$menus) {
-
+/**
+ * @brief Import menus.
+ *
+ * @param array $channel
+ * @param array $menus
+ */
+function import_menus($channel, $menus) {
if($channel && $menus) {
foreach($menus as $menu) {
@@ -710,7 +792,6 @@ function import_menus($channel,$menus) {
$m['menu_flags'] |= MENU_BOOKMARK;
if(in_array('system',$menu['flags']))
$m['menu_flags'] |= MENU_SYSTEM;
-
}
$menu_id = menu_create($m);
@@ -738,16 +819,19 @@ function import_menus($channel,$menus) {
}
menu_add_item($menu_id,$channel['channel_id'],$mitem);
}
- }
+ }
}
}
}
-
-
}
-
-function sync_menus($channel,$menus) {
+/**
+ * @brief Sync menus.
+ *
+ * @param array $channel
+ * @param array $menus
+ */
+function sync_menus($channel, $menus) {
if($channel && $menus) {
foreach($menus as $menu) {
@@ -804,7 +888,6 @@ function sync_menus($channel,$menus) {
foreach($menu['items'] as $it) {
$mitem = array();
-
$mitem['mitem_link'] = str_replace('[channelurl]',z_root() . '/channel/' . $channel['channel_address'],$it['link']);
$mitem['mitem_link'] = str_replace('[pageurl]',z_root() . '/page/' . $channel['channel_address'],$it['link']);
$mitem['mitem_link'] = str_replace('[cloudurl]',z_root() . '/cloud/' . $channel['channel_address'],$it['link']);
@@ -823,15 +906,19 @@ function sync_menus($channel,$menus) {
}
menu_add_item($menu_id,$channel['channel_id'],$mitem);
}
- }
+ }
}
}
}
}
-
-
-function import_likes($channel,$likes) {
+/**
+ * @brief Import likes.
+ *
+ * @param array $channel
+ * @param array $likes
+ */
+function import_likes($channel, $likes) {
if($channel && $likes) {
foreach($likes as $like) {
if($like['deleted']) {
@@ -844,7 +931,7 @@ function import_likes($channel,$likes) {
);
continue;
}
-
+
unset($like['id']);
unset($like['iid']);
$like['channel_id'] = $channel['channel_id'];
@@ -859,9 +946,9 @@ function import_likes($channel,$likes) {
if($r)
continue;
- create_table_from_array('likes',$like);
+ create_table_from_array('likes', $like);
}
- }
+ }
}
function import_conv($channel,$convs) {
@@ -874,7 +961,7 @@ function import_conv($channel,$convs) {
);
continue;
}
-
+
unset($conv['id']);
$conv['uid'] = $channel['channel_id'];
@@ -886,14 +973,20 @@ function import_conv($channel,$convs) {
);
if($r)
continue;
+
create_table_from_array('conv',$conv);
}
- }
+ }
}
-
-
-function import_mail($channel,$mails,$sync = false) {
+/**
+ * @brief Import mails.
+ *
+ * @param array $channel
+ * @param array $mails
+ * @param boolean $sync (optional) default false
+ */
+function import_mail($channel, $mails, $sync = false) {
if($channel && $mails) {
foreach($mails as $mail) {
if(array_key_exists('flags',$mail) && in_array('deleted',$mail['flags'])) {
@@ -922,14 +1015,27 @@ function import_mail($channel,$mails,$sync = false) {
Zotlabs\Daemon\Master::Summon(array('Notifier','single_mail',$mail_id));
}
}
- }
+ }
}
-function sync_mail($channel,$mails) {
- import_mail($channel,$mails,true);
+/**
+ * @brief Synchronise mails.
+ *
+ * @see import_mail
+ * @param array $channel
+ * @param array $mails
+ */
+function sync_mail($channel, $mails) {
+ import_mail($channel, $mails, true);
}
-function sync_files($channel,$files) {
+/**
+ * @brief Synchronise files.
+ *
+ * @param array $channel
+ * @param array $files
+ */
+function sync_files($channel, $files) {
require_once('include/attach.php');
@@ -943,7 +1049,7 @@ function sync_files($channel,$files) {
$original_channel = $f['original_channel'];
if(! ($fetch_url && $original_channel))
- continue;
+ continue;
if($f['attach']) {
$attachment_stored = false;
@@ -973,12 +1079,11 @@ function sync_files($channel,$files) {
$att['aid'] = $channel['channel_account_id'];
$att['uid'] = $channel['channel_id'];
-
- // check for duplicate folder names with the same parent.
+ // check for duplicate folder names with the same parent.
// If we have a duplicate that doesn't match this hash value
- // change the name so that the contents won't be "covered over"
- // by the existing directory. Use the same logic we use for
- // duplicate files.
+ // change the name so that the contents won't be "covered over"
+ // by the existing directory. Use the same logic we use for
+ // duplicate files.
if(strpos($att['filename'],'.') !== false) {
$basename = substr($att['filename'],0,strrpos($att['filename'],'.'));
@@ -1009,7 +1114,7 @@ function sync_files($channel,$files) {
}
if($found)
$x++;
- }
+ }
while($found);
$att['filename'] = $basename . '(' . $x . ')' . $ext;
}
@@ -1018,30 +1123,31 @@ function sync_files($channel,$files) {
// end duplicate detection
-// @fixme - update attachment structures if they are modified rather than created
+ /// @FIXME update attachment structures if they are modified rather than created
$att['content'] = $newfname;
// Note: we use $att['hash'] below after it has been escaped to
- // fetch the file contents.
+ // fetch the file contents.
// If the hash ever contains any escapable chars this could cause
- // problems. Currently it does not.
+ // problems. Currently it does not.
- // @TODO implement os_path
+ /// @TODO implement os_path
if(!isset($att['os_path']))
$att['os_path'] = '';
-
if($attach_exists) {
logger('sync_files attach exists: ' . print_r($att,true), LOGGER_DEBUG);
if(! dbesc_array($att))
continue;
+
$str = '';
- foreach($att as $k => $v) {
- if($str)
- $str .= ",";
- $str .= " " . TQUOT . $k . TQUOT . " = '" . $v . "' ";
- }
+ foreach($att as $k => $v) {
+ if($str)
+ $str .= ",";
+
+ $str .= " " . TQUOT . $k . TQUOT . " = '" . $v . "' ";
+ }
$r = dbq("update attach set " . $str . " where id = " . intval($attach_id) );
}
else {
@@ -1049,7 +1155,6 @@ function sync_files($channel,$files) {
create_table_from_array('attach',$att);
}
-
// is this a directory?
if($att['filetype'] === 'multipart/mixed' && $att['is_dir']) {
@@ -1058,17 +1163,16 @@ function sync_files($channel,$files) {
continue;
}
else {
-
// it's a file
// for the sync version of this algorithm (as opposed to 'offline import')
- // we will fetch the actual file from the source server so it can be
+ // we will fetch the actual file from the source server so it can be
// streamed directly to disk and avoid consuming PHP memory if it's a huge
- // audio/video file or something.
+ // audio/video file or something.
$time = datetime_convert();
- $parr = array('hash' => $channel['channel_hash'],
- 'time' => $time,
+ $parr = array('hash' => $channel['channel_hash'],
+ 'time' => $time,
'resource' => $att['hash'],
'revision' => 0,
'signature' => base64url_encode(rsa_sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey']))
@@ -1093,7 +1197,7 @@ function sync_files($channel,$files) {
}
}
if(! $attachment_stored) {
- // @TODO should we queue this and retry or delete everything or what?
+ /// @TODO should we queue this and retry or delete everything or what?
logger('attachment store failed',LOGGER_NORMAL,LOG_ERR);
}
if($f['photo']) {
@@ -1137,7 +1241,6 @@ function sync_files($channel,$files) {
else
$p['content'] = base64_decode($p['content']);
-
if(!isset($p['display_path']))
$p['display_path'] = '';
@@ -1147,17 +1250,18 @@ function sync_files($channel,$files) {
intval($channel['channel_id'])
);
-
if($exists) {
if(! dbesc_array($p))
continue;
- $str = '';
- foreach($p as $k => $v) {
- if($str)
- $str .= ",";
- $str .= " " . TQUOT . $k . TQUOT . " = '" . $v . "' ";
- }
- $r = dbq("update photo set " . $str . " where id = " . intval($exists[0]['id']) );
+
+ $str = '';
+ foreach($p as $k => $v) {
+ if($str)
+ $str .= ",";
+
+ $str .= " " . TQUOT . $k . TQUOT . " = '" . $v . "' ";
+ }
+ $r = dbq("update photo set " . $str . " where id = " . intval($exists[0]['id']) );
}
else {
create_attach_from_array('photo',$p);
@@ -1173,9 +1277,17 @@ function sync_files($channel,$files) {
}
}
-
-function convert_oldfields(&$arr,$old,$new) {
- if(array_key_exists($old,$arr)) {
+/**
+ * @brief Rename a key in an array.
+ *
+ * Replaces $old key with $new key in $arr.
+ *
+ * @param[in,out] array &$arr The array where to work on
+ * @param string $old The old key in the array
+ * @param string $new The new key in the array
+ */
+function convert_oldfields(&$arr, $old, $new) {
+ if(array_key_exists($old, $arr)) {
$arr[$new] = $arr[$old];
unset($arr[$old]);
}
@@ -1249,14 +1361,15 @@ function scan_webpage_elements($path, $type, $cloud = false) {
}
}
}
+
return $elements;
}
-
+
function import_webpage_element($element, $channel, $type) {
-
+
$arr = array(); // construct information for the webpage element item table record
-
+
switch($type) {
//
// PAGES
@@ -1265,26 +1378,26 @@ function import_webpage_element($element, $channel, $type) {
$arr['item_type'] = ITEM_TYPE_WEBPAGE;
$namespace = 'WEBPAGE';
$name = $element['pagelink'];
- if($name) {
+ 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'",
+ // 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",
+ $linfo = q("select mid from item where id = %d",
intval($liid[0]['iid'])
- );
- $arr['layout_mid'] = $linfo[0]['mid'];
- }
- }
+ );
+ $arr['layout_mid'] = $linfo[0]['mid'];
+ }
+ }
break;
//
// LAYOUTS
@@ -1304,15 +1417,15 @@ function import_webpage_element($element, $channel, $type) {
$namespace = 'BUILDBLOCK';
$name = $element['name'];
$arr['title'] = $element['title'];
-
+
break;
default :
return null; // return null if invalid element type
}
-
+
$arr['uid'] = local_channel();
$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)
@@ -1337,12 +1450,13 @@ function import_webpage_element($element, $channel, $type) {
// 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',
+ $mimetypes = [
+ 'text/bbcode',
'text/html',
'text/markdown',
'text/plain',
'application/x-pdl',
- 'application/x-php'
+ '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') ) {
@@ -1353,37 +1467,16 @@ function import_webpage_element($element, $channel, $type) {
}
// 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;
- }
- }
-
-// $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']),
+ $execflag = channel_codeallowed(local_channel());
+
+ $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1",
+ dbesc($arr['mid']),
intval(local_channel())
);
-
- \Zotlabs\Lib\IConfig::Set($arr,'system',$namespace,(($name) ? $name : substr($arr['mid'],0,16)),true);
-
-
+
+ IConfig::Set($arr,'system',$namespace,(($name) ? $name : substr($arr['mid'],0,16)),true);
+
if($i) {
$arr['id'] = $i[0]['id'];
// don't update if it has the same timestamp as the original
@@ -1401,23 +1494,23 @@ function import_webpage_element($element, $channel, $type) {
else
$x = item_store($arr,$execflag);
}
-
+
if($x && $x['success']) {
- $item_id = $x['item_id'];
+ //$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;
+ if(!$channel['channel_id']) {
+ return null;
}
switch($type) {
case 'all':
@@ -1425,17 +1518,16 @@ function get_webpage_elements($channel, $type = 'all') {
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
+ $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;
if($r) {
@@ -1468,7 +1560,6 @@ function get_webpage_elements($channel, $type = 'all') {
);
$elements['pages'][] = $element_arr;
}
-
}
if($type !== 'all') {
break;
@@ -1477,91 +1568,91 @@ function get_webpage_elements($channel, $type = 'all') {
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
+ $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;
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'],
+ '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;
}
-
+
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
+ $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'
+ 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;
if($r) {
$elements['blocks'] = array();
- $blocks = array();
+
foreach($r as $rr) {
unobscure($rr);
$elements['blocks'][] = array(
'type' => 'block',
- 'title' => $rr['title'],
+ 'title' => $rr['title'],
'body' => $rr['body'],
'created' => $rr['created'],
'edited' => $rr['edited'],
'mimetype' => $rr['mimetype'],
- 'name' => $rr['v'],
+ 'name' => $rr['v'],
'mid' => $rr['mid']
);
}
-
}
-
+
if($type !== 'all') {
break;
}
-
+
default:
break;
}
+
return $elements;
}
-/* creates a compressed zip file */
-
+/**
+ * @brief Create a compressed zip file.
+ *
+ * @param array $files List of files to put in zip file
+ * @param string $destination
+ * @param boolean $overwrite
+ * @return boolean Success status
+ */
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) {
@@ -1578,13 +1669,13 @@ function create_zip_file($files = array(), $destination = '', $overwrite = false
$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) {
+ if($zip->open($destination, $overwrite ? ZipArchive::OVERWRITE : ZipArchive::CREATE) !== true) {
return false;
}
// add the files
@@ -1598,7 +1689,7 @@ function create_zip_file($files = array(), $destination = '', $overwrite = false
// check to make sure the file exists
return file_exists($destination);
- }
+ }
else {
return false;
}