1 | <?php
|
---|
2 | function find_xpress_update( $version, $locale ){
|
---|
3 | $latest_version = get_option('xpressme_latest_version');
|
---|
4 | return (object)$latest_version;
|
---|
5 | }
|
---|
6 |
|
---|
7 | function list_xpress_update( $update=null ) {
|
---|
8 | global $xoops_config,$xpress_config;
|
---|
9 |
|
---|
10 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
11 | $lang = WPLANG;
|
---|
12 |
|
---|
13 | $automatically_enable = file_exists(ABSPATH .'wp-admin/includes/class-wp-upgrader.php');
|
---|
14 |
|
---|
15 | $check_url = "http://ja.xpressme.info/version_check/index.php?version=$xpress_version&lang=$lang";
|
---|
16 |
|
---|
17 | echo '<div class="wrap">'."\n";
|
---|
18 | echo '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
|
---|
19 | echo '<h2>' . __('XPressME Upgrade', 'xpressme') . "</h2><br>\n";
|
---|
20 | if( get_xpress_latest_version($check_url)){
|
---|
21 | $latest = get_option('xpressme_latest_version');
|
---|
22 | if ($latest) {
|
---|
23 | $site_url=$latest['url'];
|
---|
24 | $package=$latest['package'];
|
---|
25 | $latest_version=$latest['latest_version'];
|
---|
26 | $check_time=$latest['check_time'];
|
---|
27 | }
|
---|
28 |
|
---|
29 | $show_buttons = false;
|
---|
30 | if (version_compare($xpress_version, $latest_version, '>')){
|
---|
31 | echo '<h3 class="response">';
|
---|
32 | printf(__('You are using a XPressME Integration Kit development version (%s). Cool! Please stay updated.', 'xpressme') , $xpress_version);
|
---|
33 | echo '</h3>';
|
---|
34 | } else if (version_compare($xpress_version, $latest_version, '<')) {
|
---|
35 | echo '<h3 class="response">';
|
---|
36 | _e( 'An updated version of XPressME Integration Kit is available.', 'xpressme' );
|
---|
37 | echo '</h3>';
|
---|
38 |
|
---|
39 | if ($latest['diff_response'] == 'diff_exists'){
|
---|
40 | $download_diff ='<a class="button" href="' . $latest['diff_package'] . '">';
|
---|
41 | $download_diff .= sprintf(__('Download differential file for %s', 'xpressme') , $xpress_version);
|
---|
42 | $download_diff .='</a>';
|
---|
43 | }
|
---|
44 | if($automatically_enable){
|
---|
45 | $message = sprintf(__('You can update to XPressME Integration Kit Ver %s</a> automatically or download the package and install it manually:', 'xpressme'), $latest_version);
|
---|
46 | } else {
|
---|
47 | $message = sprintf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version);
|
---|
48 | }
|
---|
49 | $submit = __('Update Automatically', 'xpressme');
|
---|
50 | $form_action = 'admin.php?page=upgrade_page&action=do-xpress-upgrade';
|
---|
51 | $download = sprintf(__('Download %s', 'xpressme') , $latest_version);
|
---|
52 | $show_buttons = true;
|
---|
53 |
|
---|
54 | } else {
|
---|
55 | echo '<h3>';
|
---|
56 | printf(__('You have the latest version of XPressME Integration Kit Ver.%s.', 'xpressme'),$xpress_version);
|
---|
57 | echo '</h3>';
|
---|
58 |
|
---|
59 | $message = __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme');
|
---|
60 | $submit = __('Re-install Automatically', 'xpressme');
|
---|
61 | $form_action = 'update-core.php?action=do-core-reinstall';
|
---|
62 |
|
---|
63 | }
|
---|
64 |
|
---|
65 | // develop
|
---|
66 | $develop_show = false;
|
---|
67 | if ($latest['develop_response'] == 'development_exists'
|
---|
68 | && !empty($latest['develop_package'])
|
---|
69 | )
|
---|
70 | {
|
---|
71 | $develop_latest_version=$latest['develop_latest_version'];
|
---|
72 | $develop_form_action = 'admin.php?page=upgrade_page&action=do-xpress-develop_upgrade';
|
---|
73 | if($automatically_enable){
|
---|
74 | $develop_message = sprintf(__('You can update to XPressME Integration Kit development version %s automatically or download the package and install it manually:'), $develop_latest_version);
|
---|
75 | } else {
|
---|
76 | $develop_message = sprintf(__('You can use the development version %s download the package and install it manually:', 'xpressme'),$develop_latest_version);
|
---|
77 | }
|
---|
78 | $develop_show = true;
|
---|
79 | $develop_package=$latest['develop_package'];
|
---|
80 | $develop_submit = __('Update Automatically', 'xpressme');
|
---|
81 | $develop_download = sprintf(__('Download %s', 'xpressme') , $develop_latest_version);
|
---|
82 | $develop_download_diff = '';
|
---|
83 | // develop diff
|
---|
84 | if ($latest['diff_develop_response'] == 'diff_develop_exists'
|
---|
85 | && !empty($latest['diff_develop_package'])
|
---|
86 | )
|
---|
87 | {
|
---|
88 | $develop_download_diff = '<a class="button" href="' . $latest['diff_develop_package'] . '">';
|
---|
89 | $develop_download_difff .= sprintf(__('Download differential file for %s', 'xpressme') , $latest['diff_develop_latest_version']);
|
---|
90 | $develop_download_diff .= '</a>';
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | echo '<p>';
|
---|
95 | echo $message;
|
---|
96 | echo '</p>';
|
---|
97 | echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
|
---|
98 | // wp_nonce_field('upgrade-core');
|
---|
99 | echo '<p>';
|
---|
100 | echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
|
---|
101 | echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
|
---|
102 | if ( $show_buttons ) {
|
---|
103 | if($automatically_enable){
|
---|
104 | echo '<input id="upgrade" class="button" type="submit" value="' . esc_attr($submit) . '" name="upgrade" /> ';
|
---|
105 | }
|
---|
106 | echo '<a href="' . esc_url($package) . '" class="button">' . $download . '</a> ';
|
---|
107 | echo $download_diff;
|
---|
108 | }
|
---|
109 | echo '</form>';
|
---|
110 |
|
---|
111 | if ($develop_show){
|
---|
112 | echo '<p>';
|
---|
113 | echo $develop_message;
|
---|
114 | echo '</p>';
|
---|
115 | echo '<form method="post" action="' . $develop_form_action . '" name="develop_upgrade" class="develop_upgrade">';
|
---|
116 | echo '<p>';
|
---|
117 | echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
|
---|
118 | echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
|
---|
119 | if($automatically_enable){
|
---|
120 | echo '<input id="upgrade" class="button" type="submit" value="' . esc_attr($develop_submit) . '" name="develop_upgrade" /> ';
|
---|
121 | }
|
---|
122 | echo '<a href="' . esc_url($develop_package) . '" class="button">' . $develop_download . '</a> ';
|
---|
123 | echo $develop_download_diff;
|
---|
124 | echo '</form>';
|
---|
125 | }
|
---|
126 | } else {
|
---|
127 | echo '<h3 class="response">';
|
---|
128 | printf(__('There is no response from <a href="%s">version check API</a> now. sorry, please confirm it after.', 'xpressme'),$check_url);
|
---|
129 | echo "</div>\n";
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | function xpress_update_core($current) {
|
---|
135 | include_once ABSPATH . 'wp-content/plugins/xpressme/include/class-xpress-upgrader.php';
|
---|
136 | $upgrader = new Xpress_Upgrader();
|
---|
137 | return $upgrader->upgrade($current);
|
---|
138 | }
|
---|
139 |
|
---|
140 | function do_xpress_upgrade( $develop = false,$reinstall = false ) {
|
---|
141 | global $wp_filesystem,$xoops_config;
|
---|
142 |
|
---|
143 | if ( $reinstall )
|
---|
144 | $url = 'admin.php?page=upgrade_page&action=do-xpress-reinstall';
|
---|
145 | else {
|
---|
146 | if(!$develop)
|
---|
147 | $url = 'admin.php?page=upgrade_page&action=do-xpress-upgrade';
|
---|
148 | else
|
---|
149 | $url = 'admin.php?page=upgrade_page&action=do-xpress-develop_upgrade';
|
---|
150 | $url = wp_nonce_url($url, 'upgrade-xpress');
|
---|
151 | }
|
---|
152 | if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) )
|
---|
153 | return;
|
---|
154 |
|
---|
155 | $version = isset( $_POST['version'] )? $_POST['version'] : false;
|
---|
156 | $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
|
---|
157 | $update = find_xpress_update( $version, $locale );
|
---|
158 | // $update = true;
|
---|
159 | if ( !$update )
|
---|
160 | return;
|
---|
161 | if ( $develop )
|
---|
162 | $update->package = $update->develop_package;
|
---|
163 |
|
---|
164 | if ( ! WP_Filesystem($credentials, ABSPATH) ) {
|
---|
165 | request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
|
---|
166 | return;
|
---|
167 | }
|
---|
168 | ?>
|
---|
169 | <div class="wrap">
|
---|
170 | <?php screen_icon(); ?>
|
---|
171 | <h2><?php _e('Update XPressME Integration Kit', 'xpressme'); ?></h2>
|
---|
172 | <?php
|
---|
173 | if ( $wp_filesystem->errors->get_error_code() ) {
|
---|
174 | foreach ( $wp_filesystem->errors->get_error_messages() as $message )
|
---|
175 | show_message($message);
|
---|
176 | echo '</div>';
|
---|
177 | return;
|
---|
178 | }
|
---|
179 |
|
---|
180 | if ( $reinstall )
|
---|
181 | $update->response = 'reinstall';
|
---|
182 |
|
---|
183 | $result = xpress_update_core($update, 'show_message');
|
---|
184 |
|
---|
185 | if ( is_wp_error($result) ) {
|
---|
186 | show_message($result);
|
---|
187 | if ('up_to_date' != $result->get_error_code() )
|
---|
188 | show_message( __('Installation Failed', 'xpressme') );
|
---|
189 | } else {
|
---|
190 | show_message( __('XPressME Integration Kit files updated successfully', 'xpressme') );
|
---|
191 | show_message( __('Please update the module. ', 'xpressme') );
|
---|
192 |
|
---|
193 | $update_url = $xoops_config->module_url .'/admin/update.php';
|
---|
194 | show_message( '<strong>' . __('Actions:') . '</strong> <a href="' . esc_url( $update_url ) . '">' . __('Go to Module Update') . '</a>' );
|
---|
195 | }
|
---|
196 | echo '</div>';
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 |
|
---|
201 |
|
---|
202 | function upgrade_page()
|
---|
203 | {
|
---|
204 | if ( ! current_user_can('update_plugins') )
|
---|
205 | wp_die(__('You do not have sufficient permissions to update XPressME Integration Kit for this site.', 'xpressme'));
|
---|
206 | $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-xpress';
|
---|
207 | $upgrade_error = false;
|
---|
208 | if ( 'upgrade-xpress' == $action ) {
|
---|
209 | list_xpress_update();
|
---|
210 | } elseif ( 'do-xpress-upgrade' == $action) {
|
---|
211 | $update_develop = false;
|
---|
212 | do_xpress_upgrade($update_develop);
|
---|
213 | } else if ( 'do-xpress-develop_upgrade' == $action) {
|
---|
214 | $update_develop = true;
|
---|
215 | do_xpress_upgrade($update_develop);
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | function xp_remote_get($url, $headers = ""){
|
---|
220 | global $xoops_config;
|
---|
221 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
222 |
|
---|
223 | require_once( $xoops_config->module_path . '/wp-includes/class-snoopy.php');
|
---|
224 |
|
---|
225 | // Snoopy is an HTTP client in PHP
|
---|
226 | $client = new Snoopy();
|
---|
227 | $client->agent = 'XPressME/' . $xpress_version;
|
---|
228 | $client->read_timeout = 2;
|
---|
229 | if (is_array($headers) ) {
|
---|
230 | $client->rawheaders = $headers;
|
---|
231 | }
|
---|
232 |
|
---|
233 | @$client->fetch($url);
|
---|
234 | $response['response']['code'] = $client->status;
|
---|
235 | $response['body'] = $client->results;
|
---|
236 | return $response;
|
---|
237 | return $client;
|
---|
238 |
|
---|
239 | }
|
---|
240 |
|
---|
241 | function get_xpress_latest_version($check_url=null){
|
---|
242 | global $wp_version, $wpdb, $wp_local_package;
|
---|
243 | global $xoops_config;
|
---|
244 |
|
---|
245 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
246 | $lang = WPLANG;
|
---|
247 | if(is_null($check_url))
|
---|
248 | $check_url = "http://ja.xpressme.info/version_check/index.php?version=$xpress_version&lang=$lang";
|
---|
249 | $request_options = array(
|
---|
250 | 'timeout' => 3,
|
---|
251 | 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
|
---|
252 | );
|
---|
253 |
|
---|
254 | if (! function_exists('wp_remote_get')) {
|
---|
255 | $response = xp_remote_get($check_url);
|
---|
256 |
|
---|
257 | if (empty($response['body'])) return false;
|
---|
258 | } else {
|
---|
259 |
|
---|
260 | $response = wp_remote_get($check_url, $request_options);
|
---|
261 |
|
---|
262 | if ( is_wp_error( $response ) )
|
---|
263 | return false;
|
---|
264 | }
|
---|
265 | if ( 200 != $response['response']['code'] )
|
---|
266 | return false;
|
---|
267 | $body = trim( $response['body'] );
|
---|
268 | $body = str_replace(array("\r\n", "\r"), "\n", $body);
|
---|
269 | $returns = explode("\n", $body);
|
---|
270 |
|
---|
271 | if ( isset( $returns[0] ) ) $response = $returns[0]; else $response = '';
|
---|
272 | if ( isset( $returns[1] ) ) $url = clean_url( $returns[1] ); else $url = '';
|
---|
273 | if ( isset( $returns[2] ) ) $package = clean_url( $returns[2] ); else $package = '';
|
---|
274 | if ( isset( $returns[3] ) ) $latest_version = $returns[3]; else $latest_version = '';
|
---|
275 | if ( isset( $returns[4] ) ) $lang = $returns[4]; else $lang = '';
|
---|
276 |
|
---|
277 | // diff
|
---|
278 | if ( isset( $returns[6] ) ) $diff_response = $returns[6]; else $diff_response = '';
|
---|
279 | if ( isset( $returns[7] ) ) $diff_url = clean_url( $returns[7] ); else $diff_url = '';
|
---|
280 | if ( isset( $returns[8] ) ) $diff_package = clean_url( $returns[8] ); else $diff_package = '';
|
---|
281 | if ( isset( $returns[9] ) ) $diff_latest_version = $returns[9]; else $diff_latest_version = '';
|
---|
282 | if ( isset( $returns[10] ) ) $diff_lang = $returns[10]; else $diff_lang = '';
|
---|
283 |
|
---|
284 | // developer
|
---|
285 | if ( isset( $returns[12] ) ) $develop_response = $returns[12]; else $develop_response = '';
|
---|
286 | if ( isset( $returns[13] ) ) $develop_url = clean_url( $returns[13] ); else $develop_url = '';
|
---|
287 | if ( isset( $returns[14] ) ) $develop_package = clean_url( $returns[14] ); else $develop_package = '';
|
---|
288 | if ( isset( $returns[15] ) ) $develop_latest_version = $returns[15]; else $develop_latest_version = '';
|
---|
289 | if ( isset( $returns[16] ) ) $develop_lang = $returns[16]; else $develop_lang = '';
|
---|
290 |
|
---|
291 | // developer diff
|
---|
292 | if ( isset( $returns[18] ) ) $diff_develop_response = $returns[18]; else $diff_develop_response = '';
|
---|
293 | if ( isset( $returns[19] ) ) $diff_develop_url = clean_url( $returns[19] ); else $diff_develop_url = '';
|
---|
294 | if ( isset( $returns[20] ) ) $diff_develop_package = clean_url( $returns[20] ); else $diff_develop_package = '';
|
---|
295 | if ( isset( $returns[21] ) ) $diff_develop_latest_version = $returns[21]; else $diff_develop_latest_version = '';
|
---|
296 | if ( isset( $returns[22] ) ) $diff_develop_lang = $returns[22]; else $diff_develop_lang = '';
|
---|
297 |
|
---|
298 | $write_options = array (
|
---|
299 | 'response' => $response ,
|
---|
300 | 'url' => $url ,
|
---|
301 | 'package' => $package ,
|
---|
302 | 'latest_version' => $latest_version ,
|
---|
303 | 'lang' => $lang ,
|
---|
304 | 'diff_response' => $diff_response ,
|
---|
305 | 'diff_url' => $diff_url ,
|
---|
306 | 'diff_package' => $diff_package ,
|
---|
307 | 'diff_latest_version' => $diff_latest_version ,
|
---|
308 | 'diff_lang' => $diff_lang ,
|
---|
309 | 'develop_response' => $develop_response ,
|
---|
310 | 'develop_url' => $develop_url ,
|
---|
311 | 'develop_package' => $develop_package ,
|
---|
312 | 'develop_latest_version' => $develop_latest_version ,
|
---|
313 | 'develop_lang' => $develop_lang ,
|
---|
314 | 'diff_develop_response' => $diff_develop_response ,
|
---|
315 | 'diff_develop_url' => $diff_develop_url ,
|
---|
316 | 'diff_develop_package' => $diff_develop_package ,
|
---|
317 | 'diff_develop_latest_version' => $diff_develop_latest_version ,
|
---|
318 | 'diff_develop_lang' => $diff_develop_lang ,
|
---|
319 | 'check_time' => time()
|
---|
320 | );
|
---|
321 |
|
---|
322 | $latest_version = get_option('xpressme_latest_version');
|
---|
323 | if (!$latest_version) {
|
---|
324 | add_option('xpressme_latest_version', $write_options);
|
---|
325 | } else {
|
---|
326 | update_option('xpressme_latest_version', $write_options);
|
---|
327 | }
|
---|
328 | return true;
|
---|
329 | }
|
---|
330 |
|
---|
331 | function xpress_update_check() {
|
---|
332 | if ( defined('WP_INSTALLING') )
|
---|
333 | return;
|
---|
334 | global $pagenow;
|
---|
335 |
|
---|
336 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
337 |
|
---|
338 | if ( 'admin.php' == $pagenow && 'page=upgrade_page' == $php_query_string)
|
---|
339 | return;
|
---|
340 |
|
---|
341 | global $wp_version, $wpdb, $wp_local_package;
|
---|
342 | global $xoops_config;
|
---|
343 |
|
---|
344 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
345 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
346 |
|
---|
347 | $latest = get_option('xpressme_latest_version');
|
---|
348 | if (!$latest ) {
|
---|
349 | get_xpress_latest_version();
|
---|
350 | $latest = get_option('xpressme_latest_version');
|
---|
351 | }
|
---|
352 |
|
---|
353 | if ($latest) {
|
---|
354 | $next_check = $latest['check_time'] + (60*60*24);
|
---|
355 | $now_time = time();
|
---|
356 | if ($next_check < $now_time ){
|
---|
357 | get_xpress_latest_version();
|
---|
358 | $latest = get_option('xpressme_latest_version');
|
---|
359 | }
|
---|
360 | }
|
---|
361 |
|
---|
362 | if ($latest) {
|
---|
363 | $url=$latest['url'];
|
---|
364 | $package=$latest['package'];
|
---|
365 | $latest_version=$latest['latest_version'];
|
---|
366 | $check_time=$latest['check_time'];
|
---|
367 | $upgrade_page = $xoops_config->module_url . "/wp-admin/admin.php?page=upgrade_page";
|
---|
368 |
|
---|
369 | if (version_compare($xpress_version, $latest_version, '<')) {
|
---|
370 | if ( current_user_can('manage_options') ){
|
---|
371 | $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! <a href="%2$s">Please update now</a>.', 'xpressme'), $latest_version, $upgrade_page );
|
---|
372 | } else {
|
---|
373 | $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! Please notify the site administrator.', 'xpressme'), $latest_version );
|
---|
374 | }
|
---|
375 | echo "<div id='update-nag'>$msg </div>";
|
---|
376 | }
|
---|
377 | }
|
---|
378 | }
|
---|
379 | ?> |
---|