<?php
class tpl {
	private $dir_tmp     = TMP_DIR; // путь к папке с шаблонами
	private $tmp = ''; // абсолютный путь к шаблону
	private $content = '';
	function __construct($site_tmp){
        $this->tmp = realpath(dirname(__FILE__). '/../../').$this->dir_tmp.'/'.$site_tmp;
        $this->patch_site_tmp();
	}
    public function patch_site_tmp (){
    	if(is_dir($this->tmp)){
    		return $this->tmp;
    	}die('<b>папка '.$this->tmp.' не найдена!</b>');
    }
    public function _content($temp){
    	$this->load_template($temp);
    	return $this->handler_template();
    }
    public function content($temp,$print=true){
    	$this->load_template($temp);
    	if($print===true){
    		print( $this->handler_template());
    	}else{return  $this->handler_template();}
    }
    private function load_template($path){
	     if( is_file($this->tmp.'/'.$path.'.tpl') ){
	         $this->content = file_get_contents($this->tmp.'/'.$path.'.tpl');
	     }else{die('<b>шаблон - '.$path.'.tpl не найден</b>');}
    }
	function handler_template (){
	     preg_match_all ("/{([A-Z_]+)}/", $this->content, $matches);
	     if( is_array ($matches) ){
	        while (list(,$val) = each ($matches[0])){
	            $search[]  = "'".$val."'";
	            $val = str_replace ("}","",$val);
	            $VAL = str_replace ("{","",$val);
	            $replace[] = $GLOBALS[$VAL];
	          }
	        $search[]  = "'0'e";
	        $replace[] = '0';
	        $path = preg_replace ($search, $replace, $this->content);
	       }
	    return $path;
	}
}
?> 
  |