article.mod.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. if (!empty($news)) {
  59. foreach ($news as $key => $new) {
  60. $news[$key]['createtime'] = date('Y-m-d H:i:s', $new['createtime']);
  61. }
  62. }
  63. return array('total' => $total, 'news' => $news);
  64. }
  65. function article_notice_all($filter = array(), $pindex = 1, $psize = 10) {
  66. global $_W;
  67. $condition = ' WHERE is_display = 1';
  68. $params = array();
  69. if(!empty($filter['title'])) {
  70. $condition .= ' AND title LIKE :title';
  71. $params[':title'] = "%{$filter['title']}%";
  72. }
  73. if($filter['cateid'] > 0) {
  74. $condition .= ' AND cateid = :cateid';
  75. $params[':cateid'] = $filter['cateid'];
  76. }
  77. $limit = ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
  78. $order = !empty($_W['setting']['notice_display']) ? $_W['setting']['notice_display'] : 'displayorder';
  79. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('article_notice') . $condition, $params);
  80. $notice = pdo_fetchall("SELECT * FROM " . tablename('article_notice') . $condition . " ORDER BY " . $order . " DESC " . $limit, $params, 'id');
  81. foreach ($notice as $key => $notice_val) {
  82. $notice[$key]['createtime'] = date('Y-m-d H:i:s', $notice_val['createtime']);
  83. $notice[$key]['style'] = iunserializer($notice_val['style']);
  84. $notice[$key]['group'] = empty($notice_val['group']) ? array('vice_founder' => array(), 'normal' => array()) : iunserializer($notice_val['group']);
  85. if (user_is_founder($_W['uid'], true)) {
  86. continue;
  87. }
  88. 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'])) {
  89. unset($notice[$key]);
  90. }
  91. }
  92. return array('total' => $total, 'notice' => $notice);
  93. }
  94. function article_category_delete($id) {
  95. $id = intval($id);
  96. if (empty($id)) {
  97. return false;
  98. }
  99. load()->func('file');
  100. $category = pdo_fetch("SELECT id, parentid, nid FROM " . tablename('site_category')." WHERE id = " . $id);
  101. if (empty($category)) {
  102. return false;
  103. }
  104. if ($category['parentid'] == 0) {
  105. $children_cates = pdo_getall('site_category', array('parentid' => $id));
  106. pdo_update('site_article', array('pcate' => 0), array('pcate' => $id));
  107. if (!empty($children_cates)) {
  108. $children_cates_id = array_column($children_cates, 'id');
  109. pdo_update('site_article', array('ccate' => 0), array('ccate' => $children_cates_id), 'OR');
  110. }
  111. } else {
  112. pdo_update('site_article', array('ccate' => 0), array('ccate' => $id));
  113. }
  114. $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');
  115. if (!empty($navs)) {
  116. foreach ($navs as $row) {
  117. file_delete($row['icon']);
  118. }
  119. pdo_delete('site_nav', array('id' => array_keys($navs)));
  120. }
  121. pdo_delete('site_category', array('id' => $id, 'parentid' => $id), 'OR');
  122. return true;
  123. }
  124. function article_comment_add($comment) {
  125. if (empty($comment['content'])) {
  126. return error(-1, '回复内容不能为空');
  127. }
  128. if (empty($comment['uid']) && empty($comment['openid'])) {
  129. return error(-1, '用户信息不能为空');
  130. }
  131. $article_comment_table = table('site_article_comment');
  132. $article_comment_table->addComment($comment);
  133. return true;
  134. }
  135. function article_comment_detail($article_lists) {
  136. global $_W;
  137. load()->model('mc');
  138. if (empty($article_lists)) {
  139. return array();
  140. }
  141. foreach ($article_lists as $list) {
  142. $parent_article_comment_ids[] = $list['id'];
  143. }
  144. $comment_table = table('site_article_comment');
  145. $comment_table->fill('is_read', ARTICLE_COMMENT_READ)->whereId($parent_article_comment_ids)->save();
  146. $son_comment_lists = $comment_table->searchWithUniacid($_W['uniacid'])->searchWithParentid($parent_article_comment_ids)->articleCommentList();
  147. if (!empty($son_comment_lists)) {
  148. foreach ($son_comment_lists as $list) {
  149. $uids[$list['uid']] = $list['uid'];
  150. }
  151. }
  152. $user_table = table('users');
  153. $users = $user_table->searchWithUid($uids)->getUsersList();
  154. foreach ($article_lists as &$list) {
  155. $list['createtime'] = date('Y-m-d H:i:s', $list['createtime']);
  156. $fans_info = mc_fansinfo($list['openid']);
  157. $list['username'] = $fans_info['nickname'];
  158. $list['avatar'] = $fans_info['avatar'];
  159. if (empty($son_comment_lists)) {
  160. continue;
  161. }
  162. foreach ($son_comment_lists as $son_comment) {
  163. if ($son_comment['parentid'] == $list['id']) {
  164. $son_comment['username'] = $users[$son_comment['uid']]['username'];
  165. $list['son_comment'][] = $son_comment;
  166. }
  167. }
  168. }
  169. return $article_lists;
  170. }