news.ctrl.php 5.7 KB

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