]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/update.php
Wordpress 2.5.1
[autoinstalls/wordpress.git] / wp-includes / update.php
1 <?php
2 /**
3  * A simple set of functions to check our version 1.0 update service
4  *
5  * @package WordPress
6  * @since 2.3
7  */
8
9 /**
10  * wp_version_check() - Check WordPress version against the newest version.
11  *
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.
14  *
15  * @package WordPress
16  * @since 2.3
17  * @uses $wp_version Used to check against the newest WordPress version.
18  *
19  * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
20  */
21 function wp_version_check() {
22         if ( !function_exists('fsockopen') || strpos($_SERVER['PHP_SELF'], 'install.php') !== false || defined('WP_INSTALLING') )
23                 return;
24
25         global $wp_version;
26         $php_version = phpversion();
27
28         $current = get_option( 'update_core' );
29         $locale = get_locale();
30
31         if (
32                 isset( $current->last_checked ) &&
33                 43200 > ( time() - $current->last_checked ) &&
34                 $current->version_checked == $wp_version
35         )
36                 return false;
37
38         $new_option = '';
39         $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
40         $new_option->version_checked = $wp_version;
41
42         $http_request  = "GET /core/version-check/1.1/?version=$wp_version&php=$php_version&locale=$locale HTTP/1.0\r\n";
43         $http_request .= "Host: api.wordpress.org\r\n";
44         $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n";
45         $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
46         $http_request .= "\r\n";
47
48         $response = '';
49         if ( false !== ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3 ) ) && is_resource($fs) ) {
50                 fwrite( $fs, $http_request );
51                 while ( !feof( $fs ) )
52                         $response .= fgets( $fs, 1160 ); // One TCP-IP packet
53                 fclose( $fs );
54
55                 $response = explode("\r\n\r\n", $response, 2);
56                 if ( !preg_match( '|HTTP/.*? 200|', $response[0] ) )
57                         return false;
58
59                 $body = trim( $response[1] );
60                 $body = str_replace(array("\r\n", "\r"), "\n", $body);
61
62                 $returns = explode("\n", $body);
63
64                 $new_option->response = attribute_escape( $returns[0] );
65                 if ( isset( $returns[1] ) )
66                         $new_option->url = clean_url( $returns[1] );
67                 if ( isset( $returns[2] ) )
68                         $new_option->current = attribute_escape( $returns[2] );
69         }
70         update_option( 'update_core', $new_option );
71 }
72
73 add_action( 'init', 'wp_version_check' );
74
75 ?>