comment.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /**
  3. * CMS评论
  4. *
  5. *
  6. ***/
  7. defined('InShopNC') or exit('Access Invalid!');
  8. class commentControl extends CMSHomeControl{
  9. public function __construct() {
  10. parent::__construct();
  11. //是否关闭投稿功能
  12. if(intval(C('cms_comment_flag')) !== 1) {
  13. showMessage(Language::get('comment_closed'),'','','error');
  14. }
  15. }
  16. /**
  17. * 评论保存
  18. **/
  19. public function comment_saveOp() {
  20. $data = array();
  21. $data['result'] = 'true';
  22. $comment_object_id = intval($_POST['comment_object_id']);
  23. $comment_type = $_POST['comment_type'];
  24. $model_name = '';
  25. $count_field = '';
  26. switch ($comment_type) {
  27. case 'article':
  28. $comment_type = self::ARTICLE;
  29. $model_name = 'cms_article';
  30. $count_field = 'article_comment_count';
  31. $comment_object_key = 'article_id';
  32. break;
  33. case 'picture':
  34. $comment_type = self::PICTURE;
  35. $model_name = 'cms_picture';
  36. $count_field = 'picture_comment_count';
  37. $comment_object_key = 'picture_id';
  38. break;
  39. default:
  40. $comment_type = 0;
  41. break;
  42. }
  43. if($comment_object_id <= 0 || empty($comment_type) || empty($_POST['comment_message'])) {
  44. $data['result'] = 'false';
  45. $data['message'] = Language::get('wrong_argument');
  46. self::echo_json($data);
  47. }
  48. if(!empty($_SESSION['member_id'])) {
  49. $param = array();
  50. $param['comment_type'] = $comment_type;
  51. $param["comment_object_id"] = $comment_object_id;
  52. if (strtoupper(CHARSET) == 'GBK'){
  53. $param['comment_message'] = Language::getGBK(trim($_POST['comment_message']));
  54. } else {
  55. $param['comment_message'] = trim($_POST['comment_message']);
  56. }
  57. $param['comment_member_id'] = $_SESSION['member_id'];
  58. $param['comment_time'] = time();
  59. $model_comment = Model('cms_comment');
  60. if(!empty($_POST['comment_id'])) {
  61. $comment_detail = $model_comment->getOne(array('comment_id'=>$_POST['comment_id']));
  62. if(empty($comment_detail['comment_quote'])) {
  63. $param['comment_quote'] = $_POST['comment_id'];
  64. } else {
  65. $param['comment_quote'] = $comment_detail['comment_quote'].','.$_POST['comment_id'];
  66. }
  67. } else {
  68. $param['comment_quote'] = '';
  69. }
  70. $result = $model_comment->save($param);
  71. if($result) {
  72. //评论计数加1
  73. $model = Model($model_name);
  74. $update = array();
  75. $update[$count_field] = array('exp',$count_field.'+1');
  76. $condition = array();
  77. $condition[$comment_object_key] = $comment_object_id;
  78. $model->modify($update, $condition);
  79. //返回信息
  80. $data['result'] = 'true';
  81. $data['message'] = Language::get('nc_common_save_succ');
  82. $data['member_name'] = $_SESSION['member_name'].Language::get('nc_colon');
  83. $data['member_avatar'] = getMemberAvatar($_SESSION['member_avatar']);
  84. $data['member_link'] = SITEURL.DS.'index.php?act=member_snshome&mid='.$_SESSION['member_id'];
  85. $data['comment_message'] = parsesmiles(stripslashes($param['comment_message']));
  86. $data['comment_time'] = date('Y-m-d H:i:s',$param['comment_time']);
  87. $data['comment_id'] = $result;
  88. } else {
  89. $data['result'] = 'false';
  90. $data['message'] = Language::get('nc_common_save_fail');
  91. }
  92. } else {
  93. $data['result'] = 'false';
  94. $data['message'] = Language::get('no_login');
  95. }
  96. self::echo_json($data);
  97. }
  98. /**
  99. * 评论列表
  100. **/
  101. public function comment_listOp() {
  102. $page_count = 5;
  103. $order = 'comment_id desc';
  104. if($_GET['comment_all'] === 'all') {
  105. $page_count = 10;
  106. $order = 'comment_up desc, comment_id desc';
  107. }
  108. $comment_object_id = intval($_GET['comment_object_id']);
  109. $comment_type = 0;
  110. switch ($_GET['type']) {
  111. case 'article':
  112. $comment_type = self::ARTICLE;
  113. break;
  114. case 'picture':
  115. $comment_type = self::PICTURE;
  116. break;
  117. }
  118. if($comment_object_id > 0 && $comment_type > 0) {
  119. $condition = array();
  120. $condition["comment_object_id"] = $comment_object_id;
  121. $condition["comment_type"] = $comment_type;
  122. $model_cms_comment = Model('cms_comment');
  123. $comment_list = $model_cms_comment->getListWithUserInfo($condition, $page_count, $order);
  124. Tpl::output('comment_list', $comment_list);
  125. if($_GET['comment_all'] === 'all') {
  126. Tpl::output('show_page', $model_cms_comment->showpage(2));
  127. }
  128. $comment_quote_id = '';
  129. $comment_quote_list = array();
  130. if(!empty($comment_list)) {
  131. foreach ($comment_list as $value) {
  132. if(!empty($value['comment_quote'])) {
  133. $comment_quote_id .= $value['comment_quote'].',';
  134. }
  135. }
  136. }
  137. if(!empty($comment_quote_id)) {
  138. $comment_quote_list = $model_cms_comment->getListWithUserInfo(array('comment_id'=>array('in', $comment_quote_id)));
  139. }
  140. if(!empty($comment_quote_list)) {
  141. $comment_quote_list = array_under_reset($comment_quote_list, 'comment_id');
  142. }
  143. Tpl::output('comment_quote_list', $comment_quote_list);
  144. Tpl::showpage('comment_list','null_layout');
  145. }
  146. }
  147. /**
  148. * 评论删除
  149. **/
  150. public function comment_dropOp() {
  151. $data['result'] = 'false';
  152. $data['message'] = Language::get('nc_common_del_fail');
  153. $comment_id = intval($_POST['comment_id']);
  154. if($comment_id > 0) {
  155. $model_comment = Model('cms_comment');
  156. $comment_info = $model_comment->getOne(array('comment_id'=>$comment_id));
  157. if($comment_info['comment_member_id'] == $_SESSION['member_id']) {
  158. $result = $model_comment->drop(array('comment_id'=>$comment_id));
  159. if($result) {
  160. $comment_type = $_GET['type'];
  161. switch ($comment_type) {
  162. case 'article':
  163. $comment_type = self::ARTICLE;
  164. $model_name = 'cms_article';
  165. $count_field = 'article_comment_count';
  166. $comment_object_key = 'article_id';
  167. break;
  168. case 'picture':
  169. $comment_type = self::PICTURE;
  170. $model_name = 'cms_picture';
  171. $count_field = 'picture_comment_count';
  172. $comment_object_key = 'picture_id';
  173. break;
  174. default:
  175. $comment_type = 0;
  176. break;
  177. }
  178. //评论计数减1
  179. $model = Model($model_name);
  180. $update = array();
  181. $update[$count_field] = array('exp',$count_field.'-1');
  182. $condition = array();
  183. $condition[$comment_object_key] = $comment_object_id;
  184. $model->modify($update, $condition);
  185. $data['result'] = 'true';
  186. $data['message'] = Language::get('nc_common_del_succ');
  187. }
  188. }
  189. }
  190. self::echo_json($data);
  191. }
  192. /**
  193. * 评论顶
  194. **/
  195. public function comment_upOp() {
  196. $data = array();
  197. $data['result'] = 'true';
  198. $comment_id = intval($_POST['comment_id']);
  199. if($comment_id > 0) {
  200. $model_comment_up = Model('cms_comment_up');
  201. $param = array();
  202. $param['comment_id'] = $comment_id;
  203. $param['up_member_id'] = $_SESSION['member_id'];
  204. $is_exist = $model_comment_up->isExist($param);
  205. if(!$is_exist) {
  206. $param['up_time'] = time();
  207. $model_comment_up->save($param);
  208. $model_comment = Model('cms_comment');
  209. $model_comment->modify(array('comment_up'=>array('exp', 'comment_up+1')), array('comment_id'=>$comment_id));
  210. } else {
  211. $data['result'] = 'false';
  212. $data['message'] = '顶过了';
  213. }
  214. } else {
  215. $data['result'] = 'false';
  216. $data['message'] = Language::get('wrong_argument');
  217. }
  218. self::echo_json($data);
  219. }
  220. }