]> git.mxchange.org Git - friendica.git/commitdiff
Issue 10232: Improved search for embedded media links
authorMichael <heluecht@pirati.ca>
Sun, 23 May 2021 12:35:05 +0000 (12:35 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 23 May 2021 12:35:05 +0000 (12:35 +0000)
src/Model/Item.php
src/Model/Post/Media.php

index e8044ecd7a93b7b469952118194167b62f675851..4dbea3eb8b73110593548afb5081ad0460e3f4ab 100644 (file)
@@ -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'],
index c3f745fee64fc9b020f4ba7ce2c8eb5132ead5e9..48bf435fabe2a01d5a5844d88ef066193ddb31e3 100644 (file)
@@ -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;
                        }