format('Y-m-d H:i:s')."\n\n", FILE_APPEND); } // iterate through feed directories foreach ($dir as $subdir) { # 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); $feedurl = fgets(fopen("$subdir/$fs", 'r')); $feedurl = str_replace("\n", '', $feedurl); // feed list header $itemlist = "RSS feed : " . $feedurl."\n\n"; // new instance of simplepie $feed = new SimplePie(); // 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"; } }else{ $feed->set_feed_url($feedurl); } // 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; foreach ($feed->get_items(0, 30) as $item) { $itemlink = $item->get_permalink(); $itemtitle = $item->get_title(); $itemdate = $item->get_date("Y-m-d"); if (empty($itemtitle)) $itemtitle="No itemtitle found"; // build item link if ($gopher==1) { $host = parse_url($itemlink, PHP_URL_HOST); $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"; }else{ $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"; } $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 feeds $feedname = "1".$feeditemtitle."\t".basename($subdir)."\n"; file_put_contents("$root/gophermap", $feedname, FILE_APPEND); // reset unset($rssstring); unset($rssdata); unset($sfeed); unset($itemlist); } ?>