news.ctrl.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. $dos = array('category_post', 'category', 'category_del', 'list', 'post', 'batch_post', 'del', 'displaysetting');
  8. $do = in_array($do, $dos) ? $do : 'list';
  9. permission_check_account_user('system_article_news');
  10. if ($do == 'category_post') {
  11. if (checksubmit('submit')) {
  12. $i = 0;
  13. if (!empty($_GPC['title'])) {
  14. foreach ($_GPC['title'] as $k => $v) {
  15. $title = safe_gpc_string($v);
  16. if (empty($title)) {
  17. continue;
  18. }
  19. $data = array(
  20. 'title' => $title,
  21. 'displayorder' => intval($_GPC['displayorder'][$k]),
  22. 'type' => 'news',
  23. );
  24. pdo_insert('article_category', $data);
  25. $i++;
  26. }
  27. }
  28. itoast('添加分类成功', url('article/news/category'), 'success');
  29. }
  30. template('article/news-category-post');
  31. }
  32. if ($do == 'category') {
  33. $category_table = table('article_category');
  34. if (checksubmit('submit')) {
  35. $id = intval($_GPC['id']);
  36. if (empty($id)) {
  37. iajax(1, '参数有误');
  38. }
  39. if (empty($_GPC['title'])) {
  40. iajax(1, '分类名称不能为空');
  41. }
  42. $update = array(
  43. 'title' => safe_gpc_string($_GPC['title']),
  44. 'displayorder' => max(0,intval($_GPC['displayorder']))
  45. );
  46. $category_table->fill($update)->where('id', $id)->save();
  47. iajax(0, '修改分类成功');
  48. }
  49. $data = $category_table->getNewsCategoryLists();
  50. template('article/news-category');
  51. }
  52. if ($do == 'category_del') {
  53. $id = intval($_GPC['id']);
  54. pdo_delete('article_category', array('id' => $id, 'type' => 'news'));
  55. pdo_delete('article_news', array('cateid' => $id));
  56. itoast('删除分类成功', referer(), 'success');
  57. }
  58. if ($do == 'post') {
  59. $id = intval($_GPC['id']);
  60. $new = table('article_news')->searchWithId($id)->get();
  61. if (empty($new)) {
  62. $new = array(
  63. 'is_display' => 1,
  64. 'is_show_home' => 1,
  65. );
  66. }
  67. if (checksubmit()) {
  68. $title = trim($_GPC['title']) ? trim($_GPC['title']) : itoast('新闻标题不能为空', '', 'error');
  69. $cateid = intval($_GPC['cateid']) ? intval($_GPC['cateid']) : itoast('新闻分类不能为空', '', 'error');
  70. $content = trim($_GPC['content']) ? trim($_GPC['content']) : itoast('新闻内容不能为空', '', 'error');
  71. $data = array(
  72. 'title' => $title,
  73. 'cateid' => $cateid,
  74. 'content' => safe_gpc_html(htmlspecialchars_decode($content)),
  75. 'source' => safe_gpc_string($_GPC['source']),
  76. 'author' => safe_gpc_string($_GPC['author']),
  77. 'displayorder' => intval($_GPC['displayorder']),
  78. 'click' => intval($_GPC['click']),
  79. 'is_display' => intval($_GPC['is_display']),
  80. 'is_show_home' => intval($_GPC['is_show_home']),
  81. 'createtime' => TIMESTAMP,
  82. );
  83. if (!empty($_GPC['thumb'])) {
  84. $data['thumb'] = $_GPC['thumb'];
  85. } elseif (!empty($_GPC['autolitpic'])) {
  86. $match = array();
  87. preg_match('/attachment\/(.*?)(\.gif|\.jpg|\.png|\.bmp)/', $data['content'], $match);
  88. if (!empty($match[1])) {
  89. $data['thumb'] = $match[1].$match[2];
  90. }
  91. } else {
  92. $data['thumb'] = '';
  93. }
  94. if (!empty($new['id'])) {
  95. pdo_update('article_news', $data, array('id' => $id));
  96. } else {
  97. pdo_insert('article_news', $data);
  98. }
  99. itoast('编辑文章成功', url('article/news/list'), 'success');
  100. }
  101. $categorys = table('article_category')->getNewsCategoryLists();
  102. template('article/news-post');
  103. }
  104. if ($do == 'list') {
  105. $pindex = max(1, intval($_GPC['page']));
  106. $psize = 20;
  107. $article_table = table('article_news');
  108. $cateid = intval($_GPC['cateid']);
  109. $createtime = intval($_GPC['createtime']);
  110. $title = safe_gpc_string($_GPC['title']);
  111. if (!empty($cateid)) {
  112. $article_table->searchWithCateid($cateid);
  113. }
  114. if (!empty($createtime)) {
  115. $article_table->searchWithCreatetimeRange($createtime);
  116. }
  117. if (!empty($title)) {
  118. $article_table->searchWithTitle($title);
  119. }
  120. $order = !empty($_W['setting']['news_display']) ? $_W['setting']['news_display'] : 'displayorder';
  121. $article_table->searchWithPage($pindex, $psize);
  122. $article_table->orderby($order, 'DESC');
  123. $news = $article_table->getall();
  124. $total = $article_table->getLastQueryTotal();
  125. $pager = pagination($total, $pindex, $psize);
  126. $categorys = table('article_category')->getNewsCategoryLists($order);
  127. template('article/news');
  128. }
  129. if ($do == 'batch_post') {
  130. if (checksubmit()) {
  131. if (!empty($_GPC['ids'])) {
  132. foreach ($_GPC['ids'] as $k => $v) {
  133. $data = array(
  134. 'title' => trim($_GPC['title'][$k]),
  135. 'displayorder' => intval($_GPC['displayorder'][$k]),
  136. 'click' => intval($_GPC['click'][$k]),
  137. );
  138. pdo_update('article_news', $data, array('id' => intval($v)));
  139. }
  140. itoast('编辑新闻列表成功', referer(), 'success');
  141. }
  142. }
  143. }
  144. if ($do == 'del') {
  145. $id = intval($_GPC['id']);
  146. pdo_delete('article_news', array('id' => $id));
  147. itoast('删除文章成功', referer(), 'success');
  148. }
  149. if ($do == 'displaysetting') {
  150. $setting = safe_gpc_string($_GPC['setting']);
  151. $data = $setting == 'createtime' ? 'createtime' : 'displayorder';
  152. setting_save($data, 'news_display');
  153. itoast('更改成功!', referer(), 'success');
  154. }