pub / kontra

Der linke Newsaggregator.
git clone src.jayvii.de/pub/kontra.git
Home | Log | Files | Exports | Refs | README | RSS

commit df8af9ac3990c94b10fe2ea789a9f078d6e5f4ff
parent 333e413f2021d22b1de1ea3eb7eb81c36e4cc7f0
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Mon, 20 Oct 2025 15:54:48 +0200

fix: make RSS parser robust against empty returns

Diffstat:
Mlib/parse_rss.php | 45++++++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/lib/parse_rss.php b/lib/parse_rss.php @@ -11,28 +11,31 @@ function parse_rss($url, $categories, $name) { /* parse every item from XML */ $out = array(); - for ($i = 0; $i < count($xml->channel->item); $i++) { - - /* fetch required objects */ - $title = (string) $xml->channel->item[$i]->title; - $link = (string) $xml->channel->item[$i]->link; - $description = (string) $xml->channel->item[$i]->description; - $pubDate = (string) $xml->channel->item[$i]->pubDate; - $timestamp = (string) strtotime($pubDate); - - /* insert objects into array*/ - array_push( - $out, - array( - "publ" => $name, - "cats" => $categories, - "title" => $title, - "link" => $link, - "desc" => $description, - "date" => $pubDate - ) - ); + if (!is_null($xml->channel->item)) { + for ($i = 0; $i < count($xml->channel->item); $i++) { + + /* fetch required objects */ + $title = (string) $xml->channel->item[$i]->title; + $link = (string) $xml->channel->item[$i]->link; + $description = (string) $xml->channel->item[$i]->description; + $pubDate = (string) $xml->channel->item[$i]->pubDate; + $timestamp = (string) strtotime($pubDate); + + /* insert objects into array*/ + array_push( + $out, + array( + "publ" => $name, + "cats" => $categories, + "title" => $title, + "link" => $link, + "desc" => $description, + "date" => $pubDate + ) + ); + + } } /* return final array */