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