From 6113abb61710bfeaf759d8a195174398a12619e6 Mon Sep 17 00:00:00 2001 From: Dag Date: Fri, 20 Oct 2023 00:16:05 +0200 Subject: [PATCH] yup --- formats/AtomFormat.php | 75 +++++++++++-------- formats/MrssFormat.php | 6 +- .../expectedAtomFormat/feed.common.xml | 6 +- .../samples/expectedAtomFormat/feed.empty.xml | 4 +- .../expectedAtomFormat/feed.emptyItems.xml | 4 +- .../expectedAtomFormat/feed.microblog.xml | 6 +- 6 files changed, 56 insertions(+), 45 deletions(-) diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index a34378f7540..158f288e5a6 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -17,38 +17,61 @@ class AtomFormat extends FormatAbstract public function stringify() { $document = new \DomDocument('1.0', $this->getCharset()); + $document->formatOutput = true; $feedUrl = get_current_url(); - $feedArray = $this->getFeed(); - - $uri = $feedArray['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($feedArray['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)); - $iconUrl = $feedArray['icon']; - if ($iconUrl) { - $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); @@ -63,19 +86,7 @@ public function stringify() $author->appendChild($authorName); $authorName->appendChild($document->createTextNode($feedAuthor)); - if ($uri) { - $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(); diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php index 8e30a830f93..d1d91499b08 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -108,9 +108,9 @@ public function stringify() $itunesProperty->appendChild($document->createTextNode($itunesValue)); } } else { - $channelTitle = $document->createElement($feedKey); - $channel->appendChild($channelTitle); - $channelTitle->appendChild($document->createTextNode($feedValue)); + $element = $document->createElement($feedKey); + $channel->appendChild($element); + $element->appendChild($document->createTextNode($feedValue)); } } diff --git a/tests/Formats/samples/expectedAtomFormat/feed.common.xml b/tests/Formats/samples/expectedAtomFormat/feed.common.xml index aa6d0687da2..455e5440529 100644 --- a/tests/Formats/samples/expectedAtomFormat/feed.common.xml +++ b/tests/Formats/samples/expectedAtomFormat/feed.common.xml @@ -2,15 +2,15 @@ Sample feed with common data - https://example.com/feed?type=common&items=4 + + https://example.com/logo.png https://example.com/logo.png + https://example.com/feed?type=common&items=4 2000-01-01T12:00:00+00:00 RSS-Bridge - - Test Entry diff --git a/tests/Formats/samples/expectedAtomFormat/feed.empty.xml b/tests/Formats/samples/expectedAtomFormat/feed.empty.xml index 34f053bec53..083f230f9bf 100644 --- a/tests/Formats/samples/expectedAtomFormat/feed.empty.xml +++ b/tests/Formats/samples/expectedAtomFormat/feed.empty.xml @@ -2,12 +2,12 @@ Sample feed with minimum data + + https://example.com/feed 2000-01-01T12:00:00+00:00 RSS-Bridge - - diff --git a/tests/Formats/samples/expectedAtomFormat/feed.emptyItems.xml b/tests/Formats/samples/expectedAtomFormat/feed.emptyItems.xml index 72a1106a083..d7cb461a1e6 100644 --- a/tests/Formats/samples/expectedAtomFormat/feed.emptyItems.xml +++ b/tests/Formats/samples/expectedAtomFormat/feed.emptyItems.xml @@ -2,13 +2,13 @@ Sample feed with minimum data + + https://example.com/feed 2000-01-01T12:00:00+00:00 RSS-Bridge - - Sample Item #1 diff --git a/tests/Formats/samples/expectedAtomFormat/feed.microblog.xml b/tests/Formats/samples/expectedAtomFormat/feed.microblog.xml index 32bc02731e7..8eb0133c83a 100644 --- a/tests/Formats/samples/expectedAtomFormat/feed.microblog.xml +++ b/tests/Formats/samples/expectedAtomFormat/feed.microblog.xml @@ -2,15 +2,15 @@ Sample microblog feed - https://example.com/feed + + https://example.com/logo.png https://example.com/logo.png + https://example.com/feed 2000-01-01T12:00:00+00:00 RSS-Bridge - - Oh 😲 I found three monkeys 🙈🙉🙊