Make WordPress Core

Ticket #19239: 19239-2.diff

File 19239-2.diff, 10.0 KB (added by ericmann, 12 years ago)

Make feed URLs configurable for I18N

  • wp-admin/css/wp-admin.css

     
    70667066        word-wrap: break-word;
    70677067}
    70687068
     7069/* Newsfeed Widget */
     7070#dashboard_wp_newsfeed .wp-official {
     7071        height: 16px;
     7072        width: 16px;
     7073        margin-right: 8px;
     7074        display: inline-block;
     7075        background: url(../images/wp-logo-vs.png) no-repeat center center;
     7076        position: relative;
     7077        top: 3px;
     7078}
     7079
     7080#dashboard_wp_newsfeed p.sub {
     7081        color: #8f8f8f;
     7082        font-size: 14px;
     7083        padding-bottom: 0.5em;
     7084        border-bottom: 1px solid #ececec;
     7085}
     7086
    70697087/* Browser Nag */
    70707088#dashboard_browser_nag a.update-browser-link {
    70717089        font-size: 1.2em;
    7072         font-weight: bold;
     7090        }
     7091
     7092        #dashboard_wp_newsfeed .wp-official {
     7093            background-image: url(../images/wp-logo-vs-2x.png);
     7094            background-size: 16px 16px;
     7095    }
    70737096}
    70747097
    70757098#dashboard_browser_nag a {
  • wp-admin/includes/ajax-actions.php

     
    203203                case 'dashboard_incoming_links' :
    204204                        wp_dashboard_incoming_links();
    205205                        break;
    206                 case 'dashboard_primary' :
    207                         wp_dashboard_primary();
     206                case 'dashboard_wp_newsfeed':
     207                        wp_dashboard_newsfeed();
    208208                        break;
    209                 case 'dashboard_secondary' :
    210                         wp_dashboard_secondary();
    211                         break;
    212209                case 'dashboard_plugins' :
    213210                        wp_dashboard_plugins();
    214211                        break;
  • wp-admin/includes/dashboard.php

     
    8282        if ( is_blog_admin() && current_user_can('edit_posts') )
    8383                wp_add_dashboard_widget( 'dashboard_recent_drafts', __('Recent Drafts'), 'wp_dashboard_recent_drafts' );
    8484
    85         // Primary feed (Dev Blog) Widget
    86         if ( !isset( $widget_options['dashboard_primary'] ) ) {
    87                 $update = true;
    88                 $widget_options['dashboard_primary'] = array(
    89                         'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
    90                         'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
    91                         'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
    92                         'items' => 2,
    93                         'show_summary' => 1,
    94                         'show_author' => 0,
    95                         'show_date' => 1,
    96                 );
    97         }
    98         wp_add_dashboard_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_primary', 'wp_dashboard_primary_control' );
     85        // WordPress Feed Widget
     86        wp_add_dashboard_widget( 'dashboard_wp_newsfeed', __( 'WordPress News' ), 'wp_dashboard_newsfeed', 'wp_dashboard_newsfeed_control' );
    9987
    100         // Secondary Feed (Planet) Widget
    101         if ( !isset( $widget_options['dashboard_secondary'] ) ) {
    102                 $update = true;
    103                 $widget_options['dashboard_secondary'] = array(
    104                         'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
    105                         'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
    106                         'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
    107                         'items' => 5,
    108                         'show_summary' => 0,
    109                         'show_author' => 0,
    110                         'show_date' => 0,
    111                 );
    112         }
    113         wp_add_dashboard_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_secondary', 'wp_dashboard_secondary_control' );
    114 
    11588        // Hook to register new widgets
    11689        // Filter widget order
    11790        if ( is_network_admin() ) {
     
    860833        wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) );
    861834}
    862835
    863 function wp_dashboard_primary() {
    864         wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_rss_output' );
    865 }
    866 
    867 function wp_dashboard_primary_control() {
    868         wp_dashboard_rss_control( 'dashboard_primary' );
    869 }
    870 
    871836/**
    872837 * Display primary dashboard RSS widget feed.
    873838 *
     
    882847        echo "</div>";
    883848}
    884849
    885 function wp_dashboard_secondary() {
    886         wp_dashboard_cached_rss_widget( 'dashboard_secondary', 'wp_dashboard_secondary_output' );
     850/**
     851 * Display (cached) dashboard widget for WordPress news and Planet WordPress
     852 *
     853 * @since 3.6.0
     854 */
     855function wp_dashboard_newsfeed() {
     856        wp_dashboard_cached_rss_widget(
     857                'wp_dashboard_newsfeed',
     858                'wp_dashboard_newsfeed_output',
     859                array(
     860                     'http://wordpress.org/news/feed/',
     861                     'http://planet.wordpress.org/feed/'
     862                )
     863        );
    887864}
    888865
    889 function wp_dashboard_secondary_control() {
    890         wp_dashboard_rss_control( 'dashboard_secondary' );
     866/**
     867 * Display options for the newsfeed widget.
     868 *
     869 * @since 3.6.0
     870 */
     871function wp_dashboard_newsfeed_control() {
     872        if ( ! $widget_options = get_option( 'dashboard_widget_options' ) ) {
     873                $widget_options = array();
     874        }
     875
     876        if ( ! isset( $widget_options['dashboard_newsfeed'] ) ) {
     877                $widget_options['dashboard_newsfeed'] = array(
     878                        'news'   => 'http://wordpress.org/news/feed/',
     879                        'planet' => 'http://planet.wordpress.org/feed/'
     880                );
     881        }
     882
     883        $news = $widget_options['dashboard_newsfeed']['news'];
     884        $planet = $widget_options['dashboard_newsfeed']['planet'];
     885
     886        // Update options on postback
     887        if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-newsfeed'] ) ) {
     888                $news = esc_url( $_POST['widget-newsfeed']['news'] );
     889                $planet = esc_url( $_POST['widget-newsfeed']['planet'] );
     890                $widget_options['dashboard_newsfeed'] = array(
     891                        'news'   => $news,
     892                        'planet' => $planet
     893                );
     894                update_option( 'dashboard_widget_options', $widget_options );
     895
     896                // Force the cached feed to flush
     897                $cache_key = 'dash_' . md5( 'wp_dashboard_newsfeed' );
     898                delete_transient( $cache_key );
     899        }
     900
     901        echo '<p><label for="wordpress-news-newsfeed">' . __( 'WordPress News Feed URL:' ) . '</label>';
     902        echo '<input class="widefat" id="wordpress-news-newsfeed" name="widget-newsfeed[news]" type="text" value="' . esc_attr( $news ) . '"/></p>';
     903        echo '<p><label for="wordpress-planet-newsfeed">' . __( 'Planet WordPress Feed URL:' ) . '</label>';
     904        echo '<input class="widefat" id="wordpress-planet-newsfeed" name="widget-newsfeed[planet]" type="text" value="' . esc_attr( $planet ) . '"/></p>';
    891905}
    892906
    893907/**
    894  * Display secondary dashboard RSS widget feed.
     908 * Actual (uncached) output of the newsfeed widget.
    895909 *
    896  * @since 2.5.0
    897  *
    898  * @return unknown
     910 * @since 3.6.0
    899911 */
    900 function wp_dashboard_secondary_output() {
    901         $widgets = get_option( 'dashboard_widget_options' );
    902         @extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
    903         $rss = @fetch_feed( $url );
     912function wp_dashboard_newsfeed_output() {
     913        if ( ! $widget_options = get_option( 'dashboard_widget_options' ) ) {
     914                $widget_options = array();
     915        }
    904916
    905         if ( is_wp_error($rss) ) {
    906                 if ( is_admin() || current_user_can('manage_options') ) {
    907                         echo '<div class="rss-widget"><p>';
    908                         printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
    909                         echo '</p></div>';
     917        if ( ! isset( $widget_options['dashboard_newsfeed'] ) ) {
     918                $widget_options['dashboard_newsfeed'] = array(
     919                        'news'   => 'http://wordpress.org/news/feed/',
     920                        'planet' => 'http://planet.wordpress.org/feed/'
     921                );
     922        }
     923
     924        $news = $widget_options['dashboard_newsfeed']['news'];
     925        $planet = $widget_options['dashboard_newsfeed']['planet'];
     926
     927        $official = fetch_feed( $news );
     928        $planet = fetch_feed( $planet );
     929
     930        foreach( array( 'official' => __( 'WordPress.org Official Blog' ), 'planet' => __( 'Planet WordPress' ) ) as $feed => $label ) {
     931                if ( is_wp_error( $$feed ) || ! $$feed->get_item_quantity() )
     932                        continue;
     933                switch( $feed ) {
     934                        case 'official':
     935                                $items = $$feed->get_items( 0, 2 );
     936                                break;
     937                        default:
     938                                $items = $$feed->get_items( 0, 5 );
    910939                }
    911         } elseif ( !$rss->get_item_quantity() ) {
    912                 $rss->__destruct();
    913                 unset($rss);
    914                 return false;
    915         } else {
    916                 echo '<div class="rss-widget">';
    917                 wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] );
    918                 echo '</div>';
    919                 $rss->__destruct();
    920                 unset($rss);
     940
     941                echo "<p class='sub'>";
     942
     943                if ( 'official' == $feed ) {
     944                        echo '<span class="wp-official"></span>';
     945                }
     946
     947                echo "$label</p>";
     948                echo "<ul>";
     949
     950                foreach( $items as $item ) {
     951                        $link = $item->get_link();
     952                        $title = $item->get_title();
     953                        $description = $item->get_description();
     954                        $date = 'official' == $feed ? $item->get_date( 'U' ) : '';
     955
     956                        // Filter title
     957                        $title = esc_attr( strip_tags( $title ) );
     958                        if ( empty( $title ) ) {
     959                                $title = __( 'Untitled' );
     960                        }
     961
     962                        // Filter description
     963                        $description = str_replace( array( "\n", "\r" ), ' ', esc_attr( strip_tags( @html_entity_decode( $description, ENT_QUOTES, get_option( 'blog_charset' ) ) ) ) );
     964                        $description = wp_html_excerpt( $description, 360 );
     965
     966                        // Append ellipsis. Change existing [...] to [&hellip;].
     967                        if ( '[...]' == substr( $description, -5 ) ) {
     968                                $description = substr( $description, 0, -5 ) . '[&hellip;]';
     969                        } elseif ( '[&hellip;]' != substr( $description, -10 ) ) {
     970                                $description .= ' [&hellip;]';
     971                        }
     972                        $description = esc_html( $description );
     973
     974                        // Filter summary
     975                        if ( 'official' == $feed ) {
     976                                $summary = "<div class='rssSummary'>$description</div>";
     977                        } else {
     978                                $summary = '';
     979                        }
     980
     981                        // Filter date
     982                        if ( '' !== $date ) {
     983                                $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
     984                        }
     985
     986                        if ( '' === $link ) {
     987                                echo "<li>$title{$date}{$summary}</li>";
     988                        } else {
     989                                echo "<li><a class='rsswidget' href='$link' title='$description'>$title</a>{$date}{$summary}</li>";
     990                        }
     991                }
     992
     993                echo "</ul>";
     994
     995                $$feed->__destruct();
     996                unset( $$feed );
    921997        }
    922998}
    923999
  • wp-admin/js/dashboard.js

     
    3030        // These widgets are sometimes populated via ajax
    3131        ajaxWidgets = [
    3232                'dashboard_incoming_links',
    33                 'dashboard_primary',
    34                 'dashboard_secondary',
    35                 'dashboard_plugins'
     33                'dashboard_plugins',
     34                'dashboard_wp_newsfeed'
    3635        ];
    3736
    3837        ajaxPopulateWidgets = function(el) {