Browse Source

Add related article URLs for Atom and JSON

master
J. King 6 years ago
parent
commit
5d077bc5af
  1. 6
      lib/Entry.php
  2. 5
      lib/JSON/Entry.php
  3. 8
      lib/XML/Entry.php
  4. 9
      lib/XML/Primitives/Construct.php

6
lib/Entry.php

@ -13,7 +13,7 @@ abstract class Entry {
protected $feed;
public $link;
public $externalLink;
public $relatedLink;
public $title;
public $summary;
public $categories;
@ -26,6 +26,7 @@ abstract class Entry {
protected function parse() {
$this->id = $this->getId();
$this->link = $this->getLink();
$this->relatedLink = $this->getRelatedLink();
$this->title = $this->getTitle();
$this->people = $this->getPeople();
$this->author = $this->people->primary() ?? $this->feed->author;
@ -57,4 +58,7 @@ abstract class Entry {
/** General function to fetch the Web URL of the entry */
abstract public function getLink(): string;
/** General function to fetch the URL of a article related to the entry */
abstract public function getRelatedLink(): string;
}

5
lib/JSON/Entry.php

@ -72,4 +72,9 @@ class Entry extends \JKingWeb\Lax\Entry {
public function getLink(): string {
return $this->fetchUrl("url") ?? "";
}
/** General function to fetch the URL of a article related to the entry */
public function getRelatedLink(): string {
return $this->fetchUrl("external_url") ?? "";
}
}

8
lib/XML/Entry.php

@ -63,4 +63,12 @@ class Entry extends \JKingWeb\Lax\Entry {
public function getLink(): string {
return $this->getLinkAtom() ?? $this->getLinkRss1() ?? $this->getLinkRss2() ?? "";
}
/** General function to fetch the URL of a article related to the entry
*
* This is only reliable with Atom feeds
*/
public function getRelatedLink(): string {
return $this->getRelatedLinkAtom() ?? "";
}
}

9
lib/XML/Primitives/Construct.php

@ -233,7 +233,7 @@ trait Construct {
/** Primitive to fetch the list of entries in an RDF feed */
protected function getEntriesRss1() {
$out = [];
foreach ($this->fetchElements("rss1:item|rss0:item", $this->subject->ownerDocument->documentElement) ?? $this->fetchElements("rss1:item|rss0:item") ?? [] as $node) {
foreach ($this->fetchElements("rss1:item", $this->subject->ownerDocument->documentElement) ?? $this->fetchElements("rss1:item") ?? $this->fetchElements("rss0:item", $this->subject->ownerDocument->documentElement) ?? $this->fetchElements("rss0:item") ?? [] as $node) {
$out[] = new FeedEntry($node, $this, $this->xpath);
}
return count($out) ? $out : null;
@ -247,4 +247,11 @@ trait Construct {
}
return count($out) ? $out : null;
}
/** Primitive to fetch the URL of a article related to the entry */
protected function getRelatedLinkAtom() {
// FIXME: Atom link fetching should ideally prefer links to text/html resources or the like over e.g. other-format newsfeeds, generic XML, images, etc
$node = $this->fetchAtomRelations("related");
return $node->length ? $this->resolveNodeUrl($node->item(0), "href") : null;
}
}

Loading…
Cancel
Save