<?PHP
/*
RSSLIB 1.1
Modifications by Bob Zoller ( [email protected] ):
- use fsockopen() instead of fopen() to utilize timeouts
- fixed bug in makebullet() that caused output to break
- added code to customize the link list output a bit
- various configuation options added
- changed it to use PHP's parse_url() function, rather than my crappy egrep stuff ;)
Name Change by deltab ( [email protected] ):
- Thanks for the history lesson! rdflib was renamed to rsslib.
Usage example:
getrdf(" http://slashdot.org/slashdot.rdf" , 30);
listrdf("slashdot.rdf");
Where 30 is the number of minutes you wish to cache
the page for before making another request
The configuration options should explain themselves.
Bugs: None known.. please report to [email protected]
*/
$newsdir = "/home/www/htdocs/news/"; // store temp files here (make sure webserver has write permission!)
$timeout = 5; // number of seconds to wait for a connection
$font_face = "Lucida,Verdana,Helvetica,Arial"; //font face
$font_color = "#FFFFFF"; //font color
$link_color = ""; //link color
$font_size = "2"; //font size
function getrdf($rdf,$agelimit) {
global $newsdir, $timeout;
// convert agelimit to seconds
$agelimit *= 60;
$timestamp = filectime(basename($rdf));
$age = time() - $timestamp;
if($age > $agelimit) {
$url = parse_url($rdf);
$fp = fsockopen($url['host'], "80", &$errno, &$errstr, $timeout);
if (!$fp) return; //just quit on error
else {
$local = fopen($newsdir . basename($rdf), "w");
if (!$local) return; //just quit on error
fputs($fp, "GET /" . $url['path'] . " HTTP/1.0rnrn");
while(!feof($fp))
fwrite($local, fgets($fp, 128));
fclose($local);
}
}
}
function makebullet($item) {
global $font_face, $font_color, $font_size, $link_color;
$link = ereg_replace(".*<link>","",$item);
$link = ereg_replace("</link>.*","",$link);
$title = ereg_replace(".*<title>","",$item);
$title = ereg_replace("</title>.*","",$title);
if ($title)
echo "<font face="$font_face" color="$font_color" size="$font_size"><li></font><a href="$link"><font face="$font_face" color="$link_color" size="$font_size">$title</font></a>n";
}
function listrdf($rdf) {
global $newsdir;
$fp = fopen($newsdir . $rdf, "r");
if (!$fp) return; //just quit on error
$pagetext = fread($fp, filesize($newsdir . $rdf));
fclose($fp);
// kill the crud at the top and bottom
$pagetext = ereg_replace("<?xml.*/image>","",$pagetext);
$pagetext = ereg_replace("</rdf.*","",$pagetext);
$pagetext = chop($pagetext);
// make an array and walk it, printing out the item
$items = explode("</item>",$pagetext);
array_walk($items, 'makebullet');
}
?>
|