aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2025-10-22 11:14:43 +0200
committerPhilip Wittamore <philip@wittamore.com>2025-10-22 11:14:43 +0200
commit30a1a627fd445781fed8679b1e636cf1685e980e (patch)
tree458a936be49f880ea5678a3640be3118b05cac97
parent3f329dca654337da17a03ef1bde4b63abee7f1d1 (diff)
downloadscripts-30a1a627fd445781fed8679b1e636cf1685e980e.tar.gz
scripts-30a1a627fd445781fed8679b1e636cf1685e980e.tar.bz2
scripts-30a1a627fd445781fed8679b1e636cf1685e980e.zip
update
-rw-r--r--getfeeds.php83
1 files changed, 42 insertions, 41 deletions
diff --git a/getfeeds.php b/getfeeds.php
index 8da7390..a6fa2e7 100644
--- a/getfeeds.php
+++ b/getfeeds.php
@@ -12,15 +12,15 @@ $hs = "header";
$dir = glob($root . '/*' , GLOB_ONLYDIR);
if (file_exists("$root/$hs")) {
- copy("$root/$hs", "$root/gophermap");
- $dt = new DateTime("now", new DateTimeZone('Europe/Paris'));
- file_put_contents("$root/gophermap", "last update: ".$dt->format('Y-m-d H:i:s')."\n\n", FILE_APPEND);
+ copy("$root/$hs", "$root/gophermap");
+ $dt = new DateTime("now", new DateTimeZone('Europe/Paris'));
+ file_put_contents("$root/gophermap", "last update: ".$dt->format('Y-m-d H:i:s')."\n\n", FILE_APPEND);
}
foreach ($dir as $subdir) {
- # get feed settings from directory
- if (!file_exists("$subdir/$fs")) continue;
- if (!file_exists("$subdir/$ts")) continue;
+ # get feed settings from directory
+ if (!file_exists("$subdir/$fs")) continue;
+ if (!file_exists("$subdir/$ts")) continue;
$feeditemtitle = fgets(fopen("$subdir/$ts", 'r'));
$feeditemtitle = str_replace("\n", '', $feeditemtitle);
@@ -32,29 +32,29 @@ foreach ($dir as $subdir) {
$itemlist = "RSS feed : " . $feedurl."\n\n";
// new instance of simplepie
- $feed = new SimplePie();
+ $feed = new SimplePie();
- // simplepie can't recuperate a gopher url
- // so we use curl in this case
- $gopher = 0;
+ // simplepie can't recuperate a gopher url
+ // so we use curl in this case
+ $gopher = 0;
if (str_starts_with($feedurl, "gopher")) {
- exec("curl $feedurl", $rssdata, $retval);
- if (!empty($rssdata)) {
- $rssstring=implode($rssdata);
- $feed->set_raw_data($rssstring);
- $gopher=1;
- }else{
- $itemlist .= "Error $retval retrieving $feedurl\n";
- }
+ exec("curl $feedurl", $rssdata, $retval);
+ if (!empty($rssdata)) {
+ $rssstring=implode($rssdata);
+ $feed->set_raw_data($rssstring);
+ $gopher=1;
+ }else{
+ $itemlist .= "Error $retval retrieving $feedurl\n";
+ }
}else{
- $feed->set_feed_url($feedurl);
+ $feed->set_feed_url($feedurl);
}
- // initialise simplepie
- $feed->set_cache_location($cache);
- $feed->enable_order_by_date(true);
- $feed->handle_content_type();
- $feed->init();
+ // initialise simplepie
+ $feed->set_cache_location($cache);
+ $feed->enable_order_by_date(true);
+ $feed->handle_content_type();
+ $feed->init();
// extract each feed item
$x=0;
@@ -72,33 +72,34 @@ foreach ($dir as $subdir) {
$port = parse_url($itemlink, PHP_URL_PORT);
$path = parse_url($itemlink, PHP_URL_PATH);
if (pathinfo($path, PATHINFO_EXTENSION)) {
- $itemlist .= "0".$itemdate." ".$itemtitle."\t".substr($path,2)."\t".$host."\t".$port."\n";
+ $itemlist .= "0".$itemdate." ".$itemtitle."\t".substr($path,2)."\t".$host."\t".$port."\n";
}else{
- $itemlist .= "1".$itemdate." ".$itemtitle."\t".substr($path,2)."\t".$host."\t".$port."\n";
+ $itemlist .= "1".$itemdate." ".$itemtitle."\t".substr($path,2)."\t".$host."\t".$port."\n";
}
}else{
- // convert rss youtube url to youtu.be url
- $itemlink = str_replace("www.youtube.com/watch?v=", "youtu.be/", $itemlink);
- $itemlist .= "h".$itemdate." ".$itemtitle."\tURL:".$itemlink."\n";
+ // convert rss youtube url to youtu.be url
+ $itemlink = str_replace("www.youtube.com/watch?v=", "youtu.be/", $itemlink);
+ $itemlist .= "h".$itemdate." ".$itemtitle."\tURL:".$itemlink."\n";
}
$x++;
}
- // build list of feed items
- if ($x==0) {
- $itemlist .= "! Error - No items found\n\n";
- $itemlist .= "DEBUG\n";
- $itemlist .= "curl $feedurl\n";
- $itemlist .= "result:\n";
- $itemlist .= $rssstring;
- $itemlist .= "\nEOF\n";
- }
- file_put_contents("$subdir/gophermap", $itemlist);
+ // build list of feed items
+ if ($x==0) {
+ $itemlist .= "! Error - No items found\n\n";
+ $itemlist .= "DEBUG\n";
+ $itemlist .= "curl $feedurl\n";
+ $itemlist .= "result:\n";
+ $itemlist .= $rssstring;
+ $itemlist .= "\nEOF\n";
+ }
+ file_put_contents("$subdir/gophermap", $itemlist);
// build list of feeds
- $feedname = "1".$feeditemtitle."\t".basename($subdir)."\n";
- file_put_contents("$root/gophermap", $feedname, FILE_APPEND);
+ $feedname = "1".$feeditemtitle."\t".basename($subdir)."\n";
+ file_put_contents("$root/gophermap", $feedname, FILE_APPEND);
+ // reset
unset($rssstring);
unset($rssdata);
unset($sfeed);