From 4d3dd28c44f16baa1c0c136577f549c5a1c3bbc1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 7 Jun 2020 16:23:57 -0400 Subject: [PATCH] Add check for existing attachment in ActivityPub\Processor::constructAttachList --- src/Protocol/ActivityPub/Processor.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index d6ef34f5f..0c60ca57d 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -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'], '/')));