function wp_connect_login($userinfo, $tmail, $uid = '', $reg = false) { global $wpdb, $wptm_connect; $redirect_to = !empty($_SESSION['wp_url_back']) ? $_SESSION['wp_url_back'] : get_bloginfo('url'); if (!$uid && !$reg) { // 新用户 wp_connect_set_cookie("wp_connect_cookie_user", array($userinfo, $tmail, $redirect_to), BJTIMESTAMP + 600); $new_user = true; if ($userinfo[0] == 'qqtid' && empty($wptm_connect['chinese_username'])) { // QQ帐号登录,没有勾选支持中文用户名时。 $wptm_connect['reg'] = true; } } if ($new_user && $wptm_connect['reg']) { // 强制填写注册信息 return wp_connect_reg(); } $tid = $userinfo[0]; $user_name = $userinfo[1]; $user_screenname = $userinfo[2]; $user_head = $userinfo[3]; $user_siteurl = $userinfo[4]; $user_uid = $userinfo[5]; $oauth_token = $userinfo[6]; if ($user_name) { if ($new_user && in_array($user_name, explode(',', $wptm_connect['disable_username']))) { return wp_connect_reg(); } } else { wp_die("获取用户授权信息失败,请重新<a href=\"" . site_url('wp-login.php', 'login') . "\">登录</a> 或者 清除浏览器缓存再试! [ <a href='{$redirect_to}'>返回</a> ]"); } if ($uid) { $wpuid = $uid; } elseif ($new_user) { $wpuid = username_exists($user_name); if ($wpuid) { // 新注册,但是数据库存在相同的用户名 return wp_connect_reg(); } } if (!$wpuid) { if (!function_exists('wp_insert_user')) { include_once ABSPATH . WPINC . '/registration.php'; } $userdata = array('user_login' => $user_name, 'user_pass' => ifab($userinfo[8], wp_generate_password()), 'user_email' => $tmail, 'user_url' => $user_siteurl, 'user_nicename' => $user_name, 'nickname' => $user_screenname, 'display_name' => $user_screenname); $wpuid = wp_insert_user($userdata); if (!is_numeric($wpuid)) { $errors = $wpuid->errors; if ($errors['existing_user_email']) { wp_die("该电子邮件地址 {$tmail} 已被注册。 [ <a href='{$redirect_to}'>返回</a> ]"); } elseif ($errors['existing_user_login']) { wp_die("该用户名 {$user_name} 已被注册。 [ <a href='{$redirect_to}'>返回</a> ]"); } } } if ($wpuid) { $weibo = get_weibo($tid); $t = $weibo[0]; $id = $weibo[1] . 'id'; if ($tid == $id) { // UID update_usermeta($wpuid, $tid, $user_uid); } else { if ($user_head) { // 头像 update_usermeta($wpuid, $tid, $user_head); } update_usermeta($wpuid, $id, $user_uid); } update_usermeta($wpuid, 'last_login', $tid); if ($oauth_token) { // 授权信息 if ($oauth_token['access_token']) { $token = array($oauth_token['access_token'], $oauth_token['expires_in'], $user_uid, $user_name); } else { $token = array($oauth_token['oauth_token'], $oauth_token['oauth_token_secret'], $user_uid, $user_name); } update_usermeta($wpuid, 'login_' . $t, $token); if (!$uid && $wptm_connect['sync']) { // 用户首次登录的时候也绑定同步帐号 update_usermeta($wpuid, 'wptm_' . $t, $oauth_token); } if (in_array($tid, array('qtid', 'stid', 'ntid', 'shtid', 'ttid'))) { // @微博帐号 $nickname = get_user_meta($wpuid, 'login_name', true); $nickname[$t] = $t == 'qq' || $t == 'twitter' ? $user_uid : $user_screenname; update_usermeta($wpuid, 'login_name', $nickname); } } wp_set_auth_cookie($wpuid, true, false); wp_set_current_user($wpuid); } $_SESSION['wp_url_login'] = ''; wp_connect_clear_cookie("wp_connect_cookie_user"); return $wpuid; }
function connect_denglu() { if ($_GET['dl_type'] == 'create') { // 对接open.denglu.cc if (current_user_can('manage_options')) { return open_denglu_cc($_GET['token'], $_GET['mediaUserID']); } else { return wp_die('对不起,您的用户权限不够,请用管理员帐号登录操作!'); } } else { $redirect_to = isset($_GET['redirect_url']) ? $_GET['redirect_url'] : ""; if (is_user_logged_in()) { // 同步绑定 if (wp_connect_get_cookie("wp_connect_cookie_bind") == "sync") { $media = rtrim(substr($_GET['token'], 0, 2), '-'); $name = array('3' => 'sina', '4' => 'qq', '5' => 'sohu', '6' => 'netease', '7' => 'renren', '17' => 'tianya'); if ($name[$media]) { $tok = 'wptm_' . $name[$media]; if ($redirect_to == admin_url('options-general.php?page=wp-connect')) { update_option($tok, array('mediaUserID' => $_GET['mediaUserID'])); } else { if ($redirect_to == admin_url('profile.php')) { $wpuid = get_current_user_id(); } else { $parse_str = parse_url_detail($redirect_to); $wpuid = $parse_str['user_id']; } if ($wpuid) { update_usermeta($wpuid, $tok, array('mediaUserID' => $_GET['mediaUserID'])); } } } return wp_connect_clear_cookie("wp_connect_cookie_bind"); } } $user = denglu_userInfo(); // return var_dump($user); if ($username = $user['mediaUserID']) { $homepage = $user['homepage']; $mediaID = $user['mediaID']; $tid = get_tid($mediaID); $weibo = get_weibo($tid); $mid = str_replace('tid', 'mid', $tid); if ($homepage) { $id = $weibo[1] . 'id'; if ($id == 'dtid') { // douban if (strpos($user['profileImageUrl'], 'user_normal.jpg') === false) { $path = explode('/', $user['profileImageUrl']); $douban_uid = (int) substr($path[4], 1); } } $userid = str_replace($weibo[3], '', $homepage); } elseif ($tid == 'qqtid') { $id = $weibo[1] . 'id'; $path = explode('/', $user['profileImageUrl']); $userid = $path[5]; $appid = $path[4]; } else { $id = $mid; $userid = $username; } if ($user['email']) { $email = $user['email']; if ($id == 'ntid') { // netease $uid = ifabc(email_exists($email), get_user_by_meta_value($id, $userid), get_user_by_meta_value($mid, $username)); } else { // taobao,msn,facebook $uid = ifab(email_exists($email), get_user_by_meta_value($id, $userid)); } } else { $domain = ifab($weibo[4], 'denglu.cc'); if ($homepage) { $email = $userid . '@' . $domain; } elseif ($tid == 'qqtid') { $email = $appid . '/' . $userid . '@qzone.qq.com'; } else { $email = $username . '@' . $domain; } if ($id == $mid) { // google,yahoo,baidu,netease163,360,alipay $uid = get_user_by_meta_value($id, $userid); } elseif ($id == 'dtid') { // douban if ($douban_uid && $douban_uid != $userid) { $uid = ifab(get_user_by_meta_value($id, $douban_uid), get_user_by_meta_value($id, $userid)); $userid = $douban_uid; // old bug $email = $userid . '@' . $domain; } else { $uid = get_user_by_meta_value($id, $userid); } } else { // sina,tqq,sohu,netease,renren,kaixin,tianya,twitter,qq $uid = ifab(get_user_by_meta_value($id, $userid), email_exists($email)); } } if (is_user_logged_in()) { // V2.4.3,登录绑定 if ($redirect_to == admin_url('profile.php')) { $wpuid = get_current_user_id(); } else { $parse_str = parse_url_detail($redirect_to); $wpuid = $parse_str['user_id']; } if ($uid && $wpuid != $uid) { $userinfo = wp_get_user_info($uid); $user_login = $userinfo['user_login']; wp_die("很遗憾!该帐号已被用户名 {$user_login} 绑定,您可以用该 <a href=\"" . wp_logout_url() . "\">用户名</a> 登录,并到 <a href=\"" . admin_url('profile.php') . "\">我的资料</a> 页面解除绑定,再进行绑定该帐号!<strong>如果不能成功,请删除那个WP帐号,再进行绑定!</strong> <a href='{$redirect_to}'>返回</a>"); } else { update_usermeta($wpuid, $mid, $username); if ($homepage || $tid == 'qqtid') { // sina,tqq,sohu,netease,renren,kaixin,douban,tianya,twitter,facebook,qq update_usermeta($wpuid, $weibo[1] . 'id', $userid); if ($tid == 'qqtid') { update_usermeta($wpuid, $tid, $user['profileImageUrl']); } if (in_array($tid, array('qtid', 'stid', 'ntid', 'shtid', 'ttid'))) { // 微博帐号 $nickname = get_user_meta($wpuid, 'login_name', true); $nickname[$weibo[0]] = $tid == 'qtid' || $tid == 'ttid' ? $userid : $user['screenName']; update_usermeta($wpuid, 'login_name', $nickname); } } } } else { $url = ifab($user['url'], $homepage); $userinfo = array($tid, $username, $user['screenName'], $user['profileImageUrl'], $url, $userid, $username); //tid,username,nick,head,url,userid,mediaUserID if ($uid) { wp_connect_login($userinfo, $email, $uid); } elseif ($_GET['dl_type'] == 'comment') { // 从评论框登录,跳过强制填写注册信息。V2.3.3 $userinfo[1] = ifuser($userinfo[1]); wp_connect_login($userinfo, $email, '', true); } else { wp_connect_login($userinfo, $email); } } } } }
function wp_connect_login($userinfo, $tmail, $uid = '', $reg = false) { global $wpdb, $wptm_connect; $redirect_to = !empty($_GET['redirect_url']) ? $_GET['redirect_url'] : get_bloginfo('url'); if (!$uid && !$reg) { // 新用户 $new_user = true; wp_connect_set_cookie("wp_connect_cookie_user", array($userinfo, $tmail, $redirect_to), BJTIMESTAMP + 600); } if ($new_user && $wptm_connect['reg']) { // 强制填写注册信息 return wp_connect_reg(); } $tid = $userinfo[0]; $user_name = $userinfo[1]; $user_screenname = $userinfo[2]; $user_head = $userinfo[3]; $user_siteurl = $userinfo[4]; $user_uid = $userinfo[5]; $mediaUserID = $userinfo[6]; //2.0 if ($user_name) { if ($new_user && in_array($user_name, explode(',', $wptm_connect['disable_username']))) { return wp_connect_reg(); } } else { wp_die("获取用户授权信息失败,请重新<a href=\"" . site_url('wp-login.php', 'login') . "\">登录</a> 或者 清除浏览器缓存再试! [ <a href='{$redirect_to}'>返回</a> ]"); } if ($uid) { $wpuid = $uid; } elseif ($new_user) { $wpuid = username_exists($user_name); if ($wpuid) { // 新注册,但是数据库存在相同的用户名 return wp_connect_reg(); } } if (!$wpuid) { if (!function_exists('wp_insert_user')) { include_once ABSPATH . WPINC . '/registration.php'; } $userdata = array('user_login' => $user_name, 'user_pass' => ifab($userinfo[8], wp_generate_password()), 'user_email' => $tmail, 'user_url' => $user_siteurl, 'user_nicename' => $user_name, 'nickname' => $user_screenname, 'display_name' => $user_screenname); $wpuid = wp_insert_user($userdata); if (!is_numeric($wpuid)) { $errors = $wpuid->errors; if ($errors['existing_user_email']) { wp_die("该电子邮件地址 {$tmail} 已被注册。 [ <a href='{$redirect_to}'>返回</a> ]"); } elseif ($errors['existing_user_login']) { wp_die("该用户名 {$user_name} 已被注册。 [ <a href='{$redirect_to}'>返回</a> ]"); } } } if ($wpuid) { $weibo = get_weibo($tid); $t = $weibo[0]; $id = $weibo[1] . 'id'; $mid = str_replace('tid', 'mid', $tid); update_usermeta($wpuid, $mid, $mediaUserID); if ($tid == $id) { update_usermeta($wpuid, $tid, $user_uid); } elseif ($user_head) { update_usermeta($wpuid, $tid, $user_head); } if ($weibo[3] || $tid == 'qqtid') { // sina,tqq,sohu,netease,renren,kaixin,douban,qq,tianya update_usermeta($wpuid, $id, $user_uid); } if ($tid == 'guard360tid') { // 360 update_usermeta($wpuid, $id, $user_screenname); } update_usermeta($wpuid, 'last_login', $tid); if (in_array($tid, array('qtid', 'stid', 'ntid', 'shtid', 'ttid'))) { // @微博帐号 $nickname = get_user_meta($wpuid, 'login_name', true); $nickname[$t] = $tid == 'qtid' || $tid == 'ttid' ? $user_uid : $user_screenname; update_usermeta($wpuid, 'login_name', $nickname); } wp_set_auth_cookie($wpuid, true, false); wp_set_current_user($wpuid); } wp_connect_clear_cookie("wp_connect_cookie_user"); return $wpuid; }