From 5a7bd4884a359c60e09e39538b870f5df23cad7e Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Sep 2021 20:26:08 +0000 Subject: [PATCH] Issue 10772: Avoid duplicated links in AP posts --- src/Content/Text/BBCode.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index b2fb1da7af..d0c19c616f 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -424,10 +424,12 @@ class BBCode public static function removeAttachment($body, $no_link_desc = false) { return preg_replace_callback("/\s*\[attachment (.*?)\](.*?)\[\/attachment\]\s*/ism", - function ($match) use ($no_link_desc) { + function ($match) use ($body, $no_link_desc) { $attach_data = self::getAttachmentData($match[0]); if (empty($attach_data['url'])) { return $match[0]; + } elseif (strpos(str_replace($match[0], '', $body), $attach_data['url']) !== false) { + return ''; } elseif (empty($attach_data['title']) || $no_link_desc) { return " \n[url]" . $attach_data['url'] . "[/url]\n"; } else {