| | 40 | function wp_update_plugins() { |
|---|
| | 41 | global $wp_version; |
|---|
| | 42 | $plugins = get_plugins(); |
|---|
| | 43 | $active = get_option( 'active_plugins' ); |
|---|
| | 44 | $current = get_option( 'update_plugins' ); |
|---|
| | 45 | |
|---|
| | 46 | $new_option = ''; |
|---|
| | 47 | $new_option->last_checked = time(); |
|---|
| | 48 | |
|---|
| | 49 | $plugin_changed = false; |
|---|
| | 50 | foreach ( $plugins as $file => $p ) { |
|---|
| | 51 | $new_option->checked[ $file ] = $p['Version']; |
|---|
| | 52 | |
|---|
| | 53 | if ( !isset( $current->checked[ $file ] ) ) { |
|---|
| | 54 | $plugin_changed = true; |
|---|
| | 55 | continue; |
|---|
| | 56 | } |
|---|
| | 57 | |
|---|
| | 58 | if ( $current->checked[ $file ] != $p['Version'] ) |
|---|
| | 59 | $plugin_changed = true; |
|---|
| | 60 | } |
|---|
| | 61 | |
|---|
| | 62 | if ( |
|---|
| | 63 | isset( $current->last_checked ) && |
|---|
| | 64 | 43200 > ( time() - $current->last_checked ) && |
|---|
| | 65 | !$plugin_changed |
|---|
| | 66 | ) |
|---|
| | 67 | return false; |
|---|
| | 68 | |
|---|
| | 69 | $to_send->plugins = $plugins; |
|---|
| | 70 | $to_send->active = $active; |
|---|
| | 71 | $send = serialize( $to_send ); |
|---|
| | 72 | |
|---|
| | 73 | $request = 'plugins=' . urlencode( $send ); |
|---|
| | 74 | $http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n"; |
|---|
| | 75 | $http_request .= "Host: api.wordpress.org\r\n"; |
|---|
| | 76 | $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n"; |
|---|
| | 77 | $http_request .= "Content-Length: " . strlen($request) . "\r\n"; |
|---|
| | 78 | $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n"; |
|---|
| | 79 | $http_request .= "\r\n"; |
|---|
| | 80 | $http_request .= $request; |
|---|
| | 81 | |
|---|
| | 82 | $response = ''; |
|---|
| | 83 | if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) ) { |
|---|
| | 84 | fwrite($fs, $http_request); |
|---|
| | 85 | |
|---|
| | 86 | while ( !feof($fs) ) |
|---|
| | 87 | $response .= fgets($fs, 1160); // One TCP-IP packet |
|---|
| | 88 | fclose($fs); |
|---|
| | 89 | $response = explode("\r\n\r\n", $response, 2); |
|---|
| | 90 | } |
|---|
| | 91 | |
|---|
| | 92 | $response = unserialize( $response[1] ); |
|---|
| | 93 | |
|---|
| | 94 | if ( $response ) |
|---|
| | 95 | $new_option->response = $response; |
|---|
| | 96 | |
|---|
| | 97 | update_option( 'update_plugins', $new_option ); |
|---|
| | 98 | } |
|---|
| | 99 | add_action( 'load-plugins.php', 'wp_update_plugins' ); |
|---|
| | 100 | |
|---|
| | 101 | function wp_plugin_update_row( $file ) { |
|---|
| | 102 | global $plugin_data; |
|---|
| | 103 | $current = get_option( 'update_plugins' ); |
|---|
| | 104 | if ( !isset( $current->response[ $file ] ) ) |
|---|
| | 105 | return false; |
|---|
| | 106 | |
|---|
| | 107 | $r = $current->response[ $file ]; |
|---|
| | 108 | |
|---|
| | 109 | echo "<tr><td colspan='5' class='plugin-update'>"; |
|---|
| | 110 | printf( __('There is a new version of %s available. <a href="%s">Download version %s here</a>.'), $plugin_data['Name'], $r->url, $r->new_version ); |
|---|
| | 111 | echo "</td></tr>"; |
|---|
| | 112 | } |
|---|
| | 113 | add_action( 'after_plugin_row', 'wp_plugin_update_row' ); |
|---|
| | 114 | |
|---|