]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/update.php
Wordpress 2.3.3
[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 function wp_version_check() {
6         if ( !function_exists('fsockopen') || strpos($_SERVER['PHP_SELF'], 'install.php') !== false || defined('WP_INSTALLING') )
7                 return;
8
9         global $wp_version;
10         $php_version = phpversion();
11
12         $current = get_option( 'update_core' );
13         $locale = get_locale();
14
15         if (
16                 isset( $current->last_checked ) &&
17                 43200 > ( time() - $current->last_checked ) &&
18                 $current->version_checked == $wp_version
19         )
20                 return false;
21
22         $new_option = '';
23         $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
24         $new_option->version_checked = $wp_version;
25
26         $http_request  = "GET /core/version-check/1.0/?version=$wp_version&php=$php_version&locale=$locale HTTP/1.0\r\n";
27         $http_request .= "Host: api.wordpress.org\r\n";
28         $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n";
29         $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
30         $http_request .= "\r\n";
31
32         $response = '';
33         if ( false !== ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3 ) ) && is_resource($fs) ) {
34                 fwrite( $fs, $http_request );
35                 while ( !feof( $fs ) )
36                         $response .= fgets( $fs, 1160 ); // One TCP-IP packet
37                 fclose( $fs );
38
39                 $response = explode("\r\n\r\n", $response, 2);
40                 $body = trim( $response[1] );
41                 $body = str_replace(array("\r\n", "\r"), "\n", $body);
42
43                 $returns = explode("\n", $body);
44
45                 $new_option->response = $returns[0];
46                 if ( isset( $returns[1] ) )
47                         $new_option->url = $returns[1];
48         }
49         update_option( 'update_core', $new_option );
50 }
51
52 add_action( 'init', 'wp_version_check' );
53
54 ?>