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