From a2fccc011b979aab1585a989790cee4c9f4d2c2c Mon Sep 17 00:00:00 2001 From: azaozz Date: Sat, 7 Mar 2009 19:44:28 +0000 Subject: [PATCH] Add RSS Error handling functionality to RSS Widget displays, props DD32, fixes #9273 git-svn-id: http://svn.automattic.com/wordpress/trunk@10739 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/dashboard.php | 16 +++++++++++++-- wp-includes/widgets.php | 35 ++++++++++++++++----------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index 7f9104688..cd3dd7d80 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -603,6 +603,15 @@ function wp_dashboard_incoming_links_output() { @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP ); $rss = fetch_feed( $url ); + if ( is_wp_error($rss) ) { + if ( is_admin() || current_user_can('manage_options') ) { + echo '

'; + printf(__('RSS Error: %s'), $rss->get_error_message()); + echo '

'; + } + return; + } + if ( !$rss->get_item_quantity() ) { echo '

' . __('This dashboard widget queries Google Blog Search so that when another blog links to your site it will show up here. It has found no incoming links… yet. It’s okay — there is no rush.') . "

\n"; return; @@ -740,7 +749,7 @@ function wp_dashboard_plugins_output() { } foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) { - if ( !$$feed->get_item_quantity() ) + if ( is_wp_error($$feed) || !$$feed->get_item_quantity() ) continue; $items = $$feed->get_items(0, 5); @@ -898,7 +907,10 @@ function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) { // title is optional. If black, fill it if possible if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) { $rss = fetch_feed($widget_options[$widget_id]['url']); - $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title())); + if ( ! is_wp_error($rss) ) + $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title())); + else + $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed')); } update_option( 'dashboard_widget_options', $widget_options ); } diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index 408279712..641c19142 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -1541,29 +1541,30 @@ function wp_widget_rss($args, $widget_args = 1) { return; $url = $options[$number]['url']; - while ( strstr($url, 'http') != $url ) + while ( stristr($url, 'http') != $url ) $url = substr($url, 1); if ( empty($url) ) return; $rss = fetch_feed($url); - $link = clean_url(strip_tags($rss->get_permalink())); - while ( strstr($link, 'http') != $link ) - $link = substr($link, 1); - $desc = attribute_escape(strip_tags(html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset')))); $title = $options[$number]['title']; - if ( empty($title) ) - $title = htmlentities(strip_tags($rss->get_title())); + $desc = ''; + $link = ''; + if ( ! is_wp_error($rss) ) { + $desc = attribute_escape(strip_tags(html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset')))); + if ( empty($title) ) + $title = htmlentities(strip_tags($rss->get_title())); + $link = clean_url(strip_tags($rss->get_permalink())); + while ( stristr($link, 'http') != $link ) + $link = substr($link, 1); + } if ( empty($title) ) $title = $desc; if ( empty($title) ) $title = __('Unknown Feed'); $title = apply_filters('widget_title', $title ); $url = clean_url(strip_tags($url)); - if ( file_exists(dirname(__FILE__) . '/rss.png') ) - $icon = str_replace(ABSPATH, site_url() . '/', dirname(__FILE__)) . '/rss.png'; - else - $icon = includes_url('images/rss.png'); + $icon = includes_url('images/rss.png'); $title = "RSS $title"; echo $before_widget; @@ -1584,12 +1585,10 @@ function wp_widget_rss($args, $widget_args = 1) { */ function wp_widget_rss_output( $rss, $args = array() ) { if ( is_string( $rss ) ) { - if ( !$rss = fetch_feed($rss) ) - return; + $rss = fetch_feed($rss); } elseif ( is_array($rss) && isset($rss['url']) ) { $args = $rss; - if ( !$rss = fetch_feed($rss['url']) ) - return; + $rss = fetch_feed($rss['url']); } elseif ( !is_object($rss) ) { return; } @@ -1622,7 +1621,7 @@ function wp_widget_rss_output( $rss, $args = array() ) { echo '