Wytykajcie błedy

<?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 {
echo 'Error !! Invalidy File.'; }
}
// 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) {
$this -> _file
[$point]['result'] = str_replace($Key, $Value, $this -> _file
[$point]['result']); }
}
// 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
preg_match_all('/{while@(.*?)}(.*?){while@end}/sie', $this -> _file
[$point]['result'], $doWhile); $c = 0;
foreach($doWhile['1'] as $while) {
$Value = $doWhile['2'][$c];
$row = $this -> _var[$point]['array'][$while];
$b = 0;
while($b < $B) {
$Result = preg_replace('/{@(.*?)}/sie', '$row[$b][$1]', $Value); $_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);
echo $this -> _file
[$point]['result']; }
}
?>
Przykładzik
<?php
$t = new TT_Template('standard');
$t -> add('index2.tpl');
$news[] = array('id' => '2', 'name' => 'gruszka'); $news[] = array('id' => '3', 'name' => 'pomarancz'); $tablica = array('jablko', 'gruszka', 'pomarancz'); $t -> write('title', 'to jest moja super strona !! musisz to zobaczyc');
$t -> write('meta', 'ISO-8859-2');
$t -> write('news', $tablica);
?>
zródło :<table border="1" align="center"> {while@news}
<b>{@id}
</b> - {@name}
<br />{while@end}
po parsowaniu:<table border="1" align="center"> <b>2
</b> - gruszka
<br /><b>3
</b> - pomarancz
<br />
Ten post edytował Adrian Staniszewski 7.11.2006, 12:56:28