Make WordPress Core


Ignore:
Timestamp:
02/27/2009 07:32:50 PM (17 years ago)
Author:
ryan
Message:

Use SimplePie for widget and dashboard feeds. First cut. see #9198

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/widgets.php

    r10535 r10666  
    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;
     
    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) ) {
     
    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;
    1585 
    1586             if ( $show_summary ) {
    1587                 $desc = '';
    1588                 $summary = wp_specialchars( $summary );
    1589                 $summary = "<div class='rssSummary'>$summary</div>";
    1590             } else {
    1591                 $summary = '';
     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    }
     1567
     1568    echo '<ul>';
     1569    foreach ( $rss->get_items(0, $items) as $item ) {
     1570        $link = $item->get_link();
     1571        while ( strstr($link, 'http') != $link )
     1572            $link = substr($link, 1);
     1573        $link = clean_url(strip_tags($link));
     1574        $title = attribute_escape(strip_tags($item->get_title()));
     1575        if ( empty($title) )
     1576            $title = __('Untitled');
     1577
     1578        $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item->get_description(), ENT_QUOTES))));
     1579        $desc = wp_html_excerpt( $desc, 360 ) . ' [&hellip;]';
     1580        $desc = wp_specialchars( $desc );
     1581
     1582        if ( $show_summary ) {
     1583            $summary = "<div class='rssSummary'>$desc</div>";
     1584        } else {
     1585            $summary = '';
     1586        }
     1587
     1588        $date = '';
     1589        if ( $show_date ) {
     1590            $date = $item->get_date();
     1591
     1592            if ( $date ) {
     1593                if ( $date_stamp = strtotime( $date ) )
     1594                    $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>';
     1595                else
     1596                    $date = '';
    15921597            }
    1593 
    1594             $date = '';
    1595             if ( $show_date ) {
    1596                 if ( isset($item['pubdate']) )
    1597                     $date = $item['pubdate'];
    1598                 elseif ( isset($item['published']) )
    1599                     $date = $item['published'];
    1600 
    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             }
    1608 
    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             }
    1616 
    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>";
    1621             }
    1622 }
    1623         echo '</ul>';
    1624     } else {
    1625         echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
    1626     }
     1598        }
     1599
     1600        $author = '';
     1601        if ( $show_author ) {
     1602            $author = $item->get_author();
     1603            $author = $author->get_name();
     1604            $author = ' <cite>' . wp_specialchars( strip_tags( $author ) ) . '</cite>';
     1605        }
     1606
     1607        if ( $link == '' ) {
     1608            echo "<li>$title{$date}{$summary}{$author}</li>";
     1609        } else {
     1610            echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
     1611        }
     1612    }
     1613    echo '</ul>';
    16271614}
    16281615
     
    18111798
    18121799    if ( $check_feed ) {
    1813         require_once(ABSPATH . WPINC . '/rss.php');
    1814         $rss = fetch_rss($url);
     1800        $rss = fetch_feed($url);
    18151801        $error = false;
    18161802        $link = '';
     
    18191805            $error = sprintf(__('Error in RSS %1$d'), $widget_number );
    18201806        } else {
    1821             $link = clean_url(strip_tags($rss->channel['link']));
     1807            $link = clean_url(strip_tags($rss->get_permalink()));
    18221808            while ( strstr($link, 'http') != $link )
    18231809                $link = substr($link, 1);
Note: See TracChangeset for help on using the changeset viewer.