From b5136915448f9cdc94255b1d904e40db8fe94ede Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 12 Mar 2020 08:41:47 -0400 Subject: [PATCH] Cleanup --- lib/Parser/XML/Feed.php | 16 ++++++++-------- lib/Parser/XML/Primitives/Feed.php | 8 ++++++++ tests/cases/XML/feed-other.yaml | 13 +++++++++++++ tests/cases/XML/feed-rss2.yaml | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 tests/cases/XML/feed-other.yaml diff --git a/lib/Parser/XML/Feed.php b/lib/Parser/XML/Feed.php index fcd63bd..3519c9a 100644 --- a/lib/Parser/XML/Feed.php +++ b/lib/Parser/XML/Feed.php @@ -55,7 +55,7 @@ class Feed implements \MensBeam\Lax\Parser\Feed { if (is_null($ns) && $name === "rss") { $this->subject = $this->fetchElement("channel") ?? $this->subject; $feed->format = "rss"; - $feed->version = $this->document->documentElement->getAttribute("version"); + $feed->version = $this->document->documentElement->hasAttribute("version") ? $this->document->documentElement->getAttribute("version") : null; } elseif ($ns === XPath::NS['rdf'] && $name === "RDF") { $feed->format = "rdf"; $channel = $this->fetchElement("rss1:channel|rss0:channel"); @@ -84,7 +84,7 @@ class Feed implements \MensBeam\Lax\Parser\Feed { public function parse(FeedStruct $feed = null): FeedStruct { $feed = $this->init($feed ?? new FeedStruct); $feed->meta->url = $this->url; - //$feed->sched->expired = $this->getExpired(); + $feed->sched->expired = $this->getExpired(); $feed->id = $this->getId(); //$feed->lang = $this->getLang(); //$feed->url = $this->getUrl(); @@ -101,24 +101,24 @@ class Feed implements \MensBeam\Lax\Parser\Feed { } public function getId(): ?string { - return $this->getIdAtom() ?? $this->getIdDC() ?? $this->getIdRss2() ?? ""; + return $this->getIdAtom() ?? $this->getIdDC() ?? $this->getIdRss2(); } public function getUrl(): ?Url { - return $this->getUrlAtom() ?? $this->getUrlRss1() ?? $this->getUrlPod() ?? $this->reqUrl; + return $this->getUrlAtom() ?? $this->getUrlRss1() ?? $this->getUrlPod(); } public function getTitle(): ?Text { - return $this->getTitleAtom() ?? $this->getTitleRss1() ?? $this->getTitleRss2() ?? $this->getTitleDC() ?? $this->getTitlePod() ?? ""; + return $this->getTitleAtom() ?? $this->getTitleRss1() ?? $this->getTitleRss2() ?? $this->getTitleDC() ?? $this->getTitlePod(); } public function getLink(): ?Url { - return $this->getLinkAtom() ?? $this->getLinkRss1() ?? $this->getLinkRss2() ?? ""; + return $this->getLinkAtom() ?? $this->getLinkRss1() ?? $this->getLinkRss2(); } public function getSummary(): ?Text { // unlike most other data, Atom is not preferred, because Atom doesn't really have feed summaries - return $this->getSummaryDC() ?? $this->getSummaryRss1() ?? $this->getSummaryRss2() ?? $this->getSummaryPod() ?? $this->getSummaryAtom() ?? ""; + return $this->getSummaryDC() ?? $this->getSummaryRss1() ?? $this->getSummaryRss2() ?? $this->getSummaryPod() ?? $this->getSummaryAtom(); } public function getCategories(): CategoryCollection { @@ -142,7 +142,7 @@ class Feed implements \MensBeam\Lax\Parser\Feed { } public function getExpired(): ?bool { - return null; + return $this->getExpiredPod(); } public function getLang(): ?string { diff --git a/lib/Parser/XML/Primitives/Feed.php b/lib/Parser/XML/Primitives/Feed.php index e221d05..f990fb2 100644 --- a/lib/Parser/XML/Primitives/Feed.php +++ b/lib/Parser/XML/Primitives/Feed.php @@ -66,4 +66,12 @@ trait Feed { protected function getDateModifiedRss2() { return $this->fetchDate("lastBuildDate") ?? $this->fetchDate("pubDate"); } + + protected function getExpiredPod(): ?bool { + $complete = $this->fetchString("apple:complete"); + if ($complete === "Yes") { + return true; + } + return null; + } } diff --git a/tests/cases/XML/feed-other.yaml b/tests/cases/XML/feed-other.yaml new file mode 100644 index 0000000..fe451b3 --- /dev/null +++ b/tests/cases/XML/feed-other.yaml @@ -0,0 +1,13 @@ +# This file tests extensions primarily designed for RSS 2 + +iPod expiration marker: + input: > + + + Yes + + + output: + format: rss + sched: + expired: true diff --git a/tests/cases/XML/feed-rss2.yaml b/tests/cases/XML/feed-rss2.yaml index 3b401f7..f7b0df0 100644 --- a/tests/cases/XML/feed-rss2.yaml +++ b/tests/cases/XML/feed-rss2.yaml @@ -29,7 +29,7 @@ Channel GUID with whitespace: format: rss id: 'http://example.com/' -Root GUID: +Root GUID: # Any elements on the RSS2 root element should be ignored input: >