Make WordPress Core


Ignore:
Timestamp:
02/27/2009 07:32:50 PM (18 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-admin/includes/dashboard.php

    r10641 r10666  
    599599        $widgets = get_option( 'dashboard_widget_options' );
    600600        @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
    601         $rss = @fetch_rss( $url );
    602         if ( isset($rss->items) && 0 < count($rss->items) )  {
    603 
    604                 echo "<ul>\n";
    605 
    606                 $rss->items = array_slice($rss->items, 0, $items);
    607                 foreach ( $rss->items as $item ) {
    608                         $publisher = '';
    609                         $site_link = '';
    610                         $link = '';
    611                         $content = '';
    612                         $date = '';
    613                         $link = clean_url( strip_tags( $item['link'] ) );
    614 
    615                         if ( isset( $item['author_uri'] ) )
    616                                 $site_link = clean_url( strip_tags( $item['author_uri'] ) );
    617 
    618                         if ( !$publisher = wp_specialchars( strip_tags( isset($item['dc']['publisher']) ? $item['dc']['publisher'] : $item['author_name'] ) ) )
    619                                 $publisher = __( 'Somebody' );
    620                         if ( $site_link )
    621                                 $publisher = "<a href='$site_link'>$publisher</a>";
    622                         else
    623                                 $publisher = "<strong>$publisher</strong>";
    624 
    625                         if ( isset($item['description']) )
    626                                 $content = $item['description'];
    627                         elseif ( isset($item['summary']) )
    628                                 $content = $item['summary'];
    629                         elseif ( isset($item['atom_content']) )
    630                                 $content = $item['atom_content'];
    631                         else
    632                                 $content = __( 'something' );
    633                         $content = wp_html_excerpt($content, 50) . ' ...';
    634                         if ( $link )
    635                                 $text = _c( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"|feed_display' );
    636                         else
    637                                 $text = _c( '%1$s linked here saying, "%3$s"|feed_display' );
    638 
    639                         if ( $show_date ) {
    640                                 if ( $show_author || $show_summary )
    641                                         $text .= _c( ' on %4$s|feed_display' );
    642                                 $date = wp_specialchars( strip_tags( isset($item['pubdate']) ? $item['pubdate'] : $item['published'] ) );
    643                                 $date = strtotime( $date );
    644                                 $date = gmdate( get_option( 'date_format' ), $date );
    645                         }
    646 
    647                         echo "\t<li>" . sprintf( _c( "$text|feed_display" ), $publisher, $link, $content, $date ) . "</li>\n";
     601        $rss = fetch_feed( $url );
     602
     603        if ( !$rss->get_item_quantity() ) {
     604                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";
     605                return;
     606        }
     607
     608        echo "<ul>\n";
     609
     610        $count = 0;
     611        foreach ( $rss->get_items() as $item ) {
     612                $publisher = '';
     613                $site_link = '';
     614                $link = '';
     615                $content = '';
     616                $date = '';
     617                $link = clean_url( strip_tags( $item->get_link() ) );
     618
     619                $author = $item->get_author();
     620                $site_link = clean_url( strip_tags( $author->get_link() ) );
     621
     622                if ( !$publisher = wp_specialchars( strip_tags( $author->get_name() ) ) )
     623                        $publisher = __( 'Somebody' );
     624                if ( $site_link )
     625                        $publisher = "<a href='$site_link'>$publisher</a>";
     626                else
     627                        $publisher = "<strong>$publisher</strong>";
     628
     629                $content = $item->get_content();
     630                $content = wp_html_excerpt($content, 50) . ' ...';
     631
     632                if ( $link )
     633                        $text = _c( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"|feed_display' );
     634                else
     635                        $text = _c( '%1$s linked here saying, "%3$s"|feed_display' );
     636
     637                if ( $show_date ) {
     638                        if ( $show_author || $show_summary )
     639                                $text .= _c( ' on %4$s|feed_display' );
     640                        $date = wp_specialchars( strip_tags( $item->get_date() ) );
     641                        $date = strtotime( $date );
     642                        $date = gmdate( get_option( 'date_format' ), $date );
    648643                }
    649644
    650                 echo "</ul>\n";
    651 
    652         } else {
    653                 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";
    654         }
     645                echo "\t<li>" . sprintf( _c( "$text|feed_display" ), $publisher, $link, $content, $date ) . "</li>\n";
     646        }
     647
     648        echo "</ul>\n";
     649
    655650}
    656651
    … …  
    699694        $widgets = get_option( 'dashboard_widget_options' );
    700695        @extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
    701         $rss = @fetch_rss( $url );
    702 
    703         if ( !isset($rss->items) || 0 == count($rss->items) )
     696        $rss = @fetch_feed( $url );
     697
     698        if ( !$rss->get_item_quantity() )
    704699                return false;
    705 
    706         $rss->items = array_slice($rss->items, 0, $items);
    707 
    708         if ( 'http://planet.wordpress.org/' == $rss->channel['link'] ) {
    709                 foreach ( array_keys($rss->items) as $i ) {
    710                         list($site, $description) = explode( ':', wp_specialchars($rss->items[$i]['title']), 2 );
    711                         $rss->items[$i]['dc']['creator'] = trim($site);
    712                         $rss->items[$i]['title'] = trim($description);
    713                 }
    714         }
    715700
    716701        echo "<div class='rss-widget'>";
    … …  
    733718 */
    734719function wp_dashboard_plugins_output() {
    735         $popular = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/popular/' );
    736         $new     = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
    737         $updated = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
     720        $popular = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/popular/' );
     721        $new     = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
     722        $updated = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
    738723
    739724        foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
    740                 if ( !isset($$feed->items) || 0 == count($$feed->items) )
     725                if ( !$$feed->get_item_quantity() )
    741726                        continue;
    742727
    743                 $$feed->items = array_slice($$feed->items, 0, 5);
    744                 $item_key = array_rand($$feed->items);
     728                $items = $$feed->get_items(0, 5);
     729                $item_key = array_rand($items);
    745730
    746731                // Eliminate some common badly formed plugin descriptions
    747                 while ( ( null !== $item_key = array_rand($$feed->items) ) && false !== strpos( $$feed->items[$item_key]['description'], 'Plugin Name:' ) )
    748                         unset($$feed->items[$item_key]);
    749 
    750                 if ( !isset($$feed->items[$item_key]) )
     732                while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
     733                        unset($items[$item_key]);
     734
     735                if ( !isset($items[$item_key]) )
    751736                        continue;
    752737
    753                 $item = $$feed->items[$item_key];
     738                $item = $items[$item_key];
    754739
    755740                // current bbPress feed item titles are: user on "topic title"
    756                 if ( preg_match( '/"(.*)"/s', $item['title'], $matches ) )
     741                if ( preg_match( '/&quot;(.*)&quot;/s', $item->get_title(), $matches ) )
    757742                        $title = $matches[1];
    758743                else // but let's make it forward compatible if things change
    759                         $title = $item['title'];
     744                        $title = $item->get_title();
    760745                $title = wp_specialchars( $title );
    761746
    762                 $description = wp_specialchars( strip_tags(html_entity_decode($item['description'], ENT_QUOTES)) );
    763 
    764                 list($link, $frag) = explode( '#', $item['link'] );
     747                $description = wp_specialchars( strip_tags(html_entity_decode($item->get_description(), ENT_QUOTES)) );
     748
     749                list($link, $frag) = explode( '#', $item->get_link() );
    765750
    766751                $link = clean_url($link);
    … …  
    807792
    808793
    809         require_once( ABSPATH . WPINC . '/rss.php' );
    810         init(); // initialize rss constants
    811 
    812         $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );
    813 
     794        /* TODO Cache check here.
    814795        foreach ( $check_urls as $check_url ) {
    815                 $status = $cache->check_cache( $check_url );
     796
    816797                if ( 'HIT' !== $status ) {
    817798                        echo $loading;
    … …  
    819800                }
    820801        }
     802        */
     803
     804        // Always load async until above fixed.
     805        echo $loading;
     806        return false;
    821807
    822808        if ( $callback && is_callable( $callback ) ) {
    … …  
    873859                // title is optional.  If black, fill it if possible
    874860                if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
    875                         require_once(ABSPATH . WPINC . '/rss.php');
    876                         $rss = fetch_rss($widget_options[$widget_id]['url']);
    877                         $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->channel['title']));
     861                        $rss = fetch_feed($widget_options[$widget_id]['url']);
     862                        $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
    878863                }
    879864                update_option( 'dashboard_widget_options', $widget_options );
Note: See TracChangeset for help on using the changeset viewer.