简述
我上一个用的主题是有博主标记的。然后网上也看到了很多typecho等级划分的代码。那我就打算把两者所结合,用户等级+用户身份融合在一起显示。
考虑+实现,花了个把小时,算是完成了吧!
效果
说明
- 用户身份:博主、基友、博友。(基友是直接配置,博友是友链抓取)
- 除以上三种身份以外,由评论数量作为等级划分依据。
- 除博主和基友不显示评论数量以外,其他访客均显示评论量。名称指代为:
目的地的前进步数
。 - 鼠标经过后,会显示目的地前进步数。如果是友链博友的话,还会一并显示友链描述信息。
留言1条:您已经向目的地迈出了第一步。
留言2条+:您已经向目的地前进了XX步。
也算是正好和网站名称所契合吧!
functions.php
纯手打啊,我是纯按自己想法来的,各位按自己的主题风格改写。基友邮箱请按格式自行添加。友链数据是从数据库likns表中获取的。如果你是别的友链方式,那就按别的方式来。举一反三,举二反六。实在不会,再留言吧!
/**
* 评论者认证等级 + 身份
*
* @author Chrison
* @access public
* @param str $email 评论者邮址
* @return result
*/
function commentApprove($widget, $email = NULL)
{
$result = array(
"state" => -1,//状态
"isAuthor" => 0,//是否是博主
"userLevel" => '',//用户身份或等级名称
"userDesc" => '',//用户title描述
"bgColor" => '',//用户身份或等级背景色
"commentNum" => 0//评论数量
);
if (empty($email)) return $result;
$result['state'] = 1;
$master = array(
'基友邮箱1@qq.com',
'基友邮箱1@qq.com'
);
if ($widget->authorId == $widget->ownerId) {
$result['isAuthor'] = 1;
$result['userLevel'] = '博主';
$result['userDesc'] = '很帅的博主';
$result['bgColor'] = '#FFD67A';
$result['commentNum'] = 999;
} else if (in_array($email, $master)) {
$result['userLevel'] = '基友';
$result['userDesc'] = '很帅的基友';
$result['bgColor'] = '#65C186';
$result['commentNum'] = 888;
} else {
//数据库获取
$db = Typecho_Db::get();
//获取评论条数
$commentNumSql = $db->fetchAll($db->select(array('COUNT(cid)'=>'commentNum'))
->from('table.comments')
->where('mail = ?', $email));
$commentNum = $commentNumSql[0]['commentNum'];
//获取友情链接
$linkSql = $db->fetchAll($db->select()->from('table.links')
->where('user = ?',$email));
//等级判定
if($commentNum==1){
$result['userLevel'] = '初识';
$result['bgColor'] = '#999999';
$userDesc = '你已经向目的地迈出了第一步!';
} else {
if ($commentNum<3 && $commentNum>1) {
$result['userLevel'] = '初识';
$result['bgColor'] = '#999999';
}elseif ($commentNum<9 && $commentNum>=3) {
$result['userLevel'] = '朋友';
$result['bgColor'] = '#A0DAD0';
}elseif ($commentNum<27 && $commentNum>=9) {
$result['userLevel'] = '好友';
$result['bgColor'] = '#A0DAD0';
}elseif ($commentNum<81 && $commentNum>=27) {
$result['userLevel'] = '挚友';
$result['bgColor'] = '#A0DAD0';
}elseif ($commentNum<100 && $commentNum>=81) {
$result['userLevel'] = '兄弟';
$result['bgColor'] = '#A0DAD0';
}elseif ($commentNum>=100) {
$result['userLevel'] = '老铁';
$result['bgColor'] = '#A0DAD0';
}
$userDesc = '你已经向目的地前进了'.$commentNum.'步!';
}
if($linkSql){
$result['userLevel'] = '博友';
$result['bgColor'] = '#21b9bb';
$userDesc = '🔗'.$linkSql[0]['description'].' ✌️'.$userDesc;
}
$result['userDesc'] = $userDesc;
$result['commentNum'] = $commentNum;
}
return $result;
}
调用方法
评论中调用上面的方法<?php $commentApprove = commentApprove($comments, $comments->mail); ?>
。返回以下四个数据。
$commentApprove['state'] //状态
$commentApprove['isAuthor'] //是否是博主
$commentApprove['userLevel'] //用户身份或等级名称
$commentApprove['userDesc'] //用户title描述
$commentApprove['bgColor'] //用户身份或等级背景色
$commentApprove['commentNum'] //评论数量
具体html代码,请根据自己主题调整样式。
<?php $commentApprove = commentApprove($comments, $comments->mail); ?>
<h4 class="author" title="<?php echo $commentApprove['userDesc'] ?>">
<a href="<?php $comments->url(); ?>">
<img alt="<?php $comments->author(false); ?>" src="<?php echo $avatar ?>" srcset="<?php echo $avatar2x ?> 2x" class="avatar avatar-50 photo" height="50" width="50"/>
<?php $comments->author(false); ?>
<span class="isauthor" title="Author">
<span title="<?php echo $commentApprove['userDesc'] ?>" style="background:<?php echo $commentApprove['bgColor'] ?>;"><?php echo $commentApprove['userLevel'] ?></span>
<?php if ($commentApprove['isAuthor'] == 1){ ?>
<i title="<?php echo $commentApprove['userDesc'] ?>" class="iconfont"></i>
<?php } ?>
</span>
</a>
</h4>
哎呀~请问调用方法肿么搞呀?是在哪个文件里添加?
@柳橙睿 : 你和我是同主题,就在comments.php评论文件,但我改过文件,行数可能不一样。<section class="commeta"><div class="left">的下面。你试试
@Chrison : 测试,附件已发送
哈哈,无折腾不生活。
@wu先生 : 最近也折腾不起来了
已经使用上,感谢感谢
@sagrre : 客气啦
最近发现好多博客都在搞这个
@I'M代代付 : 多吗。哈哈哈。都爱折腾
一直想弄这个功能,但不知怎么整合到第三方的评论系统~
@Teacher Du : 第三方是什么?php的话,估计大差不多。可能需要研究吧
谁是你基友~噫~~~
@无言的结局 : 那你走远点
更新频率有点高👍🏻
@大湿兄 : 到处逛,到处参😝
第几步了?
@荒野孤灯 : 啊?在这现学啊,代码不是发你了😂
@荒野孤灯 : 就这些了。没了。一共就两段代码
@Chrison : 666 ,搞起来
@荒野孤灯 : 你网站手机版导航栏没了?是取消了还是出错了?
@Chrison : 还在,注释了……
@荒野孤灯 : 搜嘎