网站首页 » 折腾 » Typecho评论获取QQ头像

Typecho评论获取QQ头像

March 28, 2020 折腾

Typecho默认获取的头像是Gravatar的,要修改为获取QQ的头像只需一点小改动
/var/Typecho/Common.php第986行

    public static function gravatarUrl($mail, $size, $rating, $default, $isSecure = false)
    {
        if (defined('__TYPECHO_GRAVATAR_PREFIX__')) {
            $url = __TYPECHO_GRAVATAR_PREFIX__;
        } else {
            $url = $isSecure ? 'https://secure.gravatar.com' : 'http://www.gravatar.com';
            $url .= '/avatar/';
        }

        if (!empty($mail)) {
            $url .= md5(strtolower(trim($mail)));
        }

        $url .= '?s=' . $size;
        $url .= '&r=' . $rating;
        $url .= '&d=' . $default;

        return $url;
    }

修改为

public static function gravatarUrl($mail, $size, $rating, $default, $isSecure = false)
{
        $reg = "/^\d{5,11}@[qQ][Qq]\.(com)$/";
        if (preg_match($reg, $mail)) {
            $img    = explode("@", $mail);
            $url = "//q2.qlogo.cn/headimg_dl?dst_uin={$img[0]}&spec=100";
        } else {
            if (defined('__TYPECHO_GRAVATAR_PREFIX__')) {
                $url = __TYPECHO_GRAVATAR_PREFIX__;
            } else {
                $url = $isSecure ? 'https://secure.gravatar.com' : 'http://www.gravatar.com';
                $url .= '/avatar/';
            }
            if (!empty($mail)) {
                $url .= md5(strtolower(trim($mail)));
            }
            $url .= '?s=' . $size;
            $url .= '&r=' . $rating;
            $url .= '&d=' . $default;
        }
        return $url;
}

如果找不到可以Ctrl F查找一下获取gravatar头像地址
就在注释下方

添加新评论