Add RSS Error handling functionality to RSS Widget displays, props DD32, fixes #9273
git-svn-id: https://develop.svn.wordpress.org/trunk@10739 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
53f495182a
commit
ec97268ea7
|
@ -603,6 +603,15 @@ function wp_dashboard_incoming_links_output() {
|
||||||
@extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
|
@extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
|
||||||
$rss = fetch_feed( $url );
|
$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() ) {
|
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… yet. It’s okay — there is no rush.') . "</p>\n";
|
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… yet. It’s okay — there is no rush.') . "</p>\n";
|
||||||
return;
|
return;
|
||||||
|
@ -740,7 +749,7 @@ function wp_dashboard_plugins_output() {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
|
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;
|
continue;
|
||||||
|
|
||||||
$items = $$feed->get_items(0, 5);
|
$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
|
// title is optional. If black, fill it if possible
|
||||||
if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
|
if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
|
||||||
$rss = fetch_feed($widget_options[$widget_id]['url']);
|
$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 );
|
update_option( 'dashboard_widget_options', $widget_options );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1541,29 +1541,30 @@ function wp_widget_rss($args, $widget_args = 1) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$url = $options[$number]['url'];
|
$url = $options[$number]['url'];
|
||||||
while ( strstr($url, 'http') != $url )
|
while ( stristr($url, 'http') != $url )
|
||||||
$url = substr($url, 1);
|
$url = substr($url, 1);
|
||||||
if ( empty($url) )
|
if ( empty($url) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$rss = fetch_feed($url);
|
$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'];
|
$title = $options[$number]['title'];
|
||||||
if ( empty($title) )
|
$desc = '';
|
||||||
$title = htmlentities(strip_tags($rss->get_title()));
|
$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) )
|
if ( empty($title) )
|
||||||
$title = $desc;
|
$title = $desc;
|
||||||
if ( empty($title) )
|
if ( empty($title) )
|
||||||
$title = __('Unknown Feed');
|
$title = __('Unknown Feed');
|
||||||
$title = apply_filters('widget_title', $title );
|
$title = apply_filters('widget_title', $title );
|
||||||
$url = clean_url(strip_tags($url));
|
$url = clean_url(strip_tags($url));
|
||||||
if ( file_exists(dirname(__FILE__) . '/rss.png') )
|
$icon = includes_url('images/rss.png');
|
||||||
$icon = str_replace(ABSPATH, site_url() . '/', dirname(__FILE__)) . '/rss.png';
|
|
||||||
else
|
|
||||||
$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>";
|
$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;
|
echo $before_widget;
|
||||||
|
@ -1584,12 +1585,10 @@ function wp_widget_rss($args, $widget_args = 1) {
|
||||||
*/
|
*/
|
||||||
function wp_widget_rss_output( $rss, $args = array() ) {
|
function wp_widget_rss_output( $rss, $args = array() ) {
|
||||||
if ( is_string( $rss ) ) {
|
if ( is_string( $rss ) ) {
|
||||||
if ( !$rss = fetch_feed($rss) )
|
$rss = fetch_feed($rss);
|
||||||
return;
|
|
||||||
} elseif ( is_array($rss) && isset($rss['url']) ) {
|
} elseif ( is_array($rss) && isset($rss['url']) ) {
|
||||||
$args = $rss;
|
$args = $rss;
|
||||||
if ( !$rss = fetch_feed($rss['url']) )
|
$rss = fetch_feed($rss['url']);
|
||||||
return;
|
|
||||||
} elseif ( !is_object($rss) ) {
|
} elseif ( !is_object($rss) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1622,7 +1621,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
|
||||||
echo '<ul>';
|
echo '<ul>';
|
||||||
foreach ( $rss->get_items(0, $items) as $item ) {
|
foreach ( $rss->get_items(0, $items) as $item ) {
|
||||||
$link = $item->get_link();
|
$link = $item->get_link();
|
||||||
while ( strstr($link, 'http') != $link )
|
while ( stristr($link, 'http') != $link )
|
||||||
$link = substr($link, 1);
|
$link = substr($link, 1);
|
||||||
$link = clean_url(strip_tags($link));
|
$link = clean_url(strip_tags($link));
|
||||||
$title = attribute_escape(strip_tags($item->get_title()));
|
$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);
|
$rss = fetch_feed($url);
|
||||||
$error = false;
|
$error = false;
|
||||||
$link = '';
|
$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);
|
$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 );
|
$error = sprintf(__('Error in RSS %1$d'), $widget_number );
|
||||||
} else {
|
} else {
|
||||||
$link = clean_url(strip_tags($rss->get_permalink()));
|
$link = clean_url(strip_tags($rss->get_permalink()));
|
||||||
while ( strstr($link, 'http') != $link )
|
while ( stristr($link, 'http') != $link )
|
||||||
$link = substr($link, 1);
|
$link = substr($link, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue