From 8c5a65bab34da63270e6a4bc8a97df5cc5df7b3f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 19 Mar 2021 08:03:43 +0100 Subject: index.php: add get_news functions to avoid code duplication --- index.php | 65 ++++----------------------------------------------------------- 1 file changed, 4 insertions(+), 61 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index 7f5457a..7c3f54d 100644 --- a/index.php +++ b/index.php @@ -73,71 +73,14 @@ print_header("", "home"); RSS Feed = 200 && $httpcode < 300 ) { - apcu_store('news32', $news32, 300); - } else { - $news32 = false; - } - } else { - $news32 = false; - $news32status = "HTTP return code was $httpcode"; - } - } else { - $news = false; - } -} -if( $news32 != false ) { - $news32 = simplexml_load_string($news32); -} - -$news64 = apcu_fetch('news64', $apcu_success); -if( $apcu_success == false ) { - $ch = curl_init("https://archlinux.org/feeds/news/"); - 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 ) { - apcu_store('news64', $news64, 300); - } else { - $news64 = false; - } - } else { - $news64 = false; - $news64status = "HTTP return code was $httpcode"; - } -} -if( $news64 != false ) { - $news64 = simplexml_load_string($news64); -} +$news32 = get_news('news32', 'https://bbs.archlinux32.org/extern.php?action=feed&fid=12&type=atom', 300); +$news64 = get_news('news64', 'https://archlinux.org/feeds/news/', 300); $news = array(); if ($news32 === false) { print "

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

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

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

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