<?php

/*
[Dvbbs] Dv_ClsMain.php - Version: 1.0.0
Web: http://www.dvbbs.net
Copyright: 2000-2006 Dvbbs.Net
*/
//if(!defined('ISDVBBS')) exit('Access denied.Sorry, you can not access this file directly.');
if (!defined('ISDVBBS') OR !defined('ROOT_PATH') OR !defined('CACHE_PATH')) {
	//header('HTTP/1.0 401 Unauthorized');
	header('HTTP/1.0 400 Bad Request');
	exit;
}
!defined('TIME_NOW') AND define('TIME_NOW', time());
require_once INC_PATH.'general_funcs.php';
class BoardCache
{
	var $_dbObj = null;
	var $_cacheRootPath = '';//'cache/board';
	var $_cachePath = '';//'cache';

	function BoardCache(&$db){
		$this->_initialize($db);
	}//end construct function BoardCache

	function _initialize(&$argDb){
		global $IsSqlDataBase, $db;
		empty($argDb) AND isset($db) AND ($argDb =& $db);
		if( !is_object($argDb) ){
			if( !class_exists('sqldb') ){
				if( $IsSqlDataBase === true ) {
					require_once INC_PATH.'dv_clssql.mssql.php';
				} else {
					require_once INC_PATH.'dv_clssql.php';
				}
			}
			$this->_dbObj = new sqldb();
		} elseif( get_class($argDb) == 'sqldb' ){
			$this->_dbObj =& $argDb;
		} else{
			exit('Class Error!');
		}
		if( !defined('ROOT_PATH') ) define('ROOT_PATH','./');
		$this->_cacheRootPath = CACHE_PATH.'board/';
		$this->_cachePath = CACHE_PATH;
		empty($db) AND ($db =& $this->_dbObj);
	}//end function _initialize()

	function _filePutContents(&$contents,$file,$append=false){
		if( function_exists('file_put_contents') ){
			if ($append===false) {
				return ( @file_put_contents($file, $contents) > 0 ? true : false );
			} else {
				return ( @file_put_contents($file, $contents, FILE_APPEND) > 0 ? true : false );
			}
		} else{
			if( $fp = fopen($file, ($append !== false ? 'ab' : 'wb')) ){
				@flock($fp, 2);
				$writed = @fwrite($fp, $contents, strlen($contents));
				@fclose($fp);
				@chmod($file,0755);
				return ( $writed === false ? false : true );
			} else{
				return false;
			}
		}
	}//end function _filePutContents

	function & Create_HonorShowForum_File(){
		if(!file_exists($this->_cachePath.'forum_plus_honor.php')){
			$fp=fopen($this->_cachePath.'forum_plus_honor.php','w+');
			$context='';
			while (!feof($fp)) {
				$context .= fread($fp, 1024);
			}
			fclose($fp);
		}
		if(!file_exists($this->_cachePath.'Forum_Show_Cache.php')){
			$fp=fopen($this->_cachePath.'Forum_Show_Cache.php','w+');
			$context='';
			while (!feof($fp)) {
				$context .= fread($fp, 1024);
			}
			fclose($fp);
		}
		if(!file_exists($this->_cachePath.'Forum_Postcache_File.php')){
			$fp=fopen($this->_cachePath.'Forum_Postcache_File.php','w+');
			$context='';
			while (!feof($fp)) {
				$context .= fread($fp, 1024);
			}
			fclose($fp);
		}
	}
	function &_getDataBy($boardID=0){
		if( !is_numeric($boardID) ) return false;
		if( !is_object($this->_dbObj) || (get_class($this->_dbObj) != 'sqldb') ) return false;
		$boardID = intval($boardID);
		$db =& $this->_dbObj;
		global $dv;
		if( empty($dv) ) $dv = "dv_";
		if( $query = $db->query("SELECT boardid,boardtype,parentid,parentstr,boardmaster,ishidden,ischeckout,depth FROM {$dv}board WHERE boardid={$boardID}") ){
			$arrCache[0] =& $db->fetch_array($query);
			$db->free_result($query);
			$parentStr = $arrCache[0]['parentstr'];
			if( $query = $db->query("SELECT boardid,boardtype,parentid,parentstr,boardmaster,ishidden,ischeckout,depth FROM {$dv}board WHERE boardid IN ({$parentStr}) ORDER BY parentstr") ){
				while( $result =& $db->fetch_array($query) ){
					$arrCache[] =& $result;
				}
				$db->free_result($query);
			}
			$contents = "<?php\r\n\$_DCACHE['forums'] = array(\r\n";
			$tmpContents = '';
			foreach( $arrCache as $val ){
				$boardid = str_replace(array('\\', "'"), array('\\\\', "\\'"), $val['boardid']);
				$boardtype = str_replace(array('\\', "'"), array('\\\\', "\\'"), $val['boardtype']);
				$parentid = str_replace(array('\\', "'"), array('\\\\', "\\'"), $val['parentid']);
				$parentstr = str_replace(array('\\', "'"), array('\\\\', "\\'"), $val['parentstr']);
				$boardmaster = str_replace(array('\\', "'"), array('\\\\', "\\'"), $val['boardmaster']);
				$hidden = intval($val['ishidden']);
				$depth = intval($val['depth']);
				$checkout = intval($val['ischeckout']);
				if( $tmpContents == '' ) {
					$tmpContents = '1';
				} else{
					$contents .= ",\r\n";
				}
				$contents .= <<<EOT
\t'{$val['boardid']}' => array(
\t\t'boardid' => '{$boardid}',
\t\t'boardtype' => '{$boardtype}',
\t\t'parentid' => '{$parentid}',
\t\t'parentstr' => '{$parentstr}',
\t\t'hidden' => '{$hidden}',
\t\t'checkout' => '{$checkout}',
\t\t'depth' => '{$depth}',
\t\t'boardmaster' => '{$boardmaster}'
\t)
EOT;
}
$contents .= "\r\n);\r\n?>";
return $contents;
} else{
	return '';
}
	}//end function _getDataBy

	//生成所有版面总缓存文件
	function createAll(){
		global $dv;
		$db =& $this->_dbObj;
		//取得广告、版面和审核设置的第一个ID项，避免因找不到对应ID时引起的错误
		$query=$db->query("Select id From {$dv}fsettings Where s_class=1 Order By c_orders");
		while($fs =& $db->fetch_array($query)){
			if ( $setting_id == '' ){
				$setting_id = $fs['id'];
			}else{
				$setting_id .= ',' .$fs['id'];
			}
		}
		$setting_id_array = explode(',',$setting_id);
		$setting_id = ',' .$setting_id. ',';
		$query=$db->query("Select id From {$dv}fsettings Where s_class=2 Order By c_orders");
		while($fs =& $db->fetch_array($query)){
			if ( $ads_id == '' ){
				$ads_id = $fs['id'];
			}else{
				$ads_id .= ',' .$fs['id'];
			}
		}
		$ads_id_array = explode(',',$ads_id);
		$ads_id = ',' .$ads_id. ',';
		if( $query=$db->query("select boardid,boardtype,parentid,parentstr,readme,indeximg,boardmaster,child,postnum,topicnum,todaynum,lastpost,board_setting,ishidden,ischeckout,depth,rules,ads_id,setting_id,showboard,showboardmaster from {$dv}board order by rootid,orders") ){
			$contents = "<?php \$_DCACHE['all_forums']=array(";
			$tmpContents = '';
			while($forum =& $db->fetch_array($query)) {
				

				$myquery=& $db->query("Select id,title,addtime From {$dv}bbsnews Where boardid='{$forum['boardid']}' Order By ID Desc limit 10");
				$forumnews_tmpContents = '';
				unset($forumnews_contents);
				$forumnews_contents = "array(";
				while($newsinfo =& $db->fetch_array($myquery)) {

					$forumnews = str_replace(array('\\', "'"), array('\\\\', "\\'"), $newsinfo['title']);
					$forumnews = '<b>'.$forumnews.'</b> (<span class="runtime_timestamp">'.$newsinfo['addtime'].'</span>)';
					if( $forumnews_tmpContents == '' ) {
						$forumnews_tmpContents = '1';
					} else{
						$forumnews_contents .= ",\r\n";
					}
							$forumnews_contents .= <<<EOT
			\t'{$newsinfo['id']}' => '{$forumnews}'
EOT;
				}
				$forumnews_contents .= ")";

				if ( strpos($setting_id,','.$forum['setting_id'].',') !== false ){
					$mysetting_id = $forum['setting_id'];
				}else{
					$mysetting_id = $setting_id_array[0];
				}
				if ( strpos($ads_id,','.$forum['ads_id'].',') !== false ){
					$myads_id = $forum['ads_id'];
				}else{
					$myads_id = $ads_id_array[0];
				}
				$boardid = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['boardid']);
				$boardtype = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['boardtype']);
				$parentid = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['parentid']);
				$parentstr = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['parentstr']);
				$boardmaster = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['boardmaster']);
				$showboard = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['showboard']);
				$showboardmaster = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['showboardmaster']);
				$hidden = intval($forum['ishidden']);
				$checkout = intval($forum['ischeckout']);
				$depth = intval($forum['depth']);
				$child = $forum['child'];
				if( $tmpContents == '' ) {
					$tmpContents = '1';
				} else{
					$contents .= ",\r\n";
				}
				$contents .= <<<EOT
'{$forum['boardid']}'=>array('boardid'=>'{$boardid}','boardtype'=>'{$boardtype}','parentid'=>'{$parentid}','parentstr'=>'{$parentstr}','child'=>'{$child}','boardmaster'=>'{$boardmaster}','hidden'=>'{$hidden}','checkout'=>'{$checkout}','depth'=>'{$depth}','forumnews'=>{$forumnews_contents},'setting_id'=>'{$mysetting_id}','ads_id'=>'{$myads_id}','showboard'=>'{$showboard}','showboardmaster'=>'{$showboardmaster}')
EOT;
}
	//print_r($forumnews_contents);exit;

$db->free_result($query);
}
if( !empty($contents) ){
	$query=$db->query("Select id,type,setting,s_class From {$dv}fsettings Order By id");
	$tmpContents = '';
	$contents .= ");\r\n\$_DCACHE['forum_settings']=array(\r\n";
	while($fs =& $db->fetch_array($query)){
		$type = str_replace(array('\\', "'"), array('\\\\', "\\'"), $fs['type']);
		$setting = Dv_varExport(explode('","', str_replace(array('<>', '\",\",'), '","', $fs['setting'])), true, true);
		if( $tmpContents == '' ) {
			$tmpContents = '1';
		} else{
			$contents .= ",\r\n";
		}
		$contents .= <<<EOT
{$fs['id']}=>array('type'=>'{$type}','setting'=>{$setting},'class'=>'{$fs[s_class]}')
EOT;
}
$db->free_result($query);
}
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);".'?'.'>';
	$currCacheFile = $this->getRootPath().'board_all.php';
	return $this->_filePutContents($contents, $currCacheFile);
}
	}//end function createAll
	//生成论坛首页友情链接、用户组图例、公告缓存文件
	function createforumlink(){
		global $dv;
		$db =& $this->_dbObj;
		if( $query=$db->query("select id,boardname,readme,url,logo,islogo from {$dv}bbslink where islogo=1 order by id") ){
			$contents = "<?php\r\n\$_DCACHE['forum_link_1'] = array(\r\n";
			$tmpContents = '';
			while($forum =& $db->fetch_array($query)) {
				$linkname = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['boardname']);
				$readme = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['readme']);
				$linkurl = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['url']);
				$linklogo = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['logo']);
				if( $tmpContents == '' ) {
					$tmpContents = '1';
				} else{
					$contents .= ",\r\n";
				}
				$contents .= <<<EOT
\t'{$forum['id']}' => array(
\t\t'linkname' => '{$linkname}',
\t\t'readme' => '{$readme}',
\t\t'linkurl' => '{$linkurl}',
\t\t'linklogo' => '{$linklogo}'
\t)
EOT;
}
$db->free_result($query);
}
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);\r\n";
}
if( $query=$db->query("select id,boardname,readme,url,logo,islogo from {$dv}bbslink where islogo=0 order by id") ){
	$contents .= "\r\n\$_DCACHE['forum_link_2'] = array(\r\n";
	$tmpContents = '';
	while($forum =& $db->fetch_array($query)) {
		$linkname = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['boardname']);
		$readme = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['readme']);
		$linkurl = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['url']);
		if( $tmpContents == '' ) {
			$tmpContents = '1';
		} else{
			$contents .= ",\r\n";
		}
		$contents .= <<<EOT
\t'{$forum['id']}' => array(
\t\t'linkname' => '{$linkname}',
\t\t'readme' => '{$readme}',
\t\t'linkurl' => '{$linkurl}'
\t)
EOT;
}
$db->free_result($query);
}
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);\r\n";
}
if( $query=$db->query("select usergroupid,usertitle,titlepic from {$dv}usergroups where orders>0 order by orders") ){
	$contents .= "\r\n\$_DCACHE['forum_groups'] = array(\r\n";
	$tmpContents = '';
	while($forum =& $db->fetch_array($query)) {
		$usertitle = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['usertitle']);
		$titlepic = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['titlepic']);
		if( $tmpContents == '' ) {
			$tmpContents = '1';
		} else{
			$contents .= ",\r\n";
		}
		$contents .= <<<EOT
\t'{$forum['usergroupid']}' => array(
\t\t'usertitle' => '{$usertitle}',
\t\t'titlepic' => '{$titlepic}'
\t)
EOT;
}
$db->free_result($query);
}
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);\r\n";
}
if( $query=$db->query("select id,title,addtime from {$dv}bbsnews where boardid=0 order by id Desc") ){
	$contents .= "\r\n\$_DCACHE['forum_news'] = array(\r\n";
	$tmpContents = '';
	while($forum =& $db->fetch_array($query)) {
		$forumnews = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['title']);
		$forumnews = '<b>'.$forumnews.'</b> (<span class="runtime_timestamp">'.$forum['addtime'].'</span>)';
		if( $tmpContents == '' ) {
			$tmpContents = '1';
		} else{
			$contents .= ",\r\n";
		}
				$contents .= <<<EOT
\t'{$forum['id']}' => array(
\t\t'newstitle' => '{$forumnews}'
\t)
EOT;
	
	}

$db->free_result($query);
}
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);\r\n".'?'.'>';
	$currCacheFile = $this->getPath().'forum_index.php';
	return $this->_filePutContents($contents, $currCacheFile);
}
	}
	//生成邮件发送配置缓存文件
	function createmailconfig(){
		global $dv;
		$db =& $this->_dbObj;
		$query=$db->query("Select forum_setting From {$dv}setup",array('pageSize'=>1));
		if( $fs =& $db->fetch_array($query) ){
			$fsetting = explode('|||',$fs['forum_setting']);
			$forum_setting = explode(',',str_replace(array('\\', "'"), array('\\\\', "\\'"), $fsetting[1]));
			$forum_info = explode(',',str_replace(array('\\', "'"), array('\\\\', "\\'"), $fsetting[0]));
			$str = <<<EOT
\$msetting['issenderror'] = 1;
\$msetting['mailmod'] = {$forum_setting[87]};
\$msetting['server'] = '{$forum_info[4]}';
\$msetting['port'] = '25';
\$msetting['auth'] = 1;
\$msetting['username'] = '{$forum_info[12]}';
\$msetting['password'] = '{$forum_info[13]}';
EOT;
}
if( $str !== '' ){
	$str = "<?php \r\n".$str."\r\n?>";
	return $this->_filePutContents($str, $this->getPath().'mailconfig.php');
} else{
	return false;
}
	}
	//生成论坛总设置缓存文件
	function createForumSetting($opts = array()){
		global $dv,$nowtimes;
		$db =& $this->_dbObj;
		if (!is_numeric($nowtimes)) {
			$tmp = $nowtimes;
			if (-1 == $tmp OR false === $tmp) {
				$nowtimes = TIME_NOW;
			}
		}
		if (!empty($opts)) {
			if (isset($opts['time_zone_supported'])) {
				$time_zone_supported = ($opts['time_zone_supported'] ? 'true' : 'false');
			} else {
				$time_zone_supported = 'true';
			}
		} else {
			$time_zone_supported = 'true';
		}
		$str = '';
		if( file_exists($this->_cachePath.'forum_setting.php') ){
			include $this->_cachePath.'forum_setting.php';
			$isdefault = 1;
		}
		$query=$db->query("select forum_setting,forum_chansetting,forum_pack,forum_topicnum,forum_postnum,forum_usernum,forum_version,forum_adminfolder,forum_chansetting,forum_nowusebbs,forum_badwords,forum_rbadword,forum_lockip,forum_maxonline,forum_maxonlinedate,forum_maxpostnum,forum_maxpostdate,forum_usernum,forum_lastuser,forum_yesterdaynum,forum_birthuser,forum_alltopnum,forum_tpl,forum_adsid from {$dv}setup",array('pageSize'=>1));
		if( $fs =& $db->fetch_array($query) ){
			$fsetting = explode('|||', str_replace(array('\\', "'"), array('\\\\', "\\'"), $fs['forum_setting']));
			$forum_info = explode(',',str_replace(array('\\', "'"), array('\\\\', "\\'"), $fsetting[0]));
			$forum_setting = explode(',',str_replace(array('\\', "'"), array('\\\\', "\\'"), $fsetting[1]));
			$forum_regsplitwords = str_replace(array('\\', "'"), array('\\\\', "\\'"), $fsetting[4]);
			$forum_tpl = explode('|', str_replace(array('\\', "'"), array('\\\\', "\\'"), $fs['forum_tpl']));
			$style_parentid =& $db->scalar("SELECT styleid FROM {$dv}styles WHERE ename='".$db->escape_string($forum_tpl[0])."' AND directory='templates/'");
			$forum_tpl[1] = $db->scalar("SELECT CONCAT(directory, ename, '.css') FROM {$dv}styles WHERE parentid='{$style_parentid}' AND stype='2'");
			$db->query("UPDATE {$dv}setup SET forum_tpl='".$db->escape_string(implode('|', $forum_tpl))."'");

			$forum_adsid = str_replace(array('\\', "'"), array('\\\\', "\\'"), $fs['forum_adsid']);
			$date_z = $_DCACHE['settings']['timeoffset'] * 3600;
		
			$forum_uptime= strtotime(date('Y-m-d 00:00:00'));
			if (0 == $forum_setting[29]) {
				$fs['forum_birthuser'] = '';
			}
			$forum_setting[8]=intval($forum_setting[8]);
			$forumuploadname = (!empty($forum_setting[76]) ? $forum_setting[76] : 'uploadfile/');
			$filterspechtml =  (!empty($forum_setting[77]) ? $forum_setting[77] : 'iframe|frameset');
			$timedifferencesecond = date('Z');
			$timeoffset= 0;
			$forum_info[14] = intval($forum_info[14]);
			if(empty($forum_setting[103])){
				$forum_setting[103]=0;
			}
			if(empty($forum_setting[104])){
				$forum_setting[104]=0;
			}
			if(empty($forum_setting[105])){
				$forum_setting[105]= '#000000';
			}
			if(empty($forum_setting[106])){
				$forum_setting[106]= '0';
			}
			if(empty($forum_setting[107])){
				$forum_setting[107]= '0';
			}
			if(empty($forum_setting[108])){
				$forum_setting[108]= '0';
			}
			if(empty($forum_setting[109])){
				$forum_setting[109]= '0';
			}
			if(empty($forum_setting[110])){
				$forum_setting[110]= '0';
			}
			if(empty($forum_setting[111])){
				$forum_setting[111]= '0';
			}
			if($forum_setting[112]==''){
				$forum_setting[112]= '0';
			}
			if($forum_setting[113]==''){
				$forum_setting[113]= '1';
			}
			if($forum_setting[114]==''){
				$forum_setting[114]= '1';
			}
			if($forum_setting[115]==''){
				$forum_setting[115]= '1';
			}
			if($forum_setting[116]==''){
				$forum_setting[116]= '1';
			}
			if($forum_setting[117]==''){
				$forum_setting[117]= '1';
			}
			if($forum_setting[118]==''){
				$forum_setting[118]= '1';
			}
			if(empty($forum_setting[119])){
				$forum_setting[119]= 'swf';
			}
			if($forum_setting[120]==''){
				$forum_setting[120]= '1';
			}

			//modified by hj 20071217
			$bogushtml_settings=explode('|',$forum_setting[102]);
			if($bogushtml_settings[1]==0){
				$bogushtml_settings[1]='';
			}elseif($bogushtml_settings[1]==1){
				$bogushtml_settings[1]='htm';
			}if($bogushtml_settings[1]==2){
				$bogushtml_settings[1]='html';
			}if($bogushtml_settings[1]==3){
				$bogushtml_settings[1]='shtml';
			}if($bogushtml_settings[1]==4){
				$bogushtml_settings[1]='ndir';
			}
			
			if($bogushtml_settings[2]==0){
				$bogushtml_settings[2]='';
			}elseif($bogushtml_settings[2]==1){
				$bogushtml_settings[2]='htm';
			}if($bogushtml_settings[2]==2){
				$bogushtml_settings[2]='html';
			}if($bogushtml_settings[2]==3){
				$bogushtml_settings[2]='shtml';
			}if($bogushtml_settings[2]==4){
				$bogushtml_settings[2]='domain';
			}if($bogushtml_settings[2]==5){
				$bogushtml_settings[2]='ndir';
			}
			
		
			if($bogushtml_settings[3]){
				$bogushtml_settings_tmpcont="array(\r\n";
				$bogushtml_setting_boards=explode(';',$bogushtml_settings[3]);
				$i=0;
				foreach ($bogushtml_setting_boards as $bsboards){
					$bsboard=explode('@',$bsboards);
					if(empty($bsboard[0]))continue;
					empty($bsboard[1])&&($bsboard[1]=$bsboard[0]);
					$bsboard[0]=intval($bsboard[0]);
					$bogushtml_settings_tmpcont.="'{$bsboard[1]}'=>{$bsboard[0]}\r\n,{$bsboard[0]}=>'{$bsboard[1]}'\r\n,";
				}
				$bogushtml_settings_tmpcont=substr($bogushtml_settings_tmpcont,0,-1)."\r\n)";
			}else{
				$bogushtml_settings_tmpcont='0';
			}
			$str .= <<<EOT
\$_DCACHE['settings'] = array(
	 'forumversion' => '{$fs['forum_version']}' ,'prohibitcopy' =>'{$forum_setting[106]}' ,'forumname' => '{$forum_info[0]}' ,'forumurl' => '{$forum_info[1]}' ,'showtype' => {$forum_info[14]} ,'homename' => '{$forum_info[2]}' ,'homeurl' => '{$forum_info[3]}' ,'mastermail' => '{$forum_info[5]}' ,'forumlogo' => '{$forum_info[6]}' ,'forumcontact' => '{$forum_info[7]}' ,'keyword' => '{$forum_info[8]}' ,'description' => '{$forum_info[10]}' ,'homepage' => '{$forum_info[11]}' ,'copyright' => '{$fsetting[3]}' ,'forumstop' => '{$forum_setting[21]}' ,'stopreadme' => '{$fsetting[5]}' ,'stoplimited' => '{$forum_setting[69]}' ,'stoptimelist' => '{$forum_setting[70]}' ,'manageurl' => '{$fs['forum_adminfolder']}' ,'forumstarttime' => '{$forum_setting[74]}' ,'newmsgsetting' => {$forum_setting[10]} ,'msggetcode' => {$forum_setting[80]} ,'showbirthuser' => {$forum_setting[29]} ,'showindexright' => {$forum_setting[114]} ,'showindexsearch' => {$forum_setting[115]} ,'showindextopic' => {$forum_setting[116]} ,'showindexgroup' => {$forum_setting[117]} ,'showindexsavvy' => {$forum_setting[118]} ,'applynewuser' => {$forum_setting[37]} ,'usergetcode' => {$forum_setting[78]} ,'logingetcode' => {$forum_setting[79]} ,'forgetcode' => {$forum_setting[81]} ,'forgetlimited' => {$forum_setting[84]} ,'usernamelength' => '{$forum_setting[40]},{$forum_setting[41]}' ,'newusertime' => '{$forum_setting[22]}' ,'mailpassword' => {$forum_setting[23]} ,'maillimited' => {$forum_setting[24]} ,'sendnewusermail' => {$forum_setting[47]} ,'sendnewusermsg' => {$forum_setting[46]} ,'isnewuserlimited' => {$forum_setting[25]} ,'timeoffset' => $timeoffset ,'time_zone_supported' => {$time_zone_supported} ,'scripttimeout' => 300 ,'isruntime' => {$forum_setting[30]} ,'banmail' => '{$forum_setting[52]}' ,'onlineip' => {$forum_setting[28]} ,'onlinefrom' => {$forum_setting[36]} ,'onlinenow' => {$forum_setting[33]} ,'onlinetime' => {$forum_setting[34]} ,'onlinesystem' => {$forum_setting[35]} ,'onlineguess' => {$forum_setting[15]} ,'onlineuser' => {$forum_setting[14]} ,'onlinetimeout' => '{$forum_setting[8]}' ,'onlinemax' => {$forum_setting[26]} ,'onlinepagenum' => {$forum_setting[58]} ,'usersign' => {$forum_setting[42]} ,'userface' => {$forum_setting[53]} ,'userfacewidth' => {$forum_setting[38]} ,'userfaceheight' => {$forum_setting[39]} ,'userfacemaxsize' => {$forum_setting[57]} ,'myfacepostlimited' => {$forum_setting[54]} ,'httpuserface' => {$forum_setting[55]} ,'signubbcode' => {$forum_setting[65]} ,'signhtmlcode' => {$forum_setting[66]} ,'signimgcode' => {$forum_setting[67]} ,'signflashcode' => {$forum_setting[71]} ,'usertitle' => {$forum_setting[6]} ,'usertitlelength' => {$forum_setting[59]} ,'usertitlelimited_post' => {$forum_setting[60]} ,'usertitlelimited_day' => {$forum_setting[61]} ,'usertitlelimited_two' => {$forum_setting[62]} ,'usertitlelimited_word' => '{$forum_setting[63]}' ,'usertopic_alipay' => {$forum_setting[89]} ,'userupgrage_online' => {$forum_setting[107]} ,'userupgrage_show' => {$forum_setting[108]} ,'issavvy_show' => {$forum_setting[109]} ,'indivgroup_show' => {$forum_setting[110]} ,'indivgroup_check' => {$forum_setting[111]} ,'indivgroup_limit' => {$forum_setting[112]} ,'indivgroup_set' => {$forum_setting[113]} ,'userpoint' => '{$fsetting[2]}' ,'isrefresh' => {$forum_setting[19]} ,'refreshtime' => {$forum_setting[20]} ,'refreshpage' => '{$forum_setting[64]}' ,'searchlimited_time' => {$forum_setting[3]} ,'searchlimited_length' => '{$forum_setting[4]}' ,'searchwordcolor' => '{$forum_setting[105]}' ,'searchlimited_word' => '{$forum_setting[9]}' ,'searchlimited_num' => {$forum_setting[12]} ,'searchlimited_hot' => '{$forum_setting[13]}' ,'searchcontent' => {$forum_setting[16]} ,'search_user' => {$forum_setting[17]} ,'search_master' => {$forum_setting[18]} ,'search_alluser' => {$forum_setting[27]} ,'search_topuser' => {$forum_setting[31]} ,'search_usernum' => {$forum_setting[68]} ,'otherpagesize' => {$forum_setting[11]} ,'hottopicreply' => {$forum_setting[44]} ,'iseditinfo' => {$forum_setting[48]} ,'ismastereditinfo' => {$forum_setting[49]} ,'editinfo_time' => {$forum_setting[50]} ,'editinfo_timeout' => {$forum_setting[51]} ,'forum_put_revert' => {$forum_setting[103]} ,'usernewmsg' => {$forum_setting[104]} ,'ismenpai' => {$forum_setting[32]} ,'isvipgroups' => {$forum_setting[43]} ,'plus_tools' => {$forum_setting[90]} ,'plus_tools_sale' => {$forum_setting[91]} ,'plus_magicface' => {$forum_setting[98]} ,'plus_blog' => {$forum_setting[99]} ,'plus_avt' => {$forum_setting[82]} ,'wealth_money' => {$forum_setting[93]} ,'userep_money' => {$forum_setting[94]} ,'usercp_money' => {$forum_setting[95]} ,'ticket_money' => {$forum_setting[96]} ,'boardmaster_moneylimited' => {$forum_setting[97]} ,'cercode_image' => {$forum_setting[119]}
,'wss_site_id' => '{$forum_setting[123]}'
,'wss_password' => '{$forum_setting[124]}'
,'wss_enabled' => '{$forum_setting[125]}'
,'chansetting' => '{$fs['forum_chansetting']}' ,'nowtablename' => '{$fs['forum_nowusebbs']}' ,'badwords' => '{$fs['forum_badwords']}' ,'rbadwords' => '{$fs['forum_rbadword']}' ,'styletpl' => '{$forum_tpl[0]}' ,'lang' => '{$forum_tpl[2]}' ,'css' => '{$forum_tpl[1]}' ,'lockip' => '{$fs['forum_lockip']}' ,'maxonline' => {$fs['forum_maxonline']} ,'maxonlinedate' => '{$fs['forum_maxonlinedate']}' ,'maxpost' => {$fs['forum_maxpostnum']} ,'maxpostdate' => '{$fs['forum_maxpostdate']}' ,'usernum' => {$fs['forum_usernum']} ,'lastuser' => '{$fs['forum_lastuser']}' ,'yestodaynum' => {$fs['forum_yesterdaynum']} ,'birthuser' => '{$fs['forum_birthuser']}' ,'uploadsetting' => '{$forum_setting[7]}' ,'ft_settings' => '{$forum_setting[101]}' ,'bogushtml_settings' => '{$bogushtml_settings[0]}'  ,'bogushtml_settings_bbs' => '{$bogushtml_settings[1]}'  ,'bogushtml_settings_forum' => '{$bogushtml_settings[2]}'  ,'bogushtml_settings_board' => {$bogushtml_settings_tmpcont},'bogushtml_settings_domain' => '{$bogushtml_settings[4]}' ,'leftbar' => '{$forum_setting[2]}' ,'file_pic_guardchain' => $forum_setting[75] ,'forumuploadname' => '{$forumuploadname}' ,'filterspechtml'=>'{$filterspechtml}' ,'useindexstatic' => $forum_setting[120] ,'regsplitwords' => '{$forum_regsplitwords}' ,'forum_alltopnum' => '{$fs['forum_alltopnum']}' ,'forum_uptime' => '{$forum_uptime}'
);
EOT;
			$str = str_replace(' ,',"\r\n\t,",$str);
}

if( $query = $db->query("select styleid,name,ename,directory from {$dv}styles where stype='1' AND tpl_type='0' order by styleid asc") ){
	$recordCount = $db->num_rows($query);
	if( $recordCount > 0 ){
		$str .= <<<EOT
\r\n\$_DCACHE['forum_lang'] = array(
EOT;
		$comma = ' ';
		while( $result =& $db->fetch_array($query) ){
			$result['directory'] = str_replace(array('\\',"'"),array('/',"\\'"),$result['directory']);
			$currdirectory = ($result['directory']{strlen($result['directory'])-1} == '/' ? $result['directory'].$result['ename'] : $result['directory'].'/'.$result['ename']);
			$str .= <<<EOT
\r\n\t{$comma}'{$result['styleid']}'=>array('{$result['name']}','{$currdirectory}')
EOT;
			$comma = ',';
}
$str .= "\r\n);";
}
}
if( $query = $db->query("select styleid,name,ename,directory from {$dv}styles where stype='2' AND tpl_type='0' order by styleid asc") ){
	$recordCount = $db->num_rows($query);
	if( $recordCount > 0 ){
		$str .= <<<EOT
\r\n\$_DCACHE['forum_css'] = array(
EOT;
		$comma = ' ';
		while( $result =& $db->fetch_array($query) ){
			$result['directory'] = str_replace(array('\\',"'"),array('/',"\\'"),$result['directory']);
			$str .= <<<EOT
\r\n\t{$comma}'{$result['styleid']}'=>array('{$result['name']}','{$result['directory']}{$result['ename']}')
EOT;
			$comma = ',';
}
$str .= "\r\n);";
}
}
if( $query = $db->query("Select setting From {$dv}fsettings Where id='{$forum_adsid}'") ){
	$result =& $db->fetch_array($query);
	$forum_ads = Dv_varExport(explode('","', str_replace(array('<>', '\",\",'), '","', $result['setting'])), true, true);
	$str .= <<<EOT
\r\n\$_DCACHE['forum_ads'] = {$forum_ads};
EOT;
}
if( $str !== '' ){
	$str = "<?php \r\n".$str."\r\n?>";
	return $this->_filePutContents($str, $this->getPath().'forum_setting.php');
} else{
	return false;
}
	}//end function createForumSetting
	//生成CSS配置文件
	function createstylecss(){
		global $dv;
		$db =& $this->_dbObj;
		if ($query=$db->query("Select styleid,name,ename,directory,stype,tpl_type,copyright,content,parentid From {$dv}styles Where stype='2' AND tpl_type='0'")){
			$defaultcontent = array('.css' => '', '.php' => array());
			for ($i = 0 ; $i < 43 ; $i++) {
				$defaultcontent['.php'][$i] = '';
			}
			while($cs =& $db->fetch_array($query)) {
				if( $cs['content'] != '' ){
					if ($myquery=$db->query("Select ename From {$dv}styles Where styleid={$cs['parentid']}")){
						$tpl =& $db->fetch_array($myquery);
						$content = unserialize(base64_decode($cs['content']));
						if (false === $content) {
							continue;
						}
						if (empty($content['.css'])) {
							$content['.css'] =& $defaultcontent['.css'];
						}
						if (empty($content['.php'])) {
							$content['.php'] =& $defaultcontent['.php'];
						}
						$stylecss = "'{$tpl['ename']}', '".implode("', '", $content['.php'])."'";
						$str = "<?php \r\n";
						$str .= <<<EOT
\$_DCACHE['stylecss'] = array(
\t{$stylecss}
);
EOT;
						$str .= "\r\n?>";
						if (!$this->_filePutContents($str, $this->getPath()."style/{$cs['ename']}.php")) {
							return false;
						}
					}
				}
			}
		} else {
			return false;
		}
		return true;
	}
	//生成用户组缓存文件
	function createusergroup(){
		global $dv;
		$db =& $this->_dbObj;
		if ($query=$db->query("Select usergroupid,usertitle,minarticle,titlepic,grouppic,parentgid,issetting,groupsetting From {$dv}usergroups Order By usergroupid")){
			$contents = "<?php\r\n\$_DCACHE['all_groups'] = array(\r\n";
			$tmpContents = '';
			while($forum =& $db->fetch_array($query)) {
				$s_contents = "<?php\r\n";
				$groupsetting = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['groupsetting']);
				$usertitle = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['usertitle']);
				$groupsetting = str_replace(',',"','",$groupsetting);
				$groupsetting = "'" .$groupsetting. "'";
				$titlepic = str_replace(array('\\',"'"),array('/',"\\'"),$forum['titlepic']);
				if( $tmpContents === '' ) {
					$tmpContents = '1';
				} else{
					$contents .= ",\r\n";
				}
				$contents .= <<<EOT
\t'{$forum['usergroupid']}' => array(
\t\t{$groupsetting}, '{$usertitle}', 'usertitle'=>'{$usertitle}', 'titlepic'=>'{$titlepic}'
\t)
EOT;
				$s_contents .= <<<EOT
\$gp_usertitle = '{$usertitle}';
\$gp_minarticle = {$forum['minarticle']};
\$gp_titlepic = '{$forum['titlepic']}';
\$gp_pic = '{$forum['grouppic']}';
\$gp_parentgid = {$forum['parentgid']};
\$gp_issetting = '{$forum['issetting']}';
\$groupsetting = array({$groupsetting});
EOT;
				if( !empty($s_contents) ){
					$s_contents .= "\r\n".'?'.'>';
					$currCacheFile = $this->getPath()."group/group_{$forum['usergroupid']}.php";
					if (!$this->_filePutContents($s_contents, $currCacheFile)) {
						return false;
					}
				}
				$s_contents = '';
			}
			$db->free_result($query);
		} else {
			return false;
		}
		if( empty($contents) ){
			return false;
		} else{
			$contents .= "\r\n);\r\n".'?'.'>';
			$currCacheFile = $this->getPath().'group/group_all.php';
			return $this->_filePutContents($contents, $currCacheFile);
		}
	}
	//生成版面用户组设置缓存文件
	function createboardgroup(){
		global $dv;
		$db =& $this->_dbObj;
		if ($query=$db->query("Select boardid,groupid,psetting From {$dv}boardpermission Order By pid")){
			while($forum =& $db->fetch_array($query)) {
				$s_contents = "<?php\r\n";
				$groupsetting = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['psetting']);
				$groupsetting = str_replace(',',"','",$groupsetting);
				$groupsetting = "'" .$groupsetting. "'";
				$s_contents .= <<<EOT
\$groupsetting = array({$groupsetting});
EOT;
				if( !empty($s_contents) ){
					$s_contents .= "\r\n".'?'.'>';
					$currCacheFile = $this->getPath()."group/board_{$forum['groupid']}_{$forum['boardid']}.php";
					if (!$this->_filePutContents($s_contents, $currCacheFile)) {
						return false;
					}
				}
				$s_contents = '';
			}
			$db->free_result($query);
		} else {
			return false;
		}
		return true;
	}
	//生成自定义用户用户组设置缓存文件
	function createuserpermission(){
		global $dv;
		$db =& $this->_dbObj;
		if ($query=$db->query("Select uc_boardid,uc_userid,uc_setting From {$dv}useraccess Order By uc_userid")){
			while($forum =& $db->fetch_array($query)) {
				$s_contents = "<?php\r\n";
				$groupsetting = str_replace(array('\\', "'"), array('\\\\', "\\'"), $forum['uc_setting']);
				$groupsetting = str_replace(',',"','",$groupsetting);
				$groupsetting = "'" .$groupsetting. "'";
				$s_contents .= <<<EOT
\$groupsetting = array({$groupsetting});
EOT;
				if( !empty($s_contents) ){
					$s_contents .= "\r\n".'?'.'>';
					$currCacheFile = $this->getPath()."group/user_{$forum['uc_boardid']}_{$forum['uc_userid']}.php";
					if (!$this->_filePutContents($s_contents, $currCacheFile)) {
						return false;
					}
				}
				$s_contents = '';
			}
			$db->free_result($query);
		} else {
			return false;
		}
		return true;
	}
	//生成用户头像缓存文件
	function createforumface(){
		global $dv;
		$db =& $this->_dbObj;
		$query=$db->query("select forum_face from {$dv}setup Limit 1");
		if( $fs =& $db->fetch_array($query) ){
			$contents = "<?php\r\n\$_DCACHE['userface'] = array(\r\n";
			$tmpContents = '';
			$fsetting = explode('@@@',$fs['forum_face']);
			$forum_face = $fsetting[0];
			$forum_face = str_replace('|||',"','",$forum_face);
			$forum_face = "'" .$forum_face. "userface'";
			if( $tmpContents === '' ) {
				$tmpContents = '1';
			} else{
				$contents .= ",\r\n";
			}
			$contents .= <<<EOT
\t{$forum_face}
EOT;
}
$db->free_result($query);
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);\r\n".'?'.'>';
	$currCacheFile = $this->getPath().'forum_face.php';
	return $this->_filePutContents($contents, $currCacheFile);
}
	}
	function createforumpic(){
		global $dv;
		$db =& $this->_dbObj;
		$query=$db->query("select forum_face from {$dv}setup Limit 1");
		if( $fs =& $db->fetch_array($query) ){
			$contents = "<?php\r\n";
			$forum_pic = explode('@@@',$fs['forum_face']);
			$forum_postface = $forum_pic[1];
			$forum_postface = str_replace('|||',"','",$forum_postface);
			$forum_postface = "'" .$forum_postface. "postface'";
			$forum_emot = $forum_pic[2];
			$forum_emot = str_replace('|||',"','",$forum_emot);
			$forum_emot = "'" .$forum_emot. "postemot'";
			$forum_birth = $forum_pic[3];
			$forum_birth = str_replace('|||',"','",$forum_birth);
			$forum_birth = "'" .$forum_birth. "userbirth'";
			$contents .= <<<EOT
\$_DCACHE['forum_postface'] = array(
\t{$forum_postface}
);
\$_DCACHE['forum_emot'] = array(
\t{$forum_emot}
);
\$_DCACHE['forum_birth'] = array(
\t{$forum_birth}
);
EOT;
}
$db->free_result($query);
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n".'?'.'>';
	$currCacheFile = $this->getPath().'forum_pic.php';
	return $this->_filePutContents($contents, $currCacheFile);
}
	}

	//生成我的空间相关设置缓存文件
	function createSpaceConfig(){
		global $dv;
		$db =& $this->_dbObj;
		$filestring = '';
		if( $query = $db->query("SELECT b.s_name,s_note,s_lastposttime,s_topicnum,s_photonum,s_favnum,s_usernum,s_todaynum,s_postnum,s_setting,s_url,s_sdomain,skinid,s.s_skinname,s.s_path,s.s_viewpic,s.s_info,s.s_builder,b.s_topnews,b.s_managenews,b.today_recommend,b.today_star FROM {$dv}space_system b INNER JOIN {$dv}space_skins s ON s.s_id = b.skinid",array('pageSize'=>1)) ){
			if ($db->num_rows($query) > 0) {
				if ($dbinfo =& $db->fetch_array($query)) {
					//if( (dateDiff('DAY',$dbinfo['s_lastposttime'],date('Y-m-d')) != 0 AND $dbinfo['s_todaynum'] > 0 ) OR $dbinfo['s_todaynum'] < 0 ){
					if( (dateDiff('DAY',$dbinfo['s_lastposttime'],TIME_NOW) != 0 AND $dbinfo['s_todaynum'] > 0 ) OR $dbinfo['s_todaynum'] < 0 ){
						$dbinfo['s_todaynum'] = 0;
						$db->query("UPDATE {$dv}space_system SET s_todaynum=0;");
					}
					if (!empty($dbinfo['today_recommend'])) {
						$arrtmp = array(0=>array('', ''), 1=>array('', ''), 2=>array('', ''), 3=>array('', ''), 4=>array('', ''));
						if ($unserialize = unserialize(base64_decode($dbinfo['today_recommend']))) {
							$dbinfo['today_recommend'] = $unserialize;
						} else {
							$dbinfo['today_recommend'] = $arrtmp;
						}
					} else {
						$dbinfo['today_recommend'] = array();
					}
					if (!empty($dbinfo['today_star'])) {
						$arrtmp = array();
						if ($unserialize = unserialize(base64_decode($dbinfo['today_star']))) {
							$dbinfo['today_star'] = $unserialize;
						} else {
							$dbinfo['today_star'] = $arrtmp;
						}
					} else {
						$dbinfo['today_star'] = array();
					}
					$filestring .= "\r\n\$_DCACHE['spaceConfig_system'] = ".Dv_varExport($dbinfo, true, true).';';
				}
			}
		}

		if( $query = $db->query("SELECT scatid,scattitle,scatnote,ucatnum,topicnum,postnum,todaynum,stype,lastuptime FROM {$dv}space_syscat WHERE stype=0") ){
			if ($db->num_rows($query) > 0) {
				$spaceConfig_syscat = array();
				while ($dbinfo =& $db->fetch_array($query)) {
					if( (dateDiff('d',$dbinfo['lastuptime'],TIME_NOW) != 0 AND $dbinfo['todaynum'] > 0 ) OR $dbinfo['todaynum'] < 0 ){
						$dbinfo['todaynum'] = 0;
						$db->query("UPDATE {$dv}space_syscat SET todaynum=0 WHERE scatid='{$dbinfo['scatid']}';");
					}
					$spaceConfig_syscat[$dbinfo['scatid']] = $dbinfo;
				}
				$filestring .= "\r\n\$_DCACHE['spaceConfig_syscat'] = ".Dv_varExport($spaceConfig_syscat, true, true).';';
			}
		}

		if( $query = $db->query("SELECT scatid,scattitle,scatnote,ucatnum,topicnum,postnum,todaynum,stype,lastuptime FROM {$dv}space_syscat WHERE stype>0 ORDER BY stype ASC") ){
			if ($db->num_rows($query) > 0) {
				$strtmp = '';
				$spaceConfig_syschatcat = array();
				while ($dbinfo =& $db->fetch_array($query)) {
					if( (dateDiff('d',$dbinfo['lastuptime'],TIME_NOW) != 0 && $dbinfo['todaynum'] > 0 ) || $dbinfo['todaynum'] < 0 ){
						$dbinfo['todaynum'] = 0;
						$db->query("UPDATE {$dv}space_syscat SET todaynum=0 WHERE scatid='{$dbinfo['scatid']}';");
					}
					$spaceConfig_syschatcat[$dbinfo['scatid']] =& $dbinfo;
					$dbinfo['stype'] = intval($dbinfo['stype']) - 1;
					$strtmp .= "\r\n\$_DCACHE['spaceConfig_syscat_parent'][{$dbinfo['stype']}][] =& \$_DCACHE['spaceConfig_syschatcat'][{$dbinfo['scatid']}];";
				}
				$filestring .= "\r\n\$_DCACHE['spaceConfig_syschatcat'] = ".Dv_varExport($spaceConfig_syschatcat, true, true).';'.$strtmp."\r\n";
			}
		}

		$timenow = TIME_NOW;
		$strtmp = <<<EOT
\r\n\$_DCACHE['spaceConfig_default'] = array(
\t'spaceUserInfo' => array(
\t\t 'userid' => 0 ,'username' => 'YourName' ,'nickname' => 'NickName' ,'spacename' => 'YourspaceName' ,'password' => '' ,'spacetitle' => 'Dvspace Demo - spaceTitle' ,'spacechildtitle' => 'space Intro' ,'spacenote' => '' ,'joinspacetime' => {$timenow} ,'pageview' => 0 ,'topicnum' => 0 ,'favnum' => 0 ,'photonum' => 0 ,'postnum' => 0 ,'todaynum' => 0 ,'trackbacks' => 0 ,'spacesize' => -1 ,'xmldata' => '' ,'syscatid' => 0 ,'spacesetting' => '1,0,120,15,1,2,15,15,20,12,15,10,space/images/sex/footmark1.gif,space/images/sex/footmark2.gif,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1' ,'lastuptime' => {$timenow} ,'skinid' => 1 ,'s_name' => 'Dv_space {$GLOBALS['lang']['boardcache.str1']}' ,'s_path' => 'space/skins/default/' ,'s_builder' => 'AspSky.Net' ,'stats' => 0
\t\t)
\t,'spacetopic' => array()
\t,'spacelink' => array()
\t,'spacephoto' => array()
\t,'spacepost' => array()
\t,'spacekeyword' => array()
);
EOT;
		$filestring .= str_replace(' ,',"\r\n\t\t,",$strtmp);

		$filestring .= <<<EOT
\r\n\$_DCACHE['spaceConfig_usercat'] = array(
	 'result_set' => array()
	,'spacetopic' => array()
	,'spacelink' => array()
	,'spacephoto' => array()
	,'spacepost' => array()
	,'spacekeyword' => array()
	,'selected_templates_prev'=>'default.'
);
EOT;
		if ('' !== $filestring) {
			$filestring = "<?php \r\n".$filestring."\r\n?>";
			return $this->_filePutContents($filestring, $this->getPath().'space/space_config.php');
		} else{
			return false;
		}
	}//end function createspaceConfig

	function createBy($boardID=0){
		if( !is_numeric($boardID) ) return false;
		$boardID = intval($boardID);
		$contents = '';
		$cacheFile = $this->getRootPath()."board_{$boardID}.php";
		$firstWrite = $this->_filePutContents($contents, $cacheFile);
		//测试是否可以写入，如果写入失败，则退出，不再从数据库取数据。
		if( $firstWrite == false ) return false;
		return $this->_filePutContents($this->_getDataBy($boardID), $cacheFile);
	}//end function createBy

	function removeBy($boardID=0){
		if( !is_numeric($boardID) ) return false;
		$boardID = intval($boardID);
		$cacheFileName = $this->getRootPath()."board_{$boardID}.php";
		if( is_file($cacheFileName) ) @unlink($cacheFileName);
	}//end function removeBy

	function &getBy($boardID=0,$useCache=true){
		if( !is_numeric($boardID) ) return false;
		$boardID = intval($boardID);
		$cacheFile = realpath($this->getRootPath())."/board_{$boardID}.php";
		if( $useCache != true ){
			$this->removeBy($boardID);
			if( !$this->createBy($boardID) ){
				return false;
			}
		}
		if( !is_file($cacheFile) ){
			if( !$this->createBy($boardID) ){
				return false;
			}
		}
		require_once($cacheFile);
		if( !empty($_DCACHE['forums']) && is_array($_DCACHE['forums']) ){
			return $_DCACHE['forums'];
		}
	}//end function getBy

	function getRootPath(){
		return $this->_cacheRootPath;
	}//end function getRootPath
	function getPath(){
		return $this->_cachePath;
	}//end function getPath

	function setRootPath($newPath){
		if( empty($newPath) ) return false;
		$newPath = realpath($newPath);
		if( is_dir($newPath) ){
			$this->_cacheRootPath = $newPath;
			return true;
		}
		return false;
	}//end function setRootPath
}

function Create_forum_show() {
	global $dv,$db;
	if($sql=$db->query("select f_id,f_boardid,f_filename,f_readme from {$dv}upfile where f_boardid!=0 and f_boardid!=444 and f_boardid!=777 order by f_viewnum desc",array('absolutePage'=>0,'pageSize'=>10))){
		$contents.= "<?php\r\n\$forumshowcache['forumshow_cache_1'] = array(\r\n";//热
		$tmpContents='';
		while ($arr=$db->fetch_array($sql)){
			$fid=$arr['f_id'];
			$fboardid=$arr['f_boardid'];
			$ffilename=strleach($arr['f_filename']);
			$freadme=strleach($arr['f_readme']);
			if( $tmpContents == '' ) {
				$tmpContents = '1';
			} else{
				$contents.= ",\r\n";
			}
			$contents .= <<<EOT
\t'{$arr['f_id']}' => array(
\t\t'fid' => '{$fid}',
\t\t'fboardid' => '{$fboardid}',
\t\t'ffilename' => '{$ffilename}',
\t\t'freadme' => '{$freadme}'
\t)
EOT;
}
$db->free_result($sql);
}
if(empty($contents) ){
	return false;
} else{
	$contents.= "\r\n);\r\n";
}
if($sql=$db->query("select f_id,f_boardid,f_filename,f_readme from {$dv}upfile where f_boardid!=0 and f_boardid!=444 and f_boardid!=777 order by f_addtime desc",array('absolutePage'=>0,'pageSize'=>10))){//新
	$contents.= "\r\n\$forumshowcache['forumshow_cache_2'] = array(\r\n";
	$tmpContents='';
	while ($arr=$db->fetch_array($sql)){
		$fid=$arr['f_id'];
		$fboardid=$arr['f_boardid'];
		$ffilename=strleach($arr['f_filename']);
		$freadme=strleach($arr['f_readme']);
		if( $tmpContents == '' ) {
			$tmpContents = '1';
		} else{
			$contents.= ",\r\n";
		}
		$contents .= <<<EOT
\t'{$arr['f_id']}' => array(
\t\t'fid' => '{$fid}',
\t\t'fboardid' => '{$fboardid}',
\t\t'ffilename' => '{$ffilename}',
\t\t'freadme' => '{$freadme}'
\t)
EOT;
}
$db->free_result($sql);
}
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);\r\n".'?'.'>';
	$currcachefile =CACHE_PATH.'Forum_Show_Cache.php';
	return putcachefile($contents, $currcachefile);
}
}
function strleach($str){
	$content=str_replace(array('\\',"'"),array('\\\\',"\\'"),$str);
	return $content;
}
function putcachefile(&$contents,$file,$append=false){
	if( function_exists('file_put_contents') ){
		if ($append===false) {
			return ( @file_put_contents($file, $contents) > 0 ? true : false );
		}
		else {
			if( $fp = fopen($file, ($append !== false ? 'ab' : 'wb')) ){
				@flock($fp, 2);
				$writed = @fwrite($fp, $contents, strlen($contents));
				@fclose($fp);
				@chmod($file,0755);
				return ( $writed === false ? false : true );
			} else{
				return false;
			}
		}
	} else{
		if( $fp = fopen($file, ($append !== false ? 'ab' : 'wb')) ){
			@flock($fp, 2);
			$writed = @fwrite($fp, $contents, strlen($contents));
			@fclose($fp);
			@chmod($file,0755);
			return ( $writed === false ? false : true );
		} else{
			return false;
		}
	}
}

function Create_plus_honor() {
	global $dv,$db;
	if($sql=$db->query("select id,plus_type,plus_name,isuse,plus_setting,mainpage,isshowmenu,plus_copyright,plus_adminpage,plus_id from {$dv}plus where plus_id='honor' order by id desc")){
		$contents.= "<?php\r\n\$plus_index_value['beplusvalue'] = array(\r\n";
		$tmpContents='';
		while ($arr=$db->fetch_array($sql)){
			$isuse=$arr['isuse'];
			$plusid=strleach($arr['plus_id']);
			if( $tmpContents == '' ) {
				$tmpContents = '1';
			} else{
				$contents.= ",\r\n";
			}
			$contents .= <<<EOT
\t\t'isuse' => '{$isuse}',
\t\t'plusid' => '{$plusid}'
EOT;
}
$db->free_result($sql);
}
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);\r\n".'?'.'>';
	$currcachefile =CACHE_PATH.'forum_plus_honor.php';
	@chmod($currcachefile,0777);
	return putcachefile($contents, $currcachefile);
}
}

function Create_index_forumnum() {
	global $dv,$db;
	$forumsql=$db->query("select boardid,boardtype,showtype,parentid,readme,indeximg,boardmaster,child,postnum,topicnum,todaynum,lastpost,allowpost,ishidden,ischeckout from {$dv}board where parentid=0");
	$contents.= "<?php\r\n\$index_forumnum['forumnum'] = array(\r\n";
	$tmpContents='';
	while ($arr=$db->fetch_array($forumsql)){
		$topicnum+=intval($arr['topicnum']);//主题数;
		$forumnum+=intval($arr['postnum']);//贴子数;
	}
	$db->free_result($forumsql);
	if(empty($topicnum)){
		$topicnum=0;
	}
	if(empty($forumnum)){
		$forumnum=0;
	}
	$t_sql=$db->query("select tablename from {$dv}tablelist");
	while($t_arr=$db->fetch_array($t_sql)){
		$time1 = strtotime(date('Y-m-d 00:00:00'));
		$time2 = $time1 + (24 * 3600 - 1);
		$today_num=$db->scalar("SELECT count(1) FROM ".$t_arr['tablename']." WHERE boardid!=444 and boardid!=777 AND (dateandtime between ".$time1." and ".$time2.")");
		$to_count+=$today_num;//今日贴子数;
	}
	if( $tmpContents == '' ) {
		$tmpContents = '1';
	} else{
		$contents.= ",\r\n";
	}
	if(empty($to_count)){
		$to_count=0;
	}
	$contents .= <<<EOT
\t\t'topicnum' => {$topicnum},
\t\t'forumnum' => {$forumnum},
\t\t'todaynum' => {$to_count}
EOT;
	if( empty($contents) ){
		return false;
	} else{
		$contents .= "\r\n);\r\n".'?'.'>';
		$currcachefile =CACHE_PATH.'Forum_Postcache_File.php';
		@chmod($currcachefile,0777);
		return putcachefile($contents, $currcachefile);
	}
}

function Create_index_forumnum_group() {
	global $dv,$db;
	$forumsql=$db->query("select id,postnum,topicnum,todaynum,boardstats from {$dv}group_board");
	$contents.= "<?php\r\n\$indivgroup_forumnum['forumnum'] = array(\r\n";

	while ($arr=$db->fetch_array($forumsql)){
		if ($arr['boardstats'] == 1) {
			$topicnum+=intval($arr['topicnum']);//主题数;
			$forumnum+=intval($arr['postnum']);//贴子数;
			$todaynum+=intval($arr['todaynum']);//今日贴子数;
		}
	}
	$db->free_result($forumsql);
	$time1 = strtotime(date('Y-m-d 00:00:00'));
	$time2 = $time1 - 1;
	$time1 = $time1 - (24 * 3600);
	//昨日贴子数;
	$yestodaynum=$db->scalar("SELECT count(1) FROM {$dv}group_bbs1 WHERE boardid<>-1 AND (dateandtime between ".$time1." and ".$time2.")");
	if(empty($topicnum)){
		$topicnum=0;
	}
	if(empty($forumnum)){
		$forumnum=0;
	}
	if(empty($todaynum)){
		$todaynum=0;
	}
	if(empty($yestodaynum)){
		$yestodaynum=0;
	}

	$contents .= <<<EOT
\t\t'topicnum' => {$topicnum},
\t\t'forumnum' => {$forumnum},
\t\t'todaynum' => {$todaynum},
\t\t'yestodaynum' => {$yestodaynum}
EOT;
	if( empty($contents) ){
		return false;
	} else{
		$contents .= "\r\n);\r\n".'?'.'>';
		$currcachefile =CACHE_PATH.'Forum_Postcache_File_Group.php';
		@chmod($currcachefile,0777);
		return putcachefile($contents, $currcachefile);
	}
}

function CreateBoarderInfo($bid,$taxit){
	if(!$bid)return '';
	global $dv,$db,$lang;
	$sql=$db->query("select boardid,boardtype,showtype,parentid,parentstr,depth,rootid,child,readme,boardmaster,postnum,topicnum,indeximg,todaynum,boarduser,lastpost,orders,board_setting,board_user,isgroupsetting,boardtopstr,cid,rules,allowpost,ishidden,ischeckout,ads_id,setting_id,audit_settings_id from {$dv}board where boardid='{$bid}'");
	$tmpContents='';
	$forumnews='';
	//取得广告、版面和审核设置的第一个ID项，避免因找不到对应ID时引起的错误
	$query=$db->query("Select id From {$dv}fsettings Where s_class=1 Order By c_orders");
	while($fs =& $db->fetch_array($query)){
		if ( $setting_id == '' ){
			$setting_id = $fs['id'];
		}else{
			$setting_id .= ',' .$fs['id'];
		}
	}
	$setting_id_array = explode(',',$setting_id);
	$setting_id = ',' .$setting_id. ',';
	$querysql=$db->query("Select id From {$dv}fsettings Where s_class=2 Order By c_orders");
	while($fs =& $db->fetch_array($querysql)){
		if ( $ads_id == '' ){
			$ads_id = $fs['id'];
		}else{
			$ads_id .= ',' .$fs['id'];
		}
	}
	$ads_id_array = explode(',',$ads_id);
	$ads_id = ',' .$ads_id. ',';
	while ($arr=$db->fetch_array($sql)){
		$myquery=$db->query("Select title,addtime From {$dv}bbsnews Where boardid={$arr['boardid']} Order By ID Desc",array('pageSize'=>1));
		if($newsinfo =& $db->fetch_array($myquery)){
			$forumnews = str_replace(array('\\', "'"), array('\\\\', "\\'"), $newsinfo['title']);
			$forumnews = '<b>'.$forumnews.'</b> (<span class="runtime_timestamp">'.$newsinfo['addtime'].'</span>)';
		}else{
			$forumnews = '';
		}
		$mysetting_id=( strpos($setting_id,','.$arr['setting_id'].',') !== false )? $arr['setting_id']:$setting_id_array[0];
		$myads_id=( strpos($ads_id,','.$forum['ads_id'].',') !== false )? $forum['ads_id']:$ads_id_array[0];
		if(!empty($arr['parentid'])){
			$boardid = strleach($arr['boardid']);
			$boardtype = strleach($arr['boardtype']);
			$parentid = strleach($arr['parentid']);
			$parentstr = strleach($arr['parentstr']);
			$boardmaster = strleach($arr['boardmaster']);
			$hidden = intval($arr['ishidden']);
			$checkout = intval($arr['ischeckout']);
			$depth = intval($arr['depth']);
			$postnum = intval($arr['postnum']);
			$topicnum = $db->scalar("select count(1) from {$dv}savvy_topic where boardid={$bid}");
			$todaynum = intval($arr['todaynum']);
			$child = $arr['child'];
			if( $taxit == 1 ) {
				$tmpContents = '1';
			} else{
				$contents .= ",\r\n";
			}
			if(!empty($boardid)){
				$contents .= <<<EOT
\t'{$taxit}' => array(
\t\t'savvy_boardid' => '{$boardid}',
\t\t'savvy_boardtype' => '{$boardtype}',
\t\t'savvy_parentid' => '{$parentid}',
\t\t'savvy_parentstr' => '{$parentstr}',
\t\t'savvy_child' => '{$child}',
\t\t'savvy_boardmaster' => '{$boardmaster}',
\t\t'savvy_hidden' => '{$hidden}',
\t\t'savvy_checkout' => '{$checkout}',
\t\t'savvy_depth' => '{$depth}',
\t\t'savvy_forumnews' => '{$forumnews}',
\t\t'savvy_setting_id' => '{$mysetting_id}',
\t\t'savvy_ads_id' => '{$myads_id}',
\t\t'savvy_postnum' => '{$postnum}',
\t\t'savvy_topicnum' => '{$topicnum}',
\t\t'savvy_todaynum' => '{$todaynum}'
\t)
EOT;
			}
		}
	}
	$db->free_result($sql);
	if( empty($contents) ){
		return false;
	}
	else{
		$contents .= "";
	}
	return $contents;
}

function CreateSavvy_BoarderInfo(){
	global $db,$dv,$lang,$savvy_board;
	require_once CACHE_PATH.'savvy_board.php';
	$getallboard=array();
	$getallboard=explode(',',$savvy_board['boardidset']['boardid_set']);
	$i=1;
	$contents.= "<?php\r\n\$savvy_board['boardinfo'] = array(\r\n";
	$tmpcontent='';
	foreach ($getallboard as $getboardarr){
		$tmpcontent.=CreateBoarderInfo($getboardarr,$i);
		$i++;
	}
	$contents.=(substr($tmpcontent,0,1)==',')?substr($tmpcontent,1):$tmpcontent;
	$contents.="\r\n);\r\n\r\n";
	$contents.= dv_GetBoardKey($savvy_board['boardkey']['board_key'],$savvy_board['boardkey']['highsetup'],$savvy_board['boardkey']['sysputintegral'],$savvy_board['boardkey']['prise_integral'],$savvy_board['boardkey']['hiddenname'],$savvy_board['boardkey']['askcount']);
	$contents.="\r\n);\r\n\r\n";
	$contents.= dv_GetBoardid($savvy_board['boardidset']['boardid_set']);
	$contents.="\r\n);\r\n\r\n";
	$contents.= dv_hot_question();// 热门问题
	$contents.="\r\n);\r\n\r\n";
	$contents.= dv_best_question();// 精华问题
	$contents.="\r\n);\r\n\r\n";
	$contents.= savvy_user_weekmoney();// 上周积分排行
	$contents.="\r\n);\r\n\r\n";
	$contents.= dv_Getsetup($savvy_board['setup']['isInsertSavvy']);// 论坛知道开关
	if(empty($contents)){
		return false;
	} else{
		$contents .= "\r\n);\r\n".'?'.'>';
		$currcachefile = CACHE_PATH.'savvy_board.php';
		@chmod($currcachefile,0777);
		return putcachefile($contents, $currcachefile);
	}
}

function dv_GetBoardKey($bkey,$high,$sysput,$prise_num,$hiddennamefen,$askcountstr){
	global $db,$dv,$db;
	$contents .= "\r\n\$savvy_board['boardkey'] = array(\r\n";
	if( $tmpContents == '' ) {
		$tmpContents = '1';
	} else{
		$contents .= ",\r\n";
	}
	$boardkey_contents =strleach($bkey);
	$high=intval($high);
	$highsetup=(empty($high))? 100:intval($high);//高分提问
	$sysput=intval($sysput);
	$sysputintegral=(empty($sysput))? 2:intval($sysput);//系统奖赏回答分
	$prise_num=intval($prise_num);
	$prise_integral=(empty($prise_num))? 2:intval($prise_num);//提高奖赏次数
	$hiddennamefen=intval($hiddennamefen);
	$hiddenname_integral=(empty($hiddennamefen))? 10:intval($hiddennamefen);//匿名提问扣除分
	$askcountstr=intval($askcountstr);
	$askcount_value=(empty($askcountstr))? 3:$askcountstr;//提问次数
	$contents .= <<<EOT
\t\t'board_key' => '{$boardkey_contents}',
\t\t'highsetup' => '{$highsetup}',
\t\t'sysputintegral' => '{$sysputintegral}',
\t\t'prise_integral' => '{$prise_integral}',
\t\t'hiddenname' => '{$hiddenname_integral}',
\t\t'askcount' => '{$askcount_value}'
EOT;
	if( empty($contents) ){
		return false;
	} else{
		$contents .= "\r\n";
	}
	return $contents;
}


function dv_Getsetup($ins){
	global $db,$dv,$db;
	$contents .= "\r\n\$savvy_board['setup'] = array(\r\n";
	if( $tmpContents == '' ) {
		$tmpContents = '1';
	} else{
		$contents .= ",\r\n";
	}
	$forumins=(empty($ins))? '0':$ins;
	$contents .= <<<EOT
\t\t'isInsertSavvy' => '{$forumins}'
EOT;
	if( empty($contents) ){
		return false;
	} else{
		$contents .= "\r\n";
	}
	return $contents;
}


function dv_GetBoardid($bidlist){
	global $db,$dv,$db;
	$contents .= "\r\n\$savvy_board['boardidset'] = array(\r\n";
	if( $tmpContents == '' ) {
		$tmpContents = '1';
	} else{
		$contents .= ",\r\n";
	}
	$contents .= <<<EOT
\t\t'boardid_set' => '{$bidlist}'
EOT;
	if( empty($contents) ){
		return false;
	} else{
		$contents .= "\r\n";
	}
	return $contents;
}


//论坛知道热门问题
//
//
//
function dv_hot_question(){
	global $db,$dv,$lang;
	$usersql=$db->query("select topicid,title,boardid,pollid,locktopic,child,postusername,postuserid,dateandtime,hits,expression,votetotal,lastpost,lastposttime,istop,isvote,isbest,posttable,smsuserlist,issmstopic,lastsmstime,topicmode,mode,getmoney,usetools,getmoneytype,hidename,solve,anonymity,againmoney from {$dv}savvy_topic order by child desc",array('absolutePage'=>0,'pageSize'=>15));
	$contents.= "\r\n\$savvy_board['tmphotinfo'] = array(\r\n";
	$tmpContents='';
	$j=0;
	while ($arrlist=$db->fetch_array($usersql)){
		$userid=$arrlist['postuserid'];
		$username=strleach($arrlist['postusername']);
		$topicid=strleach($arrlist['topicid']);
		$boardid=strleach($arrlist['boardid']);
		$title=strleach($arrlist['title']);
		$dateandtime=strleach($arrlist['dateandtime']);
		$child=strleach($arrlist['child']);
		$j++;
		if( $tmpContents == '' ) {
			$tmpContents = '1';
		} else{
			$contents.= ",\r\n";
		}
		$contents .= <<<EOT
\t'{$j}' => array(
\t\t'userid' => '{$userid}',
\t\t'username' => '{$username}',
\t\t'topicid' => '{$topicid}',
\t\t'boardid' => '{$boardid}',
\t\t'title' => '{$title}',
\t\t'dateandtime' => '{$dateandtime}',
\t\t'child' => '{$child}'
\t)
EOT;
}
$db->free_result($usersql);
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n";
}
return $contents;
}


//论坛知道精华问题
//
//
//
function dv_best_question(){
	global $db,$dv,$lang;
	$usersql=$db->query("select topicid,title,boardid,pollid,locktopic,child,postusername,postuserid,dateandtime,hits,expression,votetotal,lastpost,lastposttime,istop,isvote,isbest,posttable,smsuserlist,issmstopic,lastsmstime,topicmode,mode,getmoney,usetools,getmoneytype,hidename,solve,anonymity,againmoney from {$dv}savvy_topic where isbest=1 order by dateandtime desc",array('absolutePage'=>0,'pageSize'=>15));
	$contents.= "\r\n\$savvy_board['tmpbestinfo'] = array(\r\n";
	$tmpContents='';
	$j=0;
	while ($arrlist=$db->fetch_array($usersql)){
		$userid=$arrlist['postuserid'];
		$username=strleach($arrlist['postusername']);
		$topicid=strleach($arrlist['topicid']);
		$boardid=strleach($arrlist['boardid']);
		$title=strleach($arrlist['title']);
		$dateandtime=strleach($arrlist['dateandtime']);
		$j++;
		if( $tmpContents == '' ) {
			$tmpContents = '1';
		} else{
			$contents.= ",\r\n";
		}
		$contents .= <<<EOT
\t'{$j}' => array(
\t\t'userid' => '{$userid}',
\t\t'username' => '{$username}',
\t\t'topicid' => '{$topicid}',
\t\t'boardid' => '{$boardid}',
\t\t'title' => '{$title}',
\t\t'dateandtime' => '{$dateandtime}'
\t)
EOT;
}
$db->free_result($usersql);
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n";
}
return $contents;
}



//论坛知道用户上周积分排行
//

function savvy_user_weekmoney(){
	global $db,$dv,$lang;
	$front_weekdata=time()-7*24*3600;
	$usersql=$db->query("select id,userid,username,forumid,title,sum(wealth) as wealth,dateandtime,position from {$dv}savvy_wealth where dateandtime > {$front_weekdata} group by userid order by wealth desc",array('absolutePage'=>0,'pageSize'=>10));
	$contents.= "\r\n\$savvy_board['userweekmoney'] = array(\r\n";
	$tmpContents='';
	$j=0;
	while ($arrlist=$db->fetch_array($usersql)){
		$userid=$arrlist['userid'];
		$username=strleach($arrlist['username']);
		$wealth=strleach($arrlist['wealth']);
		$position=strleach($arrlist['position']);
		$dateandtime=strleach($arrlist['dateandtime']);
		$j++;
		if( $tmpContents == '' ) {
			$tmpContents = '1';
		} else{
			$contents.= ",\r\n";
		}
		$contents .= <<<EOT
\t'{$j}' => array(
\t\t'userid' => '{$userid}',
\t\t'username' => '{$username}',
\t\t'wealth' => '{$wealth}',
\t\t'position' => '{$position}',
\t\t'dateandtime' => '{$dateandtime}'
\t)
EOT;
}
$db->free_result($usersql);
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n";
}
return $contents;
}

//------------------------------2007-8-27 IvanSky guesttoday---------------------------------------------
function Create_Forum_guest_info() {

	global $dv,$arrUserToday,$arrguest_info;


	if ($arrguest_info[1] != strtotime(date("Y-m-d")))
	{
		$arrUserToday = array(0,0,0,0,0,strtotime(date("Y-m-d")));
		$getdaynum = 0;
	}else{
		$getdaynum = 1;
	}
	$guesttoday0 = intval($arrUserToday[0])+$getdaynum;//Dvbbs.UserToday(0)
	$guesttoday1 = intval($arrUserToday[1]);
	$guesttoday2 = intval($arrUserToday[2]);
	$guesttoday3 = intval($arrUserToday[3]);
	$guesttoday4 = intval($arrUserToday[4]);
	$guesttodaytime = intval($arrUserToday[5]);

	$guesttoday00 = !empty($guesttoday0) ? $guesttoday0 : 0;
	$guesttoday11 = !empty($guesttoday1) ? $guesttoday1 : 0;
	$guesttoday22 = !empty($guesttoday2) ? $guesttoday2 : 0;
	$guesttoday33 = !empty($guesttoday3) ? $guesttoday3 : 0;
	$guesttoday44 = !empty($guesttoday4) ? $guesttoday4 : 0;
	$guesttodaytime = !empty($guesttodaytime) ? $guesttodaytime : strtotime(date("Y-m-d"));

	$contents.= "<?php\r\n\$Forum_guest_info['guesttoday'] = array(\r\n'";
	$contents.= $guesttoday00."|";
	$contents.= $guesttoday11."|";
	$contents.= $guesttoday22."|";
	$contents.= $guesttoday33."|";
	$contents.= $guesttoday44."'\r\n,'";
	$contents.= $guesttodaytime;

	if( empty($contents) ){
		return false;
	} else{
		$contents .= "'\r\n);\r\n".'?'.'>';

		$currcachefile =CACHE_PATH.'Forum_guest_info_File.php';
		@chmod($currcachefile,0777);
		return putcachefile($contents, $currcachefile);
	}

}

//更新最新个人圈子
function Create_Forum_Group_top_new($groupid,$limits=10){
	global $db,$dv;
	$limits=10;
	!is_numeric($limits)||$limits<1 AND $limits=10;

	if (file_exists(CACHE_PATH.'Forum_Group_top.php')){
		require_once CACHE_PATH.'Forum_Group_top.php';
	}

	if(empty($Forum_group['topnew']))
	$Forum_group['topnew']= array();
	if(empty($Forum_group['topuser']))
	$Forum_group['topuser']= array();
	if(empty($Forum_group['tophots']))
	$Forum_group['tophots']= array();

	$temp= array();

	$groupsql=$db->query("select id as groupid,groupname,groupinfo,appusername,usernum,limituser,appdate,postnum,groupface from {$dv}group_name where id='{$groupid}'");

	if($arrlist=$db->fetch_array($groupsql)){
		$groupid=$arrlist['groupid'];
		$groupname=strleach($arrlist['groupname']);
		$groupinfo=strleach($arrlist['groupinfo']);
		$appusername=strleach($arrlist['appusername']);
		$usernum=intval($arrlist['usernum']);
		$limituser=intval($arrlist['limituser']);
		$appdate= $arrlist['appdate'];
		$postnum=intval($arrlist['postnum']);
		$grouppic=$arrlist['groupface'];
		$temp[1]= array(
		'groupid' => $groupid,
		'groupname' => $groupname,
		'groupinfo' => $groupinfo,
		'appusername' => $appusername,
		'grouppic' => $grouppic,
		'usernum' => $usernum,
		'limituser' => $limituser,
		'appdate' => $appdate,
		'postnum' => $postnum
		);

		for($i=1;($i<=count($Forum_group['topnew']) && $i<$limits);$i++)
		{
			$temp[$i+1]= $Forum_group['topnew'][$i];
		}

		$currcachefile= CACHE_PATH.'Forum_Group_top.php';
		$contents.= "<?php\r\n//最新加入圈子\r\n\$Forum_group['topnew'] = ";
		$contents.= var_export($temp,TRUE);
		$contents.= ";\r\n\r\n//最活跃圈子\r\n\$Forum_group['topuser'] = ";
		$contents.= var_export($Forum_group['topuser'],TRUE);
		$contents.= ";\r\n\r\n//最热门圈子\r\n\$Forum_group['tophots'] = ";
		$contents.= var_export($Forum_group['tophots'],TRUE);
		$contents .= ";\r\n".'?'.'>';

		putcachefile($contents, $currcachefile);

	}
}

//创建最新、最活跃、最热个人圈子
function Create_Forum_Group_top($limits=10){
	global $db,$dv;
	$limits=10;
	!is_numeric($limits)||$limits<1 AND $limits=10;
	$groupsql=$db->query("select id as groupid,groupname,groupinfo,appusername,usernum,limituser,appdate,postnum,groupface from {$dv}group_name order by appdate desc",array('absolutePage'=>0,'pageSize'=>$limits));
	$contents= "<?php\r\n//最新加入圈子\r\n\$Forum_group['topnew'] = array(";
	$tmpContents='';
	$i=0;
	while ($arrlist=$db->fetch_array($groupsql)){
		$groupid=$arrlist['groupid'];
		$groupname=strleach($arrlist['groupname']);
		$groupinfo=strleach($arrlist['groupinfo']);
		$appusername=strleach($arrlist['appusername']);
		$usernum=intval($arrlist['usernum']);
		$limituser=intval($arrlist['limituser']);
		$appdate=$arrlist['appdate'];
		$postnum=intval($arrlist['postnum']);
		$grouppic=$arrlist['groupface'];
		$i++;
		$tmpContents .= <<<EOT
\r\n\t'{$i}' => array(
\t\t'groupid' => '{$groupid}',
\t\t'groupname' => '{$groupname}',
\t\t'groupinfo' => '{$groupinfo}',
\t\t'appusername' => '{$appusername}',
\t\t'grouppic' => '{$grouppic}',
\t\t'usernum' => '{$usernum}',
\t\t'limituser' => '{$limituser}',
\t\t'appdate' => '{$appdate}',
\t\t'postnum' => '{$postnum}'
\t),
EOT;
}
$tmpContents!=='' AND $tmpContents=substr($tmpContents,0,-1);
$contents.=$tmpContents;
$db->free_result($groupsql);
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);";
}

$groupsql=$db->query("select id as groupid,groupname,groupinfo,appusername,usernum,limituser,appdate,postnum,groupface from {$dv}group_name order by usernum desc",array('absolutePage'=>0,'pageSize'=>$limits));
$contents.= "\r\n//最活跃圈子\r\n\$Forum_group['topuser'] = array(";
$tmpContents='';
$i=0;
while ($arrlist=$db->fetch_array($groupsql)){
	$groupid=$arrlist['groupid'];
	$groupname=strleach($arrlist['groupname']);
	$groupinfo=strleach($arrlist['groupinfo']);
	$appusername=strleach($arrlist['appusername']);
	$usernum=intval($arrlist['usernum']);
	$limituser=intval($arrlist['limituser']);
	$appdate=$arrlist['appdate'];
	$postnum=intval($arrlist['postnum']);
	$grouppic=$arrlist['groupface'];
	$i++;
	$tmpContents .= <<<EOT
\r\n\t'{$i}' => array(
\t\t'groupid' => '{$groupid}',
\t\t'groupname' => '{$groupname}',
\t\t'groupinfo' => '{$groupinfo}',
\t\t'appusername' => '{$appusername}',
\t\t'grouppic' => '{$grouppic}',
\t\t'usernum' => '{$usernum}',
\t\t'limituser' => '{$limituser}',
\t\t'appdate' => '{$appdate}',
\t\t'postnum' => '{$postnum}'
\t),
EOT;
}

$tmpContents!=='' AND $tmpContents=substr($tmpContents,0,-1);
$contents.=$tmpContents;
$db->free_result($groupsql);
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);";
}

$groupsql=$db->query("select id as groupid,groupname,groupinfo,appusername,usernum,limituser,appdate,postnum,groupface from {$dv}group_name order by postnum desc",array('absolutePage'=>0,'pageSize'=>$limits));
$contents.= "\r\n//最热门圈子\r\n\$Forum_group['tophots'] = array(";
$tmpContents='';
$i=0;
while ($arrlist=$db->fetch_array($groupsql)){
	$groupid=$arrlist['groupid'];
	$groupname=strleach($arrlist['groupname']);
	$groupinfo=strleach($arrlist['groupinfo']);
	$appusername=strleach($arrlist['appusername']);
	$usernum=intval($arrlist['usernum']);
	$limituser=intval($arrlist['limituser']);
	$appdate=$arrlist['appdate'];
	$postnum=intval($arrlist['postnum']);
	$grouppic=$arrlist['groupface'];
	$i++;
	$tmpContents .= <<<EOT
\r\n\t'{$i}' => array(
\t\t'groupid' => '{$groupid}',
\t\t'groupname' => '{$groupname}',
\t\t'groupinfo' => '{$groupinfo}',
\t\t'appusername' => '{$appusername}',
\t\t'grouppic' => '{$grouppic}',
\t\t'usernum' => '{$usernum}',
\t\t'limituser' => '{$limituser}',
\t\t'appdate' => '{$appdate}',
\t\t'postnum' => '{$postnum}'
\t),
EOT;
}
$tmpContents!=='' AND $tmpContents=substr($tmpContents,0,-1);
$contents.=$tmpContents;
$db->free_result($groupsql);
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n";
}

$contents .= ")\r\n".'?'.'>';
$currcachefile =CACHE_PATH.'Forum_Group_top.php';
@chmod($currcachefile,0777);
return putcachefile($contents, $currcachefile);
}

//更新圈子昨日/今日帖子数
function update_group_all(){
	global $dv,$db;
	$time1 = strtotime(date('Y-m-d 00:00:00'));
	$time2 = $time1 + (24*3600 - 1);
	$time3 = $time1 - (24*3600);
	$time4 = $time1 - 1;

	$db->query("update {$dv}group_name set yesterdaynum=0,todaynum=0");
	$db->query("update {$dv}group_board set todaynum=0");

	//更新今日贴子数
	$SQL = "Select count(1) todaynum,boardid From {$dv}group_bbs1 Where (dateandtime between ".$time1." and ".$time2.") group by boardid";
	$query=$db->query($SQL);
	while ($arr=$db->fetch_array($query)){
		$db->query("UPDATE {$dv}group_board SET todaynum=".$arr["todaynum"]." Where id=".$arr["boardid"]."");
	}
	$SQL = "Select sum(todaynum) todaynum,rootid From {$dv}group_board group by rootid";
	$query=$db->query($SQL);
	while ($arr=$db->fetch_array($query)){
		$db->query("UPDATE {$dv}group_name SET todaynum=".$arr["todaynum"]." Where id=".$arr["rootid"]."");
	}

	//更新昨日贴子数
	$SQL = "Select count(1) yesterdaynum,groupid From {$dv}group_bbs1 Where (dateandtime between ".$time3." and ".$time4.") group by groupid";
	$query=$db->query($SQL);
	while ($arr=$db->fetch_array($query)){
		$db->query("UPDATE {$dv}group_name SET yesterdaynum=".$arr["yesterdaynum"]." Where id=".$arr["groupid"]."");
	}
}

function del_static_cache(){
	$dirName= CACHE_PATH.'static';
	if(empty($dirName)) {
		return;
	}
	if(file_exists($dirName)) {
		$dir = dir($dirName);
		while($file = $dir->read()) {
			if($file != '.' && $file != '..') {
				if(is_dir($dirName.'/'.$file)) {
					delDir($dirName.'/'.$file);
				}
				else {
					@unlink($dirName.'/'.$file);
				}
			}
		}
	}
}

//------------------------------edit 2007-12-28  DownLoad_benefit---------------------------------------------
function Create_Forum_DownLoad_benefit() {

	global $dv,$do_action,$strDB_id,$DB_boardid,$strDB_File,$strDB_File_type,$DB_width,$DB_height,$DB_second,$DB_starttime,$DB_endtime,$DB_close,$DB_File_type,$arrDownLoad_benefit,$DB_dot,$DB_name,$DB_HTML,$DB_linkurl,$arrDB_del_id,$DB_type,$DB_groupid;

	$DB_linkurl = preg_match('/^http:\/\//', $DB_linkurl) ? $DB_linkurl : 'http://'.$DB_linkurl;
	if (false!==strpos($DB_HTML,'[/imgTmp]')){
		$DB_HTML=preg_replace('/\[imgTmp=(.*?)\](.*?)\[\/imgTmp\]/','[img=$1]'.$strDB_File.'[/img]',$DB_HTML);
	}
	if (false!==strpos($DB_HTML,'[/flashTmp]')){
		$DB_HTML=preg_replace('/\[flashTmp=(.*?)\](.*?)\[\/flashTmp\]/','[flash=$1]'.$strDB_File.'[/flash]',$DB_HTML);
	}
	$DB_HTML=    str_r($DB_HTML);

	if ( $do_action!='del')
	{
		$DB_starttime=strtotime($DB_starttime)+date('Z');
		$DB_endtime=  strtotime($DB_endtime)+date('Z');
		$DB_dot = empty($DB_dot) ? 0 :$DB_dot;
		$contents.= "<?php\r\n\$Forum_DownLoad_benefit['DownLoad_benefit'] = array(\r\n";
		if ( count($arrDownLoad_benefit) > 0 )
		{
			$i=1;
			$tmpContents1='';
			foreach ($arrDownLoad_benefit as $k => $v)
			{

				if( $tmpContents1 == '' ) {
					$tmpContents1 = '1';
				} else{
					$contents.= ",";
				}
				$contents .= <<<EOT
				\t\t\n'{$i}' => array(
EOT;

				if ( $do_action=='edit' and $strDB_id == $i )
				{
					$contents .= <<<EOT
		\n\t\t'DB_id' => '{$i}',
		'DB_boardid' => '{$DB_boardid}',
		'DB_type' => '{$DB_type}',
		'DB_groupid' => '{$DB_groupid}',
		'DB_name' => '{$DB_name}',
		'DB_linkurl' => '{$DB_linkurl}',
		'DB_File' => '{$strDB_File}',
		'DB_HTML' => '{$DB_HTML}',
		'DB_File_type' => '{$strDB_File_type}',
		'DB_width' => '{$DB_width}',
		'DB_height' => '{$DB_height}',
		'DB_second' => '{$DB_second}',
		'DB_starttime' => '{$DB_starttime}',
		'DB_endtime' => '{$DB_endtime}',
		'DB_dot' => '{$DB_dot}',						
		'DB_close' => '{$DB_close}'
EOT;
				}


$ii=1;
$tmpContents2='';
foreach ($v as $kk => $vv)
{
	$vv = ($tmpContents2=='') ? $i : $vv;
	if( $tmpContents2 == '' ) {
		$tmpContents2 = '1';
	} else if ( $strDB_id != $i){
		$contents.= ",";
	}
	if (($do_action=='save') or ($do_action=='edit' and $strDB_id != $i) )
	{
		$contents .= <<<EOT
					\t\t\n\t\t'{$kk}' => '{$vv}'
EOT;
	}

$ii=$ii+1;
}
$contents .= <<<EOT
			\n\t)
EOT;
$i=$i+1;
			}
			$strDB_id =$i;
		}else{
			$strDB_id = 1;
		}

		if ($do_action=="save")
		{
			if ($ii>1)$contents.= ",";
			$contents .= <<<EOT
		\n\t'{$strDB_id}' => array(
		'DB_id' => '{$strDB_id}',
		'DB_boardid' => '{$DB_boardid}',
		'DB_type' => '{$DB_type}',
		'DB_groupid' => '{$DB_groupid}',
		'DB_name' => '{$DB_name}',
		'DB_linkurl' => '{$DB_linkurl}',
		'DB_File' => '{$strDB_File}',
		'DB_HTML' => '{$DB_HTML}',
		'DB_File_type' => '{$strDB_File_type}',
		'DB_width' => '{$DB_width}',
		'DB_height' => '{$DB_height}',
		'DB_second' => '{$DB_second}',
		'DB_starttime' => '{$DB_starttime}',
		'DB_endtime' => '{$DB_endtime}',
		'DB_dot' => '0',
		'DB_close' => '{$DB_close}'
		\n\t)
EOT;
}
	}
	else
	{
		if ( count($arrDB_del_id) > 0 )
		{

			foreach ( $arrDB_del_id as $v )
			{
				$delDB_File_Name = $arrDownLoad_benefit[$v][DB_File];
				if (!empty($delDB_File_Name))
				{
					if (file_exists('..'.$delDB_File_Name))
					{
						@chmod('..'.$delDB_File_Name,0777);
						@unlink('..'.$delDB_File_Name);
					}
				}

				if (!empty($v))
				unset($arrDownLoad_benefit[$v]);

			}
		}
		$contents.= "<?php\r\n\$Forum_DownLoad_benefit['DownLoad_benefit'] = ";
		$contents.=var_export($arrDownLoad_benefit,TRUE);
		$contents .= "\r\n".'?'.'>';

	}

	if( empty($contents) ){
		return false;
	} else{
		if ($do_action!="del")
		$contents .= "\r\n);\r\n".'?'.'>';
		$currcachefile =CACHE_PATH.'Forum_DownLoad_benefit_File.php';
		@chmod($currcachefile,0777);
		return putcachefile($contents, $currcachefile);
	}
}

//------------------------------2007-9-2 IvanSky DownLoad_benefit---------------------------------------------
function dotDegree_Forum_DownLoad_benefit($dotCount,$dotDB_id,$arrDownLoad_benefit) {

	if (is_numeric($dotCount) and is_numeric($dotDB_id) )
	{
		if (is_array($arrDownLoad_benefit[$dotDB_id]))
		{

			$dotDB_dot = $arrDownLoad_benefit[$dotDB_id]['DB_dot']+$dotCount;
			$arrDownLoad_benefit[$dotDB_id]['DB_dot'] = $dotDB_dot;
			$contents.= "<?php\r\n\$Forum_DownLoad_benefit['DownLoad_benefit'] = ";
			$contents.=var_export($arrDownLoad_benefit,TRUE);
			$contents .= "\r\n".'?'.'>';
		}
	}

	if( empty($contents) ){
		return false;
	} else{
		$currcachefile =CACHE_PATH.'Forum_DownLoad_benefit_File.php';
		@chmod($currcachefile,0777);
		return putcachefile($contents, $currcachefile);
	}

}
//------------------------------2007-9-3 IvanSky DownLoad_benefit---------------------------------------------

function StartClose_Forum_DownLoad_benefit() {
	global $setDB_Close,$setDB_id,$arrDownLoad_benefit;

	if ( is_numeric($setDB_Close) and is_numeric($setDB_id) )
	{
		if (is_array($arrDownLoad_benefit[$setDB_id]))
		{
			$getDB_Close = ($setDB_Close==1)?2:1;
			$arrDownLoad_benefit[$setDB_id]['DB_close'] = $getDB_Close;
			$contents.= "<?php\r\n\$Forum_DownLoad_benefit['DownLoad_benefit'] = ";
			$contents.=var_export($arrDownLoad_benefit,TRUE);
			$contents .= "\r\n".'?'.'>';
		}
	}
	if( empty($contents) ){
		return false;
	} else{
		$currcachefile =CACHE_PATH.'Forum_DownLoad_benefit_File.php';
		@chmod($currcachefile,0777);
		return putcachefile($contents, $currcachefile);
	}
}

function StartClose_Index_Right_Ads() {
	global $setDB_Close,$setDB_id,$arrIndex_Ads;

	if ( is_numeric($setDB_Close) and is_numeric($setDB_id) )
	{
		if (is_array($arrIndex_Ads[$setDB_id]))
		{
			$getDB_Close = ($setDB_Close==1)?0:1;
			$arrIndex_Ads[$setDB_id]['DB_close'] = $getDB_Close;
			$contents.= "<?php\r\n\$index_right_ads['setting'] = ";
			$contents.=var_export($arrIndex_Ads,TRUE);
			$contents .= "\r\n".'?'.'>';
		}
	}
	if( empty($contents) ){
		return false;
	} else{
		$currcachefile =CACHE_PATH.'index_right_ads_file.php';
		@chmod($currcachefile,0777);
		return putcachefile($contents, $currcachefile);
	}
}//end function StartClose_Index_Right_Ads

function Create_Index_Right_Ads() {

	global $dv,$do_action,$strDB_id,$DB_boardid,$strDB_File,$strDB_File_type,$DB_width,$DB_height,$DB_close,$DB_File_type,$arrIndex_Ads,$DB_dot,$DB_name,$DB_linkurl,$arrDB_del_id;

	$DB_linkurl = preg_match('/^http:\/\//', $DB_linkurl) ? $DB_linkurl : 'http://'.$DB_linkurl;

	if ( $do_action!='del')
	{
		$DB_dot = empty($DB_dot) ? 0 :$DB_dot;
		$contents.= "<?php\r\n\$index_right_ads['setting'] = array(\r\n";
		if ( count($arrIndex_Ads) > 0 )
		{
			$i=1;
			$tmpContents1='';
			foreach ($arrIndex_Ads as $k => $v)
			{

				if( $tmpContents1 == '' ) {
					$tmpContents1 = '1';
				} else{
					$contents.= ",";
				}
				$contents .= <<<EOT
				\t\t\n'{$i}' => array(
EOT;

				if ( $do_action=='edit' and $strDB_id == $i )
				{
					$contents .= <<<EOT
		\n\t\t'DB_id' => '{$i}',
		'DB_boardid' => '{$DB_boardid}',
		'DB_name' => '{$DB_name}',
		'DB_linkurl' => '{$DB_linkurl}',
		'DB_File' => '{$strDB_File}',
		'DB_File_type' => '{$strDB_File_type}',
		'DB_width' => '{$DB_width}',
		'DB_height' => '{$DB_height}',
		'DB_dot' => '{$DB_dot}',						
		'DB_close' => '{$DB_close}'
EOT;
}
$ii=1;
$tmpContents2='';
foreach ($v as $kk => $vv)
{
	$vv = ($tmpContents2=='') ? $i : $vv;
	if( $tmpContents2 == '' ) {
		$tmpContents2 = '1';
	} else if ( $strDB_id != $i){
		$contents.= ",";
	}
	if (($do_action=='save') or ($do_action=='edit' and $strDB_id != $i) )
	{
		$contents .= <<<EOT
					\t\t\n\t\t'{$kk}' => '{$vv}'
EOT;
}
$ii=$ii+1;
}
$contents .= <<<EOT
			\n\t)
EOT;
$i=$i+1;
}

$strDB_id =$i;
}else{
	$strDB_id = 1;
}

if ($do_action=="save")
{
	if ($ii>1)$contents.= ",";
	$contents .= <<<EOT
		\n\t'{$strDB_id}' => array(
		'DB_id' => '{$strDB_id}',
		'DB_boardid' => '{$DB_boardid}',
		'DB_name' => '{$DB_name}',
		'DB_linkurl' => '{$DB_linkurl}',
		'DB_File' => '{$strDB_File}',
		'DB_File_type' => '{$strDB_File_type}',
		'DB_width' => '{$DB_width}',
		'DB_height' => '{$DB_height}',
		'DB_dot' => '0',
		'DB_close' => '{$DB_close}'
		\n\t)
EOT;
}



}
else
{
	if ( count($arrDB_del_id) > 0 )
	{

		foreach ( $arrDB_del_id as $v )
		{
			$delDB_File_Name = $arrIndex_Ads[$v][DB_File];
			if (!empty($delDB_File_Name))
			{
				if (file_exists('..'.$delDB_File_Name))
				{
					@chmod('..'.$delDB_File_Name,0777);
					@unlink('..'.$delDB_File_Name);
				}
			}

			if (!empty($v))
			unset($arrIndex_Ads[$v]);

		}
	}
	$contents.= "<?php\r\n\$index_right_ads['setting'] = ";
	$contents.=var_export($arrIndex_Ads,TRUE);
	$contents .= "\r\n".'?'.'>';

}

if( empty($contents) ){
	return false;
} else{
	if ($do_action!="del")
	$contents .= "\r\n);\r\n".'?'.'>';
	$currcachefile =CACHE_PATH.'index_right_ads_file.php';
	@chmod($currcachefile,0777);
	return putcachefile($contents, $currcachefile);
}
}//end function Create_Index_Right_Ads


function getForumTopic($mode){//获取原有的最新贴子9条数据;
	global $ForumTopicList;
	require_once CACHE_PATH.'Forum_Topic_list.php';
	$getForumcontents='';
	$tmpContents='';

	if($mode != 3){
		$i=0;
		$topicnum=count($ForumTopicList['new']);
		foreach ($ForumTopicList['new'] as $newtopic){
			$id=$newtopic['id'];
			$boardid=$newtopic['boardid'];
			$hits=$hottopic['hits'];
			$child=strleach($besttopic['child']);
			$title=strleach($newtopic['title']);
			$dateandtime=$newtopic['dateandtime'];
			$i++;
			if($i==1){
				$i=2;
			}
			$tmpContents .= <<<EOT
\r\n\t'{$i}' => array(
\t\t'id' => '{$id}',
\t\t'boardid' => '{$boardid}',
\t\t'title' => '{$title}',
\t\t'hits' => '{$hits}',
\t\t'child' => '{$child}',
\t\t'dateandtime' => '{$dateandtime}'
\t),
EOT;
			if($topicnum==10){
				if($i==10){
					break;
				}
			}
		}
	}
	$getForumcontents.=$tmpContents."\r\n);\r\n";

	$getForumcontents.= "\r\n\$ForumTopicList['tophits'] = array(";//最热贴子
	$tmpContents='';
	$i=0;
	foreach ($ForumTopicList['tophits'] as $hottopic){
		$id=$hottopic['id'];
		$boardid=$hottopic['boardid'];
		$hits=$hottopic['hits'];
		$child=strleach($besttopic['child']);
		$title=strleach($hottopic['title']);
		$dateandtime=$hottopic['dateandtime'];
		$i++;
		$tmpContents .= <<<EOT
\r\n\t'{$i}' => array(
\t\t'id' => '{$id}',
\t\t'boardid' => '{$boardid}',
\t\t'hits' => '{$hits}',
\t\t'child' => '{$child}',
\t\t'title' => '{$title}',
\t\t'dateandtime' => '{$dateandtime}'
\t),
EOT;
}
$getForumcontents.=$tmpContents."\r\n);\r\n";
$getForumcontents.= "\r\n\$ForumTopicList['best'] = array(";//精华帖子
$tmpContents='';
$i=0;
foreach ($ForumTopicList['best'] as $besttopic){
	$id=$besttopic['id'];
	$boardid=$besttopic['boardid'];
	$hits=$hottopic['hits'];
	$child=strleach($besttopic['child']);
	$title=strleach($besttopic['title']);
	$dateandtime=$besttopic['dateandtime'];
	$i++;
	$tmpContents .= <<<EOT
\r\n\t'{$i}' => array(
\t\t'id' => '{$id}',
\t\t'boardid' => '{$boardid}',
\t\t'hits' => '{$hits}',
\t\t'child' => '{$child}',
\t\t'title' => '{$title}',
\t\t'dateandtime' => '{$dateandtime}'
\t),
EOT;
}
$getForumcontents.=$tmpContents;
return $getForumcontents;
}

//创建贴子列表
function Create_Forum_Topic_List($postnew,$postid) {
	global $dv,$db;
	if($postid==''){
		if($postnew == 1)
		$sql=$db->query("select topicid as id,boardid,title,dateandtime,hits,child from {$dv}topic where boardid not in(444,777) order by dateandtime desc",array('absolutePage'=>0,'pageSize'=>1));
		else
		$sql=$db->query("select topicid as id,boardid,title,dateandtime,hits,child from {$dv}topic where boardid not in(444,777) order by dateandtime desc",array('absolutePage'=>0,'pageSize'=>10));
	}
	else{
		$sql=$db->query("select topicid as id,boardid,title,dateandtime,hits,child from {$dv}topic where boardid not in(444,777) and topicid={$postid}");
	}
	if($sql){
		$contents.= "<?php\r\n\$ForumTopicList['new'] = array(";//最新贴子
		$tmpContents='';
		$i=0;
		while ($arr=$db->fetch_array($sql)){
			$id=$arr['id'];
			$boardid=$arr['boardid'];
			$hits=strleach($arr['hits']);
			$child=strleach($arr['child']);
			$title=strleach($arr['title']);
			$dateandtime=$arr['dateandtime'];
			$i++;
			$tmpContents .= <<<EOT
\r\n\t'{$i}' => array(
\t\t'id' => '{$id}',
\t\t'boardid' => '{$boardid}',
\t\t'hits' => '{$hits}',
\t\t'child' => '{$child}',
\t\t'title' => '{$title}',
\t\t'dateandtime' => '{$dateandtime}'
\t),
EOT;
}
$db->free_result($sql);
}
if(($postnew==1) || ($postnew==3)){
	$contents.=$tmpContents.getForumTopic($postnew);
	if( empty($contents) ){
		return false;
	} else{
		$contents .= "\r\n);\r\n".'?'.'>';
		$currcachefile =CACHE_PATH.'Forum_Topic_list.php';
		return putcachefile($contents, $currcachefile);
	}
}
else{
	$contents.=$tmpContents."\r\n);\r\n";
}

if($sql=$db->query("select topicid as id,boardid,title,hits,dateandtime,child from {$dv}topic where boardid not in(444,777) order by hits desc",array('absolutePage'=>0,'pageSize'=>10))){
	$contents.= "\r\n\$ForumTopicList['tophits'] = array(";//最热贴子
	$tmpContents='';
	$i=0;
	while ($arr=$db->fetch_array($sql)){
		$id=$arr['id'];
		$boardid=$arr['boardid'];
		$hits=strleach($arr['hits']);
		$child=strleach($arr['child']);
		$title=strleach($arr['title']);
		$dateandtime=$arr['dateandtime'];
		$i++;
		$tmpContents .= <<<EOT
\r\n\t'{$i}' => array(
\t\t'id' => '{$id}',
\t\t'boardid' => '{$boardid}',
\t\t'hits' => '{$hits}',
\t\t'child' => '{$child}',
\t\t'title' => '{$title}',
\t\t'dateandtime' => '{$dateandtime}'
\t),
EOT;
}
$db->free_result($sql);
}
$tmpContents!=='' AND $tmpContents=substr($tmpContents,0,-1);
$contents.=$tmpContents."\r\n);\r\n";

if($sql=$db->query("select topicid as id,boardid,title,child,dateandtime,hits from {$dv}topic where isbest=1 and boardid not in(444,777) order by child desc",array('absolutePage'=>0,'pageSize'=>10))){
	$contents.= "\r\n\$ForumTopicList['best'] = array(";//精华帖子
	$tmpContents='';
	$i=0;
	while ($arr=$db->fetch_array($sql)){
		$id=$arr['id'];
		$boardid=$arr['boardid'];
		$child=strleach($arr['child']);
		$hits=strleach($arr['hits']);
		$title=strleach($arr['title']);
		$dateandtime=$arr['dateandtime'];
		$i++;
		$tmpContents .= <<<EOT
\r\n\t'{$i}' => array(
\t\t'id' => '{$id}',
\t\t'boardid' => '{$boardid}',
\t\t'hits' => '{$hits}',
\t\t'child' => '{$child}',
\t\t'title' => '{$title}',
\t\t'dateandtime' => '{$dateandtime}'
\t),
EOT;
}
$db->free_result($sql);
}
$tmpContents!=='' AND $tmpContents=substr($tmpContents,0,-1);
$contents.=$tmpContents;
if( empty($contents) ){
	return false;
} else{
	$contents .= "\r\n);\r\n".'?'.'>';
	$currcachefile =CACHE_PATH.'Forum_Topic_list.php';
	return putcachefile($contents, $currcachefile);
}
}


function Create_online_boardmaster() {
	global $dv,$db;
	if($sql=$db->query("select id,username,userclass,stats,ip,actforip,startime,lastimebk,boardid,browser,usergroupid,actcome,userhidden,userid from {$dv}online where usergroupid in (1,2,3) order by startime desc")){
		$contents.= "<?php\r\n\$boardmaster_online['online'] = array(\r\n";
		$tmpContents='';
		$i=0;
		while ($arr=$db->fetch_array($sql)){
			$i++;
			$id=$arr['id'];
			$userid=$arr['userid'];
			$boardid=$arr['boardid'];
			$usergroupid=$arr['usergroupid'];
			$username=strleach($arr['username']);
			if( $tmpContents == '' ) {
				$tmpContents = '1';
			} else{
				$contents.= ",\r\n";
			}
			$contents .= <<<EOT
	\t'{$i}' => array(
	\t\t'id' => '{$id}',
	\t\t'userid' => '{$userid}',
	\t\t'boardid' => '{$boardid}',
	\t\t'usergroupid' => '{$usergroupid}',
	\t\t'username' => '{$username}'
	\t)
EOT;
		}
	$db->free_result($sql);
	}
	if( empty($contents) ){
		return false;
	}
	else{
		$contents .= "\r\n);\r\n".'?'.'>';
		$currcachefile =CACHE_PATH.'Create_online_boardmaster.php';
		return putcachefile($contents, $currcachefile);
	}
}
?>