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