Browse Source

Add RSS1 schedule base

master
J. King 4 years ago
parent
commit
b84b3aa333
  1. 2
      lib/Parser/XML/Construct.php
  2. 18
      lib/Parser/XML/Entry.php
  3. 28
      lib/Parser/XML/Feed.php
  4. 16
      tests/cases/XML/feed-rss1.yaml

2
lib/Parser/XML/Construct.php

@ -74,7 +74,7 @@ abstract class Construct {
*/
protected function fetchDate(string $query, ?bool $multi = null, \DOMNode $context = null) {
$out = [];
foreach((array) $this->fetchString($query, null, $multi, $context) as $d) {
foreach((array) $this->fetchString($query, null, true, $context) as $d) {
if ($d = $this->parseDate($d ?? "")) {
if (!$multi) {
return $d;

18
lib/Parser/XML/Entry.php

@ -6,6 +6,7 @@
declare(strict_types=1);
namespace MensBeam\Lax\Parser\XML;
use MensBeam\Lax\Entry as EntryStruct;
use MensBeam\Lax\Person\Collection as PersonCollection;
use MensBeam\Lax\Category\Collection as CategoryCollection;
use MensBeam\Lax\Enclosure\Collection as EnclosureCollection;
@ -27,21 +28,8 @@ class Entry extends Construct implements \MensBeam\Lax\Parser\Entry {
}
/** Parses the feed to extract sundry metadata */
protected function parse(\DOMElement $data, \MensBeam\Lax\Feed $feed): \MensBeam\Lax\Entry {
$entry = new \MensBeam\Lax\Entry;
$entry->id = $this->getId();
$entry->link = $this->getLink();
$entry->relatedLink = $this->getRelatedLink();
$entry->title = $this->getTitle();
$entry->people = $this->getPeople();
$entry->author = $this->people->primary() ?? $this->feed->author;
$entry->dateModified = $this->getDateModified();
$entry->dateCreated = $this->getDateCreated();
// do a second pass on missing data we'd rather fill in
$entry->title = strlen($this->title) ? $this->title : $this->link;
// do extra stuff just to test it
$entry->categories = $this->getCategories();
return $entry;
protected function parse(\DOMElement $data, \MensBeam\Lax\Feed $feed): EntryStruct {
return new EntryStruct;
}
/** General function to fetch the entry title */

28
lib/Parser/XML/Feed.php

@ -101,6 +101,20 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
return $this->getIdAtom() ?? $this->getIdDC() ?? $this->getIdRss2();
}
public function getSchedule(): Schedule {
$sched = new Schedule;
$sched->interval = $this->getSchedIntervalRss1() ?? $this->getSchedIntervalRss2();
$sched->skip = $this->getSchedSkipRss2();
$sched->expired = $this->getExpiredPod();
if (is_null($sched->expired) && (($sched->skip & Schedule::DAY_ALL) == Schedule::DAY_ALL || ($sched->skip & Schedule::HOUR_ALL) == Schedule::HOUR_ALL)) {
$sched->expired = true;
}
if ($sched->interval) {
$sched->base = $this->getSchedBaseRss1();
}
return $sched;
}
public function getUrl(): ?Url {
return $this->getUrlAtom() ?? $this->getUrlRss1() ?? $this->getUrlPod();
}
@ -138,20 +152,6 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
return $this->getEntriesAtom() ?? $this->getEntriesRss1() ?? $this->getEntriesRss2() ?? [];
}
public function getSchedule(): Schedule {
$sched = new Schedule;
$sched->interval = $this->getSchedIntervalRss1() ?? $this->getSchedIntervalRss2();
$sched->skip = $this->getSchedSkipRss2();
$sched->expired = $this->getExpiredPod();
if (is_null($sched->expired) && (($sched->skip & Schedule::DAY_ALL) == Schedule::DAY_ALL || ($sched->skip & Schedule::HOUR_ALL) == Schedule::HOUR_ALL)) {
$sched->expired = true;
}
if ($sched->interval) {
$sched->base = $this->getSchedBaseRss1();
}
return $sched;
}
public function getLang(): ?string {
return null;
}

16
tests/cases/XML/feed-rss1.yaml

@ -134,3 +134,19 @@ Syndication schedule 5:
version: '1.0'
sched:
interval: P1M
Syndication schedule base 1:
input: >
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">
<channel>
<sy:updatePeriod>daily</sy:updatePeriod>
<sy:updateBase>bogus</sy:updateBase>
<sy:updateBase>2020-03-01T20:21:12-04:00</sy:updateBase>
</channel>
</rdf:RDF>
output:
format: rdf
version: '1.0'
sched:
interval: PT24H
base: '2020-03-01T20:21:12-04:00'

Loading…
Cancel
Save