]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Feed.php
Merge pull request #9526 from MrPetovan/bug/9525-mastodon-emojis-tag
[friendica.git] / src / Protocol / Feed.php
index f414a3ca8a3dc9e5c2121e759cfadcfe1cb22198..89e7d75423bf6c5e6ac64edb08b3ad83bae3e73e 100644 (file)
@@ -33,6 +33,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
+use Friendica\Model\Post;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
@@ -436,28 +437,22 @@ class Feed
                        $enclosures = $xpath->query("enclosure|atom:link[@rel='enclosure']", $entry);
                        foreach ($enclosures AS $enclosure) {
                                $href = "";
-                               $length = "";
-                               $type = "";
+                               $length = null;
+                               $type = null;
 
                                foreach ($enclosure->attributes AS $attribute) {
                                        if (in_array($attribute->name, ["url", "href"])) {
                                                $href = $attribute->textContent;
                                        } elseif ($attribute->name == "length") {
-                                               $length = $attribute->textContent;
+                                               $length = (int)$attribute->textContent;
                                        } elseif ($attribute->name == "type") {
                                                $type = $attribute->textContent;
                                        }
                                }
 
-                               if (!empty($item["attach"])) {
-                                       $item["attach"] .= ',';
-                               } else {
-                                       $item["attach"] = '';
+                               if (!empty($href)) {
+                                       $attachments[] = ['type' => Post\Media::DOCUMENT, 'url' => $href, 'mimetype' => $type, 'size' => $length];
                                }
-
-                               $attachments[] = ["link" => $href, "type" => $type, "length" => $length];
-
-                               $item["attach"] .= '[attach]href="' . $href . '" length="' . $length . '" type="' . $type . '"[/attach]';
                        }
 
                        $taglist = [];
@@ -494,6 +489,9 @@ class Feed
                        }
                        $item["body"] = HTML::toBBCode($body, $basepath);
 
+                       // Remove tracking pixels
+                       $item["body"] = preg_replace("/\[img=1x1\]([^\[\]]*)\[\/img\]/Usi", '', $item["body"]);
+
                        if (($item["body"] == '') && ($item["title"] != '')) {
                                $item["body"] = $item["title"];
                                $item["title"] = '';
@@ -511,8 +509,8 @@ class Feed
                        if (!empty($contact["fetch_further_information"]) && ($contact["fetch_further_information"] < 3)) {
                                // Handle enclosures and treat them as preview picture
                                foreach ($attachments AS $attachment) {
-                                       if ($attachment["type"] == "image/jpeg") {
-                                               $preview = $attachment["link"];
+                                       if ($attachment["mimetype"] == "image/jpeg") {
+                                               $preview = $attachment["url"];
                                        }
                                }
 
@@ -554,7 +552,7 @@ class Feed
 
                                $data = PageInfo::queryUrl($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_denylist"] ?? '');
 
-                               // Take the data that was provided by the feed if the query wasn't empty
+                               // Take the data that was provided by the feed if the query is empty
                                if (($data['type'] == 'link') && empty($data['title']) && empty($data['text'])) {
                                        $data['title'] = $saved_title;
                                        $item["body"] = $saved_body;
@@ -563,7 +561,7 @@ class Feed
                                $data_text = strip_tags(trim($data['text'] ?? ''));
                                $item_body = strip_tags(trim($item['body'] ?? ''));
 
-                               if (!empty($data['text']) && (($data_text == $item_body) || strstr($item_body, $data_text))) {
+                               if (!empty($data_text) && (($data_text == $item_body) || strstr($item_body, $data_text))) {
                                        $data['text'] = '';
                                }
 
@@ -572,7 +570,7 @@ class Feed
                                $item["body"] = $item["body"] . "\n" . PageInfo::getFooterFromData($data, false);
                                $taglist = $contact["fetch_further_information"] == 2 ? PageInfo::getTagsFromUrl($item["plink"], $preview, $contact["ffi_keyword_denylist"] ?? '') : [];
                                $item["object-type"] = Activity\ObjectType::BOOKMARK;
-                               unset($item["attach"]);
+                               $attachments = [];
                        } else {
                                if (!empty($summary)) {
                                        $item["body"] = '[abstract]' . HTML::toBBCode($summary, $basepath) . "[/abstract]\n" . $item["body"];
@@ -612,11 +610,15 @@ class Feed
 
                        Logger::info("Feed for contact " . $contact["url"] . " stored under id " . $id);
 
-                       if (!empty($id) && !empty($taglist)) {
+                       if (!empty($id) && (!empty($taglist) || !empty($attachments))) {
                                $feeditem = Item::selectFirst(['uri-id'], ['id' => $id]);
                                foreach ($taglist as $tag) {
                                        Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag);
                                }
+                               foreach ($attachments as $attachment) {
+                                       $attachment['uri-id'] = $feeditem['uri-id']; 
+                                       Post\Media::insert($attachment);
+                               }
                        }
                }