Make WordPress Core

Changeset 8550


Ignore:
Timestamp:
08/05/2008 05:06:42 PM (16 years ago)
Author:
ryan
Message:

Plugin install fixes from DD32. see #6015

Location:
trunk/wp-admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/dashboard.php

    r8540 r8550  
    439439            $slug = '';
    440440
    441         $ilink = wp_nonce_url('plugin-install.php?tab=install-confirmation&plugin=' . $slug, 'install-plugin_' . $slug) .
     441        $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
    442442                            '&TB_iframe=true&width=600&height=800';
    443443
  • trunk/wp-admin/includes/plugin-install.php

    r8541 r8550  
    11<?php
    22
    3 function plugins_api($action, $args = '') {
     3function plugins_api($action, $args = NULL) {
    44    global $wp_version;
    55
     
    88
    99    $args = apply_filters('plugins_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
    10     $res = apply_filters('plugins_api', false); //NOTE: Allows a plugin to completely override the builtin WordPress.org API.
     10    $res = apply_filters('plugins_api', false, $action, $args); //NOTE: Allows a plugin to completely override the builtin WordPress.org API.
    1111   
    1212    if ( ! $res ) {
    13         $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array(), array(), http_build_query(array('action' => $action, 'request' => serialize($args))) );//Note: http_build_query() can be removed once WP_HTTP accepts unencoded data.
     13        $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array(), array(), array('action' => $action, 'request' => serialize($args)) );
    1414        $res = unserialize($request['body']);
    1515        if ( ! $res )
     
    1717    }
    1818
    19     return apply_filters('plugins_api_result', $res);
     19    return apply_filters('plugins_api_result', $res, $action, $args);
    2020}
    2121
    2222function install_popular_tags( $args = array() ) {
    23     if ( ! $cache = get_option('wporg_popular_tags') )
     23    if ( ! ($cache = wp_cache_get('popular_tags', 'api')) && ! ($cache = get_option('wporg_popular_tags')) )
    2424        add_option('wporg_popular_tags', array(), '', 'no');///No autoload.
    2525
     
    2727        return $cache->cached;
    2828
    29     $tags = plugins_api('hot_tags');
    30 
    31     update_option('wporg_popular_tags', (object) array('timeout' => time(), 'cached' => $tags));
     29    $tags = plugins_api('hot_tags', $args);
     30
     31    $cache = (object) array('timeout' => time(), 'cached' => $tags);
     32
     33    update_option('wporg_popular_tags', $cache);
     34    wp_cache_set('popular_tags', $cache, 'api');
    3235
    3336    return $tags;
     
    237240function install_iframe_header($title = '') {
    238241if( empty($title) )
    239     $title = __('Plugin Install') . ' &#8212; ' . __('WordPress');
    240 
    241 register_shutdown_function('install_iframe_footer'); //Do footer after content, Allows us to simply die or return at any point.
     242    $title = __('Plugin Install &#8212; WordPress');
     243
     244register_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
    242245
    243246?>
     
    289292   
    290293        $title = $section_name;
    291         $title[0] = strtoupper($title[0]);
     294        $title[0] = strtoupper($title[0]); //Capitalize first character.
    292295        $title = str_replace('_', ' ', $title);
    293296
     
    306309        <p class="action-button">
    307310        <?php
     311            //Default to a "new" plugin
    308312            $type = 'install';
    309             if ( file_exists( WP_PLUGIN_DIR  . '/' . $api->slug ) ) { //TODO: Make more.. searchable?
    310                 $type = 'latest_installed';
    311                 $update_plugins = get_option('update_plugins');
    312                 foreach ( (array)$update_plugins->response as $file => $plugin ) {
    313                     if ( $plugin->slug === $api->slug ) {
    314                         $type = 'update_available';
    315                         $update_file = $file;
    316                         break;
    317                     }
     313            //Check to see if this plugin is known to be installed, and has an update awaiting it.
     314            $update_plugins = get_option('update_plugins');
     315            foreach ( (array)$update_plugins->response as $file => $plugin ) {
     316                if ( $plugin->slug === $api->slug ) {
     317                    $type = 'update_available';
     318                    $update_file = $file;
     319                    break;
    318320                }
    319321            }
     322            if ( 'install' == $type && file_exists( WP_PLUGIN_DIR  . '/' . $api->slug ) ) //TODO: Make more.. searchable?
     323                $type = 'latest_installed';
    320324
    321325            switch ( $type ) :
     
    371375        <small><?php printf(__('(based on %d ratings)'), $api->num_ratings) ?></small>
    372376    </div>
     377    <div id="section-holder" class="wrap">
    373378        <?php
    374     echo "<div id='section-holder' class='wrap'>\n";
    375     foreach ( (array)$api->sections as $section_name => $content ) {
    376         $title = $section_name;
    377         $title[0] = strtoupper($title[0]);
    378         $title = str_replace('_', ' ', $title);
    379        
    380         $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/');
    381         $content = links_add_target($content, '_blank');
    382        
    383         $san_title = attribute_escape(sanitize_title_with_dashes($title));
    384        
    385         $display = ( $section_name == $section ) ? 'block' : 'none';
    386        
    387         echo "\t<div id='section-{$san_title}' style='display: {$display};'>\n";
    388         echo "\t\t<h2 class='long-header'>$title</h2>";
    389         echo $content;
    390         echo "\t</div>\n";
    391     }
     379        foreach ( (array)$api->sections as $section_name => $content ) {
     380            $title = $section_name;
     381            $title[0] = strtoupper($title[0]);
     382            $title = str_replace('_', ' ', $title);
     383           
     384            $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/');
     385            $content = links_add_target($content, '_blank');
     386           
     387            $san_title = attribute_escape(sanitize_title_with_dashes($title));
     388           
     389            $display = ( $section_name == $section ) ? 'block' : 'none';
     390           
     391            echo "\t<div id='section-{$san_title}' style='display: {$display};'>\n";
     392            echo "\t\t<h2 class='long-header'>$title</h2>";
     393            echo $content;
     394            echo "\t</div>\n";
     395        }
    392396    echo "</div>\n";
    393        
    394     //var_dump($api);
     397
    395398    exit;
    396399}
     
    399402function install_plugin() {
    400403
    401     check_admin_referer('install-plugin_' . $_REQUEST['plugin']);
     404    $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
     405
     406    check_admin_referer('install-plugin_' . $plugin);
    402407
    403408    install_iframe_header();
    404409   
    405     $api = plugins_api('plugin_information', array('slug' => $_REQUEST['plugin'], 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
     410    $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
    406411   
    407412    echo '<div class="wrap">';
    408413    echo '<h2>', sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version ), '</h2>';
    409414
    410     do_plugin_install($api->download_link);
     415    do_plugin_install($api->download_link, $api);
    411416    echo '</div>';
    412417
    413418    exit;
    414419}
    415 function do_plugin_install($download_url = '') {
     420function do_plugin_install($download_url = '', $plugin_information = NULL) {
    416421    global $wp_filesystem;
    417422   
     
    426431    $url = add_query_arg(array('plugin' => $plugin, 'plugin_name' => $_REQUEST['plugin_name'], 'download_url' => $_REQUEST['download_url']), $url);
    427432
    428     $url = wp_nonce_url($url, "install-plugin_$plugin");
     433    $url = wp_nonce_url($url, 'install-plugin_' . $plugin);
    429434    if ( false === ($credentials = request_filesystem_credentials($url)) )
    430435        return;
     
    447452        show_message( __('Installation Failed') );
    448453    } else {
    449         show_message( sprintf(__('Successfully installed the plugin <strong>%s %s</strong>.'), $plugin_information->name, $plugin_information->version) ); 
     454        show_message( sprintf(__('Successfully installed the plugin <strong>%s %s</strong>.'), $plugin_information->name, $plugin_information->version) );
     455        $plugin_file = $result;
     456
     457        $install_actions = apply_filters('install_plugin_complete_actions', array(
     458                            'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
     459                            'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . __('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
     460                            'dismiss_dialog' => '<a href="' . admin_url('plugin-installer.php') . '" onclick="window.parent.tb_remove(); return false;" title="' . __('Dismiss Dialog') . '" target="_parent">' . __('Dismiss Dialog') . '</a>'
     461                            ), $plugin_information, $plugin_file);
     462
     463        echo '<p><strong>' . __('Actions:') . '</strong>' . implode(' | ', (array)$install_actions) . '</p>';
    450464    }
    451465}
     
    524538    }
    525539
     540    //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
     541    $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
     542
    526543    // Remove working directory
    527544    $wp_filesystem->delete($working_dir, true);
    528 
     545   
     546    if( empty($filelist) )
     547        return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
     548   
     549    $folder = $filelist[0];
     550    $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
     551    $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
     552
     553    //Return the plugin files name.
     554    return  $folder . '/' . $pluginfiles[0];
    529555}
    530556
  • trunk/wp-admin/index.php

    r8540 r8550  
    2828
    2929wp_enqueue_script( 'jquery' );
    30 wp_enqueue_script( 'plugin-installer' );
     30wp_enqueue_script( 'plugin-install' );
    3131wp_admin_css( 'dashboard' );
    32 wp_admin_css( 'plugin-installer' );
     32wp_admin_css( 'plugin-install' );
    3333add_thickbox();
    3434
  • trunk/wp-admin/plugin-install.php

    r8541 r8550  
    11<?php
    22require_once('admin.php');
     3
     4if ( ! current_user_can('install_plugins') )
     5    wp_die(__('You do not have sufficient permissions to install plugins on this blog.'));
    36
    47include(ABSPATH . 'wp-admin/includes/plugin-install.php');
     
    69$title = __('Install Plugins');
    710$parent_file = 'plugins.php';
    8 
    9 if ( ! current_user_can('install_plugins') )
    10     wp_die(__('You do not have sufficient permissions to install plugins on this blog.'));
    1111
    1212wp_reset_vars( array('tab', 'paged') );
  • trunk/wp-admin/plugins.php

    r8540 r8550  
    114114                        <?php
    115115                        foreach( $plugin_info as $plugin )
    116                             echo '<li>', $plugin['Title'], ' ', __('By'), ' ', $plugin['Author'], '</li>';
     116                            echo '<li>', sprintf(__('%s by %s'), $plugin['Name'], $plugin['Author']), '</li>';
    117117                        ?>
    118118                    </ul>
Note: See TracChangeset for help on using the changeset viewer.