解决Typecho Gravatar头像无法加载的问题

前言

Typecho评论默认使用的是Gravatar头像,但因为Gravatar网站总是被墙,导致页面加载被拖慢,而且加载半天也还是个裂图,太影响心情,所以我们可以不使用Gravatar头像,换成另一个头像源,改变这个,其实只需要修改很少量的代码就可以了,见下:

代码

1.找到/var/Widget/Abstract/Comments.php,并打开
2.找到第390行,看到gravatar函数,并修改该函数,改成如下代码:


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://secure.gravatar.com/avatar/';
            $url = 'https://cdn.v2ex.com/gravatar/';
            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 . '" />';
        }
    }
}

结语

保存即可,这样的话,使用的就是v2ex的头像了,速度很快具体速度可以看我的站点:https://www.meitubk.com/

猜你喜欢

转载自www.cnblogs.com/meitubk/p/12751406.html