Ticket #6015: 6015.diff
File 6015.diff, 19.4 KB (added by , 17 years ago) |
---|
-
wp-admin/admin-ajax.php
534 534 $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0; 535 535 die(get_sample_permalink_html($post_id, $_POST['new_slug'])); 536 536 break; 537 case 'plugin-install': 538 require_once( ABSPATH . WPINC . '/rss.php' ); 539 require_once( ABSPATH . '/wp-admin/includes/plugin-install.php' ); 540 installplugin_display(); 541 break; 537 542 default : 538 543 do_action( 'wp_ajax_' . $_POST['action'] ); 539 544 die('0'); -
wp-admin/includes/plugin-install.php
1 <?php 2 3 add_action('installplugin_sources','get_installplugin_sources'); 4 function get_installplugin_sources($sources){ 5 $sources['featured'] = array( 'title' => __('Featured Plugins'), 'callback' => 'installplugin_featured'); 6 $sources['popular'] = array( 'title' => __('Popular Plugins'), 'callback' => 'installplugin_popular'); 7 $sources['updated'] = array( 'title' => __('Recently Updated'), 'callback' => 'installplugin_updated'); 8 $sources['newest'] = array( 'title' => __('Newest Plugins'), 'callback'=> 'installplugin_newest'); 9 $sources['custom'] = array( 'title' => __('Custom Search'), 'callback' => 'installplugin_custom'); 10 return $sources; 11 } 12 13 function installplugin_display(){ 14 $show_values = apply_filters('installplugin_sources', array()); 15 16 $show_selected = isset($_REQUEST['show']) ? $_REQUEST['show'] : false; 17 if( ! isset($show_values[$show_selected]) ) 18 $show_selected = 'featured'; 19 20 $plugins = @call_user_func($show_values[ $show_selected ]['callback']); 21 22 if ( ! is_array($plugins) ) 23 return; 24 25 if( empty($plugins) ){ 26 echo '<h3>' . __('No Plugins Found') . '</h3>'; 27 } else { 28 foreach($plugins as $plugin){ 29 extract($plugin); 30 $ilink = 'update.php?action=install-plugin&plugin=' . urlencode($latestzip); 31 $ilink = wp_nonce_url($ilink, 'install-plugin_' . $latestzip); 32 echo "<h3>$title</h3>\n"; 33 echo "<p><span><a href='$link' target='_blank'>" . __('Visit Homepage') . 34 "</a> | <a href='$dlink' target='_blank'>" . __('Download Page') . 35 "</a> | <a href='$ilink'>" . __('Install Now') . "</a></span></p>"; 36 echo "<p>$description</p>\n"; 37 } 38 } 39 } 40 41 function installplugin_featured(){ 42 return array(); //TODO: Need a API for wordpress.org for this :) 43 } 44 function installplugin_popular(){ 45 return installplugin_wporg('http://wordpress.org/extend/plugins/rss/browse/popular/'); 46 } 47 function installplugin_newest(){ 48 return installplugin_wporg('http://wordpress.org/extend/plugins/rss/browse/new/'); 49 } 50 function installplugin_updated(){ 51 return installplugin_wporg('http://wordpress.org/extend/plugins/rss/browse/updated/'); 52 } 53 function installplugin_custom(){ 54 //REQUEST used as GET = Web interface, POST = Ajax 55 if( isset($_REQUEST['term']) && ! empty($_REQUEST['term']) ){ 56 $term = urldecode($_REQUEST['term']); 57 echo '<p>' . sprintf(__('Displaying a selection from the %s category'), $term) . '</p>'; 58 return installplugin_wporg('http://wordpress.org/extend/plugins/rss/tags/' . $term); 59 } 60 61 $tags = installplugin_custom_tags(); 62 63 echo "<p>" . __('Please select a Category to view plugins from.') . "</p>"; 64 65 echo "<div id='tag-list'>"; 66 67 foreach($tags as $tag){ 68 $num = sprintf(__('%s plugins'), $tag['num']); 69 echo "<a href='plugin-install.php?show=custom&term={$tag['tag']}' onclick='return showSelection(\"custom\", \"{$tag['tag']}\")' title='$num' rel='tag' style='font-size: {$tag['size']}pt;'>{$tag['tag']}</a> "; 70 } 71 72 echo "</div>"; 73 } 74 function installplugin_custom_tags(){ 75 //TODO: Needs Caching 76 //TODO: Needs a API on Wordpress.org :) 77 $url = 'http://wordpress.org/extend/plugins/tags/'; 78 $html = file_get_contents($url); //TODO: Replace. 79 $html = substr( $html, strpos($html,'<div id="hottags">')); 80 81 preg_match_all("|<a href='.*/([a-zA-Z0-9]+)' title='(\d+) topics' rel='tag' style='font-size: ([\d\.]+)pt;'>.*</a>|i", $html, $mat); 82 83 $tags = array(); 84 85 for($i = 0; $i < count($mat[1]); $i++) 86 $tags[] = array('tag' => $mat[1][$i], 'num' => $mat[2][$i], 'size' => $mat[3][$i]); 87 88 return $tags; 89 } 90 91 function installplugin_wporg($feedurl){ 92 $plugins = array(); 93 $items = @fetch_rss( $feedurl ); 94 if( ! $items || empty($items->items) ) 95 return $plugins; 96 97 foreach($items->items as $item){ 98 // current bbPress feed item titles are: user on "topic title" 99 if ( preg_match( '/"(.*)"/s', $item['title'], $matches ) ) 100 $title = $matches[1]; 101 else // but let's make it forward compatible if things change 102 $title = $item['title']; 103 $title = wp_specialchars( $title ); 104 105 $description = wp_specialchars( strip_tags(html_entity_decode($item['description'], ENT_QUOTES)) ); 106 107 list($link, $frag) = explode( '#', $item['link'] ); 108 109 $link = clean_url($link); 110 $link = rtrim($link, '/'); 111 $dlink = $link . '/download/'; 112 113 if( preg_match("|\/([a-zA-Z\-0-9]+)$|", $link, $slug) ) 114 $slug = $slug[1]; 115 else 116 $slug = ''; 117 118 $latestzip = 'http://downloads.wordpress.org/plugin/' . $slug . '.zip'; 119 120 $plugins[] = array('title' => $title, 'link' => $link, 'dlink' => $dlink, 'description' => $description, 'slug' => $slug, 'latestzip' => $latestzip); 121 } 122 return $plugins; 123 } 124 ?> 125 No newline at end of file -
wp-admin/includes/update.php
192 192 delete_option('update_plugins'); 193 193 } 194 194 195 function wp_install_plugin($package, $feedback = '') { 196 global $wp_filesystem; 197 198 if ( !empty($feedback) ) 199 add_filter('update_feedback', $feedback); 200 201 if ( empty($package) ) 202 return new WP_Error('empty_url', __('Invalid URL given')); 203 204 // Is a filesystem accessor setup? 205 if ( ! $wp_filesystem || !is_object($wp_filesystem) ) 206 WP_Filesystem(); 207 208 if ( ! is_object($wp_filesystem) ) 209 return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 210 211 if ( $wp_filesystem->errors->get_error_code() ) 212 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); 213 214 // Download the package 215 apply_filters('update_feedback', __("Downloading installer from $package")); 216 $file = download_url($package); 217 218 if ( !$file ) 219 return new WP_Error('download_failed', __('Download failed.')); 220 221 $name = basename($package, '.zip'); 222 $working_dir = ABSPATH . 'wp-content/upgrade/' . $name; 223 224 // Clean up working directory 225 $wp_filesystem->delete($working_dir, true); 226 227 apply_filters('update_feedback', __("Unpacking the files")); 228 // Unzip package to working directory 229 $result = unzip_file($file, $working_dir); 230 if ( is_wp_error($result) ) { 231 unlink($file); 232 $wp_filesystem->delete($working_dir, true); 233 return $result; 234 } 235 236 // Once installed, delete the package 237 unlink($file); 238 239 240 //TODO: Check if the plugin is allready installed. 241 // Remove the existing plugin. 242 //apply_filters('update_feedback', __("Removing the old version of the plugin")); 243 //$wp_filesystem->delete(ABSPATH . PLUGINDIR . "/$plugin"); 244 //$plugin_dir = dirname(ABSPATH . PLUGINDIR . "/$plugin"); 245 246 // If plugin is in its own directory, recursively delete the directory. 247 //if ( '.' != $plugin_dir && ABSPATH . PLUGINDIR != $plugin_dir ) 248 // $wp_filesystem->delete($plugin_dir, true); 249 250 apply_filters('update_feedback', __("Installing the files")); 251 // Copy new version of plugin into place. 252 copy_dir($working_dir, ABSPATH . PLUGINDIR); 253 254 // Remove working directory 255 $wp_filesystem->delete($working_dir, true); 256 257 // Force refresh of plugin update information 258 //delete_option('update_plugins'); 259 } 260 195 261 ?> -
wp-admin/plugin-install.php
1 <?php 2 require_once('admin.php'); 3 require_once('includes/plugin-install.php'); 4 5 $title = __('Get More Plugins'); 6 $parent_file = 'plugins.php'; 7 8 //wp_reset_vars(array('show')); //Does it do both POST and GET? 9 10 add_action('admin_head','installplugin_head'); 11 function installplugin_head(){ ?> 12 <style> 13 .plugin-install-search-types{ 14 background-color:#eaf3fa; 15 width: 200px; 16 border:inset thin #000; 17 float: left; 18 clear: left; 19 } 20 .plugin-install-plugins{ 21 background-color:#eaf3fa; 22 border:inset thin #000; 23 margin-left: 210px; 24 } 25 .plugin-install-search-types ul{ 26 list-style: none; 27 } 28 .plugin-install-search-types li{ 29 margin-left: -30px; 30 margin-right: 10px; 31 font-size: 1.2em; 32 padding:0; 33 } 34 .plugin-install-search-types li:hover{ 35 background-color: #e1e4f1; 36 } 37 .plugin-install-search-types li.selected{ 38 background-color: #fff; 39 } 40 .plugin-install-search-types a { 41 display:block; 42 padding:3px; 43 margin: 0; 44 } 45 </style> 46 <script type="text/javascript"> 47 function showSelection(selection, selectedterm){ 48 if( selectedterm == undefined) 49 var selectedterm = ''; 50 51 jQuery('.plugin-install-search-types ul li').removeClass('selected'); 52 jQuery('#plugin-install-search-' + selection).addClass('selected'); 53 54 jQuery('.plugin-install-plugins').html('<p><strong><?php _e('Loading Plugin list..') ?></strong></p>'); 55 jQuery.post("admin-ajax.php", 56 { action: "plugin-install", show: selection, term: selectedterm }, 57 function(data){ 58 jQuery('.plugin-install-plugins').html(data); 59 } 60 ); 61 62 return false; 63 } 64 </script> 65 <?php 66 }//End head items. 67 68 require_once('admin-header.php'); 69 ?> 70 <div class="wrap"> 71 <h2><?php _e('Get more Plugins'); ?></h2> 72 <p><?php _e('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, You may activate on the Plugins tab.'); ?></p> 73 </div> 74 75 <div class="wrap"> 76 <div class='plugin-install-search-types'> 77 <ul> 78 <?php 79 $show_values = apply_filters('installplugin_sources', array()); 80 $show_selected = isset($_REQUEST['show']) ? $_REQUEST['show'] : false; 81 if( ! isset($show_values[$show_selected]) ) 82 $show_selected = 'featured'; 83 84 foreach ( $show_values as $show_value => $info ){ 85 $show_value = attribute_escape( $show_value ); 86 $show_text = wp_specialchars( $info['title'] ); 87 $class = ($show_value == $show_selected) ? ' class="selected"' : ''; 88 echo "<li id='plugin-install-search-{$show_value}'$class><a href='plugin-browse.php?show=$show_value' onclick='return showSelection(\"$show_value\")'>$show_text</a></li>"; 89 } 90 ?> 91 </ul> 92 </div> 93 <div class='plugin-install-plugins'> 94 <?php 95 installplugin_display(); 96 ?> 97 </div> 98 </div> 99 <?php include('admin-footer.php') ?> 100 No newline at end of file -
wp-admin/update.php
1 <?php 2 3 require_once('admin.php'); 4 5 if ( !current_user_can('edit_plugins') ) 6 wp_die('<p>'.__('You do not have sufficient permissions to update plugins for this blog.').'</p>'); 7 8 function request_filesystem_credentials($form_post, $type = '') { 9 if ( empty($type) ) 10 $type = get_filesystem_method(); 11 12 if ( 'direct' == $type ) 13 return array(); 14 15 if ( !empty($_POST['password']) && !empty($_POST['username']) && !empty($_POST['hostname']) ) { 16 $credentials = array('hostname' => $_POST['hostname'], 'username' => $_POST['username'], 17 'password' => $_POST['password'], 'ssl' => $_POST['ssl']); 18 $stored_credentials = $credentials; 19 unset($stored_credentials['password']); 20 update_option('ftp_credentials', $stored_credentials); 21 return $credentials; 22 } 23 $hostname = ''; 24 $username = ''; 25 $password = ''; 26 $ssl = ''; 27 if ( $credentials = get_option('ftp_credentials') ) 28 extract($credentials, EXTR_OVERWRITE); 29 ?> 30 <form action="<?php echo $form_post ?>" method="post"> 31 <div class="wrap"> 32 <h2><?php _e('FTP Connection Information') ?></h2> 33 <p><?php _e('To perform the requested update, FTP connection information is required.') ?></p> 34 <table class="form-table"> 35 <tr valign="top"> 36 <th scope="row"><?php _e('Hostname:') ?></th> 37 <td><input name="hostname" type="text" id="hostname" value="<?php echo attribute_escape($hostname) ?>" size="40" /></td> 38 </tr> 39 <tr valign="top"> 40 <th scope="row"><?php _e('Username:') ?></th> 41 <td><input name="username" type="text" id="username" value="<?php echo attribute_escape($username) ?>" size="40" /></td> 42 </tr> 43 <tr valign="top"> 44 <th scope="row"><?php _e('Password:') ?></th> 45 <td><input name="password" type="text" id="password" value="<?php echo attribute_escape($password) ?>" size="40" /></td> 46 </tr> 47 <tr valign="top"> 48 <th scope="row"><?php _e('Use SSL:') ?></th> 49 <td> 50 <select name="ssl" id="ssl"> 51 <?php 52 foreach ( array(0 => __('No'), 1 => __('Yes')) as $key => $value ) : 53 $selected = ($ssl == $value) ? 'selected="selected"' : ''; 54 echo "\n\t<option value='$key' $selected>" . $value . '</option>'; 55 endforeach; 56 ?> 57 </select> 58 </td> 59 </tr> 60 </table> 61 <p class="submit"> 62 <input type="submit" name="submit" value="<?php _e('Proceed'); ?>" /> 63 </p> 64 </div> 65 </form> 66 <?php 67 return false; 68 } 69 70 function show_message($message) { 71 if ( is_wp_error($message) ) 72 $message = $message->get_error_message(); 73 echo "<p>$message</p>"; 74 } 75 76 function do_plugin_upgrade($plugin) { 77 global $wp_filesystem; 78 79 $credentials = request_filesystem_credentials("update.php?action=upgrade-plugin&plugin=$plugin"); 80 if ( false === $credentials ) 81 return; 82 echo '<div class="wrap">'; 83 echo '<h2>' . __('Upgrade Plugin') . '</h2>'; 84 WP_Filesystem($credentials); 85 // TODO: look for auth and connect error codes and direct back to credentials form. 86 if ( $wp_filesystem->errors->get_error_code() ) { 87 foreach ( $wp_filesystem->errors->get_error_messages() as $message ) 88 show_message($message); 89 echo '</div>'; 90 return; 91 } 92 93 $result = wp_update_plugin($plugin, 'show_message'); 94 95 if ( is_wp_error($result) ) 96 show_message($result); 97 else 98 echo __('Plugin upgraded successfully'); 99 echo '</div>'; 100 } 101 102 if ( isset($_GET['action']) ) { 103 if ( isset($_GET['plugin']) ) 104 $plugin = trim($_GET['plugin']); 105 106 if ( 'upgrade-plugin' == $_GET['action'] ) { 107 //check-admin_referer('upgrade-plugin_' . $plugin); 108 $title = __('Upgrade Plugin'); 109 $parent_file = 'plugins.php'; 110 require_once('admin-header.php'); 111 do_plugin_upgrade($plugin); 112 include('admin-footer.php'); 113 } 114 115 } 116 1 <?php 2 3 require_once('admin.php'); 4 5 if ( !current_user_can('edit_plugins') ) 6 wp_die('<p>'.__('You do not have sufficient permissions to update plugins for this blog.').'</p>'); 7 8 function request_filesystem_credentials($form_post, $type = '') { 9 if ( empty($type) ) 10 $type = get_filesystem_method(); 11 12 if ( 'direct' == $type ) 13 return array(); 14 15 if ( !empty($_POST['password']) && !empty($_POST['username']) && !empty($_POST['hostname']) ) { 16 $credentials = array('hostname' => $_POST['hostname'], 'username' => $_POST['username'], 17 'password' => $_POST['password'], 'ssl' => $_POST['ssl']); 18 $stored_credentials = $credentials; 19 unset($stored_credentials['password']); 20 update_option('ftp_credentials', $stored_credentials); 21 return $credentials; 22 } 23 $hostname = ''; 24 $username = ''; 25 $password = ''; 26 $ssl = ''; 27 if ( $credentials = get_option('ftp_credentials') ) 28 extract($credentials, EXTR_OVERWRITE); 29 ?> 30 <form action="<?php echo $form_post ?>" method="post"> 31 <div class="wrap"> 32 <h2><?php _e('FTP Connection Information') ?></h2> 33 <p><?php _e('To perform the requested update, FTP connection information is required.') ?></p> 34 <table class="form-table"> 35 <tr valign="top"> 36 <th scope="row"><?php _e('Hostname:') ?></th> 37 <td><input name="hostname" type="text" id="hostname" value="<?php echo attribute_escape($hostname) ?>" size="40" /></td> 38 </tr> 39 <tr valign="top"> 40 <th scope="row"><?php _e('Username:') ?></th> 41 <td><input name="username" type="text" id="username" value="<?php echo attribute_escape($username) ?>" size="40" /></td> 42 </tr> 43 <tr valign="top"> 44 <th scope="row"><?php _e('Password:') ?></th> 45 <td><input name="password" type="text" id="password" value="<?php echo attribute_escape($password) ?>" size="40" /></td> 46 </tr> 47 <tr valign="top"> 48 <th scope="row"><?php _e('Use SSL:') ?></th> 49 <td> 50 <select name="ssl" id="ssl"> 51 <?php 52 foreach ( array(0 => __('No'), 1 => __('Yes')) as $key => $value ) : 53 $selected = ($ssl == $value) ? 'selected="selected"' : ''; 54 echo "\n\t<option value='$key' $selected>" . $value . '</option>'; 55 endforeach; 56 ?> 57 </select> 58 </td> 59 </tr> 60 </table> 61 <p class="submit"> 62 <input type="submit" name="submit" value="<?php _e('Proceed'); ?>" /> 63 </p> 64 </div> 65 </form> 66 <?php 67 return false; 68 } 69 70 function show_message($message) { 71 if ( is_wp_error($message) ) 72 $message = $message->get_error_message(); 73 echo "<p>$message</p>"; 74 } 75 76 function do_plugin_upgrade($plugin) { 77 global $wp_filesystem; 78 79 $credentials = request_filesystem_credentials("update.php?action=upgrade-plugin&plugin=$plugin"); 80 if ( false === $credentials ) 81 return; 82 echo '<div class="wrap">'; 83 echo '<h2>' . __('Upgrade Plugin') . '</h2>'; 84 WP_Filesystem($credentials); 85 // TODO: look for auth and connect error codes and direct back to credentials form. 86 if ( $wp_filesystem->errors->get_error_code() ) { 87 foreach ( $wp_filesystem->errors->get_error_messages() as $message ) 88 show_message($message); 89 echo '</div>'; 90 return; 91 } 92 93 $result = wp_update_plugin($plugin, 'show_message'); 94 95 if ( is_wp_error($result) ) 96 show_message($result); 97 else 98 echo __('Plugin upgraded successfully'); 99 echo '</div>'; 100 } 101 102 function do_plugin_install($url) { 103 global $wp_filesystem; 104 105 $credentials = request_filesystem_credentials('plugin-install.php?action=install-plugin&plugin=' . urlencode($url)); 106 if ( false === $credentials ) 107 return; 108 echo '<div class="wrap">'; 109 echo '<h2>' . __('Install Plugin') . '</h2>'; 110 WP_Filesystem($credentials); 111 // TODO: look for auth and connect error codes and direct back to credentials form. 112 if ( $wp_filesystem->errors->get_error_code() ) { 113 foreach ( $wp_filesystem->errors->get_error_messages() as $message ) 114 show_message($message); 115 echo '</div>'; 116 return; 117 } 118 119 $result = wp_install_plugin($url, 'show_message'); 120 121 if ( is_wp_error($result) ) 122 show_message($result); 123 else 124 echo __('Plugin installed successfully'); 125 echo '</div>'; 126 } 127 128 if ( isset($_GET['action']) ) { 129 if ( isset($_GET['plugin']) ) 130 $plugin = trim($_GET['plugin']); 131 132 if ( 'upgrade-plugin' == $_GET['action'] ) { 133 //check-admin_referer('upgrade-plugin_' . $plugin); 134 $title = __('Upgrade Plugin'); 135 $parent_file = 'plugins.php'; 136 require_once('admin-header.php'); 137 do_plugin_upgrade($plugin); 138 include('admin-footer.php'); 139 } elseif ( 'install-plugin' == $_GET['action'] ){ 140 141 $plugin = urldecode($plugin); 142 check_admin_referer('install-plugin_' . $plugin); 143 144 $title = __('Install Plugins'); 145 $parent_file = 'plugins.php'; 146 147 require_once('admin-header.php'); 148 do_plugin_install($plugin); 149 include('admin-footer.php'); 150 } 151 152 } 153 117 154 ?> 155 No newline at end of file