diff options
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r-- | Zotlabs/Lib/Activity.php | 68 | ||||
-rw-r--r-- | Zotlabs/Lib/Libzot.php | 51 |
2 files changed, 108 insertions, 11 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 2cc11427b..b74f6b2bc 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2,6 +2,7 @@ namespace Zotlabs\Lib; +use Zotlabs\Access\PermissionLimits; use Zotlabs\Daemon\Master; use Zotlabs\Web\HTTPSig; @@ -41,6 +42,8 @@ class Activity { if($x['type'] === ACTIVITY_OBJ_PHOTO) { return self::fetch_image($x); } + + call_hooks('encode_object',$x); } return $x; @@ -340,10 +343,21 @@ class Activity { } } + if (intval($i['item_wall']) && $i['mid'] === $i['parent_mid']) { + $ret['commentPolicy'] = map_scope(PermissionLimits::Get($i['uid'],'post_comments')); + } + if (intval($i['item_private']) === 2) { $ret['directMessage'] = true; } + if (array_key_exists('comments_closed',$i) && $i['comments_closed'] !== EMPTY_STR && $i['comments_closed'] !== NULL_DATE) { + if($ret['commentPolicy']) { + $ret['commentPolicy'] .= ' '; + } + $ret['commentPolicy'] .= 'until=' . datetime_convert('UTC','UTC',$i['comments_closed'],ATOM_TIME); + } + $ret['attributedTo'] = $i['author']['xchan_url']; if($i['id'] != $i['parent']) { @@ -795,6 +809,7 @@ class Activity { 'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept' ]; + call_hooks('activity_mapper',$acts); if(array_key_exists($verb,$acts) && $acts[$verb]) { return $acts[$verb]; @@ -840,6 +855,7 @@ class Activity { 'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept' ]; + call_hooks('activity_decode_mapper',$acts); foreach($acts as $k => $v) { if($verb === $v) { @@ -873,6 +889,8 @@ class Activity { ]; + call_hooks('activity_obj_decode_mapper',$objs); + foreach($objs as $k => $v) { if($obj === $v) { return $k; @@ -910,6 +928,8 @@ class Activity { ]; + call_hooks('activity_obj_mapper',$objs); + if(array_key_exists($obj,$objs)) { return $objs[$obj]; } @@ -1930,6 +1950,15 @@ class Activity { set_iconfig($s,'activitypub','rawmsg',$act->raw,1); } + $hookinfo = [ + 'act' => $act, + 's' => $s + ]; + + call_hooks('decode_note',$hookinfo); + + $s = $hookinfo['s']; + return $s; } @@ -2119,16 +2148,25 @@ class Activity { break; } - if(! $item) { - break; - } - array_unshift($p,[ $a, $item, $replies]); + $hookinfo = [ + 'a' => $a, + 'item' => $item + ]; - if($item['parent_mid'] === $item['mid'] || count($p) > 20) { - break; - } + call_hooks('fetch_and_store',$hookinfo); + + $item = $hookinfo['item']; + + if($item) { + + array_unshift($p,[ $a, $item, $replies]); + + if($item['parent_mid'] === $item['mid'] || count($p) > 20) { + break; + } + } $current_act = $a; $current_item = $item; } @@ -2177,11 +2215,19 @@ class Activity { default: break; } - if(! $item) { - break; - } - array_unshift($p,[ $a, $item ]); + $hookinfo = [ + 'a' => $a, + 'item' => $item + ]; + + call_hooks('fetch_and_store',$hookinfo); + + $item = $hookinfo['item']; + + if($item) { + array_unshift($p,[ $a, $item ]); + } } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 2a13744a3..0c90ff34d 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1223,9 +1223,39 @@ class Libzot { if($private) { $arr['item_private'] = true; } + + if ($arr['mid'] === $arr['parent_mid']) { + if (is_array($AS->obj) && array_key_exists('commentPolicy',$AS->obj)) { + $p = strstr($AS->obj['commentPolicy'],'until='); + if($p !== false) { + $arr['comments_closed'] = datetime_convert('UTC','UTC', substr($p,6)); + $arr['comment_policy'] = trim(str_replace($p,'',$AS->obj['commentPolicy'])); + } + else { + $arr['comment_policy'] = $AS->obj['commentPolicy']; + } + } + } + + /// @FIXME - spoofable if($AS->data['hubloc']) { $arr['item_verified'] = true; + + if (! array_key_exists('comment_policy',$arr)) { + // set comment policy depending on source hub. Unknown or osada is ActivityPub. + // Anything else we'll say is zot - which could have a range of project names + $s = q("select site_project from site where site_url = '%s' limit 1", + dbesc($r[0]['hubloc_url']) + ); + + if ((! $s) || (in_array($s[0]['site_project'],[ '', 'osada' ]))) { + $arr['comment_policy'] = 'authenticated'; + } + else { + $arr['comment_policy'] = 'contacts'; + } + } } if($AS->data['signed_data']) { IConfig::Set($arr,'activitystreams','signed_data',$AS->data['signed_data'],false); @@ -1819,6 +1849,10 @@ class Libzot { $ret = []; + $signer = q("select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1", + dbesc($a['signature']['signer']) + ); + foreach($a['data']['orderedItems'] as $activity) { $AS = new ActivityStreams($activity); @@ -1877,6 +1911,23 @@ class Libzot { if($AS->data['hubloc']) { $arr['item_verified'] = true; } + + // set comment policy depending on source hub. Unknown or osada is ActivityPub. + // Anything else we'll say is zot - which could have a range of project names + + if ($signer) { + $s = q("select site_project from site where site_url = '%s' limit 1", + dbesc($signer[0]['hubloc_url']) + ); + if ((! $s) || (in_array($s[0]['site_project'],[ '', 'osada' ]))) { + $arr['comment_policy'] = 'authenticated'; + } + else { + $arr['comment_policy'] = 'contacts'; + } + } + + if($AS->data['signed_data']) { IConfig::Set($arr,'activitystreams','signed_data',$AS->data['signed_data'],false); } |