', $data);
+ }
+ }
+
+ if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML))
+ {
+ // Strip comments
+ if ($this->strip_comments)
+ {
+ $data = SimplePie_Misc::strip_comments($data);
+ }
+
+ // Strip out HTML tags and attributes that might cause various security problems.
+ // Based on recommendations by Mark Pilgrim at:
+ // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
+ if ($this->strip_htmltags)
+ {
+ foreach ($this->strip_htmltags as $tag)
+ {
+ $pcre = "/<($tag)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$tag" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>|(\/)?>)/siU';
+ while (preg_match($pcre, $data))
+ {
+ $data = preg_replace_callback($pcre, array(&$this, 'do_strip_htmltags'), $data);
+ }
+ }
+ }
+
+ if ($this->strip_attributes)
+ {
+ foreach ($this->strip_attributes as $attrib)
+ {
+ $data = preg_replace('/ '. trim($attrib) .'=("|")(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\'|'|<|>|\+|{|})*("|")/i', '', $data);
+ $data = preg_replace('/ '. trim($attrib) .'=(\'|')(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|"|"|<|>|\+|{|})*(\'|')/i', '', $data);
+ $data = preg_replace('/ '. trim($attrib) .'=(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\+|{|})*/i', '', $data);
+ }
+ }
+
+ // Replace relative URLs
+ $this->base = $base;
+ foreach ($this->replace_url_attributes as $element => $attribute)
+ {
+ if ((!is_array($this->strip_htmltags) || !in_array($element, $this->strip_htmltags)) && (!is_array($this->strip_attributes) || !in_array($attribute, $this->strip_attributes)))
+ {
+ $data = $this->replace_urls($data, $element, $attribute);
+ }
+ }
+
+ // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
+ if (isset($this->image_handler) && !empty($this->image_handler) && $this->enable_cache)
+ {
+ $images = SimplePie_Misc::get_element('img', $data);
+ foreach ($images as $img)
+ {
+ if (!empty($img['attribs']['src']['data']))
+ {
+ $image_url = $img['attribs']['src']['data'];
+ $cache =& new $this->cache_class($this->cache_location, call_user_func($this->cache_name_function, $image_url), 'spi');
+
+ if ($cache->load())
+ {
+ $img['attribs']['src']['data'] = $this->image_handler . rawurlencode($img['attribs']['src']['data']);
+ $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
+ }
+ else
+ {
+ $file =& new $this->file_class($image_url, $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen);
+ $headers = $file->headers;
+
+ if ($file->success && ($file->status_code == 200 || ($file->status_code > 206 && $file->status_code < 300)))
+ {
+ if (!$cache->save(array('headers' => $file->headers, 'body' => $file->body)))
+ {
+ trigger_error("$cache->name is not writeable", E_USER_WARNING);
+ }
+ $img['attribs']['src']['data'] = $this->image_handler . rawurlencode($img['attribs']['src']['data']);
+ $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
+ }
+ }
+ }
+ }
+ }
+
+ // Having (possibly) taken stuff out, there may now be whitespace at the beginning/end of the data
+ $data = trim($data);
+ }
+
+ if ($type & SIMPLEPIE_CONSTRUCT_IRI)
+ {
+ $data = SimplePie_Misc::absolutize_url($data, $base);
+ }
+
+ if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
+ {
+ $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
+ }
+
+ if ($this->output_encoding != 'UTF-8')
+ {
+ $data = SimplePie_Misc::change_encoding($data, 'UTF-8', $this->output_encoding);
+ }
+ }
+ return $data;
+ }
+
+ function replace_urls($data, $tag, $attribute)
+ {
+ $elements = SimplePie_Misc::get_element($tag, $data);
+ foreach ($elements as $element)
+ {
+ if (isset($element['attribs'][$attribute]['data']))
+ {
+ $element['attribs'][$attribute]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attribute]['data'], $this->base);
+ $data = str_replace($element['full'], SimplePie_Misc::element_implode($element), $data);
+ }
+ }
+ return $data;
+ }
+
+ function do_strip_htmltags($match)
+ {
+ if ($this->encode_instead_of_strip)
+ {
+ if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
+ {
+ $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
+ $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
+ return "<$match[1]$match[2]>$match[3]</$match[1]>";
+ }
+ else
+ {
+ return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
+ }
+ }
+ else
+ {
+ if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
+ {
+ return $match[4];
+ }
+ else
+ {
+ return '';
+ }
+ }
+ }
+}
+
+/* Magpie function backported for Simplepie */
+function fetch_rss ($url) {
+ $rss = new SimplePie($url);
+ $rss->enable_cache(false);
+ return $rss;
+} // end fetch_rss()
+
+
function wp_rss( $url, $num_items = -1 ) {
- if ( $rss = fetch_rss( $url ) ) {
+ // Provide new default for Simplepie
+ if(-1 == $num_items )
+ $num_items = 0;
+
+ if ( $rss = new SimplePie($url) ) {
+ $rss->enable_cache(false);
echo '
';
- if ( $num_items !== -1 ) {
- $rss->items = array_slice( $rss->items, 0, $num_items );
+ if ( $num_items !== 0 ) {
+ $items = $rss->get_items(0, $num_items);
}
- foreach ( $rss->items as $item ) {
+ foreach ( $items as $item ) {
printf(
'- %3$s
',
- clean_url( $item['link'] ),
- attribute_escape( strip_tags( $item['description'] ) ),
- htmlentities( $item['title'] )
+ clean_url( $item->get_link() ),
+ attribute_escape( strip_tags( $item->get_description() ) ),
+ htmlentities( $item->get_title() )
);
}
@@ -841,13 +10563,14 @@
}
function get_rss ($url, $num_items = 5) { // Like get posts, but for RSS
- $rss = fetch_rss($url);
+ $rss = new SimplePie( $url );
+ $rss->enable_cache(false);
if ( $rss ) {
- $rss->items = array_slice($rss->items, 0, $num_items);
- foreach ($rss->items as $item ) {
+ $items = $rss->get_items(0, $num_items);
+ foreach ( $items as $item ) {
echo "- \n";
- echo "";
- echo htmlentities($item['title']);
+ echo '';
+ echo htmlentities( $item->get_title() );
echo "
\n";
echo " \n";
}
Index: wp-admin/index-extra.php
===================================================================
--- wp-admin/index-extra.php (revision 5767)
+++ wp-admin/index-extra.php (working copy)
@@ -7,16 +7,17 @@
switch ( $_GET['jax'] ) {
case 'incominglinks' :
-$rss = @fetch_rss(apply_filters( 'dashboard_incoming_links_feed', 'http://feeds.technorati.com/cosmos/rss/?url='. trailingslashit(get_option('home')) .'&partner=wordpress' ));
-if ( isset($rss->items) && 1 < count($rss->items) ) { // Technorati returns a 1-item feed when it has no results
+$rss = new SimplePie( (apply_filters( 'dashboard_incoming_links_feed', 'http://feeds.technorati.com/cosmos/rss/?url='. trailingslashit(get_option('home')) .'&partner=wordpress' ) ), ABSPATH . '/wp-content/rsscache', ABSPATH . '/wp-content/rsscache' );
+$rss->enable_cache(false);
+if (1 < count($rss->get_items() ) ) { // Technorati returns a 1-item feed when it has no results
?>
items = array_slice($rss->items, 0, 10);
-foreach ($rss->items as $item ) {
+$items = $rss->get_items(0, 10);
+foreach ($items as $item ) {
?>
-
+ - get_title() ) ); ?>
items) && 0 != count($rss->items) ) {
+$rss = new SimplePie( apply_filters( 'dashboard_primary_feed', 'http://wordpress.org/development/feed/' ), ABSPATH . '/wp-content/rsscache' );
+$rss->enable_cache(false);
+if ( 0 != count($rss->get_items() ) ) {
?>
items = array_slice($rss->items, 0, 3);
-foreach ($rss->items as $item ) {
+$items = $rss->get_items(0, 3);
+foreach ($items as $item ) {
?>
-
-
+
+get_description(); ?>
items) && 0 != count($rss->items) ) {
+$rss = new SimplePie( apply_filters( 'dashboard_secondary_feed', 'http://planet.wordpress.org/feed/' ), ABSPATH . '/wp-content/rsscache' );
+
+if ( 0 != count($rss->get_items() ) ) {
?>
items = array_slice($rss->items, 0, 20);
-foreach ($rss->items as $item ) {
-$title = wp_specialchars($item['title']);
-$author = preg_replace( '|(.+?):.+|s', '$1', $item['title'] );
-$post = preg_replace( '|.+?:(.+)|s', '$1', $item['title'] );
+$items = $rss->get_items(0, 20);
+foreach ($items as $item ) {
+$title = wp_specialchars($item->get_title() );
+$author = preg_replace( '|(.+?):.+|s', '$1', $item->get_title() );
+$post = preg_replace( '|.+?:(.+)|s', '$1', $item->get_title() );
?>
-- '> -
+- -