PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/source/module/forum/forum_viewthread.php

https://github.com/kuaileshike/upload
PHP | 1295 lines | 1140 code | 149 blank | 6 comment | 524 complexity | 8ca99de81e88234abcdea919048f3a25 MD5 | raw file

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

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