forumdisplay.php

来自「速度很快的PHP论坛源程序」· PHP 代码 · 共 273 行

PHP
273
字号
<?php

/*
	[DISCUZ!] forumdisplay.php - list board threads(topics)
	This is NOT a freeware, use is subject to license terms

	Version: 4.0.0
	Web: http://www.comsenz.com
	Copyright: 2001-2005 Comsenz Technology Ltd.
	Last Modified: 2004/12/17 09:03
*/

require_once './include/common.inc.php';
require_once DISCUZ_ROOT.'./include/forum.func.php';

$discuz_action = 2;

if($forum['redirect']) {
	header("Location: $forum[redirect]");
	exit();
}

if(isset($showoldetails)) {
	switch ($showoldetails) {
		case 'no': dsetcookie('onlinedetail', 0, 86400 * 365); break;
		case 'yes': dsetcookie('onlinedetail', 1, 86400 * 365); break;
	}
} else {
	$showoldetails = false;
}

if(!$forum['fid'] || $forum['type'] == 'group') {
	showmessage('forum_nonexistence', NULL, 'HALTED');
}

if($forum['type'] == 'forum') {
	$navigation = "&raquo; $forum[name]";
	$navtitle = ' - '.strip_tags($forum['name']);
} else {
	$forumup = $_DCACHE['forums'][$forum['fup']]['name'];
	$navigation = "&raquo; <a href=\"forumdisplay.php?fid=$forum[fup]\">$forumup</a> &raquo; $forum[name]";
	$navtitle = ' - '.strip_tags($forumup).' - '.strip_tags($forum['name']);
}

if($forum['password'] && $action == 'pwverify') {
	if($pw != $forum['password']) {
		showmessage('forum_passwd_incorrect', NULL, 'HALTED');
	} else {
		dsetcookie('fidpw'.$fid, $pw);
		showmessage('forum_passwd_correct', "forumdisplay.php?fid=$fid");
	}
}

$forum['rules'] = $forum['rules'] ? nl2br($forum['rules']) : '';

if($forum['viewperm'] && !strstr($forum['viewperm'], "\t$groupid\t") && !$forum['allowview']) {
	showmessage('forum_nopermission', NULL, 'NOPERM');
}

if(!empty($forum['password']) && $forum['password'] != $_DCOOKIE['fidpw'.$fid]) {
	include template('forumdisplay_passwd');
	exit();
}

$moderatedby = moddisplay($forum['moderators'], 'forumdisplay');
$postcredits = $forum['postcredits'] != -1 ? $forum['postcredits'] : $postcredits;
$replycredits = $forum['replycredits'] != -1 ? $forum['replycredits'] : $replycredits;

if($forum['autoclose']) {
	$forum['autoclose'] = abs($forum['autoclose']) * 86400;
	$closedby = $forum['autoclose'] > 0 ? 'dateline' : 'lastpost';
}

$subexists = 0;
foreach($_DCACHE['forums'] as $sub) {
	if($sub['type'] == 'sub' && $sub['fup'] == $fid && (!$hideprivate || !$sub['viewperm'] || strstr($sub['viewperm'], "\t$groupid\t") || strstr($sub['users'], "\t$discuz_uid\t"))) {
		$subexists = 1;
		$sublist = array();
		$sql = $accessmasks	? "SELECT f.fid, f.fup, f.type, f.name, f.description, f.threads, f.posts, f.lastpost, ff.moderators, ff.icon, ff.viewperm, a.allowview FROM {$tablepre}forums f
						LEFT JOIN {$tablepre}forumfields ff ON ff.fid=f.fid
						LEFT JOIN {$tablepre}access a ON a.uid='$discuz_uid' AND a.fid=f.fid
						WHERE fup='$fid' AND status='1' AND type='sub' ORDER BY f.displayorder"
					: "SELECT f.fid, f.fup, f.type, f.name, f.description, f.threads, f.posts, f.lastpost, ff.moderators, ff.icon, ff.viewperm FROM {$tablepre}forums f
						LEFT JOIN {$tablepre}forumfields ff USING(fid)
						WHERE f.fup='$fid' AND f.status='1' AND f.type='sub' ORDER BY f.displayorder";
		$query = $db->query($sql);
		while($sub = $db->fetch_array($query)) {
			if(forum($sub)) {
				$sublist[] = $sub;
			}
		}
		break;
	}
}

$page = !ispage($page) || ($threadmaxpages && $page > $threadmaxpages) ? 1 : $page;
$start_limit = ($page - 1) * $tpp;

if($page == 1) {
	if($_DCACHE['announcements_forum']) {
		$announcement = $_DCACHE['announcements_forum'];
		$announcement['starttime'] = gmdate("$dateformat $timeformat", $announcement['starttime'] + ($timeoffset * 3600));
	} else {
		$announcement = NULL;
	}	
}

$forumdisplayadd = $filteradd = '';
if(isset($filter)) {
	if($filter == 'digest') {
		$forumdisplayadd .= "&filter=digest";
		$filteradd = "AND digest>'0'";
	} else {
		$filter = intval($filter);
		$forumdisplayadd .= "&filter=$filter";
		$filteradd = $filter ? "AND lastpost>='".($timestamp - $filter)."'" : '';
	}
} else {
	$filter = '';
}

in_array($orderby, array('dateline', 'replies', 'views')) ? $forumdisplayadd .= "&orderby=$orderby" : $orderby = 'lastpost';
$ascdesc == 'ASC' ? $forumdisplayadd .= '&ascdesc=ASC' : $ascdesc = 'DESC';

$dotadd1 = $dotadd2 = '';
if($dotfolders && $discuz_uid) {
	$dotadd1 = "DISTINCT p.authorid AS dotauthor, ";
	$dotadd2 = "LEFT JOIN {$tablepre}posts p ON (t.tid=p.tid AND p.authorid='$discuz_uid')";
}

if($whosonlinestatus == 2 || $whosonlinestatus == 3) {
	$whosonlinestatus = 0;
	$onlineinfo = explode("\t", $onlinerecord);
	$detailstatus = ((!isset($_DCOOKIE['onlinedetail']) && $onlineinfo[0] < 500) || ($_DCOOKIE['onlinedetail'] || $showoldetails == 'yes')) && $showoldetails != 'no';

	if($detailstatus) {
		updatesession();
		@include language('actions');

		$whosonline = array();
		$forumname = strip_tags($forum['name']);
		$query = $db->query("SELECT uid, groupid, username, invisible, lastactivity, action FROM {$tablepre}sessions WHERE uid>'0' AND fid='$fid' AND invisible='0'");
		if($db->num_rows($query)) {
			$whosonlinestatus = 1;
			while($online = $db->fetch_array($query)) {
				$online['icon'] = isset($_DCACHE['onlinelist'][$online['groupid']]) ? $_DCACHE['onlinelist'][$online['groupid']] : $_DCACHE['onlinelist'][0];
				$online['action'] = $actioncode[$online['action']];
				$online['lastactivity'] = gmdate($timeformat, $online['lastactivity'] + ($timeoffset * 3600));
				$whosonline[] = $online;     
			}
		}
		unset($online);
	}
} else {
	$whosonlinestatus = 0;
}

if($discuz_uid && $newpm) {
	require_once DISCUZ_ROOT.'./include/pmprompt.inc.php';
}

if(!empty($filter)) {
	$query = $db->query("SELECT COUNT(*) FROM {$tablepre}threads WHERE fid='$fid' $filteradd AND displayorder>='0'");
	$threadcount = $db->result($query, 0);
} else {
	$threadcount = $forum['threads'];
}

$multipage = multi($threadcount, $tpp, $page, "forumdisplay.php?fid=$fid$forumdisplayadd", $threadmaxpages);
$extra = rawurlencode("page=$page$forumdisplayadd");

$separatepos = 0;
$threadlist = array();
$colorarray = array('', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'gray');
$query = $db->query("SELECT $dotadd1 t.* FROM {$tablepre}threads t $dotadd2
			WHERE t.fid='$fid' $filteradd AND t.displayorder>='0'
			ORDER BY t.displayorder DESC, t.$orderby $ascdesc
			LIMIT $start_limit, $tpp");

while($thread = $db->fetch_array($query)) {
	$thread['icon'] = isset($_DCACHE['icons'][$thread['iconid']]) ? '<img src="'.SMDIR.'/'.$_DCACHE['icons'][$thread['iconid']].'" align="absmiddle">' : '&nbsp;';
	$thread['lastposterenc'] = rawurlencode($thread['lastposter']);

	$topicposts = $thread['replies'] + 1;
	if($topicposts  > $ppp) {
		$pagelinks = '';
		$topicpages = ceil($topicposts / $ppp);
		for ($i = 1; $i <= $topicpages; $i++) {
			$pagelinks .= "<a href=\"viewthread.php?tid=$thread[tid]&page=$i&extra=$extra\">$i</a> ";
			if($i == 6) {
				$i = $topicpages + 1;
			}
		}
		if($topicpages > 6) {
			$pagelinks .= " .. <a href=\"viewthread.php?tid=$thread[tid]&page=$topicpages&extra=$extra\">$topicpages</a> ";
		}
		$thread['multipage'] = '&nbsp; &nbsp;( <img src="'.IMGDIR.'/multipage.gif" align="absmiddle" boader="0"> '.$pagelinks.')';
	} else {
		$thread['multipage'] = '';
	}

	if($thread['highlight']) {
		$string = sprintf('%02d', $thread['highlight']);
		$stylestr = sprintf('%03b', $string[0]);

		$thread['highlight'] = 'style="';
		$thread['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
		$thread['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
		$thread['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
		$thread['highlight'] .= $string[1] ? 'color: '.$colorarray[$string[1]] : '';
		$thread['highlight'] .= '"';
	} else {
		$thread['highlight'] = '';
	}

	if($thread['closed']) {
		$thread['new'] = 0;
		if($thread['closed'] > 1) {
			$thread['moved'] = $thread['tid'];
			$thread['tid'] = $thread['closed'];
			$thread['replies'] = '-';
			$thread['views'] = '-';
		} else {
			$thread['moved'] = 0;
		}
		$thread['folder'] = 'lock_folder.gif';
	} else {
		$thread['folder'] = 'folder.gif';
		if($lastvisit < $thread['lastpost'] && strpos($_DCOOKIE['oldtopics'], 'D'.$thread['tid'].'D') === FALSE) {
			$thread['new'] = 1;
			$thread['folder'] = 'red_'.$thread['folder'];
		} else {
			$thread['new'] = 0;
		}
		if($thread['replies'] > $thread['views']) {
			$thread['views'] = $thread['replies'];
		}
		if($thread['replies'] >= $hottopic) {
			$thread['folder'] = 'hot_'.$thread['folder'];
		}
		if($dotfolders && $thread['dotauthor'] == $discuz_uid && $discuz_uid) {
			$thread['folder'] = 'dot_'.$thread['folder'];
		}
	}

	$thread['closed'] = ($thread['closed'] || ($forum['autoclose'] && $timestamp - $thread[$closedby] > $forum['autoclose'])) ? 1 : 0;
	$thread['dateline'] = gmdate($dateformat, $thread['dateline'] + $timeoffset * 3600);
	$thread['lastpost'] = gmdate("$dateformat $timeformat", $thread['lastpost'] + $timeoffset * 3600);

	if($thread['displayorder'] > 0) {
		$separatepos++;
	}

	$threadlist[] = $thread;

}

//$separatepos = $announcement && !$separatepos ? 1 : ($separatepos ? $separatepos + 1 : 0);
$separatepos = $separatepos ? $separatepos + 1 : ($announcement ? 1 : 0);

$check = array();
$check[$filter] = $check[$orderby] = $check[$ascdesc] = 'selected="selected"';

$forumselect = $forumjump ? forumselect() : NULL;

$usesigcheck = $sigstatus ? 'checked' : NULL;
$allowpost = (!$forum['postperm'] && $allowpost) || ($forum['postperm'] && strstr($forum['postperm'], "\t$groupid\t")) || $forum['allowpost'];
$allowpostpoll = $allowpost && $allowpostpoll;

include template('forumdisplay');

?>

⌨️ 快捷键说明

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