1 | <?php
|
---|
2 | function upgrade_page()
|
---|
3 | {
|
---|
4 | global $xoops_config,$xpress_config;
|
---|
5 |
|
---|
6 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
7 | $check_url = "http://ja1.xpressme.info/version_check/?version=$xpress_version";
|
---|
8 |
|
---|
9 | echo '<div class="wrap">'."\n";
|
---|
10 | echo '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
|
---|
11 | echo '<h2>' . __('XPressME Upgrade', 'xpressme') . "</h2><br>\n";
|
---|
12 |
|
---|
13 | if(get_xpress_latest_version()){
|
---|
14 | $latest = get_option('xpressme_latest_version');
|
---|
15 | if ($latest) {
|
---|
16 | $site_url=$latest['url'];
|
---|
17 | $package=$latest['package'];
|
---|
18 | $latest_version=$latest['latest_version'];
|
---|
19 | $check_time=$latest['check_time'];
|
---|
20 | }
|
---|
21 |
|
---|
22 |
|
---|
23 | if (version_compare($xpress_version, $latest_version, '>')){
|
---|
24 | echo '<h3 class="response">';
|
---|
25 | 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);
|
---|
26 | echo '</h3>';
|
---|
27 |
|
---|
28 | } else if (version_compare($xpress_version, $latest_version, '<')) {
|
---|
29 | echo '<h3 class="response">'. __('There is a new version of XPressME Integration Kit available for upgrade', 'xpressme') . '</h3>';
|
---|
30 | echo '<p>';
|
---|
31 | // printf(__('You can upgrade to version %s automatically or download the package and install it manually:'),$latest_version);
|
---|
32 | printf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version);
|
---|
33 | echo '</p>';
|
---|
34 | echo '<a class="button" href="' . $package . '">';
|
---|
35 | printf(__('Download %s', 'xpressme') , $latest_version);
|
---|
36 | echo '</a>';
|
---|
37 | } else {
|
---|
38 | echo '<h3 class="response">'. __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme') . '</h3>';
|
---|
39 | }
|
---|
40 | } else {
|
---|
41 | echo '<h3 class="response">';
|
---|
42 | printf(__('There is no response from <a href="%s">version check API</a> now. sorry, please confirm it after.', 'xpressme'),$check_url);
|
---|
43 | echo "</div>\n";
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | function xp_remote_get($url, $headers = ""){
|
---|
48 | global $xoops_config;
|
---|
49 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
50 |
|
---|
51 | require_once( $xoops_config->module_path . '/wp-includes/class-snoopy.php');
|
---|
52 |
|
---|
53 | // Snoopy is an HTTP client in PHP
|
---|
54 | $client = new Snoopy();
|
---|
55 | $client->agent = 'XPressME/' . $xpress_version;
|
---|
56 | $client->read_timeout = 2;
|
---|
57 | if (is_array($headers) ) {
|
---|
58 | $client->rawheaders = $headers;
|
---|
59 | }
|
---|
60 |
|
---|
61 | @$client->fetch($url);
|
---|
62 | $response['response']['code'] = $client->status;
|
---|
63 | $response['body'] = $client->results;
|
---|
64 | return $response;
|
---|
65 | return $client;
|
---|
66 |
|
---|
67 | }
|
---|
68 |
|
---|
69 | function get_xpress_latest_version(){
|
---|
70 | global $wp_version, $wpdb, $wp_local_package;
|
---|
71 | global $xoops_config;
|
---|
72 |
|
---|
73 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
74 | $lang = WPLANG;
|
---|
75 |
|
---|
76 | $check_url = "http://ja.xpressme.info/version_check/index2.php?version=$xpress_version?lang=$lang";
|
---|
77 | $request_options = array(
|
---|
78 | 'timeout' => 3,
|
---|
79 | 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
|
---|
80 | );
|
---|
81 |
|
---|
82 | if (! function_exists('wp_remote_get')) {
|
---|
83 | $response = xp_remote_get($check_url);
|
---|
84 |
|
---|
85 | if (empty($response['body'])) return false;
|
---|
86 | } else {
|
---|
87 |
|
---|
88 | $response = wp_remote_get($check_url, $request_options);
|
---|
89 |
|
---|
90 | if ( is_wp_error( $response ) )
|
---|
91 | return false;
|
---|
92 | }
|
---|
93 | if ( 200 != $response['response']['code'] )
|
---|
94 | return false;
|
---|
95 | $body = trim( $response['body'] );
|
---|
96 | $body = str_replace(array("\r\n", "\r"), "\n", $body);
|
---|
97 | $returns = explode("\n", $body);
|
---|
98 | if ( isset( $returns[0] ) ) $response = $returns[0]; else $response = '';
|
---|
99 | if ( isset( $returns[1] ) ) $url = clean_url( $returns[1] ); else $url = '';
|
---|
100 | if ( isset( $returns[2] ) ) $package = clean_url( $returns[2] ); else $package = '';
|
---|
101 | if ( isset( $returns[3] ) ) $latest_version = $returns[3]; else $latest_version = '';
|
---|
102 | if ( isset( $returns[4] ) ) $before_version = $returns[4]; else $before_version = '';
|
---|
103 |
|
---|
104 | // diff
|
---|
105 | if ( isset( $returns[5] ) ) $diff_response = $returns[5]; else $diff_response = '';
|
---|
106 | if ( isset( $returns[6] ) ) $diff_url = clean_url( $returns[6] ); else $diff_url = '';
|
---|
107 | if ( isset( $returns[7] ) ) $diff_package = clean_url( $returns[7] ); else $diff_package = '';
|
---|
108 | if ( isset( $returns[8] ) ) $diff_latest_version = $returns[8]; else $diff_latest_version = '';
|
---|
109 | if ( isset( $returns[9] ) ) $diff_before_version = $returns[9]; else $diff_before_version = '';
|
---|
110 |
|
---|
111 | // developer
|
---|
112 | if ( isset( $returns[10] ) ) $develop_response = $returns[10]; else $develop_response = '';
|
---|
113 | if ( isset( $returns[11] ) ) $develop_url = clean_url( $returns[11] ); else $develop_url = '';
|
---|
114 | if ( isset( $returns[12] ) ) $develop_package = clean_url( $returns[12] ); else $develop_package = '';
|
---|
115 | if ( isset( $returns[13] ) ) $develop_latest_version = $returns[13]; else $develop_latest_version = '';
|
---|
116 | if ( isset( $returns[14] ) ) $develop_before_version = $returns[14]; else $develop_before_version = '';
|
---|
117 |
|
---|
118 | $write_options = array (
|
---|
119 | 'response' => $response ,
|
---|
120 | 'url' => $url ,
|
---|
121 | 'package' => $package ,
|
---|
122 | 'latest_version' => $latest_version ,
|
---|
123 | 'before_version' => $before_version ,
|
---|
124 | 'diff_response' => $diff_response ,
|
---|
125 | 'diff_url' => $diff_url ,
|
---|
126 | 'diff_package' => $diff_package ,
|
---|
127 | 'diff_latest_version' => $diff_latest_version ,
|
---|
128 | 'diff_before_version' => $diff_before_version ,
|
---|
129 | 'develop_response' => $develop_response ,
|
---|
130 | 'develop_url' => $develop_url ,
|
---|
131 | 'develop_package' => $develop_package ,
|
---|
132 | 'develop_latest_version' => $develop_latest_version ,
|
---|
133 | 'develop_before_version' => $develop_before_version ,
|
---|
134 | 'check_time' => time()
|
---|
135 | );
|
---|
136 |
|
---|
137 | $latest_version = get_option('xpressme_latest_version');
|
---|
138 | if (!$latest_version) {
|
---|
139 | add_option('xpressme_latest_version', $write_options);
|
---|
140 | } else {
|
---|
141 | update_option('xpressme_latest_version', $write_options);
|
---|
142 | }
|
---|
143 | return true;
|
---|
144 | }
|
---|
145 |
|
---|
146 | function xpress_update_check() {
|
---|
147 | if ( defined('WP_INSTALLING') )
|
---|
148 | return;
|
---|
149 | global $pagenow;
|
---|
150 |
|
---|
151 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
152 |
|
---|
153 | if ( 'admin.php' == $pagenow && 'page=upgrade_page' == $php_query_string)
|
---|
154 | return;
|
---|
155 |
|
---|
156 | global $wp_version, $wpdb, $wp_local_package;
|
---|
157 | global $xoops_config;
|
---|
158 |
|
---|
159 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
160 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
161 |
|
---|
162 | $latest = get_option('xpressme_latest_version');
|
---|
163 | if (!$latest ) {
|
---|
164 | get_xpress_latest_version();
|
---|
165 | $latest = get_option('xpressme_latest_version');
|
---|
166 | }
|
---|
167 |
|
---|
168 | if ($latest) {
|
---|
169 | $next_check = $latest['check_time'] + (60*60*24);
|
---|
170 | $now_time = time();
|
---|
171 | if ($next_check < $now_time ){
|
---|
172 | get_xpress_latest_version();
|
---|
173 | $latest = get_option('xpressme_latest_version');
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | if ($latest) {
|
---|
178 | $url=$latest['url'];
|
---|
179 | $package=$latest['package'];
|
---|
180 | $latest_version=$latest['latest_version'];
|
---|
181 | $check_time=$latest['check_time'];
|
---|
182 | $upgrade_page = $xoops_config->module_url . "/wp-admin/admin.php?page=upgrade_page";
|
---|
183 |
|
---|
184 | if (version_compare($xpress_version, $latest_version, '<')) {
|
---|
185 | if ( current_user_can('manage_options') ){
|
---|
186 | $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! <a href="%2$s">Please update now</a>.', 'xpressme'), $latest_version, $upgrade_page );
|
---|
187 | } else {
|
---|
188 | $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! Please notify the site administrator.', 'xpressme'), $latest_version );
|
---|
189 | }
|
---|
190 | echo "<div id='update-nag'>$msg </div>";
|
---|
191 | }
|
---|
192 | }
|
---|
193 | }
|
---|
194 | ?> |
---|