V9 让前台用户能管理自己发表的文章的评论

修改两处和添加一个模版页面
1、修改phpcms/modules/member/content.php

新添加两个函数用于显示评论和删除评论

/*评论列表*/
public function comment_list() {
$memberinfo = $this->memberinfo;
$_username = $this->memberinfo[‘username’];
$_userid = $this->memberinfo[‘userid’];
$commentid = isset($_GET[‘commentid’]) && trim(urldecode($_GET[‘commentid’])) ? trim(urldecode($_GET[‘commentid’])) : $this->_show_msg(L(‘illegal_parameters’));
list($module,$contentid, $siteid) = explode(‘-‘, $commentid);
$pagesize = 20;
$page = max(intval($_GET[‘page’]),1);
$comment_db = pc_base::load_model(‘comment_model’);
$comment_data_db = pc_base::load_model(‘comment_data_model’);
$comment = $comment_db->get_one(array(‘commentid’=>$commentid, ‘siteid’=>$siteid));
if ($comment){
$comment_data_db->table_name($comment[‘tableid’]);
$comment_info = $comment_data_db->listinfo(Array(‘commentid’=>$commentid,’status’=>1) , ‘id desc’, $page);
$pages = $comment_data_db->pages;
}
/**/
include template(‘member’, ‘comment_list’);
}
/*评论列表*/
public function comment_del() {
$memberinfo = $this->memberinfo;
$_username = $this->memberinfo[‘username’];
$_userid = $this->memberinfo[‘userid’];
$commentid = isset($_GET[‘commentid’]) && trim(urldecode($_GET[‘commentid’])) ? trim(urldecode($_GET[‘commentid’])) : $this->_show_msg(L(‘illegal_parameters’));
$id = isset($_GET[‘id’]) && trim(urldecode($_GET[‘id’])) ? trim(urldecode($_GET[‘id’])) : $this->_show_msg(L(‘illegal_parameters’));
list($module,$contentid, $siteid) = explode(‘-‘, $commentid);
list($modulename,$catid) = explode(‘_’,$module);
//判断管理权限
$this->content_db = pc_base::load_model(‘content_model’);
$this->content_db->set_catid($catid);
$table_name = $this->content_db->table_name;
$this->content_db->table_name = $table_name;
if($this->content_db->get_one(array(‘id’=>$contentid,’username’=>$_username))){
$comment_db = pc_base::load_model(‘comment_model’);
$comment_data_db = pc_base::load_model(‘comment_data_model’);
$comment = $comment_db->get_one(array(‘commentid’=>$commentid, ‘siteid’=>$siteid));
if ($comment){
$comment_data_db->table_name($comment[‘tableid’]);
if($comment_data_db->delete(Array(‘id’=>$id,’commentid’=>$commentid))){
$comment_db->update(‘total=total-1’,array(‘commentid’=>$commentid, ‘siteid’=>$siteid));
}
showmessage(‘ok’, APP_PATH.’index.php?m=member&c=content&a=published’);
}
}else{
showmessage(‘error’, APP_PATH.’index.php?m=member&c=content&a=published’);
}

}

 

放到content.php页面最后一个大括号上面

 

2、修改phpcms/templates/default/member/content_published.html
修改已发布文章列表模版
其实就是在后面加个按钮,点击能进入评论列表页

找到<font color=”red”>{L(‘edit’)}</font></a>{/if},然后在后面添加

|<?php $commentid = id_encode(“content_$info[catid]”,$info[id],$info[siteid]);?><a href=”index.php?m=member&c=content&a=comment_list&commentid={$commentid}”><font color=”red”>评论</font></a>

k

 

3、新加一个页面用来显示当前文章的评论列表,我是直接拿content_published.html复制了一份直接改的,o(∩_∩)o,不怎么美观但是能用就行了,美化页面那是美工的工作,先实现功能再说呗

哦,是utf-8的,GBK的自己打开复制粘贴就行了,放在phpcms/templates/default/member/目录下

其实最复杂的地方就在于判断这个人能不能管理这条评论,因为有人会伪造评论的id号啊,所以必须得保证这条评论是这个人能管的

 

标签

发表评论