<?
/**
 * ����ģ�����.
 *
 * ���������ģ�飬�������κ�ʵ������Ĵ���
 * @author       Peak Jing       
 * @version      1.0
 * @copyright    BlogBus.com
 * @access       public
 */
class FastTemplate {


	/**
	 * ���ڴ����ģ���ļ��б�
	 * @access    private
	 */
	var $arrFileList = array();

	/**
	 * �����ֵĴ�����Ϣ
	 * @access    private
	 */
	var $strError = "";

	/**
	 * ģ���Ƿ����
	 * @access    private
	 */
	var $arrLoaded = array();
        
	/**
	 * �������
	 * @access    private
	 */
	var $arrHandle = array();

	/**
	 * �������ı��
	 * @access    private
	 */
	var $strLast = "";

	/**
	 * ���ݱ�Ǻ�ֵ
	 * @access    private
	 */
	var $arrParseVars = array();

	/**
	 * ģ�建���ļ����·��
	 * @access    private
	 */
	var $intTSID;


	/**
	 * ģ������
	 * @access    private
	 */
	var $charTemplateType = "P";


	/**
	 * ���ݿ����ʵ��
	 * @access    private
	 */
	var $objDB;


	/**
	 * ģ�弯��֤��ʶ
	 * @access    private
	 */
	var $arrTSID = array();

	/**
	 * ģ�弯��Ϣ
	 * @access    private
	 */
	var $arrTSData = array();

	/**
	 * ģ����֤��ʶ
	 * @access    private
	 */
	var $arrTemplates = array();

	/**
	 * ģ����֤��ʶ
	 * @access    private
	 */
	var $arrTemplateContent = array();

	/**
	 * ģ�弯����
	 * @access    private
	 */
	var $strTableTS;

	/**
	 * ģ�����
	 * @access    private
	 */
	var $strTableTemplate;


	/**
	 * ��ǰ������ģ�弯
	 * @access    private
	 */
	var $intTemplateSet;


	/**
	 * δ֪���
	 * @access    private
	 */
	var $arrUnknowns;




		
	/**
	 * ���췽�� 
	 *
	 * Detail description
	 * @param      string $_strPathToTemplates : ����ѡ�ģ�ģ���ļ����Ŀ¼
	 * @global     string $php_errormsg : PHPϵͳ������Ϣ
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-8-31 18:28
	*/
	function FastTemplate () {

		$this->objDB            = $GLOBALS["PEAK"]["SO"]->createObject("DataBase");
		$this->strTableTS       = $GLOBALS["PEAK"]["SO"]->getTableName("TemplateSet");
		$this->strTableTemplate = $GLOBALS["PEAK"]["SO"]->getTableName("Templates");
	}

	/**
	 * �����Լ�. 
	 *
	 * Detail description
	 * @param      none
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-8-17 21:16
	*/
	function checkMe(){
		if ($this->objDB->checkMe()) {
			return TRUE;
		}else{
			return FALSE;
		}
	} // end checkMe


	/**
	 * ����ѽ�����ģ������
	 *
	 * Detail description
	 * @param      string $__strReturnVar : (Optional)����
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function clearParse ( $_strReturnVar = "") {
		$this->clear($_strReturnVar);
	} // end clearParse


	
	/**
	 * �������
	 *
	 * Detail description
	 * @param      object $__objReturnVar : (Optional)����
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function clear($_objReturnVar = "") {
		
		// Clears out hash created by call to parse()
		if(!empty($_objReturnVar)) {
			if( (gettype($_objReturnVar)) != "array") {
				unset($this->$_objReturnVar);
				return;
			}else{
				while ( list ($__strKey,$__objVal) = each ($_objReturnVar) ) {
					unset($this->$__objVal);
				}
				return;
			}
		}
		
		// Empty - clear all of them
		while ( list ( $__strKey,$__objVal) = each ($this->arrHandle) ) {
			$__strKEY = $__strKey;
			unset($this->$__strKEY);
		}
		
		return;
	}   //  end clear()
        

	
	/**
	 * �����������
	 *
	 * Detail description
	 * @param      none
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function clearAll (){

		$this->clear();
		$this->clearAssign();
		$this->clearDefine();
		$this->clearTemplate();
 		//$this->clearDynamic();
       return;
	}   //  end clearAll



	/**
	 * ���ģ��
	 *
	 * Detail description
	 * @param      object $_objTemplate : (Optional)ģ���ļ�����
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
    function clearTemplate ($_objTemplate = "") {

        if(empty($this->arrLoaded)) {
			// Nothing loaded, nothing to clear
			return true;
		}
		
		if(empty($_objTemplate)) {

			// Clear ALL templates
			while ( list ($key, $val) = each ($this->arrLoaded) ) {
				unset($this->$key);
			}
			unset($this->arrLoaded);
			
			return true;
		} else {
			if( (gettype($_objTemplate)) != "array") {
				if( (isset($this->$_objTemplate)) || (!empty($this->$_objTemplate)) ) {
					unset($this->arrLoaded[$_objTemplate]);
					unset($this->$_objTemplate);
					return true;
				}
			} else {
				while ( list ($__strKey, $__tmpVal) = each ($_objTemplate) ) {
					unset($this->arrLoaded[$__strKey]);
					unset($this->$__strKey);
				}
				return true;
			}
		}
		
		return false;
	}   // end clearTemplate


	
	/**
	 * ����ļ�������
	 *
	 * Detail description
	 * @param      object $_objTag : (Optional)�ļ����б�
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function clearDefine($_objTag = "") {
		
		if(empty($_objTag)) {
			unset($this->arrFileList);
			return;
		}
		
		// Peak Jing :: ԭ��������
		if( (gettype($_objTag)) != "array") {
			unset($this->arrFileList[$_objTag]);
			return;
		} else {
			while ( list ( $__strTag, $__tmpVal) = each ($_objTag) ) {
				unset($this->arrFileList[$__strTag]);
			}
			return;
		}
	} // end clearDefine



	/**
	 * �������ģ����
	 *
	 * Detail description
	 * @param      none
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function clearAssign () {
		if(!(empty($this->arrParseVars))) {

			while(list($__strRef,$__tmpVal) = each ($this->arrParseVars) ) {
				unset($this->arrParseVars["$__strRef"]);
			}
		}
	}


	
	/**
	 * ���ָ��ģ����
	 *
	 * Detail description
	 * @param      object $_objHref : Ҫ���������
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function clearHref ($_objHref){
		
		if(!empty($_objHref)) {
			if( (gettype($_objHref)) != "array") {
				unset($this->arrParseVars[$_objHref]);
				return;
			} else {
				while (list ($__strRef,$__tmpVal) = each ($_objHref) ) {
					unset($this->arrParseVars[$__strRef]);
				}
				return;
			}
		} else {
			// Empty - clear them all
			$this->clearAssign();
		}
		return;
	}




	/**
	 * ȡ�ñ�����ı��
	 *
	 * Detail description
	 * @param      string $_strFT
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function getAssigned($_strFT = ""){
		if(empty($_strFT)) { 
			return false;
		}

		if(isset($this->arrParseVars["$_strFT"])) {
			return ($this->arrParseVars["$_strFT"]);
		} else {
			return false;
		}
	}



	/**
	 * ���沢��ʾ����
	 *
	 * Detail description
	 * @param      string $_strErrorMsg
	 * @param      int $_isDie
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function error ($_strErrorMsg, $_isDie = 0){
		$this->strError = $_strErrorMsg;
		echo "ERROR: $this->strError <BR> \n";
		
		if ($_isDie == 1) {
			exit;
		}
		
		return;
		
	} // end error()
 


	/**
	 * ��ʾ������Ϣ
	 *
	 * Detail description
	 * @param      array $_arrArray
	 * @param      string $_strCaption
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function printArray($_arrArray , $_strCaption){

		if (count($_arrArray) != 0){
			print "_debug_console.document.write('<font face=Tahoma color=#0000FF size=2><strong>$_strCaption</strong> </font>');\n";
			print "_debug_console.document.write(\"<table border=0 width=100%  cellspacing=1 cellpadding=2>\");";
			print "_debug_console.document.write('<tr bgcolor=#CCCCCC><th>key</th><th>value</th></tr>');\n ";
			
			$__booleanFlag = true;
			while ( list ($__strKey , $__strVal) = each ($_arrArray) ){
				$__booleanFlag = !$__booleanFlag;
				$__strVal = htmlspecialchars(mysql_escape_string ($__strVal));
				if (!$__booleanFlag) {
					$__strColor ="#EEFFEE";
				}else{
					$__strColor ="#EFEFEF";
				}
				
				print "_debug_console.document.write('<tr bgcolor=$__strColor><td> $__strKey</td><td valign=bottom><pre>$__strVal</pre></td></tr>');\n ";
			}
			print "_debug_console.document.write(\"</table>\");";
		}
	} 

	/**
	 * ����ģ�弯
	 *
	 * Detail description
	 * @param      integer $_intTSID : ģ�弯ID
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function setTSID($_intTSID) {
		if (array_key_exists($_intTSID,$this->arrTSID)) {
		    return true;
		}else{
			$this->objDB->query("select TSID,TSName,Description,Type,Owner,Status from ".$this->strTableTS." where Type='".$this->charTemplateType."' and TSID='".$_intTSID."' and Status=1");
			if ($this->objDB->nextRecord()) {

				$this->arrTSID[$_intTSID] = true;
				$this->intTemplateSet = $_intTSID;

				$this->arrTSData[$_intTSID]["Name"]        = $this->objDB->f("TSName");
				$this->arrTSData[$_intTSID]["Description"] = $this->objDB->f("Description");
				$this->arrTSData[$_intTSID]["Type"]        = $this->objDB->f("Type");
				$this->arrTSData[$_intTSID]["Owner"]       = $this->objDB->f("Owner");
				$this->arrTSData[$_intTSID]["Status"]      = $this->objDB->f("Status");
				if ($this->getTemplateCachePath($_intTSID)) {
					return true;
				}else{
					return false;
				}
			}else{
				return false;
			}
		}
		
    }   // End setTSID()


	/**
	 * ����ģ�弯
	 *
	 * Detail description
	 * @param      integer $_intTSID : ģ�弯ID
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function getTSData($_intTSID, $_strKey = "") {
		if ($this->setTSID($_intTSID)) {
			if (empty($_strKey)) {
			    return $this->arrTSData[$_intTSID];
			}else{
			    return $this->arrTSData[$_intTSID][$_strKey];
			}
		}else{
			return false;
		}
    }   // End getTemplateSet()

	
	/**
	 * ����ģ�弯
	 *
	 * Detail description
	 * @param      integer $_intTSID : ģ�弯ID
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function getTemplateSet() {
		return 	$this->intTemplateSet;	
    }   // End getTemplateSet()


	/**
	 * ����ģ�弯
	 *
	 * Detail description
	 * @param      integer $_intTSID : ģ�弯ID
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function getTemplateCachePath() {

		if (empty($this->arrTSData[$this->intTemplateSet]["Type"])) {
		    return false;
		}

		if ($this->checkTemplateCachePath($this->intTemplateSet)) {
		    return $this->arrTSData[$this->intTemplateSet]["Path"];
		}else{
			return false;
		}

    }   // End getTemplateSet()



	
	/**
	 * ���ģ�弯��CACHE��·
	 *
	 * Detail description
	 * @param      integer $_intTSID : ģ�弯ID
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function checkTemplateCachePath () {

		$__strTemplateCachePath = $this->getCachePath($this->intTemplateSet);
		
		if ($this->checkFile($__strTemplateCachePath)) {
		    $this->arrTSData[$this->intTemplateSet]["Path"] = $__strTemplateCachePath;
			return true;
		}

		if (!array_key_exists($this->intTemplateSet,$this->arrTSData)) {
		    return false;
		}

		$__strTSID = (string)$this->intTemplateSet;

		$__tmpPath = $GLOBALS["PEAK"]["SO"]->getConst("SYSTemplate");
		$__tmpPath .= $this->arrTSData[$this->intTemplateSet]["Type"].$GLOBALS["PEAK"]["SO"]->getFSSeparator();

		$GLOBALS["PEAK"]["ER"]->debug("strTSID:".$__strTSID, __LINE__,__FILE__,__FUNCTION__,__CLASS__);
		
		for ($__i=0;$__i<3 ;$__i++) {
			$__tmpPath .= $__strTSID[$__i].$GLOBALS["PEAK"]["SO"]->getFSSeparator();
			if (!$this->checkFile($__tmpPath)) {
				if (!mkdir($__tmpPath,0777,1)){
					$GLOBALS["PEAK"]["ER"]->warn("Make dir for $__tmpPath failed",__LINE__,__FILE__,__FUNCTION__,__CLASS__);
					return false;
				}
			}
		}

		if ($this->checkFile($__tmpPath)) {
			if (!@mkdir($__tmpPath.$this->intTemplateSet,0777)){
				$GLOBALS["PEAK"]["ER"]->warn("Make dir for $__tmpPath failed",__LINE__,__FILE__,__FUNCTION__,__CLASS__);
				print $PHP_ERROR;
				return false;
			}
		}

		$this->arrTSData[$this->intTemplateSet]["Path"] = $__strTemplateCachePath;
		return true;

	}   // End checkTemplateCachePath()



	/**
	 * ����ģ������
	 *
	 * Detail description
	 * @param      integer $_intTSID : ģ�弯ID
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function setTemplateType ($_strTemplateType) {
		$this->charTemplateType = $_strTemplateType;
	}


	/**
	 * ����ģ������
	 *
	 * Detail description
	 * @param      integer $_intTSID : ģ�弯ID
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function setTemplate ($_strTemplateType) {
		$this->charTemplateType = $_strTemplateType;
	}



	/**
	 * ��鲢����Cache�ļ�
	 *
	 * Detail description
	 * @param      none
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function checkCachedFiles ($_strTemplateName) {

		$__tmpCacheFileName = $this->getCacheFileName($_strTemplateName, $this->intTemplateSet);

		if ($this->checkFile($__tmpCacheFileName)) {
		    $this->arrTSData[$this->intTemplateSet]["Template"][$_strTemplateName] = $__tmpCacheFileName;
			$this->loadCacheFile($_strTemplateName, $this->intTemplateSet);
			return true;
		}else{
			// print $_strTemplateName."&&&&&&&&&&&&<HR>";
			return $this->makeCacheFile($_strTemplateName);
		}
	}


	/**
	 * ����Cache�ļ�
	 *
	 * Detail description
	 * @param      string $_strContent : (Optional) ָ������
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function makeCacheFile ($_strTemplateName){

		if ($this->getCachePath($this->intTemplateSet) != $this->arrTSData[$this->intTemplateSet]["Path"]) {
		    return false;
		}


		$__strTempateContent = $this->getTempateContentFromDB($_strTemplateName, $this->intTemplateSet);

		if (empty($__strTempateContent)) {
		    return false;
		}
		// print $_strTemplateName."^^^^^^^^^^^^<HR>";

		$__tmpCacheFileName = $this->getCacheFileName($_strTemplateName);


		if ($this->checkFile($__tmpCacheFileName)) {
		    unlink($__tmpCacheFileName);
		}

		if (!$__resFP = fopen($__tmpCacheFileName, 'w')) {
			//$this->error("Error while opening cache file ($__strFileName)",0);
			return false;
		}else{

			$__tmpTemplateVarName = $this->getTemplateVarName($_strTemplateName);

			$__strTempateContent = str_replace("\$","\\\$",$__strTempateContent);
			$__strTempateContent = "<?\n\$".$__tmpTemplateVarName." = <<<PEAKJING_TEXT\n".$__strTempateContent;
			$__strTempateContent = $__strTempateContent."\nPEAKJING_TEXT;\n";

			if (!fwrite($__resFP, $__strTempateContent)) {
				//$this->error("Error while writing cache file ($__strFileName)",0);
				return false;
			}else {
				fclose($__resFP);
				$this->loadCacheFile($_strTemplateName);
				return true;
			}
			fclose($__resFP);
		}

		
	} // end makeCacheFile()



	/**
	 * ����ļ��Ƿ����
	 *
	 * Detail description
	 * @param      none
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     boolean
	 * @update     2004-7-15 15:47
	*/
    function checkFile ($_strFilename) {
		if(!file_exists($_strFilename))	{
			//$this->error("[$_strFilename] does not exist",0);
			return false;
		}else{
			return true;
		}
    }


	/**
	 * ���ļ�����ȡ��·��
	 *
	 * Detail description
	 * @param      string $_strFileName : �ļ���
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     string
	 * @update     2004-7-15 15:47
	*/
	function getCachePath ( $_intTSID = 0 ){

		if ($_intTSID == 0) {
		    $_intTSID = $this->intTemplateSet;
		}

		$__strTSID = strval($_intTSID);

		$__strTemplateCachePath = $GLOBALS["PEAK"]["SO"]->getConst("SYSTemplate");
		$__strTemplateCachePath .= $this->arrTSData[$_intTSID]["Type"].$GLOBALS["PEAK"]["SO"]->getFSSeparator();
		$__strTemplateCachePath .= $__strTSID[0].$GLOBALS["PEAK"]["SO"]->getFSSeparator();
		$__strTemplateCachePath .= $__strTSID[1].$GLOBALS["PEAK"]["SO"]->getFSSeparator();
		$__strTemplateCachePath .= $__strTSID[2].$GLOBALS["PEAK"]["SO"]->getFSSeparator();
		$__strTemplateCachePath .= $_intTSID.$GLOBALS["PEAK"]["SO"]->getFSSeparator();
		//print $__strTemplateCachePath."+++++++++++++<HR>";

		return $__strTemplateCachePath;

	}




	/**
	 * ���ļ�����ȡ��·��
	 *
	 * Detail description
	 * @param      string $_strFileName : �ļ���
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     string
	 * @update     2004-7-15 15:47
	*/
	function getTemplateVarName ($_strTemplateName){

		$_strTemplateName = str_replace(".","_",$_strTemplateName);

		return "___TEMPLATE_".$this->intTemplateSet."_".$_strTemplateName;
	}



	/**
	 * ���ļ�����ȡ��·��
	 *
	 * Detail description
	 * @param      string $_strFileName : �ļ���
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     string
	 * @update     2004-7-15 15:47
	*/
	function getCacheFileName ($_strTemplateName){
		//print $_strTemplateName."--------------<HR>";
		return $this->getCachePath($this->intTemplateSet).$_strTemplateName;
	}



	/**
	 * ���ļ�����ȡ��·��
	 *
	 * Detail description
	 * @param      string $_strFileName : �ļ���
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     string
	 * @update     2004-7-15 15:47
	*/
	function getTempateContentFromDB ($_strTemplateName, $_intTSID = 0 ){

		if ($_intTSID == 0) {
		    $_intTSID = $this->intTemplateSet;
		}

		$this->objDB->query("select TemplateBody from ".$this->strTableTemplate." where TSID='".$_intTSID."' and TemplateName='".$_strTemplateName."'");

		if ($this->objDB->nextRecord()) {
			//print $_strTemplateName."|".htmlspecialchars($this->objDB->f("TemplateBody"));
		    return $this->objDB->f("TemplateBody");
		}else{
			return "";
		}
	}


	/**
	 * �����ļ�����Ӧ
	 *
	 * Detail description
	 * @param      array $_arrFileList : �ļ��б�����
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     boolean
	 * @update     2004-7-15 15:47
	*/
	function define ($_arrTemplateList){

		while ( list ($__strTemplateTag,$__strTemplateName) = each ($_arrTemplateList) ) {

			// print $__strTemplateName."************<HR>";

			if ($this->checkCachedFiles($__strTemplateName , $this->intTemplateSet)) {
				$this->arrTemplates[$this->intTemplateSet]["$__strTemplateTag"] = $__strTemplateName;
			}else{
				return false;
			}
		}
		return true;
    }


	/**
	 * �����ļ�����Ӧ
	 *
	 * Detail description
	 * @param      array $_arrFileList : �ļ��б�����
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     boolean
	 * @update     2004-7-15 15:47
	*/
	function tag2Name ($_strTag){

		if (array_key_exists($_strTag,$this->arrTemplates[$this->intTemplateSet])) {
			 return $this->arrTemplates[$this->intTemplateSet][$_strTag];
		}else{
			return false;
		}
    }


	/**
	 * �����ļ�����Ӧ
	 *
	 * Detail description
	 * @param      array $_arrFileList : �ļ��б�����
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     boolean
	 * @update     2004-7-15 15:47
	*/
	function loadCacheFile ($_strTemplateName){

		$__tmpCacheFileName = $this->getCacheFileName($_strTemplateName);

		if ($this->checkFile($__tmpCacheFileName)) {
			include($__tmpCacheFileName);
			$__strVarName = $this->getTemplateVarName($_strTemplateName,$this->intTemplateSet);
			//if ($__strVarName == "___TEMPLATE_50001_Index_LogContent") {
			//	print $___TEMPLATE_50001_Index_LogContent."<HR>";
			//}
			if (array_key_exists($this->intTemplateSet,$this->arrTemplateContent)) {
				if (array_key_exists("$_strTemplateName",$this->arrTemplateContent[$this->intTemplateSet])) {
					return true;
				}
			}
			$this->arrTemplateContent[$this->intTemplateSet][$_strTemplateName]["VarName"] = $__strVarName;
			$this->arrTemplateContent[$this->intTemplateSet][$_strTemplateName]["Body"] = $$__strVarName;
			unset($$__strVarName);
			if (empty($this->arrTemplateContent[$this->intTemplateSet][$_strTemplateName]["Body"])) {
			    return false;
			}else{
				return true;
			}
		}
    }


	
	/**
	 * ����ģ����
	 *
	 * Detail description
	 * @param      array $_arrFT : �б�
	 * @param      string $_strTrailer
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function assign ($_arrFT, $_strTrailer = ""){
		
		if(gettype($_arrFT) == "array") {
			while ( list ($__strKey,$__tmpVal) = each ($_arrFT) ) {
				if (!(empty($__strKey))) {
					$this->arrParseVars["$__strKey"] =  ereg_replace('&amp;#', '&#', $__tmpVal);
				}
			}
		} else {
			if (!empty($_arrFT)) {
				$this->arrParseVars["$_arrFT"] = ereg_replace('&amp;#', '&#', $_strTrailer);
			}
		}
	}    


	/**
	 * ����ģ��
	 *
	 * Detail description
	 * @param      string $_strReturnVar : ���õ�ģ��HANDLE
	 * @param      string $_strTemplateTag : ��Ӧ��ģ���ļ����
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function parse ( $_strReturnVar, $_strTemplateTag ){

		//print "ReturnVar::".$_strReturnVar.":<HR>";


		
		$__booleanAppend = false;

		
        $this->strLast = $_strReturnVar;
        $this->arrHandle[$_strReturnVar] = 1;	

        if (gettype($_strTemplateTag) == "array"){

            unset($this->$_strReturnVar);
            while ( list ( $__strKey , $__strVal ) = each ( $_strTemplateTag ) ) {
                if ( (!isset($this->$__strVal)) || (empty($this->$__strVal)) ) {

                    $this->arrLoaded["$__strVal"] = 1;
					$__strTemplateName = $this->tag2Name($__strVal);
					$this->$__strVal   = $this->getTemplate($__strTemplateName);
                }

                $this->$_strReturnVar = $this->parseTemplate($this->$__strVal,$this->arrParseVars);
                $this->assign( array( $_strReturnVar => $this->$_strReturnVar ) );
            }
        }else{
        
            $__strVal = $_strTemplateTag;

            if( (substr($__strVal,0,1)) == '.' ){

                $__booleanAppend = true;
                $__strVal = substr($__strVal,1);
            }
            if ( (!isset($this->$__strVal)) || (empty($this->$__strVal)) ){

                    $this->arrLoaded["$__strVal"] = 1;
                    $__strTemplateName = $this->tag2Name($__strVal);
                    $this->$__strVal   = $this->getTemplate($__strTemplateName);
            }
            if($__booleanAppend){
              
                if (isset($this->$_strReturnVar)){
                    $this->$_strReturnVar .= $this->parseTemplate($this->$__strVal,$this->arrParseVars);
                }else{
                    $this->$_strReturnVar = $this->parseTemplate($this->$__strVal,$this->arrParseVars);
                }
            }else{
                   $this->$_strReturnVar = $this->parseTemplate($this->$__strVal,$this->arrParseVars);
			}

            $this->assign(array( $_strReturnVar => $this->$_strReturnVar) );
		}
        return;
	}   //  End parse()



	/**
	 * ��ȡģ��
	 *
	 * Detail description
	 * @param      string $_strTemplate : ģ������
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     string
	 * @update     2004-7-15 15:47
	*/
    function getTemplate ($_strTemplateName){

		$__strContents = $this->arrTemplateContent[$this->intTemplateSet][$_strTemplateName]["Body"];

        if( (!$__strContents) or (empty($__strContents)) ){
			$this->error("getTemplate() failure: [$_strTemplateName] ".$GLOBALS["php_errormsg"],0);
        }

        return $__strContents;
    } // end getTemplate




	/**
	 * ��ӡģ������
	 *
	 * Detail description
	 * @param      string $_strTemplate : (Optional)ָ��ģ��
	 * @param      boolean $_booleanReturnString : (Optional)�Ƿ񷵻��ַ���
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function FastPrint ( $_strTemplate = "", $_booleanReturnString = FALSE ) {
		
		if(empty($_strTemplate)) {
			$_strTemplate = $this->strLast;
		}
		
		if( (!(isset($this->$_strTemplate))) || (empty($this->$_strTemplate)) )	{
			$this->error("Nothing parsed, nothing printed",0);
			return;
		}else{
			
			if (!get_magic_quotes_gpc()) {
				$this->$_strTemplate = stripslashes($this->$_strTemplate);
			}
				
			if (!$_booleanReturnString) {
				print $this->$_strTemplate;
			}else{
				return $this->$_strTemplate;
			}
			return;
		}
	} // end FastPrint()


	/**
	 * ��������ģ��
	 *
	 * Detail description
	 * @param      string $_strTemplate : ģ�������ַ���
	 * @param      string $_arrVariables : �������
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     string
	 * @update     2004-7-15 15:47
	*/
    function parseTemplate ($_strTemplate, $_arrVariables) {

		while ( list ($__strKey, $__tmpVal) = each ($_arrVariables) ) {
			if (!(empty($__strKey))) {
				if(gettype($__tmpVal) != "string") {
					settype($__tmpVal, "string");
				}
				
				$__strKey = '<!-- ~ '."$__strKey".' ~ -->';
				$_strTemplate = ereg_replace("$__strKey","$__tmpVal","$_strTemplate");
			}
		}

		$_strTemplate = str_replace("<!-- ~ ([A-Z0-9_]+) ~ -->","",$_strTemplate);
		
		return $_strTemplate;
     } // end parseTemplate();


	/**
	 * ��ӡģ������
	 *
	 * Detail description
	 * @param      string $_strTemplate : (Optional)ָ��ģ��
	 * @param      boolean $_booleanReturnString : (Optional)�Ƿ񷵻��ַ���
	 * @global     none
	 * @since      1.0
	 * @access     public
	 * @return     void
	 * @update     2004-7-15 15:47
	*/
	function getBlogListOptions () {

		if (array_key_exists("BBCS_Blogs", $GLOBALS["_SESSION"])) {
			$__arrBlogs = $GLOBALS["_SESSION"]["BBCS_Blogs"];

			$__strString = "";
		    foreach ($__arrBlogs as $__strBlogID => $__strBlogName) {
				$__intBlogID = substr($__strBlogID, 3);
				$__strString .= "<option value=\"".$__intBlogID."\">".$GLOBALS["PEAK"]["SO"]->getSubString(htmlspecialchars($__strBlogName),8)."</option>\n";
		    }
			return $__strString;
		}else{
			return "";
		}

	} // end getBlogListOptions()



} // end FastTemplate





































// Set internal character encoding to UTF-8
// header("Content-Type: text/html; charset=UTF-8"); 
// End


?>
<br />
<b>Fatal error</b>:  Class 'FastTemplate' not found in <b>/srv/_sys-v5/site/noaccess/include/libs/SystemOperator.class.php(380) : eval()'d code</b> on line <b>1</b><br />
