But the problem is that I told it to only look for new headers after certain time (after 3 hours), but every time i load the page, it refreshes it. (I noticed it because my cache files are always updated whenver i load the page)
I don't like this because I don't want to be a bastard to the sites and keep requesting from them every minute. Everybody in my house uses the news page to get quick links, so I would hate to waste the sites bandwidth.
Can someone look at the code and tell me if there is a solution to it?
Code: Select all
<?php
// InsertRDF Documentation
// InsertRDF($url, $cache_file, $description = true, $max = 10, $cache_time = 3600)
//
// This is file has a function, InsertRDF, to insert a RDF feed into your website
//
// Just copy the URL of the RDF and paste it as the first agrument and then
// create an unique file name for the second agrument. The other arguments are
// optional.
//
// A third agrument of TRUE can be added if you want to see descriptions of the news
// stories, something some RDF news sources provide. It trys to show descriptions by default.
//
// $max is the maximum number of items to be displayed. It is 10 by default.
// $cache_time is the amount of time in seconds that has to pass before it downloads a
// new version instead of using the cache. Its an hour be default. You probably shouldn't
// make this any lower, as I've read it could get your IP banned.
//
// Examples:
// PHP for Freshmeat.net:
// <?
// include("rdf.php");
// InsertRDF("http://freshmeat.net/backend/fm.rdf", "/tmp/freshmeat.net.cache");
// ?>
// PHP for BBC World (with news descriptions):
// <?
// include("rdf.php");
// InsertRDF("http://www.newsisfree.com/HPE/xml/feeds/60/60.xml", "/tmp/bbcworld.cache", TRUE);
// ?>
// Some of the code (such as the stuff deciding whether or not to download
// a new version) comes from the freshmeat.php3 located at http://swamp.chl.chalmers.se/backends/
//
// The closest thing this script has to a homepage would be http://ian.webhop.org/projects.php
//Two general purpose functions
function FindLength($AString) //from some comments from the docs at http://www.php.net
{
foreach (count_chars($AString) as $my_value) $length=$length+$my_value;
return $length;
}
//I'm used to REBOL text parsing. PHP probably has better ways of doing this.
function ParseIt($begin, $end, $haystack, $offset = 0)
{
$StartPos = strpos($haystack, $begin, $offset);
$EndPos = strpos($haystack, $end, $offset);
$ParsedLength = $EndPos - $StartPos;
//$returnthis = substr($haystack, $StartPos, $ParsedLength);
$offset=$EndPos + FindLength($end);
return substr($haystack, $StartPos, $ParsedLength);
}
//You change the default values here
function InsertRDF($url, $cache_file, $description = false, $max = 5, $cache_time = 10800)
{
$cache_time_rnd = 300 - rand(0, 600);
$time = split(" ", microtime());
if ( (!(file_exists($cache_file))) || ((filectime($cache_file) + $cache_time - $timeї1]) +
$cache_time_rnd < 0) || (!(filesize($cache_file))) )
{
//Put file in string
$rdf = join ('', file ($url));
$fcache = fopen($cache_file, "w");
fputs($fcache, "<br>");
if(substr_count($rdf, "<item") < $max)
{
$max = substr_count($rdf, "<item");
}
$ItemArray = Array();
//get items
$offset = 0;
for($i=1; $i<=$max; $i++)
{
$ItemArrayї$i] = ParseIt("<item", "</item>", $rdf, &$offset);
}
$TitleArray = Array();
$LinkArray = Array();
$DescriptionArray = Array();
$nobug = true; //Get around a bug in some newsisfree.com RDFs
if(strpos($rdf, "</link>"))
{
$nobug = true;
}
else
{
$nobug = false;
}
for($i=1; $i<=$max; $i++)
{
$TitleArrayї$i] = strip_tags(ParseIt("<title>", "</title>", $ItemArrayї$i]));
if($nobug)
{
$LinkArrayї$i] = strip_tags(ParseIt("<link>", "</link>", $ItemArrayї$i]));
}
else
{
$LinkArrayї$i] = strip_tags(ParseIt("<link>", "<description>", $ItemArrayї$i]));
}
$DescriptionArrayї$i] = strip_tags(ParseIt("<description>", "</description>", $ItemArrayї$i]));
fputs($fcache, "<div class=news><img src="images/square.gif" align="absmiddle"> <a href="$LinkArrayї$i]">$TitleArrayї$i]</a></div>");
if($description) fputs($fcache, " $DescriptionArrayї$i]\n");
}
fputs($fcache, "\n");
fclose($fcache);
}
if (file_exists($cache_file)) {
include($cache_file);
}
}
?>IcE.