From 94893d896007b13af9e99d7d6becb14b28b12e8a Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 23 Oct 2019 00:40:13 +0200 Subject: [PATCH 1/9] Move expand_acl to ACLFormatter::expand() - including tests --- remote_permissions/remote_permissions.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/remote_permissions/remote_permissions.php b/remote_permissions/remote_permissions.php index 5adfc028..ad6d7b25 100644 --- a/remote_permissions/remote_permissions.php +++ b/remote_permissions/remote_permissions.php @@ -7,12 +7,14 @@ * Status: Unsupported */ +use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\Util\ACLFormatter; use Friendica\Util\Strings; function remote_permissions_install() { @@ -123,10 +125,13 @@ function remote_permissions_content($a, $item_copy) { $item = $r[0]; - $allowed_users = expand_acl($item['allow_cid']); - $allowed_groups = expand_acl($item['allow_gid']); - $deny_users = expand_acl($item['deny_cid']); - $deny_groups = expand_acl($item['deny_gid']); + /** @var ACLFormatter $aclFormatter */ + $aclFormatter = BaseObject::getClass(ACLFormatter::class); + + $allowed_users = $aclFormatter->expand($item['allow_cid']); + $allowed_groups = $aclFormatter->expand($item['allow_gid']); + $deny_users = $aclFormatter->expand($item['deny_cid']); + $deny_groups = $aclFormatter->expand($item['deny_gid']); $o = L10n::t('Visible to:') . '
'; $allow = []; -- 2.45.2 From 46bccdc9e0eaa2a45ae5017be024789dadec14ad Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Thu, 24 Oct 2019 00:25:42 +0200 Subject: [PATCH 2/9] Move Activity/Namespaces defines to constants --- mailstream/mailstream.php | 3 ++- pumpio/pumpio.php | 31 ++++++++++++++++--------------- statusnet/statusnet.php | 13 +++++++------ twitter/twitter.php | 23 ++++++++++++----------- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index a58dfc1c..d6d880f1 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -14,6 +14,7 @@ use Friendica\Core\Logger; use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\Protocol\Activity; use Friendica\Util\Network; use Friendica\Model\Item; @@ -122,7 +123,7 @@ function mailstream_post_hook(&$a, &$item) { return; } if (PConfig::get($item['uid'], 'mailstream', 'nolikes')) { - if ($item['verb'] == ACTIVITY_LIKE) { + if ($item['verb'] == Activity::LIKE) { Logger::debug('mailstream: like item ' . $item['id']); return; } diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 537bf280..7bbaf246 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -21,6 +21,7 @@ use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\User; +use Friendica\Protocol\Activity; use Friendica\Util\ConfigFileLoader; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -480,7 +481,7 @@ function pumpio_send(App $a, array &$b) } } - if ($b['verb'] == ACTIVITY_LIKE) { + if ($b['verb'] == Activity::LIKE) { if ($b['deleted']) { pumpio_action($a, $b["uid"], $b["thr-parent"], "unlike"); } else { @@ -489,15 +490,15 @@ function pumpio_send(App $a, array &$b) return; } - if ($b['verb'] == ACTIVITY_DISLIKE) { + if ($b['verb'] == Activity::DISLIKE) { return; } - if (($b['verb'] == ACTIVITY_POST) && ($b['created'] !== $b['edited']) && !$b['deleted']) { + if (($b['verb'] == Activity::POST) && ($b['created'] !== $b['edited']) && !$b['deleted']) { pumpio_action($a, $b["uid"], $b["uri"], "update", $b["body"]); } - if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) { + if (($b['verb'] == Activity::POST) && $b['deleted']) { pumpio_action($a, $b["uid"], $b["uri"], "delete"); } @@ -560,8 +561,8 @@ function pumpio_send(App $a, array &$b) $inReplyTo = ["id" => $orig_post["uri"], "objectType" => "note"]; - if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], NAMESPACE_ACTIVITY_SCHEMA))) { - $inReplyTo["objectType"] = str_replace(NAMESPACE_ACTIVITY_SCHEMA, '', $orig_post["object-type"]); + if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\Namespaces::ACTIVITY_SCHEMA))) { + $inReplyTo["objectType"] = str_replace(Activity\Namespaces::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); } $params["object"] = [ @@ -636,8 +637,8 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") $uri = $orig_post["uri"]; } - if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], NAMESPACE_ACTIVITY_SCHEMA))) { - $objectType = str_replace(NAMESPACE_ACTIVITY_SCHEMA, '', $orig_post["object-type"]); + if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\Namespaces::ACTIVITY_SCHEMA))) { + $objectType = str_replace(Activity\Namespaces::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); } elseif (strstr($uri, "/api/comment/")) { $objectType = "comment"; } elseif (strstr($uri, "/api/note/")) { @@ -914,7 +915,7 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) } } - Item::delete(['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]); + Item::delete(['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]); if (DBA::isResult($r)) { Logger::log("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); @@ -969,7 +970,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = } } - $condition = ['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]; + $condition = ['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]; if (Item::exists($condition)) { Logger::log("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); return; @@ -977,7 +978,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = $likedata = []; $likedata['parent'] = $orig_post['id']; - $likedata['verb'] = ACTIVITY_LIKE; + $likedata['verb'] = Activity::LIKE; $likedata['gravity'] = GRAVITY_ACTIVITY; $likedata['uid'] = $uid; $likedata['wall'] = 0; @@ -996,11 +997,11 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = $objauthor = '[url=' . $orig_post['author-link'] . ']' . $orig_post['author-name'] . '[/url]'; $post_type = L10n::t('status'); $plink = '[url=' . $orig_post['plink'] . ']' . $post_type . '[/url]'; - $likedata['object-type'] = ACTIVITY_OBJ_NOTE; + $likedata['object-type'] = Activity::OBJ_NOTE; $likedata['body'] = L10n::t('%1$s likes %2$s\'s %3$s', $author, $objauthor, $plink); - $likedata['object'] = '' . ACTIVITY_OBJ_NOTE . '1' . + $likedata['object'] = '' . Activity::OBJ_NOTE . '1' . '' . $orig_post['uri'] . '' . XML::escape('') . '' . $orig_post['title'] . '' . $orig_post['body'] . ''; $ret = Item::insert($likedata); @@ -1147,7 +1148,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp $postarray['uid'] = $uid; $postarray['wall'] = 0; $postarray['uri'] = $post->object->id; - $postarray['object-type'] = NAMESPACE_ACTIVITY_SCHEMA.strtolower($post->object->objectType); + $postarray['object-type'] = Activity\Namespaces::ACTIVITY_SCHEMA.strtolower($post->object->objectType); if ($post->object->objectType != "comment") { $contact_id = pumpio_get_contact($uid, $post->actor); @@ -1230,7 +1231,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp } $postarray['contact-id'] = $contact_id; - $postarray['verb'] = ACTIVITY_POST; + $postarray['verb'] = Activity::POST; $postarray['owner-name'] = $post->actor->displayName; $postarray['owner-link'] = $post->actor->url; $postarray['author-name'] = $postarray['owner-name']; diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index ed7b87d8..f78252ff 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -56,6 +56,7 @@ use Friendica\Model\Item; use Friendica\Model\ItemContent; use Friendica\Model\Photo; use Friendica\Model\User; +use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\Strings; @@ -550,11 +551,11 @@ function statusnet_post_hook(App $a, &$b) } } - if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) { + if (($b['verb'] == Activity::POST) && $b['deleted']) { statusnet_action($a, $b["uid"], substr($orig_post["uri"], $hostlength), "delete"); } - if ($b['verb'] == ACTIVITY_LIKE) { + if ($b['verb'] == Activity::LIKE) { Logger::log("statusnet_post_hook: parameter 2 " . substr($b["thr-parent"], $hostlength), Logger::DEBUG); if ($b['deleted']) statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "unlike"); @@ -1139,11 +1140,11 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $postarray['thr-parent'] = $item['uri']; $postarray['parent-uri'] = $item['parent-uri']; $postarray['parent'] = $item['parent']; - $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; + $postarray['object-type'] = Activity::OBJ_COMMENT; } else { $postarray['thr-parent'] = $postarray['uri']; $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + $postarray['object-type'] = Activity::OBJ_NOTE; } // Is it me? @@ -1167,7 +1168,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $create_user = false; } else { $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + $postarray['object-type'] = Activity::OBJ_NOTE; } if ($contactid == 0) { @@ -1184,7 +1185,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $postarray['contact-id'] = $contactid; - $postarray['verb'] = ACTIVITY_POST; + $postarray['verb'] = Activity::POST; $postarray['author-name'] = $content->user->name; $postarray['author-link'] = $content->user->statusnet_profile_url; diff --git a/twitter/twitter.php b/twitter/twitter.php index a43e8358..9a2aea75 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -85,6 +85,7 @@ use Friendica\Model\Item; use Friendica\Model\ItemContent; use Friendica\Model\User; use Friendica\Object\Image; +use Friendica\Protocol\Activity; use Friendica\Util\ConfigFileLoader; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -556,11 +557,11 @@ function twitter_post_hook(App $a, array &$b) } } - if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) { + if (($b['verb'] == Activity::POST) && $b['deleted']) { twitter_action($a, $b["uid"], substr($orig_post["uri"], 9), "delete"); } - if ($b['verb'] == ACTIVITY_LIKE) { + if ($b['verb'] == Activity::LIKE) { Logger::log("twitter_post_hook: parameter 2 " . substr($b["thr-parent"], 9), Logger::DEBUG); if ($b['deleted']) { twitter_action($a, $b["uid"], substr($b["thr-parent"], 9), "unlike"); @@ -1340,7 +1341,7 @@ function twitter_media_entities($post, array &$postarray) $media[$medium->url] .= "\n[img]" . $medium->media_url_https . '[/img]'; } - $postarray['object-type'] = ACTIVITY_OBJ_IMAGE; + $postarray['object-type'] = Activity::OBJ_IMAGE; break; case 'video': case 'animated_gif': @@ -1351,7 +1352,7 @@ function twitter_media_entities($post, array &$postarray) $media[$medium->url] .= "\n[img]" . $medium->media_url_https . '[/img]'; } - $postarray['object-type'] = ACTIVITY_OBJ_VIDEO; + $postarray['object-type'] = Activity::OBJ_VIDEO; if (is_array($medium->video_info->variants)) { $bitrate = 0; // We take the video with the highest bitrate @@ -1408,11 +1409,11 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl $postarray['thr-parent'] = $parent_item['uri']; $postarray['parent-uri'] = $parent_item['parent-uri']; $postarray['parent'] = $parent_item['parent']; - $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; + $postarray['object-type'] = Activity::OBJ_COMMENT; } else { $postarray['thr-parent'] = $postarray['uri']; $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + $postarray['object-type'] = Activity::OBJ_NOTE; } // Is it me? @@ -1437,7 +1438,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl $create_user = false; } else { $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + $postarray['object-type'] = Activity::OBJ_NOTE; } if ($contactid == 0) { @@ -1457,7 +1458,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl $postarray['contact-id'] = $contactid; - $postarray['verb'] = ACTIVITY_POST; + $postarray['verb'] = Activity::POST; $postarray['author-name'] = $postarray['owner-name']; $postarray['author-link'] = $postarray['owner-link']; $postarray['author-avatar'] = $postarray['owner-avatar']; @@ -1480,7 +1481,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl // When the post contains links then use the correct object type if (count($post->entities->urls) > 0) { - $postarray['object-type'] = ACTIVITY_OBJ_BOOKMARK; + $postarray['object-type'] = Activity::OBJ_BOOKMARK; } // Search for media links @@ -1518,9 +1519,9 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl Item::insert($retweet); // CHange the other post into a reshare activity - $postarray['verb'] = ACTIVITY2_ANNOUNCE; + $postarray['verb'] = Activity::ANNOUNCE; $postarray['gravity'] = GRAVITY_ACTIVITY; - $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + $postarray['object-type'] = Activity::OBJ_NOTE; $postarray['thr-parent'] = $retweet['uri']; $postarray['parent-uri'] = $retweet['uri']; -- 2.45.2 From a555820111d548737b435e170d4626a03ba183ae Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Thu, 24 Oct 2019 09:06:21 +0200 Subject: [PATCH 3/9] Rename namespace --- pumpio/pumpio.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 7bbaf246..7a37f5f4 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -561,8 +561,8 @@ function pumpio_send(App $a, array &$b) $inReplyTo = ["id" => $orig_post["uri"], "objectType" => "note"]; - if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\Namespaces::ACTIVITY_SCHEMA))) { - $inReplyTo["objectType"] = str_replace(Activity\Namespaces::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); + if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\ANamespace::ACTIVITY_SCHEMA))) { + $inReplyTo["objectType"] = str_replace(Activity\ANamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); } $params["object"] = [ @@ -637,8 +637,8 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") $uri = $orig_post["uri"]; } - if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\Namespaces::ACTIVITY_SCHEMA))) { - $objectType = str_replace(Activity\Namespaces::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); + if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\ANamespace::ACTIVITY_SCHEMA))) { + $objectType = str_replace(Activity\ANamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); } elseif (strstr($uri, "/api/comment/")) { $objectType = "comment"; } elseif (strstr($uri, "/api/note/")) { @@ -1148,7 +1148,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp $postarray['uid'] = $uid; $postarray['wall'] = 0; $postarray['uri'] = $post->object->id; - $postarray['object-type'] = Activity\Namespaces::ACTIVITY_SCHEMA.strtolower($post->object->objectType); + $postarray['object-type'] = Activity\ANamespace::ACTIVITY_SCHEMA . strtolower($post->object->objectType); if ($post->object->objectType != "comment") { $contact_id = pumpio_get_contact($uid, $post->actor); -- 2.45.2 From 9bd0609625e005df17dca72bbd408493bcf3e4e0 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Fri, 25 Oct 2019 00:10:19 +0200 Subject: [PATCH 4/9] Add docs --- pumpio/pumpio.php | 4 ++-- statusnet/statusnet.php | 8 ++++---- twitter/twitter.php | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 7a37f5f4..589764fe 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -997,11 +997,11 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = $objauthor = '[url=' . $orig_post['author-link'] . ']' . $orig_post['author-name'] . '[/url]'; $post_type = L10n::t('status'); $plink = '[url=' . $orig_post['plink'] . ']' . $post_type . '[/url]'; - $likedata['object-type'] = Activity::OBJ_NOTE; + $likedata['object-type'] = Activity\ObjectType::NOTE; $likedata['body'] = L10n::t('%1$s likes %2$s\'s %3$s', $author, $objauthor, $plink); - $likedata['object'] = '' . Activity::OBJ_NOTE . '1' . + $likedata['object'] = '' . Activity\ObjectType::NOTE . '1' . '' . $orig_post['uri'] . '' . XML::escape('') . '' . $orig_post['title'] . '' . $orig_post['body'] . ''; $ret = Item::insert($likedata); diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index f78252ff..fee8fd82 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -36,6 +36,7 @@ define('STATUSNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes require_once __DIR__ . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'statusnetoauth.php'; + use CodebirdSN\CodebirdSN; use Friendica\App; use Friendica\Content\OEmbed; @@ -48,7 +49,6 @@ use Friendica\Core\Logger; use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Group; @@ -1140,11 +1140,11 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $postarray['thr-parent'] = $item['uri']; $postarray['parent-uri'] = $item['parent-uri']; $postarray['parent'] = $item['parent']; - $postarray['object-type'] = Activity::OBJ_COMMENT; + $postarray['object-type'] = Activity\ObjectType::COMMENT; } else { $postarray['thr-parent'] = $postarray['uri']; $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = Activity::OBJ_NOTE; + $postarray['object-type'] = Activity\ObjectType::NOTE; } // Is it me? @@ -1168,7 +1168,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $create_user = false; } else { $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = Activity::OBJ_NOTE; + $postarray['object-type'] = Activity\ObjectType::NOTE; } if ($contactid == 0) { diff --git a/twitter/twitter.php b/twitter/twitter.php index 9a2aea75..11f21a89 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -1341,7 +1341,7 @@ function twitter_media_entities($post, array &$postarray) $media[$medium->url] .= "\n[img]" . $medium->media_url_https . '[/img]'; } - $postarray['object-type'] = Activity::OBJ_IMAGE; + $postarray['object-type'] = Activity\ObjectType::IMAGE; break; case 'video': case 'animated_gif': @@ -1352,7 +1352,7 @@ function twitter_media_entities($post, array &$postarray) $media[$medium->url] .= "\n[img]" . $medium->media_url_https . '[/img]'; } - $postarray['object-type'] = Activity::OBJ_VIDEO; + $postarray['object-type'] = Activity\ObjectType::VIDEO; if (is_array($medium->video_info->variants)) { $bitrate = 0; // We take the video with the highest bitrate @@ -1409,11 +1409,11 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl $postarray['thr-parent'] = $parent_item['uri']; $postarray['parent-uri'] = $parent_item['parent-uri']; $postarray['parent'] = $parent_item['parent']; - $postarray['object-type'] = Activity::OBJ_COMMENT; + $postarray['object-type'] = Activity\ObjectType::COMMENT; } else { $postarray['thr-parent'] = $postarray['uri']; $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = Activity::OBJ_NOTE; + $postarray['object-type'] = Activity\ObjectType::NOTE; } // Is it me? @@ -1438,7 +1438,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl $create_user = false; } else { $postarray['parent-uri'] = $postarray['uri']; - $postarray['object-type'] = Activity::OBJ_NOTE; + $postarray['object-type'] = Activity\ObjectType::NOTE; } if ($contactid == 0) { @@ -1481,7 +1481,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl // When the post contains links then use the correct object type if (count($post->entities->urls) > 0) { - $postarray['object-type'] = Activity::OBJ_BOOKMARK; + $postarray['object-type'] = Activity\ObjectType::BOOKMARK; } // Search for media links @@ -1521,7 +1521,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl // CHange the other post into a reshare activity $postarray['verb'] = Activity::ANNOUNCE; $postarray['gravity'] = GRAVITY_ACTIVITY; - $postarray['object-type'] = Activity::OBJ_NOTE; + $postarray['object-type'] = Activity\ObjectType::NOTE; $postarray['thr-parent'] = $retweet['uri']; $postarray['parent-uri'] = $retweet['uri']; -- 2.45.2 From 2c5fe26ae92c45d1705fe307a23952fc6edd0891 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Fri, 25 Oct 2019 00:32:35 +0200 Subject: [PATCH 5/9] Renamed to ActivityNamespace --- pumpio/pumpio.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 589764fe..43228f71 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -561,8 +561,8 @@ function pumpio_send(App $a, array &$b) $inReplyTo = ["id" => $orig_post["uri"], "objectType" => "note"]; - if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\ANamespace::ACTIVITY_SCHEMA))) { - $inReplyTo["objectType"] = str_replace(Activity\ANamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); + if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\ActivityNamespace::ACTIVITY_SCHEMA))) { + $inReplyTo["objectType"] = str_replace(Activity\ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); } $params["object"] = [ @@ -637,8 +637,8 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") $uri = $orig_post["uri"]; } - if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\ANamespace::ACTIVITY_SCHEMA))) { - $objectType = str_replace(Activity\ANamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); + if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\ActivityNamespace::ACTIVITY_SCHEMA))) { + $objectType = str_replace(Activity\ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); } elseif (strstr($uri, "/api/comment/")) { $objectType = "comment"; } elseif (strstr($uri, "/api/note/")) { @@ -1148,7 +1148,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp $postarray['uid'] = $uid; $postarray['wall'] = 0; $postarray['uri'] = $post->object->id; - $postarray['object-type'] = Activity\ANamespace::ACTIVITY_SCHEMA . strtolower($post->object->objectType); + $postarray['object-type'] = Activity\ActivityNamespace::ACTIVITY_SCHEMA . strtolower($post->object->objectType); if ($post->object->objectType != "comment") { $contact_id = pumpio_get_contact($uid, $post->actor); -- 2.45.2 From 65250b3fa505a050e10a8dac18c968f22bbd25c5 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Fri, 25 Oct 2019 00:34:46 +0200 Subject: [PATCH 6/9] Move Namespace of ActivityNamespace --- pumpio/pumpio.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 43228f71..7075873f 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -561,8 +561,8 @@ function pumpio_send(App $a, array &$b) $inReplyTo = ["id" => $orig_post["uri"], "objectType" => "note"]; - if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\ActivityNamespace::ACTIVITY_SCHEMA))) { - $inReplyTo["objectType"] = str_replace(Activity\ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); + if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], ActivityNamespace::ACTIVITY_SCHEMA))) { + $inReplyTo["objectType"] = str_replace(ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); } $params["object"] = [ @@ -637,8 +637,8 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") $uri = $orig_post["uri"]; } - if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\ActivityNamespace::ACTIVITY_SCHEMA))) { - $objectType = str_replace(Activity\ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); + if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], ActivityNamespace::ACTIVITY_SCHEMA))) { + $objectType = str_replace(ActivityNamespace::ACTIVITY_SCHEMA, '', $orig_post["object-type"]); } elseif (strstr($uri, "/api/comment/")) { $objectType = "comment"; } elseif (strstr($uri, "/api/note/")) { @@ -1148,7 +1148,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp $postarray['uid'] = $uid; $postarray['wall'] = 0; $postarray['uri'] = $post->object->id; - $postarray['object-type'] = Activity\ActivityNamespace::ACTIVITY_SCHEMA . strtolower($post->object->objectType); + $postarray['object-type'] = ActivityNamespace::ACTIVITY_SCHEMA . strtolower($post->object->objectType); if ($post->object->objectType != "comment") { $contact_id = pumpio_get_contact($uid, $post->actor); -- 2.45.2 From e92a154a6cfa1a105037796c2106bc5178b4b340 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Fri, 25 Oct 2019 00:41:37 +0200 Subject: [PATCH 7/9] Move Namespace of ActivityNamespace --- pumpio/pumpio.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 7075873f..e8b740c2 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -22,6 +22,7 @@ use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\User; use Friendica\Protocol\Activity; +use Friendica\Protocol\ActivityNamespace; use Friendica\Util\ConfigFileLoader; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; -- 2.45.2 From d53d690f0dc42d2208b813693e40a058c40711e1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 26 Oct 2019 18:31:45 +0000 Subject: [PATCH 8/9] Added logging to twitter addon --- twitter/twitter.php | 47 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/twitter/twitter.php b/twitter/twitter.php index a43e8358..c4a1a57e 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -109,7 +109,7 @@ function twitter_install() Hook::register('expire' , __FILE__, 'twitter_expire'); Hook::register('prepare_body' , __FILE__, 'twitter_prepare_body'); Hook::register('check_item_notification', __FILE__, 'twitter_check_item_notification'); - Logger::log("installed twitter"); + Logger::info("installed twitter"); } function twitter_uninstall() @@ -154,7 +154,7 @@ function twitter_check_item_notification(App $a, array &$notification_data) function twitter_follow(App $a, array &$contact) { - Logger::log("twitter_follow: Check if contact is twitter contact. " . $contact["url"], Logger::DEBUG); + Logger::info('Check if contact is twitter contact', ['url' => $contact["url"]]); if (!strstr($contact["url"], "://twitter.com") && !strstr($contact["url"], "@twitter.com")) { return; @@ -239,7 +239,7 @@ function twitter_settings_post(App $a) } else { if (isset($_POST['twitter-pin'])) { // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen - Logger::log('got a Twitter PIN'); + Logger::notice('got a Twitter PIN'); $ckey = Config::get('twitter', 'consumerkey'); $csecret = Config::get('twitter', 'consumersecret'); // the token and secret for which the PIN was generated were hidden in the settings @@ -428,7 +428,7 @@ function twitter_hook_fork(App $a, array &$b) if (PConfig::get($post['uid'], 'twitter', 'import')) { // Don't fork if it isn't a reply to a twitter post if (($post['parent'] != $post['id']) && !Item::exists(['id' => $post['parent'], 'network' => Protocol::TWITTER])) { - Logger::log('No twitter parent found for item ' . $post['id']); + Logger::notice('No twitter parent found', ['item' => $post['id']]); $b['execute'] = false; return; } @@ -623,7 +623,7 @@ function twitter_post_hook(App $a, array &$b) $b['body'] = twitter_update_mentions($b['body']); $msgarr = ItemContent::getPlaintextPost($b, $max_char, true, 8); - Logger::info('Got plaintext', $msgarr); + Logger::info('Got plaintext', ['id' => $b['id'], 'message' => $msgarr]); $msg = $msgarr["text"]; if (($msg == "") && isset($msgarr["title"])) { @@ -640,6 +640,7 @@ function twitter_post_hook(App $a, array &$b) } if (empty($msg)) { + Logger::info('Empty message', ['id' => $b['id']]); return; } @@ -647,6 +648,7 @@ function twitter_post_hook(App $a, array &$b) $post = []; if (!empty($msgarr['images'])) { + Logger::info('Got images', ['id' => $b['id'], 'images' => $msgarr['images']]); try { $media_ids = []; foreach ($msgarr['images'] as $image) { @@ -659,6 +661,7 @@ function twitter_post_hook(App $a, array &$b) $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); + Logger::info('Uploading', ['id' => $b['id'], 'image' => $image['url']]); $media = $connection->upload('media/upload', ['media' => $tempfile]); unlink($tempfile); @@ -670,10 +673,10 @@ function twitter_post_hook(App $a, array &$b) $data = ['media_id' => $media->media_id_string, 'alt_text' => ['text' => substr($image['description'], 0, 420)]]; $ret = $cb->media_metadata_create($data); - Logger::info('Metadata create', ['data' => $data, 'return' => json_encode($ret)]); + Logger::info('Metadata create', ['id' => $b['id'], 'data' => $data, 'return' => json_encode($ret)]); } } else { - throw new Exception('Failed upload of ' . $image['url']); + throw new Exception('Failed upload', ['id' => $b['id'], 'image' => $image['url']]); } } $post['media_ids'] = implode(',', $media_ids); @@ -681,7 +684,7 @@ function twitter_post_hook(App $a, array &$b) unset($post['media_ids']); } } catch (Exception $e) { - Logger::log('Exception when trying to send to Twitter: ' . $e->getMessage()); + Logger::info('Exception when trying to send to Twitter', ['id' => $b['id'], 'message' => $e->getMessage()]); } } @@ -693,17 +696,17 @@ function twitter_post_hook(App $a, array &$b) $url = 'statuses/update'; $result = $connection->post($url, $post); - Logger::log('twitter_post send, result: ' . print_r($result, true), Logger::DEBUG); + Logger::info('twitter_post send', ['id' => $b['id'], 'result' => $result]); if (!empty($result->source)) { Config::set("twitter", "application_name", strip_tags($result->source)); } if (!empty($result->errors)) { - Logger::log('Send to Twitter failed: "' . print_r($result->errors, true) . '"'); + Logger::info('Send to Twitter failed', ['id' => $b['id'], 'error' => $result->errors]); Worker::defer(); } elseif ($iscomment) { - Logger::log('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']); + Logger::info('Update extid', ['id' => $b['id'], 'extid' => $result->id_str]); Item::update(['extid' => "twitter::" . $result->id_str], ['id' => $b['id']]); } } @@ -742,16 +745,16 @@ function twitter_cron(App $a) if ($last) { $next = $last + ($poll_interval * 60); if ($next > time()) { - Logger::log('twitter: poll intervall not reached'); + Logger::notice('twitter: poll intervall not reached'); return; } } - Logger::log('twitter: cron_start'); + Logger::notice('twitter: cron_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'mirror_posts' AND `v` = '1'"); if (DBA::isResult($r)) { foreach ($r as $rr) { - Logger::log('twitter: fetching for user ' . $rr['uid']); + Logger::notice('Fetching', ['user' => $rr['uid']]); Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], "addon/twitter/twitter_sync.php", 1, (int) $rr['uid']); } } @@ -769,12 +772,12 @@ function twitter_cron(App $a) if ($abandon_days != 0) { $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); if (!DBA::isResult($user)) { - Logger::log('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported'); + Logger::notice('abandoned account: timeline from user will not be imported', ['user' => $rr['uid']]); continue; } } - Logger::log('twitter: importing timeline from user ' . $rr['uid']); + Logger::notice('importing timeline', ['user' => $rr['uid']]); Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], "addon/twitter/twitter_sync.php", 2, (int) $rr['uid']); /* // To-Do @@ -793,7 +796,7 @@ function twitter_cron(App $a) } } - Logger::log('twitter: cron_end'); + Logger::notice('twitter: cron_end'); Config::set('twitter', 'last_poll', time()); } @@ -812,17 +815,17 @@ function twitter_expire(App $a) } DBA::close($r); - Logger::log('twitter_expire: expire_start'); + Logger::notice('twitter_expire: expire_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); if (DBA::isResult($r)) { foreach ($r as $rr) { - Logger::log('twitter_expire: user ' . $rr['uid']); + Logger::notice('twitter_expire', ['user' => $rr['uid']]); Item::expire($rr['uid'], $days, Protocol::TWITTER, true); } } - Logger::log('twitter_expire: expire_end'); + Logger::notice('twitter_expire: expire_end'); } function twitter_prepare_body(App $a, array &$b) @@ -956,12 +959,12 @@ function twitter_fetchtimeline(App $a, $uid) try { $items = $connection->get('statuses/user_timeline', $parameters); } catch (TwitterOAuthException $e) { - Logger::log('Error fetching timeline for user ' . $uid . ': ' . $e->getMessage()); + Logger::notice('Error fetching timeline', ['user' => $uid, 'message' => $e->getMessage()]); return; } if (!is_array($items)) { - Logger::log('No items for user ' . $uid, Logger::INFO); + Logger::notice('No items', ['user' => $uid]); return; } -- 2.45.2 From 1137b703ed89bbcd6d1e8b58b8914e6d453012bc Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 28 Oct 2019 18:16:09 +0100 Subject: [PATCH 9/9] Check null for acl-fields --- remote_permissions/remote_permissions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/remote_permissions/remote_permissions.php b/remote_permissions/remote_permissions.php index ad6d7b25..6c25df27 100644 --- a/remote_permissions/remote_permissions.php +++ b/remote_permissions/remote_permissions.php @@ -128,10 +128,10 @@ function remote_permissions_content($a, $item_copy) { /** @var ACLFormatter $aclFormatter */ $aclFormatter = BaseObject::getClass(ACLFormatter::class); - $allowed_users = $aclFormatter->expand($item['allow_cid']); - $allowed_groups = $aclFormatter->expand($item['allow_gid']); - $deny_users = $aclFormatter->expand($item['deny_cid']); - $deny_groups = $aclFormatter->expand($item['deny_gid']); + $allowed_users = $aclFormatter->expand($item['allow_cid'] ?? ''); + $allowed_groups = $aclFormatter->expand($item['allow_gid'] ?? ''); + $deny_users = $aclFormatter->expand($item['deny_cid'] ?? ''); + $deny_groups = $aclFormatter->expand($item['deny_gid'] ?? ''); $o = L10n::t('Visible to:') . '
'; $allow = []; -- 2.45.2