rssmonster/lib/read-feed.php

36 lines
987 B
PHP

<?php
declare(strict_types = 1);
include_once('config/default.php');
include_once('lib/comic-page.php');
include_once('lib/log.php');
function readFeed($path) {
$awfulSinging = file_get_contents($path);
if ($awfulSinging === false) {
Log::warn("Failed to read existing XML feed from " . $path);
return null;
};
Log::info("Read " . strlen($awfulSinging) . " bytes from " . $path);
$xml = simplexml_load_string($awfulSinging);
$items = array();
foreach ($xml->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'];
$item->pubDate = strtotime((string) $itemXml->pubDate);
array_push($items, $item);
};
Log::info("Read " . count($items) . " items from " . $path);
return $items;
};