Changeset 8317
- Timestamp:
- 07/11/2008 10:04:03 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/update.php
r8305 r8317 53 53 echo "<span id='wp-version-message'>$msg</span>"; 54 54 } 55 56 function wp_update_plugins() {57 global $wp_version;58 59 if ( !function_exists('fsockopen') )60 return false;61 62 $plugins = get_plugins();63 $active = get_option( 'active_plugins' );64 $current = get_option( 'update_plugins' );65 66 $new_option = '';67 $new_option->last_checked = time();68 69 $plugin_changed = false;70 foreach ( $plugins as $file => $p ) {71 $new_option->checked[ $file ] = $p['Version'];72 73 if ( !isset( $current->checked[ $file ] ) ) {74 $plugin_changed = true;75 continue;76 }77 78 if ( strval($current->checked[ $file ]) !== strval($p['Version']) )79 $plugin_changed = true;80 }81 82 if (83 isset( $current->last_checked ) &&84 43200 > ( time() - $current->last_checked ) &&85 !$plugin_changed86 )87 return false;88 89 $to_send->plugins = $plugins;90 $to_send->active = $active;91 $send = serialize( $to_send );92 93 $request = 'plugins=' . urlencode( $send );94 $http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n";95 $http_request .= "Host: api.wordpress.org\r\n";96 $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";97 $http_request .= "Content-Length: " . strlen($request) . "\r\n";98 $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";99 $http_request .= "\r\n";100 $http_request .= $request;101 102 $response = '';103 if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) && is_resource($fs) ) {104 fwrite($fs, $http_request);105 106 while ( !feof($fs) )107 $response .= fgets($fs, 1160); // One TCP-IP packet108 fclose($fs);109 $response = explode("\r\n\r\n", $response, 2);110 }111 112 $response = unserialize( $response[1] );113 114 if ( $response )115 $new_option->response = $response;116 117 update_option( 'update_plugins', $new_option );118 }119 add_action( 'init', 'wp_update_plugins' );120 55 121 56 function wp_plugin_update_row( $file, $plugin_data ) { -
trunk/wp-includes/update.php
r7237 r8317 11 11 * 12 12 * The WordPress version, PHP version, and Locale is sent. Checks against the WordPress server at 13 * api.wordpress.org server. Will only check if PHP has fsockopen enabled and WordPress isn't installing.13 * api.wordpress.org. Will only check if PHP has fsockopen enabled and WordPress isn't installing. 14 14 * 15 15 * @package WordPress … … 20 20 */ 21 21 function wp_version_check() { 22 if ( !function_exists('fsockopen') || strpos($_SERVER['PHP_SELF'], 'install.php') !== false ||defined('WP_INSTALLING') )22 if ( !function_exists('fsockopen') || defined('WP_INSTALLING') ) 23 23 return; 24 24 … … 70 70 update_option( 'update_core', $new_option ); 71 71 } 72 73 72 add_action( 'init', 'wp_version_check' ); 74 73 74 /** 75 * wp_update_plugins() - Check plugin versions against the latest versions hosted on WordPress.org. 76 * 77 * The WordPress version, PHP version, and Locale is sent along with a list of all plugins installed. 78 * Checks against the WordPress server at api.wordpress.org. 79 * Will only check if PHP has fsockopen enabled and WordPress isn't installing. 80 * 81 * @package WordPress 82 * @since 2.3 83 * @uses $wp_version Used to notidy the WordPress version. 84 * 85 * @return mixed Returns null if update is unsupported. Returns false if check is too soon. 86 */ 87 function wp_update_plugins() { 88 global $wp_version; 89 90 if ( !function_exists('fsockopen') || defined('WP_INSTALLING') ) 91 return false; 92 93 $current = get_option( 'update_plugins' ); 94 95 $time_not_changed = isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ); 96 97 // If running blog-side, bail unless we've not checked in the last 12 hours 98 if ( !function_exists( 'get_plugins' ) ) { 99 if ( $time_not_changed ) 100 return false; 101 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 102 } 103 104 $plugins = get_plugins(); 105 $active = get_option( 'active_plugins' ); 106 107 $new_option = ''; 108 $new_option->last_checked = time(); 109 110 $plugin_changed = false; 111 foreach ( $plugins as $file => $p ) { 112 $new_option->checked[ $file ] = $p['Version']; 113 114 if ( !isset( $current->checked[ $file ] ) ) { 115 $plugin_changed = true; 116 continue; 117 } 118 119 if ( strval($current->checked[ $file ]) !== strval($p['Version']) ) 120 $plugin_changed = true; 121 } 122 123 // Bail if we've checked in the last 12 hours and if nothing has changed 124 if ( $time_not_changed && !$plugin_changed ) 125 return false; 126 127 $to_send->plugins = $plugins; 128 $to_send->active = $active; 129 $send = serialize( $to_send ); 130 131 $request = 'plugins=' . urlencode( $send ); 132 $http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n"; 133 $http_request .= "Host: api.wordpress.org\r\n"; 134 $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n"; 135 $http_request .= "Content-Length: " . strlen($request) . "\r\n"; 136 $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n"; 137 $http_request .= "\r\n"; 138 $http_request .= $request; 139 140 $response = ''; 141 if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) && is_resource($fs) ) { 142 fwrite($fs, $http_request); 143 144 while ( !feof($fs) ) 145 $response .= fgets($fs, 1160); // One TCP-IP packet 146 fclose($fs); 147 $response = explode("\r\n\r\n", $response, 2); 148 } 149 150 $response = unserialize( $response[1] ); 151 152 if ( $response ) 153 $new_option->response = $response; 154 155 update_option( 'update_plugins', $new_option ); 156 } 157 if ( defined( 'WP_ADMIN' ) && WP_ADMIN ) 158 add_action( 'admin_init', 'wp_update_plugins' ); 159 else 160 add_action( 'init', 'wp_update_plugins' ); 161 75 162 ?>
Note: See TracChangeset
for help on using the changeset viewer.