From 53b951a179254e4e8c8d515a9a520aa45eba5aef Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 10 Jun 2020 11:19:44 -0400 Subject: [PATCH] Strip the link preview URL from the end of the body if any in ActivityPub\Processor --- src/Protocol/ActivityPub/Processor.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 35d4626daa..02ea24224a 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -103,6 +103,9 @@ class Processor // 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 { + // Strip the link preview URL from the end of the body if any + $quotedUrl = preg_quote($attach['url'], '#'); + $item['body'] = preg_replace("#\s*(?:\[bookmark={$quotedUrl}].+?\[/bookmark]|\[url={$quotedUrl}].+?\[/url]|\[url]{$quotedUrl}\[/url]|{$quotedUrl})\s*$#", '', $item['body']); $item['body'] .= "\n[attachment type='link' url='" . $attach['url'] . "' title='" . htmlspecialchars($attach['title'] ?? '', ENT_QUOTES) . "' image='" . ($attach['image'] ?? '') . "']" . ($attach['desc'] ?? '') . '[/attachment]'; } break;