comment.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. define('IN_SMT', true);
  3. define('IN_MYMPS', true);
  4. require_once dirname(__FILE__) . '/include/global.php';
  5. require_once dirname(__FILE__) . '/data/config.php';
  6. require_once MYMPS_DATA . '/config.db.php';
  7. require_once MYMPS_INC . '/db.class.php';
  8. require_once MYMPS_INC . '/member.class.php';
  9. $iflogin = $member_log->chk_in();
  10. $action = isset($action) ? trim($action) : '';
  11. $part = isset($part) ? trim($part) : '';
  12. $id = isset($id) ? intval($id) : '';
  13. $inajax = isset($inajax) ? intval($inajax) : '';
  14. if (empty($id)) {
  15. exit('Access Denied!');
  16. }
  17. if (!in_array($part, array('information', 'news', 'store'))) {
  18. write_msg('您提交的评论所属模块不能为空!');
  19. }
  20. $dotphpurlarray = array('information' => 'information.php', 'news' => 'news.php', 'coupon' => 'coupon.php', 'group' => 'group.php');
  21. $commentsettings = get_commentsettings();
  22. if (!$commentsettings[$part]) {
  23. exit();
  24. }
  25. if ($action == 'insert') {
  26. $_COOKIE['comment' . $part . $id] == 1 && write_msg('您的语速太快了,请休息一下再发表评论...');
  27. if (!$iflogin && !($randcode = mymps_chk_randcode($checkcode))) {
  28. write_msg('验证码输入错误,请返回重新输入');
  29. exit();
  30. }
  31. empty($content) && write_msg('提交失败!评论内容不能为空!');
  32. 255 < strlen($content) && write_msg('请不要填写超过127个汉字!');
  33. if (!$iflogin) {
  34. switch ($commentsettings[$part]) {
  35. case 1:
  36. $userid = '';
  37. break;
  38. case 2:
  39. $loginuser = $loginuser ? mhtmlspecialchars($loginuser) : '';
  40. $loginpwd = $loginpwd ? mhtmlspecialchars($loginpwd) : '';
  41. if (empty($loginuser)) {
  42. write_msg('请填写你的用户帐号!');
  43. }
  44. if (empty($loginpwd)) {
  45. write_msg('请填写你的用户密码!');
  46. }
  47. $loginpwd = md5($loginpwd);
  48. if (!($res = $db->getOne('SELECT id FROM `' . $db_mymps . 'member` WHERE userid = \'' . $loginuser . '\' AND userpwd = \'' . $loginpwd . '\''))) {
  49. unset($res);
  50. write_msg('你的帐号或密码输入错误,或不存在该用户!');
  51. }
  52. else {
  53. $userid = $loginuser;
  54. $member_log->in($loginuser, $loginpwd, '', 'noredirect');
  55. }
  56. break;
  57. }
  58. }
  59. else {
  60. $userid = $s_uid;
  61. }
  62. $result = verify_badwords_filter($mymps_global['cfg_if_comment_verify'], '', $content);
  63. $content = textarea_post_change($result['content']);
  64. $comment_level = $result['level'];
  65. $db->query('INSERT INTO `' . $db_mymps . 'comment` (typeid,content,pubtime,ip,comment_level,userid,type)VALUES(\'' . $id . '\',\'' . $content . '\',\'' . $timestamp . '\',\'' . GetIP() . ('\',\'' . $comment_level . '\',\'') . $userid . ('\',\'' . $part . '\')'));
  66. setcookie('comment' . $part . $id, 1, $timestamp + 30, '/');
  67. if ($comment_level == 1) {
  68. write_msg('', $dotphpurlarray[$part] . '?id=' . $id . '#comment_write');
  69. }
  70. else {
  71. define('IN_AJAX', true);
  72. write_msg('您提交的留言可能含有违禁词语,审核通过后显示!', $dotphpurlarray[$part] . '?id=' . $id);
  73. }
  74. unset($loginuser);
  75. unset($loginpwd);
  76. unset($comment_level);
  77. unset($id);
  78. }
  79. $res = $db->getAll('SELECT content,userid,pubtime,ip FROM `' . $db_mymps . 'comment` WHERE typeid = \'' . $id . '\' AND comment_level = \'1\' AND type = \'' . $part . '\' ORDER BY pubtime ASC LIMIT 0,10');
  80. foreach ($res as $k => $row) {
  81. $arr['content'] = $row['content'];
  82. $arr['pubtime'] = get_format_time($row['pubtime']);
  83. $arr['userid'] = $row['userid'];
  84. $arr['ip'] = $row['ip'];
  85. $comment_all[] = $arr;
  86. }
  87. $ajax_content = '
  88. <script type="text/javascript" src="' . $mymps_global[SiteUrl] . '/template/default/js/comment.js"></script>
  89. <div class="box specialpostcontainer">';
  90. if (is_array($comment_all)) {
  91. $i = 0;
  92. foreach ($comment_all as $key => $val) {
  93. $i++;
  94. $ajax_content .= '
  95. <div class="specialpost">
  96. <div class="postinfo">
  97. <h2>';
  98. $ajax_content .= $val['userid'] ? '<a class="dropmenu" style="font-weight: normal;" href="' . Rewrite('space', array('user' => $val['userid'])) . '" target="_blank" >' . $val['userid'] . '</a>' : '<a class="dropmenu" style="font-weight: normal;">' . part_ip($val['ip']) . '</a>';
  99. $ajax_content .= '
  100. ' . $val['pubtime'] . ' </h2>
  101. <strong>' . $i . '<sup>楼</sup></strong>
  102. </div>
  103. <div class="postmessage">
  104. <div class="t_msgfont">' . $val['content'] . '
  105. </div>
  106. </div>
  107. </div>';
  108. }
  109. }
  110. else {
  111. $ajax_content .= '
  112. <div class="specialpost"></div>
  113. <div class="clear"></div>';
  114. }
  115. $ajax_content .= '
  116. <div id="postleave">
  117. <a name="comment_write"></a>
  118. <form action="' . $mymps_global['SiteUrl'] . '/comment.php?part=' . $part . '&amp;action=insert" method="post" id="CommentForm" name="CommentForm" onsubmit="return CommentCheckForm();">
  119. <input name="id" value="' . $id . '" type="hidden">
  120. <dl><dt>评论内容:</dt><dd><textarea name="content" class="commenttextarea"></textarea></dd></dl>
  121. ';
  122. if ($iflogin) {
  123. $ajax_content .= '<div class=clearfix></div><dl><dt>&nbsp;</dt><dd><div style="margin-top:5px">' . $s_uid . ' &nbsp;<a href="' . $mymps_global[SiteUrl] . '/' . $mymps_global[cfg_member_logfile] . '?part=out&url=' . urlencode($mymps_global['SiteUrl'] . '/' . $dotphpurlarray[$part] . '?id=' . $id) . '">退出</a></div></dd></dl>';
  124. }
  125. else {
  126. if ($commentsettings[$part] == 2) {
  127. $ajax_content .= '
  128. <div class="clearfix"></div>
  129. <dl>
  130. <dt>登录帐号:</dt>
  131. <dd>
  132. <input name="loginuser" class="commenttxt" style="width:100px;">
  133. &nbsp;&nbsp;&nbsp;&nbsp;
  134. 密码:<input name="loginpwd" type="password" class="commenttxt" style="width:100px;">&nbsp;&nbsp;&nbsp;&nbsp;<a href="' . $mymps_global[SiteUrl] . '/' . $mymps_global[cfg_member_logfile] . '?mod=register" target="_blank">注册帐号 &raquo;</a>
  135. </dd>
  136. </dl>
  137. ';
  138. }
  139. $ajax_content .= '<div class="clearfix"></div>';
  140. $ajax_content .= '<dl><dt>验 证 码:</dt><dd><input name="checkcode" class="commenttxt" type="text" style="width:74px"/></dd></dl>';
  141. $ajax_content .= '<div class="clearfix"></div>';
  142. $ajax_content .= '<dl><dt>&nbsp;</dt><dd><img src="' . $mymps_global['SiteUrl'] . '/' . $mymps_global[cfg_authcodefile] . '" alt="看不清,请点击刷新" class="authcode" align="absmiddle" onClick="this.src=this.src+\'?\'"/></dd></dl>';
  143. }
  144. $ajax_content .= '
  145. <div class="clearfix"></div>
  146. <dl><dt>&nbsp;</dt><dd><input type="submit" class="commentsubmit" value="提交评论" style="line-height:18px" name="mymps"></dd></dl>
  147. </form>
  148. </div>
  149. </div>
  150. ';
  151. echo $ajax_content;
  152. is_object($db) && $db->Close();
  153. unset($ajax_concotent);
  154. unset($iflogin);
  155. unset($mymps_global);
  156. unset($member_log);
  157. unset($comment_all);
  158. unset($rows_num);
  159. unset($param);
  160. unset($page);
  161. unset($userid);
  162. unset($content);
  163. unset($inajax);
  164. unset($id);
  165. unset($part);
  166. unset($action);
  167. unset($userid);
  168. unset($s_uid);
  169. unset($db);
  170. unset($timestamp);
  171. unset($dotphpurlarray);
  172. unset($commentsettings);
  173. ?>