]> git.mxchange.org Git - friendica.git/commitdiff
Add check for existing attachment in ActivityPub\Processor::constructAttachList
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 7 Jun 2020 20:23:57 +0000 (16:23 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 7 Jun 2020 20:23:57 +0000 (16:23 -0400)
src/Protocol/ActivityPub/Processor.php

index d6ef34f5f5201258f0989a723ef30d1728052eb8..0c60ca57d90a2f6f3d2b64610ad179d6bc4e472b 100644 (file)
@@ -96,7 +96,15 @@ class Processor
                foreach ($activity['attachments'] as $attach) {
                        switch ($attach['type']) {
                                case 'link':
-                                       $item['body'] .= "\n[attachment type='link' url='" . $attach['url'] . "' title='" . ($attach['title'] ?? '') . "' image='" . ($attach['image'] ?? '') . "']" . ($attach['desc'] ?? '') . '[/attachment]';
+                                       // Only one [attachment] tag is allowed
+                                       $existingAttachmentPos = strpos($item['body'], '[attachment');
+                                       if ($existingAttachmentPos !== false) {
+                                               $linkTitle = $attach['title'] ?: $attach['url'];
+                                               // Additional link attachments are prepended before the existing [attachment] tag
+                                               $item['body'] = substr_replace($item['body'], "\n[bookmark=" . $attach['url'] . ']' . $linkTitle . "[/bookmark]\n", $existingAttachmentPos, 0);
+                                       } else {
+                                               $item['body'] .= "\n[attachment type='link' url='" . $attach['url'] . "' title='" . ($attach['title'] ?? '') . "' image='" . ($attach['image'] ?? '') . "']" . ($attach['desc'] ?? '') . '[/attachment]';
+                                       }
                                        break;
                                default:
                                        $filetype = strtolower(substr($attach['mediaType'], 0, strpos($attach['mediaType'], '/')));