- Timestamp:
- Mar 3, 2009, 8:33:23 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-content/plugins/xpressme/include/user_sync_xoops.php
r87 r95 43 43 $db_groups_users_link = get_xoops_prefix() . 'groups_users_link'; 44 44 $db_group_role = get_wp_prefix() . 'group_role'; 45 $db_groups = get_xoops_prefix() . 'groups'; 45 46 46 47 $sql = "SELECT * "; 47 48 $sql .= "FROM $db_groups_users_link "; 48 49 $sql .= "LEFT JOIN $db_group_role ON $db_groups_users_link.groupid = $db_group_role.groupid "; 50 $sql .= "LEFT JOIN $db_groups ON $db_groups_users_link.groupid = $db_groups.groupid "; 49 51 $sql .= "WHERE uid = $uid"; 50 51 52 $user_groups = $xoops_db->get_results($sql); 52 53 $ans['capabillities'] = ''; … … 54 55 55 56 foreach($user_groups as $user_group){ 57 if ($user_group->group_type == 'Admin'){ 58 $ans['capabillities'] = 'administrator'; 59 $ans['allway_update'] = 0; 60 break; 61 } 56 62 $before_level = get_role_level($ans['capabillities']); 63 57 64 $now_level = get_role_level($user_group->role); 58 65 if ($now_level > $before_level){ … … 80 87 function user_sync_to_wordpress($sync_uid = 0, &$message){ 81 88 global $xoops_db; 82 global $xoopsModule; 83 84 if( is_object($xoopsModule)) { 85 $db_xoops_users = get_xoops_prefix() . 'users'; 86 $db_xpress_users = get_wp_prefix() . 'users'; 87 88 $message = 'Do Sync'; 89 90 if ($sync_uid == 0) { 91 $xu_sql = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users"; 89 90 $db_xoops_users = get_xoops_prefix() . 'users'; 91 $db_xpress_users = get_wp_prefix() . 'users'; 92 93 $message = 'Do Sync'; 94 95 if ($sync_uid == 0) { 96 $xu_sql = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users"; 97 } else { 98 $xu_sql = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users WHERE uid = $sync_uid"; 99 } 100 101 $xoops_users = $xoops_db->get_results($xu_sql); 102 if (empty($xoops_users)){ 103 $message .= '...ERR ('. $xu_sql . ')'; 104 return false; 105 } 106 107 foreach($xoops_users as $xoops_user){ 108 $role = get_xoops_group_role($xoops_user->uid); 109 $capabillities_name = $role['capabillities']; 110 $allway_update = $role['allway_update']; 111 if (empty($capabillities_name)){ 112 $message .= "...PASS '" . $xoops_user->uname ."'[uid=".$xoops_user->uid ."](not xpress user)"; 113 if ($sync_uid != 0){ 114 $message .= '...NOT XPRESS USER ' . $xoops_user->uname; 115 return false; 116 } 92 117 } else { 93 $xu_sql = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users WHERE uid = $sync_uid"; 94 } 95 96 $xoops_users = $xoops_db->get_results($xu_sql); 97 if (empty($xoops_users)){ 98 $message .= '...ERR ('. $xu_sql . ')'; 99 return false; 100 } 101 102 foreach($xoops_users as $xoops_user){ 103 $role = get_xoops_group_role($xoops_user->uid); 104 $capabillities_name = $role['capabillities']; 105 $allway_update = $role['allway_update']; 106 if (empty($capabillities_name)){ 107 $message .= "...PASS '" . $xoops_user->uname ."'[uid=".$xoops_user->uid ."](not xpress user)"; 108 if ($sync_uid != 0){ 109 $message .= '...NOT XPRESS USER ' . $xoops_user->uname; 110 return false; 118 $user_regist_time = date('Y-m-d H:i:s' , $xoops_user->user_regdate); 119 $user_status = 0; 120 $user_display_name =empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ; 121 122 $is_update = false; 123 124 $wp_user_id = get_wp_user_id($xoops_user->uname) ; 125 if ($wp_user_id){ 126 $wu_sql = "UPDATE $db_xpress_users "; 127 $wu_sql .= 'SET '; 128 $wu_sql .= "user_pass = '$xoops_user->pass', "; 129 $wu_sql .= "user_email = '$xoops_user->email', "; 130 $wu_sql .= "user_url = '$xoops_user->url', "; 131 $wu_sql .= "user_nicename = '$xoops_user->uname', "; 132 $wu_sql .= "user_registered = '$user_regist_time', "; 133 $wu_sql .= "user_status = 0 "; 134 $wu_sql .= "WHERE (user_login = '$xoops_user->uname' )"; 135 136 $xoops_db->query($wu_sql); 137 if ($allway_update){ 138 $sycc_user = new WP_User($wp_user_id); 139 $sycc_user->set_role($capabillities_name); 140 $message .= '...UPDATE ' . $user_login_name . '(' . $capabillities_name . ')'; 141 142 } else { 143 $message .= '...UPDATE ' . $user_login_name . '(Level Not Change)'; 111 144 } 112 } else { 113 $user_regist_time = date('Y-m-d H:i:s' , $xoops_user->user_regdate); 114 $user_status = 0; 115 $user_display_name =empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ; 116 117 $is_update = false; 118 119 $wp_user_id = get_wp_user_id($xoops_user->uname) ; 120 if ($wp_user_id){ 121 $wu_sql = "UPDATE $db_xpress_users "; 122 $wu_sql .= 'SET '; 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', "; 127 $wu_sql .= "user_registered = '$user_regist_time', "; 128 $wu_sql .= "user_status = 0 "; 129 $wu_sql .= "WHERE (user_login = '$xoops_user->uname' )"; 130 131 $xoops_db->query($wu_sql); 132 if ($allway_update){ 133 $sycc_user = new WP_User($wp_user_id); 134 $sycc_user->set_role($capabillities_name); 135 $message .= '...UPDATE ' . $user_login_name . '(' . $capabillities_name . ')'; 136 137 } else { 138 $message .= '...UPDATE ' . $user_login_name . '(Level Not Change)'; 139 } 140 }else{ 141 $wu_sql = "INSERT INTO $db_xpress_users "; 142 $wu_sql .= "(user_login , user_pass ,user_email , user_url , user_nicename " ; 143 $wu_sql .= " , user_registered , user_status , display_name) "; 144 $wu_sql .= "VALUES "; 145 $wu_sql .= "('$xoops_user->uname', '$xoops_user->pass', '$xoops_user->email', '$xoops_user->url', '$xoops_user->uname' "; 146 $wu_sql .= " , '$user_regist_time', $user_status, '$user_display_name')"; 147 $xoops_db->query($wu_sql); 145 }else{ 146 $wu_sql = "INSERT INTO $db_xpress_users "; 147 $wu_sql .= "(user_login , user_pass ,user_email , user_url , user_nicename " ; 148 $wu_sql .= " , user_registered , user_status , display_name) "; 149 $wu_sql .= "VALUES "; 150 $wu_sql .= "('$xoops_user->uname', '$xoops_user->pass', '$xoops_user->email', '$xoops_user->url', '$xoops_user->uname' "; 151 $wu_sql .= " , '$user_regist_time', $user_status, '$user_display_name')"; 152 $xoops_db->query($wu_sql); 148 153 // $wp_user_id = get_wp_user_id($user_login_name) ; 149 $wp_user_id = mysql_insert_id(); 150 $sycc_user = new WP_User($wp_user_id); 151 $sycc_user->set_role($capabillities_name); 152 $message .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . ')'; 153 } 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); 169 if ($is_update === false ) { 170 update_usermeta( $wp_user_id,'rich_editing',$user_rich_editing); 171 } 172 } 173 } 174 $message .= "...END"; 175 return true; 176 } 154 $wp_user_id = mysql_insert_id(); 155 $sycc_user = new WP_User($wp_user_id); 156 $sycc_user->set_role($capabillities_name); 157 $message .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . ')'; 158 } 159 160 $user_nickname = empty($xoops_user->name) ? $xoops_user->uname :$xoops_user->name ; 161 $user_rich_editing = 'true'; 162 $user_first_name = $xoops_user->uname; 163 $user_last_name = ''; 164 $user_description = ''; 165 $user_jabber = ''; 166 167 update_usermeta( $wp_user_id,'nickname',$user_nickname); 168 update_usermeta( $wp_user_id,'first_name',$user_first_name); 169 update_usermeta( $wp_user_id,'last_name',$user_last_name); 170 update_usermeta( $wp_user_id,'description',$user_description); 171 update_usermeta( $wp_user_id,'jabber',$user_jabber); 172 update_usermeta( $wp_user_id,'aim',$xoops_user->user_aim); 173 update_usermeta( $wp_user_id,'yim',$xoops_user->user_yim); 174 if ($is_update === false ) { 175 update_usermeta( $wp_user_id,'rich_editing',$user_rich_editing); 176 } 177 } 178 } 179 $message .= "...END"; 180 return true; 177 181 } 178 182
Note: See TracChangeset
for help on using the changeset viewer.