comment_admin.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin', 'admin', 0);
  4. class comment_admin extends admin {
  5. private $comment_setting_db,$comment_data_db,$comment_db,$siteid;
  6. function __construct() {
  7. parent::__construct();
  8. $this->comment_setting_db = pc_base::load_model('comment_setting_model');
  9. $this->comment_data_db = pc_base::load_model('comment_data_model');
  10. $this->comment_db = pc_base::load_model('comment_model');
  11. $this->siteid = $this->get_siteid();
  12. }
  13. public function init() {
  14. $data = $this->comment_setting_db->get_one(array('siteid'=>$this->siteid));
  15. if (isset($_POST['dosubmit'])) {
  16. $guest = isset($_POST['guest']) && intval($_POST['guest']) ? intval($_POST['guest']) : 0;
  17. $check = isset($_POST['check']) && intval($_POST['check']) ? intval($_POST['check']) : 0;
  18. $code = isset($_POST['code']) && intval($_POST['code']) ? intval($_POST['code']) : 0;
  19. $add_point = isset($_POST['add_point']) && abs(intval($_POST['add_point'])) ? intval($_POST['add_point']) : 0;
  20. $del_point = isset($_POST['del_point']) && abs(intval($_POST['del_point'])) ? intval($_POST['del_point']) : 0;
  21. $sql = array('guest'=>$guest, 'check'=>$check, 'code'=>$code, 'add_point'=>$add_point, 'del_point'=>$del_point);
  22. if ($data) {
  23. $this->comment_setting_db->update($sql, array('siteid'=>$this->siteid));
  24. } else {
  25. $sql['siteid'] = $this->siteid;
  26. $this->comment_setting_db->insert($sql);
  27. }
  28. showmessage(L('operation_success'), HTTP_REFERER);
  29. } else {
  30. $show_header = true;
  31. include $this->admin_tpl('comment_setting');
  32. }
  33. }
  34. public function lists() {
  35. $show_header = true;
  36. $commentid = isset($_GET['commentid']) && trim($_GET['commentid']) ? trim($_GET['commentid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  37. $hot = isset($_GET['hot']) && intval($_GET['hot']) ? intval($_GET['hot']) : 0;
  38. $comment = $this->comment_db->get_one(array('commentid'=>$commentid, 'siteid'=>$this->siteid));
  39. if (empty($comment)) {
  40. $forward = isset($_GET['show_center_id']) ? 'blank' : HTTP_REFERER;
  41. showmessage(L('no_comment'), $forward);
  42. }
  43. pc_base::load_app_func('global');
  44. pc_base::load_sys_class('format','', 0);
  45. $page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
  46. $pagesize = 20;
  47. $offset = ($page-1)*$pagesize;
  48. $this->comment_data_db->table_name($comment['tableid']);
  49. $desc = 'id desc';
  50. if (!empty($hot)) {
  51. $desc = 'support desc, id desc';
  52. }
  53. $list = $this->comment_data_db->select(array('commentid'=>$commentid, 'siteid'=>$this->siteid, 'status'=>1), '*', $offset.','.$pagesize, $desc);
  54. $pages = pages($comment['total'], $page, $pagesize);
  55. include $this->admin_tpl('comment_data_list');
  56. }
  57. public function listinfo() {
  58. $r = $max_table = '';
  59. $max_table = isset($_GET['max_table']) ? intval($_GET['max_table']) : 0;
  60. if (!$max_table) {
  61. $r = $this->comment_db->get_one(array(), 'MAX(tableid) AS tableid');
  62. if (!$r['tableid']) {
  63. showmessage(L('no_comment'));
  64. }
  65. $max_table = $r['tableid'];
  66. }
  67. $page = max(intval($_GET['page']), 1);
  68. $tableid = isset($_GET['tableid']) ? intval($_GET['tableid']) : $max_table;
  69. if ($tableid > $max_table) {
  70. $tableid = $max_table;
  71. }
  72. if (isset($_GET['search'])) {
  73. $where = $sql = $t = $comment_id = $order = '';
  74. $keywords = safe_replace($_GET['keyword']);
  75. $searchtype = intval($_GET['searchtype']);
  76. switch ($searchtype) {
  77. case '0':
  78. $sql = "SELECT `commentid` FROM `phpcms_comment` WHERE `siteid` = '$this->siteid' AND `title` LIKE '%$keywords%' AND `tableid` = '$tableid' ";
  79. $this->comment_db->query($sql);
  80. $data = $this->comment_db->fetch_array();
  81. if (!empty($data)) {
  82. foreach ($data as $d) {
  83. $comment_id .= $t.'\''.$d['commentid'].'\'';
  84. $t = ',';
  85. }
  86. $where = "`commentid` IN ($comment_id)";
  87. }
  88. break;
  89. case '1':
  90. $keywords = intval($keywords);
  91. $sql = "SELECT `commentid` FROM `phpcms_comment` WHERE `commentid` LIKE 'content_%-$keywords-%' ";
  92. $this->comment_db->query($sql);
  93. $data = $this->comment_db->fetch_array();
  94. if (!empty($data)) {
  95. foreach ($data as $d) {
  96. $comment_id .= $t.'\''.$d['commentid'].'\'';
  97. $t = ',';
  98. }
  99. $where = "`commentid` IN ($comment_id)";
  100. }
  101. break;
  102. case '2':
  103. $where = "`username` = '$keywords'";
  104. break;
  105. }
  106. }
  107. $data = array();
  108. if (isset($_GET['search'])) {
  109. if(!empty($where)){
  110. $where .= ' AND siteid='.$this->siteid;
  111. }else{
  112. pc_base::load_sys_class('format','', 0);
  113. $data= '';
  114. include $this->admin_tpl('comment_listinfo');
  115. exit;
  116. }
  117. }else{
  118. $where = 'siteid='.$this->siteid;
  119. }
  120. $order = '`id` DESC';
  121. pc_base::load_sys_class('format','', 0);
  122. $this->comment_data_db->table_name($tableid);
  123. $data = $this->comment_data_db->listinfo($where, $order, $page, 10);
  124. $pages = $this->comment_data_db->pages;
  125. include $this->admin_tpl('comment_listinfo');
  126. }
  127. public function del() {
  128. if (isset($_GET['dosubmit']) && $_GET['dosubmit']) {
  129. $ids = $_GET['ids'];
  130. $tableid = isset($_GET['tableid']) ? intval($_GET['tableid']) : 0;
  131. $r = $this->comment_db->get_one(array(), 'MAX(tableid) AS tableid');
  132. $max_table = $r['tableid'];
  133. if (!$tableid || $max_table<$tableid) showmessage(L('illegal_operation'));
  134. $this->comment_data_db->table_name($tableid);
  135. $site = $this->comment_setting_db->site($this->siteid);
  136. if (is_array($ids)) {
  137. foreach ($ids as $id) {
  138. $comment_info = $this->comment_data_db->get_one(array('id'=>$id), 'commentid, userid, username');
  139. //判断总数是否为0
  140. $comment_allinfo = $this->comment_db->get_one(array('commentid'=>$comment_info['commentid']),'*');
  141. if($comment_allinfo['total']<=0){
  142. showmessage('评论统计不正常,请返回检查!', HTTP_REFERER);
  143. }
  144. $this->comment_db->update(array('total'=>'-=1'), array('commentid'=>$comment_info['commentid']));
  145. $this->comment_data_db->delete(array('id'=>$id));
  146. //当评论ID不为空,站点配置了删除的点数,支付模块存在的时候,删除用户的点数。
  147. if (!empty($comment_info['userid']) && !empty($site['del_point']) && module_exists('pay')) {
  148. pc_base::load_app_class('spend', 'pay', 0);
  149. $op_userid = param::get_cookie('userid');
  150. $op_username = param::get_cookie('admin_username');
  151. spend::point($site['del_point'], L('comment_point_del', '', 'comment'), $comment_info['userid'], $comment_info['username'], $op_userid, $op_username);
  152. }
  153. }
  154. $ids = implode(',', $ids);
  155. } elseif (is_numeric($ids)) {
  156. $id = intval($ids);
  157. $comment_info = $this->comment_data_db->get_one(array('id'=>$id), 'commentid, userid, username');
  158. //判断总数是否为0
  159. $comment_allinfo = $this->comment_db->get_one(array('commentid'=>$comment_info['commentid']),'*');
  160. if($comment_allinfo['total']<=0){
  161. showmessage('评论统计不正常,请返回检查!', HTTP_REFERER);
  162. }
  163. $this->comment_db->update(array('total'=>'-=1'), array('commentid'=>$comment_info['commentid']));
  164. $this->comment_data_db->delete(array('id'=>$id));
  165. //当评论ID不为空,站点配置了删除的点数,支付模块存在的时候,删除用户的点数。
  166. if (!empty($comment_info['userid']) && !empty($site['del_point']) && module_exists('pay')) {
  167. pc_base::load_app_class('spend', 'pay', 0);
  168. $op_userid = param::get_cookie('userid');
  169. $op_username = param::get_cookie('admin_username');
  170. spend::point($site['del_point'], L('comment_point_del', '', 'comment'), $comment_info['userid'], $comment_info['username'], $op_userid, $op_username);
  171. }
  172. } else {
  173. showmessage(L('illegal_operation'));
  174. }
  175. showmessage(L('operation_success'), HTTP_REFERER);
  176. }
  177. }
  178. }