国内流行的内容管理系统(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.

370 lines
14KB

  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. #api{{
  171. if(defined('UC_API') && @include_once DEDEROOT.'/api/uc.func.php')
  172. {
  173. //同步积分
  174. uc_credit_note($cfg_ml->M_LoginID, $cfg_sendfb_scores);
  175. //推送事件
  176. $arcRow = GetOneArchive($aid);
  177. $feed['icon'] = 'thread';
  178. $feed['title_template'] = '<b>{username} 在网站发表了评论</b>';
  179. $feed['title_data'] = array('username' => $cfg_ml->M_UserName);
  180. $feed['body_template'] = '<b>{subject}</b><br>{message}';
  181. $url = !strstr($arcRow['arcurl'],'http://') ? ($cfg_basehost.$arcRow['arcurl']) : $arcRow['arcurl'];
  182. $feed['body_data'] = array('subject' => "<a href=\"".$url."\">$arcRow[arctitle]</a>", 'message' => cn_substr(strip_tags(preg_replace("/\[.+?\]/is", '', $msg)), 150));
  183. $feed['images'][] = array('url' => $cfg_basehost.'/images/scores.gif', 'link'=> $cfg_basehost);
  184. uc_feed_note($cfg_ml->M_LoginID,$feed); unset($arcRow);
  185. }
  186. #/aip}}
  187. $dsql->ExecuteNoneQuery("UPDATE `#@__member` set scores=scores+{$cfg_sendfb_scores} WHERE mid='{$cfg_ml->M_ID}' ");
  188. $row = $dsql->GetOne("SELECT COUNT(*) AS nums FROM `#@__feedback` WHERE `mid`='".$cfg_ml->M_ID."'");
  189. $dsql->ExecuteNoneQuery("UPDATE `#@__member_tj` SET `feedback`='$row[nums]' WHERE `mid`='".$cfg_ml->M_ID."'");
  190. }
  191. $_SESSION['sedtime'] = time();
  192. if($ischeck==0)
  193. {
  194. echo '<font color="red">成功发表评论,但需审核后才会显示你的评论!</font>';
  195. exit();
  196. }
  197. else
  198. {
  199. $spaceurl = '#';
  200. if($cfg_ml->M_ID > 0) $spaceurl = "{$cfg_memberurl}/index.php?uid=".urlencode($cfg_ml->M_LoginID);
  201. $id = $newid;
  202. $msg = stripslashes($msg);
  203. $msg = str_replace('<', '&lt;', $msg);
  204. $msg = str_replace('>', '&gt;', $msg);
  205. helper('smiley');
  206. $msg = RemoveXSS(Quote_replace(parseSmileys($msg, $cfg_cmspath.'/images/smiley')));
  207. //$msg = RemoveXSS(Quote_replace($msg));
  208. if($feedbacktype=='bad') $bgimg = 'cmt-bad.gif';
  209. else if($feedbacktype=='good') $bgimg = 'cmt-good.gif';
  210. else $bgimg = 'cmt-neu.gif';
  211. global $dsql, $aid, $pagesize, $cfg_templeturl;
  212. if($cfg_ml->M_ID==""){
  213. $mface=$cfg_cmspath."/member/templets/images/dfboy.png";
  214. } else {
  215. $row = $dsql->GetOne("SELECT face,sex FROM `#@__member` WHERE mid={$cfg_ml->M_ID} ");
  216. if(empty($row['face']))
  217. {
  218. if($row['sex']=="女") $mface=$cfg_cmspath."/member/templets/images/dfgirl.png";
  219. else $mface=$cfg_cmspath."/member/templets/images/dfboy.png";
  220. }
  221. }
  222. ?>
  223. <div class='decmt-box2'>
  224. <ul>
  225. <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>
  226. <div class="comment_act"><span class="fl"><?php echo GetDateMk($dtime); ?>发表</span></div>
  227. <div style="clear:both"><?php echo ubb($msg); ?></div>
  228. <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'>
  229. <!--<a href='/plus/feedback.php?aid=<?php echo $id; ?>&fid=<?php echo $id; ?>&action=quote'>[引用]</a>-->
  230. <a href='javascript:ajaxFeedback(<?php echo $id; ?>,<?php echo $id; ?>,"quote");'>[引用]</a> </span></span></div>
  231. </li>
  232. <div id="ajaxfeedback_<?php echo $id; ?>"></div>
  233. </ul>
  234. </div>
  235. <br style='clear:both' />
  236. <?php
  237. }
  238. exit();
  239. }
  240. /**
  241. * 读取列表内容
  242. *
  243. * @param int $page 页码
  244. * @return string
  245. */
  246. function GetList($page=1)
  247. {
  248. global $dsql, $aid, $pagesize, $cfg_templeturl,$cfg_cmspath;
  249. $querystring = "SELECT fb.*,mb.userid,mb.face as mface,mb.spacesta,mb.scores,mb.sex FROM `#@__feedback` fb
  250. LEFT JOIN `#@__member` mb on mb.mid = fb.mid WHERE fb.aid='$aid' AND fb.ischeck='1' ORDER BY fb.id DESC";
  251. $row = $dsql->GetOne("SELECT COUNT(*) AS dd FROM `#@__feedback` WHERE aid='$aid' AND ischeck='1' ");
  252. $totalcount = (empty($row['dd']) ? 0 : $row['dd']);
  253. $startNum = $pagesize * ($page-1);
  254. if($startNum > $totalcount)
  255. {
  256. echo "参数错误!";
  257. return $totalcount;
  258. }
  259. $dsql->Execute('fb', $querystring." LIMIT $startNum, $pagesize ");
  260. while($fields = $dsql->GetArray('fb'))
  261. {
  262. if($fields['userid']!='') $spaceurl = $GLOBALS['cfg_memberurl'].'/index.php?uid='.$fields['userid'];
  263. else $spaceurl = '#';
  264. if($fields['username']=='匿名') $spaceurl = '#';
  265. $fields['bgimg'] = 'cmt-neu.gif';
  266. $fields['ftypetitle'] = '该用户表示中立';
  267. if($fields['ftype']=='bad')
  268. {
  269. $fields['bgimg'] = 'cmt-bad.gif';
  270. $fields['ftypetitle'] = '该用户表示差评';
  271. }
  272. else if($fields['ftype']=='good')
  273. {
  274. $fields['bgimg'] = 'cmt-good.gif';
  275. $fields['ftypetitle'] = '该用户表示好评';
  276. }
  277. if(empty($fields['mface']))
  278. {
  279. if($fields['sex']=="女") $fields['mface']=$cfg_cmspath."/member/templets/images/dfgirl.png";
  280. else $fields['mface']=$cfg_cmspath."/member/templets/images/dfboy.png";
  281. }
  282. $fields['face'] = empty($fields['face']) ? 6 : $fields['face'];
  283. $fields['msg'] = str_replace('<', '&lt;', $fields['msg']);
  284. $fields['msg'] = str_replace('>', '&gt;', $fields['msg']);
  285. helper('smiley');
  286. $fields['msg'] = RemoveXSS(Quote_replace(parseSmileys($fields['msg'], $cfg_cmspath.'/images/smiley')));
  287. extract($fields, EXTR_OVERWRITE);
  288. ?>
  289. <div class="decmt-box2">
  290. <ul>
  291. <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>
  292. <div class="comment_act"><span class="fl"><?php echo GetDateMk($dtime); ?>发表</span></div>
  293. <div style="clear:both"><?php echo ubb($msg); ?></div>
  294. <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'>
  295. <!--<a href='/plus/feedback.php?aid=<?php echo $id; ?>&fid=<?php echo $id; ?>&action=quote'>[引用]</a>-->
  296. <a href='javascript:ajaxFeedback(<?php echo $id; ?>,<?php echo $id; ?>,"quote");'>[引用]</a> </span></span></div>
  297. </li>
  298. </ul>
  299. <div id="ajaxfeedback_<?php echo $id; ?>"></div>
  300. </div>
  301. <?php
  302. }
  303. return $totalcount;
  304. }
  305. /**
  306. * 获取分页列表
  307. *
  308. * @param int $pagesize 显示条数
  309. * @param int $totalcount 总数
  310. * @return string
  311. */
  312. function GetPageList($pagesize, $totalcount)
  313. {
  314. global $page;
  315. $curpage = empty($page) ? 1 : intval($page);
  316. $allpage = ceil($totalcount / $pagesize);
  317. if($allpage < 2)
  318. {
  319. echo '';
  320. return ;
  321. }
  322. echo "
  323. <div id='commetpages'>";
  324. echo "<span>总: {$allpage} 页/{$totalcount} 条评论</span> ";
  325. $listsize = 5;
  326. $total_list = $listsize * 2 + 1;
  327. $totalpage = $allpage;
  328. $listdd = '';
  329. if($curpage-1 > 0 )
  330. {
  331. echo "<a href='#commettop' onclick='LoadCommets(".($curpage-1).");'>上一页</a> ";
  332. }
  333. if($curpage >= $total_list)
  334. {
  335. $j = $curpage - $listsize;
  336. $total_list = $curpage + $listsize;
  337. if($total_list > $totalpage)
  338. {
  339. $total_list = $totalpage;
  340. }
  341. }
  342. else
  343. {
  344. $j = 1;
  345. if($total_list > $totalpage) $total_list = $totalpage;
  346. }
  347. for($j; $j <= $total_list; $j++)
  348. {
  349. echo ($j==$curpage ? "<strong>$j</strong> " : "<a href='#commettop' onclick='LoadCommets($j);'>{$j}</a> ");
  350. }
  351. if($curpage+1 <= $totalpage )
  352. {
  353. echo "<a href='#commettop' onclick='LoadCommets(".($curpage+1).");'>下一页</a> ";
  354. }
  355. echo "</div>
  356. ";
  357. }