- Timestamp:
- Aug 24, 2009, 8:53:44 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme.php
r360 r368 34 34 add_submenu_page(__FILE__, __('Integration Settings', 'xpressme'), __('Integration Settings', 'xpressme'), 8, 'integration_option_page', 'integration_option_page'); 35 35 add_submenu_page(__FILE__, __('Other Settings', 'xpressme'), __('Other Settings', 'xpressme'), 8, 'other_option_page', 'other_option_page'); 36 if (function_exists(wp_remote_get)) 37 add_submenu_page(__FILE__, __('Upgrade', 'xpressme'), __('Upgrade', 'xpressme'), 8, 'upgrade_page', 'upgrade_page'); 36 38 add_submenu_page(__FILE__, __('to XOOPS Admin', 'xpressme'), __('to XOOPS Admin', 'xpressme'), 8, 'redirect_xoops_admin', 'redirect_xoops_admin'); 37 39 } … … 261 263 } 262 264 265 function upgrade_page() 266 { 267 global $xoops_config,$xpress_config; 268 269 $xpress_version = $xoops_config->module_version . $xoops_config->module_codename; 270 $check_url = "http://ja1.xpressme.info/version_check/?version=$xpress_version"; 271 272 echo '<div class="wrap">'."\n"; 273 echo '<div id="icon-options-general" class="icon32"><br /></div>'."\n"; 274 echo '<h2>' . __('XPressME Upgrade', 'xpressme') . "</h2><br>\n"; 275 276 if(get_xpress_latest_version()){ 277 $latest = get_option('xpressme_latest_version'); 278 if ($latest) { 279 $site_url=$latest['url']; 280 $package=$latest['package']; 281 $latest_version=$latest['latest_version']; 282 $check_time=$latest['check_time']; 283 } 284 285 286 if (version_compare($xpress_version, $latest_version, '>')){ 287 echo '<h3 class="response">'; 288 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); 289 echo '</h3>'; 290 291 } else if (version_compare($xpress_version, $latest_version, '<')) { 292 echo '<h3 class="response">'. __('There is a new version of XPressME Integration Kit available for upgrade', 'xpressme') . '</h3>'; 293 echo '<p>'; 294 // printf(__('You can upgrade to version %s automatically or download the package and install it manually:'),$latest_version); 295 printf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version); 296 echo '</p>'; 297 echo '<a class="button" href="' . $package . '">'; 298 printf(__('Download %s', 'xpressme') , $latest_version); 299 echo '</a>'; 300 } else { 301 echo '<h3 class="response">'. __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme') . '</h3>'; 302 } 303 } else { 304 echo '<h3 class="response">'; 305 printf(__('There is no response from <a href="%s">version check API</a> now. sorry, please confirm it after.', 'xpressme'),$check_url); 306 echo "</div>\n"; 307 } 308 } 309 310 function get_xpress_latest_version(){ 311 global $wp_version, $wpdb, $wp_local_package; 312 global $xoops_config; 313 314 $xpress_version = $xoops_config->module_version . $xoops_config->module_codename; 315 316 $check_url = "http://ja.xpressme.info/version_check/?version=$xpress_version"; 317 $request_options = array( 318 'timeout' => 3, 319 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 320 ); 321 322 if (! function_exists(wp_remote_get)) return false; 323 324 $response = wp_remote_get($check_url, $request_options); 325 if ( is_wp_error( $response ) ) 326 return false; 327 328 if ( 200 != $response['response']['code'] ) 329 return false; 330 331 $body = trim( $response['body'] ); 332 $body = str_replace(array("\r\n", "\r"), "\n", $body); 333 $returns = explode("\n", $body); 334 $response = esc_attr( $returns[0] ); 335 if ( isset( $returns[1] ) ) 336 $url = esc_url( $returns[1] ); 337 if ( isset( $returns[2] ) ) 338 $package = esc_url( $returns[2] ); 339 if ( isset( $returns[3] ) ) 340 $latest_version = esc_attr( $returns[3] ); 341 342 $write_options = array ( 343 'url' => $url , 344 'package' => $package , 345 'latest_version' => $latest_version , 346 'check_time' => time() 347 ); 348 349 $latest_version = get_option('xpressme_latest_version'); 350 if (!$latest_version) { 351 add_option('xpressme_latest_version', $write_options); 352 } else { 353 update_option('xpressme_latest_version', $write_options); 354 } 355 return true; 356 } 357 358 function xpress_update_check() { 359 if ( defined('WP_INSTALLING') ) 360 return; 361 global $pagenow; 362 363 $php_query_string = $_SERVER['QUERY_STRING']; 364 365 if ( 'admin.php' == $pagenow && 'page=upgrade_page' == $php_query_string) 366 return; 367 368 global $wp_version, $wpdb, $wp_local_package; 369 global $xoops_config; 370 371 $php_query_string = $_SERVER['QUERY_STRING']; 372 $xpress_version = $xoops_config->module_version . $xoops_config->module_codename; 373 374 $latest = get_option('xpressme_latest_version'); 375 if (!$latest ) { 376 get_xpress_latest_version(); 377 $latest = get_option('xpressme_latest_version'); 378 } 379 380 if ($latest) { 381 $next_check = $latest['check_time'] + (60*60*24); 382 $now_time = time(); 383 if ($next_check < $now_time ){ 384 get_xpress_latest_version(); 385 $latest = get_option('xpressme_latest_version'); 386 } 387 } 388 389 if ($latest) { 390 $url=$latest['url']; 391 $package=$latest['package']; 392 $latest_version=$latest['latest_version']; 393 $check_time=$latest['check_time']; 394 $upgrade_page = $xoops_config->module_url . "/wp-admin/admin.php?page=upgrade_page"; 395 396 if (version_compare($xpress_version, $latest_version, '<')) { 397 if ( current_user_can('manage_options') ){ 398 $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! <a href="%2$s">Please update now</a>.', 'xpressme'), $latest_version, $upgrade_page ); 399 } else { 400 $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! Please notify the site administrator.', 'xpressme'), $latest_version ); 401 } 402 echo "<div id='update-nag'>$msg </div>"; 403 } 404 } 405 } 406 407 add_action( 'admin_notices', 'xpress_update_check', 3 ); 263 408 ?>
Note: See TracChangeset
for help on using the changeset viewer.