wsqapi.class.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: wsqapi.class.php 34924 2014-08-27 06:33:08Z nemohou $
  7. */
  8. if (!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class WSQAPI {
  12. function forumdisplay_variables(&$variables) {
  13. global $_G;
  14. if(!$_G['wechat']['setting']['wsq_allow'] || !$_G['wechat']['setting']['showactivity']['tids']) {
  15. return;
  16. }
  17. $tids = array();
  18. foreach ($variables['forum_threadlist'] as &$thread) {
  19. if(in_array($thread['tid'], $_G['wechat']['setting']['showactivity']['tids'])) {
  20. $thread['showactivity'] = 1;
  21. $tids[] = $thread['tid'];
  22. }
  23. }
  24. $activities = C::t('forum_activity')->fetch_all($tids);
  25. foreach($activities as $tid => $activity) {
  26. $variables['showactivity'][$tid]['starttimefrom'] = dgmdate($activities[$tid]['starttimefrom']);
  27. $variables['showactivity'][$tid]['expiration'] = dgmdate($activities[$tid]['expiration']);
  28. $variables['showactivity'][$tid]['applynumber'] = $activities[$tid]['applynumber'];
  29. $variables['showactivity'][$tid]['thumb'] = $activity['aid'] ? $_G['siteurl'].getforumimg($activity['aid'], 0, 400, 400) : '';
  30. }
  31. }
  32. function viewthread_variables(&$variables) {
  33. if(!showActivity::init()) {
  34. return;
  35. }
  36. global $_G;
  37. $variables['thread']['showactivity'] = 1;
  38. $variables['special_activity']['thumb'] = preg_match('/^http:\//', $GLOBALS['activity']['thumb']) ? $GLOBALS['activity']['thumb'] : $_G['siteurl'].$GLOBALS['activity']['thumb'];
  39. unset($variables['special_activity']['attachurl']);
  40. if(empty($_GET['viewpid'])) {
  41. if(!$_GET['viewhot']) {
  42. $pids = array();
  43. foreach($variables['postlist'] as $post) {
  44. $pids[] = $post['pid'];
  45. }
  46. if($pids) {
  47. $posts = DB::fetch_all("SELECT pid, voters FROM %t WHERE pid IN (%n)", array('forum_debatepost', $pids), 'pid');
  48. $voters = array();
  49. foreach($variables['postlist'] as $key => $post) {
  50. $variables['postlist'][$key]['voters'] = intval($posts[$post['pid']]['voters']);
  51. if($_G['page'] == 1 && !$post['first'] && $_G['uid'] && $_G['uid'] == $post['authorid']) {
  52. unset($variables['postlist'][$key]);
  53. }
  54. }
  55. }
  56. $variables['postlist'] = array_values($variables['postlist']);
  57. $myarr = array();
  58. if($_G['uid'] && $_G['page'] == 1) {
  59. $pids = array();
  60. $posts = C::t('forum_post')->fetch_all_common_viewthread_by_tid($_G['tid'], 0, $_G['uid'], 1, 2, 0, 0, 0);
  61. foreach($posts as $pid => $post) {
  62. $myarr[$pid] = array(
  63. 'pid' => $pid,
  64. 'author' => $post['author'],
  65. 'authorid' => $post['authorid'],
  66. 'voters' => 0,
  67. );
  68. $pids[] = $post['pid'];
  69. }
  70. $posts = DB::fetch_all("SELECT pid, voters FROM %t WHERE pid IN (%n)", array('forum_debatepost', $pids), 'pid');
  71. foreach($posts as $pid => $post) {
  72. $myarr[$pid]['voters'] = intval($post['voters']);
  73. }
  74. if($myarr) {
  75. require_once libfile('function/attachment');
  76. parseattach(array_keys($myarr), array(), $myarr);
  77. }
  78. }
  79. $variables['special_activity']['my_postlist'] = array_values($myarr);
  80. $variables['special_activity']['view'] = 'new';
  81. } else {
  82. foreach($variables['postlist'] as $key => $post) {
  83. if(!$post['first']) {
  84. unset($variables['postlist'][$key]);
  85. }
  86. }
  87. $cachekey = 'showactivity_'.$_G['tid'];
  88. loadcache($cachekey);
  89. if(!$_G['cache'][$cachekey] || TIMESTAMP - $_G['cache'][$cachekey]['expiration'] > 600) {
  90. $posts = DB::fetch_all("SELECT pid, voters FROM %t d WHERE tid=%d AND voters>1 ORDER BY voters DESC LIMIT 500", array('forum_debatepost', $_G['tid']), 'pid');
  91. foreach($posts as $vpost) {
  92. $voters[$vpost['pid']] = $vpost['voters'];
  93. }
  94. $top = 1;
  95. $toparr = array();
  96. $posts = C::t('forum_post')->fetch_all_by_pid('tid:'.$_G['tid'], array_keys($voters), false, '', 0, 0, null, 0);
  97. foreach($voters as $pid => $voters) {
  98. if($posts[$pid]) {
  99. $toparr[$pid] = array(
  100. 'pid' => $pid,
  101. 'author' => $posts[$pid]['author'],
  102. 'authorid' => $posts[$pid]['authorid'],
  103. 'voters' => $voters,
  104. 'top' => $top++
  105. );
  106. if($top > 50) {
  107. break;
  108. }
  109. }
  110. }
  111. $variables['special_activity']['top_postlist'] = $toparr;
  112. savecache($cachekey, array('variable' => $toparr, 'expiration' => TIMESTAMP));
  113. } else {
  114. $variables['special_activity']['top_postlist'] = $_G['cache'][$cachekey]['variable'];
  115. }
  116. $hotpage = max(1, $_GET['page']);
  117. $start = max(0, ($hotpage - 1) * $_G['ppp']);
  118. $toplist = & $variables['special_activity']['top_postlist'];
  119. $toplist = array_slice($toplist, $start, $_G['ppp'], 1);
  120. require_once libfile('function/attachment');
  121. parseattach(array_keys($toplist), array(), $toplist);
  122. $toplist = array_values($toplist);
  123. $variables['special_activity']['view'] = 'hot';
  124. }
  125. } else {
  126. $comments = array();
  127. foreach($GLOBALS['comments'][$_GET['viewpid']] as $comment) {
  128. $comments[] = array(
  129. 'author' => $comment['author'],
  130. 'authorid' => $comment['authorid'],
  131. 'avatar' => avatar($comment['authorid'], 'small', 1),
  132. 'message' => $comment['comment'],
  133. 'dateline' => strip_tags(dgmdate($comment['dateline'], 'u')),
  134. );
  135. }
  136. $variables['postlist'] = array_merge($variables['postlist'], $comments);
  137. $variables['thread']['replies'] = $GLOBALS['commentcount'][$_GET['viewpid']];
  138. $voters = C::t('forum_debatepost')->fetch($_GET['viewpid']);
  139. $variables['thread']['recommend_add'] = $voters['voters'];
  140. }
  141. }
  142. }