$val) { if ($key == $xml_key) { $feedranges = $val; for ($i = 0; $i < count($feedranges); $i += 2) { $offset = $feedranges[$i] + 1; $len = $feedranges[$i + 1] - $offset; $fdb[] = $this->parseFeed(array_slice($values, $offset, $len)); } } else { continue; } } return $fdb; } function parseFeed($values) { for ($i = 0; $i < 2; $i++) { $feed[$values[$i]["tag"]] = $values[$i]["value"]; } return $feed; } function clean_title($title) //Clean the Titles of some unexpected characters.. Donno why those Appear :-/ { $title = trim($title); $title = stripslashes($title); $title = str_replace("’", "'", $title); $title = str_replace("â€", """, $title); $title = str_replace("œ", "", $title); $title = htmlspecialchars($title); return $title; } function process_data($feed_array) { $linkcount = 0; $linksshown = 1; $processed = array(); foreach($feed_array as $array) { $link = $array['link']; $title = $this->clean_title($array['title']); $tooltip = $title; $title = substr($title, 0, $this->numchars); //Limit the Number of Characters to be Shown in Title $title = (strlen($title) >= $this->numchars) ? ($title . $this->prefix) : $title; $processed[$linkcount] = sprintf("\t%s%s%s\n", $this->tag1, $link, $tooltip, $this->link_class, $this->link_target, $title, $this->tag2); $linkcount = $linkcount + 1; } foreach ($processed as $show_link) { if ($linksshown <= $this->numlinks) { echo $show_link; $linksshown = $linksshown + 1; } } return ($linksshown - 1); } function feeder($filename = "", $numlinks = 0, $tag1 = "", $tag2 = "", $link_class = "", $link_target = "", $numchars = 0, $cache = 0, $update_time = 0) //Class Constructor { if ($filename != "") //Check if the given Feed Path is Empty { error_reporting(0); $filep = fopen($filename, "r"); //Try to open it.. Throws a insane amount of errors if the server can't, //So Disable the Error Reporting for a While :-/ (Have a better Method??) error_reporting(E_ALL & ~E_NOTICE); //Assign the basic variables $cached = false; $feed_file; $upload_path = ABSPATH . 'wp-content/uploads/'; if (!is_dir($upload_path)) { echo "\n
  • Feeder: Upload Dir. Doesn't Exist
  • "; } $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
  • Feeder: Resource NOT a Feed
  • "; $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
  • Feeder: Cache Permission Denied
  • "; $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
  • Feeder: Resource NOT a Feed
  • "; } } } else { echo "\n
  • Feeder: (404) Feed not Found
  • "; } } else { echo "\n
  • Feeder: No URL Provided
  • "; } } } //Thats all folks! ?>