From 49f9d5076f1e414aa451b4cfe93428971bd22b92 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 9 Dec 2018 14:15:35 -0800 Subject: [PATCH 01/10] fix home ping results when large number of network posts is present --- Zotlabs/Module/Ping.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index 6a52f5f72..aeb3ec680 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -345,6 +345,9 @@ class Ping extends \Zotlabs\Web\Controller { if(argc() > 1 && (argv(1) === 'network' || argv(1) === 'home')) { $result = array(); + if(argv(1) === 'home') { + $sql_extra .= " and item_wall = 1 "; + } $r = q("SELECT * FROM item WHERE uid = %d AND item_unseen = 1 @@ -356,13 +359,11 @@ class Ping extends \Zotlabs\Web\Controller { intval(local_channel()), dbesc($ob_hash) ); - if($r) { xchan_query($r); foreach($r as $item) { - if((argv(1) === 'home') && (! intval($item['item_wall']))) - continue; $z = \Zotlabs\Lib\Enotify::format($item); + if($z) { $result[] = $z; } @@ -543,10 +544,12 @@ class Ping extends \Zotlabs\Web\Controller { call_hooks('network_ping', $arr); foreach ($r as $it) { - if(intval($it['item_wall'])) + if(intval($it['item_wall'])) { $result['home'] ++; - else + } + else { $result['network'] ++; + } } } } From 4deda0c9fea60aaf252c82e1ed09fc8f5cfd0eae Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 9 Dec 2018 14:16:23 -0800 Subject: [PATCH 02/10] rev update --- boot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot.php b/boot.php index a7226ea68..06946e451 100755 --- a/boot.php +++ b/boot.php @@ -32,7 +32,7 @@ require_once('include/bbcode.php'); require_once('include/items.php'); -define ( 'STD_VERSION', '1.7' ); +define ( 'STD_VERSION', '2.1' ); define ( 'ZOT_REVISION', '6.0' ); define ( 'DB_UPDATE_VERSION', 1223 ); From 74d1b11961ec17e9b9f28d0341d70a9de9807a41 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 10 Dec 2018 21:01:57 -0800 Subject: [PATCH 03/10] use modulus differentiation between thread levels to aid quick comparisons --- Zotlabs/Lib/MessageFilter.php | 4 ++++ include/items.php | 10 ++++++++++ view/theme/redbasic/css/style.css | 4 ++++ view/tpl/conv_item.tpl | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Lib/MessageFilter.php b/Zotlabs/Lib/MessageFilter.php index eb0fc3d2c..281a47c83 100644 --- a/Zotlabs/Lib/MessageFilter.php +++ b/Zotlabs/Lib/MessageFilter.php @@ -43,6 +43,8 @@ class MessageFilter { return false; elseif((strpos($word,'lang=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,5))) == 0)) return false; + elseif((strpos($word,'lang!=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,6))) != 0)) + return false; elseif(stristr($text,$word) !== false) return false; } @@ -64,6 +66,8 @@ class MessageFilter { return true; elseif((strpos($word,'lang=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,5))) == 0)) return true; + elseif((strpos($word,'lang!=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,6))) != 0)) + return true; elseif(stristr($text,$word) !== false) return true; } diff --git a/include/items.php b/include/items.php index a90dac143..17b261e21 100755 --- a/include/items.php +++ b/include/items.php @@ -15,6 +15,7 @@ use Zotlabs\Lib\Enotify; use Zotlabs\Lib\MarkdownSoap; use Zotlabs\Lib\MessageFilter; use Zotlabs\Lib\IConfig; +use Zotlabs\Lib\PConfig; use Zotlabs\Lib\ThreadListener; use Zotlabs\Access\PermissionLimits; use Zotlabs\Access\AccessList; @@ -3265,6 +3266,15 @@ function post_is_importable($item,$abook) { if(! $abook) return true; + $incl = PConfig::get($abook['abook_channel'],'system','message_filter_incl',EMPTY_STR); + $excl = PConfig::get($abook['abook_channel'],'system','message_filter_excl',EMPTY_STR); + if($incl || $excl) { + $x = MessageFilter::evaluate($item,$incl,$excl); + if(! $x) { + return false; + } + } + if(($abook['abook_channel']) && (! feature_enabled($abook['abook_channel'],'connfilter'))) return true; diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css index dd1e9b790..8e5080445 100644 --- a/view/theme/redbasic/css/style.css +++ b/view/theme/redbasic/css/style.css @@ -1807,3 +1807,7 @@ dl.bb-dl > dd > li { .hover-fx-show:hover .hover-fx-hide { opacity: 1; } + +.threadlevel.even { + color: #888; +} \ No newline at end of file diff --git a/view/tpl/conv_item.tpl b/view/tpl/conv_item.tpl index 7cab64592..5fbf8708d 100755 --- a/view/tpl/conv_item.tpl +++ b/view/tpl/conv_item.tpl @@ -9,7 +9,7 @@
- {{for $x=3 to $item.thread_level}}{{/for}} + {{for $x=3 to $item.thread_level}}{{/for}} {{if $item.photo}}
{{$item.photo}} From 0a2eae66129efe836e92def7270da43e279b4431 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 10 Dec 2018 23:53:03 -0800 Subject: [PATCH 04/10] configurable hyperdrive --- Zotlabs/Lib/Activity.php | 5 ++++- Zotlabs/Lib/Libzot.php | 4 ++++ Zotlabs/Module/Settings/Channel.php | 5 +++++ view/tpl/settings.tpl | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 738c94a0e..efbfcbee3 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2179,7 +2179,10 @@ class Activity { intval($item['uid']) ); if(! $p) { - $a = (($fetch_parents) ? self::fetch_and_store_parents($channel,$observer_hash,$act,$item) : false); + $a = false; + if(get_pconfig('system','hyperdrive',true)) { + $a = (($fetch_parents) ? self::fetch_and_store_parents($channel,$observer_hash,$act,$item) : false); + } if($a) { $p = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", dbesc($item['parent_mid']), diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 489b57727..aa3af4ae3 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1551,6 +1551,10 @@ class Libzot { // the top level post is unlikely to be imported and // this is just an exercise in futility. + if(! get_pconfig($channel['channel_id'],'system','hyperdrive',true)) { + continue; + } + if((! $relay) && (! $request) && (! $local_public) && perm_is_allowed($channel['channel_id'],$sender,'send_stream')) { $f = self::fetch_conversation($channel,$arr['parent_mid']); diff --git a/Zotlabs/Module/Settings/Channel.php b/Zotlabs/Module/Settings/Channel.php index d9789e053..b94102f73 100644 --- a/Zotlabs/Module/Settings/Channel.php +++ b/Zotlabs/Module/Settings/Channel.php @@ -147,6 +147,7 @@ class Channel { $suggestme = ((x($_POST,'suggestme')) ? intval($_POST['suggestme']) : 0); $autoperms = ((x($_POST,'autoperms')) ? intval($_POST['autoperms']) : 0); $anymention = ((x($_POST,'anymention')) ? intval($_POST['anymention']) : 0); + $hyperdrive = ((x($_POST,'hyperdrive')) ? intval($_POST['hyperdrive']) : 0); $public_uploads = ((isset($_POST['public_uploads'])) ? intval($_POST['public_uploads']) : 0); $post_newfriend = (($_POST['post_newfriend'] == 1) ? 1: 0); $post_joingroup = (($_POST['post_joingroup'] == 1) ? 1: 0); @@ -257,6 +258,7 @@ class Channel { set_pconfig(local_channel(),'system','profile_assign',$profile_assign); set_pconfig(local_channel(),'system','autoperms',$autoperms); set_pconfig(local_channel(),'system','anymention',$anymention); + set_pconfig(local_channel(),'system','hyperdrive',$hyperdrive); set_pconfig(local_channel(),'system','force_public_uploads',$public_uploads); $r = q("update channel set channel_name = '%s', channel_pageflags = %d, channel_timezone = '%s', channel_location = '%s', channel_notifyflags = %d, channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d $set_perms where channel_id = %d", @@ -495,6 +497,8 @@ class Channel { $anymention = ''; } + $hyperdrive = [ 'hyperdrive', t('Enable hyperdrive'), ((get_pconfig(local_channel(),'system','hyperdrive',true)) ? 1 : 0), t('Dramatically increases the content available in your stream.'), $yes_no ]; + $permissions_set = (($permissions_role != 'custom') ? true : false); $perm_roles = \Zotlabs\Access\PermissionRoles::roles(); @@ -575,6 +579,7 @@ class Channel { '$autoperms' => $autoperms, '$anymention' => $anymention, + '$hyperdrive' => $hyperdrive, '$h_not' => t('Notification Settings'), '$activity_options' => t('By default post a status message when:'), '$post_newfriend' => array('post_newfriend', t('accepting a friend request'), $post_newfriend, '', $yes_no), diff --git a/view/tpl/settings.tpl b/view/tpl/settings.tpl index 5a1247f7e..70c4285ac 100755 --- a/view/tpl/settings.tpl +++ b/view/tpl/settings.tpl @@ -189,7 +189,7 @@
{{/if}} {{include file="field_checkbox.tpl" field=$cal_first_day}} - + {{include file="field_checkbox.tpl" field=$hyperdrive}} {{if $misc_addon}} {{$misc_addon}} {{/if}} From 50ad168ad0071b40259c0cd71e1f495c558d7cb3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 11 Dec 2018 15:57:15 -0800 Subject: [PATCH 05/10] issues with language filtering --- Zotlabs/Lib/Activity.php | 26 ++++++++++---------------- Zotlabs/Lib/Libzot.php | 4 ++-- Zotlabs/Lib/MessageFilter.php | 3 +-- include/feedutils.php | 4 ++-- include/items.php | 17 +++++++++-------- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index efbfcbee3..9c920b362 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1603,11 +1603,9 @@ class Activity { } - if($abook) { - if(! post_is_importable($s,$abook[0])) { - logger('post is filtered'); - return; - } + if(! post_is_importable($channel['channel_id'],$s,$abook[0])) { + logger('post is filtered'); + return; } if($act->obj['conversation']) { @@ -2139,13 +2137,11 @@ class Activity { intval($channel['channel_id']) ); - if($abook) { - if(! post_is_importable($item,$abook[0])) { - logger('post is filtered'); - return; - } - } + if(! post_is_importable($channel['channel_id'],$item,$abook[0])) { + logger('post is filtered'); + return; + } if($act->obj['conversation']) { set_iconfig($item,'ostatus','conversation',$act->obj['conversation'],1); @@ -2374,11 +2370,9 @@ class Activity { intval($channel['channel_id']) ); - if($abook) { - if(! post_is_importable($s,$abook[0])) { - logger('post is filtered'); - return; - } + if(! post_is_importable($channel['channel_id'],$s,$abook[0])) { + logger('post is filtered'); + return; } if($act->obj['conversation']) { diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index aa3af4ae3..14893f71b 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1666,7 +1666,7 @@ class Libzot { elseif($arr['edited'] > $r[0]['edited']) { $arr['id'] = $r[0]['id']; $arr['uid'] = $channel['channel_id']; - if(($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($arr,$abook))) { + if(($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($channel['channel_id'],$arr,$abook))) { $DR->update('update ignored'); $result[] = $DR->get(); } @@ -1706,7 +1706,7 @@ class Libzot { $item_id = 0; - if(($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($arr,$abook))) { + if(($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($arr['uid'],$arr,$abook))) { $DR->update('post ignored'); $result[] = $DR->get(); } diff --git a/Zotlabs/Lib/MessageFilter.php b/Zotlabs/Lib/MessageFilter.php index 281a47c83..b45a1f229 100644 --- a/Zotlabs/Lib/MessageFilter.php +++ b/Zotlabs/Lib/MessageFilter.php @@ -16,10 +16,9 @@ class MessageFilter { $text = prepare_text($item['body'],$item['mimetype']); $text = html2plain(($item['title']) ? $item['title'] . ' ' . $text : $text); - $lang = null; - if((strpos($incl,'lang=') !== false) || (strpos($excl,'lang=') !== false)) { + if((strpos($incl,'lang=') !== false) || (strpos($excl,'lang=') !== false) || (strpos($incl,'lang!=') !== false) || (strpos($excl,'lang!=') !== false)) { $lang = detect_language($text); } diff --git a/include/feedutils.php b/include/feedutils.php index 6de7d86e0..1bc006211 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1338,7 +1338,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } } - if(! post_is_importable($datarray, $contact)) + if(! post_is_importable($importer['channel_id'],$datarray, $contact)) continue; $datarray['parent_mid'] = $datarray['mid']; @@ -1494,7 +1494,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } } - if(! post_is_importable($datarray, $contact)) + if(! post_is_importable($importer['channel_id'],$datarray, $contact)) continue; logger('author: ' . print_r($author, true), LOGGER_DEBUG); diff --git a/include/items.php b/include/items.php index 17b261e21..9a64ce66a 100755 --- a/include/items.php +++ b/include/items.php @@ -3261,25 +3261,26 @@ function check_item_source($uid, $item) { return false; } -function post_is_importable($item,$abook) { +function post_is_importable($channel_id,$item,$abook) { - if(! $abook) - return true; + if(! $item) + return false; - $incl = PConfig::get($abook['abook_channel'],'system','message_filter_incl',EMPTY_STR); - $excl = PConfig::get($abook['abook_channel'],'system','message_filter_excl',EMPTY_STR); + $incl = PConfig::get($channel_id,'system','message_filter_incl',EMPTY_STR); + $excl = PConfig::get($channel_id,'system','message_filter_excl',EMPTY_STR); if($incl || $excl) { $x = MessageFilter::evaluate($item,$incl,$excl); if(! $x) { + logger('MessageFilter: channel blocked content',LOGGER_DEBUG,LOG_INFO); return false; } } - if(($abook['abook_channel']) && (! feature_enabled($abook['abook_channel'],'connfilter'))) + if(($channel_id) && (! feature_enabled($channel_id,'connfilter'))) return true; - if(! $item) - return false; + if(! $abook) + return true; if(! ($abook['abook_incl'] || $abook['abook_excl'])) return true; From c4b3ad8c7608dabd4608afdaaa68f36cae567d5e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 11 Dec 2018 20:30:47 -0800 Subject: [PATCH 06/10] try to gracefully handle multi-protocol xchans/hublocs with the same url --- Zotlabs/Lib/Activity.php | 22 ++++++++++++++++++++++ Zotlabs/Lib/Libzot.php | 6 ++++++ include/items.php | 30 +++++++++++++++++++++++------- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9c920b362..409230061 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2120,11 +2120,21 @@ class Activity { $item['aid'] = $channel['channel_account_id']; $item['uid'] = $channel['channel_id']; + + // Some authors may be zot6 authors in which case we want to store their nomadic identity + // instead of their ActivityPub identity + + $item['author_xchan'] = self::find_best_identity($item['author_xchan']); + $item['owner_xchan'] = self::find_best_identity($item['owner_xchan']); + if(! ( $item['author_xchan'] && $item['owner_xchan'])) { logger('owner or author missing.'); return; } + + + if($channel['channel_system']) { if(! MessageFilter::evaluate($item,get_config('system','pubstream_incl'),get_config('system','pubstream_excl'))) { logger('post is filtered'); @@ -2245,6 +2255,18 @@ class Activity { } + static public function find_best_identity($xchan) { + + $r = q("select hubloc_hash from hubloc where hubloc_id_url = '%s' limit 1", + dbesc($xchan) + ); + if($r) { + return $r[0]['hubloc_hash']; + } + return $xchan; + } + + static public function fetch_and_store_parents($channel,$observer_hash,$act,$item) { logger('fetching parents'); diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 14893f71b..47fe57cd8 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1412,6 +1412,12 @@ class Libzot { $result = []; + // If an upstream hop used ActivityPub, set the identities to zot6 nomadic identities where applicable + // else things could easily get confused + + $arr['author_xchan'] = Activity::find_best_identity($arr['author_xchan']); + $arr['owner_xchan'] = Activity::find_best_identity($arr['owner_xchan']); + // We've validated the sender. Now make sure that the sender is the owner or author if(! $public) { diff --git a/include/items.php b/include/items.php index 9a64ce66a..1a8b810f2 100755 --- a/include/items.php +++ b/include/items.php @@ -834,32 +834,48 @@ function import_author_activitypub($x) { if(! $x['url']) return false; - // let somebody upgrade from an 'unknown' connection which has no xchan_addr - $r = q("select xchan_hash, xchan_url, xchan_name, xchan_photo_s from xchan where xchan_url = '%s' limit 1", + // let somebody upgrade from an 'unknown' connection which has no xchan_addr and resolve issues with identities from multiple protocols using the same url + + $r = q("select xchan_hash, xchan_url, xchan_network, xchan_name, xchan_photo_s from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_id_url = '%s'", dbesc($x['url']) ); if(! $r) { - $r = q("select xchan_hash, xchan_url, xchan_name, xchan_photo_s from xchan where xchan_hash = '%s' limit 1", + $r = q("select xchan_hash, xchan_url, xchan_network, xchan_name, xchan_photo_s from xchan where xchan_hash = '%s' ", dbesc($x['url']) ); } if($r) { - logger('in_cache: ' . $r[0]['xchan_name'], LOGGER_DATA); - return $r[0]['xchan_hash']; + $ptr = null; + foreach($r as $rv) { + if (strpos($rv['xchan_network'],'zot') !== false) { + $ptr = $rv; + } + } + if(! $ptr) { + $ptr = $r[0]; + } + + logger('in_cache: ' . $ptr['xchan_name'], LOGGER_DATA); + return $ptr['xchan_hash']; } $z = discover_by_webbie($x['url']); if($z) { - $r = q("select xchan_hash, xchan_url, xchan_name, xchan_photo_s from xchan where xchan_url = '%s' limit 1", + $r = q("select xchan_hash, xchan_url, xchan_network, xchan_name, xchan_photo_s from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_id_url = '%s'", dbesc($x['url']) ); if(! $r) { - $r = q("select xchan_hash, xchan_url, xchan_name, xchan_photo_s from xchan where xchan_hash = '%s' limit 1", + $r = q("select xchan_hash, xchan_url, xchan_name, xchan_photo_s from xchan where xchan_hash = '%s' ", dbesc($x['url']) ); } if($r) { + foreach($r as $rv) { + if (strpos($rv['xchan_network'],'zot') !== false) { + return $rv['xchan_hash']; + } + } return $r[0]['xchan_hash']; } } From 334bec0f401ce9230463787d70319f81e45d3a2c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 11 Dec 2018 21:03:50 -0800 Subject: [PATCH 07/10] strip titles on response activities --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 409230061..9520414e0 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1820,7 +1820,7 @@ class Activity { if(! $s['edited']) $s['edited'] = $s['created']; - $s['title'] = self::bb_content($content,'name'); + $s['title'] = (($response_activity) ? EMPTY_STR : self::bb_content($content,'name')); $s['summary'] = self::bb_content($content,'summary'); $s['body'] = ((self::bb_content($content,'bbcode') && (! $response_activity)) ? self::bb_content($content,'bbcode') : self::bb_content($content,'content')); From 42fa248f8174468e66fbad210244ad65d077551e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 11 Dec 2018 21:42:15 -0800 Subject: [PATCH 08/10] prefer zot6 hublocs and xchans when there's a choice. --- Zotlabs/Lib/Libzot.php | 20 ++++++++++++++++++++ Zotlabs/Web/HTTPSig.php | 38 +++++++++++++++++++++++++++----------- include/follow.php | 14 +++++++++++--- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 47fe57cd8..e53ae4334 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -3038,4 +3038,24 @@ class Libzot { return(($x) ? true : false); } + + static public function zot_record_preferred($arr, $check = 'hubloc_network') { + + if(! $arr) { + return $arr; + } + + foreach($arr as $v) { + if($v[$check] === 'zot6') { + return $v; + } + } + + return $arr[0]; + + } + + + + } diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index 3cb771a0d..047758b10 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -4,6 +4,8 @@ namespace Zotlabs\Web; use Zotlabs\Lib\ActivityStreams; use Zotlabs\Lib\Webfinger; +use Zotlabs\Lib\Zotfinger; +use Zotlabs\Lib\Libzot; /** * @brief Implements HTTP Signatures per draft-cavage-http-signatures-10. @@ -240,13 +242,17 @@ class HTTPSig { $url = ((strpos($id,'#')) ? substr($id,0,strpos($id,'#')) : $id); - $x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_addr = '%s' or hubloc_id_url = '%s' limit 1", + $x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_addr = '%s' or hubloc_id_url = '%s' ", dbesc(str_replace('acct:','',$url)), dbesc($url) ); - if($x && $x[0]['xchan_pubkey']) { - return [ 'portable_id' => $x[0]['xchan_hash'], 'public_key' => $x[0]['xchan_pubkey'] , 'hubloc' => $x[0] ]; + if($x) { + $best = Libzot::zot_record_preferred($best); + } + + if($best && $best['xchan_pubkey']) { + return [ 'portable_id' => $best['xchan_hash'], 'public_key' => $best['xchan_pubkey'] , 'hubloc' => $best ]; } $r = ActivityStreams::fetch($id); @@ -265,13 +271,17 @@ class HTTPSig { function get_webfinger_key($id) { - $x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_addr = '%s' or hubloc_id_url = '%s' limit 1", + $x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_addr = '%s' or hubloc_id_url = '%s' ", dbesc(str_replace('acct:','',$id)), dbesc($id) ); - if($x && $x[0]['xchan_pubkey']) { - return [ 'portable_id' => $x[0]['xchan_hash'], 'public_key' => $x[0]['xchan_pubkey'] , 'hubloc' => $x[0] ]; + if($x) { + $best = Libzot::zot_record_preferred($best); + } + + if($best && $best['xchan_pubkey']) { + return [ 'portable_id' => $best['xchan_hash'], 'public_key' => $best['xchan_pubkey'] , 'hubloc' => $best ]; } $wf = Webfinger::exec($id); @@ -299,14 +309,20 @@ class HTTPSig { function get_zotfinger_key($id) { - $x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_addr = '%s' or hubloc_id_url = '%s' limit 1", + $x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_addr = '%s' or hubloc_id_url = '%s' ", dbesc(str_replace('acct:','',$id)), dbesc($id) ); - if($x && $x[0]['xchan_pubkey']) { - return [ 'portable_id' => $x[0]['xchan_hash'], 'public_key' => $x[0]['xchan_pubkey'] , 'hubloc' => $x[0] ]; + + if($x) { + $best = Libzot::zot_record_preferred($best); } + if($best && $best['xchan_pubkey']) { + return [ 'portable_id' => $best['xchan_hash'], 'public_key' => $best['xchan_pubkey'] , 'hubloc' => $best ]; + } + + $wf = Webfinger::exec($id); $key = [ 'portable_id' => '', 'public_key' => '', 'hubloc' => [] ]; @@ -320,9 +336,9 @@ class HTTPSig { continue; } if($l['rel'] === 'http://purl.org/zot/protocol/6.0' && array_key_exists('href',$l) && $l['href'] !== EMPTY_STR) { - $z = \Zotlabs\Lib\Zotfinger::exec($l['href']); + $z = Zotfinger::exec($l['href']); if($z) { - $i = Zotlabs\Lib\Libzot::import_xchan($z['data']); + $i = Libzot::import_xchan($z['data']); if($i['success']) { $key['portable_id'] = $i['hash']; diff --git a/include/follow.php b/include/follow.php index bf4a8e4f7..48cad44ba 100644 --- a/include/follow.php +++ b/include/follow.php @@ -60,12 +60,20 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $xchan_hash = ''; $sql_options = (($protocol) ? " and xchan_network = '" . dbesc($protocol) . "' " : ''); - $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s' $sql_options limit 1", + $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s' $sql_options ", dbesc($url), dbesc($url), dbesc($url) ); + if($r) { + + // reset results to the best record or the first if we don't have the best + + $r = Libzot::zot_record_preferred($r,'xchan_network'); + } + + $singleton = false; $d = false; @@ -99,8 +107,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) // if discovery was a success we should have an xchan record in $r if($r) { - $xchan = $r[0]; - $xchan_hash = $r[0]['xchan_hash']; + $xchan = $r; + $xchan_hash = $r['xchan_hash']; $their_perms = EMPTY_STR; } From a66c72127a15c2716348951637a17c0fc4dac9a0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 12 Dec 2018 15:39:17 -0800 Subject: [PATCH 09/10] missing arg in pconfig_get --- Zotlabs/Lib/Activity.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9520414e0..680c03495 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -806,7 +806,7 @@ class Activity { $ret['type'] = 'Person'; if($c) { - $role = get_pconfig($c['channel_id'],'system','permissions_role'); + $role = PConfig::Get($c['channel_id'],'system','permissions_role'); if(strpos($role,'forum') !== false) { $ret['type'] = 'Group'; } @@ -1105,7 +1105,7 @@ class Activity { $my_perms = Permissions::serialise($p['perms']); $automatic = $p['automatic']; - $closeness = get_pconfig($channel['channel_id'],'system','new_abook_closeness',80); + $closeness = PConfig::Get($channel['channel_id'],'system','new_abook_closeness',80); $r = abook_store_lowlevel( [ @@ -1123,10 +1123,10 @@ class Activity { ); if($my_perms) - set_abconfig($channel['channel_id'],$ret['xchan_hash'],'system','my_perms',$my_perms); + AbConfig:Set($channel['channel_id'],$ret['xchan_hash'],'system','my_perms',$my_perms); if($their_perms) - set_abconfig($channel['channel_id'],$ret['xchan_hash'],'system','their_perms',$their_perms); + AbConfig::Set($channel['channel_id'],$ret['xchan_hash'],'system','their_perms',$their_perms); if($r) { @@ -2186,7 +2186,7 @@ class Activity { ); if(! $p) { $a = false; - if(get_pconfig('system','hyperdrive',true)) { + if(PConfig::Get($channel['channel_id'],'system','hyperdrive',true)) { $a = (($fetch_parents) ? self::fetch_and_store_parents($channel,$observer_hash,$act,$item) : false); } if($a) { From 1fa2d111baf463e2ebe5041b6582816af5c669eb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 12 Dec 2018 16:26:30 -0800 Subject: [PATCH 10/10] wrong varname --- Zotlabs/Web/HTTPSig.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index 047758b10..738cf2163 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -248,7 +248,7 @@ class HTTPSig { ); if($x) { - $best = Libzot::zot_record_preferred($best); + $best = Libzot::zot_record_preferred($x); } if($best && $best['xchan_pubkey']) { @@ -277,7 +277,7 @@ class HTTPSig { ); if($x) { - $best = Libzot::zot_record_preferred($best); + $best = Libzot::zot_record_preferred($x); } if($best && $best['xchan_pubkey']) { @@ -315,7 +315,7 @@ class HTTPSig { ); if($x) { - $best = Libzot::zot_record_preferred($best); + $best = Libzot::zot_record_preferred($x); } if($best && $best['xchan_pubkey']) {