View file core/autoload/Template.class.php

File size: 1.15Kb
<?

class template
{
	public $template_dir = THEME;
	protected $Vars = array();

	public function __construct($template_dir = false) 
	{
		$this->template_dir = $template_dir ? $template_dir : $this->template_dir;
	}

	public function assign($var_name, $var_value) 
	{
		$this->Vars[$var_name] = $var_value;
	}

	public function fetch($template,$format = '.php')
	{	
		$arr_reg_loads = array('sql', 'user','time','system','urlPage','set','t');
		$registry = Registry::getInstance(); 
		foreach($arr_reg_loads AS $key => $val)
		{
			$$val = $registry->get($val);
		}

		extract($this->Vars);
		ob_start();
	
		if (file_exists($this->template_dir . $template . $format))
		{	
			include $this->template_dir . $template . $format;
			return ob_get_clean();
		}
		else
		{
			$TemplateName = THEME_USER . 'template/'. $template . $format;
			$text_t = __("Шаблон :: %template% :: не найден", array('template' => $TemplateName));
			$this->assign('text', $text_t);
			echo $this->fetch('template.empty');
		}
	}

	public function get_template_vars($var) 
	{
		return isset($this->Vars[$var]) ? $this->Vars[$var] : false;
	}
}