[95] | 1 | <?php
|
---|
[99] | 2 | global $xoops_config;
|
---|
| 3 | if (!is_object($xoops_config)){ // is call other modules
|
---|
[133] | 4 | require_once dirname(dirname(dirname(dirname(dirname( __FILE__ ))))) .'/class/config_from_xoops.class.php' ;
|
---|
[99] | 5 | $xoops_config = new ConfigFromXoops;
|
---|
| 6 | }
|
---|
| 7 |
|
---|
[549] | 8 | $dummy = __('After Blog address (URL) is set, it is necessary to set the permalink again.','xpressme');
|
---|
| 9 | $dummy = __('Can not access WordPress address (URL).','xpressme');
|
---|
| 10 | $dummy = __('WordPress Blog address (URL) is different from access URL.','xpressme');
|
---|
| 11 |
|
---|
| 12 |
|
---|
[104] | 13 | function get_xoops_config($config_name,$module_dir){
|
---|
| 14 | global $xoops_db;
|
---|
| 15 |
|
---|
| 16 | $modules_db = get_xoops_prefix() . 'modules';
|
---|
| 17 | $config_db = get_xoops_prefix() . 'config';
|
---|
| 18 |
|
---|
| 19 | $moduleID = $xoops_db->get_var("SELECT mid FROM $modules_db WHERE dirname = '$module_dir'");
|
---|
| 20 | if (empty($moduleID)) return null;
|
---|
| 21 | $conf_value = $xoops_db->get_var("SELECT conf_value FROM $config_db WHERE (conf_modid = $moduleID) AND (conf_name = '$config_name')");
|
---|
| 22 | if (empty($conf_value)) return null;
|
---|
| 23 | return $conf_value;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[95] | 26 | // xoops db
|
---|
| 27 | function get_xpress_dir_path()
|
---|
| 28 | {
|
---|
| 29 | return ABSPATH;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | function get_xpress_dir_name()
|
---|
| 33 | {
|
---|
| 34 | return basename(ABSPATH);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | function get_wp_prefix_only()
|
---|
| 38 | {
|
---|
| 39 | $dir_name = get_xpress_dir_name();
|
---|
| 40 | $prefix = $dir_name;
|
---|
| 41 | if ($prefix == 'wordpress') $prefix = 'wp';
|
---|
| 42 |
|
---|
| 43 | $prefix = $prefix . '_';
|
---|
| 44 | return $prefix;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | function get_xoops_prefix()
|
---|
| 48 | {
|
---|
| 49 | global $xoops_config;
|
---|
| 50 | $ret =$xoops_config->xoops_db_prefix . '_';
|
---|
| 51 | return $ret;
|
---|
| 52 | }
|
---|
[99] | 53 |
|
---|
[104] | 54 | function get_xoops_trust_path()
|
---|
| 55 | {
|
---|
| 56 | global $xoops_config;
|
---|
| 57 | $ret =$xoops_config->xoops_trust_path;
|
---|
| 58 | return $ret;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[99] | 61 | function get_xoops_root_path()
|
---|
| 62 | {
|
---|
| 63 | global $xoops_config;
|
---|
| 64 | $ret =$xoops_config->xoops_root_path;
|
---|
| 65 | return $ret;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[95] | 68 | function get_wp_prefix()
|
---|
| 69 | {
|
---|
| 70 | $prefix = get_xoops_prefix() . get_wp_prefix_only();
|
---|
| 71 | return $prefix;
|
---|
| 72 | }
|
---|
[140] | 73 | function get_xoops_url()
|
---|
| 74 | {
|
---|
| 75 | global $xoops_config;
|
---|
| 76 | $ret =$xoops_config->xoops_url ;
|
---|
| 77 | return $ret;
|
---|
| 78 | }
|
---|
[95] | 79 |
|
---|
[140] | 80 | function get_xpress_url()
|
---|
| 81 | {
|
---|
| 82 | global $xoops_config;
|
---|
| 83 | $ret =$xoops_config->module_url ;
|
---|
| 84 | return $ret;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[95] | 87 | function get_xpress_modid()
|
---|
| 88 | {
|
---|
| 89 | global $xoops_db;
|
---|
| 90 |
|
---|
| 91 | $modulename = get_xpress_dir_name();
|
---|
| 92 | $sql = "SELECT mid FROM " . get_xoops_prefix() . "modules WHERE dirname = '$modulename'";
|
---|
| 93 | $mid = $xoops_db->get_var($sql);
|
---|
| 94 | return $mid;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | function get_xpress_db_version()
|
---|
| 98 | {
|
---|
| 99 | include get_xpress_dir_path() . '/wp-includes/version.php';
|
---|
| 100 | return $wp_db_version;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[104] | 103 | function is_xpress_mobile()
|
---|
| 104 | {
|
---|
| 105 | //ktai_style
|
---|
| 106 | if (function_exists('is_ktai')){
|
---|
| 107 | if (is_ktai()) {
|
---|
| 108 | // $file_path = $GLOBALS['xoopsModuleConfig']["ktai_style_tmpdir"] . '/comments.php';
|
---|
| 109 | return true;
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | //mobg
|
---|
| 114 | if (function_exists('is_mobile')) {
|
---|
| 115 | if (is_mobile()){
|
---|
| 116 | return true;
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | if (
|
---|
| 120 | preg_match("/DoCoMo/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
| 121 | preg_match("/softbank/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
| 122 | preg_match("/vodafone/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
| 123 | preg_match("/J-PHONE/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
| 124 | preg_match("/UP\.Browser/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
| 125 | preg_match("/ASTEL/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
| 126 | preg_match("/PDXGW/", $_SERVER['HTTP_USER_AGENT'])
|
---|
| 127 | )
|
---|
| 128 | {
|
---|
| 129 | return true;
|
---|
| 130 | } else {
|
---|
| 131 | return false;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[141] | 135 | function block_cache_refresh()
|
---|
| 136 | {
|
---|
| 137 | global $xoops_db;
|
---|
| 138 | $mid = get_xpress_modid();
|
---|
| 139 | $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid";
|
---|
| 140 | $blocks = $xoops_db->get_results($sql);
|
---|
| 141 | $mydirname = get_xpress_dir_name();
|
---|
| 142 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
| 143 |
|
---|
| 144 | foreach($blocks as $block){
|
---|
| 145 | $func_file = $block->func_file;
|
---|
[540] | 146 |
|
---|
| 147 | // Avoid the failure of the operation when switch_to_blog() and other plugin code is called on the admin page.
|
---|
[543] | 148 | $excludes = '|global_recent_posts_list_block.php|my_.*_block.php|global_recent_comments_block.php|';
|
---|
[540] | 149 | if (preg_match('/' . $excludes . '/' , $func_file)) continue;
|
---|
| 150 |
|
---|
[141] | 151 | $call_theme_function_name = str_replace(".php", "", $func_file);
|
---|
| 152 | $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
|
---|
| 153 | $cache_title = str_replace(".php", "", $func_file);
|
---|
| 154 | $blockID = $block->bid;
|
---|
| 155 | $options = explode("|", $block->options);
|
---|
| 156 |
|
---|
| 157 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
[452] | 158 | require_once $block_theme_file['file_path'];
|
---|
[141] | 159 | $block_render = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
| 160 | $xml['block'] = $block_render;
|
---|
| 161 | $xml['block']['options'] = $block->options;
|
---|
| 162 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $xml);
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
[145] | 165 | function is_wordpress_style()
|
---|
| 166 | {
|
---|
| 167 | global $xpress_config;
|
---|
| 168 |
|
---|
| 169 | if ($xpress_config->viewer_type == 'wordpress') return true;
|
---|
| 170 | if ($xpress_config->viewer_type == 'xoops') return false;
|
---|
| 171 |
|
---|
| 172 | // user select
|
---|
| 173 | $get_style = isset($_GET["style"]) ? $_GET["style"] : '';
|
---|
| 174 | $cookie_style = isset($_COOKIE["xpress_style"]) ? $_COOKIE["xpress_style"] : '';
|
---|
| 175 |
|
---|
| 176 | // set style
|
---|
| 177 | if (!empty($get_style)){
|
---|
| 178 | $style = $get_style;
|
---|
| 179 | } else {
|
---|
| 180 | if (!empty($cookie_style)){
|
---|
| 181 | $style = $cookie_style;
|
---|
| 182 | } else {
|
---|
| 183 | $style = 'x';
|
---|
| 184 | }
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | // set cookie
|
---|
| 188 | if (empty($cookie_style)){
|
---|
| 189 | setcookie("xpress_style", $style);
|
---|
| 190 | $_COOKIE["xpress_style"] = $style;
|
---|
| 191 | } else {
|
---|
| 192 | if ($style != $cookie_style) {
|
---|
| 193 | setcookie("xpress_style", $style);
|
---|
| 194 | $_COOKIE["xpress_style"] = $style;
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 | if ($style == 'w') {
|
---|
| 198 | return true;
|
---|
| 199 | } else {
|
---|
| 200 | return false;
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | function wp_meta_add_xpress_menu()
|
---|
| 205 | {
|
---|
| 206 | global $xpress_config;
|
---|
| 207 | if ($xpress_config->viewer_type == 'user_select'){
|
---|
| 208 | echo disp_mode_set();
|
---|
| 209 | }
|
---|
| 210 | if (function_exists('wp_theme_switcher') ) {
|
---|
| 211 | echo '<li>' . __('Themes') . ':';
|
---|
| 212 | wp_theme_switcher('dropdown');
|
---|
| 213 | echo '</li>';
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | function disp_mode_set(){
|
---|
| 218 | global $xpress_config;
|
---|
| 219 |
|
---|
| 220 | $select ="";
|
---|
| 221 | if ($xpress_config->viewer_type == 'user_select'){
|
---|
| 222 | $style = isset($_GET["style"]) ? $_GET["style"] : (isset($_COOKIE["xpress_style"]) ? $_COOKIE["xpress_style"] : "");
|
---|
| 223 |
|
---|
| 224 | switch($style) {
|
---|
| 225 | case 'w':
|
---|
| 226 | $select ='<li><a href="'.get_settings('siteurl').'/?style=x" title="'. __('Switch to XOOPS mode','xpressme').'">'.__('Switch to XOOPS mode','xpressme').'</a></li>';
|
---|
| 227 | // $select.='<img src="'. get_settings('siteurl').'/images/external.png" alt="'.__('Switch to XOOPS mode','xpressme') . '"></a></li>';
|
---|
| 228 | break;
|
---|
| 229 | case 'x':
|
---|
| 230 | $select='<li><a href="'.get_settings('siteurl').'/?style=w" title="'.__('Switch to WordPress mode','xpressme').'">'.__('Switch to WordPress mode','xpressme').'</a></li>';
|
---|
| 231 | break;
|
---|
| 232 | default:
|
---|
| 233 | $select='<li><a href="'.get_settings('siteurl').'/?style=w" title="'.__('Switch to WordPress mode','xpressme').'">'.__('Switch to WordPress mode','xpressme').'</a></li>';
|
---|
| 234 | break;
|
---|
| 235 | }
|
---|
| 236 | }
|
---|
| 237 | return $select;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[147] | 240 | function xpress_comment_count( $count ) {
|
---|
| 241 | global $id;
|
---|
[389] | 242 | $post_comments =get_comments('status=approve&post_id=' . $id);
|
---|
| 243 | $comments_by_type = &separate_comments($post_comments);
|
---|
[147] | 244 | return count($comments_by_type['comment']);
|
---|
| 245 | }
|
---|
[145] | 246 |
|
---|
[236] | 247 | function xpress_set_author_cookie($query_vars)
|
---|
[155] | 248 | {
|
---|
[236] | 249 | global $wp , $wpdb;
|
---|
[286] | 250 |
|
---|
| 251 | if (is_admin()) return $query_vars;
|
---|
| 252 |
|
---|
[477] | 253 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
[155] | 254 | if(xpress_is_multi_user()){
|
---|
[236] | 255 | if (!empty($_GET)){
|
---|
[155] | 256 | $auth = intval( @$_GET["author"] );
|
---|
| 257 | if ($auth > 0){
|
---|
[236] | 258 | setcookie($author_cookie, $auth, time()+3600, COOKIEPATH);
|
---|
[155] | 259 | $_COOKIE[$author_cookie] = $auth;
|
---|
| 260 | }
|
---|
[236] | 261 | } else {
|
---|
[360] | 262 | if(xpress_is_wp_version('<','2.1')){ // Maybe, I think that it is ver2.1 or less.
|
---|
[282] | 263 | if (!empty($wp->matched_query) ){
|
---|
| 264 | if (strpos($wp->matched_query,'author_name') !== false ){
|
---|
| 265 | $pattern = "author_name\s*=\s*(.*)\s*";
|
---|
| 266 | if ( preg_match ( "/".$pattern."/i", $wp->matched_query, $match ) ){
|
---|
| 267 | $author_name = "$match[1]";
|
---|
| 268 | $auth = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$author_name'");
|
---|
[236] | 269 |
|
---|
[282] | 270 | setcookie($author_cookie, $auth, time()+3600, COOKIEPATH);
|
---|
| 271 | $_COOKIE[$author_cookie] = $auth;
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
| 274 | } else {
|
---|
| 275 | setcookie($author_cookie, 0, time()+3600, COOKIEPATH);
|
---|
| 276 | $_COOKIE[$author_cookie] = 0;
|
---|
[236] | 277 | }
|
---|
| 278 | } else {
|
---|
[282] | 279 | if (!empty($wp->query_vars) ){
|
---|
| 280 | if (!empty($wp->query_vars['author_name']) ){
|
---|
| 281 | $author_name = $wp->query_vars['author_name'];
|
---|
| 282 | $auth = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$author_name'");
|
---|
| 283 |
|
---|
| 284 | setcookie($author_cookie, $auth, time()+3600, COOKIEPATH);
|
---|
| 285 | $_COOKIE[$author_cookie] = $auth;
|
---|
| 286 | }
|
---|
| 287 | } else {
|
---|
| 288 | setcookie($author_cookie, 0, time()+3600, COOKIEPATH);
|
---|
| 289 | $_COOKIE[$author_cookie] = 0;
|
---|
| 290 | }
|
---|
[236] | 291 | }
|
---|
[155] | 292 | }
|
---|
| 293 | }else{
|
---|
| 294 | // $GLOBALS["wp_xoops_author"] = null;
|
---|
[236] | 295 | setcookie($author_cookie, 0, time()+3600, COOKIEPATH);
|
---|
[155] | 296 | $_COOKIE[$author_cookie] = 0;
|
---|
| 297 | }
|
---|
[236] | 298 | return $query_vars;
|
---|
[155] | 299 | }
|
---|
| 300 |
|
---|
[469] | 301 | function xpress_query_filter($query)
|
---|
[155] | 302 | {
|
---|
[286] | 303 | if (is_admin()) return $query;
|
---|
| 304 |
|
---|
[477] | 305 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
[155] | 306 |
|
---|
[282] | 307 | if (strpos($query,'SELECT') === false) return $query;
|
---|
[155] | 308 |
|
---|
| 309 | $select_pattern = "SELECT(.*)post_author(.*)FROM";
|
---|
| 310 | if (preg_match ( "/".$select_pattern."/i", $query, $select_match ))
|
---|
| 311 | return $query;
|
---|
| 312 |
|
---|
| 313 | $query = preg_replace('/\s\s+/', ' ', $query);
|
---|
| 314 | if (!empty($_COOKIE[$author_cookie])){
|
---|
[360] | 315 | if(xpress_is_wp_version('<','2.1')){
|
---|
[282] | 316 | $pattern = "WHERE.*AND\s?\(*post_author\s*=";
|
---|
| 317 | if ( preg_match ( "/".$pattern."/i", $query, $match ) ){
|
---|
| 318 | return $query;
|
---|
| 319 | }
|
---|
[283] | 320 | $pattern = "WHERE\s?post_author\s*="; // get_usernumposts()
|
---|
| 321 | if ( preg_match ( "/".$pattern."/i", $query, $match ) ){
|
---|
| 322 | return $query;
|
---|
| 323 | }
|
---|
[282] | 324 | $pattern = "WHERE.*post_status\s*=\s*'publish'\s*\)?";
|
---|
| 325 | if ( preg_match ( "/".$pattern."/i", $query, $match ) ){
|
---|
| 326 |
|
---|
| 327 | $where_str = "$match[0]";
|
---|
| 328 | $where_arry = split(' ',$where_str);
|
---|
| 329 | $post_prefix = '';
|
---|
| 330 | foreach ($where_arry as $p){
|
---|
| 331 | if ( preg_match ( "/post_status/", $p, $match3 ) ){
|
---|
| 332 | $post_prefix = preg_replace("/post_status/", "", $p);
|
---|
| 333 | $post_prefix = preg_replace("/\(/", "", $post_prefix);
|
---|
| 334 | break;
|
---|
| 335 | }
|
---|
[155] | 336 | }
|
---|
[282] | 337 | $patern = 'WHERE';
|
---|
| 338 | $replace = "WHERE {$post_prefix}post_author = " . intval($_COOKIE[$author_cookie]) . " AND ";
|
---|
| 339 | $query = preg_replace("/$patern/", $replace, $query);
|
---|
[155] | 340 | }
|
---|
[282] | 341 | } else {
|
---|
| 342 | $pattern = "WHERE.*post_type\s*=\s*'post'\s*\)?";
|
---|
| 343 | if ( preg_match ( "/".$pattern."/i", $query, $match ) ){
|
---|
| 344 | $where_str = "$match[0]";
|
---|
| 345 | $where_arry = split(' ',$where_str);
|
---|
| 346 | $post_prefix = '';
|
---|
| 347 | foreach ($where_arry as $p){
|
---|
| 348 | if ( preg_match ( "/post_type/", $p, $match3 ) ){
|
---|
| 349 | $post_prefix = preg_replace("/post_type/", "", $p);
|
---|
| 350 | $post_prefix = preg_replace("/\(/", "", $post_prefix);
|
---|
| 351 | break;
|
---|
| 352 | }
|
---|
| 353 | }
|
---|
| 354 | preg_match ( "/post_type(.*)/", $where_str, $p_match );
|
---|
| 355 | $patern_s = $p_match[0];
|
---|
| 356 | $patern = preg_replace('/\)/', '\)', $patern_s);
|
---|
| 357 |
|
---|
| 358 | $replace = $patern_s . " AND {$post_prefix}post_author = " . intval($_COOKIE[$author_cookie]) . " ";
|
---|
[158] | 359 |
|
---|
[282] | 360 | $query = preg_replace("/$patern/", $replace, $query);
|
---|
| 361 | }
|
---|
[155] | 362 | }
|
---|
| 363 | }
|
---|
| 364 | // xpress_show_sql_quary($query);
|
---|
| 365 | return $query;
|
---|
| 366 | }
|
---|
[182] | 367 |
|
---|
[448] | 368 | function get_block_file_path($mydirname,$file_name)
|
---|
| 369 | {
|
---|
| 370 | global $xoops_config, $xpress_config;
|
---|
| 371 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
| 372 | $select_theme = xpress_ThemeTemplate(get_xpress_theme_name($mydirname));
|
---|
| 373 | $xpress_default_theme = 'xpress_default';
|
---|
| 374 | $select_block = '/wp-content/themes/' . $select_theme . '/blocks/' . $file_name;
|
---|
| 375 | $default_block = '/wp-content/themes/xpress_default/blocks/' . $file_name;
|
---|
| 376 | $select_block_path = $mydirpath . $select_block;
|
---|
| 377 | $default_block_path = $mydirpath . $default_block;
|
---|
| 378 |
|
---|
| 379 | $block_file_data = array();
|
---|
| 380 | $block_file_data['file_path'] = $default_block_path;
|
---|
| 381 | $block_file_data['error'] = '';
|
---|
| 382 |
|
---|
| 383 | if($select_theme != $xpress_default_theme){
|
---|
| 384 | if (file_exists($select_block_path)){
|
---|
| 385 | $select_block_version = get_block_version($select_block_path);
|
---|
| 386 | $default_block_version = get_block_version($default_block_path);
|
---|
| 387 | if (version_compare($select_block_version,$default_block_version, "<")){
|
---|
| 388 | $block_file_data['file_path'] = $default_block_path;
|
---|
| 389 | if ($xpress_config->is_block_error_display){
|
---|
| 390 | $error_str = '<div style="color:red">';
|
---|
| 391 | $error_str .= sprintf(__('Block file %1$s is an old version %2$s.<br />used block file %3$s of new version %4$s.','xpressme'),$select_block,$select_block_version,$default_block,$default_block_version);
|
---|
| 392 | $error_str .= '</div>';
|
---|
| 393 | $block_file_data['error'] = $error_str;
|
---|
| 394 | }
|
---|
| 395 | } else {
|
---|
| 396 | $block_file_data['file_path'] = $select_block_path;
|
---|
| 397 | $block_file_data['error'] = '';
|
---|
| 398 | }
|
---|
| 399 | }
|
---|
| 400 | }
|
---|
| 401 | return $block_file_data;
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | function get_block_version($file_path = ''){
|
---|
| 405 | $array_file = file($file_path);
|
---|
| 406 | $pattern = '^[\s|\/]*[B|b]lock\s+[V|v]ersion\s*[:|;]\s*([0-9|.]*)';
|
---|
| 407 | $version = '0.1';
|
---|
| 408 | if (empty($file_path)) return $version;
|
---|
| 409 | if (!file_exists($file_path)) return $version;
|
---|
| 410 | if (count($array_file) > 5) $file_count = 5; else $file_count = count($array_file);
|
---|
| 411 | for ($i = 0 ; $i < $file_count ; $i++){
|
---|
| 412 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
| 413 | $version = $matchs[1];
|
---|
| 414 | break;
|
---|
| 415 | }
|
---|
| 416 | }
|
---|
| 417 | return $version;
|
---|
| 418 | }
|
---|
| 419 |
|
---|
[95] | 420 | ?> |
---|