XPressME Integration Kit

Trac

Changeset 282


Ignore:
Timestamp:
Jun 16, 2009, 12:19:08 PM (15 years ago)
Author:
toemon
Message:

WP2011のときパーマリンク設定するとマルチユーザモードにならないバグ修正 fixes #153

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_common_functions.php

    r236 r282  
    247247                        } 
    248248                } else { 
    249                         if (!empty($wp->query_vars) ){ 
    250                                 if (!empty($wp->query_vars['author_name']) ){ 
    251                                         $author_name = $wp->query_vars['author_name']; 
    252                                         $auth = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$author_name'"); 
    253  
    254                                         setcookie($author_cookie, $auth, time()+3600, COOKIEPATH); 
    255                                         $_COOKIE[$author_cookie] = $auth; 
     249                        if(xpress_is_wp20()){ 
     250                                if (!empty($wp->matched_query) ){ 
     251                                        if (strpos($wp->matched_query,'author_name') !== false ){ 
     252                                                $pattern = "author_name\s*=\s*(.*)\s*"; 
     253                                                if ( preg_match ( "/".$pattern."/i", $wp->matched_query, $match ) ){ 
     254                                                        $author_name = "$match[1]"; 
     255                                                        $auth = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$author_name'"); 
     256 
     257                                                        setcookie($author_cookie, $auth, time()+3600, COOKIEPATH); 
     258                                                        $_COOKIE[$author_cookie] = $auth; 
     259                                                } 
     260                                        } 
     261                                } else { 
     262                                        setcookie($author_cookie, 0, time()+3600, COOKIEPATH); 
     263                                        $_COOKIE[$author_cookie] = 0; 
    256264                                } 
    257265                        } else { 
    258                                 setcookie($author_cookie, 0, time()+3600, COOKIEPATH); 
    259                                 $_COOKIE[$author_cookie] = 0; 
     266                                if (!empty($wp->query_vars) ){ 
     267                                        if (!empty($wp->query_vars['author_name']) ){ 
     268                                                $author_name = $wp->query_vars['author_name']; 
     269                                                $auth = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$author_name'"); 
     270 
     271                                                setcookie($author_cookie, $auth, time()+3600, COOKIEPATH); 
     272                                                $_COOKIE[$author_cookie] = $auth; 
     273                                        } 
     274                                } else { 
     275                                        setcookie($author_cookie, 0, time()+3600, COOKIEPATH); 
     276                                        $_COOKIE[$author_cookie] = 0; 
     277                                } 
    260278                        } 
    261279                } 
     
    272290        $author_cookie = get_xpress_dir_name() . "_select_author" ; 
    273291         
    274         if (strpos($query,'SELECT') !==0)  return $query; 
     292        if (strpos($query,'SELECT') === false)  return $query; 
    275293 
    276294        $select_pattern = "SELECT(.*)post_author(.*)FROM"; 
     
    280298        $query = preg_replace('/\s\s+/', ' ', $query); 
    281299        if (!empty($_COOKIE[$author_cookie])){ 
    282                 $pattern = "WHERE.*post_type\s*=\s*'post'\s*\)?"; 
    283                 if ( preg_match ( "/".$pattern."/i", $query, $match ) ){ 
    284                         $where_str = "$match[0]"; 
    285                         $where_arry = split(' ',$where_str); 
    286                         $post_prefix = ''; 
    287                         foreach ($where_arry as $p){ 
    288                                 if ( preg_match ( "/post_type/", $p, $match3 ) ){ 
    289                                         $post_prefix = preg_replace("/post_type/", "", $p); 
    290                                         $post_prefix = preg_replace("/\(/", "", $post_prefix); 
    291                                         break; 
     300                if(xpress_is_wp20()){ 
     301                        $pattern = "WHERE.*AND\s?\(*post_author\s*="; 
     302                        if ( preg_match ( "/".$pattern."/i", $query, $match ) ){ 
     303                                return $query; 
     304                        } 
     305                        $pattern = "WHERE.*post_status\s*=\s*'publish'\s*\)?"; 
     306                        if ( preg_match ( "/".$pattern."/i", $query, $match ) ){ 
     307                                 
     308                                $where_str = "$match[0]"; 
     309                                $where_arry = split(' ',$where_str); 
     310                                $post_prefix = ''; 
     311                                foreach ($where_arry as $p){ 
     312                                        if ( preg_match ( "/post_status/", $p, $match3 ) ){ 
     313                                                $post_prefix = preg_replace("/post_status/", "", $p); 
     314                                                $post_prefix = preg_replace("/\(/", "", $post_prefix); 
     315                                                break; 
     316                                        } 
    292317                                } 
    293                         } 
    294                         preg_match ( "/post_type(.*)/", $where_str, $p_match ); 
    295                         $patern = $p_match[0]; 
    296                         $patern = preg_replace('/\)/', '\)', $patern); 
    297                          
    298                         $replace = $patern . " AND {$post_prefix}post_author = " . intval($_COOKIE[$author_cookie]) . " "; 
    299  
    300                         $query = preg_replace("/$patern/", $replace, $query); 
     318                                $patern = 'WHERE';                               
     319                                $replace = "WHERE {$post_prefix}post_author = " . intval($_COOKIE[$author_cookie]) . " AND "; 
     320                                $query = preg_replace("/$patern/", $replace, $query); 
     321                        } 
     322                } else { 
     323                        $pattern = "WHERE.*post_type\s*=\s*'post'\s*\)?";                        
     324                        if ( preg_match ( "/".$pattern."/i", $query, $match ) ){ 
     325                                $where_str = "$match[0]"; 
     326                                $where_arry = split(' ',$where_str); 
     327                                $post_prefix = ''; 
     328                                foreach ($where_arry as $p){ 
     329                                        if ( preg_match ( "/post_type/", $p, $match3 ) ){ 
     330                                                $post_prefix = preg_replace("/post_type/", "", $p); 
     331                                                $post_prefix = preg_replace("/\(/", "", $post_prefix); 
     332                                                break; 
     333                                        } 
     334                                } 
     335                                preg_match ( "/post_type(.*)/", $where_str, $p_match ); 
     336                                $patern_s = $p_match[0]; 
     337                                $patern = preg_replace('/\)/', '\)', $patern_s); 
     338                                 
     339                                $replace = $patern_s . " AND {$post_prefix}post_author = " . intval($_COOKIE[$author_cookie]) . " "; 
     340 
     341                                $query = preg_replace("/$patern/", $replace, $query); 
     342                        } 
    301343                } 
    302344        } 
Note: See TracChangeset for help on using the changeset viewer.