Login   Register  
PHP Classes
elePHPant
Icontem

File: templates/class/exp.tpl

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Vladimir  >  Templates class  >  templates/class/exp.tpl  >  Download  
File: templates/class/exp.tpl
Role: Auxiliary data
Content type: text/plain
Description: templates
Class: Templates class
Template engine that replaces variable marks
Author: By
Last change:
Date: 4 months ago
Size: 1,617 bytes
 

Contents

Class file image Download
<?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;
	}
}


?>