Browse Source

Add feed identifiers

master
J. King 6 years ago
parent
commit
6a7bc4c6e9
  1. 1
      .gitignore
  2. 18
      lib/XMLCommonPrimitives.php
  3. 6
      lib/XMLFeed.php

1
.gitignore

@ -1,2 +1,3 @@
vendor
samples
test.php

18
lib/XMLCommonPrimitives.php

@ -121,4 +121,22 @@ trait XMLCommonPrimitives {
return $grouped ? ['' => $out] : $out;
}
/** Primitive to fetch an Atom feed/entry identifier */
protected function getIdAtom() {
return $this->fetchText("./atom:id");
}
/** Primitive to fetch an RSS feed/entry identifier
*
* Using RSS' <guid> for feed identifiers is non-standard, but harmless
*/
protected function getIdRss2() {
return $this->fetchText("./guid");
}
/** Primitive to fetch a Dublin Core feed/entry identifier */
protected function getIdDC() {
return $this->fetchText("./dc:identifier");
}
}

6
lib/XMLFeed.php

@ -61,6 +61,7 @@ class XMLFeed extends XMLCommon {
/** Parses the feed to extract sundry metadata */
protected function parse() {
$this->id = $this->getId();
$this->link = $this->getLink();
$this->title = $this->getTitle() ?? $this->link;
$this->summary = $this->getSummary();
@ -91,4 +92,9 @@ class XMLFeed extends XMLCommon {
public function getCategories(bool $grouped = false, bool $humanFriendly = true) {
return $this->getCategoriesAtom($grouped, $humanFriendly) ?? $this->getCategoriesRss2($grouped, $humanFriendly) ?? $this->getCategoriesDC($grouped, $humanFriendly) ?? $this->getCategoriesApple($grouped, $humanFriendly);
}
/** General function to fetch the feed identifier */
public function getId() {
return $this->getIdAtom() ?? $this->getIdDC() ?? $this->getIdRss2();
}
}

Loading…
Cancel
Save