方法一:直接调用多说的头像缓存
将下面的代码复制到模板文件module.php中
<?php //blog-tool:获取Gravatar头像 function DuoshuoGravatar($email, $s = 40, $d = ’mm’, $g = ’g’) { $hash = md5($email); $avatar = "http://gravatar.duoshuo.com/avatar/$hash?s=$s&d=$d&r=$g"; return $avatar; } ?>
将module.php中所有的getGravatar替换为DuoshuoGravatar。
方法二:将多说的头像缓存到本地 将下面的代码复制到模板文件module.php中
<?php //Custom:获取模板目录名称 function get_template_name(){ $template_name = str_replace(BLOG_URL,"",TEMPLATE_URL); $template_name = str_replace("content/templates/","",$template_name); $template_name = str_replace("/","",$template_name); return $template_name; } ?> <?php //blog-tool:获取Gravatar头像并缓存到本地 function MyGravatar($email, $s=40, $d=’monsterid’, $r=’g’) { $f = md5($email); $a = TEMPLATE_URL.’avatar/’.$f.’.jpg’; $e = EMLOG_ROOT.’/content/templates/’.get_template_name().’/avatar/’.$f.’.jpg’; $t = 1296000; //15天,单位:秒 if (empty($d)) $d = BLOG_URL.’avatar/default.jpg’; if (!is_file($e) || (time() - filemtime($e)) > $t ) { //当头像不存在或者超过15天才更新 $g = sprintf("http://gravatar.duoshuo.com",(hexdec($f{0})%2)).’/avatar/’.$f.’?s=48&d=’.$d.’&r=’.$r; copy($g,$e); $a=$g; //新头像copy时, 取gravatar显示 } if (filesize($e) < 500) copy($d,$e); return $a; } ?>在模板文件夹新建名为avatar的文件夹,将module.php中的getGravatar替换为MyGravatar。
修改完成后刷新两次网页,查看头像路径为本地路径即设置成功。
如gravatar网站恢复正常,不需使用上述功能时,删除上述代码,将MyGravatar或者DuoshuoGravatar替换为原来的getGravatar即可。方法三:(这个方法比较靠谱)
由于Gravatar网站被墙后,很多网站使用Gravatar头像作为评论头像的功能都失效了,一打开网站所有的Gravatar头像头挂了,看上去很不美观;蓝叶分享一个在网上找到的方法,使EMLOG评论Gravatar头像不在失效;首先登陆你的网站FTP里面,进入includelib目录下面,把function.base.php文件下载到本地并使用编辑器打开,查找
www.gravatar.com并替换为gravatar.duoshuo.com保存上传覆盖到空间里去,刷新下页面你就会看到已经挂了的Gravatar头像已经显示了。 如果你想让匿名头像显示的其它样式,只需要把$d=’mm’里的mm替换成monsterid就可以了。蔡二超整理于网络发布于记忆时光|二超博客
来学习学习,我已解?问题了,谢谢!
@李明:你怎么解决的呢?方法学习一下啊
@5258:博友投稿的。/?post=395
曾经尝试过emlog,但没有正式使用过
@自由草:emlong貌似还是不错的
地球磁场
测试一下头像
@紫月潇然:你的头像还是空的