<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: forum_viewthread.php 32592 2013-02-25 01:31:16Z zhangjie $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
require_once libfile('function/forumlist');
require_once libfile('function/discuzcode');
require_once libfile('function/post');
$thread = & $_G['forum_thread'];
$forum = & $_G['forum'];
if(!$_G['forum_thread'] || !$_G['forum']) {
showmessage('thread_nonexistence');
}
$page = max(1, $_G['page']);
if($page === 1 && !empty($_G['setting']['antitheft']['allow']) && empty($_G['setting']['antitheft']['disable']['thread']) && empty($_G['forum']['noantitheft'])) {
helper_antitheft::check($_G['forum_thread']['tid'], 'tid');
}
if($_G['setting']['cachethreadlife'] && $_G['forum']['threadcaches'] && !$_G['uid'] && $page == 1 && !$_G['forum']['special'] && empty($_GET['do']) && !defined('IN_ARCHIVER') && !defined('IN_MOBILE')) {
viewthread_loadcache();
}
$threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array();
$threadtable_info = !empty($_G['cache']['threadtable_info']) ? $_G['cache']['threadtable_info'] : array();
$archiveid = $thread['threadtableid'];
$thread['is_archived'] = $archiveid ? true : false;
$thread['archiveid'] = $archiveid;
$forum['threadtableid'] = $archiveid;
$threadtable = $thread['threadtable'];
$posttableid = $thread['posttableid'];
$posttable = $thread['posttable'];
$_G['action']['fid'] = $_G['fid'];
$_G['action']['tid'] = $_G['tid'];
if($_G['fid'] == $_G['setting']['followforumid'] && $_G['adminid'] != 1) {
dheader("Location: home.php?mod=follow");
}
$close_leftinfo = intval($_G['setting']['close_leftinfo']);
if($_G['setting']['close_leftinfo_userctrl']) {
if($_G['cookie']['close_leftinfo'] == 1) {
$close_leftinfo = 1;
} elseif($_G['cookie']['close_leftinfo'] == 2) {
$close_leftinfo = 0;
}
}
$_GET['authorid'] = !empty($_GET['authorid']) ? intval($_GET['authorid']) : 0;
$_GET['ordertype'] = !empty($_GET['ordertype']) ? intval($_GET['ordertype']) : 0;
$_GET['from'] = in_array($_GET['from'], array('preview', 'portal', 'album')) ? $_GET['from'] : '';
if($_GET['from'] == 'portal' && !$_G['setting']['portalstatus']) {
$_GET['from'] = '';
} elseif($_GET['from'] == 'preview' && !$_G['inajax']) {
$_GET['from'] = '';
}
$fromuid = $_G['setting']['creditspolicy']['promotion_visit'] && $_G['uid'] ? '&fromuid='.$_G['uid'] : '';
$feeduid = $_G['forum_thread']['authorid'] ? $_G['forum_thread']['authorid'] : 0;
$feedpostnum = $_G['forum_thread']['replies'] > $_G['ppp'] ? $_G['ppp'] : ($_G['forum_thread']['replies'] ? $_G['forum_thread']['replies'] : 1);
if(!empty($_GET['extra'])) {
parse_str($_GET['extra'], $extra);
$_GET['extra'] = array();
foreach($extra as $_k => $_v) {
if(preg_match('/^\w+$/', $_k)) {
if(!is_array($_v)) {
$_GET['extra'][] = $_k.'='.rawurlencode($_v);
} else {
$_GET['extra'][] = http_build_query(array($_k => $_v));
}
}
}
$_GET['extra'] = implode('&', $_GET['extra']);
}
$_G['forum_threadindex'] = '';
$skipaids = $aimgs = $_G['forum_posthtml'] = array();
$thread['subjectenc'] = rawurlencode($_G['forum_thread']['subject']);
$thread['short_subject'] = cutstr($_G['forum_thread']['subject'], 52);
$navigation = '';
if($_GET['from'] == 'portal') {
$_G['setting']['ratelogon'] = 1;
$navigation = ' <em>›</em> <a href="portal.php">'.lang('core', 'portal').'</a>';
$navsubject = $_G['forum_thread']['subject'];
$navtitle = $_G['forum_thread']['subject'];
}elseif($_GET['from'] == 'preview') {
$_G['setting']['ratelogon'] = 1;
} elseif($_G['forum']['status'] == 3) {
$_G['action']['action'] = 3;
require_once libfile('function/group');
$status = groupperm($_G['forum'], $_G['uid']);
if($status == 1) {
showmessage('forum_group_status_off');
} elseif($status == 2) {
showmessage('forum_group_noallowed', 'forum.php?mod=group&fid='.$_G['fid']);
} elseif($status == 3) {
showmessage('forum_group_moderated', 'forum.php?mod=group&fid='.$_G['fid']);
}
$nav = get_groupnav($_G['forum']);
$navigation = ' <em>›</em> <a href="group.php">'.$_G['setting']['navs'][3]['navname'].'</a> '.$nav['nav'];
$upnavlink = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].($_GET['extra'] && !IS_ROBOT ? '&'.$_GET['extra'] : '');
$_G['grouptypeid'] = $_G['forum']['fup'];
} else {
$navigation = '';
$upnavlink = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].($_GET['extra'] && !IS_ROBOT ? '&'.$_GET['extra'] : '');
if($_G['forum']['type'] == 'sub') {
$fup = $_G['cache']['forums'][$_G['forum']['fup']]['fup'];
$t_link = $_G['cache']['forums'][$fup]['type'] == 'group' ? 'forum.php?gid='.$fup : 'forum.php?mod=forumdisplay&fid='.$fup;
$navigation .= ' <em>›</em> <a href="'.$t_link.'">'.($_G['cache']['forums'][$fup]['name']).'</a>';
}
if($_G['forum']['fup']) {
$fup = $_G['forum']['fup'];
$t_link = $_G['cache']['forums'][$fup]['type'] == 'group' ? 'forum.php?gid='.$fup : 'forum.php?mod=forumdisplay&fid='.$fup;
$navigation .= ' <em>›</em> <a href="'.$t_link.'">'.($_G['cache']['forums'][$fup]['name']).'</a>';
}
$t_link = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].($_GET['extra'] && !IS_ROBOT ? '&'.$_GET['extra'] : '');
$navigation .= ' <em>›</em> <a href="'.$t_link.'">'.($_G['forum']['name']).'</a>';
if($archiveid) {
if($threadtable_info[$archiveid]['displayname']) {
$t_name = dhtmlspecialchars($threadtable_info[$archiveid]['displayname']);
} else {
$t_name = lang('core', 'archive').' '.$archiveid;
}
$navigation .= ' <em>›</em> <a href="forum.php?mod=forumdisplay&fid='.$_G['fid'].'&archiveid='.$archiveid.'">'.$t_name.'</a>';
}
unset($t_link, $t_name);
}
$_GET['extra'] = $_GET['extra'] ? rawurlencode($_GET['extra']) : '';
if(@in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
$canonical = rewriteoutput('forum_viewthread', 1, '', $_G['tid'], 1, '', '');
} else {
$canonical = 'forum.php?mod=viewthread&tid='.$_G['tid'];
}
$_G['setting']['seohead'] .= '<link href="'.$_G['siteurl'].$canonical.'" rel="canonical" />';
$_G['forum_tagscript'] = '';
$threadsort = $thread['sortid'] && isset($_G['forum']['threadsorts']['types'][$thread['sortid']]) ? 1 : 0;
if($threadsort) {
require_once libfile('function/threadsort');
$threadsortshow = threadsortshow($thread['sortid'], $_G['tid']);
}
if(empty($_G['forum']['allowview'])) {
if(!$_G['forum']['viewperm'] && !$_G['group']['readaccess']) {
showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
} elseif($_G['forum']['viewperm'] && !forumperm($_G['forum']['viewperm'])) {
showmessagenoperm('viewperm', $_G['fid']);
}
} elseif($_G['forum']['allowview'] == -1) {
showmessage('forum_access_view_disallow');
}
if($_G['forum']['formulaperm']) {
formulaperm($_G['forum']['formulaperm']);
}
if($_G['forum']['password'] && $_G['forum']['password'] != $_G['cookie']['fidpw'.$_G['fid']]) {
dheader("Location: $_G[siteurl]forum.php?mod=forumdisplay&fid=$_G[fid]");
}
if($_G['forum']['price']) {
$membercredits = C::t('common_member_forum_buylog')->get_credits($_G['uid'], $_G['fid']);
$paycredits = $_G['forum']['price'] - $membercredits;
if($paycredits > 0) {
dheader("Location: $_G[siteurl]forum.php?mod=forumdisplay&fid=$_G[fid]");
}
}
if($_G['forum_thread']['readperm'] && $_G['forum_thread']['readperm'] > $_G['group']['readaccess'] && !$_G['forum']['ismoderator'] && $_G['forum_thread']['authorid'] != $_G['uid']) {
showmessage('thread_nopermission', NULL, array('readperm' => $_G['forum_thread']['readperm']), array('login' => 1));
}
$usemagic = array('user' => array(), 'thread' => array());
$replynotice = getstatus