⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewthread.php

📁 论坛代码网增加免费空间业务
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	}

	$onlyauthoradd = '';
	$authorid = intval($authorid);
	if($authorid) {
		$thread['replies'] = $db->result_first("SELECT COUNT(*) FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0' AND authorid='$authorid' AND anonymous='0'") - 1;
		if($thread['replies'] < 0) {
			showmessage('undefined_action');
		}
		$onlyauthoradd = "AND p.authorid='$authorid' AND p.anonymous='0'";
	};

	$ppp = $forum['threadcaches'] && !$discuz_uid ? $_DCACHE['settings']['postperpage'] : $ppp;
	$totalpage = ceil(($thread['replies'] + 1) / $ppp);
	$page > $totalpage && $page = $totalpage;
	$pagebydesc = $page > 50 && $page > ($totalpage / 2) ? TRUE : FALSE;

	if($pagebydesc) {
		$firstpagesize = ($thread['replies'] + 1) % $ppp;
		$ppp3 = $ppp2 = $page == $totalpage && $firstpagesize ? $firstpagesize : $ppp;
		$realpage = $totalpage - $page + 1;
		$start_limit = max(0, ($realpage - 2) * $ppp + $firstpagesize);
		$numpost = ($page - 1) * $ppp;
		$pageadd =  "ORDER BY dateline DESC LIMIT $start_limit, $ppp2";
	} else {
		$start_limit = $numpost = ($page - 1) * $ppp;
		if($start_limit > $thread['replies']) {
			$start_limit = $numpost = 0;
			$page = 1;
		}
		$pageadd =  "ORDER BY dateline LIMIT $start_limit, $ppp";
	}

	$multipage = multi($thread['replies'] + 1, $ppp, $page, "viewthread.php?tid=$tid&amp;extra=$extra".(isset($highlight) ? "&amp;highlight=".rawurlencode($highlight) : '').(!empty($authorid) ? "&amp;authorid=$authorid" : ''));

	$newpostanchor = $postcount = $ratelogpids = 0;

	$onlineauthors = array();
	$query = $db->query("SELECT p.*, m.uid, m.username, m.groupid, m.adminid, m.regdate, m.lastactivity, m.posts, m.digestposts, m.oltime,
		m.pageviews, m.credits, m.extcredits1, m.extcredits2, m.extcredits3, m.extcredits4, m.extcredits5, m.extcredits6,
		m.extcredits7, m.extcredits8, m.email, m.gender, m.showemail, m.invisible, mf.nickname, mf.site,
		mf.icq, mf.qq, mf.yahoo, mf.msn, mf.taobao, mf.alipay, mf.location, mf.medals,
		mf.sightml AS signature, mf.customstatus, mf.spacename $fieldsadd
		FROM {$tablepre}posts p
		LEFT JOIN {$tablepre}members m ON m.uid=p.authorid
		LEFT JOIN {$tablepre}memberfields mf ON mf.uid=m.uid
		WHERE p.tid='$tid' AND p.invisible='0' $onlyauthoradd  $pageadd");

	while($post = $db->fetch_array($query)) {
		$postlist[$post['pid']] = viewthread_procpost($post);
	}
	if($pagebydesc) {
		$postlist = array_reverse($postlist, TRUE);
	}

	if($vtonlinestatus == 2 && $onlineauthors) {
		$query = $db->query("SELECT uid FROM {$tablepre}sessions WHERE uid IN(".(implode(',', $onlineauthors)).") AND invisible=0");
		$onlineauthors = array();
		while($author = $db->fetch_array($query)) {
			$onlineauthors[$author['uid']] = 1;
		}
	} else {
		$onlineauthors = array();
	}
	if($ratelogpids) {
		$query = $db->query("SELECT * FROM {$tablepre}ratelog WHERE pid IN ($ratelogpids) ORDER BY dateline DESC");
		while($ratelog = $db->fetch_array($query)) {
			if(count($postlist[$ratelog['pid']]['ratelog']) < $ratelogrecord) {
				$ratelog['dateline'] = gmdate("$dateformat $timeformat", $ratelog['dateline'] + $timeoffset * 3600);
				$ratelog['score'] = $ratelog['score'] > 0 ? '+'.$ratelog['score'] : $ratelog['score'];
				$ratelog['reason'] = dhtmlspecialchars($ratelog['reason']);
				$postlist[$ratelog['pid']]['ratelog'][] = $ratelog;
			}
		}
	}

	if($attachpids) {
		require_once DISCUZ_ROOT.'./include/attachment.func.php';
		parseattach($attachpids, $attachtags, $postlist, $showimages);
	}

	if(empty($postlist)) {
		showmessage('undefined_action', NULL, 'HALTED');
	} else {
		$seodescription = current($postlist);
		$seodescription = cutstr(htmlspecialchars(strip_tags($seodescription['message'])), 150);
	}

	viewthread_parsetags();

	include template('viewthread');

} elseif($action == 'printable' && $tid) {

	require_once DISCUZ_ROOT.'./include/printable.inc.php';

}

function viewthread_updateviews() {
	global $delayviewcount, $timestamp, $tablepre, $tid, $db, $adminid;
	global $thread, $do;
	if($thread['special'] && !$do) {
		return NULL;
	}

	if($delayviewcount == 1 || $delayviewcount == 3) {
		$logfile = './forumdata/cache/cache_threadviews.log';
		if(substr($timestamp, -2) == '00') {
			require_once DISCUZ_ROOT.'./include/misc.func.php';
			updateviews('threads', 'tid', 'views', $logfile);
		}
		if(@$fp = fopen(DISCUZ_ROOT.$logfile, 'a')) {
			fwrite($fp, "$tid\n");
			fclose($fp);
		} elseif($adminid == 1) {
			showmessage('view_log_invalid');
		}
	} else {

		$db->query("UPDATE LOW_PRIORITY {$tablepre}threads SET views=views+1 WHERE tid='$tid'", 'UNBUFFERED');
	}
}

function viewthread_procpost($post, $special = 0) {

	global $_DCACHE, $newpostanchor, $numpost, $thisbg, $postcount, $ratelogpids, $onlineauthors, $lastvisit, $thread,
		$attachpids, $attachtags, $forum, $dateformat, $timeformat, $timeoffset, $userstatusby, $allowgetattach,
		$ratelogrecord, $showimages, $forum, $discuz_uid, $showavatars, $pagebydesc, $ppp, $ppp2, $ppp3,
		$firstpid, $videoopen, $threadpay;

	if(!$newpostanchor && $post['dateline'] > $lastvisit) {
		$post['newpostanchor'] = '<a name="newpost"></a>';
		$newpostanchor = 1;
	} else {
		$post['newpostanchor'] = '';
	}

	$post['lastpostanchor'] = $numpost == $thread['replies'] ? '<a name="lastpost"></a>' : '';

	if($pagebydesc) {
		$post['number'] = $numpost + $ppp2--;
		$post['count'] = $ppp == $ppp3 ? $ppp - $postcount - 1 : $ppp3 - $postcount - 1;
	} else {
		$post['number'] = ++$numpost;
		$post['count'] = $postcount;
	}

	$postcount++;

	$post['dbdateline'] = $post['dateline'];
	$post['dateline'] = gmdate("$dateformat $timeformat", $post['dateline'] + $timeoffset * 3600);
	$post['groupid'] = $_DCACHE['usergroups'][$post['groupid']] ? $post['groupid'] : 7;

	if($post['username']) {
		$onlineauthors[] = $post['authorid'];
		$post['usernameenc'] = rawurlencode($post['username']);
		!$special && $post['groupid'] = getgroupid($post['authorid'], $_DCACHE['usergroups'][$post['groupid']], $post);
		$post['readaccess'] = $_DCACHE['usergroups'][$post['groupid']]['readaccess'];
		if($_DCACHE['usergroups'][$post['groupid']]['userstatusby'] == 1) {
			$post['authortitle'] = $_DCACHE['usergroups'][$post['groupid']]['grouptitle'];
			$post['stars'] = $_DCACHE['usergroups'][$post['groupid']]['stars'];
		} elseif($_DCACHE['usergroups'][$post['groupid']]['userstatusby'] == 2) {
			foreach($_DCACHE['ranks'] as $rank) {
				if($post['posts'] > $rank['postshigher']) {
					$post['authortitle'] = $rank['ranktitle'];
					$post['stars'] = $rank['stars'];
					break;
				}
			}
		}

		$post['taobaoas'] = addslashes($post['taobao']);
		$post['authoras'] = !$post['anonymous'] ? ' '.addslashes($post['author']) : '';
		$post['regdate'] = gmdate($dateformat, $post['regdate'] + $timeoffset * 3600);
		$post['lastdate'] = gmdate($dateformat, $post['lastactivity'] + $timeoffset * 3600);

		if($post['medals']) {
			@include_once DISCUZ_ROOT.'./forumdata/cache/cache_medals.php';
			foreach($post['medals'] = explode("\t", $post['medals']) as $key => $medalid) {
				list($medalid, $medalexpiration) = explode("|", $medalid);
				if(isset($_DCACHE['medals'][$medalid]) && (!$medalexpiration || $medalexpiration > $timestamp)) {
					$post['medals'][$key] = $_DCACHE['medals'][$medalid];
				} else {
					unset($post['medals'][$key]);
				}
			}
		}
		if($showavatars) {
			$post['avatar'] = '<div class="avatar">'.discuz_uc_avatar($post['authorid']);
			if($_DCACHE['usergroups'][$post['groupid']]['groupavatar']) {
				$post['avatar'] .= '<br /><img src="'.$_DCACHE['usergroups'][$post['groupid']]['groupavatar'].'" border="0" alt="" />';
			}
			$post['avatar'] .= '</div>';
		} else {
			$post['avatar'] = '';
		}

		$post['banned'] = $post['status'] & 1;
		$post['warned'] = $post['status'] & 2;

	} else {
		if(!$post['authorid']) {
			$post['useip'] = substr($post['useip'], 0, strrpos($post['useip'], '.')).'.x';
		}
	}
	$post['attachments'] = array();
	if($post['attachment']) {
		if($allowgetattach && !$threadpay) {
			$attachpids .= ",$post[pid]";
			$post['attachment'] = 0;
			if(preg_match_all("/\[attach\](\d+)\[\/attach\]/i", $post['message'], $matchaids)) {
				$attachtags[$post['pid']] = $matchaids[1];
			}
		} else {
			$post['message'] = preg_replace("/\[attach\](\d+)\[\/attach\]/i", '', $post['message']);
		}
	}

	$ratelogpids .= ($ratelogrecord && $post['ratetimes']) ? ','.$post['pid'] : '';
	$forum['allowbbcode'] = $forum['allowbbcode'] ? ($_DCACHE['usergroups'][$post['groupid']]['allowcusbbcode'] ? 2 : 1) : 0;
	$post['ratings'] = karmaimg($post['rate'], $post['ratetimes']);
	$post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], $post['htmlon'] & 1, $forum['allowsmilies'], $forum['allowbbcode'], ($forum['allowimgcode'] && $showimages ? 1 : 0), $forum['allowhtml'], ($forum['jammer'] && $post['authorid'] != $discuz_uid ? 1 : 0), 0, $post['authorid'], $forum['allowmediacode'], $post['pid']);
	$videoopen && $post['message'] = videocode($post['message'], $post['tid'], $post['pid']);
	$post['signature'] = $post['usesig'] ? $post['signature'] : '';
	$post['first'] && $firstpid = $post['pid'];
	return $post;
}

function showoption($var, $type) {
	global $optionlist;
	if($optionlist[$var][$type]) {
		return $optionlist[$var][$type];
	} else {
		return 'none';
	}
}

function viewthread_loadcache() {
	global $tid, $forum, $thread, $timestamp, $cachethreadlife, $_DCACHE, $gzipcompress, $debug, $styleid;
	$forum['livedays'] = ceil(($timestamp - $forum['dateline']) / 86400);
	$forum['lastpostdays'] = ceil(($timestamp - $forum['lastthreadpost']) / 86400);

	$threadcachemark = 100 - (
		$thread['displayorder'] * 15 +
		$thread['digest'] * 10 +
		min($thread['views'] / max($forum['livedays'], 10) * 2, 50) +
		max(-10, (15 - $forum['lastpostdays'])) +
		min($thread['replies'] / $_DCACHE['settings']['postperpage'] * 1.5, 15));

	if($threadcachemark < $forum['threadcaches']) {

		$threadcache = getcacheinfo($tid);

		if($timestamp - $threadcache['filemtime'] > $cachethreadlife) {
			@unlink($threadcache['filename']);
			define('CACHE_FILE', $threadcache['filename']);
			$styleid = $_DCACHE['settings']['styleid'];
			@include DISCUZ_ROOT.'./forumdata/cache/style_'.$styleid.'.php';
		} else {
			readfile($threadcache['filename']);

			viewthread_updateviews();
			$debug && debuginfo();
			$debug ? die('<script type="text/javascript">document.getElementById("debuginfo").innerHTML = " '.($debug ? 'Updated at '.gmdate("H:i:s", $threadcache['filemtime'] + 3600 * 8).', Processed in '.$debuginfo['time'].' second(s), '.$debuginfo['queries'].' Queries'.($gzipcompress ? ', Gzip enabled' : '') : '').'";</script>') : die();
		}
	}
}

function viewthread_lastmod() {
	global $db, $tablepre, $dateformat, $timeformat, $timeoffset, $tid;
	if($lastmod = $db->fetch_first("SELECT uid AS moduid, username AS modusername, dateline AS moddateline, action AS modaction, magicid
		FROM {$tablepre}threadsmod
		WHERE tid='$tid' ORDER BY dateline DESC LIMIT 1")) {
		include language('modactions');
		$lastmod['modusername'] = $lastmod['modusername'] ? $lastmod['modusername'] : 'System';
		$lastmod['moddateline'] = gmdate("$dateformat $timeformat", $lastmod['moddateline'] + $timeoffset * 3600);
		$lastmod['modaction'] = $modactioncode[$lastmod['modaction']];
		if($lastmod['magicid']) {
			require_once DISCUZ_ROOT.'./forumdata/cache/cache_magics.php';
			$lastmod['magicname'] = $_DCACHE['magics'][$lastmod['magicid']]['name'];
		}
	} else {
		$db->query("UPDATE {$tablepre}threads SET moderated='0' WHERE tid='$tid'", 'UNBUFFERED');
	}
	return $lastmod;
}

function viewthread_parsetags() {
	global $tagstatus, $_DCACHE, $firstpid, $postlist, $forum, $tagscript;
	if($firstpid && $tagstatus && $forum['allowtag'] && !($postlist[$firstpid]['htmlon'] & 2) && !empty($_DCACHE['tags'])) {
		$tagscript = '<script type="text/javascript">var tagarray = '.$GLOBALS['_DCACHE']['tags'][0].';var tagencarray = '.$GLOBALS['_DCACHE']['tags'][1].';parsetag('.$firstpid.');</script>';
	}
}


function remaintime($time) {
	$seconds 	= $time % 60;
	$minutes 	= $time % 3600 / 60;
	$hours 		= $time % 86400 / 3600;
	$days 		= $time / 86400;
	return array((int)$days, (int)$hours, (int)$minutes, (int)$seconds);
}

function arrayslice($array, $offset, $length) {
	if(PHP_VERSION >= '5.0.2') {
		return array_slice($array, $offset, $length, TRUE);
	} else {
		$array = array_chunk($array, $length, TRUE);
		return $array[$offset / $length];
	}
}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -