dedecms插件开发之留言模块
1、建立基本的目录结构
首先,新建以下文件
plus/comment.php
dede/comment.php
dede/templets/comment_list.htm
dede/templets/comment_add.htm
dede/templets/comment_edit.htm
dede/templets/comment_reply.htm
2、填写插件开发者信息
打开后台->模块->模块管理->模块生成向导,按提示填写相关信息

3、填写菜单信息:
<m:top name='评论管理' c='6,' display='block' rank=''>
<m:item name='评论列表' link=comment.php' rank='' target='main' />
</m:top>
如果你不想单分出一个主菜单,而是将菜单添加到“辅助插件”下,可以在安装信息中添加下内容:
Delete From `#@__plus` where plusname like '评论管理';
INSERT INTO `#@__plus` (`plusname`, `menustring`, `mainurl`, `writer`, `isshow`, `filelist`) VALUES ('评论管理', '<m:item name=''评论管理'' link=''comment.php'' rank=''plus_评论管理'' target=''main'' />', '', '子海', 1, '');
然后在卸载信息将附加一句:
Delete From `#@__plus` where plusname like '评论管理';

4、填写安装信息:
DROP TABLE IF EXISTS `#@__comment`;
CREATE TABLE `#@__comment` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int(10) unsigned NOT NULL DEFAULT '0',
`username` varchar(10) NOT NULL DEFAULT '',
`comment` varchar(255) NOT NULL DEFAULT '',
`rank` tinyint(1) unsigned NOT NULL,
`addtime` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY(`id`)
) TYPE=MyISAM;

5、填写卸载信息:DROP TABLE IF EXISTS `#@__comment`;

6、填写文件列表
../plus/comment.php
../dede/comment.php
../dede/templets/comment_list.htm
../dede/templets/comment_add.htm
../dede/templets/comment_edit.htm
../dede/templets/comment_reply.htm
最后点击提交即可

7、后台处理文件之评论列表
$dlist = new DataListCP();
$dlist->SetTemplet(DEDEADMIN."/templets/comment_list.htm");
$sql = 'SELECT * FROM `#@__comment` ORDER BY id';
$dlist->SetSource($sql);
$dlist->display();
8、后台处理文件之添加评论
if($a== 'add'){
if(isset($_POST['send'])){
$comment = cn_substrR($comment,250);
$username = cn_substrR($username,50);
$time = time();
$sql = "INSERT INTO `#@__comment`(comment,rank,username,addtime) VALUES('$comment',$rank,'$username',$time)";
if(!$dsql->ExecuteNoneQuery($sql)){
$gerr = $dsql->GetError();
ShowMsg("回复评论出错。错误信息:".$gerr."!",'javascript:;');
exit();
}
ShowMsg("添加成功!",$ENV_GOBACK_URL);
exit();
}
include DedeInclude("templets/comment_add.htm");
}
9、后台处理文件之编辑评论
if($a == 'edit'){
if(isset($_POST['send'])){
$comment = cn_substrR($comment,250);
$username = cn_substrR($username,50);
$sql = "UPDATE `#@__comment` SET comment='$comment',username='$username',rank=$rank WHERE id=$id";
if(!$dsql->ExecuteNoneQuery($sql)){
$gerr = $dsql->GetError();
ShowMsg("修改评论出错。错误信息:".$gerr."!",'javascript:;');
exit();
}
ShowMsg("修改成功!",$ENV_GOBACK_URL);
exit();
}
if(empty($id)){
ShowMsg("参数无效!",$ENV_GOBACK_URL);
exit();
}
$row = $dsql->GetOne("SELECT * FROM `#@__comment` WHERE id='$id'");
include DedeInclude("templets/comment_edit.htm");
}

10、后台处理文件之回复评论
if($a== 'reply'){
if(isset($_POST['send'])){
$comment = cn_substrR($comment,255);
$username = cn_substrR($username,50);
$time = time();
$sql = "INSERT INTO `#@__comment`(parent_id,comment,username,addtime) VALUES($id,'$comment','$username',$time)";
if(!$dsql->ExecuteNoneQuery($sql)){
$gerr = $dsql->GetError();
ShowMsg("回复评论出错。错误信息:".$gerr."!",'javascript:;');
exit();
}
ShowMsg("回复成功!",$ENV_GOBACK_URL);
exit();
}
$row = $dsql->GetOne("SELECT * FROM `#@__comment` WHERE id='$id'");
include DedeInclude("templets/comment_reply.htm");
}

11、后台处理文件之删除评论
if($a == 'delete'){
if( !empty($aid) && empty($ids) )
{
$ids = $aid;
}
if($ids=='')
{
ShowMsg("参数无效!",$ENV_GOBACK_URL);
exit();
}
$ids_arr = explode("`",$ids);
$okaids = Array();
foreach($ids_arr as $aid)
{
if(!isset($okaids[$aid]))
{
$sql = 'DELETE FROM `#@__comment` WHERE id='.$aid;
$dsql->ExecuteNoneQuery($sql);
}
else
{
$okaids[$aid] = 1;
}
}
ShowMsg("成功删除指定的咨询!",$ENV_GOBACK_URL);
exit();
}
