人人商城

news.ctrl.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 = safe_gpc_string($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' => safe_gpc_string($_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 = table('articlecategory')->getNewsCategoryLists();
  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 = table('articlenews')->searchWithId($id)->get();
  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' => safe_gpc_string($_GPC['source']),
  75. 'author' => safe_gpc_string($_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 = table('articlecategory')->getNewsCategoryLists();
  101. template('article/news-post');
  102. }
  103. if ($do == 'list') {
  104. $_W['page']['title'] = '所有新闻-新闻列表';
  105. $pindex = max(1, intval($_GPC['page']));
  106. $psize = 20;
  107. $article_table = table('articlenews');
  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. $news = $article_table->getArticleNewsLists($order);
  123. $total = $article_table->getLastQueryTotal();
  124. $pager = pagination($total, $pindex, $psize);
  125. $categorys = table('articlecategory')->getNewsCategoryLists($order);
  126. template('article/news');
  127. }
  128. if ($do == 'batch_post') {
  129. if (checksubmit()) {
  130. if (!empty($_GPC['ids'])) {
  131. foreach ($_GPC['ids'] as $k => $v) {
  132. $data = array(
  133. 'title' => trim($_GPC['title'][$k]),
  134. 'displayorder' => intval($_GPC['displayorder'][$k]),
  135. 'click' => intval($_GPC['click'][$k]),
  136. );
  137. pdo_update('article_news', $data, array('id' => intval($v)));
  138. }
  139. itoast('编辑新闻列表成功', referer(), 'success');
  140. }
  141. }
  142. }
  143. if ($do == 'del') {
  144. $id = intval($_GPC['id']);
  145. pdo_delete('article_news', array('id' => $id));
  146. itoast('删除文章成功', referer(), 'success');
  147. }
  148. if ($do == 'displaysetting') {
  149. $setting = safe_gpc_string($_GPC['setting']);
  150. $data = $setting == 'createtime' ? 'createtime' : 'displayorder';
  151. setting_save($data, 'news_display');
  152. itoast('更改成功!', referer(), 'success');
  153. }