作者:星知苑 时间:2013-04-19 19:36:30
最近无聊对emlog后台程序修改了很多,添加了很多小功能,方便自己的管理操作,老是直接修改数据库很烦。
废话不多说了,这次就emlog后台评论管理中的评论者下面添加2个小功能——屏蔽昵称和删除网址。
别看就这2个功能,要修改的地方还是蛮多的。
include/model文件夹下的评论类comment_model.php,admin文件夹下的comment.php,admin/views文件夹下的comment.php,以及admin/views/js的common.js,接下来就是修改这4个文件。
因为这是HACK程序,请先备份程序。[break]
1、修改comment_model.php,在大概174行左右添加下面2个函数。
function delurlComment($commentId) { $row = $this->db->once_fetch_array("SELECT gid FROM ".DB_PREFIX."comment WHERE cid=$commentId"); $blogId = intval($row['gid']); $commentIds = array($commentId); /* 获取子评论ID */ $query = $this->db->query("SELECT cid,pid FROM ".DB_PREFIX."comment WHERE gid=$blogId AND cid>$commentId "); while ($row = $this->db->fetch_array($query)) { if (in_array($row['pid'],$commentIds)) { $commentIds[] = $row['cid']; } } $commentIds = implode(',',$commentIds); $this->db->query("UPDATE ".DB_PREFIX."comment SET url='' WHERE cid IN ($commentIds)"); $this->updateCommentNum($blogId); } function delnameComment($commentId) { $row = $this->db->once_fetch_array("SELECT gid FROM ".DB_PREFIX."comment WHERE cid=$commentId"); $blogId = intval($row['gid']); $commentIds = array($commentId); /* 获取子评论ID */ $query = $this->db->query("SELECT cid,pid FROM ".DB_PREFIX."comment WHERE gid=$blogId AND cid>$commentId "); while ($row = $this->db->fetch_array($query)) { if (in_array($row['pid'],$commentIds)) { $commentIds[] = $row['cid']; } } $commentIds = implode(',',$commentIds); $this->db->query("UPDATE ".DB_PREFIX."comment SET poster='该昵称被屏蔽' WHERE cid IN ($commentIds)"); $this->updateCommentNum($blogId); }
注1:上面代码中poster='该昵称被屏蔽',改为'游客'的话,如果后台屏蔽后前台就会显示为'游客'。
修改comment_model.php中的批量处理评论,修改如下:
/** * 批量处理评论 */ function batchComment($action, $comments) { switch ($action) { case 'delcom': foreach($comments as $val) { $this->delComment($val); } break; case 'hidecom': foreach($comments as $val) { $this->hideComment($val); } break; case 'showcom': foreach($comments as $val) { $this->showComment($val); } break; case 'delurlcom': foreach($comments as $val) { $this->delurlComment($val); } break; case 'delnamecom': foreach($comments as $val) { $this->delnameComment($val); } break; } }
2、修改admin的comment.php文件,大概在文件的47行添加如下代码:
if ($action=='delurl') { $id = isset($_GET['id']) ? intval($_GET['id']) : ''; $Comment_Model->delurlComment($id); $CACHE->updateCache(array('sta','comment')); emDirect("./comment.php?active_delurl=true"); } if ($action=='delname') { $id = isset($_GET['id']) ? intval($_GET['id']) : ''; $Comment_Model->delnameComment($id); $CACHE->updateCache(array('sta','comment')); emDirect("./comment.php?active_delname=true"); }
然后在做了如上修改的情况下,大概在84行添加如下代码:
if ($operate == 'delurl') { $Comment_Model->batchComment('delurlcom', $comments); $CACHE->updateCache(array('sta','comment')); emDirect("./comment.php?active_delurl=true"); } if ($operate == 'delname') { $Comment_Model->batchComment('delnamecom', $comments); $CACHE->updateCache(array('sta', 'comment')); emDirect("./comment.php?active_delname=true"); }
注2:上面2段代码多是加在comment.php?active_show=true后面的大括号后就可以了。
3、admin/views中的comment.php,这个主要是后台显示的。
大概在3行“删除评论成功”下一行添加如下代码:
<?php if(isset($_GET['active_delname'])):?><span class="actived">屏蔽昵称成功</span><?php endif;?> <?php if(isset($_GET['active_delurl'])):?><span class="actived">删除地址成功</span><?php endif;?>
搜索<?php echo $ip;?>,在这个后面添加如下代码:
<br /> <span style="display:none;"> <a href="javascript: em_confirm(<?php echo $value['cid']; ?>, 'delname');">屏蔽昵称</a> <a href="javascript: em_confirm(<?php echo $value['cid']; ?>, 'delurl');">删除地址</a> </span>
搜索<a href="javascript:commentact('pub');">审核</a>,在这个后面添加如下代码:
<a href="javascript:commentact('delurl');">删除地址</a> <a href="javascript:commentact('delname');">屏蔽昵称</a>
搜索if(act == 'del' && !confirm('你确定要删除所选评论吗?')){return;},在这个后面添加如下代码:
if(act == 'delname' && !confirm('你确定要屏蔽所选评论的评论人昵称吗?')){return;} if(act == 'delurl' && !confirm('你确定要删除所选评论的评论人地址吗?')){return;}
4、修改admin/views/js的common.js
在var msg = "你确定要删除该评论吗?";break;后面添加如下代码:
case 'delname': var urlreturn="comment.php?action=delname&id="+id; var msg = "你确定要屏蔽所选评论的评论人昵称吗?";break; case 'delurl': var urlreturn="comment.php?action=delurl&id="+id; var msg = "你确定要删除所选评论的评论人地址吗?";break;
到了这里差不多改完了。
修改好的文件包,百度网盘,ftp上传覆盖即可。
来几张演示图: