article.ctrl.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->func('file');
  8. load()->model('article');
  9. load()->model('account');
  10. $dos = array('display', 'post', 'del');
  11. $do = in_array($do, $dos) ? $do : 'display';
  12. permission_check_account_user('platform_site_article');
  13. $category = pdo_fetchall("SELECT id,parentid,name FROM ".tablename('site_category')." WHERE uniacid = '{$_W['uniacid']}' AND enabled=1 ORDER BY parentid ASC, displayorder ASC, id ASC ", array(), 'id');
  14. $parent = array();
  15. $children = array();
  16. if (!empty($category)) {
  17. foreach ($category as $cid => $cate) {
  18. if (!empty($cate['parentid'])) {
  19. $children[$cate['parentid']][] = $cate;
  20. } else {
  21. $parent[$cate['id']] = $cate;
  22. }
  23. }
  24. }
  25. if ($do == 'display') {
  26. $pindex = max(1, intval($_GPC['page']));
  27. $psize = 20;
  28. $condition = '';
  29. $params = array();
  30. if (!empty($_GPC['keyword'])) {
  31. $condition .= " AND `title` LIKE :keyword";
  32. $params[':keyword'] = "%{$_GPC['keyword']}%";
  33. }
  34. if (!empty($_GPC['category']['childid'])) {
  35. $cid = intval($_GPC['category']['childid']);
  36. $condition .= " AND ccate = '{$cid}'";
  37. } elseif (!empty($_GPC['category']['parentid'])) {
  38. $cid = intval($_GPC['category']['parentid']);
  39. $condition .= " AND pcate = '{$cid}'";
  40. }
  41. $list = pdo_fetchall("SELECT * FROM ".tablename('site_article')." WHERE uniacid = '{$_W['uniacid']}' $condition ORDER BY displayorder DESC, edittime DESC, id DESC LIMIT ".($pindex - 1) * $psize.','.$psize, $params);
  42. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('site_article') . " WHERE uniacid = '{$_W['uniacid']}'".$condition, $params);
  43. $pager = pagination($total, $pindex, $psize);
  44. $article_ids = array();
  45. if (!empty($list)) {
  46. foreach ($list as $item) {
  47. $article_ids[] = $item['id'];
  48. }
  49. }
  50. $article_comment = table('site_article_comment')->srticleCommentUnread($article_ids);
  51. $setting = uni_setting($_W['uniacid']);
  52. template('site/article-display');
  53. } elseif ($do == 'post') {
  54. $id = intval($_GPC['id']);
  55. $template = uni_templates();
  56. $pcate = intval($_GPC['pcate']);
  57. $ccate = intval($_GPC['ccate']);
  58. if (!empty($id)) {
  59. $item = pdo_fetch("SELECT * FROM ".tablename('site_article')." WHERE id = :id" , array(':id' => $id));
  60. $item['type'] = explode(',', $item['type']);
  61. $pcate = $item['pcate'];
  62. $ccate = $item['ccate'];
  63. if (empty($item)) {
  64. itoast('抱歉,文章不存在或是已经删除!', '', 'error');
  65. }
  66. $key = pdo_fetchall('SELECT content FROM ' . tablename('rule_keyword') . ' WHERE rid = :rid AND uniacid = :uniacid', array(':rid' => $item['rid'], ':uniacid' => $_W['uniacid']));
  67. if (!empty($key)) {
  68. $keywords = array();
  69. foreach ($key as $row) {
  70. $keywords[] = $row['content'];
  71. }
  72. $keywords = implode(',', array_values($keywords));
  73. }
  74. $item['credit'] = iunserializer($item['credit']) ? iunserializer($item['credit']) : array();
  75. if (!empty($item['credit']['limit'])) {
  76. $credit_num = pdo_fetchcolumn('SELECT SUM(credit_value) FROM ' . tablename('mc_handsel') . ' WHERE uniacid = :uniacid AND module = :module AND sign = :sign', array(':uniacid' => $_W['uniacid'], ':module' => 'article', ':sign' => md5(iserializer(array('id' => $id)))));
  77. if (is_null($credit_num)) {
  78. $credit_num = 0;
  79. }
  80. $credit_yu = (($item['credit']['limit'] - $credit_num) < 0) ? 0 : $item['credit']['limit'] - $credit_num;
  81. }
  82. } else {
  83. $item['credit'] = array();
  84. $keywords = '';
  85. }
  86. if (checksubmit('submit')) {
  87. if (empty($_GPC['title'])) {
  88. itoast('标题不能为空,请输入标题!', '', '');
  89. }
  90. $sensitive_title = detect_sensitive_word($_GPC['title']);
  91. if (!empty($sensitive_title)) {
  92. itoast('不能使用敏感词:' . $sensitive_title, '', '');
  93. }
  94. $sensitive_content = detect_sensitive_word($_GPC['content']);
  95. if (!empty($sensitive_content)) {
  96. itoast('不能使用敏感词:' . $sensitive_content, '', '');
  97. }
  98. $data = array(
  99. 'uniacid' => $_W['uniacid'],
  100. 'iscommend' => intval($_GPC['option']['commend']),
  101. 'ishot' => intval($_GPC['option']['hot']),
  102. 'pcate' => intval($_GPC['category']['parentid']),
  103. 'ccate' => intval($_GPC['category']['childid']),
  104. 'template' => addslashes($_GPC['template']),
  105. 'title' => addslashes($_GPC['title']),
  106. 'description' => addslashes($_GPC['description']),
  107. 'content' => safe_gpc_html(htmlspecialchars_decode($_GPC['content'], ENT_QUOTES)),
  108. 'incontent' => intval($_GPC['incontent']),
  109. 'source' => addslashes($_GPC['source']),
  110. 'author' => addslashes($_GPC['author']),
  111. 'displayorder' => intval($_GPC['displayorder']),
  112. 'linkurl' => addslashes($_GPC['linkurl']),
  113. 'createtime' => TIMESTAMP,
  114. 'edittime' => TIMESTAMP,
  115. 'click' => intval($_GPC['click'])
  116. );
  117. if (!empty($_GPC['thumb'])) {
  118. if (file_is_image($_GPC['thumb'])) {
  119. $data['thumb'] = $_GPC['thumb'];
  120. }
  121. } elseif (!empty($_GPC['autolitpic'])) {
  122. $match = array();
  123. preg_match('/&lt;img.*?src=&quot;(.+\.(jpg|jpeg|gif|bmp|png))&quot;/U', $_GPC['content'], $match);
  124. if (file_is_image($match[1])) {
  125. $data['thumb'] = $match[1];
  126. }
  127. } else {
  128. $data['thumb'] = '';
  129. }
  130. $keyword = str_replace(',', ',', trim($_GPC['keyword']));
  131. $keyword = explode(',', $keyword);
  132. if (!empty($keyword)) {
  133. $rule['uniacid'] = $_W['uniacid'];
  134. $rule['name'] = '文章:' . $_GPC['title'] . ' 触发规则';
  135. $rule['module'] = 'news';
  136. $rule['status'] = 1;
  137. $keywords = array();
  138. foreach ($keyword as $key) {
  139. $key = trim($key);
  140. if (empty($key)) continue;
  141. $keywords[] = array(
  142. 'uniacid' => $_W['uniacid'],
  143. 'module' => 'news',
  144. 'content' => $key,
  145. 'status' => 1,
  146. 'type' => 1,
  147. 'displayorder' => 1,
  148. );
  149. }
  150. $reply['title'] = $_GPC['title'];
  151. $reply['description'] = $_GPC['description'];
  152. $reply['thumb'] = $data['thumb'];
  153. $reply['url'] = murl('site/site/detail', array('id' => $id));
  154. }
  155. if (!empty($_GPC['credit']['status'])) {
  156. $credit['status'] = intval($_GPC['credit']['status']);
  157. $credit['limit'] = intval($_GPC['credit']['limit']) ? intval($_GPC['credit']['limit']) : itoast('请设置积分上限', '', '');
  158. $credit['share'] = intval($_GPC['credit']['share']) ? intval($_GPC['credit']['share']) : itoast('请设置分享时赠送积分多少', '', '');
  159. $credit['click'] = intval($_GPC['credit']['click']) ? intval($_GPC['credit']['click']) : itoast('请设置阅读时赠送积分多少', '', '');
  160. $data['credit'] = iserializer($credit);
  161. } else {
  162. $data['credit'] = iserializer(array('status' => 0, 'limit' => 0, 'share' => 0, 'click' => 0));
  163. }
  164. if (empty($id)) {
  165. unset($data['edittime']);
  166. if (!empty($keywords)) {
  167. pdo_insert('rule', $rule);
  168. $rid = pdo_insertid();
  169. foreach ($keywords as $li) {
  170. $li['rid'] = $rid;
  171. pdo_insert('rule_keyword', $li);
  172. }
  173. $reply['rid'] = $rid;
  174. pdo_insert('news_reply', $reply);
  175. $data['rid'] = $rid;
  176. }
  177. pdo_insert('site_article', $data);
  178. $aid = pdo_insertid();
  179. pdo_update('news_reply', array('url' => murl('site/site/detail', array('id' => $aid))), array('rid' => $rid));
  180. } else {
  181. unset($data['createtime']);
  182. uni_delete_rule($item['rid'], 'news_reply');
  183. if (!empty($keywords)) {
  184. pdo_insert('rule', $rule);
  185. $rid = pdo_insertid();
  186. foreach ($keywords as $li) {
  187. $li['rid'] = $rid;
  188. pdo_insert('rule_keyword', $li);
  189. }
  190. $reply['rid'] = $rid;
  191. pdo_insert('news_reply', $reply);
  192. $data['rid'] = $rid;
  193. } else {
  194. $data['rid'] = 0;
  195. $data['kid'] = 0;
  196. }
  197. pdo_update('site_article', $data, array('id' => $id, 'uniacid' => $_W['uniacid']));
  198. }
  199. itoast('文章更新成功!', url('site/article/display'), 'success');
  200. } else {
  201. template('site/article-post');
  202. }
  203. } elseif($do == 'del') {
  204. if (checksubmit('submit')) {
  205. foreach ($_GPC['rid'] as $key => $id) {
  206. $id = intval($id);
  207. $row = pdo_get('site_article', array('id' => $id, 'uniacid' => $_W['uniacid']));
  208. if (empty($row)) {
  209. itoast('抱歉,文章不存在或是已经被删除!', '', '');
  210. }
  211. if (!empty($row['rid'])) {
  212. uni_delete_rule($row['rid'], 'news_reply');
  213. }
  214. pdo_delete('site_article', array('id' => $id, 'uniacid'=>$_W['uniacid']));
  215. }
  216. itoast('批量删除成功!', referer(), 'success');
  217. } else {
  218. $id = intval($_GPC['id']);
  219. $row = pdo_fetch("SELECT id,rid,kid,thumb FROM ".tablename('site_article')." WHERE id = :id", array(':id' => $id));
  220. if (empty($row)) {
  221. itoast('抱歉,文章不存在或是已经被删除!', '', '');
  222. }
  223. if (!empty($row['rid'])) {
  224. uni_delete_rule($row['rid'], 'news_reply');
  225. }
  226. if (pdo_delete('site_article', array('id' => $id,'uniacid'=>$_W['uniacid']))){
  227. itoast('删除成功!', referer(), 'success');
  228. } else {
  229. itoast('删除失败!', referer(), 'error');
  230. }
  231. }
  232. }