]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Fix possible fatal error when body is null
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index a65f85542296cc79a047f33db4b92fcdfde58946..20b8f2a26221f5bc766c5a4c06a8689e5c2bece5 100644 (file)
@@ -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);
@@ -1343,27 +1343,6 @@ class Transmitter
                return $attachments;
        }
 
-       /**
-        * Callback function to replace a Friendica style mention in a mention that is used on AP
-        *
-        * @param array $match Matching values for the callback
-        * @return string Replaced mention
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        */
-       private static function mentionCallback($match)
-       {
-               if (empty($match[1])) {
-                       return '';
-               }
-
-               $data = Contact::getByURL($match[1], false, ['url', 'alias', 'nick']);
-               if (empty($data['nick'])) {
-                       return $match[0];
-               }
-
-               return '[url=' . $data['url'] . ']@' . $data['nick'] . '[/url]';
-       }
-
        /**
         * Callback function to replace a Friendica style mention in a mention for a summary
         *
@@ -1568,8 +1547,7 @@ class Transmitter
                if ($type == 'Event') {
                        $data = array_merge($data, self::createEvent($item));
                } else {
-                       $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
-                       $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
+                       $body = BBCode::setMentionsToNicknames($body);
 
                        $data['content'] = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
                }
@@ -1579,8 +1557,7 @@ class Transmitter
                // The contentMap does contain the unmodified HTML.
                $language = self::getLanguage($item);
                if (!empty($language)) {
-                       $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
-                       $richbody = preg_replace_callback($regexp, ['self', 'mentionCallback'], $item['body']);
+                       $richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
                        $richbody = BBCode::removeAttachment($richbody);
 
                        $data['contentMap'][$language] = BBCode::convertForUriId($item['uri-id'], $richbody, BBCode::EXTERNAL);