国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

352 lines
13KB

  1. <?php
  2. /**
  3. *
  4. * Ajax评论
  5. *
  6. * @version $Id: feedback_ajax.php 1 15:38 2010年7月8日Z tianya $
  7. * @package DedeCMS.Site
  8. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  9. * @license http://help.dedecms.com/usersguide/license.html
  10. * @link http://www.dedecms.com
  11. */
  12. require_once(dirname(__FILE__).'/../include/common.inc.php');
  13. require_once(DEDEINC.'/channelunit.func.php');
  14. AjaxHead();
  15. if($cfg_feedback_forbid=='Y') exit('系统已经禁止评论功能!');
  16. $aid = intval($aid);
  17. if(empty($aid)) exit('没指定评论文档的ID,不能进行操作!');
  18. include_once(DEDEINC.'/memberlogin.class.php');
  19. $cfg_ml = new MemberLogin();
  20. if(empty($dopost)) $dopost = '';
  21. $page = empty($page) || $page<1 ? 1 : intval($page);
  22. $pagesize = 10;
  23. /*----------------------
  24. 获得指定页的评论内容
  25. function getlist(){ }
  26. ----------------------*/
  27. if($dopost=='getlist')
  28. {
  29. $totalcount = GetList($page);
  30. GetPageList($pagesize, $totalcount);
  31. exit();
  32. }
  33. /*----------------------
  34. 发送评论
  35. function send(){ }
  36. ----------------------*/
  37. else if($dopost=='send')
  38. {
  39. require_once(DEDEINC.'/charset.func.php');
  40. //检查验证码
  41. if($cfg_feedback_ck=='Y')
  42. {
  43. $svali = strtolower(trim(GetCkVdValue()));
  44. if(strtolower($validate) != $svali || $svali=='')
  45. {
  46. ResetVdValue();
  47. echo '<font color="red">验证码错误,请点击验证码图片更新验证码!</font>';
  48. exit();
  49. }
  50. }
  51. $arcRow = GetOneArchive($aid);
  52. if(empty($arcRow['aid']))
  53. {
  54. echo '<font color="red">无法查看未知文档的评论!</font>';
  55. exit();
  56. }
  57. if(isset($arcRow['notpost']) && $arcRow['notpost']==1)
  58. {
  59. echo '<font color="red">这篇文档禁止评论!</font>';
  60. exit();
  61. }
  62. if( $cfg_soft_lang != 'utf8' )
  63. {
  64. $msg = UnicodeUrl2Gbk($msg);
  65. if(!empty($username)) $username = UnicodeUrl2Gbk($username);
  66. }
  67. //词汇过滤检查
  68. if( $cfg_notallowstr != '' )
  69. {
  70. if(preg_match("#".$cfg_notallowstr."#i", $msg))
  71. {
  72. echo "<font color='red'>评论内容含有禁用词汇!</font>";
  73. exit();
  74. }
  75. }
  76. if( $cfg_replacestr != '' )
  77. {
  78. $msg = preg_replace("#".$cfg_replacestr."#i", '***', $msg);
  79. }
  80. if( empty($msg) )
  81. {
  82. echo "<font color='red'>评论内容可能不合法或为空!</font>";
  83. exit();
  84. }
  85. if($cfg_feedback_guest == 'N' && $cfg_ml->M_ID < 1)
  86. {
  87. echo "<font color='red'>管理员禁用了游客评论!<a href='{$cfg_cmspath}/member/login.php'>点击登录</a></font>";
  88. exit();
  89. }
  90. //检查用户
  91. $username = empty($username) ? '游客' : $username;
  92. if(empty($notuser)) $notuser = 0;
  93. if($notuser==1)
  94. {
  95. $username = $cfg_ml->M_ID > 0 ? '匿名' : '游客';
  96. }
  97. else if($cfg_ml->M_ID > 0)
  98. {
  99. $username = $cfg_ml->M_UserName;
  100. }
  101. else if($username!='' && $pwd!='')
  102. {
  103. $rs = $cfg_ml->CheckUser($username, $pwd);
  104. if($rs==1)
  105. {
  106. $dsql->ExecuteNoneQuery("Update `#@__member` set logintime='".time()."',loginip='".GetIP()."' where mid='{$cfg_ml->M_ID}'; ");
  107. }
  108. $cfg_ml = new MemberLogin();
  109. }
  110. //检查评论间隔时间
  111. $ip = GetIP();
  112. $dtime = time();
  113. if(!empty($cfg_feedback_time))
  114. {
  115. //检查最后发表评论时间,如果未登录判断当前IP最后评论时间
  116. $where = ($cfg_ml->M_ID > 0 ? "WHERE `mid` = '$cfg_ml->M_ID' " : "WHERE `ip` = '$ip' ");
  117. $row = $dsql->GetOne("SELECT dtime FROM `#@__feedback` $where ORDER BY `id` DESC ");
  118. if(is_array($row) && $dtime - $row['dtime'] < $cfg_feedback_time)
  119. {
  120. ResetVdValue();
  121. echo '<font color="red">管理员设置了评论间隔时间,请稍等休息一下!</font>';
  122. exit();
  123. }
  124. }
  125. $face = 1;
  126. extract($arcRow, EXTR_SKIP);
  127. $msg = cn_substrR(TrimMsg($msg), 500);
  128. $username = cn_substrR(HtmlReplace($username,2), 20);
  129. if(empty($feedbacktype) || ($feedbacktype!='good' && $feedbacktype!='bad'))
  130. {
  131. $feedbacktype = 'feedback';
  132. }
  133. //保存评论内容
  134. if(!empty($fid))
  135. {
  136. $row = $dsql->GetOne("SELECT username,msg from `#@__feedback` WHERE id ='$fid' ");
  137. $qmsg = '{quote}{content}'.$row['msg'].'{/content}{title}'.$row['username'].' 的原帖:{/title}{/quote}';
  138. $msg = addslashes($qmsg).$msg;
  139. }
  140. $ischeck = ($cfg_feedbackcheck=='Y' ? 0 : 1);
  141. $arctitle = addslashes(RemoveXSS($title));
  142. $typeid = intval($typeid);
  143. $feedbacktype = preg_replace("#[^0-9a-z]#i", "", $feedbacktype);
  144. $inquery = "INSERT INTO `#@__feedback`(`aid`,`typeid`,`username`,`arctitle`,`ip`,`ischeck`,`dtime`, `mid`,`bad`,`good`,`ftype`,`face`,`msg`)
  145. VALUES ('$aid','$typeid','$username','$arctitle','$ip','$ischeck','$dtime', '{$cfg_ml->M_ID}','0','0','$feedbacktype','$face','$msg'); ";
  146. $rs = $dsql->ExecuteNoneQuery($inquery);
  147. if( !$rs )
  148. {
  149. echo "<font color='red'>发表评论出错了!</font>";
  150. //echo $dslq->GetError();
  151. exit();
  152. }
  153. $newid = $dsql->GetLastID();
  154. //给文章评分
  155. if($feedbacktype=='bad')
  156. {
  157. $dsql->ExecuteNoneQuery("UPDATE `#@__archives` SET scores=scores-{cfg_feedback_sub},badpost=badpost+1,lastpost='$dtime' WHERE id='$aid' ");
  158. }
  159. else if($feedbacktype=='good')
  160. {
  161. $dsql->ExecuteNoneQuery("UPDATE `#@__archives` SET scores=scores+{$cfg_feedback_add},goodpost=goodpost+1,lastpost='$dtime' WHERE id='$aid' ");
  162. }
  163. else
  164. {
  165. $dsql->ExecuteNoneQuery("UPDATE `#@__archives` SET scores=scores+1,lastpost='$dtime' WHERE id='$aid' ");
  166. }
  167. //给用户增加积分
  168. if($cfg_ml->M_ID > 0)
  169. {
  170. $dsql->ExecuteNoneQuery("UPDATE `#@__member` set scores=scores+{$cfg_sendfb_scores} WHERE mid='{$cfg_ml->M_ID}' ");
  171. $row = $dsql->GetOne("SELECT COUNT(*) AS nums FROM `#@__feedback` WHERE `mid`='".$cfg_ml->M_ID."'");
  172. $dsql->ExecuteNoneQuery("UPDATE `#@__member_tj` SET `feedback`='$row[nums]' WHERE `mid`='".$cfg_ml->M_ID."'");
  173. }
  174. $_SESSION['sedtime'] = time();
  175. if($ischeck==0)
  176. {
  177. echo '<font color="red">成功发表评论,但需审核后才会显示你的评论!</font>';
  178. exit();
  179. }
  180. else
  181. {
  182. $spaceurl = '#';
  183. if($cfg_ml->M_ID > 0) $spaceurl = "{$cfg_memberurl}/index.php?uid=".urlencode($cfg_ml->M_LoginID);
  184. $id = $newid;
  185. $msg = stripslashes($msg);
  186. $msg = str_replace('<', '&lt;', $msg);
  187. $msg = str_replace('>', '&gt;', $msg);
  188. helper('smiley');
  189. $msg = RemoveXSS(Quote_replace(parseSmileys($msg, $cfg_cmspath.'/images/smiley')));
  190. //$msg = RemoveXSS(Quote_replace($msg));
  191. if($feedbacktype=='bad') $bgimg = 'cmt-bad.gif';
  192. else if($feedbacktype=='good') $bgimg = 'cmt-good.gif';
  193. else $bgimg = 'cmt-neu.gif';
  194. global $dsql, $aid, $pagesize, $cfg_templeturl;
  195. if($cfg_ml->M_ID==""){
  196. $mface=$cfg_cmspath."/member/templets/images/dfboy.png";
  197. } else {
  198. $row = $dsql->GetOne("SELECT face,sex FROM `#@__member` WHERE mid={$cfg_ml->M_ID} ");
  199. if(empty($row['face']))
  200. {
  201. if($row['sex']=="女") $mface=$cfg_cmspath."/member/templets/images/dfgirl.png";
  202. else $mface=$cfg_cmspath."/member/templets/images/dfboy.png";
  203. }
  204. }
  205. ?>
  206. <div class='decmt-box2'>
  207. <ul>
  208. <li> <a href='<?php echo $spaceurl; ?>' class='plpic'><img src='<?php echo $mface;?>' height='40' width='40'/></a> <span class="title"><a href="<?php echo $spaceurl; ?>"><?php echo $username; ?></a></span>
  209. <div class="comment_act"><span class="fl"><?php echo GetDateMk($dtime); ?>发表</span></div>
  210. <div style="clear:both"><?php echo ubb($msg); ?></div>
  211. <div class="newcomment_act"><span class="fr"><span id='goodfb<?php echo $id; ?>'> <a href='#goodfb<?php echo $id; ?>' onclick="postBadGood('goodfb',<?php echo $id; ?>);">支持</a>[0] </span> <span id='badfb<?php echo $id; ?>'> <a href='#badfb<?php echo $id; ?>' onclick="postBadGood('badfb',<?php echo $id; ?>);">反对</a>[0] </span> <span class='quote'>
  212. <!--<a href='/plus/feedback.php?aid=<?php echo $id; ?>&fid=<?php echo $id; ?>&action=quote'>[引用]</a>-->
  213. <a href='javascript:ajaxFeedback(<?php echo $id; ?>,<?php echo $id; ?>,"quote");'>[引用]</a> </span></span></div>
  214. </li>
  215. <div id="ajaxfeedback_<?php echo $id; ?>"></div>
  216. </ul>
  217. </div>
  218. <br style='clear:both' />
  219. <?php
  220. }
  221. exit();
  222. }
  223. /**
  224. * 读取列表内容
  225. *
  226. * @param int $page 页码
  227. * @return string
  228. */
  229. function GetList($page=1)
  230. {
  231. global $dsql, $aid, $pagesize, $cfg_templeturl,$cfg_cmspath;
  232. $querystring = "SELECT fb.*,mb.userid,mb.face as mface,mb.spacesta,mb.scores,mb.sex FROM `#@__feedback` fb
  233. LEFT JOIN `#@__member` mb on mb.mid = fb.mid WHERE fb.aid='$aid' AND fb.ischeck='1' ORDER BY fb.id DESC";
  234. $row = $dsql->GetOne("SELECT COUNT(*) AS dd FROM `#@__feedback` WHERE aid='$aid' AND ischeck='1' ");
  235. $totalcount = (empty($row['dd']) ? 0 : $row['dd']);
  236. $startNum = $pagesize * ($page-1);
  237. if($startNum > $totalcount)
  238. {
  239. echo "参数错误!";
  240. return $totalcount;
  241. }
  242. $dsql->Execute('fb', $querystring." LIMIT $startNum, $pagesize ");
  243. while($fields = $dsql->GetArray('fb'))
  244. {
  245. if($fields['userid']!='') $spaceurl = $GLOBALS['cfg_memberurl'].'/index.php?uid='.$fields['userid'];
  246. else $spaceurl = '#';
  247. if($fields['username']=='匿名') $spaceurl = '#';
  248. $fields['bgimg'] = 'cmt-neu.gif';
  249. $fields['ftypetitle'] = '该用户表示中立';
  250. if($fields['ftype']=='bad')
  251. {
  252. $fields['bgimg'] = 'cmt-bad.gif';
  253. $fields['ftypetitle'] = '该用户表示差评';
  254. }
  255. else if($fields['ftype']=='good')
  256. {
  257. $fields['bgimg'] = 'cmt-good.gif';
  258. $fields['ftypetitle'] = '该用户表示好评';
  259. }
  260. if(empty($fields['mface']))
  261. {
  262. if($fields['sex']=="女") $fields['mface']=$cfg_cmspath."/member/templets/images/dfgirl.png";
  263. else $fields['mface']=$cfg_cmspath."/member/templets/images/dfboy.png";
  264. }
  265. $fields['face'] = empty($fields['face']) ? 6 : $fields['face'];
  266. $fields['msg'] = str_replace('<', '&lt;', $fields['msg']);
  267. $fields['msg'] = str_replace('>', '&gt;', $fields['msg']);
  268. helper('smiley');
  269. $fields['msg'] = RemoveXSS(Quote_replace(parseSmileys($fields['msg'], $cfg_cmspath.'/images/smiley')));
  270. extract($fields, EXTR_OVERWRITE);
  271. ?>
  272. <div class="decmt-box2">
  273. <ul>
  274. <li> <a href='<?php echo $spaceurl; ?>' class='plpic'><img src='<?php echo $mface;?>' height='40' width='40'/></a> <span class="title"><a href="<?php echo $spaceurl; ?>"><?php echo $username; ?></a></span>
  275. <div class="comment_act"><span class="fl"><?php echo GetDateMk($dtime); ?>发表</span></div>
  276. <div style="clear:both"><?php echo ubb($msg); ?></div>
  277. <div class="newcomment_act"><span class="fr"><span id='goodfb<?php echo $id; ?>'> <a href='#goodfb<?php echo $id; ?>' onclick="postBadGood('goodfb',<?php echo $id; ?>);">支持</a>[<?php echo $good; ?>] </span> <span id='badfb<?php echo $id; ?>'> <a href='#badfb<?php echo $id; ?>' onclick="postBadGood('badfb',<?php echo $id; ?>);">反对</a>[<?php echo $bad; ?>] </span> <span class='quote'>
  278. <!--<a href='/plus/feedback.php?aid=<?php echo $id; ?>&fid=<?php echo $id; ?>&action=quote'>[引用]</a>-->
  279. <a href='javascript:ajaxFeedback(<?php echo $id; ?>,<?php echo $id; ?>,"quote");'>[引用]</a> </span></span></div>
  280. </li>
  281. </ul>
  282. <div id="ajaxfeedback_<?php echo $id; ?>"></div>
  283. </div>
  284. <?php
  285. }
  286. return $totalcount;
  287. }
  288. /**
  289. * 获取分页列表
  290. *
  291. * @param int $pagesize 显示条数
  292. * @param int $totalcount 总数
  293. * @return string
  294. */
  295. function GetPageList($pagesize, $totalcount)
  296. {
  297. global $page;
  298. $curpage = empty($page) ? 1 : intval($page);
  299. $allpage = ceil($totalcount / $pagesize);
  300. if($allpage < 2)
  301. {
  302. echo '';
  303. return ;
  304. }
  305. echo "
  306. <div id='commetpages'>";
  307. echo "<span>总: {$allpage} 页/{$totalcount} 条评论</span> ";
  308. $listsize = 5;
  309. $total_list = $listsize * 2 + 1;
  310. $totalpage = $allpage;
  311. $listdd = '';
  312. if($curpage-1 > 0 )
  313. {
  314. echo "<a href='#commettop' onclick='LoadCommets(".($curpage-1).");'>上一页</a> ";
  315. }
  316. if($curpage >= $total_list)
  317. {
  318. $j = $curpage - $listsize;
  319. $total_list = $curpage + $listsize;
  320. if($total_list > $totalpage)
  321. {
  322. $total_list = $totalpage;
  323. }
  324. }
  325. else
  326. {
  327. $j = 1;
  328. if($total_list > $totalpage) $total_list = $totalpage;
  329. }
  330. for($j; $j <= $total_list; $j++)
  331. {
  332. echo ($j==$curpage ? "<strong>$j</strong> " : "<a href='#commettop' onclick='LoadCommets($j);'>{$j}</a> ");
  333. }
  334. if($curpage+1 <= $totalpage )
  335. {
  336. echo "<a href='#commettop' onclick='LoadCommets(".($curpage+1).");'>下一页</a> ";
  337. }
  338. echo "</div>
  339. ";
  340. }