From 7e3046b85cec84ffdd8f482ec2e519b165fe3d54 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 16 Feb 2021 23:33:39 -0800 Subject: more work on zap channel export. --- Zotlabs/Module/Uexport.php | 7 ++--- boot.php | 1 + include/api_zot.php | 6 +++-- include/channel.php | 65 ++++++++++++++++++++++------------------------ include/items.php | 2 +- 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/Zotlabs/Module/Uexport.php b/Zotlabs/Module/Uexport.php index 3d1587b87..55c316317 100644 --- a/Zotlabs/Module/Uexport.php +++ b/Zotlabs/Module/Uexport.php @@ -17,6 +17,7 @@ class Uexport extends Controller { if(argc() > 1) { $sections = (($_REQUEST['sections']) ? explode(',',$_REQUEST['sections']) : ''); + $zap_compat = (($_REQUEST['zap_compat']) ? intval($_REQUEST['zap_compat']) : false); $channel = App::get_channel(); @@ -32,12 +33,12 @@ class Uexport extends Controller { header('content-disposition: attachment; filename="' . $channel['channel_address'] . (($year) ? '-' . $year : '') . (($month) ? '-' . $month : '') . (($_REQUEST['sections']) ? '-' . $_REQUEST['sections'] : '') . '.json"' ); if($year) { - echo json_encode(identity_export_year(local_channel(),$year,$month)); + echo json_encode(identity_export_year(local_channel(),$year,$month, $zap_compat)); killme(); } if(argc() > 1 && argv(1) === 'basic') { - echo json_encode(identity_basic_export(local_channel(),$sections)); + echo json_encode(identity_basic_export(local_channel(),$sections, $zap_compat)); killme(); } @@ -46,7 +47,7 @@ class Uexport extends Controller { if(argc() > 1 && argv(1) === 'complete') { $sections = get_default_export_sections(); $sections[] = 'items'; - echo json_encode(identity_basic_export(local_channel(),$sections)); + echo json_encode(identity_basic_export(local_channel(),$sections, $zap_compat)); killme(); } } diff --git a/boot.php b/boot.php index 1d8872257..1e84a36a6 100644 --- a/boot.php +++ b/boot.php @@ -603,6 +603,7 @@ define ( 'DBTYPE_POSTGRES', 1 ); function sys_boot() { + // our central App object App::init(); diff --git a/include/api_zot.php b/include/api_zot.php index 8f621d998..0ec9202dc 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -87,12 +87,13 @@ return false; } $sections = (($_REQUEST['sections']) ? explode(',',$_REQUEST['sections']) : ''); + $codebase = ((isset($_REQUEST['codebase']) && $_REQUEST['codebase'] === 'zap') ? true : false); if($_REQUEST['posts']) { $sections = get_default_export_sections(); $sections[] = 'items'; } - json_return_and_die(identity_basic_export(api_user(),$sections)); + json_return_and_die(identity_basic_export(api_user(),$sections,$codebase)); } function api_item_export_page($type) { @@ -111,8 +112,9 @@ $start = datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['since']); } $finish = datetime_convert(date_default_timezone_get(),'UTC', (($_REQUEST['until']) ? $_REQUEST['until'] : 'now')); + $codebase = ((isset($_REQUEST['codebase']) && $_REQUEST['codebase'] === 'zap') ? true : false); - json_return_and_die(channel_export_items_page(api_user(),$start,$finish,$page,$records)); + json_return_and_die(channel_export_items_page(api_user(),$start,$finish,$page,$records,$codebase)); } diff --git a/include/channel.php b/include/channel.php index 08b5ee889..ba4f6c6d9 100644 --- a/include/channel.php +++ b/include/channel.php @@ -937,50 +937,47 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals $newconfig = []; $abconfig = load_abconfig($channel_id,$ret['abook'][$x]['abook_xchan']); - // Partly revert of commit 85cf25a2a8bfbbfe10de485d4affd54626fbbfa4 if($abconfig) { - $ret['abook'][$x]['abconfig'] = $abconfig; - } + if ($zap_compat) { + foreach ($abconfig as $abc) { + + if ($abc['cat'] === 'my_perms') { + if (intval($abc['v'])) { + $my_perms[] = $abc['k']; + } + continue; + } + if ($abc['cat'] === 'their_perms') { + if (intval($abc['v'])) { + $their_perms[] = $abc['k']; + } + continue; + } + if (preg_match('|^a:[0-9]+:{.*}$|s', $abc['v'])) { + $abc['v'] = serialise(unserialize($abc['v'])); + } + $newconfig[] = $abc; + } - /* This was added in commit 85cf25a2a8bfbbfe10de485d4affd54626fbbfa4 - * Seems unfinished work on zap compatibility for cloning. - * It breaks cloning of abconfig for hubzilla - reverted to the above code. + $ret['abook'][$x]['abconfig'] = $newconfig; - if($abconfig) { - foreach ($abconfig as $abc) { + $ret['abook'][$x]['abconfig'][] = [ 'chan' => $channel_id, 'xchan' => $ret['abook'][$x]['abook_xchan'], 'cat' => 'system', 'k' => 'my_perms', 'v' => implode(',',$my_perms) ]; + $ret['abook'][$x]['abconfig'][] = [ 'chan' => $channel_id, 'xchan' => $ret['abook'][$x]['abook_xchan'], 'cat' => 'system', 'k' => 'their_perms', 'v' => implode(',',$their_perms) ]; - if ($abc['cat'] === 'my_perms' && intval($abc['v'])) { - $my_perms[] = $abc['k']; - continue; - } - if ($abc['cat'] === 'their_perms' && intval($abc['v'])) { - $their_perms[] = $abc['k']; - continue; - } - if ($zap_compat && preg_match('|^a:[0-9]+:{.*}$|s', $abc['v'])) { - $abc['v'] = serialise(unserialize($abc['v'])); - } - $newconfig[] = $abc; } - - $ret['abook'][$x]['abconfig'] = $newconfig; - - if ($zap_compat) { - $ret['abook'][$x]['abconfig'][] = [ 'chan' => $channel_id, 'xchan' => $ret['abook'][$x]['abook_chan'], 'cat' => 'system', 'k' => 'my_perms', 'v' => implode(',',$my_perms) ]; - $ret['abook'][$x]['abconfig'][] = [ 'chan' => $channel_id, 'xchan' => $ret['abook'][$x]['abook_chan'], 'cat' => 'system', 'k' => 'their_perms', 'v' => implode(',',$their_perms) ]; + else { + $ret['abook'][$x]['abconfig'] = $abconfig; } } - */ + translate_abook_perms_outbound($ret['abook'][$x]); } - - // pick up the zot xchan and hublocs also - if($ret['channel']['channel_portable_id']) { + if($ret['channel']['channel_portable_id'] && ! $zot_compat) { $xchans[] = $ret['channel']['channel_portable_id']; } @@ -1223,7 +1220,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals * * \e array \b relocate - (optional) * * \e array \b item - array with items encoded_item() */ -function identity_export_year($channel_id, $year, $month = 0) { +function identity_export_year($channel_id, $year, $month = 0, $zap_compat = false) { if(! $year) return array(); @@ -1241,7 +1238,7 @@ function identity_export_year($channel_id, $year, $month = 0) { else $maxdate = datetime_convert('UTC', 'UTC', $year+1 . '-01-01 00:00:00'); - return channel_export_items_date($channel_id,$mindate,$maxdate); + return channel_export_items_date($channel_id,$mindate,$maxdate, $zap_compat); } @@ -1256,7 +1253,7 @@ function identity_export_year($channel_id, $year, $month = 0) { * @return array */ -function channel_export_items_date($channel_id, $start, $finish) { +function channel_export_items_date($channel_id, $start, $finish, $zap_compat = false) { if(! $start) return array(); @@ -1304,7 +1301,7 @@ function channel_export_items_date($channel_id, $start, $finish) { * @return array */ -function channel_export_items_page($channel_id, $start, $finish, $page = 0, $limit = 50) { +function channel_export_items_page($channel_id, $start, $finish, $page = 0, $limit = 50, $zap_compat = false) { if(intval($page) < 1) { $page = 0; diff --git a/include/items.php b/include/items.php index 12b543697..bc3ce55ec 100644 --- a/include/items.php +++ b/include/items.php @@ -1089,7 +1089,7 @@ function empty_acl($item) { return (($item['allow_cid'] === EMPTY_STR && $item['allow_gid'] === EMPTY_STR && $item['deny_cid'] === EMPTY_STR && $item['deny_gid'] === EMPTY_STR) ? true : false); } -function encode_item($item,$mirror = false) { +function encode_item($item,$mirror = false,$zap_compat = false) { $x = []; $x['type'] = 'activity'; $x['encoding'] = 'zot'; -- cgit v1.2.3 From 383917eb0f219b999e1e46358317ab9ac8a9937d Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 17 Feb 2021 01:05:30 -0800 Subject: more zap export compatibility work --- include/channel.php | 12 ++++++------ include/items.php | 14 +++++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/channel.php b/include/channel.php index ba4f6c6d9..800871ab6 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1102,7 +1102,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals xchan_query($r); $r = fetch_post_tags($r,true); foreach($r as $rr) - $ret['event_item'][] = encode_item($rr,true); + $ret['event_item'][] = encode_item($rr,true, $zap_compat); } } @@ -1125,7 +1125,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals xchan_query($r); $r = fetch_post_tags($r,true); foreach($r as $rr) - $ret['webpages'][] = encode_item($rr,true); + $ret['webpages'][] = encode_item($rr,true, $zap_compat); } } @@ -1162,7 +1162,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals xchan_query($r); $r = fetch_post_tags($r,true); foreach($r as $rv) { - $ret['wiki'][] = encode_item($rv,true); + $ret['wiki'][] = encode_item($rv,true, $zap_compat); } } } @@ -1187,7 +1187,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals xchan_query($r); $r = fetch_post_tags($r,true); foreach($r as $rr) - $ret['item'][] = encode_item($rr,true); + $ret['item'][] = encode_item($rr,true, $zap_compat); } } @@ -1283,7 +1283,7 @@ function channel_export_items_date($channel_id, $start, $finish, $zap_compat = f xchan_query($r); $r = fetch_post_tags($r, true); foreach($r as $rr) - $ret['item'][] = encode_item($rr, true); + $ret['item'][] = encode_item($rr, true, $zap_compat); } return $ret; @@ -1347,7 +1347,7 @@ function channel_export_items_page($channel_id, $start, $finish, $page = 0, $lim xchan_query($r); $r = fetch_post_tags($r, true); foreach($r as $rr) - $ret['item'][] = encode_item($rr, true); + $ret['item'][] = encode_item($rr, true, $zap_compat); } return $ret; diff --git a/include/items.php b/include/items.php index bc3ce55ec..9a744787b 100644 --- a/include/items.php +++ b/include/items.php @@ -1167,9 +1167,9 @@ function encode_item($item,$mirror = false,$zap_compat = false) { $x['summary'] = $item['summary']; $x['body'] = $item['body']; $x['app'] = $item['app']; - $x['verb'] = $item['verb']; - $x['object_type'] = $item['obj_type']; - $x['target_type'] = $item['tgt_type']; + $x['verb'] = (($zap_compat) ? Activity::activity_mapper($item['verb']) : $item['verb']); + $x['object_type'] = (($zap_compat && $item['obj_type']) ? Activity::activity_object_mapper($item['obj_type']) : $item['obj_type']); + $x['target_type'] = (($zap_compat && $item['tgt_type']) ? Activity::activity_object_mapper($item['tgt_type']) : $item['tgt_type']); $x['permalink'] = $item['plink']; $x['location'] = $item['location']; $x['longlat'] = $item['coord']; @@ -1179,9 +1179,13 @@ function encode_item($item,$mirror = false,$zap_compat = false) { $x['author'] = encode_item_xchan($item['author']); if($item['obj']) - $x['object'] = json_decode($item['obj'],true); + $x['object'] = (($zap_compat) + ? Activity::encode_object(json_decode($item['obj'],true)) + : json_decode($item['obj'],true)) ; if($item['target']) - $x['target'] = json_decode($item['target'],true); + $x['target'] = (($zap_compat) + ? Activity::encode_object(json_decode($item['target'],true)) + : json_decode($item['target'],true)) ; if($item['attach']) $x['attach'] = json_decode($item['attach'],true); if($y = encode_item_flags($item)) -- cgit v1.2.3 From 0b95e061a3f15a21913e8d3c505dfe5d3fccb287 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 17 Feb 2021 01:15:07 -0800 Subject: more zap export work --- include/items.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/items.php b/include/items.php index 9a744787b..5b6dabde4 100644 --- a/include/items.php +++ b/include/items.php @@ -1204,9 +1204,16 @@ function encode_item($item,$mirror = false,$zap_compat = false) { if($item['term']) $x['tags'] = encode_item_terms($item['term'],$mirror); - if($item['iconfig']) + if($item['iconfig']) { + if ($zap_compat) { + for ($x = 0; $x < count($item['iconfig']); $x ++) { + if (preg_match('|^a:[0-9]+:{.*}$|s', $item['iconfig'][$x]['v'])) { + $item['iconfig'][$x]['v'] = serialise(unserialize($item['iconfig'][$x]['v'])); + } + } + } $x['meta'] = encode_item_meta($item['iconfig'],$mirror); - + } logger('encode_item: ' . print_r($x,true), LOGGER_DATA); -- cgit v1.2.3 From 8a65fc8a43116fcdce12bcbccd452b82a70d8da1 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 17 Feb 2021 16:36:27 -0800 Subject: more work on hz->zap migration stuff --- include/api_zot.php | 7 ++++--- include/attach.php | 4 ++-- include/channel.php | 8 +++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/api_zot.php b/include/api_zot.php index 0ec9202dc..9beaaa19c 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -87,7 +87,7 @@ return false; } $sections = (($_REQUEST['sections']) ? explode(',',$_REQUEST['sections']) : ''); - $codebase = ((isset($_REQUEST['codebase']) && $_REQUEST['codebase'] === 'zap') ? true : false); + $codebase = ((isset($_REQUEST['zap_compat']) && $_REQUEST['zap_compat']) ? true : false); if($_REQUEST['posts']) { $sections = get_default_export_sections(); $sections[] = 'items'; @@ -112,7 +112,7 @@ $start = datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['since']); } $finish = datetime_convert(date_default_timezone_get(),'UTC', (($_REQUEST['until']) ? $_REQUEST['until'] : 'now')); - $codebase = ((isset($_REQUEST['codebase']) && $_REQUEST['codebase'] === 'zap') ? true : false); + $codebase = ((isset($_REQUEST['zap_compat']) && $_REQUEST['zap_compat']) ? true : false); json_return_and_die(channel_export_items_page(api_user(),$start,$finish,$page,$records,$codebase)); } @@ -291,10 +291,11 @@ return false; if(! $_REQUEST['file_id']) return false; + $codebase = ((isset($_REQUEST['zap_compat']) && $_REQUEST['zap_compat']) ? true : false); $channel = channelx_by_n(api_user()); - $ret = attach_export_data($channel,$_REQUEST['file_id']); + $ret = attach_export_data($channel,$_REQUEST['file_id'],false,$codebase); if($ret) { json_return_and_die($ret); diff --git a/include/attach.php b/include/attach.php index 9ba6be109..db7046ef0 100644 --- a/include/attach.php +++ b/include/attach.php @@ -2339,7 +2339,7 @@ function filepath_macro($s) { } -function attach_export_data($channel, $resource_id, $deleted = false) { +function attach_export_data($channel, $resource_id, $deleted = false, $zap_compat = false) { $ret = array(); @@ -2429,7 +2429,7 @@ function attach_export_data($channel, $resource_id, $deleted = false) { xchan_query($items); $items = fetch_post_tags($items,true); foreach($items as $rr) - $ret['item'][] = encode_item($rr,true); + $ret['item'][] = encode_item($rr,true,$zap_compat); } } } diff --git a/include/channel.php b/include/channel.php index 800871ab6..cc5761162 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1088,11 +1088,17 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals } if(in_array('events',$sections)) { + + // @fixme - Not totally certain how to handle $zot_compat for the event timezone which exists + // in Hubzilla but is stored with the item and not the event. In Zap, stored information is + // always UTC and localised on access as per standard conventions for working with global time data. + $r = q("select * from event where uid = %d", intval($channel_id) ); - if($r) + if ($r) { $ret['event'] = $r; + } $r = q("select * from item where resource_type = 'event' and uid = %d", intval($channel_id) -- cgit v1.2.3 From 62b738da953e8b59f03660eeab592dc58e83ccb0 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 17 Feb 2021 19:42:58 -0800 Subject: migration testing --- Zotlabs/Lib/Activity.php | 32 ++++++++++++++++++++++++++++++-- include/channel.php | 23 ++++++++++++++++++++--- include/items.php | 25 +++++++++++++++---------- 3 files changed, 65 insertions(+), 15 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index d4d1cd28c..d286f35c2 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -423,7 +423,7 @@ class Activity { $ret['published'] = datetime_convert('UTC', 'UTC', $i['created'], ATOM_TIME); if ($i['created'] !== $i['edited']) $ret['updated'] = datetime_convert('UTC', 'UTC', $i['edited'], ATOM_TIME); - if ($i['expires'] <= NULL_DATE) { + if ($i['expires'] > NULL_DATE) { $ret['expires'] = datetime_convert('UTC', 'UTC', $i['expires'], ATOM_TIME); } @@ -450,7 +450,7 @@ class Activity { $ret['directMessage'] = true; } - if (array_key_exists('comments_closed', $i) && $i['comments_closed'] !== EMPTY_STR && $i['comments_closed'] !== NULL_DATE) { + if (array_key_exists('comments_closed', $i) && $i['comments_closed'] !== EMPTY_STR && $i['comments_closed'] > NULL_DATE) { if ($ret['commentPolicy']) { $ret['commentPolicy'] .= ' '; } @@ -1109,6 +1109,34 @@ class Activity { return $ret; } + static function encode_item_object($item, $elm = 'obj') { + $ret = []; + + if ($item[$elm]) { + if (! is_array($item[$elm])) { + $item[$elm] = json_decode($item[$elm],true); + } + if ($item[$elm]['type'] === ACTIVITY_OBJ_PHOTO) { + $item[$elm]['id'] = $item['mid']; + } + + $obj = self::encode_object($item[$elm]); + if ($obj) + return $obj; + else + return []; + } + else { + $obj = self::encode_item($item); + if ($obj) + return $obj; + else + return []; + } + + } + + static function activity_mapper($verb) { if (strpos($verb, '/') === false) { diff --git a/include/channel.php b/include/channel.php index cc5761162..fb9dcbc53 100644 --- a/include/channel.php +++ b/include/channel.php @@ -903,8 +903,20 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals $r = q("select * from profile where uid = %d", intval($channel_id) ); - if($r) + + if($r) { $ret['profile'] = $r; + if ($zap_compat) { + // zap only supports one profile + foreach ($r as $rv) { + if ($rv['is_default']) { + $ret['profile'] = [ $rv ]; + break; + } + } + } + } + $r = q("select mimetype, content, os_storage from photo where imgscale = 4 and photo_usage = %d and uid = %d limit 1", @@ -1092,15 +1104,20 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals // @fixme - Not totally certain how to handle $zot_compat for the event timezone which exists // in Hubzilla but is stored with the item and not the event. In Zap, stored information is // always UTC and localised on access as per standard conventions for working with global time data. + + // Older Zot (pre-Zot6) records aren't translated correctly w/r/t AS2 so only include events for the last year or so if + // migrating to Zap. - $r = q("select * from event where uid = %d", + $sqle = (($zap_compat) ? " and created > '2020-01-01 00:00:00' " : ''); + + $r = q("select * from event where uid = %d $sqle", intval($channel_id) ); if ($r) { $ret['event'] = $r; } - $r = q("select * from item where resource_type = 'event' and uid = %d", + $r = q("select * from item where resource_type = 'event' and uid = %d $sqle", intval($channel_id) ); if($r) { diff --git a/include/items.php b/include/items.php index 5b6dabde4..1eecfcb0b 100644 --- a/include/items.php +++ b/include/items.php @@ -1168,8 +1168,8 @@ function encode_item($item,$mirror = false,$zap_compat = false) { $x['body'] = $item['body']; $x['app'] = $item['app']; $x['verb'] = (($zap_compat) ? Activity::activity_mapper($item['verb']) : $item['verb']); - $x['object_type'] = (($zap_compat && $item['obj_type']) ? Activity::activity_object_mapper($item['obj_type']) : $item['obj_type']); - $x['target_type'] = (($zap_compat && $item['tgt_type']) ? Activity::activity_object_mapper($item['tgt_type']) : $item['tgt_type']); + $x['object_type'] = (($zap_compat && $item['obj_type']) ? Activity::activity_obj_mapper($item['obj_type']) : $item['obj_type']); + $x['target_type'] = (($zap_compat && $item['tgt_type']) ? Activity::activity_obj_mapper($item['tgt_type']) : $item['tgt_type']); $x['permalink'] = $item['plink']; $x['location'] = $item['location']; $x['longlat'] = $item['coord']; @@ -1178,13 +1178,18 @@ function encode_item($item,$mirror = false,$zap_compat = false) { $x['owner'] = encode_item_xchan($item['owner']); $x['author'] = encode_item_xchan($item['author']); - if($item['obj']) - $x['object'] = (($zap_compat) - ? Activity::encode_object(json_decode($item['obj'],true)) - : json_decode($item['obj'],true)) ; + if ($zap_compat) { + $x['object'] = Activity::encode_item_object($item,'obj'); + } + else { + if ($item['obj']) { + $x['object'] = json_decode($item['obj'],true); + } + } + if($item['target']) $x['target'] = (($zap_compat) - ? Activity::encode_object(json_decode($item['target'],true)) + ? Activity::encode_item_object($item,'target') : json_decode($item['target'],true)) ; if($item['attach']) $x['attach'] = json_decode($item['attach'],true); @@ -1206,9 +1211,9 @@ function encode_item($item,$mirror = false,$zap_compat = false) { if($item['iconfig']) { if ($zap_compat) { - for ($x = 0; $x < count($item['iconfig']); $x ++) { - if (preg_match('|^a:[0-9]+:{.*}$|s', $item['iconfig'][$x]['v'])) { - $item['iconfig'][$x]['v'] = serialise(unserialize($item['iconfig'][$x]['v'])); + for ($y = 0; $y < count($item['iconfig']); $y ++) { + if (preg_match('|^a:[0-9]+:{.*}$|s', $item['iconfig'][$y]['v'])) { + $item['iconfig'][$y]['v'] = serialise(unserialize($item['iconfig'][$y]['v'])); } } } -- cgit v1.2.3 From 136bc13ff6081a17782ef757c2e979e16333d663 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 17 Feb 2021 21:50:11 -0800 Subject: forgot these --- include/channel.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/channel.php b/include/channel.php index fb9dcbc53..5843dacf9 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1294,6 +1294,11 @@ function channel_export_items_date($channel_id, $start, $finish, $zap_compat = f $ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()]; } + if ($zap_compat) { + $ret['compatibility']['codebase'] = 'zap'; + } + + $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 != 'photo' order by created", intval(ITEM_TYPE_POST), intval($channel_id), @@ -1356,6 +1361,11 @@ function channel_export_items_page($channel_id, $start, $finish, $page = 0, $lim $ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()]; } + if ($zap_compat) { + $ret['compatibility']['codebase'] = 'zap'; + } + + $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and resource_type != 'photo' and created >= '%s' and created <= '%s' order by created limit %d offset %d", intval(ITEM_TYPE_POST), intval($channel_id), -- cgit v1.2.3 From fc88c306ab282ab7061d69e5bdc60896fbdb8839 Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 22 Feb 2021 17:23:08 -0800 Subject: some minor issues uncovered during hubzilla->zap export testing --- Zotlabs/Lib/Activity.php | 6 +++--- include/items.php | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index d286f35c2..6129e7f55 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -3313,17 +3313,17 @@ class Activity { $ret = false; foreach ($attach as $a) { - if (strpos($a['type'], 'image') !== false) { + if (array_key_exists('type',$a) && stripos($a['type'], 'image') !== false) { if (self::media_not_in_body($a['href'], $body)) { $ret .= "\n\n" . '[img]' . $a['href'] . '[/img]'; } } - if (array_key_exists('type', $a) && strpos($a['type'], 'video') === 0) { + if (array_key_exists('type', $a) && stripos($a['type'], 'video') !== false) { if (self::media_not_in_body($a['href'], $body)) { $ret .= "\n\n" . '[video]' . $a['href'] . '[/video]'; } } - if (array_key_exists('type', $a) && strpos($a['type'], 'audio') === 0) { + if (array_key_exists('type', $a) && stripos($a['type'], 'audio') !== false) { if (self::media_not_in_body($a['href'], $body)) { $ret .= "\n\n" . '[audio]' . $a['href'] . '[/audio]'; } diff --git a/include/items.php b/include/items.php index 1eecfcb0b..eda79c00d 100644 --- a/include/items.php +++ b/include/items.php @@ -1416,6 +1416,25 @@ function decode_tags($t) { return ''; } + +function purify_imported_object($obj) { + $ret = null; + if (is_array($obj)) { + foreach ( $obj as $k => $v ) { + $ret[$k] = purify_html($v); + } + } + elseif (is_string($obj)) { + $ret = purify_html($obj); + } + + return $ret; +} + + + + + /** * @brief Santise a potentially complex array. * @@ -1427,6 +1446,10 @@ function activity_sanitise($arr) { if(is_array($arr)) { $ret = array(); foreach($arr as $k => $x) { + if (in_array($k, [ 'content', 'summary', 'contentMap', 'summaryMap' ])) { + $ret[$k] = purify_imported_object($arr[$k]); + continue; + } if(is_array($x)) $ret[$k] = activity_sanitise($x); else -- cgit v1.2.3 From 0f89d2b8e06de56effc5e5f751c098a432e26e6a Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 23 Feb 2021 15:37:58 -0800 Subject: some content fields found in the wild are actually arrays --- include/items.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/items.php b/include/items.php index eda79c00d..50645fac2 100644 --- a/include/items.php +++ b/include/items.php @@ -1421,7 +1421,12 @@ function purify_imported_object($obj) { $ret = null; if (is_array($obj)) { foreach ( $obj as $k => $v ) { - $ret[$k] = purify_html($v); + if (is_array($v)) { + $ret[$k] = purify_imported_object($v); + } + elseif (is_string($v)) { + $ret[$k] = purify_html($v); + } } } elseif (is_string($obj)) { -- cgit v1.2.3 From 878be8fff0328ee4ab978de20e7e385244ac54ec Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 24 Feb 2021 11:47:46 -0800 Subject: small adjustment (effects export output but is correctly handled by import) --- include/channel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/channel.php b/include/channel.php index 34bf6aa79..c6ca673eb 100644 --- a/include/channel.php +++ b/include/channel.php @@ -891,7 +891,7 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals unset($ret['channel']['channel_salt']); } if ($zap_compat) { - unset($channel['channel_portable_id']); + unset($ret['channel']['channel_portable_id']); } } -- cgit v1.2.3 From 05152ac8c88711a74e61f75feae2c0a43dd40cc4 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 25 Aug 2021 19:15:46 -0700 Subject: issue 1599 - import_author_zot failing if primary is both dead and unknown --- Zotlabs/Lib/Libzot.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index e0e13eb60..f7d8c417a 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -2584,21 +2584,26 @@ class Libzot { $desturl = $x['url']; + $found_primary = false; + $r1 = q("select hubloc_url, hubloc_updated, site_dead from hubloc left join site on hubloc_url = site_url where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", dbesc($x['id']), dbesc($x['id_sig']) ); + if ($r1) { + $found_primary = true; + } $r2 = q("select xchan_hash from xchan where xchan_guid = '%s' and xchan_guid_sig = '%s' limit 1", dbesc($x['id']), dbesc($x['id_sig']) ); - $site_dead = false; + $primary_dead = false; if ($r1 && intval($r1[0]['site_dead'])) { - $site_dead = true; + $primary_dead = true; } // We have valid and somewhat fresh information. Always true if it is our own site. @@ -2616,13 +2621,14 @@ class Libzot { // cached entry and the identity is valid. It's just unreachable until they bring back their // server from the grave or create another clone elsewhere. - if ($site_dead) { - logger('dead site - ignoring', LOGGER_DEBUG, LOG_INFO); + if ($primary_dead || ! $found_primary) { + logger('dead or unknown primary site - ignoring', LOGGER_DEBUG, LOG_INFO); $r = q("select hubloc_id_url from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and site_dead = 0", dbesc($hash) ); + if ($r) { logger('found another site that is not dead: ' . $r[0]['hubloc_url'], LOGGER_DEBUG, LOG_INFO); $desturl = $r[0]['hubloc_url']; -- cgit v1.2.3 From 8343f63964c6cc992c2a8c90aa2a1080d5804323 Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 29 Aug 2021 04:54:50 -0700 Subject: OWA: very difficult to trace failures due to empty public key record. The signature might succeed because an empty key triggers an external key fetch. But the empty key cannot encrypt the token. This has been observed in the wild on a number of sites/projects. --- Zotlabs/Module/Owa.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zotlabs/Module/Owa.php b/Zotlabs/Module/Owa.php index 9a3513f34..e30aa5fb4 100644 --- a/Zotlabs/Module/Owa.php +++ b/Zotlabs/Module/Owa.php @@ -32,14 +32,14 @@ class Owa extends Controller { $keyId = $sigblock['keyId']; if ($keyId) { $r = q("SELECT * FROM hubloc LEFT JOIN xchan ON hubloc_hash = xchan_hash - WHERE hubloc_id_url = '%s'", + WHERE hubloc_id_url = '%s' AND xchan_pubkey != '' ", dbesc($keyId) ); if (! $r) { $found = discover_by_webbie(str_replace('acct:','',$keyId)); if ($found) { $r = q("SELECT * FROM hubloc LEFT JOIN xchan ON hubloc_hash = xchan_hash - WHERE hubloc_id_url = '%s'", + WHERE hubloc_id_url = '%s' AND xchan_pubkey != '' ", dbesc($keyId) ); } -- cgit v1.2.3