From b84b3aa33399c92caa21f254e19d78629b66c4f0 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 12 Mar 2020 22:52:53 -0400 Subject: [PATCH] Add RSS1 schedule base --- lib/Parser/XML/Construct.php | 2 +- lib/Parser/XML/Entry.php | 18 +++--------------- lib/Parser/XML/Feed.php | 28 ++++++++++++++-------------- tests/cases/XML/feed-rss1.yaml | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/lib/Parser/XML/Construct.php b/lib/Parser/XML/Construct.php index 106a50a..7c15569 100644 --- a/lib/Parser/XML/Construct.php +++ b/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; diff --git a/lib/Parser/XML/Entry.php b/lib/Parser/XML/Entry.php index 954ab92..425c6c3 100644 --- a/lib/Parser/XML/Entry.php +++ b/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 */ diff --git a/lib/Parser/XML/Feed.php b/lib/Parser/XML/Feed.php index 81934b5..44c52bf 100644 --- a/lib/Parser/XML/Feed.php +++ b/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; } diff --git a/tests/cases/XML/feed-rss1.yaml b/tests/cases/XML/feed-rss1.yaml index 8229ed8..1f094e1 100644 --- a/tests/cases/XML/feed-rss1.yaml +++ b/tests/cases/XML/feed-rss1.yaml @@ -134,3 +134,19 @@ Syndication schedule 5: version: '1.0' sched: interval: P1M + +Syndication schedule base 1: + input: > + + + daily + bogus + 2020-03-01T20:21:12-04:00 + + + output: + format: rdf + version: '1.0' + sched: + interval: PT24H + base: '2020-03-01T20:21:12-04:00'