Make WordPress Core


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.