Typecho评论获取QQ头像

折腾

Typecho评论获取QQ头像

Typecho默认获取的头像是`Gravatar`的,要修改为获取QQ的头像只需一点小改动

/var/Typecho/Common.php第986行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
}

修改为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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头像地址
就在注释下方

Comments