]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Processor.php
Merge pull request #7092 from MrPetovan/task/7047-theme-error-page
[friendica.git] / src / Protocol / ActivityPub / Processor.php
index de17770601d839ead9ba88e830bf1b6a0ea1e163..3bb0639ab05cd349931475695d2115b03818cad0 100644 (file)
@@ -48,7 +48,7 @@ class Processor
         *
         * @return string with replaced emojis
         */
-       public static function replaceEmojis($body, array $emojis)
+       private static function replaceEmojis($body, array $emojis)
        {
                foreach ($emojis as $emoji) {
                        $replace = '[class=emoji mastodon][img=' . $emoji['href'] . ']' . $emoji['name'] . '[/img][/class]';
@@ -252,7 +252,7 @@ class Processor
         *
         * @param array $activity Activity array
         * @param array $item
-        * @return array
+        * @return array|bool Returns the item array or false if there was an unexpected occurrence
         * @throws \Exception
         */
        private static function processContent($activity, $item)
@@ -263,7 +263,11 @@ class Processor
                        $item['body'] = $activity['source'];
                } else {
                        $content = HTML::toBBCode($activity['content']);
-                       $content = self::replaceEmojis($content, $activity['emojis']);
+
+                       if (!empty($activity['emojis'])) {
+                               $content = self::replaceEmojis($content, $activity['emojis']);
+                       }
+
                        $content = self::convertMentions($content);
 
                        if (($item['thr-parent'] != $item['uri']) && ($item['gravity'] == GRAVITY_COMMENT)) {
@@ -450,7 +454,7 @@ class Processor
                $cid = Contact::getIdForURL($activity['actor'], $uid);
                if (!empty($cid)) {
                        self::switchContact($cid);
-                       DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]);
+                       DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
                        $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
                } else {
                        $contact = false;
@@ -459,17 +463,19 @@ class Processor
                $item = ['author-id' => Contact::getIdForURL($activity['actor']),
                        'author-link' => $activity['actor']];
 
+               $note = Strings::escapeTags(trim(defaults($activity, 'content', '')));
+
                // Ensure that the contact has got the right network type
                self::switchContact($item['author-id']);
 
-               Contact::addRelationship($owner, $contact, $item);
+               Contact::addRelationship($owner, $contact, $item, '', false, $note);
                $cid = Contact::getIdForURL($activity['actor'], $uid);
                if (empty($cid)) {
                        return;
                }
 
                if (empty($contact)) {
-                       DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]);
+                       DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
                }
 
                Logger::log('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
@@ -574,7 +580,7 @@ class Processor
 
                self::switchContact($cid);
 
-               if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING, 'pending' => true])) {
+               if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING])) {
                        Contact::remove($cid);
                        Logger::log('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', Logger::DEBUG);
                } else {
@@ -649,7 +655,7 @@ class Processor
        private static function switchContact($cid)
        {
                $contact = DBA::selectFirst('contact', ['network'], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
-               if (!DBA::isResult($contact) || ($contact['network'] == Protocol::ACTIVITYPUB)) {
+               if (!DBA::isResult($contact) || in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
                        return;
                }