viewthread.php
define('CURRSCRIPT', 'viewthread');
require_once './include/common.php';
require_once DISCUZ_ROOT.'./include/forum.php';
require_once DISCUZ_ROOT.'./include/discuzcode.php';
require("./lib/add_function.php");
$discuz_action = 3;
// ----------------------------------------------------------------
// Shop By FY
// ----------------------------------------------------------------
$myitemlist=itemlist($discuz_uid);
$useitem = ($myitemlist[4][num]>0 || $myitemlist[2][num]>0 || $myitemlist[5][num]>0 || $myitemlist[5][num]>0 || $myitemlist[6][num]>0)? 1:0;
$randnum = rand(1,4);
// ----------------------------------------------------------------
$words = file("./newWord.txt","r");
$fadvert = $forum['fadvert'];
$fadverts = $forum['fadverts'];
if ($tid && $forum){
$thread = $forum;
}elseif($fid && defined('ViewLastPost')) {
$query = $db->query("SELECT * FROM $table_threads WHERE fid='$fid' ORDER BY lastpost DESC LIMIT 1");
if(!$thread = $db->fetch_array($query)) {
showmessage('thread_nonexistence');
}
} else {
showmessage('thread_nonexistence');
}
//========================================================================================
if ($thread['digest'] && !$discuz_user){
showmessage('请登录','logging.php');
}
$query = $db->query("SELECT tic FROM $table_members WHERE username='$discuz_user'");
$ifmt = $db->fetch_array($query);
$dqbegintime = $timestamp;
$time=floor(($ifmt[tic]-$dqbegintime)/86400);
if($thread['digest'] && $time<0){
showmessage('你的通票已过期。','plugins.php?p=tic');
}
//========================================================================================
if (defined('ViewLastPost')) {
$page = @ceil(($thread['replies'] + 1) / $ppp);
}
$tid = $thread['tid'];
$thread['markread'] = explode("\t", $thread['markread']);
$codecount = 0;
$oldtopics = $_COOKIE['oldtopics'] ? $_COOKIE['oldtopics'] : "\t";
if(!strstr($oldtopics, "\t$tid\t")) {
$oldtopics .= "$tid\t";
setcookie('oldtopics', $oldtopics, $timestamp + 900, $cookiepath, $cookiedomain);
}
if($forum['type'] == 'forum') {
$navigation .= "» <a href=\"forumdisplay.php?fid=$fid&page=$fpage\"> $forum[name]</a> » $thread[subject]";
$navtitle .= ' - '.strip_tags($forum['name']).' - '.$thread['subject'];
} else {
$query = $db->query("SELECT fid, name, moderator FROM $table_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&page=$fpage\"> $forum[name]</a> » $thread[subject]";
$navtitle .= ' - '.strip_tags($fup['name']).' - '.strip_tags($forum['name']).' - '.$thread['subject'];
}
$ismoderator = modcheck($discuz_user);
if(!$forum['allowview']) {
if(!$forum['viewperm'] && !$allowview) {
showmessage('group_nopermission', NULL, 'HALTED');
} elseif($forum['viewperm'] && !strstr($forum['viewperm'], "\t$groupid\t")) {
showmessage('forum_nopermission', NULL, 'HALTED');
}
}
if($thread['creditsrequire'] && $thread['creditsrequire'] > $credit && !$ismoderator && ($thread['authorid'] !=$discuz_uid)) {
showmessage('thread_nopermission', NULL, 'HALTED');
}
if($forum['password'] && $forum['password'] != $_COOKIE["fidpw$fid"]) {
header("Location: {$boardurl}forumdisplay.php?fid=$fid&sid=$sid");
exit();
}
//最近到访论坛 by 凡人
$recentopic = $_COOKIE['recentopic'] ? $_COOKIE['recentopic'] : "\t";
if(!stristr($recentopic, "\t".$forum[name]."\n".$fid."\t")) {
$recentopic .= "".$forum[name]."\n".$fid."\t";
} else {
$replacement=explode("\t",$recentopic);
for($i=1;!empty($replacement[$i]);$i++) {
if ($replacement[$i] == $forum[name]."\n".$fid) {
array_splice($replacement,$i,1);
$recentopic = implode("\t",$replacement);
$recentopic .= "".$forum[name]."\n".$fid."\t";
}
}
}
setcookie('recentopic', $recentopic, $timestamp + 86400 * 7, $cookiepath, $cookiedomain);
$recentopic = explode("\t",$recentopic);
$recentopic = array_reverse($recentopic);
$recentselect = "<select onchange=\"if(this.options[this.selectedIndex].value != '') { window.location=('forumdisplay.php?fid='+this.options[this.selectedIndex].value+'&sid=$sid') }\">";
$recentselect .= "<option value=\"\">最近访问的论坛 ...</option>\n";
for($i=1;!empty($recentopic[$i]);$i++) {
$rforumid=explode("\n",$recentopic[$i]);
if($forum[name]!=$rforumid[0]) {
$recentselect .= "<option value=\"$rforumid[1]\">".$rforumid[0]."</option>\n";
}
}
$recentselect .= '</select>';
//最近到访论坛 by 凡人 (完毕)
if(!$action && $tid) {
if($discuz_uid && $newpm) {
require DISCUZ_ROOT.'./include/pmprompt.php';
}
$highlightstatus = str_replace('+', '', $highlight) ? 1 : 0;
$karmaoptions = '';
if($allowkarma && $maxkarmarate) {
$offset = ceil($maxkarmarate / 6);
for($vote = - $maxkarmarate + $offset; $vote <= $maxkarmarate; $vote += $offset) {
$votenum = $vote > 0 ? '+'.$vote : $vote;
$karmaoptions .= $vote ? "<option value=\"$vote\">$votenum</option>\n" : NULL;
}
}
unset($vote, $votenum, $offset);
if(empty($page)) {
$start_limit = 0;
$page = 1;
} else {
$start_limit = ($page - 1) * $ppp;
}
$fpage = intval($fpage);
$multipage = multi($thread['replies'] + 1, $ppp, $page, "viewthread.php?tid=$tid&fpage=$fpage&highlight=".rawurlencode($highlight));
$thread[subject] = cutstr($thread[subject],77);
$polloptions = array();
if($thread['poll']) {
$query = $db->query("SELECT pollopts FROM $table_polls WHERE tid='$tid'");
$pollopts = unserialize($db->result($query, 0));
if (is_array($pollopts) && count($pollopts)){
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';
}else{
unset ($pollopts);
}
}
$query = $db->query("SELECT * FROM $table_medal where medalid <> '0';");
while($medalist = $db->fetch_array($query)) {
$medalshow[$medalist[medalid]]="<img src=\"$medalist[medalpic]\" title=\"$medalist[medalname]\n$medalist[medalexpl]\">";
}
$altbg1 = ALTBG1;
$altbg2 = ALTBG2;
$postlist = $attachelist = $attachpost =$searcharray=$replacearray= array();
$newpostanchor = $topiccount = 0;
//-----------------------------虛擬形象參數查詢
require_once('./virtualimage/images_config.php');
$imagesset = $setting;
unset($setting);
if($imagesset[openalpha]){
$alpha = "FILTER: alpha(opacity=\"+WearArray+\")";
}
$imagesdatas = '';
//-----------------------------
$postcount = $start_limit;
$post_phpcodecount = -1;
$post_user_info_sql = 'm.username, m.gender, m.groupid, m.regdate, m.invisible, m.lastactivity,m.userpower, m.postnum,m.medals, m.credit, m.email, m.site, m.icq, m.oicq, m.yahoo, m.msn, m.location, m.avatar, m.avatarwidth, m.avatarheight, m.signature, m.customstatus, m.showemail, m.warning, m.useimages,m.uid,m.level,m.useimages,m.hw,m.onlinetime, m.bank, m.money, m.bankmimi, m.bankstatus';
$query = $db->query("
SELECT p.*, $post_user_info_sql
FROM $table_posts p
LEFT JOIN $table_members m ON m.uid=p.authorid
WHERE p.tid='$tid' ORDER BY dateline LIMIT $start_limit, $ppp");
while($post = $db->fetch_array($query)) {
if($post['medals']){
$medalid = strtok($post['medals'],",");
$medalout='';
while($medalid){
$medalout.= $medalshow[$medalid];
$medalid = strtok(",");
}
$post['medals'] = $medalout;
}
if(!$newpostanchor && $post['dateline'] > $lastvisit) {
$post['newpostanchor'] = '<a name="newpost"></a>';
$newpostanchor = 1;
} else {
$post['newpostanchor'] = '';
}
$topiccount ++;
$post['postcount'] = $postcount+1;
$post['thisbg'] =$postcolor= ${'altbg'.($postcount++ % 2 + 1)};
$post['dateline'] = gmdate("$dateformat $timeformat", $post['dateline'] + $timeoffset * 3600);
//mp_hp_exp hack begin
$daysreg = ($timestamp - $post['regdate']) / (24*3600);
$ppd = $post['postnum'] / $daysreg;//平均每日發貼
$post['exp_mp_hp'] = exp_mp_hp($post['postnum'],$ppd,$daysreg);
//end here
$post['onlinehour'] = intval($post['onlinetime']/3600);
$post['onlinemin'] = intval($post['onlinetime']%3600/60);
$change = 1; //兑换比率,即N点换一颗星
$changebase = $post['onlinehour']; //兑换基数,要小时为$post['onlinehour'],分钟为intval($post['onlinetime']/60),秒为$post['onlinetime']
$post['onlinestars'] = $changebase/$change; //计算方法:基数的数值除以兑换比率,得到星星数
if($post['username']) {
if($userstatusby == 1 || $_DCACHE['usergroups'][$post['groupid']]['byrank'] === 0) {
if ($_DCACHE['usergroups'][$post['groupid']]['groupcolor']){
$post['authortitle'] ="<font color =\"".$_DCACHE['usergroups'][$post['groupid']]['groupcolor']."\">".$_DCACHE['usergroups'][$post['groupid']]['grouptitle']."</font>";
}else{
$post['authortitle'] =$_DCACHE['usergroups'][$post['groupid']]['grouptitle'];
}
$post['stars'] = $_DCACHE['usergroups'][$post['groupid']]['stars'];
} elseif($userstatusby == 2) {
foreach($_DCACHE['ranks'] as $rank) {
if($post['postnum'] > $rank['postshigher']) {
$post['authortitle'] = $rank['ranktitle'];
$post['stars'] = $rank['stars'];
break;
}
}
}
$post['age'] = floor(($timestamp - $post['regdate'])/2592000);
$post['bemem'] = intval(($timestamp-$post['regdate'])/(3600*24));
$post['missday'] = intval(($timestamp-$post[lastactivity])/(3600*24));
$post['regdate'] = gmdate($dateformat, $post['regdate'] + $timeoffset * 3600);
$post[word] = "<font color=red>『每日英语』"." [</font>".$words[rand(0,6050)]." <font color=red>]</font>";
if (!$post[hw]) {
$post[hw]='未婚';
}
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'] = '';
}
//------------------------------------------------------------虛擬形象
if ($imagesset['orderuse']!='1' && $post['useimages']!=1){
$post['avatar'] = $post['avatar'];
}elseif($post['gender']=='0'){
if($imagesset['orderuse']=='1'){
$post['avatar'] = "<img src='{$imagesset[imageurl]}noface.gif' border='0'>";
}else{
$post['avatar'] = $post['avatar'];
}
}else{
if ($post[gender]==1){
$imagesdata[tempequip] = '0-0-0-0-0-0-0-0-init-init-0-init-0-init-init-0-0-0-init-0-0-0-0-0-0-0'; //男性的初始值
$imagesdata[sex] = "m";
$imagesdata[upid] = "init";
}else if ($post[gender]==2){
$imagesdata[tempequip] = '0-0-0-0-0-0-0-0-initf-initf-0-initf-0-initf-initf-0-0-0-initf-0-0-0-0-0-0-0'; //女性的初始值
$imagesdata[sex] = "f";
$imagesdata[upid] = "initf";
}
$imagesdata[pid] = $post[pid];
$imagesdata[uid] = $post[uid];
$imagesdatas[] = $imagesdata;
$post['avatar'] = "
<!-- 虛擬形象開始-->
<DIV id=Show{$post['pid']}
style=\"PADDING-RIGHT: 0px; PADDING-LEFT: 0px; LEFT: 0px; PADDING-BOTTOM: 0px; WIDTH: 120px; PADDING-TOP: 0px; POSITION: relative; TOP: 0px; HEIGHT: 150px\"></DIV>
<!-- 虛擬形象結束-->";
}
//--------------------------------------------------------------
} else {
if(!$post['authorid']) {
$post['useip'] = substr($post['useip'], 0, strrpos($post['useip'], '.')).'.x';
}
$post['postnum'] = $post['credit'] = $post['regdate'] = $post['hw'] = 'N/A';
}
$post['karma'] = '';
if($post['rate'] && $post['ratetimes']) {
$rateimg = $post['rate'] > 0 ? 'agree.gif' : 'disagree.gif';
for($i = 0; $i < round(abs($post['rate']) / $post['ratetimes']); $i++) {
$post['karma'] .= '<img src="'.IMGDIR.'/'.$rateimg.'" align="right">';
}
}
$query1 = $db->query("SELECT username, ignorepm FROM $table_members WHERE username='$discuz_user'");
while($member = $db->fetch_array($query1)) {
if(preg_match("/(,|^)\s*".preg_quote($post['username'], '/')."\s*(,|$)/i", $member['ignorepm'])) {
$post['subject'] = "忽略會員<span style=\"background-color: #CCCCFF\">$thread[author]</span>發起的主題";
$thread['subject'] = "忽略會員<u>$thread[author]</u>發起的主題";
$navigation = "» <a href=\"forumdisplay.php?fid=$fid&page=$fpage\"> $forum[name]</a> » $post[subject]";
$post['message'] = "會員<span style=\"background-color: #CCCCFF\">$post[username]</span>正在您的忽略清單內,故本訊息已被屏蔽,如要讀取本訊息,請將此會員從忽略列表中移除。";
$post['signature'] = "會員<span style=\"background-color: #CCCCFF\">$post[username]</span>正在您的忽略清單內,故本簽名已被屏蔽,如要讀取本簽名,請將此會員從忽略列表中移除。";
} else {
$post['subject'] = $post['subject'] ? $post['subject'] : NULL;
$post['payed'] = 0 ;
if($post[hidepost] == '1') {
$post['message'] = '<b>****本帖已被版主隐藏****</b>';
$post['message'] .= $post['wnmessagepost'];
} else {
$post['message'] = postify($post['message'], $post['smileyoff'], $post['bbcodeoff'], $forum['allowsmilies'], $forum['allowhtml'], $forum['allowbbcode'], $forum['allowimgcode']);
$post['message'] = $post['message'] ;
$post['message'] .=$post['wnmessagepost'];
} if( $isallowcopy){
$poststr = $post['message'];
$post['message'] = chaos($poststr);
}
$post['signature'] = $post['usesig'] && $post['signature'] ? postify($post['signature'], 1, 0, 0, 0, $_DCACHE['usergroups'][$post['groupid']]['allowsigbbcode'], $_DCACHE['usergroups'][$post['groupid']]['allowsigimgcode']) : NULL;
}
}
if($post['aid']){
$attachpost[] = $post['pid'];
}
$postlist[] = $post;
}
if (empty($postlist)) {
showmessage('undefined_action', NULL, 'HALTED');
}
if (count($attachpost)) {
require_once DISCUZ_ROOT.'./include/attachment.php';
$query = $db->query("select * from $table_attachments where pid in(".implode_ids($attachpost).")");
while($attach = $db->fetch_array($query)) {
$attach[checkid] = substr(md5($attach['filesize']),0,5);
$extension = strtolower(fileext($attach['filename']));
$attach['attachicon'] = attachtype($extension."\t".$attach['filetype']);
$attach['attachtype'] = attachtype($extension."\t".$attach['filetype']);
$attach['attachext'] = $extension;
$attach['attachsize'] = sizecount($attach['filesize']);
if($attachimgpost && in_array($extension, array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp'))) {
$attach['attachimg'] = 1;
} else {
$attaches['attachimg'] = 0;
}
$attach['dateline'] = $attach['dateline']?gmdate("$dateformat $timeformat", $attach['dateline'] + $timeoffset * 3600): '';
$attachelist["$attach[pid]"][] = $attach;
}
}
$typearray = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
if($thread['badge']) {
$string = sprintf('%02d', $thread['badge']);
$stylestr = sprintf('%03b', $string[0]);
//$thread['badge'] .= $string[1];
} else {
$thread['badge'] = '';
}
$forumselect = $forumjump ? forumselect() : NULL;
if($imagesdatas!=''){
$showimages = '';
require_once('./virtualimage/global.php');
$showimages = images_showimages($imagesdatas,$alhpa,$imagesset[imageurl]);
unset($imagesdatas,$imagesdata,$alpha);
}
$usesigcheck = $signature ? 'checked' : NULL;
$allowpost = (!$forum['postperm'] && $allowpost) || ($forum['postperm'] && strstr($forum['postperm'], "\t$groupid\t")) || $forum['allowpost'];
$allowpostreply = (!$thread['closed'] || $ismoderator) && ((!$forum['replyperm'] && $allowpost) || ($forum['replyperm'] && strstr($forum['replyperm'], "\t$groupid\t")) || $forum['allowreply']);
if($delayviewcount) {
$logfile = DISCUZ_ROOT.'./forumdata/viewcount.log';
if(substr($timestamp, -2) == '00') {
require DISCUZ_ROOT.'./include/misc.php';
updateviews();
}
if(@$fp = fopen($logfile, 'a')) {
fwrite($fp, "$tid\n");
fclose($fp);
}elseif($adminid == 1) {
showmessage('view_log_invalid');
}
} else {
$db->query("UPDATE LOW_PRIORITY $table_threads SET views=views+1 WHERE tid='$tid'", 'UNBUFFERED');
}
include template('viewthread');
} elseif( $action == 'printable' && $tid) {
require DISCUZ_ROOT.'./include/printable.php';
}
?> |