<?php
require( 'Smarty.class.php' );
class TplParser{
	var $aVariables = Array( );
	var $sDir;
	function __construct( $sDir ){
		$this->oSmarty = new Smarty( );
		$this->oSmarty->left_delimiter = "{{";
		$this->oSmarty->right_delimiter = "}}";
		$this->sDir = $sDir;
		$this->oSmarty->template_dir = $sDir;
		$this->oSmarty->compile_dir = str_replace( 'templates/', 'templates_comp/', $sDir );
		$this->oSmarty->plugins_dir[] = 'sysplugins';
		$this->assign( 'lang', $GLOBALS['lang'] );
		$this->assign( 'config', $GLOBALS['config'] );
		$this->assign( 'aOuterPaymentOption', $GLOBALS['aOuterPaymentOption'] );
		$this->assign( 'aProductMinSizes', $GLOBALS['aProductMinSizes'] );
		$this->assign( 'aPageMinSizes', $GLOBALS['aPageMinSizes'] );
		$this->assign( 'aProducersMinSizes', $GLOBALS['aProducersMinSizes'] );
		$this->assign( '_SESSION', $_SESSION );
		$this->assign( '_SERVER', $_SERVER );
		$this->assign( '_GET', $_GET );
		$this->assign( '_POST', $_POST );
		$this->assign( 'MOBILE', MOBILE );
	}
	static function &getInstance( $sDir = null ){
		static $oInstance = null;
		if( !isset( $oInstance ) ){
			$oInstance = new TplParser( $sDir );
		}
		return $oInstance;
	}
	function setDir( $sDir = null ){
		$this->sDir = $sDir;
		$this->oSmarty->template_dir = $sDir;
		$this->oSmarty->compile_dir = str_replace( 'templates/', 'templates_comp/', $sDir );
	}
	function getDir( ){
		return $this->sDir;
	}
	function assign( $sName, $mValue ){
		$this->oSmarty->assign( $sName, $mValue );
	}
	function unassign( $sName ){
		$this->oSmarty->clearAssign( $sName );
	}
	function parse( $sFile ){
		return $this->oSmarty->fetch( $sFile );
	}
	function getTemplateVars( $varname = null, $_ptr = null, $search_parents = true ){
		return $this->oSmarty->getTemplateVars( $varname, $_ptr, $search_parents );
	}
}
?>