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_avatar($avatar, $id_or_email = '', $size = '32') { global $comment; if (is_numeric($id_or_email)) { $uid = $userid = (int) $id_or_email; $user = get_userdata($uid); if ($user) { $email = $user->user_email; } } elseif (is_object($comment)) { $uid = $comment->user_id; $email = $comment->comment_author_email; } elseif (is_object($id_or_email)) { $uid = $id_or_email->user_id; $email = $id_or_email->user_email; } else { $uid = email_exists($id_or_email); $email = $id_or_email; } if (!$email) { return $avatar; } if ($uid) { $tname = array('@t.sina.com.cn' => 'stid', '@t.qq.com' => 'qtid', '@renren.com' => 'rtid', '@kaixin001.com' => 'ktid', '@douban.com' => 'dtid', '@t.sohu.com' => 'shtid', '@t.163.com' => 'ntid', '@baidu.com' => 'bdtid', '@tianya.cn' => 'tytid', '@twitter.com' => 'ttid'); $tmail = strstr($email, '@'); $tid = ifab(get_user_meta($uid, 'last_login', true), $tname[$tmail]); if ($tid) { if ($head = get_user_meta($uid, $tid, true)) { $weibo = get_weibo($tid); $out = $weibo[5] ? str_replace('[head]', $head, $weibo[5]) : $head; $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />"; if ($weibo[3]) { $username = get_user_meta($uid, $weibo[1] . 'id', true); if ($username) { $url = $weibo[3] . $username; if (is_admin()) { if (!is_admin_footer()) { $avatar = "<a href='{$url}' target='_blank'>{$avatar}</a>"; } } elseif (!$userid) { $avatar = "<a href='{$url}' target='_blank'>{$avatar}</a>"; } } } } } elseif ($out = get_user_meta($uid, 'qqtid', true)) { $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />"; } elseif ($out = get_user_meta($uid, 'tbtid', true)) { $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />"; } } return $avatar; }
function wp_connect_avatar($avatar, $id_or_email = '', $size = '32') { global $comment, $parent_file, $wp_version; if (is_numeric($id_or_email)) { $uid = $userid = (int) $id_or_email; $user = get_userdata($uid); if ($user) { $email = $user->user_email; } } elseif (is_object($comment)) { $uid = $comment->user_id; $email = $comment->comment_author_email; $author_url = $comment->comment_author_url; if ($author_url && strpos($author_url, 'http://weibo.com/') === 0) { $weibo_uid = ltrim($author_url, 'http://weibo.com/'); $out = 'http://tp' . rand(1, 4) . '.sinaimg.cn/' . $weibo_uid . '/50/0/1'; return "<a href='{$author_url}' rel='nofollow' target='_blank'><img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' /></a>"; } if ($uid) { $user = get_userdata($uid); } } elseif (is_object($id_or_email)) { $user = $id_or_email; $uid = $user->user_id; $email = ifab($user->comment_author_email, $user->user_email); } else { $email = $id_or_email; if ($parent_file != 'options-general.php') { $user = get_user_by_email($email); $uid = $user->ID; } } if (!$email) { return $avatar; } if ($uid) { $tid = $user->last_login; if (!$tid) { $tname = array('@t.sina.com.cn' => 'stid', '@weibo.com' => 'stid', '@t.qq.com' => 'qtid', '@renren.com' => 'rtid', '@kaixin001.com' => 'ktid', '@douban.com' => 'dtid', '@t.sohu.com' => 'shtid', '@t.163.com' => 'ntid', '@baidu.com' => 'bdtid', '@tianya.cn' => 'tytid', '@twitter.com' => 'ttid'); $tmail = strstr($email, '@'); $tid = $tname[$tmail]; } if ($tid) { if ($tid == 'qqtid' && !$user->qqid || $tid == 'tbtid' && !$user->taobaoid) { return $avatar; } if ($head = $user->{$tid}) { $weibo = get_weibo($tid); $out = $weibo[5] ? str_replace('[head]', $head, $weibo[5]) : $head; $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />"; if ($weibo[3]) { $oid = $weibo[1] . 'id'; $username = $user->{$oid}; if ($username) { $url = $weibo[3] . $username; if ($userid) { if (is_admin()) { if (version_compare($wp_version, '3.4', '<')) { if (!is_admin_footer()) { $avatar = "<a href='{$url}' target='_blank'>{$avatar}</a>"; } } else { if (is_admin_footer()) { $avatar = "<a href='{$url}' target='_blank'>{$avatar}</a>"; } } } } else { $avatar = "<a href='{$url}' rel='nofollow' target='_blank'>{$avatar}</a>"; } } } } } elseif ($user->qqid && ($out = $user->qqtid)) { $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />"; } elseif ($user->taobaoid && ($out = $user->tbtid)) { $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />"; } } return $avatar; }