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
This commit is contained in:
azaozz 2009-03-07 19:44:28 +00:00
parent 98462ab1b6
commit a2fccc011b
2 changed files with 31 additions and 20 deletions

View File

@ -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 '<p>';
printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
echo '</p>';
}
return;
}
if ( !$rss->get_item_quantity() ) {
echo '<p>' . __('This dashboard widget queries <a href="http://blogsearch.google.com/">Google Blog Search</a> so that when another blog links to your site it will show up here. It has found no incoming links&hellip; yet. It&#8217;s okay &#8212; there is no rush.') . "</p>\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 );
}

View File

@ -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 = "<a class='rsswidget' href='$url' title='" . attribute_escape(__('Syndicate this content')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
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 '<ul>';
foreach ( $rss->get_items(0, $items) as $item ) {
$link = $item->get_link();
while ( strstr($link, 'http') != $link )
while ( stristr($link, 'http') != $link )
$link = substr($link, 1);
$link = clean_url(strip_tags($link));
$title = attribute_escape(strip_tags($item->get_title()));
@ -1854,12 +1853,12 @@ function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
$rss = fetch_feed($url);
$error = false;
$link = '';
if ( !is_object($rss) ) {
if ( is_wp_error($rss) ) {
$url = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1);
$error = sprintf(__('Error in RSS %1$d'), $widget_number );
} else {
$link = clean_url(strip_tags($rss->get_permalink()));
while ( strstr($link, 'http') != $link )
while ( stristr($link, 'http') != $link )
$link = substr($link, 1);
}
}