+/**
+ * WordPress News dashboard widget.
+ *
+ * @since 2.7.0
+ */
+function wp_dashboard_primary() {
+ $feeds = array(
+ 'news' => array(
+ 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
+ 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
+ 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
+ 'items' => 1,
+ 'show_summary' => 1,
+ 'show_author' => 0,
+ 'show_date' => 1,
+ ),
+ 'planet' => array(
+ 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
+ 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
+ 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
+ 'items' => 3,
+ 'show_summary' => 0,
+ 'show_author' => 0,
+ 'show_date' => 0,
+ )
+ );
+
+ if ( ( ! is_multisite() && is_blog_admin() && current_user_can( 'install_plugins' ) ) || ( is_network_admin() && current_user_can( 'manage_network_plugins' ) && current_user_can( 'install_plugins' ) ) ) {
+ $feeds['plugins'] = array(
+ 'link' => '',
+ 'url' => array(
+ 'popular' => 'http://wordpress.org/plugins/rss/browse/popular/',
+ ),
+ 'title' => '',
+ 'items' => 1,
+ 'show_summary' => 0,
+ 'show_author' => 0,
+ 'show_date' => 0,
+ );
+ }
+
+ wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
+}
+
+/**
+ * Display the WordPress news feeds.
+ *
+ * @since 3.8.0
+ *
+ * @param string $widget_id Widget ID.
+ * @param array $feeds Array of RSS feeds.
+ */
+function wp_dashboard_primary_output( $widget_id, $feeds ) {
+ foreach( $feeds as $type => $args ) {
+ $args['type'] = $type;
+ echo '<div class="rss-widget">';
+ if ( $type === 'plugins' ) {
+ wp_dashboard_plugins_output( $args['url'], $args );
+ } else {
+ wp_widget_rss_output( $args['url'], $args );
+ }
+ echo "</div>";
+ }
+}
+
+/**
+ * Display plugins text for the WordPress news widget.
+ *
+ * @since 2.5.0
+ */
+function wp_dashboard_plugins_output( $rss, $args = array() ) {
+ // Plugin feeds plus link to install them
+ $popular = fetch_feed( $args['url']['popular'] );
+
+ if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
+ $plugin_slugs = array_keys( get_plugins() );
+ set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
+ }
+
+ echo '<ul>';
+
+ foreach ( array(
+ 'popular' => __( 'Popular Plugin' )
+ ) as $feed => $label ) {
+ if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
+ continue;
+
+ $items = $$feed->get_items(0, 5);
+
+ // Pick a random, non-installed plugin
+ while ( true ) {
+ // Abort this foreach loop iteration if there's no plugins left of this type
+ if ( 0 == count($items) )
+ continue 2;
+
+ $item_key = array_rand($items);
+ $item = $items[$item_key];
+
+ list($link, $frag) = explode( '#', $item->get_link() );
+
+ $link = esc_url($link);
+ if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
+ $slug = $matches[1];
+ else {
+ unset( $items[$item_key] );
+ continue;
+ }
+
+ // Is this random plugin's slug already installed? If so, try again.
+ reset( $plugin_slugs );
+ foreach ( $plugin_slugs as $plugin_slug ) {
+ if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
+ unset( $items[$item_key] );
+ continue 2;
+ }
+ }
+
+ // If we get to this point, then the random plugin isn't installed and we can stop the while().
+ break;
+ }
+
+ // Eliminate some common badly formed plugin descriptions
+ while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
+ unset($items[$item_key]);
+
+ if ( !isset($items[$item_key]) )
+ continue;
+
+ $title = esc_html( $item->get_title() );
+
+ $description = esc_html( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
+
+ $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&TB_iframe=true&width=600&height=800';
+
+ echo "<li class='dashboard-news-plugin'><span>$label:</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a></h5> <span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span></li>";
+
+ $$feed->__destruct();
+ unset( $$feed );
+ }
+
+ echo '</ul>';
+}
+
+/**
+ * Display file upload quota on dashboard.
+ *
+ * Runs on the activity_box_end hook in wp_dashboard_right_now().
+ *
+ * @since 3.0.0
+ *
+ * @return bool True if not multisite, user can't upload files, or the space check option is disabled.
+*/