Browse Source

Cleanup

master
J. King 4 years ago
parent
commit
b513691544
  1. 16
      lib/Parser/XML/Feed.php
  2. 8
      lib/Parser/XML/Primitives/Feed.php
  3. 13
      tests/cases/XML/feed-other.yaml
  4. 2
      tests/cases/XML/feed-rss2.yaml

16
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 {

8
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;
}
}

13
tests/cases/XML/feed-other.yaml

@ -0,0 +1,13 @@
# This file tests extensions primarily designed for RSS 2
iPod expiration marker:
input: >
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<itunes:complete>Yes</itunes:complete>
</channel>
</rss>
output:
format: rss
sched:
expired: true

2
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: >
<rss>
<channel/>

Loading…
Cancel
Save