From 128a758de50188b43fad22e4f60225d03ccacb54 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 18 Mar 2021 19:18:59 +0100 Subject: fixes in news syndication in index.php --- index.php | 56 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/index.php b/index.php index 3ae406e..e77e36e 100644 --- a/index.php +++ b/index.php @@ -73,38 +73,58 @@ print_header("", "home"); RSS Feed = 200 && $httpcode < 300 ) { + $news32 = simplexml_load_string($news32); + } else { + $news32 = false; + $news32status = "HTTP return code was $httpcode"; + } + } else { + $news = false; + } } else { $news32 = false; } $ch = curl_init("https://archlinux.org/feeds/news/"); -curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); -curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); -$news64 = curl_exec($ch); -curl_close($ch); -$news64 = simplexml_load_string($news64); +if( $ch != null && $ch != false ) { + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + $news64 = curl_exec($ch); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if( $httpcode >= 200 && $httpcode < 300 ) { + $news64 = simplexml_load_string($news64); + } else { + $news64 = false; + $news64status = "HTTP return code was $httpcode"; + } +} else { + $news64 = false; +} $news = array(); if ($news32 === false) { print "

\n"; - print " sorry, arch 32 news are currently unavailable\n"; + print " sorry, arch 32 news are currently unavailable ($news32status)\n"; print "

\n"; } else { foreach($news32 -> {'entry'} as $entry) { @@ -125,7 +145,7 @@ if ($news32 === false) { } if ($news64 === false) { print "

\n"; - print " sorry, upstream arch news are currently unavailable\n"; + print " sorry, upstream arch news are currently unavailable ($news64status)\n"; print "

\n"; } else { foreach($news64 -> {'channel'} -> {'item'} as $entry) { -- cgit v1.2.3