Ticket #9198: simplepie.diff

File simplepie.diff, 8.0 KB (added by ryan, 4 years ago)

Switch widgets over to simplepie. Caching not done yet. Assumes simplepie.inc in wp-includes

  • wp-includes/feed.php

     
    534534        return apply_filters( 'feed_content_type', $content_type, $type ); 
    535535} 
    536536 
     537function fetch_feed($url) { 
     538        require_once (ABSPATH . WPINC . '/simplepie.inc'); 
     539 
     540        $feed = new SimplePie(); 
     541        $feed->set_feed_url($url); 
     542        $feed->enable_cache(false); // TODO Create custom cache class that uses get_transient() and set_transient(). 
     543        $feed->init(); 
     544        $feed->handle_content_type(); 
     545 
     546        return $feed; 
     547} 
     548 
    537549?> 
  • wp-includes/widgets.php

     
    15011501        if ( empty($url) ) 
    15021502                return; 
    15031503 
    1504         require_once(ABSPATH . WPINC . '/rss.php'); 
    1505  
    1506         $rss = fetch_rss($url); 
    1507         $link = clean_url(strip_tags($rss->channel['link'])); 
     1504        $rss = fetch_feed($url); 
     1505        $link = clean_url(strip_tags($rss->get_permalink())); 
    15081506        while ( strstr($link, 'http') != $link ) 
    15091507                $link = substr($link, 1); 
    1510         $desc = attribute_escape(strip_tags(html_entity_decode($rss->channel['description'], ENT_QUOTES))); 
     1508        $desc = attribute_escape(strip_tags(html_entity_decode($rss->get_description(), ENT_QUOTES))); 
    15111509        $title = $options[$number]['title']; 
    15121510        if ( empty($title) ) 
    1513                 $title = htmlentities(strip_tags($rss->channel['title'])); 
     1511                $title = htmlentities(strip_tags($rss->get_title())); 
    15141512        if ( empty($title) ) 
    15151513                $title = $desc; 
    15161514        if ( empty($title) ) 
     
    15411539 */ 
    15421540function wp_widget_rss_output( $rss, $args = array() ) { 
    15431541        if ( is_string( $rss ) ) { 
    1544                 require_once(ABSPATH . WPINC . '/rss.php'); 
    1545                 if ( !$rss = fetch_rss($rss) ) 
     1542                if ( !$rss = fetch_feed($rss) ) 
    15461543                        return; 
    15471544        } elseif ( is_array($rss) && isset($rss['url']) ) { 
    1548                 require_once(ABSPATH . WPINC . '/rss.php'); 
    15491545                $args = $rss; 
    1550                 if ( !$rss = fetch_rss($rss['url']) ) 
     1546                if ( !$rss = fetch_feed($rss['url']) ) 
    15511547                        return; 
    15521548        } elseif ( !is_object($rss) ) { 
    15531549                return; 
     
    15641560        $show_author   = (int) $show_author; 
    15651561        $show_date     = (int) $show_date; 
    15661562 
    1567         if ( is_array( $rss->items ) && !empty( $rss->items ) ) { 
    1568                 $rss->items = array_slice($rss->items, 0, $items); 
    1569                 echo '<ul>'; 
    1570                 foreach ( (array) $rss->items as $item ) { 
    1571                         while ( strstr($item['link'], 'http') != $item['link'] ) 
    1572                                 $item['link'] = substr($item['link'], 1); 
    1573                         $link = clean_url(strip_tags($item['link'])); 
    1574                         $title = attribute_escape(strip_tags($item['title'])); 
    1575                         if ( empty($title) ) 
    1576                                 $title = __('Untitled'); 
    1577                         $desc = ''; 
    1578                         if ( isset( $item['description'] ) && is_string( $item['description'] ) ) 
    1579                                 $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['description'], ENT_QUOTES)))); 
    1580                         elseif ( isset( $item['summary'] ) && is_string( $item['summary'] ) ) 
    1581                                 $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['summary'], ENT_QUOTES)))); 
    1582                         if ( 360 < strlen( $desc ) ) 
    1583                                 $desc = wp_html_excerpt( $desc, 360 ) . ' [&hellip;]'; 
    1584                         $summary = $desc; 
     1563        if ( !$rss->get_item_quantity() ) { 
     1564                echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>'; 
     1565                return; 
     1566        } 
    15851567 
    1586                         if ( $show_summary ) { 
    1587                                 $desc = ''; 
    1588                                 $summary = wp_specialchars( $summary ); 
    1589                                 $summary = "<div class='rssSummary'>$summary</div>"; 
    1590                         } else { 
    1591                                 $summary = ''; 
    1592                         } 
     1568        echo '<ul>'; 
     1569        $count = 0; 
     1570        foreach ( $rss->get_items() as $item ) { 
     1571                $link = $item->get_link(); 
     1572                while ( strstr($link, 'http') != $link ) 
     1573                        $link = substr($link, 1); 
     1574                $link = clean_url(strip_tags($link)); 
     1575                $title = attribute_escape(strip_tags($item->get_title())); 
     1576                if ( empty($title) ) 
     1577                        $title = __('Untitled'); 
    15931578 
    1594                         $date = ''; 
    1595                         if ( $show_date ) { 
    1596                                 if ( isset($item['pubdate']) ) 
    1597                                         $date = $item['pubdate']; 
    1598                                 elseif ( isset($item['published']) ) 
    1599                                         $date = $item['published']; 
     1579                $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item->get_description(), ENT_QUOTES)))); 
     1580                $desc = wp_html_excerpt( $desc, 360 ) . ' [&hellip;]'; 
     1581                $desc = wp_specialchars( $desc ); 
    16001582 
    1601                                 if ( $date ) { 
    1602                                         if ( $date_stamp = strtotime( $date ) ) 
    1603                                                 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>'; 
    1604                                         else 
    1605                                                 $date = ''; 
    1606                                 } 
    1607                         } 
     1583                if ( $show_summary ) { 
     1584                        $summary = "<div class='rssSummary'>$desc</div>"; 
     1585                } else { 
     1586                        $summary = ''; 
     1587                } 
    16081588 
    1609                         $author = ''; 
    1610                         if ( $show_author ) { 
    1611                                 if ( isset($item['dc']['creator']) ) 
    1612                                         $author = ' <cite>' . wp_specialchars( strip_tags( $item['dc']['creator'] ) ) . '</cite>'; 
    1613                                 elseif ( isset($item['author_name']) ) 
    1614                                         $author = ' <cite>' . wp_specialchars( strip_tags( $item['author_name'] ) ) . '</cite>'; 
    1615                         } 
     1589                $date = ''; 
     1590                if ( $show_date ) { 
     1591                        $date = $item->get_date(); 
    16161592 
    1617                         if ( $link == '' ) { 
    1618                                 echo "<li>$title{$date}{$summary}{$author}</li>"; 
    1619                         } else { 
    1620                                 echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>"; 
     1593                        if ( $date ) { 
     1594                                if ( $date_stamp = strtotime( $date ) ) 
     1595                                        $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>'; 
     1596                                else 
     1597                                        $date = ''; 
    16211598                        } 
    1622 } 
    1623                 echo '</ul>'; 
    1624         } else { 
    1625                 echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>'; 
     1599                } 
     1600 
     1601                $author = ''; 
     1602                if ( $show_author ) { 
     1603                        $author = $item->get_author(); 
     1604                        $author = $author->get_name(); 
     1605                        $author = ' <cite>' . wp_specialchars( strip_tags( $author ) ) . '</cite>'; 
     1606                } 
     1607 
     1608                if ( $link == '' ) { 
     1609                        echo "<li>$title{$date}{$summary}{$author}</li>"; 
     1610                } else { 
     1611                        echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>"; 
     1612                } 
     1613                $count++; 
     1614                if ( $count >= $items ) 
     1615                        break; 
    16261616        } 
     1617        echo '</ul>'; 
    16271618} 
    16281619 
    16291620/** 
     
    18101801        $show_date     = (int) $widget_rss['show_date']; 
    18111802 
    18121803        if ( $check_feed ) { 
    1813                 require_once(ABSPATH . WPINC . '/rss.php'); 
    1814                 $rss = fetch_rss($url); 
     1804                $rss = fetch_feed($url); 
    18151805                $error = false; 
    18161806                $link = ''; 
    18171807                if ( !is_object($rss) ) { 
    18181808                        $url = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1); 
    18191809                        $error = sprintf(__('Error in RSS %1$d'), $widget_number ); 
    18201810                } else { 
    1821                         $link = clean_url(strip_tags($rss->channel['link'])); 
     1811                        $link = clean_url(strip_tags($rss->get_permalink())); 
    18221812                        while ( strstr($link, 'http') != $link ) 
    18231813                                $link = substr($link, 1); 
    18241814                } 
  • wp-admin/includes/dashboard.php

     
    670670function wp_dashboard_secondary_output() { 
    671671        $widgets = get_option( 'dashboard_widget_options' ); 
    672672        @extract( @$widgets['dashboard_secondary'], EXTR_SKIP ); 
    673         $rss = @fetch_rss( $url ); 
     673        $rss = @fetch_feed( $url ); 
    674674 
    675         if ( !isset($rss->items) || 0 == count($rss->items) ) 
     675        if ( !$rss->get_item_quantity() ) 
    676676                return false; 
    677677 
    678         $rss->items = array_slice($rss->items, 0, $items); 
    679  
    680         if ( 'http://planet.wordpress.org/' == $rss->channel['link'] ) { 
    681                 foreach ( array_keys($rss->items) as $i ) { 
    682                         list($site, $description) = explode( ':', wp_specialchars($rss->items[$i]['title']), 2 ); 
    683                         $rss->items[$i]['dc']['creator'] = trim($site); 
    684                         $rss->items[$i]['title'] = trim($description); 
    685                 } 
    686         } 
    687  
    688678        echo "<div class='rss-widget'>"; 
    689679        wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] ); 
    690680        echo "</div>"; 
     
    778768        } 
    779769 
    780770 
    781         require_once( ABSPATH . WPINC . '/rss.php' ); 
    782         init(); // initialize rss constants 
    783  
    784         $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); 
    785  
     771        /* TODO Cache check here. 
    786772        foreach ( $check_urls as $check_url ) { 
    787                 $status = $cache->check_cache( $check_url ); 
     773 
    788774                if ( 'HIT' !== $status ) { 
    789775                        echo $loading; 
    790776                        return false; 
    791777                } 
    792778        } 
     779        */ 
    793780 
    794781        if ( $callback && is_callable( $callback ) ) { 
    795782                $args = array_slice( func_get_args(), 2 );