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