article.mod.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 = 'notice') {
  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_notice_info($id) {
  12. $id = intval($id);
  13. $news = pdo_fetch('SELECT * FROM ' . tablename('article_notice') . ' WHERE id = :id', array(':id' => $id));
  14. if (empty($news)) {
  15. return error(-1, '公告不存在或已经删除');
  16. }
  17. return $news;
  18. }
  19. function article_notice_all($filter = array(), $pindex = 1, $psize = 10) {
  20. global $_W;
  21. $condition = ' WHERE is_display = 1';
  22. $params = array();
  23. if (!empty($filter['title'])) {
  24. $condition .= ' AND title LIKE :title';
  25. $params[':title'] = "%{$filter['title']}%";
  26. }
  27. if (!empty($filter['cateid'])) {
  28. $condition .= ' AND cateid = :cateid';
  29. $params[':cateid'] = $filter['cateid'];
  30. }
  31. $limit = ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
  32. $order = !empty($_W['setting']['notice_display']) ? $_W['setting']['notice_display'] : 'displayorder';
  33. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('article_notice') . $condition, $params);
  34. $notice = pdo_fetchall("SELECT * FROM " . tablename('article_notice') . $condition . " ORDER BY " . $order . " DESC " . $limit, $params, 'id');
  35. foreach ($notice as $key => $notice_val) {
  36. $notice[$key]['createtime'] = date('Y-m-d H:i:s', $notice_val['createtime']);
  37. $notice[$key]['style'] = iunserializer($notice_val['style']);
  38. $notice[$key]['group'] = empty($notice_val['group']) ? array('vice_founder' => array(), 'normal' => array()) : iunserializer($notice_val['group']);
  39. if ($_W['isadmin']) {
  40. continue;
  41. }
  42. if (!empty($notice_val['group'])) {
  43. if (($_W['isfounder'] && !empty($notice[$key]['group']['vice_founder']) && !in_array($_W['user']['groupid'], $notice[$key]['group']['vice_founder'])) || (!$_W['isfounder'] && !empty($notice[$key]['group']['normal']) && !in_array($_W['user']['groupid'], $notice[$key]['group']['normal']))) {
  44. unset($notice[$key]);
  45. }
  46. }
  47. }
  48. return array('total' => $total, 'notice' => $notice);
  49. }
  50. function article_category_delete($id) {
  51. $id = intval($id);
  52. if (empty($id)) {
  53. return false;
  54. }
  55. load()->func('file');
  56. $category = pdo_fetch("SELECT id, parentid, nid FROM " . tablename('site_category') . " WHERE id = :id", array(':id' => $id));
  57. if (empty($category)) {
  58. return false;
  59. }
  60. if ($category['parentid'] == 0) {
  61. $children_cates = pdo_getall('site_category', array('parentid' => $id));
  62. pdo_update('site_article', array('pcate' => 0), array('pcate' => $id));
  63. if (!empty($children_cates)) {
  64. $children_cates_id = array_column($children_cates, 'id');
  65. pdo_update('site_article', array('ccate' => 0), array('ccate' => $children_cates_id), 'OR');
  66. }
  67. } else {
  68. pdo_update('site_article', array('ccate' => 0), array('ccate' => $id));
  69. }
  70. $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' => $id), 'id');
  71. if (!empty($navs)) {
  72. foreach ($navs as $row) {
  73. file_delete($row['icon']);
  74. }
  75. pdo_delete('site_nav', array('id' => array_keys($navs)));
  76. }
  77. pdo_delete('site_category', array('id' => $id, 'parentid' => $id), 'OR');
  78. return true;
  79. }
  80. function article_comment_add($comment) {
  81. if (empty($comment['content'])) {
  82. return error(-1, '回复内容不能为空');
  83. }
  84. if (empty($comment['uid']) && empty($comment['openid'])) {
  85. return error(-1, '用户信息不能为空');
  86. }
  87. $article_comment_table = table('site_article_comment');
  88. $article_comment_table->addComment($comment);
  89. return true;
  90. }
  91. function article_comment_detail($article_lists) {
  92. global $_W;
  93. load()->model('mc');
  94. if (empty($article_lists)) {
  95. return array();
  96. }
  97. foreach ($article_lists as $list) {
  98. $parent_article_comment_ids[] = $list['id'];
  99. }
  100. table('site_article_comment')->fill('is_read', ARTICLE_COMMENT_READ)->whereId($parent_article_comment_ids)->save();
  101. $son_comment_lists = pdo_getall('site_article_comment', array('uniacid' => $_W['uniacid'], 'parentid in' => $parent_article_comment_ids));
  102. if (!empty($son_comment_lists)) {
  103. foreach ($son_comment_lists as $list) {
  104. $uids[$list['uid']] = $list['uid'];
  105. }
  106. }
  107. $user_table = table('users');
  108. $users = $user_table->searchWithUid($uids)->getUsersList();
  109. foreach ($article_lists as &$list) {
  110. $list['createtime'] = date('Y-m-d H:i:s', $list['createtime']);
  111. $fans_info = mc_fansinfo($list['openid']);
  112. $list['username'] = $fans_info['nickname'];
  113. $list['avatar'] = $fans_info['avatar'];
  114. if (empty($son_comment_lists)) {
  115. continue;
  116. }
  117. foreach ($son_comment_lists as $son_comment) {
  118. if ($son_comment['parentid'] == $list['id']) {
  119. $son_comment['username'] = $users[$son_comment['uid']]['username'];
  120. $list['son_comment'][] = $son_comment;
  121. }
  122. }
  123. }
  124. return $article_lists;
  125. }