<?php
define('THIS_SCRIPT', 'loadtree');
require_once 'global.php';
$lang = load_lang($lang, 'loadtree' );

if ( intval($groupsetting[2]) == 0 ){
	exit;
}
if ( $star == '' || !is_numeric($star) ){
	$star = 1;
}
if ( $openid == '' || !is_numeric($openid) ){
	$openid = 0;
}
if ( $id == '' || !is_numeric($id) ){
	exit;
}
if ( $replyid == '' || !is_numeric($replyid) ){
	$replyid = $id;
}

echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body>';

$query=$db->query("Select child,posttable From {$dv}topic Where topicid=$id");
if ($ts = $db->fetch_array($query)){
	$allnum = $ts['child'];
	$totalusetable = $ts['posttable'];
}else{
	exit;
}
$pagecount = ceil(($allnum + 1) / $board_settings[61]);
$query=$db->query("select t.announceid,t.parentid,t.boardid,t.username,t.postuserid,t.topic,t.dateandtime,t.length,t.rootid,t.layer,t.orders,t.expression,t.body,t.locktopic,u.lockuser,t.signflag from {$totalusetable} t Inner Join {$dv}user u On t.postuserid=u.userid where boardid=$boardid and t.rootid=$id order by t.RootID desc,t.orders",array('absolutePage'=>$star,'pageSize'=>$board_settings[61]));

require_once printout('loadtree');

footer(false);

echo '</body></html>';

//过滤不必要UBB,和HTML
function reUBBCode(&$strContent){
	if( $strContent == '' ){
		return '';
	}
	return preg_replace(
			 array(
			  '/&nbsp;/i'
			 ,'/(\[QUOTE\])(.|\n)*(\[\/QUOTE\])/i'
			 ,'/(\[point=*([0-9]*)\])(.|\n)*(\[\/point\])/i'
			 ,'/(\[post=*([0-9]*)\])(.|\n)*(\[\/post\])/i'
			 ,'/(\[power=*([0-9]*)\])(.|\n)*(\[\/power\])/i'
			 ,'/(\[usercp=*([0-9]*)\])(.|\n)*(\[\/usercp\])/i'
			 ,'/(\[money=*([0-9]*)\])(.|\n)*(\[\/money\])/i'
			 ,'/(\[replyview\])(.|\n)*(\[\/replyview\])/i'
			 ,'/(\[usemoney=*([0-9]*)\])(.|\n)*(\[\/usemoney\])/i'
			 ,'/<I><\/I>/i'
			 ,'/\n|\r/i'
			 ,'/'.chr(32).'/i'
			 ,'/'.chr(9).'/i'
			 ,'/<(.[^>]*)>/i'
			 )
			,array(
			 ''
			,''
			,'&nbsp;'
			,'&nbsp;'
			,'&nbsp;'
			,'&nbsp;'
			,'&nbsp;'
			,'&nbsp;'
			,'&nbsp;'
			,''
			,''
			,' '
			,' '
			,''
			)
			,$strContent
		   );
}//end function reUBBCode

//截取指定字符
function &cutStr(&$str, $strlen){
	if ($strlen <= 0) {
		return '';
	}
	$returnval = trim($str);
	if ($returnval === '') {
		return '';
	}
	//去掉所有HTML标记
	$returnval = preg_replace( '/<([^<>]*?)>/i' ,'' ,$returnval);
	static $objenc = null;
	if (empty($objenc)) {
		require_once INC_PATH.'DV_Encoding.class.php';
		$objenc = DV_Encoding::GetEncoding($GLOBALS['charset']);
	}
	$returnval = str_replace(array("\r", "\n"), '', $objenc->SubString($returnval, 0, $strlen));
	return $returnval;
}//end function cutStr
?>