HTTP API improvements. Implements chunked transfer decoding. Moves plugin update checker over to api. see #4779 props santosj.
git-svn-id: http://svn.automattic.com/wordpress/trunk@8630 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* A simple set of functions to check our version 1.0 update service
|
||||
* A simple set of functions to check our version 1.0 update service.
|
||||
*
|
||||
* @package WordPress
|
||||
* @since 2.3
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check WordPress version against the newest version. *
|
||||
* Check WordPress version against the newest version.
|
||||
*
|
||||
* The WordPress version, PHP version, and Locale is sent. Checks against the
|
||||
* WordPress server at api.wordpress.org server. Will only check if WordPress
|
||||
* isn't installing.
|
||||
|
||||
*
|
||||
* @package WordPress
|
||||
* @since 2.3
|
||||
@@ -41,20 +41,22 @@ function wp_version_check() {
|
||||
$new_option->version_checked = $wp_version;
|
||||
|
||||
$url = "http://api.wordpress.org/core/version-check/1.2/?version=$wp_version&php=$php_version&locale=$locale";
|
||||
$options = array('timeout' => 3);
|
||||
|
||||
$headers = array(
|
||||
$options = array('timeout' => 3);
|
||||
$options['headers'] = array(
|
||||
'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'),
|
||||
'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
|
||||
);
|
||||
|
||||
$response = wp_remote_request($url, $options, $headers);
|
||||
$response = wp_remote_request($url, $options);
|
||||
|
||||
if ( is_wp_error( $response ) )
|
||||
return false;
|
||||
|
||||
if ( 200 != $response['response']['code'] )
|
||||
return false;
|
||||
|
||||
$body = $response['body'];
|
||||
$body = trim( $body );
|
||||
$body = trim( $response['body'] );
|
||||
$body = str_replace(array("\r\n", "\r"), "\n", $body);
|
||||
$returns = explode("\n", $body);
|
||||
|
||||
@@ -73,11 +75,12 @@ function wp_version_check() {
|
||||
add_action( 'init', 'wp_version_check' );
|
||||
|
||||
/**
|
||||
* wp_update_plugins() - Check plugin versions against the latest versions hosted on WordPress.org.
|
||||
* Check plugin versions against the latest versions hosted on WordPress.org.
|
||||
*
|
||||
* The WordPress version, PHP version, and Locale is sent along with a list of all plugins installed.
|
||||
* Checks against the WordPress server at api.wordpress.org.
|
||||
* Will only check if PHP has fsockopen enabled and WordPress isn't installing.
|
||||
* The WordPress version, PHP version, and Locale is sent along with a list of
|
||||
* all plugins installed. Checks against the WordPress server at
|
||||
* api.wordpress.org. Will only check if PHP has fsockopen enabled and WordPress
|
||||
* isn't installing.
|
||||
*
|
||||
* @package WordPress
|
||||
* @since 2.3
|
||||
@@ -88,7 +91,7 @@ add_action( 'init', 'wp_version_check' );
|
||||
function wp_update_plugins() {
|
||||
global $wp_version;
|
||||
|
||||
if ( !function_exists('fsockopen') || defined('WP_INSTALLING') )
|
||||
if ( defined('WP_INSTALLING') )
|
||||
return false;
|
||||
|
||||
// If running blog-side, bail unless we've not checked in the last 12 hours
|
||||
@@ -116,9 +119,11 @@ function wp_update_plugins() {
|
||||
$plugin_changed = true;
|
||||
}
|
||||
|
||||
foreach ( (array) $current->response as $plugin_file => $update_details ) {
|
||||
if ( ! isset($plugins[ $plugin_file ]) ) {
|
||||
$plugin_changed = true;
|
||||
if ( isset ( $current->response ) && is_array( $current->response ) ) {
|
||||
foreach ( $current->response as $plugin_file => $update_details ) {
|
||||
if ( ! isset($plugins[ $plugin_file ]) ) {
|
||||
$plugin_changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,27 +134,22 @@ function wp_update_plugins() {
|
||||
$to_send->plugins = $plugins;
|
||||
$to_send->active = $active;
|
||||
$send = serialize( $to_send );
|
||||
$body = 'plugins=' . urlencode( $send );
|
||||
|
||||
$request = 'plugins=' . urlencode( $send );
|
||||
$http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n";
|
||||
$http_request .= "Host: api.wordpress.org\r\n";
|
||||
$http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
|
||||
$http_request .= "Content-Length: " . strlen($request) . "\r\n";
|
||||
$http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
|
||||
$http_request .= "\r\n";
|
||||
$http_request .= $request;
|
||||
$options = array('method' => 'POST', 'timeout' => 3, 'body' => $body);
|
||||
$options['headers'] = array(
|
||||
'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'),
|
||||
'Content-Length' => strlen($body),
|
||||
'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
|
||||
);
|
||||
|
||||
$response = '';
|
||||
if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) && is_resource($fs) ) {
|
||||
fwrite($fs, $http_request);
|
||||
$raw_response = wp_remote_request('http://api.wordpress.org/plugins/update-check/1.0/', $options);
|
||||
|
||||
while ( !feof($fs) )
|
||||
$response .= fgets($fs, 1160); // One TCP-IP packet
|
||||
fclose($fs);
|
||||
$response = explode("\r\n\r\n", $response, 2);
|
||||
if( 200 != $raw_response['response']['code'] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = unserialize( $response[1] );
|
||||
$response = unserialize( $raw_response['body'] );
|
||||
|
||||
if ( $response )
|
||||
$new_option->response = $response;
|
||||
|
||||
Reference in New Issue
Block a user