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&cid=<?php echo $value['cid']; ?>">回复</a> //在这段代码后面添加: <a href="comment.php?action=edit_comment&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覆盖到网站即可。