]> git.mxchange.org Git - friendica.git/commitdiff
Avoid duplicated attachments / unwanted attachments
authorMichael <heluecht@pirati.ca>
Wed, 5 May 2021 16:46:55 +0000 (16:46 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 5 May 2021 16:46:55 +0000 (16:46 +0000)
src/Content/Text/BBCode.php
src/Model/Item.php
src/Protocol/ActivityPub/Transmitter.php

index 137a6a5d1390a1ce4d32c2161a002131bf189720..1f04097bfedc3145215cd9e68ad3bbc0f771b340 100644 (file)
@@ -1893,7 +1893,7 @@ class BBCode
 
                $text = HTML::purify($text, $allowedIframeDomains);
 
-               return $text;
+               return trim($text);
        }
 
        /**
index e93708bfd29d469416c749ad9238f63ef2d3fe35..2544ed7813dc589200841bb97a0a8d83260faa1e 100644 (file)
@@ -2871,7 +2871,8 @@ class Item
                                                $found = true;
                                        }
                                }
-                               if (!$found) {
+                               // @todo Judge between the links to use the one with most information
+                               if (!$found && (empty($attachment) || empty($attachment['name']) || empty($attachment['description']))) {
                                        $attachment = $link;
                                }
                        }
index 4f8f48c153915997268048689fe968e4550f45d5..9773a5a48bbd1aa43ee7b511d2aefe6d263e1fbf 100644 (file)
@@ -1260,37 +1260,6 @@ class Transmitter
        {
                $attachments = [];
 
-               // Currently deactivated, since it creates side effects on Mastodon and Pleroma.
-               // It will be reactivated, once this cleared.
-               /*
-               $attach_data = BBCode::getAttachmentData($item['body']);
-               if (!empty($attach_data['url'])) {
-                       $attachment = ['type' => 'Page',
-                               'mediaType' => 'text/html',
-                               'url' => $attach_data['url']];
-
-                       if (!empty($attach_data['title'])) {
-                               $attachment['name'] = $attach_data['title'];
-                       }
-
-                       if (!empty($attach_data['description'])) {
-                               $attachment['summary'] = $attach_data['description'];
-                       }
-
-                       if (!empty($attach_data['image'])) {
-                               $imgdata = Images::getInfoFromURLCached($attach_data['image']);
-                               if ($imgdata) {
-                                       $attachment['icon'] = ['type' => 'Image',
-                                               'mediaType' => $imgdata['mime'],
-                                               'width' => $imgdata[0],
-                                               'height' => $imgdata[1],
-                                               'url' => $attach_data['image']];
-                               }
-                       }
-
-                       $attachments[] = $attachment;
-               }
-               */
                $uriids = [$item['uri-id']];
                $shared = BBCode::fetchShareAttributes($item['body']);
                if (!empty($shared['guid'])) {
@@ -1300,8 +1269,14 @@ class Transmitter
                        }
                }
 
+               $urls = [];
                foreach ($uriids as $uriid) {
-                       foreach (Post\Media::getByURIId($uriid, [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
+                       foreach (Post\Media::getByURIId($uriid, [Post\Media::DOCUMENT, Post\Media::TORRENT]) as $attachment) {
+                               if (in_array($attachment['url'], $urls)) {
+                                       continue;
+                               }
+                               $urls[] = $attachment['url'];
+
                                $attachments[] = ['type' => 'Document',
                                        'mediaType' => $attachment['mimetype'],
                                        'url' => $attachment['url'],
@@ -1315,11 +1290,30 @@ class Transmitter
 
                foreach ($uriids as $uriid) {
                        foreach (Post\Media::getByURIId($uriid, [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]) as $attachment) {
+                               if (in_array($attachment['url'], $urls)) {
+                                       continue;
+                               }
+                               $urls[] = $attachment['url'];
+
                                $attachments[] = ['type' => 'Document',
                                        'mediaType' => $attachment['mimetype'],
                                        'url' => $attachment['url'],
                                        'name' => $attachment['description']];
                        }
+                       // Currently deactivated, since it creates side effects on Mastodon and Pleroma.
+                       // It will be activated, once this cleared.
+                       /*
+                       foreach (Post\Media::getByURIId($uriid, [Post\Media::HTML]) as $attachment) {
+                               if (in_array($attachment['url'], $urls)) {
+                                       continue;
+                               }
+                               $urls[] = $attachment['url'];
+
+                               $attachments[] = ['type' => 'Page',
+                                       'mediaType' => $attachment['mimetype'],
+                                       'url' => $attachment['url'],
+                                       'name' => $attachment['description']];
+                       }*/
                }
 
                return $attachments;