<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
include_once(LAB_PATH_KERNEL."/classes/Smarty/Smarty.class.php");

class Tpl extends Smarty
{
	protected static $instance;
	public function __construct()
	{
		parent::__construct();
	
		$this->setCompileCheck(LabConfig::$cfg['debug_mode']);
		
		if ((!empty(LabConfig::$cfg['debug_mode']) || LabVars::$allow_debug) && isset($_GET["debug"]))
		{
			$this->debugging=true;
			$this->setCompileCheck(true);
		}
		$this->setPluginsDir(array(
			LAB_PATH_KERNEL.'/classes/Smarty/plugins',
			LAB_PATH_KERNEL.'/plugins',
			LAB_PATH_KERNEL.'/plugins_project'
		));

		if (!empty(LabConfig::$cfg['skin']))
		{
			$dir=array(	LabConfig::$cfg['skin']=>LAB_PATH_TEMPLATE.'/'.LabConfig::$cfg['skin'].'/');
			if (LabConfig::$cfg['skin']!='default') $dir['default']=LAB_PATH_TEMPLATE.'/default/';
			$this->setTemplateDir($dir);
		}
		
		$this->compile_dir  = LAB_PATH_DATA.'/template_c/';
		$this->cache_dir    = LAB_PATH_DATA.'/cache/';
		//$this->error_reporting = E_ALL & ~E_NOTICE;
		$this->error_reporting    = error_reporting();
		$this->setCacheLifetime(60*60*24);
		
		if (!empty(LabConfig::$cfg['cache']) && !empty(LabConfig::$cfg['use_memcached_tpl']))
		{
			$this->caching_type='memcache';
			$this->cache_modified_check=false;
		}
	}

	public static function i()
	{
		return self::instance();
	}
	
	public static function instance()
	{
		if (self::$instance === null)
		{
			self::$instance = new self;
		}
		return self::$instance;
	}
	
}