### Eclipse Workspace Patch 1.0
#P wordpress-trunk
|
|
|
|
| 855 | 855 | * @since unknown |
| 856 | 856 | */ |
| 857 | 857 | function wp_dashboard_plugins_output() { |
| 858 | | $popular = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/popular/' ); |
| 859 | | $new = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/new/' ); |
| 860 | | $updated = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/updated/' ); |
| | 858 | // feeds configuration |
| | 859 | $feeds = array( |
| | 860 | 'popular' => array( |
| | 861 | 'url' => 'http://wordpress.org/extend/plugins/rss/browse/popular/', |
| | 862 | 'label' => __('Most Popular'), |
| | 863 | ), |
| | 864 | 'new' => array( |
| | 865 | 'url' => 'http://wordpress.org/extend/plugins/rss/browse/popular/', |
| | 866 | 'label' => __('Newest Plugins'), |
| | 867 | ), |
| | 868 | 'updated' => array( |
| | 869 | 'url' => 'http://wordpress.org/extend/plugins/rss/browse/popular/', |
| | 870 | 'label' => __('Recently Updated'), |
| | 871 | ), |
| | 872 | ); |
| 861 | 873 | |
| 862 | | if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) { |
| | 874 | // get plugin slugs of installed plugins to compare against later |
| | 875 | if ( false === ($plugin_slugs = get_transient( 'plugin_slugs' )) ) { |
| 863 | 876 | $plugin_slugs = array_keys( get_plugins() ); |
| 864 | 877 | set_transient( 'plugin_slugs', $plugin_slugs, 86400 ); |
| 865 | 878 | } |
| 866 | 879 | |
| 867 | | foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) { |
| 868 | | if ( is_wp_error($$feed) || !$$feed->get_item_quantity() ) |
| | 880 | // Pick a random, non-installed plugin per feed |
| | 881 | foreach ( $feeds as $feed_data ) { |
| | 882 | $label = $feed_data['label']; |
| | 883 | |
| | 884 | $feed = fetch_feed( $feed_data['url'] ); |
| | 885 | if ( is_wp_error( $feed ) || ! $feed->get_item_quantity() ) |
| 869 | 886 | continue; |
| 870 | 887 | |
| 871 | | $items = $$feed->get_items(0, 5); |
| | 888 | $items = $feed->get_items( 0, 5 ); |
| 872 | 889 | |
| 873 | 890 | // Pick a random, non-installed plugin |
| 874 | | while ( true ) { |
| 875 | | // Abort this foreach loop iteration if there's no plugins left of this type |
| 876 | | if ( 0 == count($items) ) |
| | 891 | while( true ) { |
| | 892 | if ( 0 == count( $items ) ) |
| 877 | 893 | continue 2; |
| 878 | 894 | |
| 879 | | $item_key = array_rand($items); |
| 880 | | $item = $items[$item_key]; |
| | 895 | $item_key = array_rand( $items ); |
| | 896 | $item = $items[$item_key]; |
| | 897 | |
| | 898 | // filter plugins with common badly formed descriptions |
| | 899 | $description = $item->get_description(); |
| | 900 | if ( false !== strpos( $description, 'Plugin Name:' ) ) { |
| | 901 | unset( $items[$item_key] ); |
| | 902 | continue; |
| | 903 | } |
| 881 | 904 | |
| 882 | | list($link, $frag) = explode( '#', $item->get_link() ); |
| 883 | | |
| 884 | | $link = esc_url($link); |
| | 905 | // filter plugins with common badly formed links |
| | 906 | list( $link, $frag ) = explode( '#', $item->get_link() ); |
| | 907 | $link = esc_url( $link ); |
| 885 | 908 | if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) ) |
| 886 | 909 | $slug = $matches[1]; |
| 887 | 910 | else { |
| … |
… |
|
| 889 | 912 | continue; |
| 890 | 913 | } |
| 891 | 914 | |
| 892 | | // Is this random plugin's slug already installed? If so, try again. |
| 893 | | reset( $plugin_slugs ); |
| 894 | | foreach ( $plugin_slugs as $plugin_slug ) { |
| 895 | | if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) { |
| 896 | | unset( $items[$item_key] ); |
| 897 | | continue 2; |
| 898 | | } |
| | 915 | // filter out already installed plugins |
| | 916 | if ( in_array( $slug, $plugin_slugs ) ) { |
| | 917 | unset( $items[$item_key] ); |
| | 918 | continue; |
| 899 | 919 | } |
| 900 | 920 | |
| 901 | 921 | // If we get to this point, then the random plugin isn't installed and we can stop the while(). |
| 902 | 922 | break; |
| 903 | 923 | } |
| 904 | 924 | |
| 905 | | // Eliminate some common badly formed plugin descriptions |
| 906 | | while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) ) |
| 907 | | unset($items[$item_key]); |
| | 925 | $title = $item->get_title(); |
| 908 | 926 | |
| 909 | | if ( !isset($items[$item_key]) ) |
| 910 | | continue; |
| 911 | | |
| 912 | 927 | // current bbPress feed item titles are: user on "topic title" |
| 913 | | if ( preg_match( '/"(.*)"/s', $item->get_title(), $matches ) ) |
| | 928 | if ( preg_match( '/"(.*)"/s', $title, $matches ) ) |
| 914 | 929 | $title = $matches[1]; |
| 915 | | else // but let's make it forward compatible if things change |
| 916 | | $title = $item->get_title(); |
| 917 | | $title = esc_html( $title ); |
| 918 | 930 | |
| 919 | | $description = esc_html( strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))) ); |
| | 931 | $title = esc_html( $title ); |
| 920 | 932 | |
| 921 | | $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . |
| 922 | | '&TB_iframe=true&width=600&height=800'; |
| | 933 | $description = strip_tags( @html_entity_decode( $description ), ENT_QUOTES, get_option( 'blog_charset' ) ); |
| | 934 | $description = esc_html( $description ); |
| | 935 | |
| | 936 | $ilink_url = 'plugin-install.php?tab=plugin-information&plugin=' . $slug; |
| | 937 | $ilink_action = 'install-plugin_' . $slug; |
| | 938 | $ilink_suffix = '&TB_iframe=true&width=600&height=800'; |
| | 939 | $ilink = wp_nonce_url( $ilink_url , $ilink_action ) . $ilink_suffix; |
| 923 | 940 | |
| 924 | 941 | echo "<h4>$label</h4>\n"; |
| 925 | 942 | echo "<h5><a href='$link'>$title</a></h5> <span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span>\n"; |
| 926 | 943 | echo "<p>$description</p>\n"; |
| 927 | 944 | |
| 928 | | $$feed->__destruct(); |
| 929 | | unset($$feed); |
| | 945 | $feed->__destruct(); |
| | 946 | unset( $feed ); |
| 930 | 947 | } |
| 931 | 948 | } |
| 932 | 949 | |