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='
'; if (strlen($options[$number]['summary'])) { $output.='

'; $output.=$options[$number]['summary'].'

'; } $output.='
'; //save output in cache $fp=fopen($cache, 'w'); fwrite($fp, $output); fclose($fp); } } else { $output=file_get_contents($cache); } //we we go $title=$options[$number]['title']; echo $before_widget; $title ? print($before_title . $title . $after_title) : null; echo $output; echo $after_widget; return; } function widget_lordelph_rss_control($number=1) { $options = $newoptions = get_option('lordelph_rss'); if ( $_POST["lordelph-rss-submit-$number"] ) { $newoptions[$number]['items'] = (int) $_POST["lordelph-rss-items-$number"]; $url = clean_url(strip_tags(stripslashes($_POST["lordelph-rss-url-$number"]))); $newoptions[$number]['title'] = trim(strip_tags(stripslashes($_POST["lordelph-rss-title-$number"]))); $newoptions[$number]['summary'] = trim(strip_tags(stripslashes($_POST["lordelph-rss-summary-$number"]))); if ( $url !== $options[$number]['url'] ) { require_once(ABSPATH . WPINC . '/rss.php'); $rss = fetch_rss($url); if ( is_object($rss) ) { $newoptions[$number]['url'] = $url; $newoptions[$number]['error'] = false; } else { $newoptions[$number]['error'] = true; $newoptions[$number]['url'] = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1); $error = sprintf(__('Error in RSS %1$d: %2$s'), $number, $newoptions[$number]['error']); } } //flush the cache too $cache=widget_lordelph_rss_cachefile($number); if (file_exists($cache)) unlink($cache); } if ( $options != $newoptions ) { $options = $newoptions; update_option('lordelph_rss', $options); } $url = attribute_escape($options[$number]['url']); $items = (int) $options[$number]['items']; $title = attribute_escape($options[$number]['title']); $summary = attribute_escape($options[$number]['summary']); if ( empty($items) || $items < 1 ) $items = 10; ?>

" name="lordelph-rss-url-" type="text" value="" />

" name="lordelph-rss-title-" type="text" value="" />

" name="lordelph-rss-summary-" type="text" value="" />

" name="lordelph-rss-submit-" value="1" />