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:', 'xpressme'), $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:', 'xpressme') . '</strong> <a href="' . esc_url( $update_url ) . '">' . __('Go to Module Update', 'xpressme') . '</a>' );
|
---|
195 | }
|
---|
196 | echo '</div>';
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 |
|
---|
201 |
|
---|
202 | function upgrade_page()
|
---|
203 | {
|
---|
204 | $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-xpress';
|
---|
205 | $upgrade_error = false;
|
---|
206 | if ( 'upgrade-xpress' == $action ) {
|
---|
207 | list_xpress_update();
|
---|
208 | } elseif ( 'do-xpress-upgrade' == $action) {
|
---|
209 | $update_develop = false;
|
---|
210 | do_xpress_upgrade($update_develop);
|
---|
211 | } else if ( 'do-xpress-develop_upgrade' == $action) {
|
---|
212 | $update_develop = true;
|
---|
213 | do_xpress_upgrade($update_develop);
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | function xp_remote_get($url, $headers = ""){
|
---|
218 | global $xoops_config;
|
---|
219 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
220 |
|
---|
221 | require_once( $xoops_config->module_path . '/wp-includes/class-snoopy.php');
|
---|
222 |
|
---|
223 | // Snoopy is an HTTP client in PHP
|
---|
224 | $client = new Snoopy();
|
---|
225 | $client->agent = 'XPressME/' . $xpress_version;
|
---|
226 | $client->read_timeout = 2;
|
---|
227 | if (is_array($headers) ) {
|
---|
228 | $client->rawheaders = $headers;
|
---|
229 | }
|
---|
230 |
|
---|
231 | @$client->fetch($url);
|
---|
232 | $response['response']['code'] = $client->status;
|
---|
233 | $response['body'] = $client->results;
|
---|
234 | return $response;
|
---|
235 | return $client;
|
---|
236 |
|
---|
237 | }
|
---|
238 |
|
---|
239 | function get_xpress_latest_version($check_url=null){
|
---|
240 | global $wp_version, $wpdb, $wp_local_package;
|
---|
241 | global $xoops_config;
|
---|
242 |
|
---|
243 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
244 | $lang = WPLANG;
|
---|
245 | if(is_null($check_url))
|
---|
246 | $check_url = "http://ja.xpressme.info/version_check/index.php?version=$xpress_version&lang=$lang";
|
---|
247 | $request_options = array(
|
---|
248 | 'timeout' => 3,
|
---|
249 | 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
|
---|
250 | );
|
---|
251 |
|
---|
252 | if (! function_exists('wp_remote_get')) {
|
---|
253 | $response = xp_remote_get($check_url);
|
---|
254 |
|
---|
255 | if (empty($response['body'])) return false;
|
---|
256 | } else {
|
---|
257 |
|
---|
258 | $response = wp_remote_get($check_url, $request_options);
|
---|
259 |
|
---|
260 | if ( is_wp_error( $response ) )
|
---|
261 | return false;
|
---|
262 | }
|
---|
263 | if ( 200 != $response['response']['code'] )
|
---|
264 | return false;
|
---|
265 | $body = trim( $response['body'] );
|
---|
266 | $body = str_replace(array("\r\n", "\r"), "\n", $body);
|
---|
267 | $returns = explode("\n", $body);
|
---|
268 |
|
---|
269 | if ( isset( $returns[0] ) ) $response = $returns[0]; else $response = '';
|
---|
270 | if ( isset( $returns[1] ) ) $url = clean_url( $returns[1] ); else $url = '';
|
---|
271 | if ( isset( $returns[2] ) ) $package = clean_url( $returns[2] ); else $package = '';
|
---|
272 | if ( isset( $returns[3] ) ) $latest_version = $returns[3]; else $latest_version = '';
|
---|
273 | if ( isset( $returns[4] ) ) $lang = $returns[4]; else $lang = '';
|
---|
274 |
|
---|
275 | // diff
|
---|
276 | if ( isset( $returns[6] ) ) $diff_response = $returns[6]; else $diff_response = '';
|
---|
277 | if ( isset( $returns[7] ) ) $diff_url = clean_url( $returns[7] ); else $diff_url = '';
|
---|
278 | if ( isset( $returns[8] ) ) $diff_package = clean_url( $returns[8] ); else $diff_package = '';
|
---|
279 | if ( isset( $returns[9] ) ) $diff_latest_version = $returns[9]; else $diff_latest_version = '';
|
---|
280 | if ( isset( $returns[10] ) ) $diff_lang = $returns[10]; else $diff_lang = '';
|
---|
281 |
|
---|
282 | // developer
|
---|
283 | if ( isset( $returns[12] ) ) $develop_response = $returns[12]; else $develop_response = '';
|
---|
284 | if ( isset( $returns[13] ) ) $develop_url = clean_url( $returns[13] ); else $develop_url = '';
|
---|
285 | if ( isset( $returns[14] ) ) $develop_package = clean_url( $returns[14] ); else $develop_package = '';
|
---|
286 | if ( isset( $returns[15] ) ) $develop_latest_version = $returns[15]; else $develop_latest_version = '';
|
---|
287 | if ( isset( $returns[16] ) ) $develop_lang = $returns[16]; else $develop_lang = '';
|
---|
288 |
|
---|
289 | // developer diff
|
---|
290 | if ( isset( $returns[18] ) ) $diff_develop_response = $returns[18]; else $diff_develop_response = '';
|
---|
291 | if ( isset( $returns[19] ) ) $diff_develop_url = clean_url( $returns[19] ); else $diff_develop_url = '';
|
---|
292 | if ( isset( $returns[20] ) ) $diff_develop_package = clean_url( $returns[20] ); else $diff_develop_package = '';
|
---|
293 | if ( isset( $returns[21] ) ) $diff_develop_latest_version = $returns[21]; else $diff_develop_latest_version = '';
|
---|
294 | if ( isset( $returns[22] ) ) $diff_develop_lang = $returns[22]; else $diff_develop_lang = '';
|
---|
295 |
|
---|
296 | $write_options = array (
|
---|
297 | 'response' => $response ,
|
---|
298 | 'url' => $url ,
|
---|
299 | 'package' => $package ,
|
---|
300 | 'latest_version' => $latest_version ,
|
---|
301 | 'lang' => $lang ,
|
---|
302 | 'diff_response' => $diff_response ,
|
---|
303 | 'diff_url' => $diff_url ,
|
---|
304 | 'diff_package' => $diff_package ,
|
---|
305 | 'diff_latest_version' => $diff_latest_version ,
|
---|
306 | 'diff_lang' => $diff_lang ,
|
---|
307 | 'develop_response' => $develop_response ,
|
---|
308 | 'develop_url' => $develop_url ,
|
---|
309 | 'develop_package' => $develop_package ,
|
---|
310 | 'develop_latest_version' => $develop_latest_version ,
|
---|
311 | 'develop_lang' => $develop_lang ,
|
---|
312 | 'diff_develop_response' => $diff_develop_response ,
|
---|
313 | 'diff_develop_url' => $diff_develop_url ,
|
---|
314 | 'diff_develop_package' => $diff_develop_package ,
|
---|
315 | 'diff_develop_latest_version' => $diff_develop_latest_version ,
|
---|
316 | 'diff_develop_lang' => $diff_develop_lang ,
|
---|
317 | 'check_time' => time()
|
---|
318 | );
|
---|
319 |
|
---|
320 | $latest_version = get_option('xpressme_latest_version');
|
---|
321 | if (!$latest_version) {
|
---|
322 | add_option('xpressme_latest_version', $write_options);
|
---|
323 | } else {
|
---|
324 | update_option('xpressme_latest_version', $write_options);
|
---|
325 | }
|
---|
326 | return true;
|
---|
327 | }
|
---|
328 |
|
---|
329 | function xpress_update_check() {
|
---|
330 | if ( defined('WP_INSTALLING') )
|
---|
331 | return;
|
---|
332 | global $pagenow;
|
---|
333 |
|
---|
334 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
335 |
|
---|
336 | if ( 'admin.php' == $pagenow && 'page=upgrade_page' == $php_query_string)
|
---|
337 | return;
|
---|
338 |
|
---|
339 | global $wp_version, $wpdb, $wp_local_package;
|
---|
340 | global $xoops_config;
|
---|
341 |
|
---|
342 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
343 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
344 |
|
---|
345 | $latest = get_option('xpressme_latest_version');
|
---|
346 | if (!$latest ) {
|
---|
347 | get_xpress_latest_version();
|
---|
348 | $latest = get_option('xpressme_latest_version');
|
---|
349 | }
|
---|
350 |
|
---|
351 | if ($latest) {
|
---|
352 | $next_check = $latest['check_time'] + (60*60*24);
|
---|
353 | $now_time = time();
|
---|
354 | if ($next_check < $now_time ){
|
---|
355 | get_xpress_latest_version();
|
---|
356 | $latest = get_option('xpressme_latest_version');
|
---|
357 | }
|
---|
358 | }
|
---|
359 |
|
---|
360 | if ($latest) {
|
---|
361 | $url=$latest['url'];
|
---|
362 | $package=$latest['package'];
|
---|
363 | $latest_version=$latest['latest_version'];
|
---|
364 | $check_time=$latest['check_time'];
|
---|
365 | $upgrade_page = $xoops_config->module_url . "/wp-admin/admin.php?page=upgrade_page";
|
---|
366 |
|
---|
367 | if (version_compare($xpress_version, $latest_version, '<')) {
|
---|
368 | if ( current_user_can('manage_options') ){
|
---|
369 | $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! <a href="%2$s">Please update now</a>.', 'xpressme'), $latest_version, $upgrade_page );
|
---|
370 | } else {
|
---|
371 | $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! Please notify the site administrator.', 'xpressme'), $latest_version );
|
---|
372 | }
|
---|
373 | echo "<div id='update-nag'>$msg </div>";
|
---|
374 | }
|
---|
375 | }
|
---|
376 | }
|
---|
377 | ?> |
---|