-
+ 3D1DBD95F50D5FBE6C82ADE12C760E3C8FECDB8B50CC56B12705C20AA8607E5AA79D34D1C3128A8897AE673C3C513558273D73D68450A6149D2CD5F4F88DBC08
mp-wp/wp-admin/includes/plugin-install.php
(0 . 0)(1 . 894)
36836 <?php
36837 /**
36838 * WordPress Plugin Install Administration API
36839 *
36840 * @package WordPress
36841 * @subpackage Administration
36842 */
36843
36844 /**
36845 * Retrieve plugin installer pages from WordPress Plugins API.
36846 *
36847 * It is possible for a plugin to override the Plugin API result with three
36848 * filters. Assume this is for plugins, which can extend on the Plugin Info to
36849 * offer more choices. This is very powerful and must be used with care, when
36850 * overridding the filters.
36851 *
36852 * The first filter, 'plugins_api_args', is for the args and gives the action as
36853 * the second parameter. The hook for 'plugins_api_args' must ensure that an
36854 * object is returned.
36855 *
36856 * The second filter, 'plugins_api', is the result that would be returned.
36857 *
36858 * @since 2.7.0
36859 *
36860 * @param string $action
36861 * @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
36862 * @return mixed
36863 */
36864 function plugins_api($action, $args = null) {
36865
36866 if( is_array($args) )
36867 $args = (object)$args;
36868
36869 if ( !isset($args->per_page) )
36870 $args->per_page = 24;
36871
36872 $args = apply_filters('plugins_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
36873 $res = apply_filters('plugins_api', false, $action, $args); //NOTE: Allows a plugin to completely override the builtin WordPress.org API.
36874
36875 if ( ! $res ) {
36876 $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
36877 if ( is_wp_error($request) ) {
36878 $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occured during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message() );
36879 } else {
36880 $res = unserialize($request['body']);
36881 if ( ! $res )
36882 $res = new WP_Error('plugins_api_failed', __('An unknown error occured'), $request['body']);
36883 }
36884 }
36885
36886 return apply_filters('plugins_api_result', $res, $action, $args);
36887 }
36888
36889 /**
36890 * Retrieve popular WordPress plugin tags.
36891 *
36892 * @since 2.7.0
36893 *
36894 * @param array $args
36895 * @return array
36896 */
36897 function install_popular_tags( $args = array() ) {
36898 if ( ! ($cache = wp_cache_get('popular_tags', 'api')) && ! ($cache = get_option('wporg_popular_tags')) )
36899 add_option('wporg_popular_tags', array(), '', 'no'); ///No autoload.
36900
36901 if ( $cache && $cache->timeout + 3 * 60 * 60 > time() )
36902 return $cache->cached;
36903
36904 $tags = plugins_api('hot_tags', $args);
36905
36906 if ( is_wp_error($tags) )
36907 return $tags;
36908
36909 $cache = (object) array('timeout' => time(), 'cached' => $tags);
36910
36911 update_option('wporg_popular_tags', $cache);
36912 wp_cache_set('popular_tags', $cache, 'api');
36913
36914 return $tags;
36915 }
36916 add_action('install_plugins_search', 'install_search', 10, 1);
36917
36918 /**
36919 * Display search results and display as tag cloud.
36920 *
36921 * @since 2.7.0
36922 *
36923 * @param string $page
36924 */
36925 function install_search($page) {
36926 $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
36927 $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
36928
36929 $args = array();
36930
36931 switch( $type ){
36932 case 'tag':
36933 $args['tag'] = sanitize_title_with_dashes($term);
36934 break;
36935 case 'term':
36936 $args['search'] = $term;
36937 break;
36938 case 'author':
36939 $args['author'] = $term;
36940 break;
36941 }
36942
36943 $args['page'] = $page;
36944
36945 $api = plugins_api('query_plugins', $args);
36946
36947 if ( is_wp_error($api) )
36948 wp_die($api);
36949
36950 add_action('install_plugins_table_header', 'install_search_form');
36951
36952 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
36953
36954 return;
36955 }
36956
36957 add_action('install_plugins_dashboard', 'install_dashboard');
36958 function install_dashboard() {
36959 ?>
36960 <p><?php _e('Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="http://wordpress.org/extend/plugins/">WordPress Plugin Directory</a> or upload a plugin in .zip format via this page.') ?></p>
36961
36962 <h4><?php _e('Search') ?></h4>
36963 <?php install_search_form('<a href="' . add_query_arg('show-help', !isset($_REQUEST['show-help'])) .'" onclick="jQuery(\'#search-help\').toggle(); return false;">' . __('[need help?]') . '</a>') ?>
36964 <div id="search-help" style="display: <?php echo isset($_REQUEST['show-help']) ? 'block' : 'none'; ?>;">
36965 <p> <?php _e('You may search based on 3 criteria:') ?><br />
36966 <?php _e('<strong>Term:</strong> Searches plugins names and descriptions for the specified term') ?><br />
36967 <?php _e('<strong>Tag:</strong> Searches for plugins tagged as such') ?><br />
36968 <?php _e('<strong>Author:</strong> Searches for plugins created by the Author, or which the Author contributed to.') ?></p>
36969 </div>
36970
36971 <h4><?php _e('Install a plugin in .zip format') ?></h4>
36972 <p><?php _e('If you have a plugin in a .zip format, You may install it by uploading it here.') ?></p>
36973 <form method="post" enctype="multipart/form-data" action="<?php echo admin_url('plugin-install.php?tab=upload') ?>">
36974 <?php wp_nonce_field( 'plugin-upload') ?>
36975 <input type="file" name="pluginzip" />
36976 <input type="submit" class="button" value="<?php _e('Install Now') ?>" />
36977 </form>
36978
36979 <h4><?php _e('Popular tags') ?></h4>
36980 <p><?php _e('You may also browse based on the most popular tags in the Plugin Directory:') ?></p>
36981 <?php
36982
36983 $api_tags = install_popular_tags();
36984
36985 //Set up the tags in a way which can be interprated by wp_generate_tag_cloud()
36986 $tags = array();
36987 foreach ( (array)$api_tags as $tag )
36988 $tags[ $tag['name'] ] = (object) array(
36989 'link' => clean_url( admin_url('plugin-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ),
36990 'name' => $tag['name'],
36991 'id' => sanitize_title_with_dashes($tag['name']),
36992 'count' => $tag['count'] );
36993 echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%d plugin'), 'multiple_text' => __('%d plugins') ) );
36994 }
36995
36996 /**
36997 * Display search form for searching plugins.
36998 *
36999 * @since 2.7.0
37000 */
37001 function install_search_form(){
37002 $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
37003 $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
37004
37005 ?><form id="search-plugins" method="post" action="<?php echo admin_url('plugin-install.php?tab=search') ?>">
37006 <select name="type" id="typeselector">
37007 <option value="term"<?php selected('term', $type) ?>><?php _e('Term') ?></option>
37008 <option value="author"<?php selected('author', $type) ?>><?php _e('Author') ?></option>
37009 <option value="tag"<?php selected('tag', $type) ?>><?php _e('Tag') ?></option>
37010 </select>
37011 <input type="text" name="s" id="search-field" value="<?php echo attribute_escape($term) ?>" />
37012 <input type="submit" name="search" value="<?php echo attribute_escape(__('Search')) ?>" class="button" />
37013 </form><?php
37014 }
37015
37016 add_action('install_plugins_featured', 'install_featured', 10, 1);
37017 /**
37018 * Display featured plugins.
37019 *
37020 * @since 2.7.0
37021 *
37022 * @param string $page
37023 */
37024 function install_featured($page = 1) {
37025 $args = array('browse' => 'featured', 'page' => $page);
37026 $api = plugins_api('query_plugins', $args);
37027 if ( is_wp_error($api) )
37028 wp_die($api);
37029 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
37030 }
37031
37032 add_action('install_plugins_popular', 'install_popular', 10, 1);
37033 /**
37034 * Display popular plugins.
37035 *
37036 * @since 2.7.0
37037 *
37038 * @param string $page
37039 */
37040 function install_popular($page = 1) {
37041 $args = array('browse' => 'popular', 'page' => $page);
37042 $api = plugins_api('query_plugins', $args);
37043 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
37044 }
37045
37046 add_action('install_plugins_new', 'install_new', 10, 1);
37047 /**
37048 * Display new plugins.
37049 *
37050 * @since 2.7.0
37051 *
37052 * @param string $page
37053 */
37054 function install_new($page = 1) {
37055 $args = array('browse' => 'new', 'page' => $page);
37056 $api = plugins_api('query_plugins', $args);
37057 if ( is_wp_error($api) )
37058 wp_die($api);
37059 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
37060 }
37061 add_action('install_plugins_updated', 'install_updated', 10, 1);
37062
37063
37064 /**
37065 * Display recently updated plugins.
37066 *
37067 * @since 2.7.0
37068 *
37069 * @param string $page
37070 */
37071 function install_updated($page = 1) {
37072 $args = array('browse' => 'updated', 'page' => $page);
37073 $api = plugins_api('query_plugins', $args);
37074 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
37075 }
37076
37077 /**
37078 * Display plugin content based on plugin list.
37079 *
37080 * @since 2.7.0
37081 *
37082 * @param array $plugins List of plugins.
37083 * @param string $page
37084 * @param int $totalpages Number of pages.
37085 */
37086 function display_plugins_table($plugins, $page = 1, $totalpages = 1){
37087 $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
37088 $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
37089
37090 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array(), 'target' => array()),
37091 'abbr' => array('title' => array()),'acronym' => array('title' => array()),
37092 'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array());
37093
37094 ?>
37095 <div class="tablenav">
37096 <div class="alignleft actions">
37097 <?php do_action('install_plugins_table_header'); ?>
37098 </div>
37099 <?php
37100 $url = clean_url($_SERVER['REQUEST_URI']);
37101 if ( ! empty($term) )
37102 $url = add_query_arg('s', $term, $url);
37103 if ( ! empty($type) )
37104 $url = add_query_arg('type', $type, $url);
37105
37106 $page_links = paginate_links( array(
37107 'base' => add_query_arg('paged', '%#%', $url),
37108 'format' => '',
37109 'prev_text' => __('«'),
37110 'next_text' => __('»'),
37111 'total' => $totalpages,
37112 'current' => $page
37113 ));
37114
37115 if ( $page_links )
37116 echo "\t\t<div class='tablenav-pages'>$page_links</div>";
37117 ?>
37118 <br class="clear" />
37119 </div>
37120 <table class="widefat" id="install-plugins" cellspacing="0">
37121 <thead>
37122 <tr>
37123 <th scope="col" class="name"><?php _e('Name'); ?></th>
37124 <th scope="col" class="num"><?php _e('Version'); ?></th>
37125 <th scope="col" class="num"><?php _e('Rating'); ?></th>
37126 <th scope="col" class="desc"><?php _e('Description'); ?></th>
37127 <th scope="col" class="action-links"><?php _e('Actions'); ?></th>
37128 </tr>
37129 </thead>
37130
37131 <tfoot>
37132 <tr>
37133 <th scope="col" class="name"><?php _e('Name'); ?></th>
37134 <th scope="col" class="num"><?php _e('Version'); ?></th>
37135 <th scope="col" class="num"><?php _e('Rating'); ?></th>
37136 <th scope="col" class="desc"><?php _e('Description'); ?></th>
37137 <th scope="col" class="action-links"><?php _e('Actions'); ?></th>
37138 </tr>
37139 </tfoot>
37140
37141 <tbody class="plugins">
37142 <?php
37143 if( empty($plugins) )
37144 echo '<tr><td colspan="5">', __('No plugins match your request.'), '</td></tr>';
37145
37146 foreach( (array) $plugins as $plugin ){
37147 if ( is_object($plugin) )
37148 $plugin = (array) $plugin;
37149
37150 $title = wp_kses($plugin['name'], $plugins_allowedtags);
37151 $description = wp_kses($plugin['description'], $plugins_allowedtags);
37152 $version = wp_kses($plugin['version'], $plugins_allowedtags);
37153
37154 $name = strip_tags($title . ' ' . $version);
37155
37156 $author = $plugin['author'];
37157 if( ! empty($plugin['author']) )
37158 $author = ' <cite>' . sprintf( __('By %s'), $author ) . '.</cite>';
37159
37160 $author = wp_kses($author, $plugins_allowedtags);
37161
37162 if( isset($plugin['homepage']) )
37163 $title = '<a target="_blank" href="' . attribute_escape($plugin['homepage']) . '">' . $title . '</a>';
37164
37165 $action_links = array();
37166 $action_links[] = '<a href="' . admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] .
37167 '&TB_iframe=true&width=600&height=800') . '" class="thickbox onclick" title="' .
37168 attribute_escape($name) . '">' . __('Install') . '</a>';
37169
37170 $action_links = apply_filters('plugin_install_action_links', $action_links, $plugin);
37171 ?>
37172 <tr>
37173 <td class="name"><?php echo $title; ?></td>
37174 <td class="vers"><?php echo $version; ?></td>
37175 <td class="vers">
37176 <div class="star-holder" title="<?php printf(__ngettext('(based on %s rating)', '(based on %s ratings)', $plugin['num_ratings']), number_format_i18n($plugin['num_ratings'])) ?>">
37177 <div class="star star-rating" style="width: <?php echo attribute_escape($plugin['rating']) ?>px"></div>
37178 <div class="star star5"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('5 stars') ?>" /></div>
37179 <div class="star star4"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('4 stars') ?>" /></div>
37180 <div class="star star3"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('3 stars') ?>" /></div>
37181 <div class="star star2"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('2 stars') ?>" /></div>
37182 <div class="star star1"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('1 star') ?>" /></div>
37183 </div>
37184 </td>
37185 <td class="desc"><p><?php echo $description, $author; ?></p></td>
37186 <td class="action-links"><?php if ( !empty($action_links) ) echo implode(' | ', $action_links); ?></td>
37187 </tr>
37188 <?php
37189 }
37190 ?>
37191 </tbody>
37192 </table>
37193
37194 <div class="tablenav">
37195 <?php if ( $page_links )
37196 echo "\t\t<div class='tablenav-pages'>$page_links</div>"; ?>
37197 <br class="clear" />
37198 </div>
37199
37200 <?php
37201 }
37202
37203 add_action('install_plugins_pre_plugin-information', 'install_plugin_information');
37204
37205 /**
37206 * Display plugin information in dialog box form.
37207 *
37208 * @since 2.7.0
37209 */
37210 function install_plugin_information() {
37211 global $tab;
37212
37213 $api = plugins_api('plugin_information', array('slug' => stripslashes( $_REQUEST['plugin'] ) ));
37214
37215 if ( is_wp_error($api) )
37216 wp_die($api);
37217
37218 $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
37219 'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
37220 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
37221 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
37222 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
37223 'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
37224 //Sanitize HTML
37225 foreach ( (array)$api->sections as $section_name => $content )
37226 $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags);
37227 foreach ( array('version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug') as $key )
37228 $api->$key = wp_kses($api->$key, $plugins_allowedtags);
37229
37230 $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
37231 if( empty($section) || ! isset($api->sections[ $section ]) )
37232 $section = array_shift( $section_titles = array_keys((array)$api->sections) );
37233
37234 iframe_header( __('Plugin Install') );
37235 echo "<div id='$tab-header'>\n";
37236 echo "<ul id='sidemenu'>\n";
37237 foreach ( (array)$api->sections as $section_name => $content ) {
37238
37239 $title = $section_name;
37240 $title = ucwords(str_replace('_', ' ', $title));
37241
37242 $class = ( $section_name == $section ) ? ' class="current"' : '';
37243 $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
37244 $href = clean_url($href);
37245 $san_title = attribute_escape(sanitize_title_with_dashes($title));
37246 echo "\t<li><a name='$san_title' target='' href='$href'$class>$title</a></li>\n";
37247 }
37248 echo "</ul>\n";
37249 echo "</div>\n";
37250 ?>
37251 <div class="alignright fyi">
37252 <?php if ( ! empty($api->download_link) ) : ?>
37253 <p class="action-button">
37254 <?php
37255 //Default to a "new" plugin
37256 $type = 'install';
37257 //Check to see if this plugin is known to be installed, and has an update awaiting it.
37258 $update_plugins = get_option('update_plugins');
37259 foreach ( (array)$update_plugins->response as $file => $plugin ) {
37260 if ( $plugin->slug === $api->slug ) {
37261 $type = 'update_available';
37262 $update_file = $file;
37263 break;
37264 }
37265 }
37266 if ( 'install' == $type && is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
37267 $installed_plugin = get_plugins('/' . $api->slug);
37268 if ( ! empty($installed_plugin) ) {
37269 $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
37270 if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '>') ){
37271 $type = 'latest_installed';
37272 } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) {
37273 $type = 'newer_installed';
37274 $newer_version = $installed_plugin[ $key ]['Version'];
37275 } else {
37276 //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
37277 delete_option('update_plugins');
37278 $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
37279 $type = 'update_available';
37280 }
37281 }
37282 }
37283
37284 switch ( $type ) :
37285 default:
37286 case 'install':
37287 if ( current_user_can('install_plugins') ) :
37288 ?><a href="<?php echo wp_nonce_url(admin_url('plugin-install.php?tab=install&plugin=' . $api->slug), 'install-plugin_' . $api->slug) ?>" target="_parent"><?php _e('Install Now') ?></a><?php
37289 endif;
37290 break;
37291 case 'update_available':
37292 if ( current_user_can('update_plugins') ) :
37293 ?><a href="<?php echo wp_nonce_url(admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file) ?>" target="_parent"><?php _e('Install Update Now') ?></a><?php
37294 endif;
37295 break;
37296 case 'newer_installed':
37297 if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) :
37298 ?><a><?php printf(__('Newer Version (%s) Installed'), $newer_version) ?></a><?php
37299 endif;
37300 break;
37301 case 'latest_installed':
37302 if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) :
37303 ?><a><?php _e('Latest Version Installed') ?></a><?php
37304 endif;
37305 break;
37306 endswitch; ?>
37307 </p>
37308 <?php endif; ?>
37309 <h2 class="mainheader"><?php _e('FYI') ?></h2>
37310 <ul>
37311 <?php if ( ! empty($api->version) ) : ?>
37312 <li><strong><?php _e('Version:') ?></strong> <?php echo $api->version ?></li>
37313 <?php endif; if ( ! empty($api->author) ) : ?>
37314 <li><strong><?php _e('Author:') ?></strong> <?php echo links_add_target($api->author, '_blank') ?></li>
37315 <?php endif; if ( ! empty($api->last_updated) ) : ?>
37316 <li><strong><?php _e('Last Updated:') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
37317 printf( __('%s ago'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
37318 <?php endif; if ( ! empty($api->requires) ) : ?>
37319 <li><strong><?php _e('Requires WordPress Version:') ?></strong> <?php printf(__('%s or higher'), $api->requires) ?></li>
37320 <?php endif; if ( ! empty($api->tested) ) : ?>
37321 <li><strong><?php _e('Compatible up to:') ?></strong> <?php echo $api->tested ?></li>
37322 <?php endif; if ( ! empty($api->downloaded) ) : ?>
37323 <li><strong><?php _e('Downloaded:') ?></strong> <?php printf(__ngettext('%s time', '%s times', $api->downloaded), number_format_i18n($api->downloaded)) ?></li>
37324 <?php endif; if ( ! empty($api->slug) ) : ?>
37325 <li><a target="_blank" href="http://wordpress.org/extend/plugins/<?php echo $api->slug ?>/"><?php _e('WordPress.org Plugin Page »') ?></a></li>
37326 <?php endif; if ( ! empty($api->homepage) ) : ?>
37327 <li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage »') ?></a></li>
37328 <?php endif; ?>
37329 </ul>
37330 <h2><?php _e('Average Rating') ?></h2>
37331 <div class="star-holder" title="<?php printf(__ngettext('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?>">
37332 <div class="star star-rating" style="width: <?php echo attribute_escape($api->rating) ?>px"></div>
37333 <div class="star star5"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('5 stars') ?>" /></div>
37334 <div class="star star4"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('4 stars') ?>" /></div>
37335 <div class="star star3"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('3 stars') ?>" /></div>
37336 <div class="star star2"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('2 stars') ?>" /></div>
37337 <div class="star star1"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('1 star') ?>" /></div>
37338 </div>
37339 <small><?php printf(__ngettext('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?></small>
37340 </div>
37341 <div id="section-holder" class="wrap">
37342 <?php
37343 if ( version_compare($GLOBALS['wp_version'], $api->tested, '>') )
37344 echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
37345 else if ( version_compare($GLOBALS['wp_version'], $api->requires, '<') )
37346 echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has not been marked as <strong>compatible</strong> with your version of WordPress.') . '</p></div>';
37347 foreach ( (array)$api->sections as $section_name => $content ) {
37348 $title = $section_name;
37349 $title[0] = strtoupper($title[0]);
37350 $title = str_replace('_', ' ', $title);
37351
37352 $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/');
37353 $content = links_add_target($content, '_blank');
37354
37355 $san_title = attribute_escape(sanitize_title_with_dashes($title));
37356
37357 $display = ( $section_name == $section ) ? 'block' : 'none';
37358
37359 echo "\t<div id='section-{$san_title}' class='section' style='display: {$display};'>\n";
37360 echo "\t\t<h2 class='long-header'>$title</h2>";
37361 echo $content;
37362 echo "\t</div>\n";
37363 }
37364 echo "</div>\n";
37365
37366 iframe_footer();
37367 exit;
37368 }
37369
37370
37371 add_action('install_plugins_upload', 'upload_plugin');
37372 function upload_plugin() {
37373
37374 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
37375 wp_die($uploads['error']);
37376
37377 if ( !empty($_FILES) )
37378 $filename = $_FILES['pluginzip']['name'];
37379 else if ( isset($_GET['package']) )
37380 $filename = $_GET['package'];
37381
37382 check_admin_referer('plugin-upload');
37383
37384 echo '<div class="wrap">';
37385 echo '<h2>', sprintf( __('Installing Plugin from file: %s'), basename($filename) ), '</h2>';
37386
37387 //Handle a newly uploaded file, Else assume it was
37388 if ( !empty($_FILES) ) {
37389 $filename = wp_unique_filename( $uploads['basedir'], $filename );
37390 $local_file = $uploads['basedir'] . '/' . $filename;
37391
37392 // Move the file to the uploads dir
37393 if ( false === @ move_uploaded_file( $_FILES['pluginzip']['tmp_name'], $local_file) )
37394 wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));
37395 } else {
37396 $local_file = $uploads['basedir'] . '/' . $filename;
37397 }
37398
37399 do_plugin_install_local_package($local_file, $filename);
37400 echo '</div>';
37401 }
37402
37403 add_action('install_plugins_install', 'install_plugin');
37404
37405 /**
37406 * Display plugin link and execute install.
37407 *
37408 * @since 2.7.0
37409 */
37410 function install_plugin() {
37411
37412 $plugin = isset($_REQUEST['plugin']) ? stripslashes( $_REQUEST['plugin'] ) : '';
37413
37414 check_admin_referer('install-plugin_' . $plugin);
37415 $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
37416
37417 if ( is_wp_error($api) )
37418 wp_die($api);
37419
37420 echo '<div class="wrap">';
37421 echo '<h2>', sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version ), '</h2>';
37422
37423 do_plugin_install($api->download_link, $api);
37424 echo '</div>';
37425
37426 }
37427
37428 /**
37429 * Retrieve plugin and install.
37430 *
37431 * @since 2.7.0
37432 *
37433 * @param string $download_url Download URL.
37434 * @param object $plugin_information Optional. Plugin information
37435 */
37436 function do_plugin_install($download_url, $plugin_information = null) {
37437 global $wp_filesystem;
37438
37439 if ( empty($download_url) ) {
37440 show_message( __('No plugin Specified') );
37441 return;
37442 }
37443
37444 $plugin = isset($_REQUEST['plugin']) ? stripslashes( $_REQUEST['plugin'] ) : '';
37445
37446 $url = 'plugin-install.php?tab=install';
37447 $url = add_query_arg(array('plugin' => $plugin, 'plugin_name' => stripslashes( $_REQUEST['plugin_name'] ), 'download_url' => stripslashes( $_REQUEST['download_url'] ) ), $url);
37448
37449 $url = wp_nonce_url($url, 'install-plugin_' . $plugin);
37450 if ( false === ($credentials = request_filesystem_credentials($url)) )
37451 return;
37452
37453 if ( ! WP_Filesystem($credentials) ) {
37454 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
37455 return;
37456 }
37457
37458 if ( $wp_filesystem->errors->get_error_code() ) {
37459 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
37460 show_message($message);
37461 return;
37462 }
37463
37464 $result = wp_install_plugin( $download_url, 'show_message' );
37465
37466 if ( is_wp_error($result) ) {
37467 show_message($result);
37468 show_message( __('Installation Failed') );
37469 } else {
37470 show_message( sprintf(__('Successfully installed the plugin <strong>%s %s</strong>.'), $plugin_information->name, $plugin_information->version) );
37471 $plugin_file = $result;
37472
37473 $install_actions = apply_filters('install_plugin_complete_actions', array(
37474 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . attribute_escape(__('Activate this plugin')) . '" target="_parent">' . __('Activate Plugin') . '</a>',
37475 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . attribute_escape(__('Goto plugins page')) . '" target="_parent">' . __('Return to Plugins page') . '</a>'
37476 ), $plugin_information, $plugin_file);
37477 if ( ! empty($install_actions) )
37478 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
37479 }
37480 }
37481
37482 /**
37483 * Install a plugin from a local file.
37484 *
37485 * @since 2.7.0
37486 *
37487 * @param string $package Local Plugin zip
37488 * @param string $filename Optional. Original filename
37489 * @param object $plugin_information Optional. Plugin information
37490 */
37491 function do_plugin_install_local_package($package, $filename = '') {
37492 global $wp_filesystem;
37493
37494 if ( empty($package) ) {
37495 show_message( __('No plugin Specified') );
37496 return;
37497 }
37498
37499 if ( empty($filename) )
37500 $filename = basename($package);
37501
37502 $url = 'plugin-install.php?tab=upload';
37503 $url = add_query_arg(array('package' => $filename), $url);
37504
37505 $url = wp_nonce_url($url, 'plugin-upload');
37506 if ( false === ($credentials = request_filesystem_credentials($url)) )
37507 return;
37508
37509 if ( ! WP_Filesystem($credentials) ) {
37510 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
37511 return;
37512 }
37513
37514 if ( $wp_filesystem->errors->get_error_code() ) {
37515 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
37516 show_message($message);
37517 return;
37518 }
37519
37520 $result = wp_install_plugin_local_package( $package, 'show_message' );
37521
37522 if ( is_wp_error($result) ) {
37523 show_message($result);
37524 show_message( __('Installation Failed') );
37525 } else {
37526 show_message( __('Successfully installed the plugin.') );
37527 $plugin_file = $result;
37528
37529 $install_actions = apply_filters('install_plugin_complete_actions', array(
37530 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
37531 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . __('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
37532 ), array(), $plugin_file);
37533 if ( ! empty($install_actions) )
37534 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
37535 }
37536 }
37537
37538 /**
37539 * Install plugin.
37540 *
37541 * @since 2.7.0
37542 *
37543 * @param string $package
37544 * @param string $feedback Optional.
37545 * @return mixed.
37546 */
37547 function wp_install_plugin($package, $feedback = '') {
37548 global $wp_filesystem;
37549
37550 if ( !empty($feedback) )
37551 add_filter('install_feedback', $feedback);
37552
37553 // Is a filesystem accessor setup?
37554 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
37555 WP_Filesystem();
37556
37557 if ( ! is_object($wp_filesystem) )
37558 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
37559
37560 if ( $wp_filesystem->errors->get_error_code() )
37561 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
37562
37563 //Get the base plugin folder
37564 $plugins_dir = $wp_filesystem->wp_plugins_dir();
37565 if ( empty($plugins_dir) )
37566 return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));
37567
37568 //And the same for the Content directory.
37569 $content_dir = $wp_filesystem->wp_content_dir();
37570 if( empty($content_dir) )
37571 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
37572
37573 $plugins_dir = trailingslashit( $plugins_dir );
37574 $content_dir = trailingslashit( $content_dir );
37575
37576 if ( empty($package) )
37577 return new WP_Error('no_package', __('Install package not available.'));
37578
37579 // Download the package
37580 apply_filters('install_feedback', sprintf(__('Downloading plugin package from %s'), $package));
37581 $download_file = download_url($package);
37582
37583 if ( is_wp_error($download_file) )
37584 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());
37585
37586 $working_dir = $content_dir . 'upgrade/' . basename($package, '.zip');
37587
37588 // Clean up working directory
37589 if ( $wp_filesystem->is_dir($working_dir) )
37590 $wp_filesystem->delete($working_dir, true);
37591
37592 apply_filters('install_feedback', __('Unpacking the plugin package'));
37593 // Unzip package to working directory
37594 $result = unzip_file($download_file, $working_dir);
37595
37596 // Once extracted, delete the package
37597 @unlink($download_file);
37598
37599 if ( is_wp_error($result) ) {
37600 $wp_filesystem->delete($working_dir, true);
37601 return $result;
37602 }
37603
37604 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
37605 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
37606
37607 if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) {
37608 $wp_filesystem->delete($working_dir, true);
37609 return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );
37610 }
37611
37612 apply_filters('install_feedback', __('Installing the plugin'));
37613 // Copy new version of plugin into place.
37614 $result = copy_dir($working_dir, $plugins_dir);
37615 if ( is_wp_error($result) ) {
37616 $wp_filesystem->delete($working_dir, true);
37617 return $result;
37618 }
37619
37620 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
37621 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
37622
37623 // Remove working directory
37624 $wp_filesystem->delete($working_dir, true);
37625
37626 if( empty($filelist) )
37627 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
37628
37629 $folder = $filelist[0];
37630 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
37631 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
37632
37633 //Return the plugin files name.
37634 return $folder . '/' . $pluginfiles[0];
37635 }
37636
37637 /**
37638 * Install plugin from local package
37639 *
37640 * @since 2.7.0
37641 *
37642 * @param string $package
37643 * @param string $feedback Optional.
37644 * @return mixed.
37645 */
37646 function wp_install_plugin_local_package($package, $feedback = '') {
37647 global $wp_filesystem;
37648
37649 if ( !empty($feedback) )
37650 add_filter('install_feedback', $feedback);
37651
37652 // Is a filesystem accessor setup?
37653 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
37654 WP_Filesystem();
37655
37656 if ( ! is_object($wp_filesystem) )
37657 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
37658
37659 if ( $wp_filesystem->errors->get_error_code() )
37660 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
37661
37662 //Get the base plugin folder
37663 $plugins_dir = $wp_filesystem->wp_plugins_dir();
37664 if ( empty($plugins_dir) )
37665 return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));
37666
37667 //And the same for the Content directory.
37668 $content_dir = $wp_filesystem->wp_content_dir();
37669 if( empty($content_dir) )
37670 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
37671
37672 $plugins_dir = trailingslashit( $plugins_dir );
37673 $content_dir = trailingslashit( $content_dir );
37674
37675 if ( empty($package) )
37676 return new WP_Error('no_package', __('Install package not available.'));
37677
37678 $working_dir = $content_dir . 'upgrade/' . basename($package, '.zip');
37679
37680 // Clean up working directory
37681 if ( $wp_filesystem->is_dir($working_dir) )
37682 $wp_filesystem->delete($working_dir, true);
37683
37684 apply_filters('install_feedback', __('Unpacking the plugin package'));
37685 // Unzip package to working directory
37686 $result = unzip_file($package, $working_dir);
37687
37688 // Once extracted, delete the package
37689 unlink($package);
37690
37691 if ( is_wp_error($result) ) {
37692 $wp_filesystem->delete($working_dir, true);
37693 return $result;
37694 }
37695
37696 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
37697 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
37698
37699 if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) {
37700 $wp_filesystem->delete($working_dir, true);
37701 return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );
37702 }
37703
37704 apply_filters('install_feedback', __('Installing the plugin'));
37705 // Copy new version of plugin into place.
37706 $result = copy_dir($working_dir, $plugins_dir);
37707 if ( is_wp_error($result) ) {
37708 $wp_filesystem->delete($working_dir, true);
37709 return $result;
37710 }
37711
37712 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
37713 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
37714
37715 // Remove working directory
37716 $wp_filesystem->delete($working_dir, true);
37717
37718 if( empty($filelist) )
37719 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
37720
37721 $folder = $filelist[0];
37722 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
37723 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
37724
37725 //Return the plugin files name.
37726 return $folder . '/' . $pluginfiles[0];
37727 }
37728
37729 ?>