前言
Gravatar 目前新手要去玩耍已经比较麻烦了,而老鸟的头像想在博客中正常的显示也成了一大问题,说道镜像大家首先想到的肯定是多说的,可问题是多说的镜像不支持 HTTPS 啊,全站 HTTPS 的网站必须是挂的。所以我们搬出更多的镜像。
镜像大全
以下是部分 Gravatar 镜像地址:Https源:https://secure.gravatar.com (兼容性最高,国内可以访问)多说源:http://gravatar.duoshuo.com (延时较低,不支持 HTTPS,兼容性一般)
CN源:http://cn.gravatar.com (兼容性最高,国内可以访问,其实也支持 HTTPS)
@源:http://gravatar.com (兼容性最高,国内部分可以访问,其实也支持 HTTPS)
七牛镜像源:http://avacdn.qiniudn.com (延时较低,不支持 HTTPS,兼容性较低)
七牛镜像 HTTPS 源:https://dn-avacdn.qbox.me (延时较低,支持 HTTPS,兼容性较低)
function unblock_gravatar( $avatar ) {
$avatar = str_replace( array( 'http://www.gravatar.com', 'http://0.gravatar.com', 'http://1.gravatar.com', 'http://2.gravatar.com' ), '<strong>你要使用的源</strong>', $avatar );
return $avatar;
}
add_filter( 'get_avatar', 'unblock_gravatar' );
请参考:http://devework.com/qiniu-cache-acceleration-gravatar-problem.html
或者:http://immmmm.com/use-qiniu-cache-gravatar.html
function fa_cache_avatar($avatar, $id_or_email, $size, $default, $alt)
{
$avatar = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $avatar);
$tmp = strpos($avatar, 'http');
$url = get_avatar_url( $id_or_email, $size ) ;
$url = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $url);
$avatar2x = get_avatar_url( $id_or_email, ( $size * 2 ) ) ;
$avatar2x = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $avatar2x);
$g = substr($avatar, $tmp, strpos($avatar, "'", $tmp) - $tmp);
$tmp = strpos($g, 'avatar/') + 7;
$f = substr($g, $tmp, strpos($g, "?", $tmp) - $tmp);
$w = home_url();
$e = ABSPATH .'avatar/'. $size . '*'. $f .'.jpg';
$e2x = ABSPATH .'avatar/'. ( $size * 2 ) . '*'. $f .'.jpg';
$t = 1209600;
if ( (!is_file($e) || (time() - filemtime($e)) > $t) && (!is_file($e2x) || (time() - filemtime($e2x)) > $t ) ) {
copy(htmlspecialchars_decode($g), $e);
copy(htmlspecialchars_decode($avatar2x), $e2x);
} else { $avatar = $w.'/avatar/'. $size . '*'.$f.'.jpg';
$avatar2x = $w.'/avatar/'. ( $size * 2) . '*'.$f.'.jpg';
if (filesize($e) < 1000) copy($w.'/avatar/default.jpg', $e);
if (filesize($e2x) < 1000) copy($w.'/avatar/default.jpg', $e2x);
$avatar = "<img alt='{$alt}' src='{$avatar}' srcset='{$avatar2x}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
return $avatar;
}
add_filter('get_avatar', 'fa_cache_avatar',1,5);
$mailHash = NULL;
if (!empty($this->mail)) {
$mailHash = md5(strtolower($this->mail));
}
$url = 'https://secure.gravatar.com/avatar/';
if (!empty($this->mail)) {$url .= $mailHash;}
$url .= '?s=' . $size;
$url .= '&r=' . $rating;
$url .= '&d=' . $default;
//$url = Typecho_Common::gravatarUrl($this->mail, $size, $rating, $default, $this->request->isSecure());
* 获取Gravatar头像
* http://en.gravatar.com/site/implement/images/
* @param $email
* @param $s size
* @param $d default avatar
* @param $g
*/
function getGravatar($email, $s = 40, $d = 'mm', $g = 'g') {
$hash = md5($email);
$avatar = "<strong>http://www.gravatar.com</strong>/avatar/$hash?s=$s&d=$d&r=$g";
return $avatar;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。