/* RSS Reader Class 1.0 Gregwiz RSS Reader is a simple RSS integration class Author: Suppakit Taethaweesap http://www.gregwiz.com License: GPL */ class RssReader{ var $xml_parser; var $rss_content; var $currentTag = ''; var $currentAttribs = ''; var $depth = 0; var $main; var $item_counter = 0; var $cache_dir = 'temp'; function Rss_Reader ($file) { $this->xml_parser = xml_parser_create(); xml_set_object($this->xml_parser, $this); xml_set_element_handler($this->xml_parser, startElement, endElement); xml_set_character_data_handler($this->xml_parser, characterData); if($this->cache_time > 0) { $usedcache = false; $cache_file = $this->cache_dir . '/rsscache_' . md5($file); if (file_exists($cache_file)) { $timedif = @(time() - filemtime($cache_file)); if ($timedif < $this->cache_time) { // cached file is fresh enough, return cached array $file = $cache_file; $usedcache = true; } } } if (!($fp = fopen($file, "r"))) { // die("could not open XML input"); } $read = ''; while ($data = fread($fp, 4096)) { if (!xml_parse($this->xml_parser, $data, feof($fp))) { // die(sprintf("XML error: %s at line %d", // xml_error_string(xml_get_error_code($this->xml_parser)), // xml_get_current_line_number($this->xml_parser))); } $read .= $data; } xml_parser_free($this->xml_parser); if($this->cache_time > 0) { if (!$usedcache) { if (file_exists($cache_file)) { unlink($cache_file); } $f = @fopen($cache_file, 'w'); fwrite ($f, $read); fclose($f); } } echo '