parser = xml_parser_create(); xml_set_object($this->parser,$this); xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($this->parser,"tag_open","tag_close"); xml_set_character_data_handler($this->parser,"cdata"); $this->path=""; $this->tree=array(); xml_parse($this->parser,$data); } function tag_open($parser,$tag,$attributes) { if ($tag=='entry') { $this->entry[$this->entryidx]=array(); $this->entry[$this->entryidx]['attributes']=$attributes; } if (strlen($this->path)) $this->path=$this->path."/".strtolower($tag); else $this->path=strtolower($tag); if ($this->path=='feed/entry/title') { $this->entry[$this->entryidx]['title']=''; } if ($this->path=='feed/entry/summary') { $this->entry[$this->entryidx]['summary']=''; } if ($this->path=='feed/entry/link') { $this->entry[$this->entryidx]['url']=$attributes['href']; } if ($this->path=='feed/entry/source/title') { $this->entry[$this->entryidx]['source']=''; } if ($this->path=='feed/entry/source/link') { $this->entry[$this->entryidx]['sourceurl']=$attributes['href']; } } function cdata($parser,$cdata) { if ($this->path=='feed/entry/title') { $this->entry[$this->entryidx]['title'].=$cdata; } if ($this->path=='feed/entry/summary') { $this->entry[$this->entryidx]['summary'].=$cdata; } if ($this->path=='feed/entry/source/title') { $this->entry[$this->entryidx]['source'].=$cdata; } } function tag_close($parser,$tag) { $len=strlen($this->path) - (strlen($tag) + 1); $this->path=substr($this->path, 0, $len); if ($tag=='entry') { $this->entryidx++; } } function get_tag($path) { return $this->tree[strtolower($path)]; } } //returns path to cached HTML function widget_lordelph_rss_cachefile($number) { return "/tmp/lordelph_rss_{$number}.html"; } function widget_lordelph_rss($args, $number = 1) { extract($args); $options = get_option('lordelph_rss'); if ( isset($options['error']) && $options['error'] ) return; $num_items = (int) $options[$number]['items']; $show_summary = $options[$number]['show_summary']; if ( empty($num_items) || $num_items < 1 || $num_items > 10 ) $num_items = 10; $url = $options[$number]['url']; while ( strstr($url, 'http') != $url ) $url = substr($url, 1); if ( empty($url) ) return; $count=$options[$number]['items']; //do we have a cached file? $cache=widget_lordelph_rss_cachefile($number); $mtime=0; if (file_exists($cache)) $mtime=filemtime($cache); $age=time()-$mtime; //cache for 4 hours if ($age>(3600*4)) { $xml=file_get_contents($url); if (strlen($xml)) { //parse it $parser=new XMLParser; $parser->parse($xml); //create output $output='
';
$output.=$options[$number]['summary'].'
" name="lordelph-rss-submit-" value="1" />