Browse Source

More entry work

- Added entry titles (trivial)
- Added entry modification dates (also pretty trivial)
- Clean up of copy-paste hack-jobs.
master
J. King 6 years ago
parent
commit
90844bdeea
  1. 33
      lib/Entry.php
  2. 10
      lib/JSON/Entry.php
  3. 23
      lib/XML/Entry.php

33
lib/Entry.php

@ -24,41 +24,28 @@ abstract class Entry {
/** Parses the feed to extract sundry metadata */
protected function parse() {
$this->id = $this->getId();
//$this->url = $this->getUrl();
//$this->link = $this->getLink();
//$this->title = $this->getTitle();
//$this->summary = $this->getSummary();
$this->title = $this->getTitle();
$this->people = $this->getPeople();
$this->author = $this->people->primary() ?? $this->feed->author;
//$this->dateModified = $this->getDateModified();
$this->dateModified = $this->getDateModified();
// do a second pass on missing data we'd rather fill in
//$this->link = strlen($this->link) ? $this->link : $this->url;
//$this->title = strlen($this->title) ? $this->title : $this->link;
$this->title = strlen($this->title) ? $this->title : $this->link;
// do extra stuff just to test it
$this->categories = $this->getCategories();
}
/** General function to fetch the canonical feed URL */
//abstract public function getUrl(): string;
/** General function to fetch the entry title */
abstract public function getTitle(): string;
/** General function to fetch the feed title */
//abstract public function getTitle(): string;
/** General function to fetch the feed's Web-representation URL */
//abstract public function getLink(): string;
/** General function to fetch the description of a feed */
//abstract public function getSummary(): string;
/** General function to fetch the categories of a feed */
/** General function to fetch the categories of an entry */
abstract public function getCategories(): CategoryCollection;
/** General function to fetch the feed identifier */
/** General function to fetch the entry identifier */
abstract public function getId(): string;
/** General function to fetch a collection of people associated with a feed */
/** General function to fetch a collection of people associated with an entry */
abstract public function getPeople(): PersonCollection;
/** General function to fetch the feed's modification date */
//abstract public function getDateModified();
/** General function to fetch the entry's modification date */
abstract public function getDateModified();
}

10
lib/JSON/Entry.php

@ -52,4 +52,14 @@ class Entry extends \JKingWeb\Lax\Entry {
public function getPeople(): PersonCollection {
return $this->getPeopleV1() ?? new PersonCollection;
}
/** General function to fetch the modification date of an entry */
public function getDateModified() {
return $this->fetchDate("date_modified");
}
/** General function to fetch the entry title */
public function getTitle(): string {
return $this->fetchMember("title", "str") ?? "";
}
}

23
lib/XML/Entry.php

@ -27,31 +27,12 @@ class Entry extends \JKingWeb\Lax\Entry {
$this->feed = $feed;
}
/** General function to fetch the canonical entry URL
*
* If the entry does not include a canonical URL, the request URL is returned instead
*/
public function getUrl(): string {
return $this->getUrlAtom() ?? $this->getUrlRss1() ?? $this->getUrlPod() ?? $this->reqUrl;
}
/** General function to fetch the entry title */
public function getTitle(): string {
return $this->getTitleAtom() ?? $this->getTitleRss1() ?? $this->getTitleRss2() ?? $this->getTitleDC() ?? $this->getTitlePod() ?? "";
}
/** General function to fetch the entry's Web-representation URL */
public function getLink(): string {
return $this->getLinkAtom() ?? $this->getLinkRss1() ?? $this->getLinkRss2() ?? "";
}
/** General function to fetch the description of a entry */
public function getSummary(): string {
// unlike most other data, Atom is not preferred, because Atom doesn't really have entry summaries
return $this->getSummaryDC() ?? $this->getSummaryRss1() ?? $this->getSummaryRss2() ?? $this->getSummaryPod() ?? $this->getSummaryAtom() ?? "";
}
/** General function to fetch the categories of a entry */
/** General function to fetch the categories of an entry */
public function getCategories(): CategoryCollection {
return $this->getCategoriesAtom() ?? $this->getCategoriesRss2() ?? $this->getCategoriesDC() ?? $this->getCategoriesPod() ?? new CategoryCollection;
}
@ -68,7 +49,7 @@ class Entry extends \JKingWeb\Lax\Entry {
return $authors->merge($contributors);
}
/** General function to fetch the modification date of a entry */
/** General function to fetch the modification date of an entry */
public function getDateModified() {
return $this->getDateModifiedAtom() ?? $this->getDateModifiedDC() ?? $this->getDateModifiedRss2();
}

Loading…
Cancel
Save