article.mod.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. function article_categorys($type = 'news') {
  8. $categorys = pdo_fetchall('SELECT * FROM ' . tablename('article_category') . ' WHERE type = :type ORDER BY displayorder DESC', array(':type' => $type), 'id');
  9. return $categorys;
  10. }
  11. function article_news_info($id) {
  12. $id = intval($id);
  13. $news = pdo_fetch('SELECT * FROM ' . tablename('article_news') . ' WHERE id = :id', array(':id' => $id));
  14. if(empty($news)) {
  15. return error(-1, '新闻不存在或已经删除');
  16. }else {
  17. pdo_update('article_news',array('click' => $news['click']+1),array('id' => $id));
  18. }
  19. return $news;
  20. }
  21. function article_notice_info($id) {
  22. $id = intval($id);
  23. $news = pdo_fetch('SELECT * FROM ' . tablename('article_notice') . ' WHERE id = :id', array(':id' => $id));
  24. if(empty($news)) {
  25. return error(-1, '公告不存在或已经删除');
  26. }
  27. return $news;
  28. }
  29. function article_news_home($limit = 5) {
  30. $limit = intval($limit);
  31. $news = pdo_fetchall('SELECT * FROM ' . tablename('article_news') . ' WHERE is_display = 1 AND is_show_home = 1 ORDER BY displayorder DESC,id DESC LIMIT ' . $limit, array(), 'id');
  32. return $news;
  33. }
  34. function article_notice_home($limit = 5) {
  35. $limit = intval($limit);
  36. $notice = pdo_fetchall("SELECT * FROM " . tablename('article_notice') . " WHERE is_display = 1 AND is_show_home = 1 ORDER BY displayorder DESC,id DESC LIMIT " . $limit, array(), 'id');
  37. foreach ($notice as $key => $notice_val) {
  38. $notice[$key]['style'] = iunserializer($notice_val['style']);
  39. }
  40. return $notice;
  41. }
  42. function article_news_all($filter = array(), $pindex = 1, $psize = 10) {
  43. global $_W;
  44. $condition = ' WHERE is_display = 1';
  45. $params = array();
  46. if(!empty($filter['title'])) {
  47. $condition .= ' AND title LIKE :title';
  48. $params[':title'] = "%{$filter['title']}%";
  49. }
  50. if($filter['cateid'] > 0) {
  51. $condition .= ' AND cateid = :cateid';
  52. $params[':cateid'] = $filter['cateid'];
  53. }
  54. $order = !empty($_W['setting']['news_display']) ? $_W['setting']['news_display'] : 'displayorder';
  55. $limit = ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
  56. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('article_news') . $condition, $params);
  57. $news = pdo_fetchall("SELECT * FROM " . tablename('article_news') . $condition . " ORDER BY " . $order . " DESC " . $limit, $params, 'id');
  58. return array('total' => $total, 'news' => $news);
  59. }
  60. function article_notice_all($filter = array(), $pindex = 1, $psize = 10) {
  61. global $_W;
  62. $condition = ' WHERE is_display = 1';
  63. $params = array();
  64. if(!empty($filter['title'])) {
  65. $condition .= ' AND title LIKE :title';
  66. $params[':title'] = "%{$filter['title']}%";
  67. }
  68. if($filter['cateid'] > 0) {
  69. $condition .= ' AND cateid = :cateid';
  70. $params[':cateid'] = $filter['cateid'];
  71. }
  72. $limit = ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
  73. $order = !empty($_W['setting']['notice_display']) ? $_W['setting']['notice_display'] : 'displayorder';
  74. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('article_notice') . $condition, $params);
  75. $notice = pdo_fetchall("SELECT * FROM " . tablename('article_notice') . $condition . " ORDER BY " . $order . " DESC " . $limit, $params, 'id');
  76. foreach ($notice as $key => $notice_val) {
  77. $notice[$key]['style'] = iunserializer($notice_val['style']);
  78. $notice[$key]['group'] = empty($notice_val['group']) ? array('vice_founder' => array(), 'normal' => array()) : iunserializer($notice_val['group']);
  79. if (empty($_W['user']) && !empty($notice_val['group']) || !empty($_W['user']['groupid']) && !empty($notice_val['group']) && !in_array($_W['user']['groupid'], $notice[$key]['group']['vice_founder']) && !in_array($_W['user']['groupid'], $notice[$key]['group']['normal'])) {
  80. unset($notice[$key]);
  81. }
  82. }
  83. return array('total' => $total, 'notice' => $notice);
  84. }
  85. function article_category_delete($id) {
  86. $id = intval($id);
  87. if (empty($id)) {
  88. return false;
  89. }
  90. load()->func('file');
  91. $category = pdo_fetch("SELECT id, parentid, nid FROM " . tablename('site_category')." WHERE id = " . $id);
  92. if (empty($category)) {
  93. return false;
  94. }
  95. if ($category['parentid'] == 0) {
  96. $children_cates = pdo_getall('site_category', array('parentid' => $id));
  97. pdo_update('site_article', array('pcate' => 0), array('pcate' => $id));
  98. if (!empty($children_cates)) {
  99. $children_cates_id = array_column($children_cates, 'id');
  100. pdo_update('site_article', array('ccate' => 0), array('ccate' => $children_cates_id), 'OR');
  101. }
  102. } else {
  103. pdo_update('site_article', array('ccate' => 0), array('ccate' => $id));
  104. }
  105. $navs = pdo_fetchall("SELECT icon, id FROM ".tablename('site_nav')." WHERE id IN (SELECT nid FROM ".tablename('site_category')." WHERE id = {$id} OR parentid = '$id')", array(), 'id');
  106. if (!empty($navs)) {
  107. foreach ($navs as $row) {
  108. file_delete($row['icon']);
  109. }
  110. pdo_query("DELETE FROM ".tablename('site_nav')." WHERE id IN (".implode(',', array_keys($navs)).")");
  111. }
  112. pdo_delete('site_category', array('id' => $id, 'parentid' => $id), 'OR');
  113. return true;
  114. }