From f75b67de2f79611cb46f36334e2d281bc9b45d36 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 23 Jan 2025 13:56:35 +0000 Subject: [PATCH] Extract method Fee::getTitleFromItemOrEntry() --- src/Protocol/Feed.php | 44 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index fa1ea3b302..11cac371d5 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -9,6 +9,7 @@ namespace Friendica\Protocol; use DOMDocument; use DOMElement; +use DOMNode; use DOMXPath; use Friendica\App; use Friendica\Contact\LocalRelationship\Entity\LocalRelationship; @@ -386,23 +387,7 @@ class Feed } } - if (empty($item['title'])) { - $item['title'] = XML::getFirstNodeValue($xpath, $atomns . ':title/text()', $entry); - } - - if (empty($item['title'])) { - $item['title'] = XML::getFirstNodeValue($xpath, 'title/text()', $entry); - } - - if (empty($item['title'])) { - $item['title'] = XML::getFirstNodeValue($xpath, 'rss:title/text()', $entry); - } - - if (empty($item['title'])) { - $item['title'] = XML::getFirstNodeValue($xpath, 'itunes:title/text()', $entry); - } - - $item['title'] = trim(html_entity_decode($item['title'], ENT_QUOTES, 'UTF-8')); + $item['title'] = static::getTitleFromItemOrEntry($item, $xpath, $atomns, $entry); $published = XML::getFirstNodeValue($xpath, $atomns . ':published/text()', $entry); @@ -747,6 +732,31 @@ class Feed return ['header' => $author, 'items' => $items]; } + private static function getTitleFromItemOrEntry(array $item, DOMXPath $xpath, string $atomns, ?DOMNode $entry): string + { + $title = (string) $item['title']; + + if (empty($title)) { + $title = XML::getFirstNodeValue($xpath, $atomns . ':title/text()', $entry); + } + + if (empty($title)) { + $title = XML::getFirstNodeValue($xpath, 'title/text()', $entry); + } + + if (empty($title)) { + $title = XML::getFirstNodeValue($xpath, 'rss:title/text()', $entry); + } + + if (empty($title)) { + $title = XML::getFirstNodeValue($xpath, 'itunes:title/text()', $entry); + } + + $title = trim(html_entity_decode($title, ENT_QUOTES, 'UTF-8')); + + return $title; + } + /** * Return the hostname out of a variety of provided URL *