Skip to content

Commit

Permalink
yup
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan committed Oct 19, 2023
1 parent f597f0e commit 6113abb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 45 deletions.
75 changes: 43 additions & 32 deletions formats/AtomFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions formats/MrssFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Formats/samples/expectedAtomFormat/feed.common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">

<title type="text">Sample feed with common data</title>
<id>https://example.com/feed?type=common&amp;items=4</id>
<link href="https://example.com/blog/" rel="alternate" type="text/html"/>
<link href="https://example.com/feed?type=common&amp;items=4" rel="self" type="application/atom+xml"/>
<icon>https://example.com/logo.png</icon>
<logo>https://example.com/logo.png</logo>
<id>https://example.com/feed?type=common&amp;items=4</id>
<updated>2000-01-01T12:00:00+00:00</updated>
<author>
<name>RSS-Bridge</name>
</author>
<link href="https://example.com/blog/" rel="alternate" type="text/html"/>
<link href="https://example.com/feed?type=common&amp;items=4" rel="self" type="application/atom+xml"/>

<entry>
<title type="html">Test Entry</title>
Expand Down
4 changes: 2 additions & 2 deletions tests/Formats/samples/expectedAtomFormat/feed.empty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">

<title type="text">Sample feed with minimum data</title>
<link href="https://github.com/RSS-Bridge/rss-bridge/" rel="alternate" type="text/html"/>
<link href="https://example.com/feed" rel="self" type="application/atom+xml"/>
<id>https://example.com/feed</id>
<updated>2000-01-01T12:00:00+00:00</updated>
<author>
<name>RSS-Bridge</name>
</author>
<link href="https://github.com/RSS-Bridge/rss-bridge/" rel="alternate" type="text/html"/>
<link href="https://example.com/feed" rel="self" type="application/atom+xml"/>

</feed>
4 changes: 2 additions & 2 deletions tests/Formats/samples/expectedAtomFormat/feed.emptyItems.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">

<title type="text">Sample feed with minimum data</title>
<link href="https://github.com/RSS-Bridge/rss-bridge/" rel="alternate" type="text/html"/>
<link href="https://example.com/feed" rel="self" type="application/atom+xml"/>
<id>https://example.com/feed</id>
<updated>2000-01-01T12:00:00+00:00</updated>
<author>
<name>RSS-Bridge</name>
</author>
<link href="https://github.com/RSS-Bridge/rss-bridge/" rel="alternate" type="text/html"/>
<link href="https://example.com/feed" rel="self" type="application/atom+xml"/>

<entry>
<title type="html">Sample Item #1</title>
Expand Down
6 changes: 3 additions & 3 deletions tests/Formats/samples/expectedAtomFormat/feed.microblog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">

<title type="text">Sample microblog feed</title>
<id>https://example.com/feed</id>
<link href="https://example.com/blog/" rel="alternate" type="text/html"/>
<link href="https://example.com/feed" rel="self" type="application/atom+xml"/>
<icon>https://example.com/logo.png</icon>
<logo>https://example.com/logo.png</logo>
<id>https://example.com/feed</id>
<updated>2000-01-01T12:00:00+00:00</updated>
<author>
<name>RSS-Bridge</name>
</author>
<link href="https://example.com/blog/" rel="alternate" type="text/html"/>
<link href="https://example.com/feed" rel="self" type="application/atom+xml"/>

<entry>
<title type="html">Oh 😲 I found three monkeys 🙈🙉🙊</title>
Expand Down

0 comments on commit 6113abb

Please sign in to comment.