<?php
define('SCR','read');
require_once('global.php');
require_once(R_P.'require/forum.php');
require_once(R_P.'require/bbscode.php');
include_once(D_P.'data/bbscache/cache_read.php');

$fieldadd = $tablaadd = $sqladd = $fastpost = $special = $ifmagic = $urladd = '';
if (is_array($customfield)) {
	foreach ($customfield as $key => $value) {
		$fieldadd .= ',mb.field_'.(int)$value['id'];
	}
}
if ($db_union) {
	$db_union = explode("\t",stripslashes($db_union));
	$db_union[0] && $db_hackdb = array_merge((array)$db_hackdb,(array)unserialize($db_union[0]));
}
$showfield	= array();
$custominfo = $db_union[7] ? (array)unserialize($db_union[7]) : array();
foreach ($custominfo as $key => $val) {
	if (substr($val[3],2,1)=='1') {
		$showfield[] = $key;
	}
}
!empty($showfield) && $fieldadd .= ',mb.customdata';
$fieldadd && $tablaadd = 'LEFT JOIN pw_memberinfo mb ON mb.uid=t.authorid';

InitGP(array('fpage','page','uid','toread'));
if ($page > 1) {
	$S_sql = $J_sql = '';
} else {
	$page < 1 && $page != 'e' && $page = 1;
	$start_limit = 0;
	$pw_tmsgs = GetTtable($tid);
	$S_sql = ',tm.*,m.uid,m.username,m.gender,m.oicq,m.aliww,m.groupid,m.memberid,m.icon AS micon ,m.hack,m.honor,m.signature,m.regdate,m.medals,m.userstatus,md.postnum,md.digests,md.rvrc,md.money,md.credit,md.currency,md.thisvisit,md.lastvisit,md.onlinetime,md.starttime';
	$J_sql = "LEFT JOIN $pw_tmsgs tm ON t.tid=tm.tid LEFT JOIN pw_members m ON m.uid=t.authorid LEFT JOIN pw_memberdata md ON md.uid=t.authorid";
}
$read = $db->get_one("SELECT t.* $S_sql $fieldadd FROM pw_threads t $J_sql $tablaadd WHERE t.tid=".pwEscape($tid));
!$read && Showmsg('illegal_tid');

if ($read['ifmagic'] && $db_windmagic) {
	$ifmagic = 1;
	list($magicid,$magicname) = explode("\t",$read['magic']);
}
$fpage    = (int)$fpage;
$fid      = $read['fid'];
$ptable   = $read['ptable'];
$ifcheck  = $read['ifcheck'];
$pw_posts = GetPtable($ptable);
$advertdb = AdvertInit(SCR,$fid);
if (is_array($advertdb['header'])) {
	$header_ad = $advertdb['header'][array_rand($advertdb['header'])]['code'];
}
if (is_array($advertdb['footer'])) {
	$footer_ad = $advertdb['footer'][array_rand($advertdb['footer'])]['code'].'<br />';
}
$foruminfo = $db->get_one('SELECT * FROM pw_forums f LEFT JOIN pw_forumsextra fe USING(fid) WHERE f.fid='.pwEscape($fid));
!$foruminfo && Showmsg('data_error');
$forumset  = unserialize($foruminfo['forumset']);
wind_forumcheck($foruminfo);
$subject  = $read['subject'];
$authorid = $read['authorid'];
list(,,$downloadmoney,$downloadimg) = explode("\t",$forumset['uploadset']);
if (!$foruminfo['allowvisit'] && $_G['allowread']==0 && $_COOKIE) {
	Showmsg('read_group_right');
}
unset($advertdb['header'],$advertdb['footer'],$db_advertdb,$S_sql,$J_sql,$foruminfo['forumset']);

$rewardtype = null; /*** 懸賞 ***/

//安全權限
$isGM = $isBM = $admincheck = $managecheck = 0;
$pwSystem = array();

if ($groupid != 'guest') {
	$isGM = CkInArray($windid,$manager);
	$isBM = admincheck($foruminfo['forumadmin'],$foruminfo['fupadmin'],$windid);
	$admincheck = ($isGM || $isBM) ? 1 : 0;
	if (!$isGM) {
		$pwSystem = pwRights($isBM);
		if ($pwSystem && ($pwSystem['tpccheck'] || $pwSystem['typeadmin'] || $pwSystem['delatc'] || $pwSystem['moveatc'] || $pwSystem['copyatc'] || $pwSystem['topped'] || $pwSystem['unite'] || $pwSystem['pingcp'])) {//system rights
			$managecheck = 1;
		}
		$pwViewHide = $pwSystem['viewhide'];
	} else {
		$managecheck = $pwViewHide = 1;
	}
}
if ($foruminfo['allowread'] && !$admincheck && !allowcheck($foruminfo['allowread'],$groupid,$winddb['groups'])) {
	Showmsg('forum_read_right');
}
if (!$admincheck) {
	!$foruminfo['allowvisit'] && forum_creditcheck();
	$foruminfo['forumsell'] && forum_sell($fid);
}
if ($read['ifcheck'] == 0 && !$isGM && $windid != $read['author'] && !$pwSystem['viewcheck']) {
	Showmsg('read_check');
}
if ($read['locked']%3==2 && !$isGM && !$pwSystem['viewclose']) {
	Showmsg('read_locked');
}
if ($winddb['p_num']) {
	$db_readperpage = $winddb['p_num'];
} elseif ($forumset['readnum']) {
	$db_readperpage = $forumset['readnum'];
}
$creditnames = pwCreditNames();
if (is_numeric($uid) && $read['replies'] > 0) {
	$rt = $db->get_one("SELECT COUNT(*) AS n FROM $pw_posts WHERE tid=".pwEscape($tid)." AND authorid=".pwEscape($uid)." AND anonymous='0' AND ifcheck='1'");
	$read['replies'] = $rt['n'];
	$sqladd = 'AND t.authorid='.pwEscape($uid)." AND t.anonymous='0'";
	$urladd = "&uid=$uid";
}
$count = $read['replies']+1;
$numofpage = ceil($count/$db_readperpage);

if ($page == 'e' || $page > $numofpage) {
	$numofpage == 1 && $page > 1 && ObHeader("read.php?tid=$tid&page=1&toread=$toread");
	$page = $numofpage;
}

list($guidename,$forumtitle) = getforumtitle(forumindex($foruminfo['fup'],1),1);
$guidename .= " <span class=\"crumbs-item current\"><i> </i><strong><a href=\"read.php?tid=$tid\">$subject</a></strong>";
$forumtitle = '|'.$forumtitle;
$db_metakeyword = $subject.', '.trim(str_replace(array('|',' - '),', ',$forumtitle),', ');
$db_metadescrip = substrs(str_replace('"','&quot;',strip_tags($read['content'])),100);//提取內容描述

require_once(R_P.'require/header.php');
require_once(R_P.'require/showimg.php');
Update_ol();
$readdb = $authorids = $fbpid = array();

if ($read['special'] == 1 && ($foruminfo['allowtype'] & 2) && ($page == 1 || $numofpage == 1)) {
	require_once(R_P.'require/readvote.php');
} elseif ($read['special'] == 2 && ($foruminfo['allowtype'] & 4) && ($page == 1 || $numofpage == 1)) {
	require_once(R_P.'require/readact.php');
} elseif ($read['special'] == 3 && ($foruminfo['allowtype'] & 8)) {
	require_once(R_P.'require/readrew.php');
} elseif ($read['special'] == 4 && ($foruminfo['allowtype'] & 16)) {
	require_once(R_P.'require/readtrade.php');
} elseif ($read['special'] == 5 && ($foruminfo['allowtype'] & 32)) {
	require_once(R_P.'require/readdebate.php');
}

if ($db_replysitemail && $read['authorid']==$winduid && $read['ifmail']==4) {
	$sqluid = pwEscape($winduid);
	$rt = $db->get_one('SELECT replyinfo FROM pw_memberinfo WHERE uid='.$sqluid);
	$rt['replyinfo'] = str_replace(",$tid,",',',$rt['replyinfo']);
	if ($rt['replyinfo'] == ',') {
		if (getstatus($winddb['userstatus'],6)) {
			$db->update('UPDATE pw_members SET userstatus=userstatus&~(1<<5) WHERE uid='.$sqluid);
		}
		$rt['replyinfo'] = '';
	}
	$db->update('UPDATE pw_memberinfo SET replyinfo='.pwEscape($rt['replyinfo']).' WHERE uid='.$sqluid);
	$db->update("UPDATE pw_threads SET ifmail='2' WHERE tid=".pwEscape($tid));
}
if ($page == 1) {
	if ($foruminfo['allowhtm'] == 1) {
		$htmurl = $db_htmdir.'/'.$fid.'/'.date('ym',$read['postdate']).'/'.$read['tid'].'.html';
		if (!$foruminfo['cms'] && !$toread && file_exists(R_P.$htmurl)) {
			ObHeader("$R_url/$htmurl");
		}
	}
	$read['pid'] = 'tpc';
	$readdb[]	 = $read;
}
$toread && $urladd .= "&toread=$toread";
$pages = numofpage($count,$page,$numofpage,"read.php?tid=$tid&fpage=$fpage{$urladd}&");

$tpc_locked = $read['locked']%3<>0 ? 1 : 0;

if (!$db_hithour) {
	$db->update('UPDATE pw_threads SET hits=hits+1 WHERE tid='.pwEscape($tid));
} else {
	writeover(D_P.'data/bbscache/hits.txt',$tid."\t",'ab');
}

/***  帖子瀏覽記錄  ***/
$readlog = str_replace(",$tid,",',',GetCookie('readlog'));
$readlog.= ($readlog ? '' : ',').$tid.',';
substr_count($readlog,',')>11 && $readlog = preg_replace("/[\d]+\,/i",'',$readlog,3);
Cookie('readlog',$readlog);

$favortitle = str_replace(array("&#39;","'","\"","\\"),array("‘","\\'","\\\"","\\\\"),$subject);
$db_bbsname_a = addslashes($db_bbsname);//模版內用到

if ($read['replies'] > 0) {
	$readnum	 = $db_readperpage;
	$pageinverse = $page > 20 && $page > ceil($numofpage/2) ? true : false;

	if ($pageinverse) {
		$start_limit = $count-$page*$db_readperpage;
		$order = $rewardtype != null ? "t.ifreward ASC,t.postdate DESC" : "t.postdate DESC";
	} else {
		$start_limit = ($page-1)*$db_readperpage-1;
		$order = $rewardtype != null ? "t.ifreward DESC,t.postdate" : "t.postdate";
	}
	if ($start_limit < 0) {
		$readnum += $start_limit;
		$start_limit = 0;
	}
	$limit = pwLimit($start_limit,$readnum);
	$query = $db->query("SELECT t.*,m.uid,m.username,m.gender,m.oicq,m.aliww,m.groupid,m.memberid,m.icon AS micon,m.hack,m.honor,m.signature,m.regdate,m.medals,m.userstatus,md.postnum,md.digests,md.rvrc,md.money,md.credit,md.currency,md.thisvisit,md.lastvisit,md.onlinetime,md.starttime $fieldadd FROM $pw_posts t LEFT JOIN pw_members m ON m.uid=t.authorid LEFT JOIN pw_memberdata md ON md.uid=t.authorid $tablaadd WHERE t.tid=".pwEscape($tid)." AND t.ifcheck='1' $sqladd ORDER BY $order $limit");

	while ($read = $db->fetch_array($query)) {
		$readdb[] = $read;
	}
	$db->free_result($query);
	$pageinverse && $readdb = array_reverse($readdb);
}
$bandb = isban($readdb,$fid);
$start_limit = ($page - 1) * $db_readperpage;
foreach ($readdb as $key => $read) {
	isset($bandb[$read['authorid']]) && $read['groupid'] = 6;
	$authorids[]  = $read['authorid'];
	$readdb[$key] = viewread($read,$start_limit++);
	$db_menuinit .= ",'td_read_".$read['pid']."':'menu_read_".$read['pid']."'";
}
foreach ($fbpid as $key => $val) {
	if ($val) {
		$db->update("UPDATE $pw_posts SET ifwordsfb=".pwEscape($key)."WHERE pid IN (".pwImplode($val).")");
	}
}

$authorids = pwImplode($authorids);
unset($sign,$ltitle,$lpic,$lneed,$_G['right'],$_MEDALDB,$fieldadd,$tablaadd,$read,$order,$readnum,$pageinverse,$fbpid);

if ($db_showcolony && $authorids) {
	$colonydb = array();
	$query = $db->query("SELECT c.uid,cy.id,cy.cname FROM pw_cmembers c LEFT JOIN pw_colonys cy ON cy.id=c.colonyid WHERE c.uid IN($authorids) AND c.ifadmin!='-1'");
	while ($rt = $db->fetch_array($query)) {
		if (!$colonydb[$rt['uid']]) {
			$colonydb[$rt['uid']] = $rt;
		}
	}
	$db->free_result($query);
}
if ($db_showcustom && $authorids) {
	$customdb = $cids = array();
	foreach ($_CREDITDB as $key => $value) {
		if (strpos($db_showcustom,",$key,") !== false) {
			$cids[] = $key;
		}
	}
	if ($cids) {
		$cids = pwImplode($cids);
		$query = $db->query("SELECT uid,cid,value FROM pw_membercredit WHERE uid IN($authorids) AND cid IN($cids)");
		while ($rt = $db->fetch_array($query)) {
			$customdb[$rt['uid']][$rt['cid']] = $rt['value'];
		}
		$db->free_result($query);
	}
}
if ($groupid != 'guest' && !$tpc_locked && ($admincheck || !$foruminfo['allowrp'] || allowcheck($foruminfo['allowrp'],$groupid,$winddb['groups'],$fid,$winddb['reply']))) {
	$psot_sta = 'reply';//control the faster reply
	$titletop1= substrs('Re:'.str_replace('&nbsp;',' ',$subject),$db_titlemax-2);
	$fastpost = 'fastpost';
	$db_forcetype = 0;
}
$db_menuinit .= ",'td_post' : 'menu_post','td_post1' : 'menu_post','td_admin' : 'menu_admin'";

//allowtype onoff
if ($foruminfo['allowtype'] && (($foruminfo['allowtype'] & 1) || ($foruminfo['allowtype'] & 2 && $_G['allownewvote']) || ($foruminfo['allowtype'] & 4 && $_G['allowactive']) || ($foruminfo['allowtype'] & 8 && $_G['allowreward'])|| ($foruminfo['allowtype'] & 16))) {
	$N_allowtypeopen = true;
} else {
	$N_allowtypeopen = false;
}

if (defined('M_P') && file_exists(M_P.'read.php')) {
	require_once(M_P.'read.php');
}
$msg_guide = headguide($guidename);
unset($fourm,$guidename);

require_once PrintEot('read');
footer();

function viewread($read,$start_limit) {
	global $db,$_G,$isGM,$pwSystem,$groupid,$attach_url,$winduid,$tablecolor,$tpc_author,$tpc_buy,$tpc_pid,$tpc_tag,$count,$timestamp,$db_onlinetime,$attachdir,$attachpath,$readcolorone,$readcolortwo,$lpic,$ltitle,$imgpath,$db_ipfrom,$db_showonline,$stylepath,$db_windpost,$db_windpic,$db_signwindcode,$fid,$tid,$pid,$md_ifopen,$_MEDALDB,$rewardtype,$db_shield,$db_wordsfb,$db_iftag;
	$read['lou']    = $start_limit;
	$read['jupend'] = $start_limit==$count-1 ? "<a name=a></a><a name=$read[pid]></a>" : "<a name=$read[pid]></a>";
	$tpc_buy = $read['buy'];
	$tpc_pid = $read['pid'];
	$tpc_tag = NULL;
	$tpc_shield = 0;

	$read['ifsign']<2 && $read['content'] = str_replace("\n","<br />",$read['content']);
	$anonymous = ($read['anonymous'] && !$isGM && $winduid != $read['authorid'] && !$pwSystem['viewhide']);

	if ($read['groupid'] && !$anonymous) {
		$read['groupid'] == '-1' && $read['groupid'] = $read['memberid'];
		!array_key_exists($read['groupid'],(array)$lpic) && $read['groupid'] = 8;
		$read['lpic']		= $lpic[$read['groupid']];
		$read['level']		= $ltitle[$read['groupid']];
		$read['regdate']	= get_date($read['regdate'],"Y-m-d");
		$read['lastlogin']	= get_date($read['lastvisit'],"Y-m-d");
		$read['aurvrc']		= floor($read['rvrc']/10);
		$read['author']		= $read['username'];
		$tpc_author			= $read['author'];

		if (!empty($GLOBALS['showfield'])) {
			$customdata = $read['customdata'] ? (array)unserialize($read['customdata']) : array();
			$read['customdata'] = array();
			foreach ($customdata as $key => $val) {
				if ($val && in_array($key,$GLOBALS['showfield'])) {
					$read['customdata'][$key] = $val;
				}
			}
		}
		$read['ipfrom'] = $db_ipfrom == 1 && $_G['viewipfrom'] ? ' From:'.$read['ipfrom'] : '';
		if ($isGM || $pwSystem['viewip']) {
			$read['ip'] = "IP:$read[userip] |";
		}
		$read['ontime'] = (int)($read['onlinetime']/3600);
		$read['groupid'] == 6 && $read['honor'] = '';

		if ($read['groupid'] <> 6 && ($read['ifsign'] == 1 || $read['ifsign'] == 3)) {
			global $sign;
			if (!$sign[$read['author']]) {
				global $db_signmoney,$db_signgroup,$tdtime,$db_signcurtype;
				$curvalue = $db_signcurtype=='rvrc' ? $read['aurvrc'] : $read[$db_signcurtype];
				if ($db_signmoney && strpos($db_signgroup,",$read[groupid],") !== false && (!getstatus($read['userstatus'],10) || !$read['starttime'] || $curvalue < (($tdtime-$read['starttime'])/86400)*$db_signmoney)) {
					$read['signature'] = '';
				} else {
					if ($db_signwindcode && getstatus($read['userstatus'],9)) {
						if ($_G['right'][$read['groupid']]['imgwidth'] && $_G['right'][$read['groupid']]['imgheight']) {
							$db_windpic['picwidth']  = $_G['right'][$read['groupid']]['imgwidth'];
							$db_windpic['picheight'] = $_G['right'][$read['groupid']]['imgheight'];
						}
						if ($_G['right'][$read['groupid']]['fontsize']) {
							$db_windpic['size'] = $_G['right'][$read['groupid']]['fontsize'];
						}
						$read['signature'] = convert($read['signature'],$db_windpic,2);
					}
					$read['signature'] = str_replace("\n","<br />",$read['signature']);
				}
				$sign[$read['author']] = $read['signature'];
			} else {
				$read['signature'] = $sign[$read['author']];
			}
		} else {
			$read['signature'] = '';
		}
	} else {
		$read['lpic']   = '8';
		$read['level']  = $read['digests']   = $read['postnum'] = $read['money']   = '*';
		$read['aurvrc'] = $read['lastlogin'] = $read['credit']  = $read['regdate'] = '*';
		$read['honor']  = $read['signature'] = $read['micon']   = $read['aliww'] = '';
		if ($anonymous) {
			$read['oicq']		= $read['ip'] = $read['medals'] = $read['ipfrom'] = '';
			$read['author']		= $GLOBALS['db_anonymousname'];
			$read['authorid']	= 0;
			foreach ($GLOBALS['customfield'] as $key => $val) {
				$field = "field_".(int)$val['id'];
				$read[$field] = '*';
			}
		}
	}
	$read['face']	  = showfacedesign($read['micon']);
	list($read['posttime'],$read['timetype'],$read['postdate']) = getLastDate($read['postdate']);
	$read['mark'] = $read['reward'] = $read['tag'] = NULL;
	if ($read['ifmark']) {
		$markdb = explode("\t",$read['ifmark']);
		foreach ($markdb as $key => $value) {
			$read['mark'] .= "<li>$value</li>";
		}
	}
	if ($rewardtype != null) {
		if ($read['lou'] == 0 || $read['ifreward'] > 0 || ($rewardtype == '0' && $winduid == $GLOBALS['authorid'] && $winduid != $read['authorid'])) {
			$read['reward'] = Getrewhtml($read['lou'],$read['ifreward'],$read['pid']);
		}
	}
	if ($read['icon']) {
		$read['icon'] = "<img src=\"$imgpath/post/emotion/$read[icon].gif\" align=\"left\" border=\"0\" />";
	} else{
		$read['icon'] = '';
	}
	if ($md_ifopen && $read['medals']) {
		$medals = $ifMedalNotExist = '';
		$md_a = explode(',',$read['medals']);
		foreach ($md_a as $key => $value) {
			if ($value && $_MEDALDB[$value]) {
				$medals .= "<img src=\"hack/medal/image/{$_MEDALDB[$value][picurl]}\" title=\"{$_MEDALDB[$value][name]}\"> ";
			} else {
				unset($md_a[$key]);
				$ifMedalNotExist = 1;
			}
		}
		if ($ifMedalNotExist == 1) {
			$newMedalInfo = implode(',',$md_a);
			$db->update("UPDATE pw_members SET medals=".pwEscape($newMedalInfo)." WHERE uid=".pwEscape($read['authorid']));
		}
		$read['medals'] = $medals.'<br />';
	} else {
		$read['medals'] = '';
	}
	$read['leaveword'] && $read['content'] .= leaveword($read['leaveword'],$read['pid']);

	if ($db_iftag && $read['tags']) {
		list($tagdb,$tpc_tag) = explode("\t",$read['tags']);
		$tagdb = explode(' ',$tagdb);
		foreach ($tagdb as $key => $tag) {
			$tag && $read['tag'] .= "<a href=\"job.php?action=tag&tagname=".rawurlencode($tag)."\"><span class=\"s3\">$tag</span></a> ";
		}
	}
	if ($read['ifshield'] || $read['groupid'] == 6 && $db_shield) {
		if ($read['ifshield'] == 2) {
			$read['content'] = shield('shield_del_article');
			$read['subject'] = '';
			$tpc_shield = 1;
		} else {
			if ($groupid == '3') {
				$read['subject'] = shield('shield_title');
			} else {
				$read['content'] = shield($read['ifshield'] ? 'shield_article' : 'ban_article');
				$read['subject'] = '';
				$tpc_shield = 1;
			}
		}
		$read['icon'] = '';
	}
	if (!$tpc_shield) {
		$attachs = $aids = array();
		if ($read['aid']) {
			$attachs = unserialize($read['aid']);
			$read['ifhide'] > 0 && ifpost($tid) == 1 && $read['ifhide'] = 0;
			if (is_array($attachs) && !$read['ifhide']) {
				$aids = attachment($read['content']);
			}
		}
		$read['ifwordsfb'] != $db_wordsfb && $read['content'] = wordsfb($read['content'],$read['ifwordsfb']);

		if ($read['ifconvert'] == 2) {
			$read['content'] = convert($read['content'], $db_windpost);
		} else {
			$tpc_tag && $read['content'] = relatetag($read['content'], $tpc_tag);
			strpos($read['content'],'[s:') !== false && $read['content'] = showface($read['content']);
		}
		if ($attachs && is_array($attachs) && !$read['ifhide']) {
			if ($winduid == $read['authorid'] || $isGM || $pwSystem['delattach']) {
				$dfadmin = 1;
			} else {
				$dfadmin = 0;
			}
			foreach ($attachs as $at) {
				$atype = '';
				$rat = array();
				if ($at['type'] == 'img' && $at['needrvrc'] == 0 && (!$GLOBALS['downloadimg'] || !$GLOBALS['downloadmoney'] || $_G['allowdownload'] == 2)) {
					$a_url = geturl($at['attachurl'],'show');
					if (is_array($a_url)) {
						$atype = 'pic';
						$dfurl = '<br>'.cvpic($a_url[0], 1, $db_windpost['picwidth'], $db_windpost['picheight'], $at['ifthumb']);
						$rat = array('aid' => $at['aid'], 'img' => $dfurl, 'dfadmin' => $dfadmin, 'desc' => $at['desc']);
					} elseif ($a_url == 'imgurl') {
						$atype = 'picurl';
						$rat = array('aid' => $at['aid'], 'name' => $at['name'], 'dfadmin' => $dfadmin, 'verify' => md5("showimg{$tid}{$read[pid]}{$fid}{$at[aid]}{$GLOBALS[db_hash]}"));
					}
				} else {
					$atype = 'downattach';
					if ($at['needrvrc'] > 0) {
						!$at['ctype'] && $at['ctype'] = $at['special'] == 2 ? 'money' : 'rvrc';
						$at['special'] == 2 && $GLOBALS['db_sellset']['price'] > 0 && $at['needrvrc'] = min($at['needrvrc'], $GLOBALS['db_sellset']['price']);
					}
					$rat = array('aid' => $at['aid'], 'name' => $at['name'], 'size' => $at['size'], 'hits' => $at['hits'], 'needrvrc' => $at['needrvrc'], 'special' => $at['special'], 'cname' => $GLOBALS['creditnames'][$at['ctype']], 'type' => $at['type'], 'dfadmin' => $dfadmin, 'desc' => $at['desc'], 'ext' => strtolower(substr(strrchr($at['name'],'.'),1)));
				}
				if (!$atype) continue;
				if (in_array($at['aid'], $aids)) {
					$read['content'] = attcontent($read['content'], $atype, $rat);
				} else {
					$read[$atype][$at['aid']] = $rat;
				}
			}
		}
	}
	/**
	* convert the post content
	*/
	$read['alterinfo'] && $read['content'] .= "<div id=\"alert_$read[pid]\" style=\"color:gray;margin-top:30px\">[ $read[alterinfo] ]</div>";
	if ($read['remindinfo']) {
		$remind = explode("\t",$read['remindinfo']);
		$remind[0] = str_replace("\n","<br />",$remind[0]);
		$remind[2] && $remind[2] = get_date($remind[2]);
		$read['remindinfo'] = $remind;
	}
	if ($_GET['keyword']) {
		$keywords = explode("|",$_GET['keyword']);
		foreach ($keywords as $key => $value) {
			if ($value) $read['content'] = preg_replace("/(?<=[\s\"\]>()]|[\x7f-\xff]|^)(".preg_quote($value,'/').")([.,:;-?!()\s\"<\[]|[\x7f-\xff]|$)/siU","<u><font color=\"red\">\\1</font></u>\\2",$read['content']);
		}
	}
	$GLOBALS['foruminfo']['copyctrl'] && $read['content'] = preg_replace("/<br \/>/eis","copyctrl()",$read['content']);

	return $read;
}
?>