[18] | 1 | <?php
|
---|
| 2 | /*
|
---|
| 3 | Plugin Name: Plugin for XPressME
|
---|
[193] | 4 | Plugin URI: http://ja.xpressme.info
|
---|
[18] | 5 | Description: Plugin for XPressME (custom function,filter,action)
|
---|
| 6 | Author: toemon
|
---|
[193] | 7 | Version: 1.0
|
---|
| 8 | Author URI: http://ja.xpressme.info
|
---|
[18] | 9 | */
|
---|
[19] | 10 | require_once('xpressme_class.php');
|
---|
[75] | 11 |
|
---|
[95] | 12 | require_once dirname( __FILE__ ).'/include/custom_functions.php' ; // XPressME functions for themes
|
---|
| 13 | require_once dirname( __FILE__ ).'/include/xpress_common_functions.php' ;
|
---|
[46] | 14 |
|
---|
| 15 | $xoops_db = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
|
---|
| 16 | $xoops_db->prefix = get_xoops_prefix();
|
---|
| 17 | $xoops_db->tables = array('modules', 'newblocks', 'users');
|
---|
| 18 |
|
---|
[144] | 19 | $xpress_config = new XPressME_Class();
|
---|
[83] | 20 |
|
---|
| 21 | require_once dirname( __FILE__ ).'/include/pluggable-override.php' ;
|
---|
[360] | 22 | require_once dirname( __FILE__ ).'/include/functions_for_wp_old.php' ;
|
---|
[83] | 23 |
|
---|
[302] | 24 | function my_plugin_menu()
|
---|
| 25 | {
|
---|
[328] | 26 | global $xpress_config,$xoops_config;
|
---|
| 27 |
|
---|
[311] | 28 | $plugin_url = WP_PLUGIN_URL."/xpressme/";
|
---|
| 29 |
|
---|
[328] | 30 | // Add a new top-level menu:
|
---|
| 31 | add_menu_page('XPressME','XPressME', 8, __FILE__, 'display_option_page' , $plugin_url.'/images/menu_icon.png');
|
---|
| 32 | // Add submenus to the custom top-level menu:
|
---|
| 33 | add_submenu_page(__FILE__, __('Display Settings', 'xpressme'), __('Display Settings', 'xpressme'), 8, __FILE__, 'display_option_page');
|
---|
| 34 | add_submenu_page(__FILE__, __('Integration Settings', 'xpressme'), __('Integration Settings', 'xpressme'), 8, 'integration_option_page', 'integration_option_page');
|
---|
| 35 | add_submenu_page(__FILE__, __('Other Settings', 'xpressme'), __('Other Settings', 'xpressme'), 8, 'other_option_page', 'other_option_page');
|
---|
[370] | 36 | // if (function_exists('wp_remote_get'))
|
---|
[368] | 37 | add_submenu_page(__FILE__, __('Upgrade', 'xpressme'), __('Upgrade', 'xpressme'), 8, 'upgrade_page', 'upgrade_page');
|
---|
[380] | 38 | add_submenu_page(__FILE__, __('to Modules Admin', 'xpressme'), __('to Modules Admin', 'xpressme'), 8, 'redirect_xoops_admin', 'redirect_xoops_admin');
|
---|
[302] | 39 | }
|
---|
| 40 | add_action('admin_menu', 'my_plugin_menu');
|
---|
| 41 |
|
---|
[144] | 42 | add_filter("upload_dir",array(&$xpress_config, 'xpress_upload_filter'), 1); // Change wp-include/wp_upload_dir()
|
---|
| 43 | if (!$xpress_config->is_save_post_revision){
|
---|
[28] | 44 | remove_action( 'pre_post_update', 'wp_save_post_revision' ); // Not Save Post Revision
|
---|
| 45 | }
|
---|
[145] | 46 | add_action("wp_meta" , "wp_meta_add_xpress_menu"); // add xpress menu in wp_meta
|
---|
[182] | 47 |
|
---|
| 48 | //Site URL check
|
---|
| 49 | add_filter('option_home', "safe_site_url_filter");
|
---|
| 50 | add_filter('option_siteurl', "safe_site_url_filter");
|
---|
| 51 |
|
---|
[96] | 52 |
|
---|
| 53 | //XOOPS Bloack Cache Refresh
|
---|
[46] | 54 | add_action("comment_post", "block_cache_refresh");
|
---|
| 55 | add_action("edit_comment", "block_cache_refresh");
|
---|
[96] | 56 | add_action("wp_set_comment_status","block_cache_refresh"); //wp_delete_comment() at deleted
|
---|
| 57 | add_action("deleted_post", "block_cache_refresh");
|
---|
[46] | 58 | add_action("publish_post", "block_cache_refresh");
|
---|
| 59 | add_action("edit_post", "block_cache_refresh");
|
---|
| 60 | add_action("private_to_published", "block_cache_refresh");
|
---|
[96] | 61 | add_action("transition_post_status", "block_cache_refresh");
|
---|
[46] | 62 |
|
---|
[51] | 63 | add_action("the_content", "set_post_views_count");
|
---|
| 64 |
|
---|
[61] | 65 | //XOOPS notifiction
|
---|
| 66 | require_once dirname( __FILE__ ).'/include/notify_functions.php' ;
|
---|
[91] | 67 | add_action("transition_post_status", "onaction_publish_post_notify" ,10 , 3);
|
---|
[61] | 68 | // add_action("edit_post", "onaction_edit_post_notify");
|
---|
| 69 | add_action("comment_post", "onaction_comment_notify");
|
---|
| 70 | // add_action("approve_comment" , "onaction_comment_apobe_notify");
|
---|
| 71 | add_action("wp_set_comment_status" , "onaction_comment_apobe_notify");
|
---|
[51] | 72 |
|
---|
[72] | 73 | // user data sync user_sync_to_xoops($user_id)
|
---|
| 74 | require_once dirname( __FILE__ ).'/include/user_sync_xoops.php' ;
|
---|
| 75 | add_action('profile_update', 'user_sync_to_xoops');
|
---|
| 76 | add_action('user_register', 'user_sync_to_xoops');
|
---|
[32] | 77 | //require_once('../include/custom_functions.php');
|
---|
[88] | 78 |
|
---|
[104] | 79 | //D3Forum Comment Integration
|
---|
[144] | 80 | if ($xpress_config->is_use_d3forum){
|
---|
[104] | 81 | require_once dirname( __FILE__ ).'/include/d3forum_comment_synchro.php' ;
|
---|
| 82 | add_action("comment_post", "onaction_comment_post");
|
---|
| 83 | add_action("edit_comment", "onaction_edit_comment");
|
---|
| 84 | add_action("delete_comment","onaction_delete_comment");
|
---|
| 85 | add_action("delete_post", "onaction_delete_post");
|
---|
| 86 | add_action("wp_set_comment_status" , "onaction_comment_apobe");
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | add_filter('comments_template', "disp_d3forum_comments" );
|
---|
| 90 |
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[155] | 93 |
|
---|
| 94 |
|
---|
[147] | 95 | //The trackback and the pingback are excluded from the count of the comment.
|
---|
| 96 | add_filter('get_comments_number', 'xpress_comment_count', 0);
|
---|
[104] | 97 |
|
---|
[155] | 98 | // Query filter for MultiUser
|
---|
| 99 | add_filter('query','xpress_query_filter');
|
---|
[236] | 100 | //add_action("init", "xpress_set_author_cookie");
|
---|
[360] | 101 | if(xpress_is_wp_version('<','2.1')){
|
---|
[281] | 102 | // It is called before parse_request() makes $GET.
|
---|
| 103 | add_action("query_vars", "xpress_set_author_cookie");
|
---|
| 104 | } else {
|
---|
| 105 | // It is called at the end of parse_request().
|
---|
| 106 | add_filter('request', 'xpress_set_author_cookie');
|
---|
| 107 | }
|
---|
[155] | 108 |
|
---|
[88] | 109 | // SQL debug windows
|
---|
[144] | 110 | add_filter('query', array(&$xpress_config, 'xpress_sql_debug'));
|
---|
| 111 | add_action('admin_footer', array(&$xpress_config, 'displayDebugLog'));
|
---|
[280] | 112 | add_action('wp_footer', array(&$xpress_config, 'displayDebugLog'));
|
---|
| 113 |
|
---|
[349] | 114 | function redirect_xoops_admin()
|
---|
| 115 | {
|
---|
| 116 | global $xoops_config,$xpress_config;
|
---|
| 117 | $xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
|
---|
| 118 | wp_redirect($xoops_admin_url);
|
---|
| 119 | }
|
---|
[328] | 120 |
|
---|
| 121 | function display_option_page()
|
---|
| 122 | {
|
---|
| 123 | global $xoops_config,$xpress_config;
|
---|
| 124 |
|
---|
| 125 | $xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
|
---|
| 126 |
|
---|
| 127 | $do_message ='';
|
---|
| 128 | if (!empty($_POST['submit_update'])) {
|
---|
| 129 | $xpress_config->ReadPostData($_POST);
|
---|
| 130 | $xpress_config->SettingValueWrite('update');
|
---|
| 131 | } else if (isset($_POST['submit_reset'])) {
|
---|
| 132 | $xpress_config->setDefault();
|
---|
| 133 | $xpress_config->SettingValueWrite('update');
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | echo '<div class="wrap">'."\n";
|
---|
| 137 | echo '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
|
---|
[332] | 138 | echo '<h2>' . __('XPressME Display Setting', 'xpressme') . "</h2><br>\n";
|
---|
[349] | 139 | // echo '<div align="right"><a href="' . $xoops_admin_url . '"><h3>'. __('to XOOPS Modules Admin Page', 'xpressme') . '</h3></a></div>';
|
---|
[328] | 140 | echo '<form method="post" action="' . $_SERVER["REQUEST_URI"] . '">'."\n" ;
|
---|
| 141 | echo '<table class="form-table">'."\n";
|
---|
| 142 | echo $xpress_config->viewer_type_option();
|
---|
| 143 | echo $xpress_config->yes_no_radio_option('is_theme_sidebar_disp',
|
---|
| 144 | __('Thema Sidebar Display','xpressme'),
|
---|
| 145 | __('YES','xpressme'),
|
---|
| 146 | __('NO','xpressme')
|
---|
| 147 | );
|
---|
| 148 | echo $xpress_config->single_post_navi_option();
|
---|
| 149 | echo $xpress_config->posts_page_navi_option();
|
---|
| 150 | echo $xpress_config->excerpt_option();
|
---|
| 151 | echo "</table>\n";
|
---|
| 152 |
|
---|
| 153 | echo '<p class="submit">'."\n";
|
---|
| 154 | echo '<input type="submit" value= "' . __('Update Config', 'xpressme') . '" name="submit_update" />' ."\n";
|
---|
| 155 | echo '<input type="submit" value= "' . __('Preset Config', 'xpressme') . '" name="submit_reset" />' ."\n";
|
---|
| 156 | echo "</p>\n";
|
---|
| 157 |
|
---|
| 158 | echo "</form>\n" ;
|
---|
| 159 | echo "</div>\n";
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | function integration_option_page()
|
---|
| 163 | {
|
---|
| 164 | global $xoops_config,$xpress_config;
|
---|
| 165 |
|
---|
| 166 | $xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
|
---|
| 167 |
|
---|
| 168 | $do_message ='';
|
---|
| 169 | if (!empty($_POST['submit_update'])) {
|
---|
| 170 | $xpress_config->ReadPostData($_POST);
|
---|
| 171 | $xpress_config->SettingValueWrite('update');
|
---|
| 172 | } else if (isset($_POST['submit_reset'])) {
|
---|
| 173 | $xpress_config->setDefault();
|
---|
| 174 | $xpress_config->SettingValueWrite('update');
|
---|
| 175 | } else if (isset($_POST['export_d3f'])) {
|
---|
| 176 | $do_message = 'export(' . $xpress_config->d3forum_module_dir . '--ID=' . $xpress_config->d3forum_forum_id . ')................';
|
---|
| 177 | $do_message .= wp_to_d3forum($xpress_config->d3forum_forum_id, $xpress_config->d3forum_module_dir);
|
---|
| 178 | $do_message .= '....END';
|
---|
| 179 | } else if (isset($_POST['inport_d3f'])) {
|
---|
| 180 | $do_message = 'Import(' . $xpress_config->d3forum_module_dir . '--ID=' . $xpress_config->d3forum_forum_id . ')................';
|
---|
| 181 | $do_message .= d3forum_to_wp($xpress_config->d3forum_forum_id, $xpress_config->d3forum_module_dir);
|
---|
| 182 | $do_message .= '....END';
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | echo '<div class="wrap">'."\n";
|
---|
| 186 | echo '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
|
---|
[332] | 187 | echo '<h2>' . __('XPressME Integration Setting', 'xpressme') . "</h2><br>\n";
|
---|
[349] | 188 | // echo '<div align="right"><a href="' . $xoops_admin_url . '"><h3>'. __('to XOOPS Modules Admin Page', 'xpressme') . '</h3></a></div>';
|
---|
[328] | 189 | echo '<form method="post" action="' . $_SERVER["REQUEST_URI"] . '">'."\n" ;
|
---|
| 190 | echo '<table class="form-table">'."\n";
|
---|
[402] | 191 | $upload_title = __('Media Upload Base Path','xpressme');
|
---|
| 192 | if($xoops_config->is_wpmu) $upload_title = $upload_title . '(WPMU is not select)';
|
---|
[328] | 193 | echo $xpress_config->yes_no_radio_option('is_use_xoops_upload_path',
|
---|
[402] | 194 | $upload_title,
|
---|
[328] | 195 | __('Use XOOPS UPLOAD PATH','xpressme'),
|
---|
[402] | 196 | __('USE WordPress BASE_PATH','xpressme'),
|
---|
| 197 | $xoops_config->is_wpmu
|
---|
[328] | 198 | );
|
---|
[404] | 199 | $lock = ($xoops_config->module_url != get_bloginfo('url'));
|
---|
| 200 | echo $xpress_config->groupe_role_option($lock);
|
---|
[328] | 201 | echo $xpress_config->d3forum_option($do_message);
|
---|
| 202 | echo "</table>\n";
|
---|
| 203 |
|
---|
| 204 | echo '<p class="submit">'."\n";
|
---|
| 205 | echo '<input type="submit" value= "' . __('Update Config', 'xpressme') . '" name="submit_update" />' ."\n";
|
---|
| 206 | echo '<input type="submit" value= "' . __('Preset Config', 'xpressme') . '" name="submit_reset" />' ."\n";
|
---|
| 207 | echo "</p>\n";
|
---|
| 208 |
|
---|
| 209 | echo "</form>\n" ;
|
---|
| 210 | echo "</div>\n";
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | function other_option_page()
|
---|
| 214 | {
|
---|
| 215 | global $xoops_config,$xpress_config;
|
---|
| 216 |
|
---|
| 217 | $xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
|
---|
| 218 |
|
---|
| 219 | $do_message ='';
|
---|
| 220 | if (!empty($_POST['submit_update'])) {
|
---|
| 221 | $xpress_config->ReadPostData($_POST);
|
---|
| 222 | $xpress_config->SettingValueWrite('update');
|
---|
| 223 | } else if (isset($_POST['submit_reset'])) {
|
---|
| 224 | $xpress_config->setDefault();
|
---|
| 225 | $xpress_config->SettingValueWrite('update');
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | echo '<div class="wrap">'."\n";
|
---|
| 229 | echo '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
|
---|
[332] | 230 | echo '<h2>' . __('XPressME Other Setting', 'xpressme') . "</h2><br>\n";
|
---|
[349] | 231 | // echo '<div align="right"><a href="' . $xoops_admin_url . '"><h3>'. __('to XOOPS Modules Admin Page', 'xpressme') . '</h3></a></div>';
|
---|
[328] | 232 | echo '<form method="post" action="' . $_SERVER["REQUEST_URI"] . '">'."\n" ;
|
---|
| 233 | echo '<table class="form-table">'."\n";
|
---|
| 234 | echo $xpress_config->yes_no_radio_option('is_save_post_revision',
|
---|
| 235 | __('The change tracking of the post is preserved','xpressme'),
|
---|
| 236 | __('YES','xpressme'),
|
---|
| 237 | __('NO','xpressme')
|
---|
| 238 | );
|
---|
| 239 |
|
---|
| 240 | echo $xpress_config->yes_no_radio_option('is_multi_user',
|
---|
| 241 | __('Select Multi user mode','xpressme'),
|
---|
| 242 | __('YES','xpressme'),
|
---|
| 243 | __('NO','xpressme')
|
---|
| 244 | );
|
---|
| 245 | echo $xpress_config->yes_no_radio_option('is_author_view_count',
|
---|
| 246 | __('Is the posts author views counted?','xpressme'),
|
---|
| 247 | __('YES','xpressme'),
|
---|
| 248 | __('NO','xpressme')
|
---|
| 249 | );
|
---|
| 250 | echo $xpress_config->header_meta_option();
|
---|
| 251 | echo $xpress_config->yes_no_radio_option('is_sql_debug',
|
---|
| 252 | __('Is SQL debugging window displayed?','xpressme'),
|
---|
| 253 | __('YES','xpressme'),
|
---|
| 254 | __('NO','xpressme')
|
---|
| 255 | );
|
---|
| 256 | echo "</table>\n";
|
---|
| 257 |
|
---|
| 258 | echo '<p class="submit">'."\n";
|
---|
| 259 | echo '<input type="submit" value= "' . __('Update Config', 'xpressme') . '" name="submit_update" />' ."\n";
|
---|
| 260 | echo '<input type="submit" value= "' . __('Preset Config', 'xpressme') . '" name="submit_reset" />' ."\n";
|
---|
| 261 | echo "</p>\n";
|
---|
| 262 |
|
---|
| 263 | echo "</form>\n" ;
|
---|
| 264 | echo "</div>\n";
|
---|
| 265 | }
|
---|
| 266 |
|
---|
[368] | 267 | function upgrade_page()
|
---|
| 268 | {
|
---|
| 269 | global $xoops_config,$xpress_config;
|
---|
| 270 |
|
---|
| 271 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
| 272 | $check_url = "http://ja1.xpressme.info/version_check/?version=$xpress_version";
|
---|
| 273 |
|
---|
| 274 | echo '<div class="wrap">'."\n";
|
---|
| 275 | echo '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
|
---|
| 276 | echo '<h2>' . __('XPressME Upgrade', 'xpressme') . "</h2><br>\n";
|
---|
| 277 |
|
---|
| 278 | if(get_xpress_latest_version()){
|
---|
| 279 | $latest = get_option('xpressme_latest_version');
|
---|
| 280 | if ($latest) {
|
---|
| 281 | $site_url=$latest['url'];
|
---|
| 282 | $package=$latest['package'];
|
---|
| 283 | $latest_version=$latest['latest_version'];
|
---|
| 284 | $check_time=$latest['check_time'];
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | if (version_compare($xpress_version, $latest_version, '>')){
|
---|
| 289 | echo '<h3 class="response">';
|
---|
| 290 | printf(__('You are using a XPressME Integration Kit development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.', 'xpressme') , $xpress_version , $site_url);
|
---|
| 291 | echo '</h3>';
|
---|
| 292 |
|
---|
| 293 | } else if (version_compare($xpress_version, $latest_version, '<')) {
|
---|
| 294 | echo '<h3 class="response">'. __('There is a new version of XPressME Integration Kit available for upgrade', 'xpressme') . '</h3>';
|
---|
| 295 | echo '<p>';
|
---|
| 296 | // printf(__('You can upgrade to version %s automatically or download the package and install it manually:'),$latest_version);
|
---|
| 297 | printf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version);
|
---|
| 298 | echo '</p>';
|
---|
| 299 | echo '<a class="button" href="' . $package . '">';
|
---|
| 300 | printf(__('Download %s', 'xpressme') , $latest_version);
|
---|
| 301 | echo '</a>';
|
---|
| 302 | } else {
|
---|
| 303 | echo '<h3 class="response">'. __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme') . '</h3>';
|
---|
| 304 | }
|
---|
| 305 | } else {
|
---|
| 306 | echo '<h3 class="response">';
|
---|
| 307 | printf(__('There is no response from <a href="%s">version check API</a> now. sorry, please confirm it after.', 'xpressme'),$check_url);
|
---|
| 308 | echo "</div>\n";
|
---|
| 309 | }
|
---|
| 310 | }
|
---|
| 311 |
|
---|
[370] | 312 | function xp_remote_get($url, $headers = ""){
|
---|
| 313 | global $xoops_config;
|
---|
| 314 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
| 315 |
|
---|
| 316 | require_once( $xoops_config->module_path . '/wp-includes/class-snoopy.php');
|
---|
| 317 |
|
---|
| 318 | // Snoopy is an HTTP client in PHP
|
---|
| 319 | $client = new Snoopy();
|
---|
| 320 | $client->agent = 'XPressME/' . $xpress_version;
|
---|
| 321 | $client->read_timeout = 2;
|
---|
| 322 | if (is_array($headers) ) {
|
---|
| 323 | $client->rawheaders = $headers;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | @$client->fetch($url);
|
---|
| 327 | $response['response']['code'] = $client->status;
|
---|
| 328 | $response['body'] = $client->results;
|
---|
| 329 | return $response;
|
---|
| 330 | return $client;
|
---|
| 331 |
|
---|
| 332 | }
|
---|
| 333 |
|
---|
[368] | 334 | function get_xpress_latest_version(){
|
---|
| 335 | global $wp_version, $wpdb, $wp_local_package;
|
---|
| 336 | global $xoops_config;
|
---|
| 337 |
|
---|
| 338 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
| 339 |
|
---|
| 340 | $check_url = "http://ja.xpressme.info/version_check/?version=$xpress_version";
|
---|
| 341 | $request_options = array(
|
---|
| 342 | 'timeout' => 3,
|
---|
| 343 | 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
|
---|
| 344 | );
|
---|
| 345 |
|
---|
[370] | 346 | if (! function_exists('wp_remote_get')) {
|
---|
| 347 | $response = xp_remote_get($check_url);
|
---|
| 348 |
|
---|
| 349 | if (empty($response['body'])) return false;
|
---|
| 350 | } else {
|
---|
[368] | 351 |
|
---|
[370] | 352 | $response = wp_remote_get($check_url, $request_options);
|
---|
| 353 |
|
---|
| 354 | if ( is_wp_error( $response ) )
|
---|
| 355 | return false;
|
---|
| 356 | }
|
---|
[368] | 357 | if ( 200 != $response['response']['code'] )
|
---|
| 358 | return false;
|
---|
| 359 | $body = trim( $response['body'] );
|
---|
| 360 | $body = str_replace(array("\r\n", "\r"), "\n", $body);
|
---|
| 361 | $returns = explode("\n", $body);
|
---|
[370] | 362 | $response = $returns[0];
|
---|
[368] | 363 | if ( isset( $returns[1] ) )
|
---|
[370] | 364 | $url = clean_url( $returns[1] );
|
---|
[368] | 365 | if ( isset( $returns[2] ) )
|
---|
[370] | 366 | $package = clean_url( $returns[2] );
|
---|
[368] | 367 | if ( isset( $returns[3] ) )
|
---|
[370] | 368 | $latest_version = $returns[3];
|
---|
[368] | 369 |
|
---|
| 370 | $write_options = array (
|
---|
| 371 | 'url' => $url ,
|
---|
| 372 | 'package' => $package ,
|
---|
| 373 | 'latest_version' => $latest_version ,
|
---|
| 374 | 'check_time' => time()
|
---|
| 375 | );
|
---|
| 376 |
|
---|
| 377 | $latest_version = get_option('xpressme_latest_version');
|
---|
| 378 | if (!$latest_version) {
|
---|
| 379 | add_option('xpressme_latest_version', $write_options);
|
---|
| 380 | } else {
|
---|
| 381 | update_option('xpressme_latest_version', $write_options);
|
---|
| 382 | }
|
---|
| 383 | return true;
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 | function xpress_update_check() {
|
---|
| 387 | if ( defined('WP_INSTALLING') )
|
---|
| 388 | return;
|
---|
| 389 | global $pagenow;
|
---|
| 390 |
|
---|
| 391 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
| 392 |
|
---|
| 393 | if ( 'admin.php' == $pagenow && 'page=upgrade_page' == $php_query_string)
|
---|
| 394 | return;
|
---|
| 395 |
|
---|
| 396 | global $wp_version, $wpdb, $wp_local_package;
|
---|
| 397 | global $xoops_config;
|
---|
| 398 |
|
---|
| 399 | $php_query_string = $_SERVER['QUERY_STRING'];
|
---|
| 400 | $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
|
---|
| 401 |
|
---|
| 402 | $latest = get_option('xpressme_latest_version');
|
---|
| 403 | if (!$latest ) {
|
---|
| 404 | get_xpress_latest_version();
|
---|
| 405 | $latest = get_option('xpressme_latest_version');
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | if ($latest) {
|
---|
| 409 | $next_check = $latest['check_time'] + (60*60*24);
|
---|
| 410 | $now_time = time();
|
---|
| 411 | if ($next_check < $now_time ){
|
---|
| 412 | get_xpress_latest_version();
|
---|
| 413 | $latest = get_option('xpressme_latest_version');
|
---|
| 414 | }
|
---|
| 415 | }
|
---|
| 416 |
|
---|
| 417 | if ($latest) {
|
---|
| 418 | $url=$latest['url'];
|
---|
| 419 | $package=$latest['package'];
|
---|
| 420 | $latest_version=$latest['latest_version'];
|
---|
| 421 | $check_time=$latest['check_time'];
|
---|
| 422 | $upgrade_page = $xoops_config->module_url . "/wp-admin/admin.php?page=upgrade_page";
|
---|
| 423 |
|
---|
| 424 | if (version_compare($xpress_version, $latest_version, '<')) {
|
---|
| 425 | if ( current_user_can('manage_options') ){
|
---|
| 426 | $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! <a href="%2$s">Please update now</a>.', 'xpressme'), $latest_version, $upgrade_page );
|
---|
| 427 | } else {
|
---|
| 428 | $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! Please notify the site administrator.', 'xpressme'), $latest_version );
|
---|
| 429 | }
|
---|
| 430 | echo "<div id='update-nag'>$msg </div>";
|
---|
| 431 | }
|
---|
| 432 | }
|
---|
| 433 | }
|
---|
| 434 |
|
---|
| 435 | add_action( 'admin_notices', 'xpress_update_check', 3 );
|
---|
[18] | 436 | ?> |
---|