1.替换Gravatar头像地址方法
打开var/Typecho/Common.php,找到下面的代码,大概在939行。
public static function gravatarUrl($mail, $size, $rating, $default, $isSecure = false)
{
$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;
}
替换为:
<!--仅替换为Gravatar国内头像源-->
public static function gravatarUrl($mail, $size, $rating, $default, $isSecure = false)
{
$url = $isSecure ? 'https://cdn.v2ex.com/gravatar/' : 'https://gravatar.loli.net/avatar/';
if (!empty($mail)) {
$url .= md5(strtolower(trim($mail)));
}
$url .= '?s=' . $size;
$url .= '&r=' . $rating;
$url .= '&d=' . $default;
return $url;
}
<!--替换为QQ头像源及Gravatar国内头像源-->
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://cdn.v2ex.com/gravatar/' : 'https://gravatar.loli.net/avatar/';
}
if (!empty($mail)) {
$url .= md5(strtolower(trim($mail)));
}
$url .= '?s=' . $size;
$url .= '&r=' . $rating;
$url .= '&d=' . $default;
}
return $url;
}
2.另外一个修改方法
具体方式为在config.inc.php中加入<!--仅替换为Gravatar国内头像源-->
define('__TYPECHO_GRAVATAR_PREFIX__', 'https://cdn.v2ex.com/gravatar/');