dedecms是國內最知名的PHP開源網站管理系統,也是使用用戶最多的PHP類CMS系統,有眾多個人站長的擁躉。也是初級php程序員必需熟悉的主流程序。因為項目中要新增留言評論功能,而dedecms官方的留言板有些雞肋,所以自已動手開發評論插件
方法/步驟
建立基本的目錄結構
首先,新建以下文件
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
填寫插件開發者信息
打開後臺->模塊->模塊管理->模塊生成嚮導,按提示填寫相關信息
填寫菜單信息:
如果你不想單分出一個主菜單,而是將菜單添加到“輔助插件”下,可以在安裝信息中添加下內容:
Delete From `#@__plus` where plusname like '評論管理';
INSERT INTO `#@__plus` (`plusname`, `menustring`, `mainurl`, `writer`, `isshow`, `filelist`) VALUES ('評論管理', '
然後在卸載信息將附加一句:
Delete From `#@__plus` where plusname like '評論管理';
填寫安裝信息:
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;
填寫卸載信息:DROP TABLE IF EXISTS `#@__comment`;
填寫文件列表
../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
最後點擊提交即可
後臺處理文件之評論列表
$dlist = new DataListCP();
$dlist->SetTemplet(DEDEADMIN."/templets/comment_list.htm");
$sql = 'SELECT * FROM `#@__comment` ORDER BY id';
$dlist->SetSource($sql);
$dlist->display();
後臺處理文件之添加評論
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");
}
後臺處理文件之編輯評論
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");
}
後臺處理文件之回覆評論
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");
}
後臺處理文件之刪除評論
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();
}