]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Processor.php
Merge remote-tracking branch 'upstream/develop' into http-417
[friendica.git] / src / Protocol / ActivityPub / Processor.php
index dadadecde9af1c97789404cce9d51292a2f64df6..50e8dd91e8f5ec6726750d263c4ca99b341a2812 100644 (file)
@@ -75,7 +75,7 @@ class Processor
 
                $tag_text = '';
                foreach ($tags as $tag) {
-                       if (in_array(defaults($tag, 'type', ''), ['Mention', 'Hashtag'])) {
+                       if (in_array($tag['type'] ?? '', ['Mention', 'Hashtag'])) {
                                if (!empty($tag_text)) {
                                        $tag_text .= ',';
                                }
@@ -111,7 +111,11 @@ class Processor
                                        continue;
                                }
 
-                               $item['body'] .= "\n[img]" . $attach['url'] . '[/img]';
+                               if (empty($attach['name'])) {
+                                       $item['body'] .= "\n[img]" . $attach['url'] . '[/img]';
+                               } else {
+                                       $item['body'] .= "\n[img=" . $attach['url'] . ']' . $attach['name'] . '[/img]';
+                               }
                        } else {
                                if (!empty($item["attach"])) {
                                        $item["attach"] .= ',';
@@ -121,7 +125,7 @@ class Processor
                                if (!isset($attach['length'])) {
                                        $attach['length'] = "0";
                                }
-                               $item["attach"] .= '[attach]href="'.$attach['url'].'" length="'.$attach['length'].'" type="'.$attach['mediaType'].'" title="'.defaults($attach, 'name', '').'"[/attach]';
+                               $item["attach"] .= '[attach]href="'.$attach['url'].'" length="'.$attach['length'].'" type="'.$attach['mediaType'].'" title="'.($attach['name'] ?? '') .'"[/attach]';
                        }
                }
 
@@ -179,7 +183,7 @@ class Processor
                        self::fetchMissingActivity($activity['reply-to-id'], $activity);
                }
 
-               $item['diaspora_signed_text'] = defaults($activity, 'diaspora:comment', '');
+               $item['diaspora_signed_text'] = $activity['diaspora:comment'] ?? '';
 
                self::postItem($activity, $item);
        }
@@ -252,7 +256,7 @@ class Processor
                $item['gravity'] = GRAVITY_ACTIVITY;
                $item['object-type'] = ACTIVITY_OBJ_NOTE;
 
-               $item['diaspora_signed_text'] = defaults($activity, 'diaspora:like', '');
+               $item['diaspora_signed_text'] = $activity['diaspora:like'] ?? '';
 
                self::postItem($activity, $item);
        }
@@ -400,7 +404,7 @@ class Processor
                        return;
                }
 
-               $item['plink'] = defaults($activity, 'alternate-url', $item['uri']);
+               $item['plink'] = $activity['alternate-url'] ?? $item['uri'];
 
                $item = self::constructAttachList($activity['attachments'], $item, !empty($activity['source']));
 
@@ -411,9 +415,7 @@ class Processor
 
                        if ($isForum) {
                                $item['contact-id'] = Contact::getIdForURL($activity['actor'], $receiver, true);
-                       }
-
-                       if (empty($item['contact-id'])) {
+                       } else {
                                $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true);
                        }
 
@@ -581,8 +583,8 @@ class Processor
                $activity['@context'] = $object['@context'];
                unset($object['@context']);
                $activity['id'] = $object['id'];
-               $activity['to'] = defaults($object, 'to', []);
-               $activity['cc'] = defaults($object, 'cc', []);
+               $activity['to'] = $object['to'] ?? [];
+               $activity['cc'] = $object['cc'] ?? [];
                $activity['actor'] = $actor;
                $activity['object'] = $object;
                $activity['published'] = $published;
@@ -626,7 +628,7 @@ class Processor
                $item = ['author-id' => Contact::getIdForURL($activity['actor']),
                        'author-link' => $activity['actor']];
 
-               $note = Strings::escapeTags(trim(defaults($activity, 'content', '')));
+               $note = Strings::escapeTags(trim($activity['content'] ?? ''));
 
                // Ensure that the contact has got the right network type
                self::switchContact($item['author-id']);
@@ -891,7 +893,7 @@ class Processor
 
                // Extract one prepended mention at a time from the body
                while(preg_match('#^(@\[url=([^\]]+)].*?\[\/url]\s)(.*)#is', $body, $matches)) {
-                       if (!in_array($matches[2], $potential_mentions) ) {
+                       if (!in_array($matches[2], $potential_mentions)) {
                                $kept_mentions[] = $matches[1];
                        }