XPressME Integration Kit

Trac

Changeset 69


Ignore:
Timestamp:
Jan 27, 2009, 8:52:57 AM (15 years ago)
Author:
toemon
Message:

ユーザ同期周りのコード整理
(不要分カット、まとめ)

Location:
trunk/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/pluggable-override.php

    r65 r69  
    1919        global $current_user; 
    2020 
    21         if (is_root_index_page_call()){ 
    22                 if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) 
    23                         return false; 
    2421 
    25                 if ( ! empty($current_user) ) 
    26                         return; 
     22        if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) 
     23                return false; 
    2724 
    28                 if (check_xpress_auth_cookie()){ 
     25        if ( ! empty($current_user) ) 
     26                return; 
     27 
     28        if (is_xpress_index_page_call()){ 
     29                if (check_xpress_auth_cookie()){        //The cookie is login user's or it checks it 
    2930                        if ( $user = wp_validate_auth_cookie() ) { 
    3031                                wp_set_current_user($user); 
     
    3334                }                                
    3435                xpress_login();          
    35         }else { 
     36 
     37        } else { 
    3638                // WP2.7 original 
    3739                if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) 
     
    6062                                $u_pass_md5 = $GLOBALS["xoopsUser"]->getVar("pass");             
    6163                                if ( ! empty($u_name) && ! empty($u_pass_md5) ) {                
    62 //                                      include_once dirname( __FILE__ ).'/xpress_user.php'; 
    63 //                                      $mess = xpress_user_sync($GLOBALS["xoopsUser"]->getVar("uid")); 
    64 //                                      if ($mess != 'NOT XPRESS USER'){ 
     64                                        include_once dirname( __FILE__ ).'/user_sync.php'; 
     65                                        $messege = ''; 
     66                                        $ret = xpress_user_sync($GLOBALS["xoopsUser"]->getVar("uid"),$messege); 
     67                                        if ($ret){ 
    6568                                                $user = new WP_User(0, $u_name); 
    66                                                 if ( wp_login($u_name, $u_pass_md5, true) ) { 
     69                                                if ( wp_login($u_name, $u_pass_md5) ) { 
    6770                                                        wp_setcookie($u_name, $u_pass_md5, true, '', '', false); 
    6871                                                        do_action('wp_login', $u_name); 
     
    7073                                                        return  true; 
    7174                                                } 
    72 //                                      } 
     75                                        }else { 
     76                                                echo $messege; 
     77                                        } 
    7378                                } 
    7479                        } 
     
    8893        } 
    8994                                         
    90         if(is_object($GLOBALS["xoopsModule"]) && WP_BLOG_DIRNAME == $GLOBALS["xoopsModule"]->getVar("dirname")){ 
     95        if(is_object($GLOBALS["xoopsModule"])){ 
     96//              && WP_BLOG_DIRNAME == $GLOBALS["xoopsModule"]->getVar("dirname")){ 
    9197                if(is_object($GLOBALS["xoopsUser"])){ 
    9298                        $u_name = $GLOBALS["xoopsUser"]->getVar("uname"); 
     
    107113} 
    108114 
    109  
    110 /* 
    111  
    112 function wp_login($username, $password, $already_md5 = false) { 
    113         global $wpdb, $error; 
    114  
    115         $username = sanitize_user($username); 
    116  
    117         if ( '' == $username ) 
    118                 return false; 
    119  
    120         if ( '' == $password ) { 
    121                 $error = __('<strong>ERROR</strong>: The password field is empty.'); 
    122                 return false; 
    123         } 
    124  
    125         $login = get_userdatabylogin($username); 
    126         //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'"); 
    127  
    128         if (!$login) { 
    129                 $error = __('<strong>ERROR</strong>: Invalid username.'); 
    130                 return false; 
    131         } else { 
    132                 if ($login->user_login == $username) { 
    133                                 if ($login->user_pass == $password) return true; 
    134                                 if ($login->user_pass == md5($password)) return true; 
    135                 } 
    136  
    137                 $error = __('<strong>ERROR</strong>: Incorrect password.'); 
    138                 $pwd = ''; 
    139                 return false; 
    140         } 
    141 } 
    142 */ 
    143115 
    144116// for wordpress2.5 
     
    177149} 
    178150 
    179  
    180 /* 
    181  
    182 function wp_mail($to, $subject, $message, $from_email="", $from_name="") { 
    183     $xoopsMailer =& getMailer(); 
    184     $xoopsMailer->useMail(); 
    185     $xoopsMailer->setToEmails($to); 
    186     $xoopsMailer->setFromEmail( empty($from_email) ? $GLOBALS["xoopsConfig"]['adminmail'] : $from_email); 
    187     $xoopsMailer->setFromName( empty($from_name) ? $GLOBALS["xoopsConfig"]['sitename'] : $from_name ); 
    188     $xoopsMailer->setSubject($subject); 
    189     $xoopsMailer->setBody($message); 
    190     return $xoopsMailer->send(); 
    191 } 
    192  
    193 */ 
    194 /* 
    195 function auth_redirect($force = false, $message = "") { 
    196         if(!is_object($GLOBALS["xoopsUser"])){ 
    197                 header('Expires: Wed, 11 Jan 1984 05:00:00 GMT'); 
    198                 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 
    199                 header('Cache-Control: no-cache, must-revalidate, max-age=0'); 
    200                 header('Pragma: no-cache'); 
    201          
    202                 header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI'])); 
    203                 exit(); 
    204         }elseif(!empty($force)){ 
    205                 $redirect = xoops_getenv("HTTP_REFERER"); 
    206                 $redirect = (strpos($redirect, XOOPS_URL) === 0)? $redirect: XOOPS_URL."/".$redirect; 
    207                 redirect_header($redirect, 2, $message); 
    208         } 
    209 } 
    210 */ 
    211151// ***********************************  End Of Pluggable Function Edit (wp-include/pluggable.php) ************************************ 
    212152 
  • trunk/include/user_sync.php

    r1 r69  
    5454// 
    5555 
    56         include_once dirname( __FILE__ ).'/../../../mainfile.php'; 
    57         $path = dirname(dirname(__FILE__)) . '/'; 
    58         if (file_exists($path . 'wp-load.php')) { 
    59                 require_once $path . 'wp-load.php'; 
    60         } else { 
    61                 require_once $path . 'wp-config.php'; 
    62         } 
    63  
    64 //if( ! function_exists( 'get_xpress_mid' ) ) : 
     56 
    6557        function get_xpress_mid($mydirname){ 
    6658                $xoopsDB =& Database::getInstance(); 
     
    7769                return $module_id; 
    7870        } 
    79 //endif;                 
    80  
    81  
    82 //if( ! function_exists( 'get_xpress_user_level' ) ) : 
    83         function get_xpress_user_level($mydirname , $uid=0){ 
     71 
     72 
     73        function get_xoops_group_capabillities_name($mydirname , $uid=0){ 
    8474                if ($uid == 0){ 
    85                         return 0; 
     75                        return ''; 
    8676                } 
    8777 
     
    9787                $result =  $xoopsDB->query($sql, 0, 0); 
    9888                if ($xoopsDB->getRowsNum($result)  > 0){ 
    99                                 return 5; 
     89                                return 'administrator'; 
    10090                } 
    10191                 
     
    10797                $result =  $xoopsDB->query($sql, 0, 0); 
    10898                if ($result === false){ 
    109                         return 0; 
     99                        return ''; 
    110100                }else{ 
    111101                        if ($xoopsDB->getRowsNum($result)  > 0){ 
    112102                                $row = $xoopsDB->fetchArray($result);    
    113103                                $level =  $row['user_level']; 
    114                                 return $level; 
     104                                switch($level) { 
     105                                        case 5: 
     106                                                return 'administrator'; 
     107                                        case 4: 
     108                                                return 'editor'; 
     109                                        case 3: 
     110                                                return 'author'; 
     111                                        case 2: 
     112                                                return 'contributor'; 
     113                                        case 1: 
     114                                                return 'subscriber'; 
     115                                        default: 
     116                                                return ''; 
     117                                } 
    115118                        } else {  
    116                                 return 0; 
    117                         } 
    118                 } 
    119         } 
    120 //endif; 
    121  
    122 //if( ! function_exists( 'get_now_user_level' ) ) : 
    123         function get_now_user_level(){ 
    124  
    125                 global $xoopsModule; 
    126  
    127                 if(empty($GLOBALS['user_level'])){ 
    128                         return 0;                
    129                 } else { 
    130                         //$user_id =  $GLOBALS["xoopsUser"]->getVar("uid"); 
    131                         //$level = xpress2wp_user_level(get_xpress_user_level($mydirname , $user_id)); 
    132                         //$level = get_wp_user_level($mydirname,$user_id); 
    133                         $level = $GLOBALS['user_level']; 
    134                         return $level; 
    135                 }                
    136         } 
    137 //endif; 
    138  
    139 //if( ! function_exists( 'get_wp_user_leve' ) ) : 
    140         function get_wp_user_level($mydirname,$uid=0){ 
    141                 $wp_prefix = get_xpress_prefix($mydirname); 
    142                 $xoopsDB =& Database::getInstance();             
    143                 $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta'); 
    144                 $meta_key_str = $xoopsDB->prefix($wp_prefix . 'user_level'); 
    145                 $sql = "SELECT meta_value FROM $db_xpress_usermeta WHERE (user_id = $uid) AND (meta_key = $meta_key)"; 
    146                 $res =  $xoopsDB->query($sql, 0, 0); 
    147                 if ($res === false){ 
    148                         return 0; 
    149                 }else{ 
    150                         if ($xoopsDB->getRowsNum($res)  > 0){ 
    151                                 $row = $xoopsDB->fetchArray($res);       
    152                                 $level =  $row['meta_value']; 
    153                                 return $level; 
    154                         } else {  
    155                                 return 0; 
    156                         } 
    157                 } 
    158                  
    159         } 
    160 //endif;                 
     119                                return ''; 
     120                        } 
     121                } 
     122        } 
     123         
     124//endif; 
    161125 
    162126//if( ! function_exists( 'get_xpress_prefix' ) ) : 
     
    191155//endif; 
    192156 
    193 //if( ! function_exists( 'xpress2wp_user_level' ) ) : 
    194         function xpress2wp_user_level($level){ 
    195                 switch($level) { 
    196                         case 5: 
    197                                 return 10; 
    198                         case 4: 
    199                                 return 7; 
    200                         case 3: 
    201                                 return 2; 
    202                         case 2: 
    203                                 return 1; 
    204                         case 1: 
    205                                 return 0; 
    206                         default: 
    207                                 return 0; 
    208                 } 
    209         } 
    210 //endif; 
    211  
    212 //if( ! function_exists( 'get_capabillities_name' ) ) : 
    213         function get_capabillities_name($level){ 
    214                 switch($level) { 
    215                         case 10: 
    216                                 return 'administrator'; 
    217                         case 7: 
    218                                 return 'editor'; 
    219                         case 2: 
    220                                 return 'author'; 
    221                         case 1: 
    222                                 return 'contributor'; 
    223                         case 0: 
    224                                 return 'subscriber'; 
    225                         default: 
    226                                 return 'subscriber'; 
    227                 } 
    228         } 
    229 //endif; 
    230157 
    231158//if( ! function_exists( 'xpress_usermeta_sync' ) ) : 
    232         function xpress_usermeta_sync($mydirname , $uid,$meta_key,$meta_value){ 
     159        function xpress_usermeta_sync($mydirname , $uid,$meta_key,$meta_value, &$message){ 
    233160                $wp_prefix = get_xpress_prefix($mydirname); 
    234                 $xoopsDB =& Database::getInstance();             
     161                $meta_key = "'" . $meta_key . "'"; 
     162                $xoopsDB =& Database::getInstance(); 
    235163                $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta'); 
    236164                $sql = "SELECT user_id FROM $db_xpress_usermeta WHERE (user_id = $uid) AND (meta_key = $meta_key)"; 
     
    249177                $res = $xoopsDB->queryF($sql2, 0, 0); 
    250178                if ($res === false) { 
    251                         $ret = "...ERR($sql2)"; 
    252                         return $ret; 
     179                        $message .= "...ERR($sql2)"; 
     180                        return false; 
    253181                } else { 
    254                         return ''; 
    255                 } 
    256  
    257         } 
    258 //endif; 
    259  
    260 //if( ! function_exists( 'sql_str' ) ) : 
     182                        return true; 
     183                } 
     184 
     185        } 
     186//endif; 
     187 
    261188        function sql_str($text = ''){ 
    262189                return "'" . $text . "'"; 
    263190        } 
    264 //endif; 
    265191         
    266192//if( ! function_exists( 'xpress_user_sync' ) ) : 
    267         function xpress_user_sync($sync_uid = 0){ 
     193        function xpress_user_sync($sync_uid = 0, &$message){ 
    268194                $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ; 
    269195 
     
    274200                        $db_xpress_users = $xoopsDB->prefix($wp_prefix . 'users'); 
    275201 
    276                         $ret_str = 'Do Sync'; 
     202                        $message = 'Do Sync'; 
    277203                 
    278204                        if ($sync_uid == 0) { 
     
    284210                        $xu_res =  $xoopsDB->query($xu_sql, 0, 0); 
    285211                        if ($xu_res === false){ 
    286                                 $ret_str .= '...ERR ('. $xu_sql . ')'; 
    287                                 return $ret_str; 
     212                                $message .= '...ERR ('. $xu_sql . ')'; 
     213                                return false; 
    288214                        }else { 
    289215                                while($xu_row =         $xoopsDB->fetchArray($xu_res)){ 
    290                                         $xpress_user_level = get_xpress_user_level($mydirname , $xu_row['uid']); 
    291                                         if ($xpress_user_level < 1){ 
    292                                                 $ret_str .= "...PASS '" . $xu_row['uname'] ."'[uid=".$xu_row['uid'] ."](not xpress user)"; 
     216                                        $capabillities_name = get_xoops_group_capabillities_name($mydirname , $xu_row['uid']); 
     217                                        if (empty($capabillities_name)){ 
     218                                                $message .= "...PASS '" . $xu_row['uname'] ."'[uid=".$xu_row['uid'] ."](not xpress user)"; 
    293219                                                if ($sync_uid != 0){ 
    294                                                         $ret_str .= '...NOT XPRESS USER ' . $xu_row['uname']; 
    295                                                         return $ret_str; 
     220                                                        $message .= '...NOT XPRESS USER ' . $xu_row['uname']; 
     221                                                        return false; 
    296222                                                } 
    297223                                        } else { 
    298224                                                $user_ID =                      $xu_row['uid']; 
    299                                                 $user_level = xpress2wp_user_level($xpress_user_level); 
    300                                                 if ($user_level == 10 ){ 
    301                                                         $capabillities_name = 'administrator'; 
    302                                                 }else { 
     225                                                if ($capabillities_name != 'administrator' ){ 
    303226                                                        if (!empty($GLOBALS["xoopsModuleConfig"]["use_wp_userlevel"])){ 
    304                                                                 $capabillities_name = get_option('default_role');                
    305                                                         }else { 
    306                                                                 $capabillities_name = get_capabillities_name($user_level); 
     227                                                                $capabillities_name = get_option('default_role'); 
    307228                                                        } 
    308229                                                } 
     
    325246 
    326247                                                $is_update = false; 
    327                                                  
    328 //                                              $capabillities = sql_str(get_capabillities($user_level)); 
    329                  
    330248                                                if (xpress_user_found($mydirname, $user_ID)){ 
    331249                                                        $wu_sql  =      "UPDATE $db_xpress_users "; 
     
    340258                                                        $wu_sql .=      "WHERE (ID = $user_ID )"; 
    341259                                                        if (!empty($GLOBALS["xoopsModuleConfig"]["use_wp_userlevel"])){ 
    342                                                                 $ret_str .= '...UPDATE ' . $user_login_name . '(Level Not Change)'; 
     260                                                                $message .= '...UPDATE ' . $user_login_name . '(Level Not Change)'; 
    343261                                                        } else { 
    344                                                                 $ret_str .= '...UPDATE ' . $user_login_name . '(' . $capabillities_name . ')'; 
     262                                                                $message .= '...UPDATE ' . $user_login_name . '(' . $capabillities_name . ')'; 
    345263                                                        } 
    346264                                                        $is_update = true; 
     
    353271                                                        $wu_sql .=              " , $user_regist_time, $user_status, $user_display_name)"; 
    354272                                                        if (!empty($GLOBALS["xoopsModuleConfig"]["use_wp_userlevel"])){ 
    355                                                                 $ret_str .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . '-WP Default)'; 
     273                                                                $message .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . '-WP Default)'; 
    356274                                                        } else { 
    357                                                                 $ret_str .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . ')'; 
     275                                                                $message .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . ')'; 
    358276                                                        } 
    359277                                                } 
     
    362280                 
    363281                                                if ($wu_res === false){ 
    364                                                         $ret_str .= '...ERR(' . $wu_sql . ')'; 
    365                                                         return $ret_str; 
     282                                                        $message .= '...ERR(' . $wu_sql . ')'; 
     283                                                        return false; 
    366284                                                } 
    367285                                                                 
     
    376294                                                } 
    377295 
    378                                                 if( $is_update === false){ 
    379                                                         $meta_key = sql_str('nickname'); 
    380                                                         $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_nickname); 
    381                                                         if(!empty($ans)){ 
    382                                                                 $ret_str .= $ans; 
    383                                                                 return $ret_str; 
    384                                                         } 
    385                                                         $meta_key = sql_str('first_name'); 
    386                                                         $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_first_name); 
    387                                                         if(!empty($ans)){ 
    388                                                                 $ret_str .= $ans; 
    389                                                                 return $ret_str; 
    390                                                         } 
    391                                                         $meta_key = sql_str('last_name'); 
    392                                                         $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_last_name); 
    393                                                         if(!empty($ans)){ 
    394                                                                 $ret_str .= $ans; 
    395                                                                 return $ret_str; 
    396                                                         } 
    397                                                         $meta_key = sql_str('description'); 
    398                                                         $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_description); 
    399                                                         if(!empty($ans)){ 
    400                                                                 $ret_str .= $ans; 
    401                                                                 return $ret_str; 
    402                                                         } 
    403                                                         $meta_key = sql_str('jabber'); 
    404                                                         $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_jabber); 
    405                                                         if(!empty($ans)){ 
    406                                                                 $ret_str .= $ans; 
    407                                                                 return $ret_str; 
    408                                                         } 
    409                                                 } 
    410                                                 $meta_key = sql_str('aim'); 
    411                                                 $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_aim); 
    412                                                 if(!empty($ans)){ 
    413                                                         $ret_str .= $ans; 
    414                                                         return $ret_str; 
    415                                                 } 
    416                                                 $meta_key = sql_str('yim'); 
    417                                                 $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_yim); 
    418                                                 if(!empty($ans)){ 
    419                                                         $ret_str .= $ans; 
    420                                                         return $ret_str; 
    421                                                 } 
     296        //                                      if( $is_update === false){ 
     297                                                        if(!xpress_usermeta_sync($mydirname, $user_ID,'nickname',$user_nickname,$message) )return false; 
     298                                                        if(!xpress_usermeta_sync($mydirname, $user_ID,'first_name',$user_first_name,$message) )return false; 
     299                                                        if(!xpress_usermeta_sync($mydirname, $user_ID,'last_name',$user_last_name,$message) )return false; 
     300                                                        if(!xpress_usermeta_sync($mydirname, $user_ID,'description',$user_description,$message) )return false; 
     301                                                        if(!xpress_usermeta_sync($mydirname, $user_ID,'jabber',$user_jabber,$message) )return false; 
     302        //                                      } 
     303                                                if(!xpress_usermeta_sync($mydirname, $user_ID,'aim',$user_aim,$message) )return false; 
     304                                                if(!xpress_usermeta_sync($mydirname, $user_ID,'yim',$user_yim,$message) )return false; 
    422305                                                if ($is_update === false ) { 
    423                                                         $meta_key = sql_str('rich_editing'); 
    424                                                         $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_rich_editing); 
    425                                                         if(!empty($ans)){ 
    426                                                                 $ret_str .= $ans; 
    427                                                                 return $ret_str; 
    428                                                         } 
     306                                                        if(!xpress_usermeta_sync($mydirname, $user_ID,'rich_editing',$user_rich_editing,$message) )return false; 
    429307                                                }                                        
    430308                                        } 
    431309                                } 
    432310                        } 
    433                         $ret_str .= "...END"; 
    434                         return $ret_str; 
    435                 } 
    436         } 
    437 //endif; 
     311                        $message .= "...END"; 
     312                        return true; 
     313                } 
     314        } 
     315//endif; 
     316 
     317 
    438318 
    439319//if( ! function_exists( 'check_user_role_prefix' ) ) : 
Note: See TracChangeset for help on using the changeset viewer.