
<?php ############################################################### # Adrian Staniszewski # adrian_s@toya.net.pl # GG: 5513236 # # File: Class.Template.php5 # Version: 0.2 # Modif: 7.11.2006 # Description: Kubu Template Class # ############################################################## class TT_Template { // _base id directory to template folder public $_base = 'template/'; // _dir is directory to currently used template private $_dir = ''; // _var is library with varibles and array // _file is file library // _files is currently used file private $_files = ''; public function __construct($Temp = 'base') { $this -> _dir = ''.$this -> _base.''.$Temp.''; } // function add is adding new file to _file library public function add($file) { // set currently used file $this -> _files = $file; } else { } } // function write is adding new varibles or arrays to definited file varibles libr
ary public function write($key, $value, $point='') { if($point=='') $point = $this -> _files; // checks is $value is array or varible $this -> _var[$point]['array'][$key] = $value; } else { $this -> _var[$point]['var']['{'.$key.'}'] = $value; } } // function getFile is getting sources of $point file private function getFile($point='') { if($point=='') $point = $this -> _files; } // function parseVar is replace flags for added varibles defined file private function parseVar($point='') { if($point=='') $point = $this -> _files; $this -> _file[$point]['result'] = $this -> _file[$point]['source']; foreach ($this -> _var[$point]['var'] as $Key => $Value) { } } // function parseWhile is adding loop While and replace flags for added varibles d
efined file private function parseWhile($point='') { if($point=='') $point = $this -> _files; if($this -> _file[$point]['result']=='') $this -> _file[$point]['result'] = $this -> _file[$point]['source']; // searching for While loop $c = 0; foreach($doWhile['1'] as $while) { $Value = $doWhile['2'][$c]; $row = $this -> _var[$point]['array'][$while]; $b = 0; while($b < $B) { $_Result .= $Result; $b++; } // saves results $this -> _file[$point]['result'] = str_replace($doWhile['0'][$c], $_Result, $this -> _file[$point]['result']); $c++; } } public function Parse($point='') { if($point == '') $point = $this -> _files; $this -> getFile($point); $this -> parseVar($point); $this -> parseWhile($point); } } ?>
Przykładzik
<?php $t = new TT_Template('standard'); $t -> add('index2.tpl'); $t -> write('title', 'to jest moja super strona !! musisz to zobaczyc'); $t -> write('meta', 'ISO-8859-2'); $t -> write('news', $tablica); ?>
zródło :
po parsowaniu: