From b4ec4c5f73e11ef24a3c011d5c2ca40de85ac1ec Mon Sep 17 00:00:00 2001 From: Alexis Marie Wright Date: Thu, 7 Apr 2022 23:24:22 -0400 Subject: [PATCH] Read existing feed if present --- lib/comic-page.php | 14 ++++++++++++++ lib/fetch-site-content.php | 13 +------------ lib/generate-feed.php | 3 ++- lib/read-feed.php | 34 ++++++++++++++++++++++++++++++++++ rssmonster.php | 2 ++ templates/item.xml | 5 ++++- 6 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 lib/comic-page.php create mode 100644 lib/read-feed.php diff --git a/lib/comic-page.php b/lib/comic-page.php new file mode 100644 index 0000000..b76ba7e --- /dev/null +++ b/lib/comic-page.php @@ -0,0 +1,14 @@ +href}] [{$this->imageUrl}] {$this->pageNo} // {$this->title}"; + } +}; diff --git a/lib/fetch-site-content.php b/lib/fetch-site-content.php index b59bdd8..f158b2d 100644 --- a/lib/fetch-site-content.php +++ b/lib/fetch-site-content.php @@ -5,18 +5,7 @@ include_once('config/default.php'); include_once('lib/log.php'); include_once('lib/fetch-url.php'); - -class ComicPage { - public string $href = ''; - public string $pageNo = ''; - public string $title = ''; - public string $imageUrl = ''; - - function __construct() {} - function __toString() { - return "[{$this->href}] [{$this->imageUrl}] {$this->pageNo} // {$this->title}"; - } -}; +include_once('lib/comic-page.php'); function fetchSiteContent() { $comicPages = array(); diff --git a/lib/generate-feed.php b/lib/generate-feed.php index 308bd49..d423a31 100644 --- a/lib/generate-feed.php +++ b/lib/generate-feed.php @@ -25,11 +25,12 @@ function generateFeed($content) { ]); $items[] = $twig->render('item.xml', [ - 'title' => $page->title, + 'title' => htmlspecialchars($page->title), 'pageNo' => $page->pageNo, 'fullTitle' => htmlspecialchars($page->pageNo . " // " . $page->title), 'date' => $now, 'url' => $page->href, + 'imageUrl' => htmlspecialchars($page->imageUrl), 'content' => htmlspecialchars($content) ]); }; diff --git a/lib/read-feed.php b/lib/read-feed.php new file mode 100644 index 0000000..1198c10 --- /dev/null +++ b/lib/read-feed.php @@ -0,0 +1,34 @@ +channel->item as $itemXml) { + $item = new ComicPage; + $item->href = (string) $itemXml->link; + $item->pageNo = (string) $itemXml['data-pageno']; + $item->title = (string) $itemXml['data-title']; + $item->imageUrl = (string) $itemXml['data-imageurl']; + + print $item; + exit(); + + array_push($item); + }; +}; diff --git a/rssmonster.php b/rssmonster.php index faad87f..e32d2cc 100644 --- a/rssmonster.php +++ b/rssmonster.php @@ -10,9 +10,11 @@ require_once('vendor/autoload.php'); include_once('config/default.php'); include_once('lib/log.php'); +include_once('lib/read-feed.php'); include_once('lib/fetch-site-content.php'); include_once('lib/generate-feed.php'); +$existingFeed = readFeed(Config::feedPath); $content = fetchSiteContent(); $feedXml = generateFeed(array_reverse($content)); diff --git a/templates/item.xml b/templates/item.xml index 9dc7db1..6a49ed5 100644 --- a/templates/item.xml +++ b/templates/item.xml @@ -1,4 +1,7 @@ - + {{ fullTitle }} {{ content }} {{ date }}