notice-show.ctrl.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. load()->model('article');
  8. load()->model('user');
  9. $dos = array( 'detail', 'list', 'like_comment', 'more_comments');
  10. $do = in_array($do, $dos) ? $do : 'list';
  11. if($do == 'detail') {
  12. $id = intval($_GPC['id']);
  13. $notice = article_notice_info($id);
  14. if(is_error($notice)) {
  15. itoast('公告不存在或已删除', referer(), 'error');
  16. }
  17. $comment_status = setting_load('notice_comment_status');
  18. $comment_status = empty($comment_status['notice_comment_status']) ? 0 : 1;
  19. if (checksubmit('submit')) {
  20. $comment_table = table('article_comment');
  21. if (empty($comment_status)) {
  22. itoast('未开启评论功能!', referer(), 'error');
  23. }
  24. $content = safe_gpc_string($_GPC['content']);
  25. if (empty($content)) {
  26. itoast('评论内容不能为空!', referer(), 'error');
  27. }
  28. $result = $comment_table->addComment(array(
  29. 'articleid' => $id,
  30. 'content' => $content,
  31. 'uid' => $_W['uid'],
  32. ));
  33. itoast($result ? '评论成功' : '评论失败', url('article/notice-show/detail', array('id' => $id, 'page' => 1)), $result ? 'success' : 'error');
  34. }
  35. pdo_update('article_notice', array('click +=' => 1), array('id' => $id));
  36. if(!empty($_W['uid'])) {
  37. pdo_update('article_unread_notice', array('is_new' => 0), array('notice_id' => $id, 'uid' => $_W['uid']));
  38. }
  39. $title = $notice['title'];
  40. }
  41. if ($do == 'more_comments') {
  42. $order = empty($_GPC['order']) || $_GPC['order'] == 'id' ? 'id' : 'like_num';
  43. $pageindex = max(1, intval($_GPC['page']));
  44. $pagesize = 15;
  45. $comment_table = table('article_comment');
  46. $comment_table->orderby('id', 'DESC');
  47. $comment_table->searchWithPage($pageindex, $pagesize);
  48. $comments = $comment_table->getCommentsByArticleid(intval($_GPC['id']));
  49. $total = $comment_table->getLastQueryTotal();
  50. if (!empty($comments)) {
  51. $uids = array();
  52. foreach ($comments as $comment) {
  53. $uids[$comment['uid']] = $comment['uid'];
  54. }
  55. $user_info = table('users')->searchWithUid($uids)->getUsersList();
  56. foreach ($comments as $k => $comment) {
  57. if (!empty($user_info[$comment['uid']])) {
  58. $comments[$k] = array_merge($user_info[$comment['uid']], $comment);
  59. }
  60. }
  61. }
  62. iajax(0, array(
  63. 'list' => array_values($comments),
  64. 'pager' => pagination($total, $pageindex, $pagesize, '', array('ajaxcallback' => true, 'callbackfuncname' => 'changePage'))
  65. ));
  66. }
  67. if ($do == 'like_comment') {
  68. $articleid = intval($_GPC['articleid']);
  69. $comment_id = intval($_GPC['id']);
  70. $article_comment_table = table('article_comment');
  71. $comment = $article_comment_table->getById($comment_id);
  72. if (empty($comment)) {
  73. iajax(1, '评论不存在');
  74. }
  75. $like_comment = $article_comment_table->getLikeComment($_W['uid'], $articleid, $comment_id);
  76. if (!empty($like_comment)) {
  77. iajax(1, '已赞');
  78. }
  79. if ($article_comment_table->likeComment($_W['uid'], $articleid, $comment_id)) {
  80. iajax(0);
  81. } else {
  82. iajax(1, '操作失败,请重试。');
  83. }
  84. }
  85. if($do == 'list') {
  86. $categroys = article_categorys('notice');
  87. $categroys[0] = array('title' => '所有公告');
  88. $cateid = intval($_GPC['cateid']);
  89. $pindex = max(1, intval($_GPC['page']));
  90. $psize = 20;
  91. $filter = array('cateid' => $cateid);
  92. $notices = article_notice_all($filter, $pindex, $psize);
  93. $total = intval($notices['total']);
  94. $data = $notices['notice'];
  95. $pager = pagination($total, $pindex, $psize);
  96. }
  97. template('article/notice-show');