1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-09 01:56:39 +02:00

feat: support itunes namespace in top channel feed (#3776)

Also preserves other properties.
This commit is contained in:
Dag
2024-01-09 20:18:33 +01:00
committed by GitHub
parent ea58c8d2bc
commit 3ce94409ab
22 changed files with 298 additions and 203 deletions

View File

@@ -17,44 +17,61 @@ class AtomFormat extends FormatAbstract
public function stringify()
{
$document = new \DomDocument('1.0', $this->getCharset());
$document->formatOutput = true;
$feedUrl = get_current_url();
$extraInfos = $this->getExtraInfos();
if (empty($extraInfos['uri'])) {
$uri = REPOSITORY;
} else {
$uri = $extraInfos['uri'];
}
$document->formatOutput = true;
$feed = $document->createElementNS(self::ATOM_NS, 'feed');
$document->appendChild($feed);
$feed->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:media', self::MRSS_NS);
$title = $document->createElement('title');
$feed->appendChild($title);
$title->setAttribute('type', 'text');
$title->appendChild($document->createTextNode($extraInfos['name']));
$feedArray = $this->getFeed();
foreach ($feedArray as $feedKey => $feedValue) {
if (in_array($feedKey, ['donationUri'])) {
continue;
}
if ($feedKey === 'name') {
$title = $document->createElement('title');
$feed->appendChild($title);
$title->setAttribute('type', 'text');
$title->appendChild($document->createTextNode($feedValue));
} elseif ($feedKey === 'icon') {
if ($feedValue) {
$icon = $document->createElement('icon');
$feed->appendChild($icon);
$icon->appendChild($document->createTextNode($feedValue));
$logo = $document->createElement('logo');
$feed->appendChild($logo);
$logo->appendChild($document->createTextNode($feedValue));
}
} elseif ($feedKey === 'uri') {
if ($feedValue) {
$linkAlternate = $document->createElement('link');
$feed->appendChild($linkAlternate);
$linkAlternate->setAttribute('rel', 'alternate');
$linkAlternate->setAttribute('type', 'text/html');
$linkAlternate->setAttribute('href', $feedValue);
$linkSelf = $document->createElement('link');
$feed->appendChild($linkSelf);
$linkSelf->setAttribute('rel', 'self');
$linkSelf->setAttribute('type', 'application/atom+xml');
$linkSelf->setAttribute('href', $feedUrl);
}
} elseif ($feedKey === 'itunes') {
// todo: skip?
} else {
$element = $document->createElement($feedKey);
$feed->appendChild($element);
$element->appendChild($document->createTextNode($feedValue));
}
}
$id = $document->createElement('id');
$feed->appendChild($id);
$id->appendChild($document->createTextNode($feedUrl));
$uriparts = parse_url($uri);
if (empty($extraInfos['icon'])) {
$iconUrl = $uriparts['scheme'] . '://' . $uriparts['host'] . '/favicon.ico';
} else {
$iconUrl = $extraInfos['icon'];
}
$icon = $document->createElement('icon');
$feed->appendChild($icon);
$icon->appendChild($document->createTextNode($iconUrl));
$logo = $document->createElement('logo');
$feed->appendChild($logo);
$logo->appendChild($document->createTextNode($iconUrl));
$feedTimestamp = gmdate(DATE_ATOM, $this->lastModified);
$updated = $document->createElement('updated');
$feed->appendChild($updated);
@@ -69,17 +86,7 @@ class AtomFormat extends FormatAbstract
$author->appendChild($authorName);
$authorName->appendChild($document->createTextNode($feedAuthor));
$linkAlternate = $document->createElement('link');
$feed->appendChild($linkAlternate);
$linkAlternate->setAttribute('rel', 'alternate');
$linkAlternate->setAttribute('type', 'text/html');
$linkAlternate->setAttribute('href', $uri);
$linkSelf = $document->createElement('link');
$feed->appendChild($linkSelf);
$linkSelf->setAttribute('rel', 'self');
$linkSelf->setAttribute('type', 'application/atom+xml');
$linkSelf->setAttribute('href', $feedUrl);
foreach ($this->getItems() as $item) {
$itemArray = $item->toArray();