人人商城

notice-show.ctrl.php 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $_W['page']['title'] = $notice['title'] . '-公告列表';
  36. pdo_update('article_notice', array('click +=' => 1), array('id' => $id));
  37. if(!empty($_W['uid'])) {
  38. pdo_update('article_unread_notice', array('is_new' => 0), array('notice_id' => $id, 'uid' => $_W['uid']));
  39. }
  40. $title = $notice['title'];
  41. }
  42. if ($do == 'more_comments') {
  43. $order = empty($_GPC['order']) || $_GPC['order'] == 'id' ? 'id' : 'like_num';
  44. $pageindex = max(1, intval($_GPC['page']));
  45. $pagesize = 15;
  46. $comment_table = table('article_comment');
  47. $comment_list = $comment_table->getComments(intval($_GPC['id']), $pageindex, $pagesize, $order);
  48. $comment_list['list'] = empty($comment_list['list']) ? array() : array_values($comment_list['list']);
  49. $comment_list['pager'] = pagination($comment_list['total'], $pageindex, $pagesize, '', array('ajaxcallback' => true, 'callbackfuncname' => 'changePage'));
  50. iajax(0, $comment_list);
  51. }
  52. if ($do == 'like_comment') {
  53. $articleid = intval($_GPC['articleid']);
  54. $comment_id = intval($_GPC['id']);
  55. $article_comment_table = table('article_comment');
  56. $comment = $article_comment_table->getById($comment_id);
  57. if (empty($comment)) {
  58. iajax(1, '评论不存在');
  59. }
  60. if ($article_comment_table->hasLiked($articleid, $comment_id)) {
  61. iajax(1, '已赞');
  62. }
  63. if ($article_comment_table->likeComment($_W['uid'], $articleid, $comment_id)) {
  64. iajax(0);
  65. } else {
  66. iajax(1, '操作失败,请重试。');
  67. }
  68. }
  69. if($do == 'list') {
  70. $_W['page']['title'] = '-新闻列表';
  71. $categroys = article_categorys('notice');
  72. $categroys[0] = array('title' => '所有公告');
  73. $cateid = intval($_GPC['cateid']);
  74. $_W['page']['title'] = $categroys[$cateid]['title'] . '-公告列表';
  75. $pindex = max(1, intval($_GPC['page']));
  76. $psize = 20;
  77. $filter = array('cateid' => $cateid);
  78. $notices = article_notice_all($filter, $pindex, $psize);
  79. $total = intval($notices['total']);
  80. $data = $notices['notice'];
  81. $pager = pagination($total, $pindex, $psize);
  82. }
  83. template('article/notice-show');