PageRenderTime 117ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/source/module/forum/forum_viewthread.php

https://github.com/jinbo51/DiscuzX
PHP | 1655 lines | 1488 code | 161 blank | 6 comment | 595 complexity | 2ef026aa7e8c2394ccc361de5d99b304 MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  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: forum_viewthread.php 33371 2013-06-03 05:58:41Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. require_once libfile('function/forumlist');
  12. require_once libfile('function/discuzcode');
  13. require_once libfile('function/post');
  14. $thread = & $_G['forum_thread'];
  15. $forum = & $_G['forum'];
  16. if(!$_G['forum_thread'] || !$_G['forum']) {
  17. showmessage('thread_nonexistence');
  18. }
  19. $page = max(1, $_G['page']);
  20. if($page === 1 && !empty($_G['setting']['antitheft']['allow']) && empty($_G['setting']['antitheft']['disable']['thread']) && empty($_G['forum']['noantitheft'])) {
  21. helper_antitheft::check($_G['forum_thread']['tid'], 'tid');
  22. }
  23. if($_G['setting']['cachethreadlife'] && $_G['forum']['threadcaches'] && !$_G['uid'] && $page == 1 && !$_G['forum']['special'] && empty($_GET['do']) && !defined('IN_ARCHIVER') && !defined('IN_MOBILE')) {
  24. viewthread_loadcache();
  25. }
  26. $threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array();
  27. $threadtable_info = !empty($_G['cache']['threadtable_info']) ? $_G['cache']['threadtable_info'] : array();
  28. $archiveid = $thread['threadtableid'];
  29. $thread['is_archived'] = $archiveid ? true : false;
  30. $thread['archiveid'] = $archiveid;
  31. $forum['threadtableid'] = $archiveid;
  32. $threadtable = $thread['threadtable'];
  33. $posttableid = $thread['posttableid'];
  34. $posttable = $thread['posttable'];
  35. $_G['action']['fid'] = $_G['fid'];
  36. $_G['action']['tid'] = $_G['tid'];
  37. if($_G['fid'] == $_G['setting']['followforumid'] && $_G['adminid'] != 1) {
  38. dheader("Location: home.php?mod=follow");
  39. }
  40. $close_leftinfo = intval($_G['setting']['close_leftinfo']);
  41. if($_G['setting']['close_leftinfo_userctrl']) {
  42. if($_G['cookie']['close_leftinfo'] == 1) {
  43. $close_leftinfo = 1;
  44. } elseif($_G['cookie']['close_leftinfo'] == 2) {
  45. $close_leftinfo = 0;
  46. }
  47. }
  48. $_GET['authorid'] = !empty($_GET['authorid']) ? intval($_GET['authorid']) : 0;
  49. $_GET['ordertype'] = !empty($_GET['ordertype']) ? intval($_GET['ordertype']) : 0;
  50. $_GET['from'] = in_array($_GET['from'], array('preview', 'portal', 'album')) ? $_GET['from'] : '';
  51. if($_GET['from'] == 'portal' && !$_G['setting']['portalstatus']) {
  52. $_GET['from'] = '';
  53. } elseif($_GET['from'] == 'preview' && !$_G['inajax']) {
  54. $_GET['from'] = '';
  55. } elseif($_GET['from'] == 'album' && ($_G['setting']['guestviewthumb']['flag'] && !$_G['uid'] || !$_G['group']['allowgetimage'])) {
  56. $_GET['from'] = '';
  57. }
  58. $fromuid = $_G['setting']['creditspolicy']['promotion_visit'] && $_G['uid'] ? '&amp;fromuid='.$_G['uid'] : '';
  59. $feeduid = $_G['forum_thread']['authorid'] ? $_G['forum_thread']['authorid'] : 0;
  60. $feedpostnum = $_G['forum_thread']['replies'] > $_G['ppp'] ? $_G['ppp'] : ($_G['forum_thread']['replies'] ? $_G['forum_thread']['replies'] : 1);
  61. if(!empty($_GET['extra'])) {
  62. parse_str($_GET['extra'], $extra);
  63. $_GET['extra'] = array();
  64. foreach($extra as $_k => $_v) {
  65. if(preg_match('/^\w+$/', $_k)) {
  66. if(!is_array($_v)) {
  67. $_GET['extra'][] = $_k.'='.rawurlencode($_v);
  68. } else {
  69. $_GET['extra'][] = http_build_query(array($_k => $_v));
  70. }
  71. }
  72. }
  73. $_GET['extra'] = implode('&', $_GET['extra']);
  74. }
  75. $_G['forum_threadindex'] = '';
  76. $skipaids = $aimgs = $_G['forum_posthtml'] = array();
  77. $thread['subjectenc'] = rawurlencode($_G['forum_thread']['subject']);
  78. $thread['short_subject'] = cutstr($_G['forum_thread']['subject'], 52);
  79. $navigation = '';
  80. if($_GET['from'] == 'portal') {
  81. if($_G['forum']['status'] == 3) {
  82. _checkviewgroup();
  83. }
  84. $_G['setting']['ratelogon'] = 1;
  85. $navigation = ' <em>&rsaquo;</em> <a href="portal.php">'.lang('core', 'portal').'</a>';
  86. $navsubject = $_G['forum_thread']['subject'];
  87. $navtitle = $_G['forum_thread']['subject'];
  88. }elseif($_GET['from'] == 'preview') {
  89. $_G['setting']['ratelogon'] = 1;
  90. } elseif($_G['forum']['status'] == 3) {
  91. _checkviewgroup();
  92. $nav = get_groupnav($_G['forum']);
  93. $navigation = ' <em>&rsaquo;</em> <a href="group.php">'.$_G['setting']['navs'][3]['navname'].'</a> '.$nav['nav'];
  94. $upnavlink = 'forum.php?mod=forumdisplay&amp;fid='.$_G['fid'].($_GET['extra'] && !IS_ROBOT ? '&amp;'.$_GET['extra'] : '');
  95. $_G['grouptypeid'] = $_G['forum']['fup'];
  96. } else {
  97. $navigation = '';
  98. $upnavlink = 'forum.php?mod=forumdisplay&amp;fid='.$_G['fid'].($_GET['extra'] && !IS_ROBOT ? '&amp;'.$_GET['extra'] : '');
  99. if($_G['forum']['type'] == 'sub') {
  100. $fup = $_G['cache']['forums'][$_G['forum']['fup']]['fup'];
  101. $t_link = $_G['cache']['forums'][$fup]['type'] == 'group' ? 'forum.php?gid='.$fup : 'forum.php?mod=forumdisplay&fid='.$fup;
  102. $navigation .= ' <em>&rsaquo;</em> <a href="'.$t_link.'">'.($_G['cache']['forums'][$fup]['name']).'</a>';
  103. }
  104. if($_G['forum']['fup']) {
  105. $fup = $_G['forum']['fup'];
  106. $t_link = $_G['cache']['forums'][$fup]['type'] == 'group' ? 'forum.php?gid='.$fup : 'forum.php?mod=forumdisplay&fid='.$fup;
  107. $navigation .= ' <em>&rsaquo;</em> <a href="'.$t_link.'">'.($_G['cache']['forums'][$fup]['name']).'</a>';
  108. }
  109. $t_link = 'forum.php?mod=forumdisplay&amp;fid='.$_G['fid'].($_GET['extra'] && !IS_ROBOT ? '&amp;'.$_GET['extra'] : '');
  110. $navigation .= ' <em>&rsaquo;</em> <a href="'.$t_link.'">'.($_G['forum']['name']).'</a>';
  111. if($archiveid) {
  112. if($threadtable_info[$archiveid]['displayname']) {
  113. $t_name = dhtmlspecialchars($threadtable_info[$archiveid]['displayname']);
  114. } else {
  115. $t_name = lang('core', 'archive').' '.$archiveid;
  116. }
  117. $navigation .= ' <em>&rsaquo;</em> <a href="forum.php?mod=forumdisplay&fid='.$_G['fid'].'&archiveid='.$archiveid.'">'.$t_name.'</a>';
  118. }
  119. unset($t_link, $t_name);
  120. }
  121. $_GET['extra'] = $_GET['extra'] ? rawurlencode($_GET['extra']) : '';
  122. if(@in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
  123. $canonical = rewriteoutput('forum_viewthread', 1, '', $_G['tid'], 1, '', '');
  124. } else {
  125. $canonical = 'forum.php?mod=viewthread&tid='.$_G['tid'];
  126. }
  127. $_G['setting']['seohead'] .= '<link href="'.$_G['siteurl'].$canonical.'" rel="canonical" />';
  128. $_G['forum_tagscript'] = '';
  129. $threadsort = $thread['sortid'] && isset($_G['forum']['threadsorts']['types'][$thread['sortid']]) ? 1 : 0;
  130. if($threadsort) {
  131. require_once libfile('function/threadsort');
  132. $threadsortshow = threadsortshow($thread['sortid'], $_G['tid']);
  133. }
  134. if(empty($_G['forum']['allowview'])) {
  135. if(!$_G['forum']['viewperm'] && !$_G['group']['readaccess']) {
  136. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  137. } elseif($_G['forum']['viewperm'] && !forumperm($_G['forum']['viewperm'])) {
  138. showmessagenoperm('viewperm', $_G['fid']);
  139. }
  140. } elseif($_G['forum']['allowview'] == -1) {
  141. showmessage('forum_access_view_disallow');
  142. }
  143. if($_G['forum']['formulaperm']) {
  144. formulaperm($_G['forum']['formulaperm']);
  145. }
  146. if($_G['forum']['password'] && $_G['forum']['password'] != $_G['cookie']['fidpw'.$_G['fid']]) {
  147. dheader("Location: $_G[siteurl]forum.php?mod=forumdisplay&fid=$_G[fid]");
  148. }
  149. if($_G['forum']['price'] && !$_G['forum']['ismoderator']) {
  150. $membercredits = C::t('common_member_forum_buylog')->get_credits($_G['uid'], $_G['fid']);
  151. $paycredits = $_G['forum']['price'] - $membercredits;
  152. if($paycredits > 0) {
  153. dheader("Location: $_G[siteurl]forum.php?mod=forumdisplay&fid=$_G[fid]");
  154. }
  155. }
  156. if($_G['forum_thread']['readperm'] && $_G['forum_thread']['readperm'] > $_G['group']['readaccess'] && !$_G['forum']['ismoderator'] && $_G['forum_thread']['authorid'] != $_G['uid']) {
  157. showmessage('thread_nopermission', NULL, array('readperm' => $_G['forum_thread']['readperm']), array('login' => 1));
  158. }
  159. $usemagic = array('user' => array(), 'thread' => array());
  160. $replynotice = getstatus($_G['forum_thread']['status'], 6);
  161. $hiddenreplies = getstatus($_G['forum_thread']['status'], 2);
  162. $rushreply = getstatus($_G['forum_thread']['status'], 3);
  163. $savepostposition = getstatus($_G['forum_thread']['status'], 1);
  164. $incollection = getstatus($_G['forum_thread']['status'], 9);
  165. $_G['forum_threadpay'] = FALSE;
  166. if($_G['forum_thread']['price'] > 0 && $_G['forum_thread']['special'] == 0) {
  167. if($_G['setting']['maxchargespan'] && TIMESTAMP - $_G['forum_thread']['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
  168. C::t('forum_thread')->update($_G['tid'], array('price' => 0), false, false, $archiveid);
  169. $_G['forum_thread']['price'] = 0;
  170. } else {
  171. $exemptvalue = $_G['forum']['ismoderator'] ? 128 : 16;
  172. if(!($_G['group']['exempt'] & $exemptvalue) && $_G['forum_thread']['authorid'] != $_G['uid']) {
  173. if(!(C::t('common_credit_log')->count_by_uid_operation_relatedid($_G['uid'], 'BTC', $_G['tid']))) {
  174. require_once libfile('thread/pay', 'include');
  175. $_G['forum_threadpay'] = TRUE;
  176. }
  177. }
  178. }
  179. }
  180. if($rushreply) {
  181. $rewardfloor = '';
  182. $rushresult = $rewardfloorarr = $rewardfloorarray = array();
  183. $rushresult = C::t('forum_threadrush')->fetch($_G['tid']);
  184. if($rushresult['creditlimit'] == -996) {
  185. $rushresult['creditlimit'] = '';
  186. }
  187. if((TIMESTAMP < $rushresult['starttimefrom'] || ($rushresult['starttimeto'] && TIMESTAMP > $rushresult['starttimeto']) || ($rushresult['stopfloor'] && $_G['forum_thread']['replies'] + 1 >= $rushresult['stopfloor'])) && $_G['forum_thread']['closed'] == 0) {
  188. C::t('forum_thread')->update($_G['tid'], array('closed'=>1));
  189. } elseif(($rushresult['starttimefrom'] && TIMESTAMP > $rushresult['starttimefrom']) && $_G['forum_thread']['closed'] == 1) {
  190. if(($rushresult['starttimeto'] && TIMESTAMP < $rushresult['starttimeto'] || !$rushresult['starttimeto']) && ($rushresult['stopfloor'] && $_G['forum_thread']['replies'] + 1 < $rushresult['stopfloor'] || !$rushresult['stopfloor'])) {
  191. C::t('forum_thread')->update($_G['tid'], array('closed'=>0));
  192. }
  193. }
  194. if($rushresult['starttimefrom'] > TIMESTAMP) {
  195. $rushresult['timer'] = $rushresult['starttimefrom'] - TIMESTAMP;
  196. $rushresult['timertype'] = 'start';
  197. } elseif($rushresult['starttimeto'] > TIMESTAMP) {
  198. $rushresult['timer'] = $rushresult['starttimeto'] - TIMESTAMP;
  199. $rushresult['timertype'] = 'end';
  200. }
  201. $rushresult['starttimefrom'] = $rushresult['starttimefrom'] ? dgmdate($rushresult['starttimefrom']) : '';
  202. $rushresult['starttimeto'] = $rushresult['starttimeto'] ? dgmdate($rushresult['starttimeto']) : '';
  203. $rushresult['creditlimit_title'] = $_G['setting']['creditstransextra'][11] ? $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][11]]['title'] : lang('forum/misc', 'credit_total');
  204. }
  205. if($_G['forum_thread']['replycredit'] > 0) {
  206. $_G['forum_thread']['replycredit_rule'] = C::t('forum_replycredit')->fetch($thread['tid']);
  207. $_G['forum_thread']['replycredit_rule']['remaining'] = $_G['forum_thread']['replycredit'] / $_G['forum_thread']['replycredit_rule']['extcredits'];
  208. $_G['forum_thread']['replycredit_rule']['extcreditstype'] = $_G['forum_thread']['replycredit_rule']['extcreditstype'] ? $_G['forum_thread']['replycredit_rule']['extcreditstype'] : $_G['setting']['creditstransextra'][10] ;
  209. }
  210. $_G['group']['raterange'] = $_G['setting']['modratelimit'] && $adminid == 3 && !$_G['forum']['ismoderator'] ? array() : $_G['group']['raterange'];
  211. $_G['group']['allowgetattach'] = !empty($_G['forum']['allowgetattach']) || ($_G['group']['allowgetattach'] && !$_G['forum']['getattachperm']) || forumperm($_G['forum']['getattachperm']);
  212. $_G['group']['allowgetimage'] = !empty($_G['forum']['allowgetimage']) || ($_G['group']['allowgetimage'] && !$_G['forum']['getattachperm']) || forumperm($_G['forum']['getattachperm']);
  213. $_G['getattachcredits'] = '';
  214. if($_G['forum_thread']['attachment']) {
  215. $exemptvalue = $_G['forum']['ismoderator'] ? 32 : 4;
  216. if(!($_G['group']['exempt'] & $exemptvalue)) {
  217. $creditlog = updatecreditbyaction('getattach', $_G['uid'], array(), '', 1, 0, $_G['forum_thread']['fid']);
  218. $p = '';
  219. if($creditlog['updatecredit']) for($i = 1;$i <= 8;$i++) {
  220. if($policy = $creditlog['extcredits'.$i]) {
  221. $_G['getattachcredits'] .= $p.$_G['setting']['extcredits'][$i]['title'].' '.$policy.' '.$_G['setting']['extcredits'][$i]['unit'];
  222. $p = ', ';
  223. }
  224. }
  225. }
  226. }
  227. $exemptvalue = $_G['forum']['ismoderator'] ? 64 : 8;
  228. $_G['forum_attachmentdown'] = $_G['group']['exempt'] & $exemptvalue;
  229. $seccodecheck = ($_G['setting']['seccodestatus'] & 4) && (!$_G['setting']['seccodedata']['minposts'] || getuserprofile('posts') < $_G['setting']['seccodedata']['minposts']);
  230. $secqaacheck = $_G['setting']['secqaa']['status'] & 2 && (!$_G['setting']['secqaa']['minposts'] || getuserprofile('posts') < $_G['setting']['secqaa']['minposts']);
  231. $usesigcheck = $_G['uid'] && $_G['group']['maxsigsize'];
  232. $postlist = $_G['forum_attachtags'] = $attachlist = $_G['forum_threadstamp'] = array();
  233. $aimgcount = 0;
  234. $_G['forum_attachpids'] = array();
  235. if(!empty($_GET['action']) && $_GET['action'] == 'printable' && $_G['tid']) {
  236. require_once libfile('thread/printable', 'include');
  237. dexit();
  238. }
  239. if($_G['forum_thread']['stamp'] >= 0) {
  240. $_G['forum_threadstamp'] = $_G['cache']['stamps'][$_G['forum_thread']['stamp']];
  241. }
  242. $lastmod = viewthread_lastmod($_G['forum_thread']);
  243. $showsettings = str_pad(decbin($_G['setting']['showsettings']), 3, '0', STR_PAD_LEFT);
  244. $showsignatures = $showsettings{0};
  245. $showavatars = $showsettings{1};
  246. $_G['setting']['showimages'] = $showsettings{2};
  247. $highlightstatus = isset($_GET['highlight']) && str_replace('+', '', $_GET['highlight']) ? 1 : 0;
  248. $_G['forum']['allowreply'] = isset($_G['forum']['allowreply']) ? $_G['forum']['allowreply'] : '';
  249. $_G['forum']['allowpost'] = isset($_G['forum']['allowpost']) ? $_G['forum']['allowpost'] : '';
  250. $allowpostreply = ($_G['forum']['allowreply'] != -1) && (($_G['forum_thread']['isgroup'] || (!$_G['forum_thread']['closed'] && !checkautoclose($_G['forum_thread']))) || $_G['forum']['ismoderator']) && ((!$_G['forum']['replyperm'] && $_G['group']['allowreply']) || ($_G['forum']['replyperm'] && forumperm($_G['forum']['replyperm'])) || $_G['forum']['allowreply']);
  251. $fastpost = $_G['setting']['fastpost'] && !$_G['forum_thread']['archiveid'] && ($_G['forum']['status'] != 3 || $_G['isgroupuser']);
  252. $allowfastpost = $_G['setting']['fastpost'] && $allowpostreply;
  253. if(!$_G['uid'] && ($_G['setting']['need_avatar'] || $_G['setting']['need_email'] || $_G['setting']['need_friendnum']) || !$_G['adminid'] && (!cknewuser(1) || $_G['setting']['newbiespan'] && (!getuserprofile('lastpost') || TIMESTAMP - getuserprofile('lastpost') < $_G['setting']['newbiespan'] * 60) && TIMESTAMP - $_G['member']['regdate'] < $_G['setting']['newbiespan'] * 60)) {
  254. $allowfastpost = false;
  255. }
  256. $_G['group']['allowpost'] = $_G['forum']['allowpost'] != -1 && ((!$_G['forum']['postperm'] && $_G['group']['allowpost']) || ($_G['forum']['postperm'] && forumperm($_G['forum']['postperm'])) || $_G['forum']['allowpost']);
  257. $_G['forum']['allowpostattach'] = isset($_G['forum']['allowpostattach']) ? $_G['forum']['allowpostattach'] : '';
  258. $allowpostattach = $allowpostreply && ($_G['forum']['allowpostattach'] != -1 && ($_G['forum']['allowpostattach'] == 1 || (!$_G['forum']['postattachperm'] && $_G['group']['allowpostattach']) || ($_G['forum']['postattachperm'] && forumperm($_G['forum']['postattachperm']))));
  259. if($_G['group']['allowpost']) {
  260. $_G['group']['allowpostpoll'] = $_G['group']['allowpostpoll'] && ($_G['forum']['allowpostspecial'] & 1);
  261. $_G['group']['allowposttrade'] = $_G['group']['allowposttrade'] && ($_G['forum']['allowpostspecial'] & 2);
  262. $_G['group']['allowpostreward'] = $_G['group']['allowpostreward'] && ($_G['forum']['allowpostspecial'] & 4) && isset($_G['setting']['extcredits'][$_G['setting']['creditstrans']]);
  263. $_G['group']['allowpostactivity'] = $_G['group']['allowpostactivity'] && ($_G['forum']['allowpostspecial'] & 8);
  264. $_G['group']['allowpostdebate'] = $_G['group']['allowpostdebate'] && ($_G['forum']['allowpostspecial'] & 16);
  265. } else {
  266. $_G['group']['allowpostpoll'] = $_G['group']['allowposttrade'] = $_G['group']['allowpostreward'] = $_G['group']['allowpostactivity'] = $_G['group']['allowpostdebate'] = FALSE;
  267. }
  268. $_G['forum']['threadplugin'] = $_G['group']['allowpost'] && $_G['setting']['threadplugins'] ? is_array($_G['forum']['threadplugin']) ? $_G['forum']['threadplugin'] : dunserialize($_G['forum']['threadplugin']) : array();
  269. $_G['setting']['visitedforums'] = $_G['setting']['visitedforums'] && $_G['forum']['status'] != 3 ? visitedforums() : '';
  270. $relatedthreadlist = array();
  271. $relatedthreadupdate = $tagupdate = FALSE;
  272. $relatedkeywords = $tradekeywords = $_G['forum_firstpid'] = '';
  273. if(!isset($_G['cookie']['collapse']) || strpos($_G['cookie']['collapse'], 'modarea_c') === FALSE) {
  274. $collapseimg['modarea_c'] = 'collapsed_no';
  275. $collapse['modarea_c'] = '';
  276. } else {
  277. $collapseimg['modarea_c'] = 'collapsed_yes';
  278. $collapse['modarea_c'] = 'display: none';
  279. }
  280. $threadtag = array();
  281. viewthread_updateviews($archiveid);
  282. $_G['setting']['infosidestatus']['posts'] = $_G['setting']['infosidestatus'][1] && isset($_G['setting']['infosidestatus']['f'.$_G['fid']]['posts']) ? $_G['setting']['infosidestatus']['f'.$_G['fid']]['posts'] : $_G['setting']['infosidestatus']['posts'];
  283. $postfieldsadd = $specialadd1 = $specialadd2 = $specialextra = '';
  284. $tpids = array();
  285. if($_G['forum_thread']['special'] == 2) {
  286. if(!empty($_GET['do']) && $_GET['do'] == 'tradeinfo') {
  287. require_once libfile('thread/trade', 'include');
  288. }
  289. $query = C::t('forum_trade')->fetch_all_thread_goods($_G['tid']);
  290. foreach($query as $trade) {
  291. $tpids[] = $trade['pid'];
  292. }
  293. $specialadd2 = 1;
  294. } elseif($_G['forum_thread']['special'] == 5) {
  295. $_GET['stand'] = isset($_GET['stand']) && in_array($_GET['stand'], array(0, 1, 2)) ? $_GET['stand'] : null;
  296. if(isset($_GET['stand'])) {
  297. $specialadd2 = 1;
  298. $specialextra = "&amp;stand=$_GET[stand]";
  299. }
  300. }
  301. $onlyauthoradd = $threadplughtml = '';
  302. $maxposition = 0;
  303. if(empty($_GET['viewpid'])) {
  304. $disablepos = !$rushreply && C::t('forum_threaddisablepos')->fetch($_G['tid']) ? 1 : 0;
  305. if(!$disablepos && !in_array($_G['forum_thread']['special'], array(2,3,5))) {
  306. if($_G['forum_thread']['maxposition']) {
  307. $maxposition = $_G['forum_thread']['maxposition'];
  308. } else {
  309. $maxposition = C::t('forum_post')->fetch_maxposition_by_tid($posttableid, $_G['tid']);
  310. }
  311. }
  312. $ordertype = empty($_GET['ordertype']) && getstatus($_G['forum_thread']['status'], 4) ? 1 : $_GET['ordertype'];
  313. if($_GET['from'] == 'album') {
  314. $ordertype = 1;
  315. }
  316. $sticklist = array();
  317. if($_G['page'] === 1 && $_G['forum_thread']['stickreply'] && empty($_GET['authorid'])) {
  318. $poststick = C::t('forum_poststick')->fetch_all_by_tid($_G['tid']);
  319. foreach(C::t('forum_post')->fetch_all($posttableid, array_keys($poststick)) as $post) {
  320. $post['position'] = $poststick[$post['pid']]['position'];
  321. $post['avatar'] = avatar($post['authorid'], 'small');
  322. $post['isstick'] = true;
  323. $sticklist[$post['pid']] = $post;
  324. }
  325. $stickcount = count($sticklist);
  326. }
  327. if($rushreply) {
  328. $rushids = $rushpids = $rushpositionlist = $preg = $arr = array();
  329. $str = ',,';
  330. $preg_str = rushreply_rule($rushresult);
  331. if($_GET['checkrush']) {
  332. $maxposition = 0;
  333. for($i = 1; $i <= $_G['forum_thread']['replies'] + 1; $i++) {
  334. $str = $str.$i.',,';
  335. }
  336. preg_match_all($preg_str, $str, $arr);
  337. $arr = $arr[0];
  338. foreach($arr as $var) {
  339. $var = str_replace(',', '', $var);
  340. $rushids[$var] = $var;
  341. }
  342. $temp_reply = $_G['forum_thread']['replies'];
  343. $_G['forum_thread']['replies'] = $countrushpost = max(0, count($rushids) - 1);
  344. $rushids = array_slice($rushids, ($page - 1) * $_G['ppp'], $_G['ppp']);
  345. foreach(C::t('forum_post')->fetch_all_by_tid_position($posttableid, $_G['tid'], $rushids) as $post) {
  346. $postarr[$post['position']] = $post;
  347. }
  348. } else {
  349. for($i = ($page - 1) * $_G['ppp'] + 1; $i <= $page * $_G['ppp']; $i++) {
  350. $str = $str.$i.',,';
  351. }
  352. preg_match_all($preg_str, $str, $arr);
  353. $arr = $arr[0];
  354. foreach($arr as $var) {
  355. $var = str_replace(',', '', $var);
  356. $rushids[$var] = $var;
  357. }
  358. $_G['forum_thread']['replies'] = $_G['forum_thread']['replies'] - 1;
  359. }
  360. }
  361. if(!empty($_GET['authorid'])) {
  362. $maxposition = 0;
  363. $_G['forum_thread']['replies'] = C::t('forum_post')->count_by_tid_invisible_authorid($_G['tid'], $_GET['authorid']);
  364. $_G['forum_thread']['replies']--;
  365. if($_G['forum_thread']['replies'] < 0) {
  366. showmessage('undefined_action');
  367. }
  368. $onlyauthoradd = 1;
  369. } elseif($_G['forum_thread']['special'] == 5) {
  370. if(isset($_GET['stand']) && $_GET['stand'] >= 0 && $_GET['stand'] < 3) {
  371. $_G['forum_thread']['replies'] = C::t('forum_debatepost')->count_by_tid_stand($_G['tid'], $_GET['stand']);
  372. } else {
  373. $_G['forum_thread']['replies'] = C::t('forum_post')->count_visiblepost_by_tid($_G['tid']);
  374. $_G['forum_thread']['replies'] > 0 && $_G['forum_thread']['replies']--;
  375. }
  376. } elseif($_G['forum_thread']['special'] == 2) {
  377. $tradenum = C::t('forum_trade')->fetch_counter_thread_goods($_G['tid']);
  378. $_G['forum_thread']['replies'] -= $tradenum;
  379. }
  380. if($maxposition) {
  381. $_G['forum_thread']['replies'] = $maxposition - 1;
  382. }
  383. $_G['ppp'] = $_G['forum']['threadcaches'] && !$_G['uid'] ? $_G['setting']['postperpage'] : $_G['ppp'];
  384. $totalpage = ceil(($_G['forum_thread']['replies'] + 1) / $_G['ppp']);
  385. $page > $totalpage && $page = $totalpage;
  386. $_G['forum_pagebydesc'] = !$maxposition && $page > 2 && $page > ($totalpage / 2) ? TRUE : FALSE;
  387. if($_G['forum_pagebydesc']) {
  388. $firstpagesize = ($_G['forum_thread']['replies'] + 1) % $_G['ppp'];
  389. $_G['forum_ppp3'] = $_G['forum_ppp2'] = $page == $totalpage && $firstpagesize ? $firstpagesize : $_G['ppp'];
  390. $realpage = $totalpage - $page + 1;
  391. if($firstpagesize == 0) {
  392. $firstpagesize = $_G['ppp'];
  393. }
  394. $start_limit = max(0, ($realpage - 2) * $_G['ppp'] + $firstpagesize);
  395. $_G['forum_numpost'] = ($page - 1) * $_G['ppp'];
  396. if($ordertype != 1) {
  397. } else {
  398. $_G['forum_numpost'] = $_G['forum_thread']['replies'] + 2 - $_G['forum_numpost'] + ($page > 1 ? 1 : 0);
  399. }
  400. } else {
  401. $start_limit = $_G['forum_numpost'] = max(0, ($page - 1) * $_G['ppp']);
  402. if($start_limit > $_G['forum_thread']['replies']) {
  403. $start_limit = $_G['forum_numpost'] = 0;
  404. $page = 1;
  405. }
  406. if($ordertype != 1) {
  407. } else {
  408. $_G['forum_numpost'] = $_G['forum_thread']['replies'] + 2 - $_G['forum_numpost'] + ($page > 1 ? 1 : 0);
  409. }
  410. }
  411. $multipage = multi($_G['forum_thread']['replies'] + 1, $_G['ppp'], $page, 'forum.php?mod=viewthread&tid='.$_G['tid'].
  412. ($_G['forum_thread']['is_archived'] ? '&archive='.$_G['forum_thread']['archiveid'] : '').
  413. '&amp;extra='.$_GET['extra'].
  414. ($ordertype && $ordertype != getstatus($_G['forum_thread']['status'], 4) ? '&amp;ordertype='.$ordertype : '').
  415. (isset($_GET['highlight']) ? '&amp;highlight='.rawurlencode($_GET['highlight']) : '').
  416. (!empty($_GET['authorid']) ? '&amp;authorid='.$_GET['authorid'] : '').
  417. (!empty($_GET['from']) ? '&amp;from='.$_GET['from'] : '').
  418. (!empty($_GET['checkrush']) ? '&amp;checkrush='.$_GET['checkrush'] : '').
  419. (!empty($_GET['modthreadkey']) ? '&amp;modthreadkey='.rawurlencode($_GET['modthreadkey']) : '').
  420. $specialextra);
  421. } else {
  422. $_GET['viewpid'] = intval($_GET['viewpid']);
  423. $pageadd = "AND p.pid='$_GET[viewpid]'";
  424. }
  425. $_G['forum_newpostanchor'] = $_G['forum_postcount'] = 0;
  426. $_G['forum_onlineauthors'] = $_G['forum_cachepid'] = $_G['blockedpids'] = array();
  427. $isdel_post = $cachepids = $postusers = $skipaids = array();
  428. if($_G['forum_auditstatuson'] || in_array($_G['forum_thread']['displayorder'], array(-2, -3, -4)) && $_G['forum_thread']['authorid'] == $_G['uid']) {
  429. $visibleallflag = 1;
  430. }
  431. if($maxposition) {
  432. $start = ($page - 1) * $_G['ppp'] + 1;
  433. $end = $start + $_G['ppp'];
  434. if($ordertype == 1) {
  435. $end = $maxposition - ($page - 1) * $_G['ppp'] + ($page > 1 ? 2 : 1);
  436. $start = $end - $_G['ppp'] + ($page > 1 ? 0 : 1);
  437. $start = max(array(1,$start));
  438. }
  439. $have_badpost = $realpost = $lastposition = 0;
  440. foreach(C::t('forum_post')->fetch_all_by_tid_range_position($posttableid, $_G['tid'], $start, $end, $maxposition, $ordertype) as $post) {
  441. if($post['invisible'] != 0) {
  442. $have_badpost = 1;
  443. }
  444. $cachepids[$post[position]] = $post['pid'];
  445. $postarr[$post[position]] = $post;
  446. $lastposition = $post['position'];
  447. }
  448. $realpost = count($postarr);
  449. if($realpost != $_G['ppp'] || $have_badpost) {
  450. $k = 0;
  451. for($i = $start; $i < $end; $i ++) {
  452. if(!empty($cachepids[$i])) {
  453. $k = $cachepids[$i];
  454. $isdel_post[$i] = array('deleted' => 1, 'pid' => $k, 'message' => '', 'position' => $i);
  455. } elseif($i < $maxposition || ($lastposition && $i < $lastposition)) {
  456. $isdel_post[$i] = array('deleted' => 1, 'pid' => $k, 'message' => '', 'position' => $i);
  457. }
  458. $k ++;
  459. }
  460. }
  461. $pagebydesc = false;
  462. }
  463. if($_GET['checkrush'] && $rushreply) {
  464. $_G['forum_thread']['replies'] = $temp_reply;
  465. }
  466. if(!$maxposition && empty($postarr)) {
  467. if(empty($_GET['viewpid'])) {
  468. if($_G['forum_thread']['special'] == 2) {
  469. $postarr = C::t('forum_post')->fetch_all_tradepost_viewthread_by_tid($_G['tid'], $visibleallflag, $_GET['authorid'], $tpids, $_G['forum_pagebydesc'], $ordertype, $start_limit, ($_G['forum_pagebydesc'] ? $_G['forum_ppp2'] : $_G['ppp']));
  470. } elseif($_G['forum_thread']['special'] == 5) {
  471. $postarr = C::t('forum_post')->fetch_all_debatepost_viewthread_by_tid($_G['tid'], $visibleallflag, $_GET['authorid'], $_GET['stand'], $_G['forum_pagebydesc'], $ordertype, $start_limit, ($_G['forum_pagebydesc'] ? $_G['forum_ppp2'] : $_G['ppp']));
  472. } else {
  473. $postarr = C::t('forum_post')->fetch_all_common_viewthread_by_tid($_G['tid'], $visibleallflag, $_GET['authorid'], $_G['forum_pagebydesc'], $ordertype, $_G['forum_thread']['replies'] + 1, $start_limit, ($_G['forum_pagebydesc'] ? $_G['forum_ppp2'] : $_G['ppp']));
  474. }
  475. } else {
  476. $post = array();
  477. if($_G['forum_thread']['special'] == 2) {
  478. if(!in_array($_GET['viewpid'], $tpids)) {
  479. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'],$_GET['viewpid']);
  480. }
  481. } elseif($_G['forum_thread']['special'] == 5) {
  482. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['viewpid']);
  483. $debatpost = C::t('forum_debatepost')->fetch($_GET['viewpid']);
  484. if(!isset($_GET['stand']) || (isset($_GET['stand']) && ($post['first'] == 1 || $debatpost['stand'] == $_GET['stand']))) {
  485. $post = array_merge($post, $debatpost);
  486. } else {
  487. $post = array();
  488. }
  489. unset($debatpost);
  490. } else {
  491. $post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['viewpid']);
  492. }
  493. if($post) {
  494. if($visibleallflag || (!$visibleallflag && !$post['invisible'])) {
  495. $postarr[0] = $post;
  496. }
  497. }
  498. }
  499. }
  500. if(!empty($isdel_post)) {
  501. $updatedisablepos = false;
  502. foreach($isdel_post as $id => $post) {
  503. if(isset($postarr[$id]['invisible']) && ($postarr[$id]['invisible'] == 0 || $postarr[$id]['invisible'] == -3 || $visibleallflag)) {
  504. continue;
  505. }
  506. $postarr[$id] = $post;
  507. $updatedisablepos = true;
  508. }
  509. if($updatedisablepos && !$rushreply) {
  510. C::t('forum_threaddisablepos')->insert(array('tid' => $_G['tid']), false, true);
  511. dheader("Location:forum.php?mod=viewthread&tid=$_G[tid]");
  512. }
  513. $ordertype != 1 ? ksort($postarr) : krsort($postarr);
  514. }
  515. $summary = '';
  516. if($page == 1 && $ordertype == 1) {
  517. $firstpost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($_G['tid']);
  518. if($firstpost['invisible'] == 0 || $visibleallflag == 1) {
  519. $postarr = array_merge(array($firstpost), $postarr);
  520. unset($firstpost);
  521. }
  522. }
  523. $tagnames = $locationpids = $hotpostarr = $hotpids = $member_blackList = array();
  524. $remainhots = ($_G['page'] == 1 && !$rushreply && !$hiddenreplies && !$_G['forum_thread']['special'] && !$_G['forum']['noforumrecommend'] && empty($_GET['authorid'])) ? $_G['setting']['threadhotreplies'] : 0;
  525. if($remainhots) {
  526. $hotpids = array_keys(C::t('forum_hotreply_number')->fetch_all_by_tid_total($_G['tid'], 10));
  527. $remainhots = $remainhots - count($hotpids);
  528. }
  529. if($_G['setting']['nofilteredpost'] && $_G['forum_thread']['replies'] > $_G['setting']['postperpage'] && $remainhots) {
  530. $hotpids = array_merge($hotpids, array_keys(C::t('forum_filter_post')->fetch_all_by_tid_postlength_limit($_G['tid'], $remainhots)));
  531. }
  532. if($hotpids) {
  533. $hotposts = C::t('forum_post')->fetch_all_by_pid($posttableid, $hotpids);
  534. foreach($hotpids as $hotpid) {
  535. if($hotposts[$hotpid]) {
  536. $hotpostarr[$hotpid] = $hotposts[$hotpid];
  537. $hotpostarr[$hotpid]['hotrecommended'] = true;
  538. }
  539. }
  540. unset($hotposts);
  541. }
  542. if($hotpostarr || $sticklist) {
  543. $_newpostarr_first = array_shift($postarr);
  544. $postarr = (array)$sticklist + (array)$hotpostarr + $postarr;
  545. array_unshift($postarr, $_newpostarr_first);
  546. unset($_newpostarr_first, $sticklist);
  547. }
  548. foreach($postarr as $post) {
  549. if(($onlyauthoradd && empty($post['anonymous']) || !$onlyauthoradd) && !isset($postlist[$post['pid']])) {
  550. if(isset($hotpostarr[$post['pid']])) {
  551. $post['existinfirstpage'] = true;
  552. }
  553. $postusers[$post['authorid']] = array();
  554. if($post['first']) {
  555. if($ordertype == 1 && $page != 1) {
  556. continue;
  557. }
  558. $_G['forum_firstpid'] = $post['pid'];
  559. if(IS_ROBOT || $_G['adminid'] == 1) $summary = str_replace(array("\r", "\n"), '', messagecutstr(strip_tags($post['message']), 160));
  560. $tagarray_all = $posttag_array = array();
  561. $tagarray_all = explode("\t", $post['tags']);
  562. if($tagarray_all) {
  563. foreach($tagarray_all as $var) {
  564. if($var) {
  565. $tag = explode(',', $var);
  566. $posttag_array[] = $tag;
  567. $tagnames[] = $tag[1];
  568. }
  569. }
  570. }
  571. $post['tags'] = $posttag_array;
  572. if($post['tags']) {
  573. $post['relateitem'] = getrelateitem($post['tags'], $post['tid'], $_G['setting']['relatenum'], $_G['setting']['relatetime']);
  574. }
  575. if(!$_G['forum']['disablecollect']) {
  576. if($incollection) {
  577. $post['relatecollection'] = getrelatecollection($post['tid'], false, $post['releatcollectionnum'], $post['releatcollectionmore']);
  578. if($_G['group']['allowcommentcollection'] && $_GET['ctid']) {
  579. $ctid = dintval($_GET['ctid']);
  580. $post['sourcecollection'] = C::t('forum_collection')->fetch($ctid);
  581. }
  582. } else {
  583. $post['releatcollectionnum'] = 0;
  584. }
  585. }
  586. }
  587. $postlist[$post['pid']] = $post;
  588. }
  589. }
  590. unset($hotpostarr);
  591. $seodata = array('forum' => $_G['forum']['name'], 'fup' => $_G['cache']['forums'][$fup]['name'], 'subject' => $_G['forum_thread']['subject'], 'summary' => $summary, 'tags' => @implode(',', $tagnames), 'page' => intval($_GET['page']));
  592. if($_G['forum']['status'] != 3) {
  593. $seotype = 'viewthread';
  594. } else {
  595. $seotype = 'viewthread_group';
  596. $seodata['first'] = $nav['first']['name'];
  597. $seodata['second'] = $nav['second']['name'];
  598. }
  599. list($navtitle, $metadescription, $metakeywords) = get_seosetting($seotype, $seodata);
  600. if(!$navtitle) {
  601. $navtitle = helper_seo::get_title_page($_G['forum_thread']['subject'], $_G['page']).' - '.strip_tags($_G['forum']['name']);
  602. $nobbname = false;
  603. } else {
  604. $nobbname = true;
  605. }
  606. if(!$metakeywords) {
  607. $metakeywords = strip_tags($thread['subject']);
  608. }
  609. if(!$metadescription) {
  610. $metadescription = $summary.' '.strip_tags($_G['forum_thread']['subject']);
  611. }
  612. $_G['allblocked'] = true;
  613. $postno = & $_G['cache']['custominfo']['postno'];
  614. $postnostick = str_replace(array('<sup>', '</sup>'), '', $postno[0]);
  615. if($postusers) {
  616. $member_verify = $member_field_forum = $member_status = $member_count = $member_profile = $member_field_home = array();
  617. $uids = array_keys($postusers);
  618. $uids = array_filter($uids);
  619. $selfuids = $uids;
  620. if($_G['setting']['threadblacklist'] && $_G['uid'] && !in_array($_G['uid'], $selfuids)) {
  621. $selfuids[] = $_G['uid'];
  622. }
  623. if(!($_G['setting']['threadguestlite'] && !$_G['uid'])) {
  624. if($_G['setting']['verify']['enabled']) {
  625. $member_verify = C::t('common_member_verify')->fetch_all($uids);
  626. foreach($member_verify as $uid => $data) {
  627. foreach($_G['setting']['verify'] as $vid => $verify) {
  628. if($verify['available'] && $verify['showicon']) {
  629. if($data['verify'.$vid] == 1) {
  630. $member_verify[$uid]['verifyicon'][] = $vid;
  631. } elseif (!empty($verify['unverifyicon'])) {
  632. $member_verify[$uid]['unverifyicon'][] = $vid;
  633. }
  634. }
  635. }
  636. }
  637. }
  638. $member_count = C::t('common_member_count')->fetch_all($selfuids);
  639. $member_status = C::t('common_member_status')->fetch_all($uids);
  640. $member_field_forum = C::t('common_member_field_forum')->fetch_all($uids);
  641. $member_profile = C::t('common_member_profile')->fetch_all($uids);
  642. $member_field_home = C::t('common_member_field_home')->fetch_all($uids);
  643. }
  644. if($_G['setting']['threadblacklist'] && $_G['uid'] && $member_count[$_G['uid']]['blacklist']) {
  645. $member_blackList = C::t('home_blacklist')->fetch_all_by_uid_buid($_G['uid'], $uids);
  646. }
  647. foreach(C::t('common_member')->fetch_all($uids) as $uid => $postuser) {
  648. $member_field_home[$uid]['privacy'] = empty($member_field_home[$uid]['privacy']) ? array() : dunserialize($member_field_home[$uid]['privacy']);
  649. $postuser['memberstatus'] = $postuser['status'];
  650. $postuser['authorinvisible'] = $member_status[$uid]['invisible'];
  651. $postuser['signature'] = $member_field_forum[$uid]['sightml'];
  652. unset($member_field_home[$uid]['privacy']['feed'], $member_field_home[$uid]['privacy']['view'], $postuser['status'], $member_status[$uid]['invisible'], $member_field_forum[$uid]['sightml']);
  653. $postusers[$uid] = array_merge((array)$member_verify[$uid], (array)$member_field_home[$uid], (array)$member_profile[$uid], (array)$member_count[$uid], (array)$member_status[$uid], (array)$member_field_forum[$uid], $postuser);
  654. if($postusers[$uid]['regdate'] + $postusers[$uid]['oltime'] * 3600 > TIMESTAMP) {
  655. $postusers[$uid]['oltime'] = 0;
  656. }
  657. $postusers[$uid]['office'] = $postusers[$uid]['position'];
  658. $postusers[$uid]['inblacklist'] = $member_blackList[$uid] ? true : false;
  659. $postusers[$uid]['groupcolor'] = $_G['cache']['usergroups'][$postuser['groupid']]['color'];
  660. unset($postusers[$uid]['position']);
  661. }
  662. unset($member_field_forum, $member_status, $member_count, $member_profile, $member_field_home, $member_blackList);
  663. $_G['medal_list'] = array();
  664. foreach($postlist as $pid => $post) {
  665. if(getstatus($post['status'], 6)) {
  666. $locationpids[] = $pid;
  667. }
  668. $post = array_merge($postlist[$pid], (array)$postusers[$post['authorid']]);
  669. $postlist[$pid] = viewthread_procpost($post, $_G['member']['lastvisit'], $ordertype, $maxposition);
  670. }
  671. }
  672. if($_G['allblocked']) {
  673. $_G['blockedpids'] = array();
  674. }
  675. if($locationpids) {
  676. $locations = C::t('forum_post_location')->fetch_all($locationpids);
  677. }
  678. if($postlist && $rushids) {
  679. foreach($postlist as $pid => $post) {
  680. $post['number'] = $post['position'];
  681. $postlist[$pid] = checkrushreply($post);
  682. }
  683. }
  684. if($_G['setting']['repliesrank'] && $postlist) {
  685. if($postlist) {
  686. foreach(C::t('forum_hotreply_number')->fetch_all_by_pids(array_keys($postlist)) as $pid => $post) {
  687. $postlist[$pid]['postreview']['support'] = dintval($post['support']);
  688. $postlist[$pid]['postreview']['against'] = dintval($post['against']);
  689. }
  690. }
  691. }
  692. if($_G['forum_thread']['special'] > 0 && (empty($_GET['viewpid']) || $_GET['viewpid'] == $_G['forum_firstpid'])) {
  693. $_G['forum_thread']['starttime'] = gmdate($_G['forum_thread']['dateline']);
  694. $_G['forum_thread']['remaintime'] = '';
  695. switch($_G['forum_thread']['special']) {
  696. case 1: require_once libfile('thread/poll', 'include'); break;
  697. case 2: require_once libfile('thread/trade', 'include'); break;
  698. case 3: require_once libfile('thread/reward', 'include'); break;
  699. case 4: require_once libfile('thread/activity', 'include'); break;
  700. case 5: require_once libfile('thread/debate', 'include'); break;
  701. case 127:
  702. if($_G['forum_firstpid']) {
  703. $sppos = strpos($postlist[$_G['forum_firstpid']]['message'], chr(0).chr(0).chr(0));
  704. $specialextra = substr($postlist[$_G['forum_firstpid']]['message'], $sppos + 3);
  705. $postlist[$_G['forum_firstpid']]['message'] = substr($postlist[$_G['forum_firstpid']]['message'], 0, $sppos);
  706. if($specialextra) {
  707. if(array_key_exists($specialextra, $_G['setting']['threadplugins'])) {
  708. @include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  709. $classname = 'threadplugin_'.$specialextra;
  710. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'viewthread')) {
  711. $threadplughtml = $threadpluginclass->viewthread($_G['tid']);
  712. }
  713. }
  714. }
  715. }
  716. break;
  717. }
  718. }
  719. if(empty($_GET['authorid']) && empty($postlist)) {
  720. if($rushreply) {
  721. dheader("Location: forum.php?mod=redirect&tid=$_G[tid]&goto=lastpost");
  722. } else {
  723. $replies = C::t('forum_post')->count_visiblepost_by_tid($_G['tid']);
  724. $replies = intval($replies) - 1;
  725. if($_G['forum_thread']['replies'] != $replies && $replies > 0) {
  726. C::t('forum_thread')->update($_G['tid'], array('replies' => $replies), false, false, $archiveid);
  727. dheader("Location: forum.php?mod=redirect&tid=$_G[tid]&goto=lastpost");
  728. }
  729. }
  730. }
  731. if($_G['forum_pagebydesc'] && (!$savepostposition || $_GET['ordertype'] == 1)) {
  732. $postlist = array_reverse($postlist, TRUE);
  733. }
  734. if(!empty($_G['setting']['sessionclose'])) {
  735. $_G['setting']['vtonlinestatus'] = 1;
  736. }
  737. if($_G['setting']['vtonlinestatus'] == 2 && $_G['forum_onlineauthors']) {
  738. foreach(C::app()->session->fetch_all_by_uid(array_keys($_G['forum_onlineauthors'])) as $author) {
  739. if(!$author['invisible']) {
  740. $_G['forum_onlineauthors'][$author['uid']] = 1;
  741. }
  742. }
  743. } else {
  744. $_G['forum_onlineauthors'] = array();
  745. }
  746. $ratelogs = $comments = $commentcount = $totalcomment = array();
  747. if($_G['forum_cachepid']) {
  748. foreach(C::t('forum_postcache')->fetch_all($_G['forum_cachepid']) as $postcache) {
  749. if($postcache['rate']) {
  750. $postcache['rate'] = dunserialize($postcache['rate']);
  751. $postlist[$postcache['pid']]['ratelog'] = $postcache['rate']['ratelogs'];
  752. $postlist[$postcache['pid']]['ratelogextcredits'] = $postcache['rate']['extcredits'];
  753. $postlist[$postcache['pid']]['totalrate'] = $postcache['rate']['totalrate'];
  754. }
  755. if($postcache['comment']) {
  756. $postcache['comment'] = dunserialize($postcache['comment']);
  757. $commentcount[$postcache['pid']] = $postcache['comment']['count'];
  758. $comments[$postcache['pid']] = $postcache['comment']['data'];
  759. $totalcomment[$postcache['pid']] = $postcache['comment']['totalcomment'];
  760. }
  761. unset($_G['forum_cachepid'][$postcache['pid']]);
  762. }
  763. $postcache = $ratelogs = array();
  764. if($_G['forum_cachepid']) {
  765. list($ratelogs, $postlist, $postcache) = C::t('forum_ratelog')->fetch_postrate_by_pid($_G['forum_cachepid'], $postlist, $postcache, $_G['setting']['ratelogrecord']);
  766. }
  767. foreach($postlist as $key => $val) {
  768. if(!empty($val['ratelogextcredits'])) {
  769. ksort($postlist[$key]['ratelogextcredits']);
  770. }
  771. }
  772. if($_G['forum_cachepid'] && $_G['setting']['commentnumber']) {
  773. list($comments, $postcache, $commentcount, $totalcomment) = C::t('forum_postcomment')->fetch_postcomment_by_pid($_G['forum_cachepid'], $postcache, $commentcount, $totalcomment, $_G['setting']['commentnumber']);
  774. }
  775. foreach($postcache as $pid => $data) {
  776. C::t('forum_postcache')->insert(array('pid' => $pid, 'rate' => serialize($data['rate']), 'comment' => serialize($data['comment']), 'dateline' => TIMESTAMP), false, true);
  777. }
  778. }
  779. if($_G['forum_attachpids'] && !defined('IN_ARCHIVER')) {
  780. require_once libfile('function/attachment');
  781. if(is_array($threadsortshow) && !empty($threadsortshow['sortaids'])) {
  782. $skipaids = $threadsortshow['sortaids'];
  783. }
  784. parseattach($_G['forum_attachpids'], $_G['forum_attachtags'], $postlist, $skipaids);
  785. }
  786. if(empty($postlist)) {
  787. showmessage('post_not_found');
  788. } elseif(!defined('IN_MOBILE_API')) {
  789. foreach($postlist as $pid => $post) {
  790. $postlist[$pid]['message'] = preg_replace("/\[attach\]\d+\[\/attach\]/i", '', $postlist[$pid]['message']);
  791. }
  792. }
  793. if(defined('IN_ARCHIVER')) {
  794. include loadarchiver('forum/viewthread');
  795. exit();
  796. }
  797. $_G['forum_thread']['heatlevel'] = $_G['forum_thread']['recommendlevel'] = 0;
  798. if($_G['setting']['heatthread']['iconlevels']) {
  799. foreach($_G['setting']['heatthread']['iconlevels'] as $k => $i) {
  800. if($_G['forum_thread']['heats'] > $i) {
  801. $_G['forum_thread']['heatlevel'] = $k + 1;
  802. break;
  803. }
  804. }
  805. }
  806. if(!empty($_G['setting']['recommendthread']['status']) && $_G['forum_thread']['recommends']) {
  807. foreach($_G['setting']['recommendthread']['iconlevels'] as $k => $i) {
  808. if($_G['forum_thread']['recommends'] > $i) {
  809. $_G['forum_thread']['recommendlevel'] = $k+1;
  810. break;
  811. }
  812. }
  813. }
  814. $allowblockrecommend = $_G['group']['allowdiy'] || getstatus($_G['member']['allowadmincp'], 4) || getstatus($_G['member']['allowadmincp'], 5) || getstatus($_G['member']['allowadmincp'], 6);
  815. if($_G['setting']['portalstatus']) {
  816. $allowpostarticle = $_G['group']['allowmanagearticle'] || $_G['group']['allowpostarticle'] || getstatus($_G['member']['allowadmincp'], 2) || getstatus($_G['member']['allowadmincp'], 3);
  817. $allowpusharticle = empty($_G['forum_thread']['special']) && empty($_G['forum_thread']['sortid']) && !$_G['forum_thread']['pushedaid'];
  818. } else {
  819. $allowpostarticle = $allowpusharticle = false;
  820. }
  821. if($_G['forum_thread']['displayorder'] != -4) {
  822. $modmenu = array(
  823. 'thread' => $_G['forum']['ismoderator'] || $allowblockrecommend || $allowpusharticle && $allowpostarticle,
  824. 'post' => $_G['forum']['ismoderator'] && ($_G['group']['allowwarnpost'] || $_G['group']['allowbanpost'] || $_G['group']['allowdelpost'] || $_G['group']['allowstickreply']) || $_G['forum_thread']['pushedaid'] && $allowpostarticle || $_G['forum_thread']['authorid'] == $_G['uid']
  825. );
  826. } else {
  827. $modmenu = array();
  828. }
  829. if($_G['forum']['alloweditpost'] && $_G['uid']) {
  830. $alloweditpost_status = getstatus($_G['setting']['alloweditpost'], $_G['forum_thread']['special'] + 1);
  831. if(!$alloweditpost_status) {
  832. $edittimelimit = $_G['group']['edittimelimit'] * 60;
  833. }
  834. }
  835. if($_G['forum_thread']['replies'] > $_G['forum_thread']['views']) {
  836. $_G['forum_thread']['views'] = $_G['forum_thread']['replies'];
  837. }
  838. require_once libfile('function/upload');
  839. $swfconfig = getuploadconfig($_G['uid'], $_G['fid']);
  840. $_G['forum_thread']['relay'] = 0;
  841. if(getstatus($_G['forum_thread']['status'], 10)) {
  842. $preview = C::t('forum_threadpreview')->fetch($_G['tid']);
  843. $_G['forum_thread']['relay'] = $preview['relay'];
  844. }
  845. if(empty($_GET['viewpid'])) {
  846. $sufix = '';
  847. if($_GET['from'] == 'portal') {
  848. $_G['disabledwidthauto'] = 1;
  849. $_G['widthauto'] = 0;
  850. $sufix = '_portal';
  851. $post = &$postlist[$_G['forum_firstpid']];
  852. } elseif($_GET['from'] == 'preview') {
  853. $_G['disabledwidthauto'] = 1;
  854. $_G['widthauto'] = 0;
  855. $sufix = '_preview';
  856. } elseif($_GET['from'] == 'album') {
  857. $_G['disabledwidthauto'] = 1;
  858. $_G['widthauto'] = 0;
  859. $sufix = '_album';
  860. $post = &$postlist[$_G['forum_firstpid']];
  861. $post['message'] = cutstr(strip_tags(preg_replace('/(<ignore_js_op>.*<\/ignore_js_op>)/is', '', $post['message'])), 200);
  862. require_once libfile('thread/album', 'include');
  863. }
  864. include template('diy:forum/viewthread'.$sufix.':'.$_G['fid']);
  865. } else {
  866. $_G['setting']['admode'] = 0;
  867. $post = $postlist[$_GET['viewpid']];
  868. if($maxposition) {
  869. $post['number'] = $post['position'];
  870. } else {
  871. $post['number'] = C::t('forum_post')->count_by_tid_dateline($posttableid, $post['tid'], $post['dbdateline']);
  872. }
  873. if($rushreply) {
  874. $post['number'] = $post['position'];
  875. $preg_str = rushreply_rule($rewardfloorarr);
  876. preg_match_all($preg_str, ",,".$post['number'].",,", $arr);
  877. if($post['number'] == str_replace(",", '', $arr['0']['0'])) {
  878. $post['rewardfloor'] = 1;
  879. }
  880. }
  881. include template('common/header_ajax');
  882. hookscriptoutput('viewthread');
  883. $postcount = 0;
  884. if($_GET['from']) {
  885. include template($_GET['from'] == 'preview' ? 'forum/viewthread_preview_node' : 'forum/viewthread_from_node');
  886. } else {
  887. include template('forum/viewthread_node');
  888. }
  889. include template('common/footer_ajax');
  890. }
  891. function viewthread_updateviews($tableid) {
  892. global $_G;
  893. if(!$_G['setting']['preventrefresh'] || $_G['cookie']['viewid'] != 'tid_'.$_G['tid']) {
  894. if(!$tableid && $_G['setting']['optimizeviews']) {
  895. if($_G['forum_thread']['addviews']) {
  896. if($_G['forum_thread']['addviews'] < 100) {
  897. C::t('forum_threadaddviews')->update_by_tid($_G['tid']);
  898. } else {
  899. if(!discuz_process::islocked('update_thread_view')) {
  900. $row = C::t('forum_threadaddviews')->fetch($_G['tid']);
  901. C::t('forum_threadaddviews')->update($_G['tid'], array('addviews' => 0));
  902. C::t('forum_thread')->increase($_G['tid'], array('views' => $row['addviews']+1), true);
  903. discuz_process::unlock('update_thread_view');
  904. }
  905. }
  906. } else {
  907. C::t('forum_threadaddviews')->insert(array('tid' => $_G['tid'], 'addviews' => 1), false, true);
  908. }
  909. } else {
  910. C::t('forum_thread')->increase($_G['tid'], array('views' => 1), true, $tableid);
  911. }
  912. }
  913. dsetcookie('viewid', 'tid_'.$_G['tid']);
  914. }
  915. function viewthread_procpost($post, $lastvisit, $ordertype, $maxposition = 0) {
  916. global $_G, $rushreply;
  917. if(!$_G['forum_newpostanchor'] && $post['dateline'] > $lastvisit) {
  918. $post['newpostanchor'] = '<a name="newpost"></a>';
  919. $_G['forum_newpostanchor'] = 1;
  920. } else {
  921. $post['newpostanchor'] = '';
  922. }
  923. $post['lastpostanchor'] = ($ordertype != 1 && $_G['forum_numpost'] == $_G['forum_thread']['replies']) || ($ordertype == 1 && $_G['forum_numpost'] == $_G['forum_thread']['replies'] + 2) ? '<a name="lastpost"></a>' : '';
  924. if(!$post['hotrecommended']) {
  925. if($_G['forum_pagebydesc']) {
  926. if($ordertype != 1) {
  927. $post['number'] = $_G['forum_numpost'] + $_G['forum_ppp2']--;
  928. } else {
  929. $post['number'] = $post['first'] == 1 ? 1 : ($_G['forum_numpost'] - 1) - $_G['forum_ppp2']--;
  930. }
  931. } else {
  932. if($ordertype != 1) {
  933. $post['number'] = ++$_G['forum_numpost'];
  934. } else {
  935. $post['number'] = $post['first'] == 1 ? 1 : --$_G['forum_numpost'];
  936. $post['number'] = $post['number'] - 1;
  937. }
  938. }
  939. }
  940. if($post['existinfirstpage']) {
  941. if($_G['forum_pagebydesc']) {
  942. $_G['forum_ppp2']--;
  943. } else {
  944. if($ordertype != 1) {
  945. ++$_G['forum_numpost'];
  946. } else {
  947. --$_G['forum_numpost'];
  948. }
  949. }
  950. }
  951. if($maxposition) {
  952. $post['number'] = $post['position'];
  953. }
  954. if($post['hotrecommended']) {
  955. $post['number'] = -1;
  956. }
  957. if(!$_G['forum_thread']['special'] && !$rushreply && !$hiddenreplies && $_G['setting']['threadfilternum'] && getstatus($post['status'], 11)) {
  958. $post['isWater'] = true;
  959. if($_G['setting']['hidefilteredpost'] && !$_G['forum']['noforumhidewater']) {
  960. $post['inblacklist'] = true;
  961. }
  962. } else {
  963. $_G['allblocked'] = false;
  964. }
  965. if($post['inblacklist']) {
  966. $_G['blockedpids'][] = $post['pid'];
  967. }
  968. $_G['forum_postcount']++;
  969. $post['dbdateline'] = $post['dateline'];
  970. $post['dateline'] = dgmdate($post['dateline'], 'u', '9999', getglobal('setting/dateformat').' H:i:s');
  971. $post['groupid'] = $_G['cache']['usergroups'][$post['groupid']] ? $post['groupid'] : 7;
  972. if($post['username']) {
  973. $_G['forum_onlineauthors'][$post['authorid']] = 0;
  974. $post['usernameenc'] = rawurlencode($post['username']);
  975. $post['readaccess'] = $_G['cache']['usergroups'][$post['groupid']]['readaccess'];
  976. if($_G['cache']['usergroups'][$post['groupid']]['userstatusby'] == 1) {
  977. $post['authortitle'] = $_G['cache']['usergroups'][$post['groupid']]['grouptitle'];
  978. $post['stars'] = $_G['cache']['usergroups'][$post['groupid']]['stars'];
  979. }
  980. $post['upgradecredit'] = false;
  981. if($_G['cache']['usergroups'][$post['groupid']]['type'] == 'member' && $_G['cache']['usergroups'][$post['groupid']]['creditslower'] != 999999999) {
  982. $post['upgradecredit'] = $_G['cache']['usergroups'][$post['groupid']]['creditslower'] - $post['credits'];
  983. $post['upgradeprogress'] = 100 - ceil($post['upgradecredit'] / ($_G['cache']['usergroups'][$post['groupid']]['creditslower'] - $_G['cache']['usergroups'][$post['groupid']]['creditshigher']) * 100);
  984. $post['upgradeprogress'] = min(max($post['upgradeprogress'], 2), 100);
  985. }
  986. $post['taobaoas'] = addslashes($post['taobao']);
  987. $post['regdate'] = dgmdate($post['regdate'], 'd');
  988. $post['lastdate'] = dgmdate($post['lastvisit'], 'd');
  989. $post['authoras'] = !$post['anonymous'] ? ' '.addslashes($post['author']) : '';
  990. if($post['medals']) {
  991. loadcache('medals');
  992. foreach($post['medals'] = explode("\t", $post['medals']) as $key => $medalid) {
  993. list($medalid, $medalexpiration) = explode("|", $medalid);
  994. if(isset($_G['cache']['medals'][$medalid]) && (!$medalexpiration || $medalexpiration > TIMESTAMP)) {
  995. $post['medals'][$key] = $_G['cache']['medals'][$medalid];
  996. $post['medals'][$key]['medalid'] = $medalid;
  997. $_G['medal_list'][$medalid] = $_G['cache']['medals'][$medalid];
  998. } else {
  999. unset($post['medals'][$key]);
  1000. }
  1001. }
  1002. }
  1003. $post['avatar'] = avatar($post['authorid']);
  1004. $post['groupicon'] = $post['avatar'] ? g_icon($post['groupid'], 1) : '';
  1005. $post['banned'] = $post['status'] & 1;
  1006. $post['warned'] = ($post['status'] & 2) >> 1;
  1007. } else {
  1008. if(!$post['authorid']) {
  1009. $post['useip'] = substr($post['useip'], 0, strrpos($post['useip'], '.')).'.x';
  1010. }
  1011. }
  1012. $post['attachments'] = array();
  1013. $post['imagelist'] = $post['attachlist'] = '';
  1014. if($post['attachment']) {
  1015. if((!empty($_G['setting']['guestviewthumb']['flag']) && !$_G['uid']) || $_G['group']['allowgetattach'] || $_G['group']['allowgetimage']) {
  1016. $_G['forum_attachpids'][] = $post['pid'];
  1017. $post['attachment'] = 0;
  1018. if(preg_match_all("/\[attach\](\d+)\[\/attach\]/i", $post['message'], $matchaids)) {
  1019. $_G['forum_attachtags'][$post['pid']] = $matchaids[1];
  1020. }
  1021. } else {
  1022. $post['message'] = preg_replace("/\[attach\](\d+)\[\/attach\]/i", '', $post['message']);
  1023. }
  1024. }
  1025. if($_G['setting']['ratelogrecord'] && $post['ratetimes']) {
  1026. $_G['forum_cachepid'][$post['pid']] = $post['pid'];
  1027. }
  1028. if($_G['setting']['commentnumber'] && ($post['first'] && $_G['setting']['commentfirstpost'] || !$post['first']) && $post['comment']) {
  1029. $_G['forum_cachepid'][$post['pid']] = $post['pid'];
  1030. }
  1031. $post['allowcomment'] = $_G['setting']['commentnumber'] && in_array(1, $_G['setting']['allowpostcomment']) && ($_G['setting']['commentpostself'] || $post['authorid'] != $_G['uid']) &&
  1032. ($post['first'] && $_G['setting']['commentfirstpost'] && in_array($_G['group']['allowcommentpost'], array(1, 3)) ||
  1033. (!$post['first'] && in_array($_G['group']['allowcommentpost'], array(2, 3))));
  1034. $forum_allowbbcode = $_G['forum']['allowbbcode'] ? -$post['groupid'] : 0;
  1035. $post['signature'

Large files files are truncated, but you can click here to view the full file