X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/98a4d31e52bd56c908617df281730bd4ba58d110..58f607a1de715c9bca69340a4d6fb9e1b9c2bed2:/wp-admin/includes/plugin-install.php diff --git a/wp-admin/includes/plugin-install.php b/wp-admin/includes/plugin-install.php index f81ecc82..f348e609 100644 --- a/wp-admin/includes/plugin-install.php +++ b/wp-admin/includes/plugin-install.php @@ -24,27 +24,30 @@ * * @param string $action * @param array|object $args Optional. Arguments to serialize for the Plugin Info API. - * @return mixed + * @return object plugins_api response object on success, WP_Error on failure. */ function plugins_api($action, $args = null) { - if( is_array($args) ) + if ( is_array($args) ) $args = (object)$args; if ( !isset($args->per_page) ) $args->per_page = 24; - $args = apply_filters('plugins_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter. - $res = apply_filters('plugins_api', false, $action, $args); //NOTE: Allows a plugin to completely override the builtin WordPress.org API. + // Allows a plugin to override the WordPress.org API entirely. + // Use the filter 'plugins_api_result' to mearly add results. + // Please ensure that a object is returned from the following filters. + $args = apply_filters('plugins_api_args', $args, $action); + $res = apply_filters('plugins_api', false, $action, $args); - if ( ! $res ) { - $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) ); + if ( false === $res ) { + $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) ); if ( is_wp_error($request) ) { - $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.

Try again'), $request->get_error_message() ); + $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() ); } else { $res = unserialize($request['body']); - if ( ! $res ) - $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']); + if ( false === $res ) + $res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), $request['body']); } } elseif ( !is_wp_error($res) ) { $res->external = true; @@ -136,16 +139,20 @@ function install_dashboard() { $api_tags = install_popular_tags(); - //Set up the tags in a way which can be interprated by wp_generate_tag_cloud() - $tags = array(); - foreach ( (array)$api_tags as $tag ) - $tags[ $tag['name'] ] = (object) array( - 'link' => esc_url( admin_url('plugin-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ), - 'name' => $tag['name'], - 'id' => sanitize_title_with_dashes($tag['name']), - 'count' => $tag['count'] ); echo '


'; } @@ -162,7 +169,7 @@ function install_search_form(){ @@ -182,7 +189,7 @@ function install_featured($page = 1) { $args = array('browse' => 'featured', 'page' => $page); $api = plugins_api('query_plugins', $args); if ( is_wp_error($api) ) - wp_die($api); + wp_die($api->get_error_message() . '

' . __('Try again') . ''); display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']); } @@ -197,6 +204,8 @@ add_action('install_plugins_popular', 'install_popular', 10, 1); function install_popular($page = 1) { $args = array('browse' => 'popular', 'page' => $page); $api = plugins_api('query_plugins', $args); + if ( is_wp_error($api) ) + wp_die($api->get_error_message() . '

' . __('Try again') . ''); display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']); } @@ -210,7 +219,7 @@ add_action('install_plugins_upload', 'install_plugins_upload', 10, 1); function install_plugins_upload( $page = 1 ) { ?>

-

+

@@ -232,7 +241,7 @@ function install_new($page = 1) { $args = array('browse' => 'new', 'page' => $page); $api = plugins_api('query_plugins', $args); if ( is_wp_error($api) ) - wp_die($api); + wp_die($api->get_error_message() . '

' . __('Try again') . ''); display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']); } add_action('install_plugins_updated', 'install_updated', 10, 1); @@ -248,6 +257,8 @@ add_action('install_plugins_updated', 'install_updated', 10, 1); function install_updated($page = 1) { $args = array('browse' => 'updated', 'page' => $page); $api = plugins_api('query_plugins', $args); + if ( is_wp_error($api) ) + wp_die($api->get_error_message() . '

' . __('Try again') . ''); display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']); } @@ -302,7 +313,6 @@ function display_plugins_table($plugins, $page = 1, $totalpages = 1){ - @@ -312,16 +322,15 @@ function display_plugins_table($plugins, $page = 1, $totalpages = 1){ - ', __('No plugins match your request.'), ''; - foreach( (array) $plugins as $plugin ){ + foreach ( (array) $plugins as $plugin ){ if ( is_object($plugin) ) $plugin = (array) $plugin; @@ -342,23 +351,41 @@ function display_plugins_table($plugins, $page = 1, $totalpages = 1){ $name = strip_tags($title . ' ' . $version); $author = $plugin['author']; - if( ! empty($plugin['author']) ) + if ( ! empty($plugin['author']) ) $author = ' ' . sprintf( __('By %s'), $author ) . '.'; $author = wp_kses($author, $plugins_allowedtags); - if( isset($plugin['homepage']) ) - $title = '' . $title . ''; - $action_links = array(); $action_links[] = '' . __('Install') . ''; + '&TB_iframe=true&width=600&height=550') . '" class="thickbox" title="' . + esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __('Details') . ''; + + if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) { + $status = install_plugin_install_status($plugin); + + switch ( $status['status'] ) { + case 'install': + if ( $status['url'] ) + $action_links[] = '' . __('Install Now') . ''; + break; + case 'update_available': + if ( $status['url'] ) + $action_links[] = '' . sprintf( __('Update Now'), $status['version'] ) . ''; + break; + case 'latest_installed': + case 'newer_installed': + $action_links[] = '' . __('Installed') . ''; + break; + } + } - $action_links = apply_filters('plugin_install_action_links', $action_links, $plugin); + $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin ); ?> - + +

+
@@ -371,7 +398,6 @@ function display_plugins_table($plugins, $page = 1, $totalpages = 1){
- response as $file => $plugin ) { + if ( $plugin->slug === $api->slug ) { + $status = 'update_available'; + $update_file = $file; + $version = $plugin->new_version; + if ( current_user_can('update_plugins') ) + $url = wp_nonce_url(admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file); + break; + } + } + } + + if ( 'install' == $status ) { + if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { + $installed_plugin = get_plugins('/' . $api->slug); + if ( empty($installed_plugin) ) { + if ( current_user_can('install_plugins') ) + $url = wp_nonce_url(admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); + } else { + $key = array_shift( $key = array_keys($installed_plugin) ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers + if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){ + $status = 'latest_installed'; + } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) { + $status = 'newer_installed'; + $version = $installed_plugin[ $key ]['Version']; + } else { + //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh + if ( ! $loop ) { + delete_site_transient('update_plugins'); + wp_update_plugins(); + return install_plugin_install_status($api, true); + } + } + } + } else { + // "install" & no directory with that slug + if ( current_user_can('install_plugins') ) + $url = wp_nonce_url(admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); + } + } + if ( isset($_GET['from']) ) + $url .= '&from=' . urlencode(stripslashes($_GET['from'])); + + return compact('status', 'url', 'version'); +} + /** * Display plugin information in dialog box form. * @@ -416,7 +505,7 @@ function install_plugin_information() { $api->$key = wp_kses($api->$key, $plugins_allowedtags); $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English. - if( empty($section) || ! isset($api->sections[ $section ]) ) + if ( empty($section) || ! isset($api->sections[ $section ]) ) $section = array_shift( $section_titles = array_keys((array)$api->sections) ); iframe_header( __('Plugin Install') ); @@ -437,66 +526,30 @@ function install_plugin_information() { echo "\n"; ?>
- download_link) ) : ?> + download_link) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) : ?>

response as $file => $plugin ) { - if ( $plugin->slug === $api->slug ) { - $type = 'update_available'; - $update_file = $file; - break; - } - } - } - if ( 'install' == $type && is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { - $installed_plugin = get_plugins('/' . $api->slug); - if ( ! empty($installed_plugin) ) { - $key = array_shift( $key = array_keys($installed_plugin) ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers - if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){ - $type = 'latest_installed'; - } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) { - $type = 'newer_installed'; - $newer_version = $installed_plugin[ $key ]['Version']; - } else { - //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh - delete_transient('update_plugins'); - $update_file = $api->slug . '/' . $key; //This code branch only deals with a plugin which is in a folder the same name as its slug, Doesnt support plugins which have 'non-standard' names - $type = 'update_available'; - } - } - } - - switch ( $type ) : - default: - case 'install': - if ( current_user_can('install_plugins') ) : - ?>' . __('Install Now') . ''; break; - case 'update_available': - if ( current_user_can('update_plugins') ) : - ?>' . __('Install Update Now') .''; break; - case 'newer_installed': - if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) : - ?>' . sprintf(__('Newer Version (%s) Installed'), $status['version']) . ''; break; - case 'latest_installed': - if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) : - ?>' . __('Latest Version Installed') . ''; break; - endswitch; ?> + } + ?>

-

+