Browse Source

Don't use XPath sets unless actually desired

master
J. King 4 years ago
parent
commit
dffedfb556
  1. 22
      lib/Parser/XML/Construct.php
  2. 39
      lib/Parser/XML/Feed.php

22
lib/Parser/XML/Construct.php

@ -307,7 +307,7 @@ abstract class Construct {
}
protected function getLinkRss1(): ?Url {
return $this->fetchUrl("rss1:link|rss0:link");
return $this->fetchUrl("rss1:link") ?? $this->fetchUrl("rss0:link");
}
protected function getTitleAtom(): ?Text {
@ -315,7 +315,7 @@ abstract class Construct {
}
protected function getTitleRss1(): ?Text {
return $this->fetchText("rss1:title|rss0:title", self::TEXT_LOOSE);
return $this->fetchText("rss1:title", self::TEXT_LOOSE) ?? $this->fetchText("rss0:title", self::TEXT_LOOSE);
}
protected function getTitleRss2(): ?Text {
@ -370,9 +370,9 @@ abstract class Construct {
return count($out) ? $out : null;
}
protected function getCategoriesPod(): ?CategoryCollection {
protected function getCategoriesTunes(): ?CategoryCollection {
$out = new CategoryCollection;
foreach ($this->xpath->query("apple:category|gplay:category") ?? [] as $node) {
foreach ($this->xpath->query("apple:category") ?? [] as $node) {
$c = new Category;
$c->name = $this->trimText($node->getAttribute("text"));
if (strlen($c->name)) {
@ -380,5 +380,17 @@ abstract class Construct {
}
}
return count($out) ? $out : null;
}
}
protected function getCategoriesGPlay(): ?CategoryCollection {
$out = new CategoryCollection;
foreach ($this->xpath->query("gplay:category") ?? [] as $node) {
$c = new Category;
$c->name = $this->trimText($node->getAttribute("text"));
if (strlen($c->name)) {
$out[] = $c;
}
}
return count($out) ? $out : null;
}
}

39
lib/Parser/XML/Feed.php

@ -124,9 +124,10 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
}
public function getUrl(): ?Url {
return $this->fetchAtomRelation("self") // Atom 'self' relation URL
?? $this->fetchUrl("(self::rss1:channel|self::rss0:channel)/@rdf:about") // RDF-about URL from RSS 0.90 or RSS 1.0
?? $this->fetchUrl("apple:new-feed-url"); // iTunes podcast canonical URL
return $this->fetchAtomRelation("self") // Atom 'self' relation URL
?? $this->fetchUrl("self::rss1:channel/@rdf:about") // RDF-about URL from RSS 0.90 or RSS 1.0
?? $this->fetchUrl("self::rss0:channel/@rdf:about") // RDF-about URL from RSS 0.90 or RSS 1.0
?? $this->fetchUrl("apple:new-feed-url"); // iTunes podcast canonical URL
}
public function getLink(): ?Url {
@ -144,13 +145,15 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
}
public function getSummary(): ?Text {
return $this->fetchAtomText("atom:summary") // Atom summary (non-standard)
?? $this->fetchAtomText("atom:subtitle") // Atom subtitle
?? $this->fetchText("dc:description", self::TEXT_PLAIN) // Dublin Core description
?? $this->fetchText("rss1:description|rss0:description", self::TEXT_LOOSE) // RSS 0.90 or RSS 1.0 description
?? $this->fetchText("description", self::TEXT_LOOSE) // RSS 2.0 description
?? $this->fetchText("apple:summary|gplay:description", self::TEXT_PLAIN) // iTunes podcast summary or Google Play podcast description
?? $this->fetchText("apple:subtitle", self::TEXT_PLAIN); // iTunes podcast subtitle
return $this->fetchAtomText("atom:summary") // Atom summary (non-standard)
?? $this->fetchAtomText("atom:subtitle") // Atom subtitle
?? $this->fetchText("dc:description", self::TEXT_PLAIN) // Dublin Core description
?? $this->fetchText("rss1:description", self::TEXT_LOOSE) // RSS 1.0 description
?? $this->fetchText("rss0:description", self::TEXT_LOOSE) // RSS 0.90 description
?? $this->fetchText("description", self::TEXT_LOOSE) // RSS 2.0 description
?? $this->fetchText("gplay:description", self::TEXT_PLAIN) // Google Play podcast description
?? $this->fetchText("apple:summary", self::TEXT_PLAIN) // iTunes podcast summary
?? $this->fetchText("apple:subtitle", self::TEXT_PLAIN); // iTunes podcast subtitle
}
public function getDateModified(): ?Date {
@ -170,17 +173,21 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
}
public function getImage(): ?Url {
return $this->fetchUrl("atom:logo") // Atom logo URL
?? $this->fetchUrl("rss0:image/rss0:url|rss1:image/rss1:url") // RSS 0.90 or RSS 1.0 channel image
?? $this->fetchUrl("/rdf:RDF/rss0:image/rss0:url|/rdf:RDF/rss1:image/rss1:url") // RSS 0.90 or RSS 1.0 root image
?? $this->fetchUrl("image/url") // RSS 2.0 channel image
?? $this->fetchUrl("(apple:image|gplay:image)/@href"); // iTunes or Google Play podcast image
return $this->fetchUrl("atom:logo") // Atom logo URL
?? $this->fetchUrl("rss1:image/rss1:url") // RSS 1.0 channel image
?? $this->fetchUrl("/rdf:RDF/rss1:image/rss1:url") // RSS 1.0 root image
?? $this->fetchUrl("rss0:image/rss0:url") // RSS 0.90 channel image
?? $this->fetchUrl("/rdf:RDF/rss0:image/rss0:url") // RSS 0.90 root image
?? $this->fetchUrl("image/url") // RSS 2.0 channel image
?? $this->fetchUrl("gplay:image/@href") // Google Play podcast image
?? $this->fetchUrl("apple:image/@href"); // iTunes podcast image
}
public function getCategories(): CategoryCollection {
return $this->getCategoriesAtom()
?? $this->getCategoriesRss2()
?? $this->getCategoriesPod()
?? $this->getCategoriesGPlay()
?? $this->getCategoriesTunes()
?? $this->getCategoriesDC()
?? new CategoryCollection;
}

Loading…
Cancel
Save