手机游戏
经典单机
角色扮演
休闲益智
动作冒险
射击枪战
赛车竞速
模拟经营
解密闯关
策略战争
手机软件
时尚购物
体育运动
资讯阅读
教育学习
摄影摄像
生活服务
效率办公
聊天社交
其它软件
新闻资讯
游戏攻略
软件教程
游戏问答
软件技术
叨叨念念
网站技术
技术问答
软件教程
资源资料
原创作品
代码学习
网页设计
网络技术
合集
合集
游戏合集
软件合集
资讯合集
视频合集
首页 > 原创作品 > 原创作品

emlog评论管理添加编辑功能

作者:星知苑 时间:2013-04-24 11:21:44

emlog5.1.0beta出来了,添加了很多新功能,但是由于测试版本,所以一般不会去升级,但是很多功能还是很不错的。

emlog评论管理的编辑功能就很不错,所以就想移植进老版本,于是就有了这篇教程(emlog5.0.1)。

 

对于熟悉emlog结构的人要实现这个功能很简单,以下很多代码就是emlog5.1.0beta版本中的:

注意:修改之前请先备份网站文件。

1、修改comment_model.php评论管理的类,添加编辑评论的数据库执行语句。

文件所在位置:include/model中[break]

在类中(在function isCommentExist之前)添加以下代码

	/**
	 * 修改评论
	 *
	 * @param array $commentData
	 * @param int $commentId
	 */
	function updateComment($commentData, $commentId) {
		$Item = array();
		foreach ($commentData as $key => $data) {
			$Item[] = "$key='$data'";
		}
		$upStr = implode(',', $Item);
		$this->db->query("UPDATE " . DB_PREFIX . "comment SET $upStr WHERE cid=$commentId");
	}

 

2、接下就是修改comment.php文件,有2个文件,分别在admin文件夹和admin/views文件夹下

首先修改admin文件夹下的comment.php文件,在文件最后添加如下代码(和emlog5.1.0稍微有点不同):

if ($action== 'edit_comment') {
	include View::getView('header');
	$commentId = isset($_GET['cid']) ? intval($_GET['cid']) : '';
	$commentArray = $Comment_Model->getOneComment($commentId);
	extract($commentArray);

	require_once(View::getView('comment_edit'));
	include View::getView('footer');
	View::output();
}
if ($action=='doedit') {
	$name = isset($_POST['name']) ? addslashes(trim($_POST['name'])) : '';
    $mail = isset($_POST['mail']) ? addslashes(trim($_POST['mail'])) : '';
    $url = isset($_POST['url']) ? addslashes(trim($_POST['url'])) : '';
    $comment = isset($_POST['comment']) ? addslashes(trim($_POST['comment'])) : '';
	$commentId = isset($_POST['cid']) ? intval($_POST['cid']) : '';

	if ($comment == '') {
		emDirect("./comment.php?error_e=true");
	}
	if (strlen($comment) > 2000) {
		emDirect("./comment.php?error_d=true");
	}

    $commentData = array(
        'poster' => $name,
        'mail' => $mail,
        'url' => $url,
        'comment' => $comment,
    );

	$Comment_Model->updateComment($commentData, $commentId);
	$CACHE->updateCache('comment');
	emDirect("./comment.php?active_edit=true");
}

然后就是admin/views文件夹的comment.php文件修改:

<?php if(isset($_GET['error_d'])):?><span class="error">回复内容过长</span><?php endif;?>

//在上面这个行后面添加下面这些代码:

<?php if(isset($_GET['active_edit'])):?><span class="actived">修改评论成功</span><?php endif;?>
<?php if(isset($_GET['error_e'])):?><span class="error">评论内容不能为空</span><?php endif;?>
<a href="comment.php?action=reply_comment&amp;cid=<?php echo $value['cid']; ?>">回复</a>

//在这段代码后面添加:

<a href="comment.php?action=edit_comment&amp;cid=<?php echo $value['cid']; ?>">编辑</a>

 

3、添加comment_edit.php文件,直接从emlog5.1.0beta复制过来就可以了。

文件位置:admin/views中:comment_edit.php代码如下:

<?php if(!defined('EMLOG_ROOT')) {exit('error!');}?>
<div class=containertitle><b>编辑评论</b>
</div>
<div class=line></div>
<form action="comment.php?action=doedit" method="post">
<div class="item_edit">
	<li><input type="text" value="<?php echo $poster; ?>" name="name" style="width:200px;" /> 评论人</li>
    <li><input type="text"  value="<?php echo $mail; ?>" name="mail" style="width:200px;" /> 电子邮件</li>
	<li><input type="text"  value="<?php echo $url; ?>" name="url" style="width:200px;" /> 主页</li>
    <li>评论内容:<br /><textarea name="comment" rows="8" cols="60"><?php echo $comment; ?></textarea></li>
	<input type="hidden" value="<?php echo $cid; ?>" name="cid" />
	<input type="submit" value="保 存" class="button" />
	<input type="button" value="取 消" class="button" onclick="javascript: window.history.back();" /></li>
</div>
</form>
<script>
$("#menu_cm").addClass('sidebarsubmenu1');
</script>

 

到了这里已经可以使用编辑评论这个功能了。

提供下emlog5.0.1的覆盖包(前提是你没有修改过这几个文件),百度网盘下载。

安装说明:解压在本地文件,打开update文件夹,把include和admin文件夹FTP覆盖到网站即可。

良心推荐

花季传媒黄版3.0.3合集
  • 花季传媒黄版3.0.3app下载
  • 花季传媒黄版3.0.3免费下载
  • 花季传媒黄版3.0.3
花季传媒黄版3.0.3合集这里每天都是很欢乐的,让你从来都是可以免费的去欣赏各种好看的视频,完全是免费的,能够直接下载到手机上,也有的软件中是可以让你去真实交友的,真实是可以去约会的,很多的美女都是一直在线不断的让你看到那种动作门户的欣赏,蜜道的探索,每一种都是可以让你很欢乐,最关键的就是能够丰富的你情感生活。

相关资讯