]> git.mxchange.org Git - friendica.git/commitdiff
Strip the link preview URL from the end of the body if any in ActivityPub\Processor
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 10 Jun 2020 15:19:44 +0000 (11:19 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 10 Jun 2020 15:19:44 +0000 (11:19 -0400)
src/Protocol/ActivityPub/Processor.php

index 35d4626daa6bbc08156a30fe4983dbb0c1f561c2..02ea24224af0183048006a47c5836e18bf019fcc 100644 (file)
@@ -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;