Extract method Fee::getTitleFromItemOrEntry()

This commit is contained in:
Art4 2025-01-23 13:56:35 +00:00
parent befb4796f9
commit f75b67de2f

View file

@ -9,6 +9,7 @@ namespace Friendica\Protocol;
use DOMDocument; use DOMDocument;
use DOMElement; use DOMElement;
use DOMNode;
use DOMXPath; use DOMXPath;
use Friendica\App; use Friendica\App;
use Friendica\Contact\LocalRelationship\Entity\LocalRelationship; use Friendica\Contact\LocalRelationship\Entity\LocalRelationship;
@ -386,23 +387,7 @@ class Feed
} }
} }
if (empty($item['title'])) { $item['title'] = static::getTitleFromItemOrEntry($item, $xpath, $atomns, $entry);
$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'));
$published = XML::getFirstNodeValue($xpath, $atomns . ':published/text()', $entry); $published = XML::getFirstNodeValue($xpath, $atomns . ':published/text()', $entry);
@ -747,6 +732,31 @@ class Feed
return ['header' => $author, 'items' => $items]; 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 * Return the hostname out of a variety of provided URL
* *