WordPress.org

Make WordPress Core

Changeset 10739


Ignore:
Timestamp:
03/07/2009 07:44:28 PM (9 years ago)
Author:
azaozz
Message:

Add RSS Error handling functionality to RSS Widget displays, props DD32, fixes #9273

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/dashboard.php

    r10738 r10739  
    604604    $rss = fetch_feed( $url );
    605605
     606    if ( is_wp_error($rss) ) {
     607        if ( is_admin() || current_user_can('manage_options') ) {
     608            echo '<p>';
     609            printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
     610            echo '</p>';
     611        }
     612        return;
     613    }
     614
    606615    if ( !$rss->get_item_quantity() ) {
    607616        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";
     
    741750
    742751    foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
    743         if ( !$$feed->get_item_quantity() )
     752        if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
    744753            continue;
    745754
     
    899908        if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
    900909            $rss = fetch_feed($widget_options[$widget_id]['url']);
    901             $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
     910            if ( ! is_wp_error($rss) )
     911                $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
     912            else
     913                $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
    902914        }
    903915        update_option( 'dashboard_widget_options', $widget_options );
  • trunk/wp-includes/widgets.php

    r10712 r10739  
    15421542
    15431543    $url = $options[$number]['url'];
    1544     while ( strstr($url, 'http') != $url )
     1544    while ( stristr($url, 'http') != $url )
    15451545        $url = substr($url, 1);
    15461546    if ( empty($url) )
     
    15481548
    15491549    $rss = fetch_feed($url);
    1550     $link = clean_url(strip_tags($rss->get_permalink()));
    1551     while ( strstr($link, 'http') != $link )
    1552         $link = substr($link, 1);
    1553     $desc = attribute_escape(strip_tags(html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
    15541550    $title = $options[$number]['title'];
    1555     if ( empty($title) )
    1556         $title = htmlentities(strip_tags($rss->get_title()));
     1551    $desc = '';
     1552    $link = '';
     1553    if ( ! is_wp_error($rss) ) {
     1554        $desc = attribute_escape(strip_tags(html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
     1555        if ( empty($title) )
     1556            $title = htmlentities(strip_tags($rss->get_title()));
     1557        $link = clean_url(strip_tags($rss->get_permalink()));
     1558        while ( stristr($link, 'http') != $link )
     1559            $link = substr($link, 1);
     1560    }
    15571561    if ( empty($title) )
    15581562        $title = $desc;
     
    15611565    $title = apply_filters('widget_title', $title );
    15621566    $url = clean_url(strip_tags($url));
    1563     if ( file_exists(dirname(__FILE__) . '/rss.png') )
    1564         $icon = str_replace(ABSPATH, site_url() . '/', dirname(__FILE__)) . '/rss.png';
    1565     else
    1566         $icon = includes_url('images/rss.png');
     1567    $icon = includes_url('images/rss.png');
    15671568    $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>";
    15681569
     
    15851586function wp_widget_rss_output( $rss, $args = array() ) {
    15861587    if ( is_string( $rss ) ) {
    1587         if ( !$rss = fetch_feed($rss) )
    1588             return;
     1588        $rss = fetch_feed($rss);
    15891589    } elseif ( is_array($rss) && isset($rss['url']) ) {
    15901590        $args = $rss;
    1591         if ( !$rss = fetch_feed($rss['url']) )
    1592             return;
     1591        $rss = fetch_feed($rss['url']);
    15931592    } elseif ( !is_object($rss) ) {
    15941593        return;
     
    16231622    foreach ( $rss->get_items(0, $items) as $item ) {
    16241623        $link = $item->get_link();
    1625         while ( strstr($link, 'http') != $link )
     1624        while ( stristr($link, 'http') != $link )
    16261625            $link = substr($link, 1);
    16271626        $link = clean_url(strip_tags($link));
     
    18551854        $error = false;
    18561855        $link = '';
    1857         if ( !is_object($rss) ) {
     1856        if ( is_wp_error($rss) ) {
    18581857            $url = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1);
    18591858            $error = sprintf(__('Error in RSS %1$d'), $widget_number );
    18601859        } else {
    18611860            $link = clean_url(strip_tags($rss->get_permalink()));
    1862             while ( strstr($link, 'http') != $link )
     1861            while ( stristr($link, 'http') != $link )
    18631862                $link = substr($link, 1);
    18641863        }
Note: See TracChangeset for help on using the changeset viewer.