Typecho 修改 Gravatar 镜像源(已更新)

2022-04-08T10:11:00

>2022-4-13推荐使用镜像:

https://gravatar.ucany.net/wavatar
之前发布的https://cdn.v2ex.com/gravatar已被墙了

修改过程:

  • 1:修改/var/Widget/Abstract/Comments.php文件,找到第390行,修改gravatar函数:

Comments.php修改前:

 public function gravatar($size = 32, $default = NULL)
{
    if ($this->options->commentsAvatar && 'comment' == $this->type) {
        $rating = $this->options->commentsAvatarRating;
        
        $this->pluginHandle(__CLASS__)->trigger($plugged)->gravatar($size, $rating, $default, $this);
        if (!$plugged) {
            $url = Typecho_Common::gravatarUrl($this->mail, $size, $rating, $default, $this->request->isSecure());
            echo '<img class="avatar" src="' . $url . '" alt="' .
            $this->author . '" width="' . $size . '" height="' . $size . '" />';
        }
    }
}

Comments.php修改后:

 public function gravatar($size = 32, $default = NULL)
{
    if ($this->options->commentsAvatar && 'comment' == $this->type) {
        $rating = $this->options->commentsAvatarRating;
        
        $this->pluginHandle(__CLASS__)->trigger($plugged)->gravatar($size, $rating, $default, $this);
        if (!$plugged) {
            //$url = Typecho_Common::gravatarUrl($this->mail, $size, $rating, $default, $this->request->isSecure());
            $mailHash = NULL;
        if (!empty($this->mail)) {
            $mailHash = md5(strtolower($this->mail));
        }
        //$url = 'https://cdn.v2ex.com/gravatar/';
        $url = 'https://gravatar.ucany.net/wavatar/';
        if (!empty($this->mail)){
            $url .= $mailHash;
        }
        $url .= '?s=' . $size;
        $url .= '&r=' . $rating;
        $url .= '&d=' . $default;
            echo '<img class="avatar" src="' . $url . '" alt="' .
            $this->author . '" width="' . $size . '" height="' . $size . '" />';
        }
    }
}
  • 2:进入varTypecho文件夹,修改Common.php文件937、938行

Common.php修改前

$url = $isSecure ? 'https://secure.gravatar.com' : 'http://www.gravatar.com';
        $url .= '/avatar/';

Common.php修改后

$url = $isSecure ? 'https://gravatar.ucany.net' : 'http://gravatar.ucany.net';
        $url .= '/wavatar/';
  • 3.网站根目录下的config.inc.php,新增行

define('__TYPECHO_GRAVATAR_PREFIX__', 'https://gravatar.ucany.net/wavatar/');

修改完毕,网站就能正常显示头像了。

> 2022-10-22 更新镜像:

https://gravatar.loli.net/avatar/
http://gravatar.loli.net/avatar/
Typecho更换Gravatar头像镜像方法还是参考之前的修改替换就可以了。

> 2022-10-23 更新镜像:

https://gravatar.ntnas.top/avatar/
http://gravatar.ntnas.top/avatar/
Typecho更换Gravatar头像镜像方法还是参考之前的修改替换就可以了。

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »