HTTP POST and REQUEST API from jacobsantos. see #4779

git-svn-id: https://develop.svn.wordpress.org/trunk@8516 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-08-01 05:00:07 +00:00
parent cf2daaf071
commit 086b9294b9
4 changed files with 927 additions and 48 deletions

View File

@@ -7,10 +7,11 @@
*/
/**
* wp_version_check() - 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. Will only check if PHP has fsockopen enabled and WordPress isn't installing.
* 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
@@ -19,7 +20,7 @@
* @return mixed Returns null if update is unsupported. Returns false if check is too soon.
*/
function wp_version_check() {
if ( !function_exists('fsockopen') || defined('WP_INSTALLING') )
if ( defined('WP_INSTALLING') )
return;
global $wp_version;
@@ -39,34 +40,32 @@ function wp_version_check() {
$new_option->last_checked = time(); // this gets set whether we get a response or not, so if something is down or misconfigured it won't delay the page load for more than 3 seconds, twice a day
$new_option->version_checked = $wp_version;
$http_request = "GET /core/version-check/1.1/?version=$wp_version&php=$php_version&locale=$locale 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 .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
$http_request .= "\r\n";
$url = "http://api.wordpress.org/core/version-check/1.1/?version=$wp_version&php=$php_version&locale=$locale";
$options = array('timeout' => 3);
$response = '';
if ( false !== ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3 ) ) && is_resource($fs) ) {
fwrite( $fs, $http_request );
while ( !feof( $fs ) )
$response .= fgets( $fs, 1160 ); // One TCP-IP packet
fclose( $fs );
$headers = array(
'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'),
'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
);
$response = explode("\r\n\r\n", $response, 2);
if ( !preg_match( '|HTTP/.*? 200|', $response[0] ) )
return false;
$response = wp_remote_request($url, $options, $headers);
$body = trim( $response[1] );
$body = str_replace(array("\r\n", "\r"), "\n", $body);
if( 200 != $response['response']['code'] )
return false;
$returns = explode("\n", $body);
$body = $response['body'];
$body = trim( $response[1] );
$body = str_replace(array("\r\n", "\r"), "\n", $body);
$returns = explode("\n", $body);
$new_option->response = attribute_escape( $returns[0] );
if ( isset( $returns[1] ) )
$new_option->url = clean_url( $returns[1] );
if ( isset( $returns[2] ) )
$new_option->current = attribute_escape( $returns[2] );
$new_option->response = attribute_escape( $returns[0] );
if ( isset( $returns[1] ) )
$new_option->url = clean_url( $returns[1] );
if ( isset( $returns[2] ) )
$new_option->current = attribute_escape( $returns[2] );
}
update_option( 'update_core', $new_option );
}
add_action( 'init', 'wp_version_check' );