- Timestamp:
- Nov 16, 2009, 9:23:34 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme.php
r411 r442 292 292 } 293 293 294 function upgrade_page() 295 { 296 global $xoops_config,$xpress_config; 297 298 $xpress_version = $xoops_config->module_version . $xoops_config->module_codename; 299 $check_url = "http://ja1.xpressme.info/version_check/?version=$xpress_version"; 300 301 echo '<div class="wrap">'."\n"; 302 echo '<div id="icon-options-general" class="icon32"><br /></div>'."\n"; 303 echo '<h2>' . __('XPressME Upgrade', 'xpressme') . "</h2><br>\n"; 304 305 if(get_xpress_latest_version()){ 306 $latest = get_option('xpressme_latest_version'); 307 if ($latest) { 308 $site_url=$latest['url']; 309 $package=$latest['package']; 310 $latest_version=$latest['latest_version']; 311 $check_time=$latest['check_time']; 312 } 313 314 315 if (version_compare($xpress_version, $latest_version, '>')){ 316 echo '<h3 class="response">'; 317 printf(__('You are using a XPressME Integration Kit development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.', 'xpressme') , $xpress_version , $site_url); 318 echo '</h3>'; 319 320 } else if (version_compare($xpress_version, $latest_version, '<')) { 321 echo '<h3 class="response">'. __('There is a new version of XPressME Integration Kit available for upgrade', 'xpressme') . '</h3>'; 322 echo '<p>'; 323 // printf(__('You can upgrade to version %s automatically or download the package and install it manually:'),$latest_version); 324 printf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version); 325 echo '</p>'; 326 echo '<a class="button" href="' . $package . '">'; 327 printf(__('Download %s', 'xpressme') , $latest_version); 328 echo '</a>'; 329 } else { 330 echo '<h3 class="response">'. __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme') . '</h3>'; 331 } 332 } else { 333 echo '<h3 class="response">'; 334 printf(__('There is no response from <a href="%s">version check API</a> now. sorry, please confirm it after.', 'xpressme'),$check_url); 335 echo "</div>\n"; 336 } 337 } 338 339 function xp_remote_get($url, $headers = ""){ 340 global $xoops_config; 341 $xpress_version = $xoops_config->module_version . $xoops_config->module_codename; 342 343 require_once( $xoops_config->module_path . '/wp-includes/class-snoopy.php'); 344 345 // Snoopy is an HTTP client in PHP 346 $client = new Snoopy(); 347 $client->agent = 'XPressME/' . $xpress_version; 348 $client->read_timeout = 2; 349 if (is_array($headers) ) { 350 $client->rawheaders = $headers; 351 } 352 353 @$client->fetch($url); 354 $response['response']['code'] = $client->status; 355 $response['body'] = $client->results; 356 return $response; 357 return $client; 358 359 } 360 361 function get_xpress_latest_version(){ 362 global $wp_version, $wpdb, $wp_local_package; 363 global $xoops_config; 364 365 $xpress_version = $xoops_config->module_version . $xoops_config->module_codename; 366 367 $check_url = "http://ja.xpressme.info/version_check/?version=$xpress_version"; 368 $request_options = array( 369 'timeout' => 3, 370 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 371 ); 372 373 if (! function_exists('wp_remote_get')) { 374 $response = xp_remote_get($check_url); 375 376 if (empty($response['body'])) return false; 377 } else { 378 379 $response = wp_remote_get($check_url, $request_options); 380 381 if ( is_wp_error( $response ) ) 382 return false; 383 } 384 if ( 200 != $response['response']['code'] ) 385 return false; 386 $body = trim( $response['body'] ); 387 $body = str_replace(array("\r\n", "\r"), "\n", $body); 388 $returns = explode("\n", $body); 389 if ( isset( $returns[0] ) ) $response = $returns[0]; else $response = ''; 390 if ( isset( $returns[1] ) ) $url = clean_url( $returns[1] ); else $url = ''; 391 if ( isset( $returns[2] ) ) $package = clean_url( $returns[2] ); else $package = ''; 392 if ( isset( $returns[3] ) ) $latest_version = $returns[3]; else $latest_version = ''; 393 if ( isset( $returns[4] ) ) $before_version = $returns[4]; else $before_version = ''; 394 395 // diff 396 if ( isset( $returns[5] ) ) $diff_response = $returns[5]; else $diff_response = ''; 397 if ( isset( $returns[6] ) ) $diff_url = clean_url( $returns[6] ); else $diff_url = ''; 398 if ( isset( $returns[7] ) ) $diff_package = clean_url( $returns[7] ); else $diff_package = ''; 399 if ( isset( $returns[8] ) ) $diff_latest_version = $returns[8]; else $diff_latest_version = ''; 400 if ( isset( $returns[9] ) ) $diff_before_version = $returns[9]; else $diff_before_version = ''; 401 402 // developer 403 if ( isset( $returns[10] ) ) $develop_response = $returns[10]; else $develop_response = ''; 404 if ( isset( $returns[11] ) ) $develop_url = clean_url( $returns[11] ); else $develop_url = ''; 405 if ( isset( $returns[12] ) ) $develop_package = clean_url( $returns[12] ); else $develop_package = ''; 406 if ( isset( $returns[13] ) ) $develop_latest_version = $returns[13]; else $develop_latest_version = ''; 407 if ( isset( $returns[14] ) ) $develop_before_version = $returns[14]; else $develop_before_version = ''; 408 409 $write_options = array ( 410 'response' => $response , 411 'url' => $url , 412 'package' => $package , 413 'latest_version' => $latest_version , 414 'before_version' => $before_version , 415 'diff_response' => $diff_response , 416 'diff_url' => $diff_url , 417 'diff_package' => $diff_package , 418 'diff_latest_version' => $diff_latest_version , 419 'diff_before_version' => $diff_before_version , 420 'develop_response' => $develop_response , 421 'develop_url' => $develop_url , 422 'develop_package' => $develop_package , 423 'develop_latest_version' => $develop_latest_version , 424 'develop_before_version' => $develop_before_version , 425 'check_time' => time() 426 ); 427 428 $latest_version = get_option('xpressme_latest_version'); 429 if (!$latest_version) { 430 add_option('xpressme_latest_version', $write_options); 431 } else { 432 update_option('xpressme_latest_version', $write_options); 433 } 434 return true; 435 } 436 437 function xpress_update_check() { 438 if ( defined('WP_INSTALLING') ) 439 return; 440 global $pagenow; 441 442 $php_query_string = $_SERVER['QUERY_STRING']; 443 444 if ( 'admin.php' == $pagenow && 'page=upgrade_page' == $php_query_string) 445 return; 446 447 global $wp_version, $wpdb, $wp_local_package; 448 global $xoops_config; 449 450 $php_query_string = $_SERVER['QUERY_STRING']; 451 $xpress_version = $xoops_config->module_version . $xoops_config->module_codename; 452 453 $latest = get_option('xpressme_latest_version'); 454 if (!$latest ) { 455 get_xpress_latest_version(); 456 $latest = get_option('xpressme_latest_version'); 457 } 458 459 if ($latest) { 460 $next_check = $latest['check_time'] + (60*60*24); 461 $now_time = time(); 462 if ($next_check < $now_time ){ 463 get_xpress_latest_version(); 464 $latest = get_option('xpressme_latest_version'); 465 } 466 } 467 468 if ($latest) { 469 $url=$latest['url']; 470 $package=$latest['package']; 471 $latest_version=$latest['latest_version']; 472 $check_time=$latest['check_time']; 473 $upgrade_page = $xoops_config->module_url . "/wp-admin/admin.php?page=upgrade_page"; 474 475 if (version_compare($xpress_version, $latest_version, '<')) { 476 if ( current_user_can('manage_options') ){ 477 $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! <a href="%2$s">Please update now</a>.', 'xpressme'), $latest_version, $upgrade_page ); 478 } else { 479 $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! Please notify the site administrator.', 'xpressme'), $latest_version ); 480 } 481 echo "<div id='update-nag'>$msg </div>"; 482 } 483 } 484 } 485 294 include_once dirname( __FILE__ ).'/include/xpress_upgrade.php' ; 486 295 add_action( 'admin_notices', 'xpress_update_check', 3 ); 487 296
Note: See TracChangeset
for help on using the changeset viewer.