article.mod.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_delete('site_nav', array('id' => array_keys($navs)));
  111. }
  112. pdo_delete('site_category', array('id' => $id, 'parentid' => $id), 'OR');
  113. return true;
  114. }
  115. function article_comment_add($comment) {
  116. if (empty($comment['content'])) {
  117. return error(-1, '回复内容不能为空');
  118. }
  119. if (empty($comment['uid']) && empty($comment['openid'])) {
  120. return error(-1, '用户信息不能为空');
  121. }
  122. $article_comment_table = table('site_article_comment');
  123. $article_comment_table->addComment($comment);
  124. return true;
  125. }
  126. function article_comment_detail($article_lists) {
  127. global $_W;
  128. load()->model('mc');
  129. if (empty($article_lists)) {
  130. return array();
  131. }
  132. foreach ($article_lists as $list) {
  133. $parent_article_comment_ids[] = $list['id'];
  134. }
  135. $comment_table = table('site_article_comment');
  136. $comment_table->fill('is_read', ARTICLE_COMMENT_READ)->whereId($parent_article_comment_ids)->save();
  137. $son_comment_lists = $comment_table->searchWithUniacid($_W['uniacid'])->searchWithParentid($parent_article_comment_ids)->articleCommentList();
  138. if (!empty($son_comment_lists)) {
  139. foreach ($son_comment_lists as $list) {
  140. $uids[$list['uid']] = $list['uid'];
  141. }
  142. }
  143. $user_table = table('users');
  144. $users = $user_table->searchWithUid($uids)->getUsersList();
  145. foreach ($article_lists as &$list) {
  146. $list['createtime'] = date('Y-m-d H:i:s', $list['createtime']);
  147. $fans_info = mc_fansinfo($list['openid']);
  148. $list['username'] = $fans_info['nickname'];
  149. $list['avatar'] = $fans_info['avatar'];
  150. if (empty($son_comment_lists)) {
  151. continue;
  152. }
  153. foreach ($son_comment_lists as $son_comment) {
  154. if ($son_comment['parentid'] == $list['id']) {
  155. $son_comment['username'] = $users[$son_comment['uid']]['username'];
  156. $list['son_comment'][] = $son_comment;
  157. }
  158. }
  159. }
  160. return $article_lists;
  161. }