]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Added field value
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index 6e639fb9896eb900ac10d6efd601998a68f2c326..6bf507ed8f8d614287847c9add52d0ea8dc4c4f0 100644 (file)
@@ -150,7 +150,7 @@ class Transmitter
         */
        public static function getOutbox($owner, $page = null)
        {
-               $public_contact = Contact::getIdForURL($owner['url'], 0, true);
+               $public_contact = Contact::getIdForURL($owner['url'], 0, false);
 
                $condition = ['uid' => 0, 'contact-id' => $public_contact, 'author-id' => $public_contact,
                        'private' => [Item::PUBLIC, Item::UNLISTED], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
@@ -729,7 +729,7 @@ class Transmitter
                        $data = [];
                }
 
-               $data['id'] = $mail['uri'] . '#Create';
+               $data['id'] = $mail['uri'] . '/Create';
                $data['type'] = 'Create';
                $data['actor'] = $mail['author-link'];
                $data['published'] = DateTimeFormat::utc($mail['created'] . '+00:00', DateTimeFormat::ATOM);
@@ -834,7 +834,7 @@ class Transmitter
                        }
                }
 
-               $data = ActivityPub\Transmitter::createActivityFromItem($item_id);
+               $data = self::createActivityFromItem($item_id);
 
                DI::cache()->set($cachekey, $data, Duration::QUARTER_HOUR);
                return $data;
@@ -863,8 +863,8 @@ class Transmitter
                                $type = 'Announce';
 
                                // Disguise forum posts as reshares. Will later be converted to a real announce
-                               $item['body'] = share_header($item['author-name'], $item['author-link'], $item['author-avatar'],
-                                       $item['guid'], $item['created'], $item['plink']) . $item['body'] . '[/share]';
+                               $item['body'] = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'],
+                                       $item['plink'], $item['created'], $item['guid']) . $item['body'] . '[/share]';
                        }
                }
 
@@ -873,8 +873,21 @@ class Transmitter
                        $conversation = DBA::selectFirst('conversation', ['source'], $condition);
                        if (DBA::isResult($conversation)) {
                                $data = json_decode($conversation['source'], true);
-                               if (!empty($data)) {
-                                       return $data;
+                               if (!empty($data['type'])) {
+                                       if (in_array($data['type'], ['Create', 'Update'])) {
+                                               if ($object_mode) {
+                                                       unset($data['@context']);
+                                                       unset($data['signature']);
+                                               }
+                                               return $data;
+                                       } elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
+                                               if (!empty($data['@context'])) {
+                                                       $context = $data['@context'];
+                                                       unset($data['@context']);
+                                               }
+                                               unset($data['actor']);
+                                               $object = $data;
+                                       }
                                }
                        }
 
@@ -882,7 +895,7 @@ class Transmitter
                }
 
                if (!$object_mode) {
-                       $data = ['@context' => ActivityPub::CONTEXT];
+                       $data = ['@context' => $context ?? ActivityPub::CONTEXT];
 
                        if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) {
                                $type = 'Undo';
@@ -893,7 +906,7 @@ class Transmitter
                        $data = [];
                }
 
-               $data['id'] = $item['uri'] . '#' . $type;
+               $data['id'] = $item['uri'] . '/' . $type;
                $data['type'] = $type;
 
                if (Item::isForumPost($item) && ($type != 'Announce')) {
@@ -909,7 +922,7 @@ class Transmitter
                $data = array_merge($data, self::createPermissionBlockForItem($item, false));
 
                if (in_array($data['type'], ['Create', 'Update', 'Delete'])) {
-                       $data['object'] = self::createNote($item);
+                       $data['object'] = $object ?? self::createNote($item);
                } elseif ($data['type'] == 'Add') {
                        $data = self::createAddTag($item, $data);
                } elseif ($data['type'] == 'Announce') {
@@ -995,7 +1008,7 @@ class Transmitter
                                $url = DI::baseUrl() . '/search?tag=' . urlencode($term['name']);
                                $tags[] = ['type' => 'Hashtag', 'href' => $url, 'name' => '#' . $term['name']];
                        } else {
-                               $contact = Contact::getDetailsByURL($term['url']);
+                               $contact = Contact::getByURL($term['url'], false, ['addr']);
                                if (!empty($contact['addr'])) {
                                        $mention = '@' . $contact['addr'];
                                } else {
@@ -1128,7 +1141,7 @@ class Transmitter
                        return '';
                }
 
-               $data = Contact::getDetailsByURL($match[1]);
+               $data = Contact::getByURL($match[1], false, ['url', 'nick']);
                if (empty($data['nick'])) {
                        return $match[0];
                }
@@ -1215,7 +1228,7 @@ class Transmitter
        {
                $event = [];
                $event['name'] = $item['event-summary'];
-               $event['content'] = BBCode::convert($item['event-desc'], false, 9);
+               $event['content'] = BBCode::convert($item['event-desc'], false, BBCode::ACTIVITYPUB);
                $event['startTime'] = DateTimeFormat::utc($item['event-start'] . '+00:00', DateTimeFormat::ATOM);
 
                if (!$item['event-nofinish']) {
@@ -1294,7 +1307,7 @@ class Transmitter
                $body = $item['body'];
 
                if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {
-                       $body = self::prependMentions($body, $permission_block);
+                       $body = self::prependMentions($body, $item['uri-id']);
                }
 
                if ($type == 'Note') {
@@ -1309,7 +1322,7 @@ class Transmitter
                        $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
                        $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
 
-                       $data['content'] = BBCode::convert($body, false, 9);
+                       $data['content'] = BBCode::convert($body, false, BBCode::ACTIVITYPUB);
                }
 
                // The regular "content" field does contain a minimized HTML. This is done since systems like
@@ -1843,22 +1856,18 @@ class Transmitter
                HTTPSignature::transmit($signed, $profile['inbox'], $uid);
        }
 
-       private static function prependMentions($body, array $permission_block)
+       private static function prependMentions($body, int $uriid)
        {
-               if (DI::config()->get('system', 'disable_implicit_mentions')) {
-                       return $body;
-               }
-
                $mentions = [];
 
-               foreach ($permission_block['to'] as $profile_url) {
-                       $profile = Contact::getDetailsByURL($profile_url);
+               foreach (Tag::getByURIId($uriid, [Tag::IMPLICIT_MENTION]) as $tag) {
+                       $profile = Contact::getByURL($tag['url'], false, ['addr', 'contact-type', 'nick']);
                        if (!empty($profile['addr'])
                                && $profile['contact-type'] != Contact::TYPE_COMMUNITY
                                && !strstr($body, $profile['addr'])
-                               && !strstr($body, $profile_url)
+                               && !strstr($body, $tag['url'])
                        ) {
-                               $mentions[] = '@[url=' . $profile_url . ']' . $profile['nick'] . '[/url]';
+                               $mentions[] = '@[url=' . $tag['url'] . ']' . $profile['nick'] . '[/url]';
                        }
                }