"; }
$cache_path = $upload_path . 'feeder_' . substr(md5($filename), 0, 8) . '.xml'; //Prefix a Random String Made from the Filename
if ($filep) //Check if the Feed is Readable, See Line 106..
{
//Validate all the Function Variables and set Default Values
$this->prefix = "...";
$this->tag1 = ($tag1 == "") ? "
" : $tag1;
$this->tag2 = ($tag2 == "") ? "
" : $tag2;
$this->numchars = ($numchars == 0 or !is_integer($numchars) or $numchars < 1) ? 32 : $numchars;
$this->numlinks = ($numlinks == 0 or !is_integer($numlinks) or $numlinks < 1) ? 10 : $numlinks;
$this->link_class = ($link_class == "") ? "feeder-link" : $link_class;
$this->link_target = ($link_target == "" or ($link_target != "_self" and $link_target != "_blank")) ? "_self" : $link_target;
$update_time = ($update_time == 0 or !is_integer($update_time) or $update_time < 60) ? 3600 : $update_time;
$cache = ($cache == 1) ? 1 : 0;
if ($cache == 1) //If Cache is Enabled
{
$feed_file = $cache_path;
if (file_exists($cache_path)) //If the Feed was already Cached
{
//Get the Cache and Current Time (UNIX_TIMESTAMP)
$file_timestamp = filemtime($cache_path);
$current_timestamp = time();
$time_difference = $current_timestamp - $file_timestamp;
if ($time_difference >= $update_time) //Check whether the cache is deprecated (a simple validation Uh?)
{
$cached = false; //Its Deprecated, so set Cached as False
}
else
{
$cached = true; //Quite New, No Need to Update the Cache
}
}
else //Cache Doesn't Exist, Create it..
{
$cached = false;
}
if (!$cached) //The file is NOT Cached, so Create it.
{
if (file_exists($cache_path)) { unlink($cache_path); } //Unlink the old Cache to Update it.
$feeder_xml = "\r"; //Start Creating the Cache Content
$feeder_xml .= "\r";
$feeder_xml .= "\r";
$feed_array = $this->readFeed($filename, "item"); //Parse the Feed into the Cache
if ($feed_array != "")
{
foreach ($feed_array as $array) //Add XML Elements
{
$link = $array['link'];
$title = $this->clean_title($array['title']);
$feeder_xml .= sprintf("\n\t%s\n\t%s\n\r", $title, $link);
}
}
else //Could not parse the feed, So Display a Error
{
echo "\n
";
$bad_feed = 1;
}
$feeder_xml .= "";
if (!isset($bad_feed) and $bad_feed != 1) //If There was no error, Continue
{
error_reporting(0); //If only PHP(5) had a better working try-catch Method.. :-/
if ($cachep = fopen($cache_path, "w")) //Write the Cache to the File
{
fputs($cachep, $feeder_xml);
fclose($cachep);
echo "\t";
$cached = true;
}
else //Could not Write, Display Error, Set Cached as False
{
echo "\n
";
$cached = false;
}
error_reporting(E_ALL & ~E_NOTICE);
}
else //Error in the Given Feed, Set Cached as False
{
$cached = false;
}
}
}
if ($cached) //Check if Cached is True, Parse the Links from the Cache
{
$feed_array = $this->readFeed($feed_file, "url");
if ($feed_array != "")
{
$links_shown = $this->process_data($feed_array);
echo "\t";
}
else //No Data in Cache, set Cached as False and Continue
{
$cached = false;
}
}
if ($cache != 1 or !$cached) //Cache is Disabled and Cached is False
{
if (file_exists($cache_path)) { unlink($cache_path); } //Delete the Cache, Create it later (Failproof Method)
$feed_array = $this->readFeed($filename, "item");
if ($feed_array != "")
{
$links_shown = $this->process_data($feed_array);
echo "\t";
}
else //Throw some Errors....
{
echo "\n