EXCMS 评论文件
来自站长百科
导航:返回上一页
EXCMS的模块评论文件为:comment.php,用于评论动作处理,包括评论列表、增加评论、引用评论、评论支持数、反对数、文章评论列表、加载评论配置信息 。
代码[ ]
001 <?php 002 /** 003 * Project: EXCMS: the PHP content management system. 004 * File: comment.php 005 * * A product of SINOICAN Inc. 006 * 007 * EXCMS is a ten million data-level,high speed,human-based content management system. 008 * 009 * EX is Excellence & Express & Exceed & Expert. 010 * 011 * For questions, help, comments, discussion, please join the 012 * EXCMS mailing list. Send a blank e-mail to 013 * excms@sinoican.com 014 * or join the EXCMS forum 015 * www.excms.cn/forum 016 * 017 * @link http://www.excms.cn/ 018 * @copyright Copyright (c) 2007-2009 SINOICAN Inc. 019 * @license http://www.excms.cn/licenses/LICENSE-1.0 020 * @category EXCMS 021 * @author $Author: zhangxuelin $ 022 * @version $Rev: 15 $ 023 */ 024 025 /* $Id: comment.php 15 2009-10-27 09:31:46Z zhangxuelin $ */ 026 027 /** 028 * 网站评论动作程序 029 */ 030 031 //加载系统配置文件 032 include_once '../configuration/inc/common.inc.php'; 033 034 $params = array_merge ( $_POST, $_GET, $_REQUEST ); 035 $_PAGE_CONTENT = array('contentid'=>$params ['contentid']); 036 $contentid = excms_func_id_decode ( $params ['contentid'] ); 037 $_PAGE_CONTENT['original_contentid']=$contentid; 038 //获取模块配置信息 039 excms_import ( 'EXCMS.modules.Modules' ); 040 $module = new Modules ( ); 041 $moduleInfo = $module->getById ( 'comment' ); 042 //引入评论类Comment,创建评论对像Comment 043 excms_import ( 'EXCMS.comment.Comment' ); 044 $comment = new Comment ( ); 045 046 switch ($params ['act']){ 047 /** 048 * 添加评论 049 */ 050 case 'submit' : 051 @session_start (); 052 if (isset ( $EXCMS['comment']['checkcodes'] ) && $EXCMS['comment'] ['checkcodes'] == 1 && !excms_func_checkcode_check($params ['checkcodes'])) { 053 showMessage('验证码错误'); 054 } 055 //文章信息 056 excms_import ( 'EXCMS.content.Content' ); 057 $c = new Content ( ); 058 $cInfo = $c->getById ( $contentid ); 059 //栏目信息 060 excms_import ( 'EXCMS.channel.Channel' ); 061 $channel = new Channel ( ); 062 $channelInfo = $channel->getById ( $cInfo['channelid'] ); 063 if (! ($channelInfo ['comment'] > 0)) { 064 showMessage('文章不允许评论(栏目)'); 065 } 066 if (!$cInfo ['comment']) { 067 showMessage('文章不允许评论(文章)'); 068 } 069 if (! ($moduleInfo ['disabled'])) { 070 showMessage('评论已经禁用'); 071 } 072 if (! ($EXCMS['comment'] ['allow_guest'] > 0) && ! ($_SESSION ['memberid'] > 0)) { 073 showMessage('请登录后再评论'); 074 } 075 076 $data ['memberid'] = $_SESSION ['memberid'] > 0 ? $_SESSION ['memberid'] : 0; 077 $data ['membername'] = $_SESSION ['membername'] ? $_SESSION ['membername'] : '游客'; 078 079 if ($EXCMS['comment'] ['anonymous'] && $params ['anonymous']) { //匿名评论 080 $data ['memberid'] = 0; 081 $data ['membername'] = '游客'; 082 } 083 excms_import ( 'EXCMS.comment.Comment' ); 084 $comment = new Comment ( ); 085 $ip = $_SERVER ["REMOTE_ADDR"]; 086 if($EXCMS['comment']['allow_hide_ip'] && !$params['allow_hide_ip']){ //是否允许隐藏IP 087 $data ['ip'] = $ip; 088 } 089 if($EXCMS['comment']['allow_hide_posion'] && !$params['allow_hide_posion']){ //是否允许隐藏所在位置 090 include_once(DOCUMENT_ROOT.'admin/Modules/Plugins/Ipquery/IpLocation.class.php'); 091 $obj = new IpLocation(); 092 $iparea = $obj->getlocation($ip); 093 $data ['area'] = isset($iparea ['country']) && !empty($iparea ['country']) ? $iparea ['country'] : $ip; //所在地区 094 } 095 $data ['itemid'] = $contentid; 096 $data ['channelid'] = $cInfo ['channelid']; 097 $data ['channelcross'] = $cInfo ['channelcross']; 098 $data ['createddate'] = time (); 099 $data['support'] = 0; 100 $data['against'] = 0; 101 $replyid = (int)$params['reply']; 102 if($replyid){ 103 $replyInfo = $comment->getById($replyid); 104 $data ['replyid'] = $replyid; 105 $data ['floor'] = $replyInfo['floor'] + 1; 106 107 $lastFloor = $replyInfo['floor'] > 1 ? $replyInfo['lastfloor'] : ''; 108 //id=\"commentid_{\$replyid}_{$replyInfo['floor']}_head\" 109 $data['lastfloor'] = "<div class="\"cmt_old\"">".$lastFloor. 110 "<div class="\"cmt_old_head\"">". 111 "<div class="\"cmt_old_info\""><span class="\"cmt_sitename\"">EXCMS</span>". 112 "<span class="\"cmt_old_author\"">{$replyInfo['area']}网友(".ipformat($replyInfo['ip']).") 的原贴:</span></div>". 113 "<span class="\"cmt_old_floor\"">{$replyInfo['floor']}</span></div>". 114 "<p class="\"cmt_old_message\"">{$replyInfo['content']}</p></div>"; 115 }else{ 116 $data ['replyid'] = 0; 117 $data ['floor'] = 1; 118 $data['lastfloor'] = ''; 119 } 120 $data ['content'] = htmlspecialchars($_POST['commenttext']); 121 $comment->insert($data,"content"); 122 header("Location:comment.php?contentid=".icanid($contentid)); 123 break; 124 /** 125 * 引用评论 126 */ 127 case 'getquote' : 128 //根据评论ID查询评论详细信息 129 $rs = $comment->getById($params['id']); 130 $rs['createddate'] = formatDate('Y-m-d H:i:s',$rs['createddate']); 131 echo "[quote]原文由 EXCMS{$rs['area']}网友[{$rs['membername']}]于{$rs['createddate']}发表".chr(13)."{$rs['content']}[/quote]"; 132 break; 133 /** 134 * 支持数 135 */ 136 case 'support' : 137 echo $comment->support($params['id']); 138 break; 139 /** 140 * 反对数 141 */ 142 case 'against' : 143 echo $comment->against($params['id']); 144 break; 145 /** 146 * 文章评论列表 147 */ 148 case 'commentlist' : 149 excms_func_templateDisplay('comment_list.html'); 150 break; 151 /** 152 * 加载评论配置信息 153 */ 154 case 'loadcommentconfig' : 155 excms_func_json_print($EXCMS['comment']); 156 break; 157 /** 158 * 评论列表 159 */ 160 default: 161 $_PAGE['type'] = $_GET['type']; 162 $_PAGE['pageon'] = excms_func_page_decode ( $_GET ['page'] ); 163 //获取内容信息 164 excms_import('EXCMS.content.Content'); 165 $c = new Content ( ); 166 $_PAGE_CONTENT = $c->getById ( $contentid ); 167 $_PAGE_CONTENT['original_contentid'] = $contentid; 168 $_PAGE_CONTENT['contentid'] = excms_func_id_encode($contentid); 169 170 //获取栏目信息 171 excms_import('EXCMS.channel.Channel'); 172 $channel = new Channel ( ); 173 $_PAGE_CHANNEL = excms_func_getChannelCacheById($_PAGE_CONTENT['channelid']); 174 if (! ($_PAGE_CHANNEL ['comment'] > 0) || !$_PAGE_CONTENT['comment'] || ! ($moduleInfo['disabled']>0)) { 175 showMessage('本文章不允许评论'); 176 } 177 178 excms_import("EXCMS.update.ContentFunction"); 179 $_PAGE_CONTENT['href'] = ContentFunction::getContentUrl($_PAGE_CONTENT); 180 181 if(!in_array($_PAGE['type'], array('hot', 'support', 'against'))){ 182 $_PAGE['type'] = 'all'; 183 } 184 185 excms_import('EXCMS.comment.Comment'); 186 $cmt = new Comment(); 187 $_PAGE['comment']['url'] = ereg_replace('{contentid}',$_GET['contentid'],$EXCMS['comment']['rewrite_url']); 188 $_PAGE['comment']['total'] = $cmt->getCountByItemId($contentid);; 189 $_PAGE['comment']['shownum'] = $_PAGE['comment']['total']; 190 191 excms_func_templateDisplay('comment.html'); 192 break; 193 194 } 195 ?>
代码说明[ ]
- 检查验证码是否开启验证码并判断验证码是否正确。
1 if (isset ( $EXCMS['comment']['checkcodes'] ) && $EXCMS['comment'] ['checkcodes'] == 1 && !excms_func_checkcode_check($params ['checkcodes'])) { 2 showMessage('验证码错误'); 3 }
- 根据内容ID获取内容详细信息,如果内容ID为空会报缺少内空ID异常。
1 //文章信息 2 excms_import ( 'EXCMS.content.Content' ); 3 $c = new Content ( ); 4 $cInfo = $c->getById ( $contentid );
- 根据栏目ID获取栏目详细信息,如果栏目ID为空会报缺少栏目ID异常。
1 //栏目信息 2 excms_import ( 'EXCMS.channel.Channel' ); 3 $channel = new Channel ( ); 4 $channelInfo = $channel->getById ( $cInfo['channelid'] );
- 验证当前内容是否允许评论并且是否需要登陆。
01 if (! ($channelInfo ['comment'] > 0)) { 02 showMessage('文章不允许评论(栏目)'); 03 } 04 if (!$cInfo ['comment']) { 05 showMessage('文章不允许评论(文章)'); 06 } 07 if (! ($moduleInfo ['disabled'])) { 08 showMessage('评论已经禁用'); 09 } 10 if (! ($EXCMS['comment'] ['allow_guest'] > 0) && ! ($_SESSION ['memberid'] > 0)) { 11 showMessage('请登录后再评论'); 12 }
- 检查是否是匿名评论。
1 $data ['memberid'] = $_SESSION ['memberid'] > 0 ? $_SESSION ['memberid'] : 0; 2 $data ['membername'] = $_SESSION ['membername'] ? $_SESSION ['membername'] : '游客'; 3 4 if ($EXCMS['comment'] ['anonymous'] && $params ['anonymous']) { //匿名评论 5 $data ['memberid'] = 0; 6 $data ['membername'] = '游客'; 7 }
- 检查是否允许隐藏IP和所在位置,可以通过评论的后台管理设置这些配置信息。
01 $ip = $_SERVER ["REMOTE_ADDR"]; 02 if($EXCMS['comment']['allow_hide_ip'] && !$params['allow_hide_ip']){ //是否允许隐藏IP 03 $data ['ip'] = $ip; 04 } 05 if($EXCMS['comment']['allow_hide_posion'] && !$params['allow_hide_posion']){ //是否允许隐藏所在位置 06 include_once(DOCUMENT_ROOT.'admin/Modules/Plugins/Ipquery/IpLocation.class.php'); //引入 IplLocation类 07 $obj = new IpLocation(); //创建IpLocation对像 08 $iparea = $obj->getlocation($ip); //根据IP地址获取所有地区 09 $data ['area'] = isset($iparea ['country']) && !empty($iparea ['country']) ? $iparea ['country'] : $ip; //所在地区 10 }
- 把评论信息存入在$data数组中。
1 $data ['itemid'] = $contentid; //内容ID(必须) 2 $data ['channelid'] = $cInfo ['channelid']; //栏目ID(必须) 3 $data ['channelcross'] = $cInfo ['channelcross']; //交叉栏目ID 4 $data ['createddate'] = time (); //评论时间 5 $data['support'] = 0; //支持数 6 $data['against'] = 0; //反对数
- 如果当前回复的是评论,根据评论ID获取评论相关信息,然后存后到最上层内容中。
01 $replyid = (int)$params['reply']; 02 if($replyid){ 03 $replyInfo = $comment->getById($replyid); 04 $data ['replyid'] = $replyid; 05 $data ['floor'] = $replyInfo['floor'] + 1; 06 07 $lastFloor = $replyInfo['floor'] > 1 ? $replyInfo['lastfloor'] : ''; 08 //id=\"commentid_{\$replyid}_{$replyInfo['floor']}_head\" 09 $data['lastfloor'] = "<div class="\"cmt_old\"">".$lastFloor. 10 "<div class="\"cmt_old_head\"">". 11 "<div class="\"cmt_old_info\""><span class="\"cmt_sitename\"">EXCMS</span>". 12 "<span class="\"cmt_old_author\"">{$replyInfo['area']}网友(".ipformat($replyInfo['ip']).") 的原贴:</span></div>". 13 "<span class="\"cmt_old_floor\"">{$replyInfo['floor']}</span></div>". 14 "<p class="\"cmt_old_message\"">{$replyInfo['content']}</p></div>"; 15 }else{ 16 $data ['replyid'] = 0; 17 $data ['floor'] = 1; 18 $data['lastfloor'] = ''; 19 }
- 保存评论信息并跳转到当前内容评论列表。
1 $data ['content'] = htmlspecialchars($_POST['commenttext']); 2 $comment->insert($data,"content"); 3 header("Location:comment.php?contentid=".icanid($contentid));
代码修改[ ]
页面参数可以自由修改,根据模板的需要来增加和修改页面参数。模板中可自由调用页面的参数,例如:{$_PAGE.title}显示页面标题。