viewthread.php
来自「速度很快的PHP论坛源程序」· PHP 代码 · 共 247 行
PHP
247 行
<?php
/*
[DISCUZ!] viewthread.php - view thread posts
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/8/2 09:03
*/
require_once './include/common.inc.php';
require_once DISCUZ_ROOT.'./include/forum.func.php';
require_once DISCUZ_ROOT.'./include/discuzcode.func.php';
$discuz_action = 3;
$query = $db->query("SELECT t.*, tm.uid AS moduid, tm.username AS modusername, tm.dateline AS moddateline, tm.action AS modaction
FROM {$tablepre}threads t LEFT JOIN {$tablepre}threadsmod tm ON t.moderated=1 AND tm.tid=t.tid
WHERE t.tid='$tid' AND t.displayorder>='0'");
if(!$thread = $db->fetch_array($query)) {
showmessage('thread_nonexistence');
} elseif($thread['moderated']) {
if($thread['modaction']) {
include language('modactions');
$thread['moddateline'] = gmdate("$dateformat $timeformat", $thread['moddateline'] + $timeoffset * 3600);
$thread['modaction'] = $modactioncode[$thread['modaction']];
} else {
$db->query("UPDATE {$tablepre}threads SET moderated='0' WHERE tid='$tid'", 'UNBUFFERED');
}
}
$codecount = 0;
$oldtopics = $_DCOOKIE['oldtopics'] ? $_DCOOKIE['oldtopics'] : 'D';
if(strpos($oldtopics, 'D'.$tid.'D') === FALSE) {
$oldtopics = 'D'.$tid.$oldtopics;
if(strlen($oldtopics) > 3072) {
$oldtopics = preg_replace("((D\d+)+D).*$", "\\1", substr($oldtopics, 0, 3072));
}
dsetcookie('oldtopics', $oldtopics, 3600);
}
if($lastvisit < $thread['lastpost'] && $thread['lastpost'] > $_DCOOKIE['f'.$fid]) {
dsetcookie('fid'.$fid, $thread['lastpost'], 3600);
}
$extra = empty($extra) ? '' : '&'.preg_replace("/^(&)*/", '', $extra);
if($forum['type'] == 'forum') {
$navigation = "» <a href=\"forumdisplay.php?fid=$fid$extra\">$forum[name]</a> » $thread[subject]";
$navtitle = ' - '.strip_tags($forum['name']).' - '.$thread['subject'];
} else {
$query = $db->query("SELECT fid, name FROM {$tablepre}forums WHERE fid='$forum[fup]'");
$fup = $db->fetch_array($query);
$navigation = "» <a href=\"forumdisplay.php?fid=$fup[fid]\">$fup[name]</a> » <a href=\"forumdisplay.php?fid=$fid$extra\"> $forum[name]</a> » $thread[subject]";
$navtitle = ' - '.strip_tags($fup['name']).' - '.strip_tags($forum['name']).' - '.$thread['subject'];
}
if(!$forum['allowview']) {
if(!$forum['viewperm'] && !$allowview) {
showmessage('group_nopermission', NULL, 'NOPERM');
} elseif($forum['viewperm'] && !strstr($forum['viewperm'], "\t$groupid\t")) {
showmessage('forum_nopermission', NULL, 'NOPERM');
}
}
if($thread['creditsrequire'] && $thread['creditsrequire'] > $credits && !$forum['ismoderator'] && $thread['authorid'] != $discuz_uid) {
showmessage('thread_nopermission', NULL, 'NOPERM');
}
if($forum['password'] && $forum['password'] != $_DCOOKIE['fidpw'.$fid]) {
header("Location: {$boardurl}forumdisplay.php?fid=$fid&sid=$sid");
exit();
}
if(!$action && $tid) {
if($discuz_uid && $newpm) {
require_once DISCUZ_ROOT.'./include/pmprompt.inc.php';
}
$allowgetattach = ($allowgetattach && !$forum['getattachperm']) || strstr($forum['getattachperm'], "\t$groupid\t");
$highlightstatus = str_replace('+', '', $highlight) ? 1 : 0;
$allowkarma = $allowkarma && $maxkarmarate ? 1 : 0;
$page = !ispage($page) ? 1 : $page;
$start_limit = $numpost = ($page - 1) * $ppp;
$multipage = multi($thread['replies'] + 1, $ppp, $page, "viewthread.php?tid=$tid&extra=".rawurlencode($extra)."&highlight=".rawurlencode($highlight));
if($thread['poll']) {
$query = $db->query("SELECT pollopts FROM {$tablepre}polls WHERE tid='$tid'");
$pollopts = unserialize($db->result($query, 0));
$polloptions = array();
foreach($pollopts['options'] as $option) {
$polloptions[] = array
(
'option' => dhtmlspecialchars(stripslashes($option[0])),
'votes' => $option[1],
'width' => @round($option[1] * 300 / $pollopts['max']) + 2,
'percent' => @sprintf ("%01.2f", $option[1] * 100 / $pollopts['total'])
);
}
$allowvote = $allowvote && $discuz_uid && (empty($thread['closed']) || $alloweditpoll) && !in_array($discuz_user, $pollopts['voters']);
$optiontype = $pollopts['multiple'] ? 'checkbox' : 'radio';
}
$postlist = array();
$fieldadd = '';
$newpostanchor = $postcount = $attachpids = 0;
foreach($_DCACHE['fields_thread'] as $field) {
$fieldsadd .= ', mf.field_'.$field['fieldid'];
}
$query = $db->query("SELECT p.*, m.username, m.gender, m.groupid, m.regdate, m.lastactivity, m.posts, m.credits, m.digestposts,
m.email, m.showemail, m.invisible, mf.site, mf.icq, mf.qq, mf.yahoo, mf.msn, mf.location, mf.avatar,
mf.avatarwidth, mf.avatarheight, mf.sightml AS signature, mf.customstatus $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' ORDER BY dateline LIMIT $start_limit, $ppp");
while($post = $db->fetch_array($query)) {
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>' : '';
$post['number'] = ++$numpost;
$post['thisbg'] = $thisbg = $thisbg == ALTBG1 ? ALTBG2 : ALTBG1;
$post['dateline'] = gmdate("$dateformat $timeformat", $post['dateline'] + $timeoffset * 3600);
if($post['username']) {
if($userstatusby == 1 || $_DCACHE['usergroups'][$post['groupid']]['byrank'] === 0) {
$post['authortitle'] = $_DCACHE['usergroups'][$post['groupid']]['grouptitle'];
$post['stars'] = $_DCACHE['usergroups'][$post['groupid']]['stars'];
} elseif($userstatusby == 2) {
foreach($_DCACHE['ranks'] as $rank) {
if($post['posts'] > $rank['postshigher']) {
$post['authortitle'] = $rank['ranktitle'];
$post['stars'] = $rank['stars'];
break;
}
}
}
$post['regdate'] = gmdate($dateformat, $post['regdate'] + $timeoffset * 3600);
$post['allowuseblog'] = $_DCACHE['usergroups'][$post['groupid']]['allowuseblog'];
if($_DCACHE['usergroups'][$post['groupid']]['groupavatar']) {
$post['avatar'] = '<img src="'.$_DCACHE['usergroups'][$post['groupid']]['groupavatar'].'" border="0">';
} elseif($_DCACHE['usergroups'][$post['groupid']]['allowavatar'] && $post['avatar']) {
$post['avatar'] = '<img src="'.$post['avatar'].'" width="'.$post['avatarwidth'].'" height="'.$post['avatarheight'].'" border="0">';
} else {
$post['avatar'] = '';
}
} else {
if(!$post['authorid']) {
$post['useip'] = substr($post['useip'], 0, strrpos($post['useip'], '.')).'.x';
}
$post['post'] = $post['credits'] = $post['regdate'] = 'N/A';
}
if($post['attachment'] && $allowgetattach) {
$attachpids .= ",$post[pid]";
$post['attachment'] = 0;
}
$forum['allowbbcode'] = $forum['allowbbcode'] ? ($_DCACHE['usergroups'][$post['groupid']]['allowcusbbcode'] ? 2 : 1) : 0;
$post['karma'] = karmaimg($post['rate'], $post['ratetimes']);
$post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], $post['htmlon'], $forum['allowsmilies'], $forum['allowbbcode'], $forum['allowimgcode'], $forum['allowhtml']);
$post['signature'] = $post['usesig'] ? $post['signature'] : '';
$postlist[$post['pid']] = $post;
}
if($attachpids) {
$query = $db->query("SELECT aid, pid, creditsrequire, filetype, filename, attachment, filesize, downloads
FROM {$tablepre}attachments WHERE pid IN ($attachpids)");
if($db->num_rows($query)) {
require_once DISCUZ_ROOT.'./include/attachment.func.php';
while($attach = $db->fetch_array($query)) {
$extension = strtolower(fileext($attach['filename']));
$attach['attachicon'] = attachtype($extension."\t".$attach['filetype']);
if($attachimgpost && in_array($extension, array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp'))) {
$attach['attachimg'] = 1;
} else {
$attach['attachimg'] = 0;
$attach['attachsize'] = sizecount($attach['filesize']);
}
$postlist[$attach['pid']]['attachments'][] = $attach;
}
} else {
$db->query("UPDATE {$tablepre}posts SET attachment='0' WHERE pid IN ($attachpids)", 'UNBUFFERED');
}
}
if(empty($postlist)) {
showmessage('undefined_action', NULL, 'HALTED');
}
$forumselect = $forumjump ? forumselect() : NULL;
$usesigcheck = $sigstatus ? 'checked' : NULL;
$allowpostreply = ((!$thread['closed'] && !checkautoclose()) || $forum['ismoderator']) && ((!$forum['replyperm'] && $allowpost) || ($forum['replyperm'] && strstr($forum['replyperm'], "\t$groupid\t")) || $forum['allowreply']);
$allowpost = (!$forum['postperm'] && $allowpost) || ($forum['postperm'] && strstr($forum['postperm'], "\t$groupid\t")) || $forum['allowpost'];
if($delayviewcount) {
$logfile = DISCUZ_ROOT.'./forumdata/viewcount.log';
if(substr($timestamp, -2) == '00') {
require_once DISCUZ_ROOT.'./include/misc.func.php';
updateviews();
}
if(@$fp = fopen($logfile, 'a')) {
fwrite($fp, "$tid\n");
fclose($fp);
} elseif($adminid == 1) {
showmessage('view_log_invalid');
}
} else {
$db->query("UPDATE {$tablepre}threads SET views=views+1 WHERE tid='$tid'", 'UNBUFFERED');
}
include template('viewthread');
} elseif($action == 'printable' && $tid) {
require_once DISCUZ_ROOT.'./include/printable.inc.php';
}
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?