]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Feed.php
Merge pull request #13724 from Raroun/Fix-for-Issue-#13637---Photo-caption-prevents...
[friendica.git] / src / Protocol / Feed.php
index 6d6d3f6762bc7d6e4d8fdae797d37da6de3d241e..fdfe9be7d5e836b57621b65cb6a6f693124ac48c 100644 (file)
@@ -25,6 +25,7 @@ use DOMDocument;
 use DOMElement;
 use DOMXPath;
 use Friendica\App;
+use Friendica\Contact\LocalRelationship\Entity\LocalRelationship;
 use Friendica\Content\PageInfo;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
@@ -103,7 +104,7 @@ class Feed
                $xpath->registerNamespace('poco', ActivityNamespace::POCO);
 
                $author = [];
-               $atomns = '';
+               $atomns = 'atom';
                $entries = null;
                $protocol = Conversation::PARCEL_UNKNOWN;
 
@@ -128,13 +129,12 @@ class Feed
                // Is it Atom?
                if ($xpath->query('/atom:feed')->length > 0) {
                        $protocol = Conversation::PARCEL_ATOM;
-                       $atomns = 'atom';
                } elseif ($xpath->query('/atom03:feed')->length > 0) {
                        $protocol = Conversation::PARCEL_ATOM03;
                        $atomns = 'atom03';
                }
 
-               if (!empty($atomns)) {
+               if (in_array($protocol, [Conversation::PARCEL_ATOM, Conversation::PARCEL_ATOM03])) {
                        $alternate = XML::getFirstAttributes($xpath, $atomns . ":link[@rel='alternate']");
                        if (is_object($alternate)) {
                                foreach ($alternate as $attribute) {
@@ -336,7 +336,7 @@ class Feed
                                                case 'text':
                                                        $body = $attribute->nodeValue;
                                                        break;
-       
+
                                                case 'htmlUrl':
                                                        $plink = $attribute->nodeValue;
                                                        break;
@@ -344,7 +344,7 @@ class Feed
                                                case 'xmlUrl':
                                                        $uri = $attribute->nodeValue;
                                                        break;
-       
+
                                                case 'type':
                                                        $isrss = $attribute->nodeValue == 'rss';
                                                        break;
@@ -479,7 +479,7 @@ class Feed
 
                        $attachments = [];
 
-                       $enclosures = $xpath->query("enclosure|' . $atomns . ':link[@rel='enclosure']", $entry);
+                       $enclosures = $xpath->query("enclosure|$atomns:link[@rel='enclosure']", $entry);
                        if (!empty($enclosures)) {
                                foreach ($enclosures as $enclosure) {
                                        $href = '';
@@ -507,7 +507,7 @@ class Feed
                                                        $attachment['type'] = Post\Media::DOCUMENT;
                                                }
                                                $attachments[] = $attachment;
-                                       }                               
+                                       }
                                }
                        }
 
@@ -567,8 +567,10 @@ class Feed
                                continue;
                        }
 
+                       $fetch_further_information = $contact['fetch_further_information'] ?? LocalRelationship::FFI_NONE;
+
                        $preview = '';
-                       if (!empty($contact['fetch_further_information']) && ($contact['fetch_further_information'] < 3)) {
+                       if (in_array($fetch_further_information, [LocalRelationship::FFI_INFORMATION, LocalRelationship::FFI_BOTH])) {
                                // Handle enclosures and treat them as preview picture
                                foreach ($attachments as $attachment) {
                                        if ($attachment['mimetype'] == 'image/jpeg') {
@@ -612,7 +614,12 @@ class Feed
                                        }
                                }
 
-                               $data = PageInfo::queryUrl($item['plink'], false, $preview, ($contact['fetch_further_information'] == 2), $contact['ffi_keyword_denylist'] ?? '');
+                               $data = PageInfo::queryUrl(
+                                       $item['plink'],
+                                       false,
+                                       $fetch_further_information == LocalRelationship::FFI_BOTH,
+                                       $contact['ffi_keyword_denylist'] ?? ''
+                               );
 
                                if (!empty($data)) {
                                        // Take the data that was provided by the feed if the query is empty
@@ -631,7 +638,7 @@ class Feed
                                        // We always strip the title since it will be added in the page information
                                        $item['title'] = '';
                                        $item['body'] = $item['body'] . "\n" . PageInfo::getFooterFromData($data, false);
-                                       $taglist = $contact['fetch_further_information'] == 2 ? PageInfo::getTagsFromUrl($item['plink'], $preview, $contact['ffi_keyword_denylist'] ?? '') : [];
+                                       $taglist = $fetch_further_information == LocalRelationship::FFI_BOTH ? PageInfo::getTagsFromUrl($item['plink'], $preview, $contact['ffi_keyword_denylist'] ?? '') : [];
                                        $item['object-type'] = Activity\ObjectType::BOOKMARK;
                                        $attachments = [];
 
@@ -663,7 +670,7 @@ class Feed
                                        $item['body'] = '[abstract]' . HTML::toBBCode($summary, $basepath) . "[/abstract]\n" . $item['body'];
                                }
 
-                               if (!empty($contact['fetch_further_information']) && ($contact['fetch_further_information'] == 3)) {
+                               if ($fetch_further_information == LocalRelationship::FFI_KEYWORD) {
                                        if (empty($taglist)) {
                                                $taglist = PageInfo::getTagsFromUrl($item['plink'], $preview, $contact['ffi_keyword_denylist'] ?? '');
                                        }