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' ); |
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 | | |
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 | */ |
| 855 | function 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 | ); |
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>'; |
| 884 | foreach( array( 'official' => __( 'WordPress.org Official Blog' ), 'planet' => __( 'Planet WordPress' ) ) as $feed => $label ) { |
| 885 | if ( is_wp_error( $$feed ) || ! $$feed->get_item_quantity() ) |
| 886 | continue; |
| 887 | switch( $feed ) { |
| 888 | case 'official': |
| 889 | $items = $$feed->get_items( 0, 2 ); |
| 890 | break; |
| 891 | default: |
| 892 | $items = $$feed->get_items( 0, 5 ); |
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); |
| 894 | |
| 895 | echo "<h4>"; |
| 896 | |
| 897 | if ( 'official' == $feed ) { |
| 898 | echo '<span class="wp-official"></span>'; |
| 899 | } |
| 900 | |
| 901 | echo "$label</h4>"; |
| 902 | echo "<ul>"; |
| 903 | |
| 904 | foreach( $items as $item ) { |
| 905 | $link = $item->get_link(); |
| 906 | $title = $item->get_title(); |
| 907 | $description = $item->get_description(); |
| 908 | $date = 'official' == $feed ? $item->get_date( 'U' ) : ''; |
| 909 | |
| 910 | // Filter title |
| 911 | $title = esc_attr( strip_tags( $title ) ); |
| 912 | if ( empty( $title ) ) { |
| 913 | $title = __( 'Untitled' ); |
| 914 | } |
| 915 | |
| 916 | // Filter description |
| 917 | $description = str_replace( array( "\n", "\r" ), ' ', esc_attr( strip_tags( @html_entity_decode( $description, ENT_QUOTES, get_option( 'blog_charset' ) ) ) ) ); |
| 918 | $description = wp_html_excerpt( $description, 360 ); |
| 919 | |
| 920 | // Append ellipsis. Change existing [...] to […]. |
| 921 | if ( '[...]' == substr( $description, -5 ) ) { |
| 922 | $description = substr( $description, 0, -5 ) . '[…]'; |
| 923 | } elseif ( '[…]' != substr( $description, -10 ) ) { |
| 924 | $description .= ' […]'; |
| 925 | } |
| 926 | $description = esc_html( $description ); |
| 927 | |
| 928 | // Filter summary |
| 929 | if ( 'official' == $feed ) { |
| 930 | $summary = "<div class='rssSummary'>$description</div>"; |
| 931 | } else { |
| 932 | $summary = ''; |
| 933 | } |
| 934 | |
| 935 | // Filter date |
| 936 | if ( '' !== $date ) { |
| 937 | $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>'; |
| 938 | } |
| 939 | |
| 940 | if ( '' === $link ) { |
| 941 | echo "<li>$title{$date}{$summary}</li>"; |
| 942 | } else { |
| 943 | echo "<li><a class='rsswidget' href='$link' title='$description'>$title</a>{$date}{$summary}</li>"; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | echo "</ul>"; |
| 948 | |
| 949 | $$feed->__destruct(); |
| 950 | unset( $$feed ); |