diff --git a/src/Model/Item.php b/src/Model/Item.php index e8044ecd7..4dbea3eb8 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2739,9 +2739,10 @@ class Item * * @param string $body * @param string $url + * @param int $type * @return bool */ - public static function containsLink(string $body, string $url) + public static function containsLink(string $body, string $url, int $type = 0) { // Make sure that for example site parameters aren't used when testing if the link is contained in the body $urlparts = parse_url($url); @@ -2749,6 +2750,12 @@ class Item unset($urlparts['fragment']); $url = Network::unparseURL($urlparts); + // Remove media links to only search in embedded content + // @todo Check images for image link, audio for audio links, ... + if (in_array($type, [Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE])) { + $body = preg_replace("/\[url=[^\[\]]*\](.*)\[\/url\]/Usi", ' $1 ', $body); + } + if (strpos($body, $url)) { return true; } @@ -2777,7 +2784,7 @@ class Item // @todo In the future we should make a single for the template engine with all media in it. This allows more flexibilty. foreach ($attachments['visual'] as $attachment) { - if (self::containsLink($item['body'], $attachment['url'])) { + if (self::containsLink($item['body'], $attachment['url'], $attachment['type'])) { continue; } @@ -2955,7 +2962,7 @@ class Item // @todo Use a template $rendered = BBCode::convertAttachment('', BBCode::INTERNAL, false, $data); - } elseif (!self::containsLink($content, $data['url'])) { + } elseif (!self::containsLink($content, $data['url'], Post\Media::HTML)) { $rendered = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/link.tpl'), [ '$url' => $data['url'], '$title' => $data['title'], diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index c3f745fee..48bf435fa 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -600,7 +600,7 @@ class Media $body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body); foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) { - if (Item::containsLink($body, $media['url'])) { + if (Item::containsLink($body, $media['url'], $media['type'])) { continue; }