Пример #1
0
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;
}
Пример #2
0
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;
}