From 5e87cb848d35bd5ed2f5a49decbd40bab800b775 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 5 Aug 2008 17:06:42 +0000 Subject: [PATCH] Plugin install fixes from DD32. see #6015 git-svn-id: http://svn.automattic.com/wordpress/trunk@8550 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/dashboard.php | 2 +- wp-admin/includes/plugin-install.php | 116 ++++++++++++++++----------- wp-admin/index.php | 4 +- wp-admin/plugin-install.php | 6 +- wp-admin/plugins.php | 2 +- 5 files changed, 78 insertions(+), 52 deletions(-) diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index fe92c70f73..611e3a5010 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -438,7 +438,7 @@ function wp_dashboard_plugins_output() { else $slug = ''; - $ilink = wp_nonce_url('plugin-install.php?tab=install-confirmation&plugin=' . $slug, 'install-plugin_' . $slug) . + $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&TB_iframe=true&width=600&height=800'; echo "

$label

\n"; diff --git a/wp-admin/includes/plugin-install.php b/wp-admin/includes/plugin-install.php index 1fddfb9a65..58d60dba5d 100644 --- a/wp-admin/includes/plugin-install.php +++ b/wp-admin/includes/plugin-install.php @@ -1,34 +1,37 @@ $action, 'request' => serialize($args))) );//Note: http_build_query() can be removed once WP_HTTP accepts unencoded data. + $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array(), array(), array('action' => $action, 'request' => serialize($args)) ); $res = unserialize($request['body']); if ( ! $res ) wp_die($request['body']); } - return apply_filters('plugins_api_result', $res); + return apply_filters('plugins_api_result', $res, $action, $args); } function install_popular_tags( $args = array() ) { - if ( ! $cache = get_option('wporg_popular_tags') ) + if ( ! ($cache = wp_cache_get('popular_tags', 'api')) && ! ($cache = get_option('wporg_popular_tags')) ) add_option('wporg_popular_tags', array(), '', 'no');///No autoload. if ( $cache && $cache->timeout + 3 * 60 * 60 > time() ) return $cache->cached; - $tags = plugins_api('hot_tags'); + $tags = plugins_api('hot_tags', $args); - update_option('wporg_popular_tags', (object) array('timeout' => time(), 'cached' => $tags)); + $cache = (object) array('timeout' => time(), 'cached' => $tags); + + update_option('wporg_popular_tags', $cache); + wp_cache_set('popular_tags', $cache, 'api'); return $tags; } @@ -236,9 +239,9 @@ function display_plugins_table($plugins, $page = 1, $totalpages = 1){ function install_iframe_header($title = '') { if( empty($title) ) - $title = __('Plugin Install') . ' — ' . __('WordPress'); + $title = __('Plugin Install — WordPress'); -register_shutdown_function('install_iframe_footer'); //Do footer after content, Allows us to simply die or return at any point. +register_shutdown_function('install_iframe_footer'); //Do footer after content, Allows us to simply die or return at any point as may happen with error handlers ?> @@ -288,7 +291,7 @@ function install_plugin_information() { foreach ( (array)$api->sections as $section_name => $content ) { $title = $section_name; - $title[0] = strtoupper($title[0]); + $title[0] = strtoupper($title[0]); //Capitalize first character. $title = str_replace('_', ' ', $title); $class = ( $section_name == $section ) ? ' class="current"' : ''; @@ -305,18 +308,19 @@ function install_plugin_information() { download_link) ) : ?>

slug ) ) { //TODO: Make more.. searchable? - $type = 'latest_installed'; - $update_plugins = get_option('update_plugins'); - foreach ( (array)$update_plugins->response as $file => $plugin ) { - if ( $plugin->slug === $api->slug ) { - $type = 'update_available'; - $update_file = $file; - break; - } + //Check to see if this plugin is known to be installed, and has an update awaiting it. + $update_plugins = get_option('update_plugins'); + foreach ( (array)$update_plugins->response as $file => $plugin ) { + if ( $plugin->slug === $api->slug ) { + $type = 'update_available'; + $update_file = $file; + break; } } + if ( 'install' == $type && file_exists( WP_PLUGIN_DIR . '/' . $api->slug ) ) //TODO: Make more.. searchable? + $type = 'latest_installed'; switch ( $type ) : default: @@ -370,49 +374,50 @@ function install_plugin_information() { num_ratings) ?> +

\n"; - foreach ( (array)$api->sections as $section_name => $content ) { - $title = $section_name; - $title[0] = strtoupper($title[0]); - $title = str_replace('_', ' ', $title); - - $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/'); - $content = links_add_target($content, '_blank'); - - $san_title = attribute_escape(sanitize_title_with_dashes($title)); - - $display = ( $section_name == $section ) ? 'block' : 'none'; - - echo "\t
\n"; - echo "\t\t

$title

"; - echo $content; - echo "\t
\n"; - } + foreach ( (array)$api->sections as $section_name => $content ) { + $title = $section_name; + $title[0] = strtoupper($title[0]); + $title = str_replace('_', ' ', $title); + + $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/'); + $content = links_add_target($content, '_blank'); + + $san_title = attribute_escape(sanitize_title_with_dashes($title)); + + $display = ( $section_name == $section ) ? 'block' : 'none'; + + echo "\t
\n"; + echo "\t\t

$title

"; + echo $content; + echo "\t
\n"; + } echo "
\n"; - - //var_dump($api); + exit; } add_action('install_plugins_pre_install', 'install_plugin'); function install_plugin() { - check_admin_referer('install-plugin_' . $_REQUEST['plugin']); + $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : ''; + + check_admin_referer('install-plugin_' . $plugin); install_iframe_header(); - $api = plugins_api('plugin_information', array('slug' => $_REQUEST['plugin'], 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth. + $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth. echo '
'; echo '

', sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version ), '

'; - do_plugin_install($api->download_link); + do_plugin_install($api->download_link, $api); echo '
'; exit; } -function do_plugin_install($download_url = '') { +function do_plugin_install($download_url = '', $plugin_information = NULL) { global $wp_filesystem; if ( empty($download_url) ) { @@ -425,7 +430,7 @@ function do_plugin_install($download_url = '') { $url = 'plugin-install.php?tab=install'; $url = add_query_arg(array('plugin' => $plugin, 'plugin_name' => $_REQUEST['plugin_name'], 'download_url' => $_REQUEST['download_url']), $url); - $url = wp_nonce_url($url, "install-plugin_$plugin"); + $url = wp_nonce_url($url, 'install-plugin_' . $plugin); if ( false === ($credentials = request_filesystem_credentials($url)) ) return; @@ -446,7 +451,16 @@ function do_plugin_install($download_url = '') { show_message($result); show_message( __('Installation Failed') ); } else { - show_message( sprintf(__('Successfully installed the plugin %s %s.'), $plugin_information->name, $plugin_information->version) ); + show_message( sprintf(__('Successfully installed the plugin %s %s.'), $plugin_information->name, $plugin_information->version) ); + $plugin_file = $result; + + $install_actions = apply_filters('install_plugin_complete_actions', array( + 'activate_plugin' => '' . __('Activate Plugin') . '', + 'plugins_page' => '' . __('Return to Plugins page') . '', + 'dismiss_dialog' => '' . __('Dismiss Dialog') . '' + ), $plugin_information, $plugin_file); + + echo '

' . __('Actions:') . '' . implode(' | ', (array)$install_actions) . '

'; } } @@ -523,9 +537,21 @@ function wp_install_plugin($package, $feedback = '') { return $result; } + //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin + $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); + // Remove working directory $wp_filesystem->delete($working_dir, true); + + if( empty($filelist) ) + return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. + + $folder = $filelist[0]; + $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash + $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list + //Return the plugin files name. + return $folder . '/' . $pluginfiles[0]; } diff --git a/wp-admin/index.php b/wp-admin/index.php index 77e4f7e375..018f5ef31f 100644 --- a/wp-admin/index.php +++ b/wp-admin/index.php @@ -27,9 +27,9 @@ jQuery(function($) { add_action( 'admin_head', 'index_js' ); wp_enqueue_script( 'jquery' ); -wp_enqueue_script( 'plugin-installer' ); +wp_enqueue_script( 'plugin-install' ); wp_admin_css( 'dashboard' ); -wp_admin_css( 'plugin-installer' ); +wp_admin_css( 'plugin-install' ); add_thickbox(); $title = __('Dashboard'); diff --git a/wp-admin/plugin-install.php b/wp-admin/plugin-install.php index 1361a140ab..73bb7a6058 100644 --- a/wp-admin/plugin-install.php +++ b/wp-admin/plugin-install.php @@ -1,14 +1,14 @@ ', $plugin['Title'], ' ', __('By'), ' ', $plugin['Author'], ''; + echo '
  • ', sprintf(__('%s by %s'), $plugin['Name'], $plugin['Author']), '
  • '; ?>