- Timestamp:
- Feb 4, 2009, 5:52:47 PM (16 years ago)
- Location:
- trunk/wp-content/plugins/xpressme/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-content/plugins/xpressme/include/pluggable-override.php
r86 r87 21 21 22 22 23 if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) 24 return false; 23 if ($xoopsModule){ 24 if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) 25 return false; 25 26 26 if ( ! empty($current_user) )27 return;27 if ( ! empty($current_user) ) 28 return; 28 29 29 if ($xoopsModule){30 30 if (check_xpress_auth_cookie()){ //The cookie is login user's or it checks it 31 31 if ( $user = wp_validate_auth_cookie() ) { … … 34 34 } 35 35 } 36 xpress_login(); 36 xpress_login(); 37 37 38 38 } else { … … 59 59 global $current_user; 60 60 61 if(is_object($GLOBALS["xoopsUser"])){ 62 $u_name = $GLOBALS["xoopsUser"]->getVar("uname"); 63 $u_pass_md5 = $GLOBALS["xoopsUser"]->getVar("pass"); 64 if ( ! empty($u_name) && ! empty($u_pass_md5) ) { 65 include_once dirname( __FILE__ ).'/user_sync_xoops.php'; 66 $messege = ''; 67 $ret = user_sync_to_wordpress($GLOBALS["xoopsUser"]->getVar("uid"),$messege); 68 if ($ret){ 69 $user = new WP_User(0, $u_name); 70 if ( wp_login($u_name, $u_pass_md5) ) { 71 wp_setcookie($u_name, $u_pass_md5, true, '', '', false); 72 do_action('wp_login', $u_name); 73 wp_set_current_user($user->ID); 74 return true; 75 } 76 }else { 77 // echo $messege; 78 } 61 if(is_object($GLOBALS["xoopsUser"])){ 62 $u_name = $GLOBALS["xoopsUser"]->getVar("uname"); 63 $u_pass_md5 = $GLOBALS["xoopsUser"]->getVar("pass"); 64 if ( ! empty($u_name) && ! empty($u_pass_md5) ) { 65 include_once dirname( __FILE__ ).'/user_sync_xoops.php'; 66 repair_user_meta_prefix(); //Repair when data base prefix is changed on XOOPS side 67 $messege = ''; 68 $ret = user_sync_to_wordpress($GLOBALS["xoopsUser"]->getVar("uid"),$messege); 69 if ($ret){ 70 $user = new WP_User(0, $u_name); 71 if ( wp_login($u_name, $u_pass_md5) ) { 72 wp_setcookie($u_name, $u_pass_md5, true, '', '', false); 73 do_action('wp_login', $u_name); 74 wp_set_current_user($user->ID); 75 return true; 79 76 } 80 77 } 81 wp_set_current_user(0); 82 return 0; 78 } 79 } 80 wp_set_current_user(0); 81 return 0; 83 82 } 84 83 -
trunk/wp-content/plugins/xpressme/include/user_sync_xoops.php
r85 r87 34 34 * in the WordPress authority given to the group to which the user belongs are obtained. 35 35 */ 36 function get_xoops_group_role($mydirname ,$uid=0){37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 36 function get_xoops_group_role($uid=0){ 37 $ans = array(); 38 if ($uid == 0){ 39 return ''; 40 } 41 42 global $xoops_db; 43 $db_groups_users_link = get_xoops_prefix() . 'groups_users_link'; 44 $db_group_role = get_wp_prefix() . 'group_role'; 45 46 $sql = "SELECT * "; 47 $sql .= "FROM $db_groups_users_link "; 48 $sql .= "LEFT JOIN $db_group_role ON $db_groups_users_link.groupid = $db_group_role.groupid "; 49 $sql .= "WHERE uid = $uid"; 50 51 $user_groups = $xoops_db->get_results($sql); 52 $ans['capabillities'] = ''; 53 $ans['allway_update'] = 0; 54 55 foreach($user_groups as $user_group){ 56 $before_level = get_role_level($ans['capabillities']); 57 $now_level = get_role_level($user_group->role); 58 if ($now_level > $before_level){ 59 $ans['capabillities'] = $user_group->role; 60 $ans['allway_update'] = $user_group->login_all; 61 } 62 } 63 return $ans; 64 } 65 65 66 66 /* … … 74 74 } 75 75 76 77 //if( ! function_exists( 'xpress_usermeta_sync' ) ) :78 function xpress_usermeta_sync($mydirname , $uid,$meta_key,$meta_value, &$message){79 $wp_prefix = get_wp_prefix();80 $meta_key = "'" . $meta_key . "'";81 $meta_value = "'" . $meta_value . "'";82 $xoopsDB =& Database::getInstance();83 $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta');84 $sql = "SELECT user_id FROM $db_xpress_usermeta WHERE (user_id = $uid) AND (meta_key = $meta_key)";85 $res = $xoopsDB->query($sql, 0, 0);86 87 if ($res === false){88 $sql2 = "INSERT INTO $db_xpress_usermeta (user_id,meta_key,meta_value) VALUES ($uid,$meta_key,$meta_value)";89 }else {90 if ($xoopsDB->getRowsNum($res) > 0){91 92 $sql2 = "UPDATE $db_xpress_usermeta SET meta_value = $meta_value WHERE (user_id = $uid) AND (meta_key = $meta_key)";93 } else {94 $sql2 = "INSERT INTO $db_xpress_usermeta (user_id,meta_key,meta_value) VALUES ($uid,$meta_key,$meta_value)";95 }96 }97 $res = $xoopsDB->queryF($sql2, 0, 0);98 if ($res === false) {99 $message .= "...ERR($sql2)";100 return false;101 } else {102 return true;103 }104 105 }106 //endif;107 108 76 /* 109 77 * The user data of XOOPS is written in the WordPress user data. 110 78 * If $sync_uid is 0, all users are written. 111 79 */ 112 function user_sync_to_wordpress($sync_uid = 0, &$message) 80 function user_sync_to_wordpress($sync_uid = 0, &$message){ 113 81 global $xoops_db; 114 82 global $xoopsModule; 115 116 $mydirname = basename( dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) );117 83 118 84 if( is_object($xoopsModule)) { … … 135 101 136 102 foreach($xoops_users as $xoops_user){ 137 $role = get_xoops_group_role($ mydirname , $xoops_user->uid);103 $role = get_xoops_group_role($xoops_user->uid); 138 104 $capabillities_name = $role['capabillities']; 139 105 $allway_update = $role['allway_update']; … … 145 111 } 146 112 } else { 147 $user_ID = $xoops_user->uid;148 $user_login_name = $xoops_user->uname;149 $user_pass_md5 = $xoops_user->pass;150 $user_email = $xoops_user->email;151 $user_url = $xoops_user->url;152 113 $user_regist_time = date('Y-m-d H:i:s' , $xoops_user->user_regdate); 153 $user_nicename = $xoops_user->uname;154 114 $user_status = 0; 155 115 $user_display_name =empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ; 156 $user_nickname = empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ;157 $user_aim = $xoops_user->user_aim;158 $user_yim = $xoops_user->user_yim;159 $user_first_name = $xoops_user->uname;160 $user_last_name = '';161 $user_description = '';162 $user_jabber = '';163 $user_rich_editing = 'true';164 116 165 117 $is_update = false; 166 118 167 $wp_user_id = get_wp_user_id($ user_login_name) ;119 $wp_user_id = get_wp_user_id($xoops_user->uname) ; 168 120 if ($wp_user_id){ 169 121 $wu_sql = "UPDATE $db_xpress_users "; 170 122 $wu_sql .= 'SET '; 171 $wu_sql .= "user_pass = '$ user_pass_md5', ";172 $wu_sql .= "user_email = '$ user_email', ";173 $wu_sql .= "user_url = '$ user_url', ";174 $wu_sql .= "user_nicename = '$ user_nicename', ";123 $wu_sql .= "user_pass = '$xoops_user->pass', "; 124 $wu_sql .= "user_email = '$xoops_user->email', "; 125 $wu_sql .= "user_url = '$xoops_user->url', "; 126 $wu_sql .= "user_nicename = '$xoops_user->uname', "; 175 127 $wu_sql .= "user_registered = '$user_regist_time', "; 176 128 $wu_sql .= "user_status = 0 "; 177 $wu_sql .= "WHERE (user_login = '$ user_login_name' )";129 $wu_sql .= "WHERE (user_login = '$xoops_user->uname' )"; 178 130 179 131 $xoops_db->query($wu_sql); … … 191 143 $wu_sql .= " , user_registered , user_status , display_name) "; 192 144 $wu_sql .= "VALUES "; 193 $wu_sql .= "('$ user_login_name', '$user_pass_md5', '$user_email', '$user_url', '$user_nicename' ";145 $wu_sql .= "('$xoops_user->uname', '$xoops_user->pass', '$xoops_user->email', '$xoops_user->url', '$xoops_user->uname' "; 194 146 $wu_sql .= " , '$user_regist_time', $user_status, '$user_display_name')"; 195 147 $xoops_db->query($wu_sql); 196 $wp_user_id = get_wp_user_id($user_login_name) ; 148 // $wp_user_id = get_wp_user_id($user_login_name) ; 149 $wp_user_id = mysql_insert_id(); 197 150 $sycc_user = new WP_User($wp_user_id); 198 151 $sycc_user->set_role($capabillities_name); 199 152 $message .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . ')'; 200 153 } 201 202 if(!xpress_usermeta_sync($mydirname, $user_ID,'nickname',$user_nickname,$message) )return false; 203 if(!xpress_usermeta_sync($mydirname, $user_ID,'first_name',$user_first_name,$message) )return false; 204 if(!xpress_usermeta_sync($mydirname, $user_ID,'last_name',$user_last_name,$message) )return false; 205 if(!xpress_usermeta_sync($mydirname, $user_ID,'description',$user_description,$message) )return false; 206 if(!xpress_usermeta_sync($mydirname, $user_ID,'jabber',$user_jabber,$message) )return false; 207 if(!xpress_usermeta_sync($mydirname, $user_ID,'aim',$user_aim,$message) )return false; 208 if(!xpress_usermeta_sync($mydirname, $user_ID,'yim',$user_yim,$message) )return false; 154 155 $user_nickname = empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ; 156 $user_rich_editing = 'true'; 157 $user_first_name = $xoops_user->uname; 158 $user_last_name = ''; 159 $user_description = ''; 160 $user_jabber = ''; 161 162 update_usermeta( $wp_user_id,'nickname',$user_nickname); 163 update_usermeta( $wp_user_id,'first_name',$user_first_name); 164 update_usermeta( $wp_user_id,'last_name',$user_last_name); 165 update_usermeta( $wp_user_id,'description',$user_description); 166 update_usermeta( $wp_user_id,'jabber',$user_jabber); 167 update_usermeta( $wp_user_id,'aim',$xoops_user->user_aim); 168 update_usermeta( $wp_user_id,'yim',$xoops_user->user_yim); 209 169 if ($is_update === false ) { 210 if(!xpress_usermeta_sync($mydirname, $user_ID,'rich_editing',$user_rich_editing,$message) )return false;170 update_usermeta( $wp_user_id,'rich_editing',$user_rich_editing); 211 171 } 212 172 } … … 216 176 } 217 177 } 218 219 //if( ! function_exists( 'check_user_role_prefix' ) ) :220 function check_user_role_prefix($mydirname){221 $wp_prefix = get_wp_prefix();222 $xoopsDB =& Database::getInstance();223 $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta');224 $user_meta_prefix =$xoopsDB->prefix($wp_prefix);225 226 $sql = "SELECT * FROM $db_xpress_usermeta WHERE meta_key LIKE '%_" . $wp_prefix . "user_level' OR meta_key LIKE '%_" . $wp_prefix . "capabilities' OR meta_key LIKE '%_" . $wp_prefix . "autosave_draft_ids'";227 $result = $xoopsDB->query($sql, 0, 0);228 if ($result === false){229 return -1;230 }else{231 $i=0;232 while($row = $xoopsDB->fetchArray($result)){233 $meta_key = $row['meta_key'];234 if (strpos($meta_key,$user_meta_prefix) === false) {235 $i++;236 }237 }238 return $i;239 }240 }241 //endif;242 243 //if( ! function_exists( 'same_metakey_delete' ) ) :244 function same_metakey_delete($mydirname,$metakey){245 $wp_prefix = get_wp_prefix();246 $xoopsDB =& Database::getInstance();247 $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta');248 $user_meta_prefix =$xoopsDB->prefix($wp_prefix);249 250 $sql = "DELETE FROM $db_xpress_usermeta WHERE meta_key LIKE '$metakey'";251 $result = $xoopsDB->query($sql, 0, 0);252 if ($result === false){253 return false;254 }else{255 return true;256 }257 }258 //endif;259 260 //if( ! function_exists( 'repair_user_role_prefix' ) ) :261 function repair_user_role_prefix($mydirname){262 $wp_prefix = get_wp_prefix();263 $xoopsDB =& Database::getInstance();264 $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta');265 $user_meta_prefix =$xoopsDB->prefix($wp_prefix);266 $ret = '';267 268 $sql = "SELECT * FROM $db_xpress_usermeta WHERE meta_key LIKE '%_" . $wp_prefix . "user_level' OR meta_key LIKE '%_" . $wp_prefix . "capabilities' OR meta_key LIKE '%_" . $wp_prefix . "autosave_draft_ids'";269 $result = $xoopsDB->queryF($sql, 0, 0);270 if ($result === false){271 return -1;272 }else{273 $i=0;274 while($row = $xoopsDB->fetchArray($result)){275 $meta_key = $row['meta_key'];276 $umeta_id = $row['umeta_id'];277 if (strpos($meta_key,$user_meta_prefix) === false) {278 $new_meta_key = '';279 if (strpos($meta_key,$wp_prefix.'user_level')){280 $new_meta_key = $xoopsDB->prefix($wp_prefix . 'user_level');281 }282 283 if (strpos($meta_key,$wp_prefix.'capabilities')){284 $new_meta_key = $xoopsDB->prefix($wp_prefix . 'capabilities');285 }286 287 if (strpos($meta_key,$wp_prefix.'autosave_draft_ids')){288 $new_meta_key = $xoopsDB->prefix($wp_prefix . 'autosave_draft_ids');289 }290 291 if (!empty($new_meta_key)){292 same_metakey_delete($mydirname,$new_meta_key);293 294 $repair_sql = "UPDATE $db_xpress_usermeta ";295 $repair_sql .= 'SET ';296 $repair_sql .= "meta_key = '$new_meta_key' ";297 $repair_sql .= "WHERE (umeta_id = $umeta_id )";298 $repair_res = $xoopsDB->queryF($repair_sql, 0, 0);299 if ($repair_res === false){300 $ret .= '...ERR(' . $meta_key . '->' . $new_meta_key . ')<br>';301 } else {302 $ret .= '...DO(' . $meta_key . '->' . $new_meta_key . ')<br>';303 }304 }305 }306 }307 }308 return $ret;309 }310 //endif;311 312 178 313 179 /* … … 365 231 } 366 232 } 233 234 235 /* 236 * When I changed the pre-fix of the database in XOOPS Protector Module, user authority data of WordPress read it and cannot do it. 237 * This is because a meta_key pre-fix of the usermeta table of WordPress is not changed. 238 * and user_roles option_name pre-fix of the option table of WordPress is not changed. 239 */ 240 function repair_user_meta_prefix(){ 241 global $xoops_db; 242 243 // repair usermeta db 244 $db_xpress_usermeta = get_wp_prefix() . 'usermeta'; 245 $wp_prefix_only = get_wp_prefix_only(); 246 $user_meta_prefix = get_wp_prefix(); 247 $sql = "SELECT * FROM $db_xpress_usermeta WHERE meta_key LIKE '%_" . $wp_prefix_only . "%'" ; 248 $user_metas = $xoops_db->get_results($sql); 249 foreach($user_metas as $user_meta){ 250 if (strpos($user_meta->meta_key,$user_meta_prefix) === false) { 251 $new_meta_key = ''; 252 if (strpos($user_meta->meta_key,$wp_prefix_only.'user_level')) 253 $new_meta_key = $user_meta_prefix . 'user_level'; 254 if (strpos($user_meta->meta_key,$wp_prefix_only.'capabilities')) 255 $new_meta_key = $user_meta_prefix . 'capabilities'; 256 if (strpos($user_meta->meta_key,$wp_prefix_only.'autosave_draft_ids')) 257 $new_meta_key = $user_meta_prefix . 'autosave_draft_ids'; 258 if (strpos($user_meta->meta_key,$wp_prefix_only.'usersettings')){ 259 if (strpos($user_meta->meta_key,$wp_prefix_only.'usersettingstime')) 260 $new_meta_key = $user_meta_prefix . 'usersettingstime'; 261 else 262 $new_meta_key = $user_meta_prefix . 'usersettings'; 263 } 264 if (!empty($new_meta_key)){ 265 $repair_sql = "UPDATE $db_xpress_usermeta "; 266 $repair_sql .= 'SET '; 267 $repair_sql .= "meta_key = '$new_meta_key' "; 268 $repair_sql .= "WHERE (umeta_id = $user_meta->umeta_id )"; 269 $xoops_db->query($repair_sql); 270 } 271 } 272 } 273 274 // repair option db user_roles 275 $db_wp_option = get_wp_prefix() . 'options'; 276 $new_option_name = get_wp_prefix() . 'user_roles'; 277 $sql = "SELECT option_id , option_name FROM $db_wp_option WHERE option_name LIKE '%_" . $wp_prefix_only . "user_roles'" ; 278 $option= $xoops_db->get_row($sql); 279 if ($option->option_name != $new_option_name){ 280 $repair_sql = "UPDATE $db_wp_option "; 281 $repair_sql .= 'SET '; 282 $repair_sql .= "option_name = '$new_option_name' "; 283 $repair_sql .= "WHERE (option_id = $option->option_id )"; 284 $xoops_db->query($repair_sql); 285 } 286 } 367 287 ?>
Note: See TracChangeset
for help on using the changeset viewer.