From feab53b58bd51f105c4c97a53914d7ad182c5e3c Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 17 Jul 2021 04:32:46 +0000 Subject: [PATCH 1/4] Issue 10506: Fix for multiple picture posts --- src/Model/Post/Media.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index 90f42a459..c0f09b8b9 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -224,7 +224,7 @@ class Media /** * Fetch media data from local resources - * @param array $media + * @param array $media * @return array media with added data */ private static function fetchLocalData(array $media) @@ -388,7 +388,7 @@ class Media foreach ($attachments as $attachment) { // Only store attachments that are part of the unshared body - if (Item::containsLink($unshared_body, $attachment['url'], $attachment['type'])) { + if (Item::containsLink($unshared_body, $attachment['preview'] ?? $attachment['url'], $attachment['type'])) { self::insert($attachment); } } From dd2abf254d1d0113eb8bb7221794a62bd76a5296 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 17 Jul 2021 07:55:19 +0000 Subject: [PATCH 2/4] Issue 10506 - again. Improved check for pictured in body --- src/Model/Item.php | 2 +- src/Model/Post/Media.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 86b9270fe..b258e8647 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2883,7 +2883,7 @@ class Item // @todo In the future we should make a single for the template engine with all media in it. This allows more flexibilty. foreach ($attachments['visual'] as $attachment) { - if (self::containsLink($item['body'], $attachment['url'], $attachment['type'])) { + if (self::containsLink($item['body'], $attachment['preview'] ?? $attachment['url'], $attachment['type'])) { continue; } diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index c0f09b8b9..801f192e9 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -637,7 +637,7 @@ class Media $body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body); foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) { - if (Item::containsLink($body, $media['url'], $media['type'])) { + if (Item::containsLink($body, $media['preview'] ?? $media['url'], $media['type'])) { continue; } From ea056b93fa30c7cde7f722a8ef111382d11ef544 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 17 Jul 2021 20:27:18 +0000 Subject: [PATCH 3/4] Fix notice in events --- src/Model/Item.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index b258e8647..33bd861cc 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1033,9 +1033,9 @@ class Item $ev['guid'] = $item['guid']; $ev['plink'] = $item['plink']; $ev['network'] = $item['network']; - $ev['protocol'] = $item['protocol']; - $ev['direction'] = $item['direction']; - $ev['source'] = $item['source']; + $ev['protocol'] = $item['protocol'] ?? Conversation::PARCEL_UNKNOWN; + $ev['direction'] = $item['direction'] ?? Conversation::UNKNOWN; + $ev['source'] = $item['source'] ?? ''; $event = DBA::selectFirst('event', ['id'], ['uri' => $item['uri'], 'uid' => $item['uid']]); if (DBA::isResult($event)) { From f62f82df75ef96b8c8c09e5a9d3c090b00d352ac Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 17 Jul 2021 20:28:46 +0000 Subject: [PATCH 4/4] Move ActivityPub endpoints to an AP class --- src/Module/{ => ActivityPub}/Followers.php | 10 ++---- src/Module/{ => ActivityPub}/Following.php | 11 ++----- src/Module/{ => ActivityPub}/Inbox.php | 13 +++----- src/Module/{ => ActivityPub}/Objects.php | 2 +- src/Module/{ => ActivityPub}/Outbox.php | 10 ++---- src/Protocol/ActivityPub/Transmitter.php | 20 ++++++------ static/routes.config.php | 36 +++++++++++----------- 7 files changed, 43 insertions(+), 59 deletions(-) rename src/Module/{ => ActivityPub}/Followers.php (88%) rename src/Module/{ => ActivityPub}/Following.php (86%) rename src/Module/{ => ActivityPub}/Inbox.php (81%) rename src/Module/{ => ActivityPub}/Objects.php (99%) rename src/Module/{ => ActivityPub}/Outbox.php (88%) diff --git a/src/Module/Followers.php b/src/Module/ActivityPub/Followers.php similarity index 88% rename from src/Module/Followers.php rename to src/Module/ActivityPub/Followers.php index 932ebb47c..e1f1ccc4c 100644 --- a/src/Module/Followers.php +++ b/src/Module/ActivityPub/Followers.php @@ -19,10 +19,9 @@ * */ -namespace Friendica\Module; +namespace Friendica\Module\ActivityPub; use Friendica\BaseModule; -use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\User; use Friendica\Protocol\ActivityPub; @@ -34,15 +33,12 @@ class Followers extends BaseModule { public static function rawContent(array $parameters = []) { - $a = DI::app(); - - // @TODO: Replace with parameter from router - if (empty($a->argv[1])) { + if (empty($parameters['nickname'])) { throw new \Friendica\Network\HTTPException\NotFoundException(); } // @TODO: Replace with parameter from router - $owner = User::getOwnerDataByNick($a->argv[1]); + $owner = User::getOwnerDataByNick($parameters['nickname']); if (empty($owner)) { throw new \Friendica\Network\HTTPException\NotFoundException(); } diff --git a/src/Module/Following.php b/src/Module/ActivityPub/Following.php similarity index 86% rename from src/Module/Following.php rename to src/Module/ActivityPub/Following.php index 3070c5bfe..e9cb10be1 100644 --- a/src/Module/Following.php +++ b/src/Module/ActivityPub/Following.php @@ -19,10 +19,9 @@ * */ -namespace Friendica\Module; +namespace Friendica\Module\ActivityPub; use Friendica\BaseModule; -use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\User; use Friendica\Protocol\ActivityPub; @@ -34,15 +33,11 @@ class Following extends BaseModule { public static function rawContent(array $parameters = []) { - $a = DI::app(); - - // @TODO: Replace with parameter from router - if (empty($a->argv[1])) { + if (empty($parameters['nickname'])) { throw new \Friendica\Network\HTTPException\NotFoundException(); } - // @TODO: Replace with parameter from router - $owner = User::getOwnerDataByNick($a->argv[1]); + $owner = User::getOwnerDataByNick($parameters['nickname']); if (empty($owner)) { throw new \Friendica\Network\HTTPException\NotFoundException(); } diff --git a/src/Module/Inbox.php b/src/Module/ActivityPub/Inbox.php similarity index 81% rename from src/Module/Inbox.php rename to src/Module/ActivityPub/Inbox.php index 048edb5d0..36940cb2d 100644 --- a/src/Module/Inbox.php +++ b/src/Module/ActivityPub/Inbox.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Module; +namespace Friendica\Module\ActivityPub; use Friendica\BaseModule; use Friendica\Core\Logger; @@ -36,8 +36,6 @@ class Inbox extends BaseModule { public static function rawContent(array $parameters = []) { - $a = DI::app(); - $postdata = Network::postdata(); if (empty($postdata)) { @@ -51,13 +49,12 @@ class Inbox extends BaseModule $filename = 'failed-activitypub'; } $tempfile = tempnam(get_temppath(), $filename); - file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); - Logger::log('Incoming message stored under ' . $tempfile); + file_put_contents($tempfile, json_encode(['parameters' => $parameters, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); + Logger::notice('Incoming message stored', ['file' => $tempfile]); } - // @TODO: Replace with parameter from router - if (!empty($a->argv[1])) { - $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]); + if (!empty($parameters['nickname'])) { + $user = DBA::selectFirst('user', ['uid'], ['nickname' => $parameters['nickname']]); if (!DBA::isResult($user)) { throw new \Friendica\Network\HTTPException\NotFoundException(); } diff --git a/src/Module/Objects.php b/src/Module/ActivityPub/Objects.php similarity index 99% rename from src/Module/Objects.php rename to src/Module/ActivityPub/Objects.php index 8f1bbf2a5..f597b0905 100644 --- a/src/Module/Objects.php +++ b/src/Module/ActivityPub/Objects.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Module; +namespace Friendica\Module\ActivityPub; use Friendica\BaseModule; use Friendica\Core\Logger; diff --git a/src/Module/Outbox.php b/src/Module/ActivityPub/Outbox.php similarity index 88% rename from src/Module/Outbox.php rename to src/Module/ActivityPub/Outbox.php index 6e095b730..fe838960d 100644 --- a/src/Module/Outbox.php +++ b/src/Module/ActivityPub/Outbox.php @@ -19,10 +19,9 @@ * */ -namespace Friendica\Module; +namespace Friendica\Module\ActivityPub; use Friendica\BaseModule; -use Friendica\DI; use Friendica\Model\User; use Friendica\Protocol\ActivityPub; use Friendica\Util\HTTPSignature; @@ -34,14 +33,11 @@ class Outbox extends BaseModule { public static function rawContent(array $parameters = []) { - $a = DI::app(); - - // @TODO: Replace with parameter from router - if (empty($a->argv[1])) { + if (empty($parameters['nickname'])) { throw new \Friendica\Network\HTTPException\NotFoundException(); } - $owner = User::getOwnerDataByNick($a->argv[1]); + $owner = User::getOwnerDataByNick($parameters['nickname']); if (empty($owner)) { throw new \Friendica\Network\HTTPException\NotFoundException(); } diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index a65f85542..a65ebc8cd 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -235,26 +235,28 @@ class Transmitter */ public static function getOutbox($owner, $page = null, $requester = '') { - $public_contact = Contact::getIdForURL($owner['url']); - $condition = ['uid' => 0, 'contact-id' => $public_contact, - 'private' => [Item::PUBLIC, Item::UNLISTED]]; + $condition = ['private' => [Item::PUBLIC, Item::UNLISTED]]; if (!empty($requester)) { $requester_id = Contact::getIdForURL($requester, $owner['uid']); if (!empty($requester_id)) { $permissionSets = DI::permissionSet()->selectByContactId($requester_id, $owner['uid']); if (!empty($permissionSets)) { - $condition = ['uid' => $owner['uid'], 'origin' => true, - 'psid' => array_merge($permissionSets->column('id'), + $condition = ['psid' => array_merge($permissionSets->column('id'), [DI::permissionSet()->getIdFromACL($owner['uid'], '', '', '', '')])]; } } } $condition = array_merge($condition, - ['author-id' => $public_contact, - 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], - 'deleted' => false, 'visible' => true]); + ['uid' => $owner['uid'], + 'author-id' => Contact::getIdForURL($owner['url'], 0, false), + 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], + 'network' => Protocol::FEDERATED, + 'parent-network' => Protocol::FEDERATED, + 'origin' => true, + 'deleted' => false, + 'visible' => true]); $count = Post::count($condition); @@ -269,8 +271,6 @@ class Transmitter $data['type'] = 'OrderedCollectionPage'; $list = []; - $condition['parent-network'] = Protocol::NATIVE_SUPPORT; - $items = Post::select(['id'], $condition, ['limit' => [($page - 1) * 20, 20], 'order' => ['created' => true]]); while ($item = Post::fetch($items)) { $activity = self::createActivityFromItem($item['id'], true); diff --git a/static/routes.config.php b/static/routes.config.php index dfa7dad18..64a434665 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -266,14 +266,14 @@ return [ '/status_message/{guid}' => [Module\Diaspora\Fetch::class, [R::GET]], '/reshare/{guid}' => [Module\Diaspora\Fetch::class, [R::GET]], ], - '/filed' => [Module\Search\Filed::class, [R::GET]], - '/filer[/{id:\d+}]' => [Module\Filer\SaveTag::class, [R::GET]], - '/filerm/{id:\d+}' => [Module\Filer\RemoveTag::class, [R::GET]], - '/follow_confirm' => [Module\FollowConfirm::class, [R::GET, R::POST]], - '/followers/{owner}' => [Module\Followers::class, [R::GET]], - '/following/{owner}' => [Module\Following::class, [R::GET]], - '/friendica[/json]' => [Module\Friendica::class, [R::GET]], - '/friendica/inbox' => [Module\Inbox::class, [R::GET, R::POST]], + '/filed' => [Module\Search\Filed::class, [R::GET]], + '/filer[/{id:\d+}]' => [Module\Filer\SaveTag::class, [R::GET]], + '/filerm/{id:\d+}' => [Module\Filer\RemoveTag::class, [R::GET]], + '/follow_confirm' => [Module\FollowConfirm::class, [R::GET, R::POST]], + '/followers/{nickname}' => [Module\ActivityPub\Followers::class, [R::GET]], + '/following/{nickname}' => [Module\ActivityPub\Following::class, [R::GET]], + '/friendica[/json]' => [Module\Friendica::class, [R::GET]], + '/friendica/inbox' => [Module\ActivityPub\Inbox::class, [R::GET, R::POST]], '/fsuggest/{contact:\d+}' => [Module\FriendSuggest::class, [R::GET, R::POST]], @@ -288,12 +288,12 @@ return [ '/{group:\d+}/add/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]], '/{group:\d+}/remove/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]], ], - '/hashtag' => [Module\Hashtag::class, [R::GET]], - '/help[/{doc:.+}]' => [Module\Help::class, [R::GET]], - '/home' => [Module\Home::class, [R::GET]], - '/hcard/{profile}[/{action}]' => [Module\HoverCard::class, [R::GET]], - '/inbox[/{nickname}]' => [Module\Inbox::class, [R::GET, R::POST]], - '/invite' => [Module\Invite::class, [R::GET, R::POST]], + '/hashtag' => [Module\Hashtag::class, [R::GET]], + '/help[/{doc:.+}]' => [Module\Help::class, [R::GET]], + '/home' => [Module\Home::class, [R::GET]], + '/hcard/{profile}[/{action}]' => [Module\HoverCard::class, [R::GET]], + '/inbox[/{nickname}]' => [Module\ActivityPub\Inbox::class, [R::GET, R::POST]], + '/invite' => [Module\Invite::class, [R::GET, R::POST]], '/install' => [ '[/]' => [Module\Install::class, [R::GET, R::POST]], @@ -355,10 +355,10 @@ return [ '/h2b' => [Module\Oembed::class, [R::GET]], '/{hash}' => [Module\Oembed::class, [R::GET]], ], - '/outbox/{owner}' => [Module\Outbox::class, [R::GET]], - '/owa' => [Module\Owa::class, [R::GET]], - '/openid' => [Module\Security\OpenID::class, [R::GET]], - '/opensearch' => [Module\OpenSearch::class, [R::GET]], + '/outbox/{nickname}' => [Module\ActivityPub\Outbox::class, [R::GET]], + '/owa' => [Module\Owa::class, [R::GET]], + '/openid' => [Module\Security\OpenID::class, [R::GET]], + '/opensearch' => [Module\OpenSearch::class, [R::GET]], '/parseurl' => [Module\ParseUrl::class, [R::GET]], '/permission/tooltip/{type}/{id:\d+}' => [Module\PermissionTooltip::class, [R::GET]],