Index: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme.php	(revision 360)
+++ trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme.php	(revision 368)
@@ -34,4 +34,6 @@
 	add_submenu_page(__FILE__, __('Integration Settings', 'xpressme'), __('Integration Settings', 'xpressme'), 8, 'integration_option_page', 'integration_option_page');
 	add_submenu_page(__FILE__, __('Other Settings', 'xpressme'), __('Other Settings', 'xpressme'), 8, 'other_option_page', 'other_option_page');
+	if (function_exists(wp_remote_get))
+		add_submenu_page(__FILE__, __('Upgrade', 'xpressme'), __('Upgrade', 'xpressme'), 8, 'upgrade_page', 'upgrade_page');
 	add_submenu_page(__FILE__, __('to XOOPS Admin', 'xpressme'), __('to XOOPS Admin', 'xpressme'), 8,  'redirect_xoops_admin', 'redirect_xoops_admin');
 }
@@ -261,3 +263,146 @@
 }
 
+function upgrade_page()
+{
+	global $xoops_config,$xpress_config;
+	
+	$xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
+	$check_url = "http://ja1.xpressme.info/version_check/?version=$xpress_version";
+
+	echo	'<div class="wrap">'."\n";
+	echo		'<div id="icon-options-general" class="icon32"><br /></div>'."\n";
+	echo		'<h2>' . __('XPressME Upgrade', 'xpressme') . "</h2><br>\n";
+	
+	if(get_xpress_latest_version()){
+		$latest = get_option('xpressme_latest_version');
+		if ($latest) {
+			$site_url=$latest['url'];
+			$package=$latest['package'];
+			$latest_version=$latest['latest_version'];
+			$check_time=$latest['check_time'];
+		}
+
+
+		if (version_compare($xpress_version, $latest_version, '>')){
+				echo '<h3 class="response">';
+				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);
+				echo '</h3>';
+
+		} else if (version_compare($xpress_version, $latest_version, '<')) {
+			echo	'<h3 class="response">'. __('There is a new version of XPressME Integration Kit available for upgrade', 'xpressme') . '</h3>';
+			echo '<p>';
+	//		printf(__('You can upgrade to version %s automatically or download the package and install it manually:'),$latest_version);
+			printf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version);
+			echo '</p>';
+			echo '<a class="button" href="' . $package . '">';
+			printf(__('Download %s', 'xpressme') , $latest_version);
+			echo '</a>';
+		} else {
+			echo	'<h3 class="response">'. __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme') . '</h3>';
+		}
+	} else {
+		echo '<h3 class="response">';
+		printf(__('There is no response from <a href="%s">version check API</a> now. sorry, please confirm it after.', 'xpressme'),$check_url);
+		echo	"</div>\n";
+	}
+}
+
+function get_xpress_latest_version(){
+	global $wp_version, $wpdb, $wp_local_package;
+	global $xoops_config;
+	
+	$xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
+
+	$check_url = "http://ja.xpressme.info/version_check/?version=$xpress_version";
+	$request_options = array(
+	'timeout' => 3,
+	'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
+	);
+
+	if (! function_exists(wp_remote_get)) return false;
+	
+	$response = wp_remote_get($check_url, $request_options);
+	if ( is_wp_error( $response ) )
+		return false;
+
+	if ( 200 != $response['response']['code'] )
+		return false;
+
+	$body = trim( $response['body'] );
+	$body = str_replace(array("\r\n", "\r"), "\n", $body);
+	$returns = explode("\n", $body);
+	$response = esc_attr( $returns[0] );
+	if ( isset( $returns[1] ) )
+		$url = esc_url( $returns[1] );
+	if ( isset( $returns[2] ) )
+		$package = esc_url( $returns[2] );
+	if ( isset( $returns[3] ) )
+		$latest_version = esc_attr( $returns[3] );
+
+	$write_options = array (
+		'url' => $url ,
+		'package' => $package ,
+		'latest_version' => $latest_version ,
+		'check_time' => time()
+	);
+	
+	$latest_version = get_option('xpressme_latest_version');
+	if (!$latest_version) {
+		add_option('xpressme_latest_version', $write_options);
+	} else {
+		update_option('xpressme_latest_version', $write_options);
+	}
+	return true;
+}
+
+function xpress_update_check() {
+	if ( defined('WP_INSTALLING') )
+		return;
+	global $pagenow;
+
+	$php_query_string = $_SERVER['QUERY_STRING'];
+
+	if ( 'admin.php' == $pagenow && 'page=upgrade_page' == $php_query_string)
+		return;
+
+	global $wp_version, $wpdb, $wp_local_package;
+	global $xoops_config;
+
+	$php_query_string = $_SERVER['QUERY_STRING'];
+	$xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
+
+	$latest = get_option('xpressme_latest_version');
+	if (!$latest ) {
+		get_xpress_latest_version();
+		$latest = get_option('xpressme_latest_version');
+	}
+
+	if ($latest) {
+		$next_check = $latest['check_time'] + (60*60*24);
+		$now_time = time();
+		if ($next_check < $now_time ){
+			get_xpress_latest_version();
+			$latest = get_option('xpressme_latest_version');
+		}
+	}
+
+	if ($latest) {
+		$url=$latest['url'];
+		$package=$latest['package'];
+		$latest_version=$latest['latest_version'];
+		$check_time=$latest['check_time'];
+		$upgrade_page = $xoops_config->module_url . "/wp-admin/admin.php?page=upgrade_page";
+
+		if (version_compare($xpress_version, $latest_version, '<')) {
+			if ( current_user_can('manage_options') ){
+				$msg = sprintf( __('XPressME Integration Kit Version %1$s is available! <a href="%2$s">Please update now</a>.', 'xpressme'), $latest_version, $upgrade_page );
+			} else {
+				$msg = sprintf( __('XPressME Integration Kit Version %1$s is available! Please notify the site administrator.', 'xpressme'), $latest_version );
+			}
+			echo "<div id='update-nag'>$msg </div>";
+		}
+	}
+}
+
+add_action( 'admin_notices', 'xpress_update_check', 3 );
 ?>
