raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * A simple set of functions to check our version 1.0 update service.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @since 2.3.0
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Check WordPress version against the newest version.
mp-wp_genesis 11 *
mp-wp_genesis 12 * The WordPress version, PHP version, and Locale is sent. Checks against the
mp-wp_genesis 13 * WordPress server at polimedia.us/muiewp server. Will only check if WordPress
mp-wp_genesis 14 * isn't installing.
mp-wp_genesis 15 *
mp-wp_genesis 16 * @package WordPress
mp-wp_genesis 17 * @since 2.3.0
mp-wp_genesis 18 * @uses $wp_version Used to check against the newest WordPress version.
mp-wp_genesis 19 *
mp-wp_genesis 20 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
mp-wp_genesis 21 */
mp-wp_genesis 22 function wp_version_check() {
mp-wp_genesis 23 if ( defined('WP_INSTALLING') )
mp-wp_genesis 24 return;
mp-wp_genesis 25
mp-wp_genesis 26 global $wp_version, $wpdb, $wp_local_package;
mp-wp_genesis 27 $php_version = phpversion();
mp-wp_genesis 28
mp-wp_genesis 29 $current = get_option( 'update_core' );
mp-wp_genesis 30 if ( ! is_object($current) )
mp-wp_genesis 31 $current = new stdClass;
mp-wp_genesis 32
mp-wp_genesis 33 $locale = get_locale();
mp-wp_genesis 34 if (
mp-wp_genesis 35 isset( $current->last_checked ) &&
mp-wp_genesis 36 43200 > ( time() - $current->last_checked ) &&
mp-wp_genesis 37 $current->version_checked == $wp_version
mp-wp_genesis 38 )
mp-wp_genesis 39 return false;
mp-wp_genesis 40
mp-wp_genesis 41 // Update last_checked for current to prevent multiple blocking requests if request hangs
mp-wp_genesis 42 $current->last_checked = time();
mp-wp_genesis 43 update_option( 'update_core', $current );
mp-wp_genesis 44
mp-wp_genesis 45 if ( method_exists( $wpdb, 'db_version' ) )
mp-wp_genesis 46 $mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version($wpdb->users));
mp-wp_genesis 47 else
mp-wp_genesis 48 $mysql_version = 'N/A';
mp-wp_genesis 49 $local_package = isset( $wp_local_package )? $wp_local_package : '';
mp-wp_genesis 50 $url = "http://polimedia.us/muiewp/core/version-check/1.3/?version=$wp_version&php=$php_version&locale=$locale&mysql=$mysql_version&local_package=$local_package";
mp-wp_genesis 51
mp-wp_genesis 52 $options = array('timeout' => 3);
mp-wp_genesis 53 $options['headers'] = array(
mp-wp_genesis 54 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'),
mp-wp_genesis 55 'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
mp-wp_genesis 56 );
mp-wp_genesis 57
mp-wp_genesis 58 $response = wp_remote_request($url, $options);
mp-wp_genesis 59
mp-wp_genesis 60 if ( is_wp_error( $response ) )
mp-wp_genesis 61 return false;
mp-wp_genesis 62
mp-wp_genesis 63 if ( 200 != $response['response']['code'] )
mp-wp_genesis 64 return false;
mp-wp_genesis 65
mp-wp_genesis 66 $body = trim( $response['body'] );
mp-wp_genesis 67 $body = str_replace(array("\r\n", "\r"), "\n", $body);
mp-wp_genesis 68 $new_options = array();
mp-wp_genesis 69 foreach( explode( "\n\n", $body ) as $entry) {
mp-wp_genesis 70 $returns = explode("\n", $entry);
mp-wp_genesis 71 $new_option = new stdClass();
mp-wp_genesis 72 $new_option->response = attribute_escape( $returns[0] );
mp-wp_genesis 73 if ( isset( $returns[1] ) )
mp-wp_genesis 74 $new_option->url = clean_url( $returns[1] );
mp-wp_genesis 75 if ( isset( $returns[2] ) )
mp-wp_genesis 76 $new_option->package = clean_url( $returns[2] );
mp-wp_genesis 77 if ( isset( $returns[3] ) )
mp-wp_genesis 78 $new_option->current = attribute_escape( $returns[3] );
mp-wp_genesis 79 if ( isset( $returns[4] ) )
mp-wp_genesis 80 $new_option->locale = attribute_escape( $returns[4] );
mp-wp_genesis 81 $new_options[] = $new_option;
mp-wp_genesis 82 }
mp-wp_genesis 83
mp-wp_genesis 84 $updates = new stdClass();
mp-wp_genesis 85 $updates->updates = $new_options;
mp-wp_genesis 86 $updates->last_checked = time();
mp-wp_genesis 87 $updates->version_checked = $wp_version;
mp-wp_genesis 88 update_option( 'update_core', $updates);
mp-wp_genesis 89 }
mp-wp_genesis 90 add_action( 'init', 'wp_version_check' );
mp-wp_genesis 91
mp-wp_genesis 92 /**
mp-wp_genesis 93 * Check plugin versions against the latest versions hosted on WordPress.org.
mp-wp_genesis 94 *
mp-wp_genesis 95 * The WordPress version, PHP version, and Locale is sent along with a list of
mp-wp_genesis 96 * all plugins installed. Checks against the WordPress server at
mp-wp_genesis 97 * polimedia.us/muiewp. Will only check if WordPress isn't installing.
mp-wp_genesis 98 *
mp-wp_genesis 99 * @package WordPress
mp-wp_genesis 100 * @since 2.3.0
mp-wp_genesis 101 * @uses $wp_version Used to notidy the WordPress version.
mp-wp_genesis 102 *
mp-wp_genesis 103 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
mp-wp_genesis 104 */
mp-wp_genesis 105 function wp_update_plugins() {
mp-wp_genesis 106 global $wp_version;
mp-wp_genesis 107
mp-wp_genesis 108 if ( defined('WP_INSTALLING') )
mp-wp_genesis 109 return false;
mp-wp_genesis 110
mp-wp_genesis 111 // If running blog-side, bail unless we've not checked in the last 12 hours
mp-wp_genesis 112 if ( !function_exists( 'get_plugins' ) )
mp-wp_genesis 113 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
mp-wp_genesis 114
mp-wp_genesis 115 $plugins = get_plugins();
mp-wp_genesis 116 $active = get_option( 'active_plugins' );
mp-wp_genesis 117 $current = get_option( 'update_plugins' );
mp-wp_genesis 118 if ( ! is_object($current) )
mp-wp_genesis 119 $current = new stdClass;
mp-wp_genesis 120
mp-wp_genesis 121 $new_option = '';
mp-wp_genesis 122 $new_option->last_checked = time();
mp-wp_genesis 123 $time_not_changed = isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked );
mp-wp_genesis 124
mp-wp_genesis 125 $plugin_changed = false;
mp-wp_genesis 126 foreach ( $plugins as $file => $p ) {
mp-wp_genesis 127 $new_option->checked[ $file ] = $p['Version'];
mp-wp_genesis 128
mp-wp_genesis 129 if ( !isset( $current->checked[ $file ] ) ) {
mp-wp_genesis 130 $plugin_changed = true;
mp-wp_genesis 131 continue;
mp-wp_genesis 132 }
mp-wp_genesis 133
mp-wp_genesis 134 if ( strval($current->checked[ $file ]) !== strval($p['Version']) )
mp-wp_genesis 135 $plugin_changed = true;
mp-wp_genesis 136 }
mp-wp_genesis 137
mp-wp_genesis 138 if ( isset ( $current->response ) && is_array( $current->response ) ) {
mp-wp_genesis 139 foreach ( $current->response as $plugin_file => $update_details ) {
mp-wp_genesis 140 if ( ! isset($plugins[ $plugin_file ]) ) {
mp-wp_genesis 141 $plugin_changed = true;
mp-wp_genesis 142 }
mp-wp_genesis 143 }
mp-wp_genesis 144 }
mp-wp_genesis 145
mp-wp_genesis 146 // Bail if we've checked in the last 12 hours and if nothing has changed
mp-wp_genesis 147 if ( $time_not_changed && !$plugin_changed )
mp-wp_genesis 148 return false;
mp-wp_genesis 149
mp-wp_genesis 150 // Update last_checked for current to prevent multiple blocking requests if request hangs
mp-wp_genesis 151 $current->last_checked = time();
mp-wp_genesis 152 update_option( 'update_plugins', $current );
mp-wp_genesis 153
mp-wp_genesis 154 $to_send->plugins = $plugins;
mp-wp_genesis 155 $to_send->active = $active;
mp-wp_genesis 156 $send = serialize( $to_send );
mp-wp_genesis 157 $body = 'plugins=' . urlencode( $send );
mp-wp_genesis 158
mp-wp_genesis 159 $options = array('method' => 'POST', 'timeout' => 3, 'body' => $body);
mp-wp_genesis 160 $options['headers'] = array(
mp-wp_genesis 161 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'),
mp-wp_genesis 162 'Content-Length' => strlen($body),
mp-wp_genesis 163 'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
mp-wp_genesis 164 );
mp-wp_genesis 165
mp-wp_genesis 166 $raw_response = wp_remote_request('http://polimedia.us/muiewp/plugins/update-check/1.0/', $options);
mp-wp_genesis 167
mp-wp_genesis 168 if ( is_wp_error( $raw_response ) )
mp-wp_genesis 169 return false;
mp-wp_genesis 170
mp-wp_genesis 171 if( 200 != $raw_response['response']['code'] ) {
mp-wp_genesis 172 return false;
mp-wp_genesis 173 }
mp-wp_genesis 174
mp-wp_genesis 175 $response = unserialize( $raw_response['body'] );
mp-wp_genesis 176
mp-wp_genesis 177 if ( false !== $response )
mp-wp_genesis 178 $new_option->response = $response;
mp-wp_genesis 179 else
mp-wp_genesis 180 $new_option->response = array();
mp-wp_genesis 181
mp-wp_genesis 182 update_option( 'update_plugins', $new_option );
mp-wp_genesis 183 }
mp-wp_genesis 184
mp-wp_genesis 185 /**
mp-wp_genesis 186 * Check theme versions against the latest versions hosted on WordPress.org.
mp-wp_genesis 187 *
mp-wp_genesis 188 * A list of all themes installed in sent to WP. Checks against the
mp-wp_genesis 189 * WordPress server at polimedia.us/muiewp. Will only check if WordPress isn't
mp-wp_genesis 190 * installing.
mp-wp_genesis 191 *
mp-wp_genesis 192 * @package WordPress
mp-wp_genesis 193 * @since 2.7.0
mp-wp_genesis 194 * @uses $wp_version Used to notidy the WordPress version.
mp-wp_genesis 195 *
mp-wp_genesis 196 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
mp-wp_genesis 197 */
mp-wp_genesis 198 function wp_update_themes( ) {
mp-wp_genesis 199 global $wp_version;
mp-wp_genesis 200
mp-wp_genesis 201 if( defined( 'WP_INSTALLING' ) )
mp-wp_genesis 202 return false;
mp-wp_genesis 203
mp-wp_genesis 204 if( !function_exists( 'get_themes' ) )
mp-wp_genesis 205 require_once( ABSPATH . 'wp-includes/theme.php' );
mp-wp_genesis 206
mp-wp_genesis 207 $installed_themes = get_themes( );
mp-wp_genesis 208 $current_theme = get_option( 'update_themes' );
mp-wp_genesis 209 if ( ! is_object($current_theme) )
mp-wp_genesis 210 $current_theme = new stdClass;
mp-wp_genesis 211
mp-wp_genesis 212 $new_option = '';
mp-wp_genesis 213 $new_option->last_checked = time( );
mp-wp_genesis 214 $time_not_changed = isset( $current_theme->last_checked ) && 43200 > ( time( ) - $current_theme->last_checked );
mp-wp_genesis 215
mp-wp_genesis 216 if( $time_not_changed )
mp-wp_genesis 217 return false;
mp-wp_genesis 218
mp-wp_genesis 219 // Update last_checked for current to prevent multiple blocking requests if request hangs
mp-wp_genesis 220 $current_theme->last_checked = time();
mp-wp_genesis 221 update_option( 'update_themes', $current_theme );
mp-wp_genesis 222
mp-wp_genesis 223 $themes = array( );
mp-wp_genesis 224 $themes['current_theme'] = $current_theme;
mp-wp_genesis 225 foreach( (array) $installed_themes as $theme_title => $theme ) {
mp-wp_genesis 226 $themes[$theme['Template']] = array( );
mp-wp_genesis 227
mp-wp_genesis 228 foreach( (array) $theme as $key => $value ) {
mp-wp_genesis 229 $themes[$theme['Template']][$key] = $value;
mp-wp_genesis 230 }
mp-wp_genesis 231 }
mp-wp_genesis 232
mp-wp_genesis 233 $options = array(
mp-wp_genesis 234 'method' => 'POST',
mp-wp_genesis 235 'timeout' => 3,
mp-wp_genesis 236 'body' => 'themes=' . urlencode( serialize( $themes ) )
mp-wp_genesis 237 );
mp-wp_genesis 238 $options['headers'] = array(
mp-wp_genesis 239 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),
mp-wp_genesis 240 'Content-Length' => strlen( $options['body'] ),
mp-wp_genesis 241 'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
mp-wp_genesis 242 );
mp-wp_genesis 243
mp-wp_genesis 244 $raw_response = wp_remote_request( 'http://polimedia.us/muiewp/themes/update-check/1.0/', $options );
mp-wp_genesis 245
mp-wp_genesis 246 if( is_wp_error( $raw_response ) )
mp-wp_genesis 247 return false;
mp-wp_genesis 248
mp-wp_genesis 249 if( 200 != $raw_response['response']['code'] )
mp-wp_genesis 250 return false;
mp-wp_genesis 251
mp-wp_genesis 252 $response = unserialize( $raw_response['body'] );
mp-wp_genesis 253 if( $response )
mp-wp_genesis 254 $new_option->response = $response;
mp-wp_genesis 255
mp-wp_genesis 256 update_option( 'update_themes', $new_option );
mp-wp_genesis 257 }
mp-wp_genesis 258
mp-wp_genesis 259 /**
mp-wp_genesis 260 * Check the last time plugins were run before checking plugin versions.
mp-wp_genesis 261 *
mp-wp_genesis 262 * This might have been backported to WordPress 2.6.1 for performance reasons.
mp-wp_genesis 263 * This is used for the wp-admin to check only so often instead of every page
mp-wp_genesis 264 * load.
mp-wp_genesis 265 *
mp-wp_genesis 266 * @since 2.7.0
mp-wp_genesis 267 * @access private
mp-wp_genesis 268 */
mp-wp_genesis 269 function _maybe_update_plugins() {
mp-wp_genesis 270 $current = get_option( 'update_plugins' );
mp-wp_genesis 271 if ( isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ) )
mp-wp_genesis 272 return;
mp-wp_genesis 273 wp_update_plugins();
mp-wp_genesis 274 }
mp-wp_genesis 275
mp-wp_genesis 276 /**
mp-wp_genesis 277 * Check themes versions only after a duration of time.
mp-wp_genesis 278 *
mp-wp_genesis 279 * This is for performance reasons to make sure that on the theme version
mp-wp_genesis 280 * checker is not run on every page load.
mp-wp_genesis 281 *
mp-wp_genesis 282 * @since 2.7.0
mp-wp_genesis 283 * @access private
mp-wp_genesis 284 */
mp-wp_genesis 285 function _maybe_update_themes( ) {
mp-wp_genesis 286 $current = get_option( 'update_themes' );
mp-wp_genesis 287 if( isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked ) )
mp-wp_genesis 288 return;
mp-wp_genesis 289
mp-wp_genesis 290 wp_update_themes( );
mp-wp_genesis 291 }
mp-wp_genesis 292
mp-wp_genesis 293 add_action( 'load-plugins.php', 'wp_update_plugins' );
mp-wp_genesis 294 add_action( 'load-update.php', 'wp_update_plugins' );
mp-wp_genesis 295 add_action( 'admin_init', '_maybe_update_plugins' );
mp-wp_genesis 296 add_action( 'wp_update_plugins', 'wp_update_plugins' );
mp-wp_genesis 297
mp-wp_genesis 298 add_action( 'admin_init', '_maybe_update_themes' );
mp-wp_genesis 299 add_action( 'wp_update_themes', 'wp_update_themes' );
mp-wp_genesis 300
mp-wp_genesis 301 if ( !wp_next_scheduled('wp_update_plugins') && !defined('WP_INSTALLING') )
mp-wp_genesis 302 wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');
mp-wp_genesis 303
mp-wp_genesis 304
mp-wp_genesis 305 if ( !wp_next_scheduled('wp_update_themes') && !defined('WP_INSTALLING') )
mp-wp_genesis 306 wp_schedule_event(time(), 'twicedaily', 'wp_update_themes');
mp-wp_genesis 307
mp-wp_genesis 308 ?>