rendered paste body<?php
error_reporting(E_ALL);
class template
{
var $_tpl_file = '';
var $_tpl_replace = array();
var $_tpl_content = array();
var $_tpl_blocks = array();
var $_tpl_rows = array();
function template($tplfile)
{
if(file_exists("./template/".$tplfile) === true)
{
$this->_tpl_file = "./template/".$tplfile;
} else {
die("template datei nicht gefunden!");
}
}
function setBlock($blockname, $column, $value)
{
$this->_tpl_blocks[$blockname][$column] = $value;
}
function setRow($blockname, $num, $value)
{
$this->_tpl_rows[$blockname][$num] = $value;
}
function replace($column, $value)
{
$this->_tpl_replace["{".$column."}"] = $value;
}
function readtpl()
{
$this->_tpl_content = file($this->_tpl_file);
}
function compiletpl()
{
for($i=0; $i<count($this->_tpl_content); $i++)
{
if(substr($this->_tpl_content[$i],0,5) == "<!--?")
{
$tmp = explode(" ", $this->_tpl_content[$i]);
$tmp = explode(":", $tmp[1]);
$btmp = "";
// Start Block content
if($tmp[0] == "BLOCK")
{
$bcontent = file("./template/blocks/".$tmp[1].".tpl");
for($s=0; $s<count($bcontent); $s++)
{
$btmp .= $bcontent[$s];
}
$bcontent = trim($btmp);
foreach($this->_tpl_blocks[$tmp[1]] as $column => $value)
{
$bcontent = str_replace("{".$column."}", $value, $bcontent);
}
$this->_tpl_content[$i] = $bcontent;
unset($bcontet);
unset($s);
unset($btmp);
}
// End Block Content
// Start Rows Content
if($tmp[0] == "ROWS")
{
$bcontent = file("./template/blocks/".$tmp[1].".tpl");
for($s=0; $s<count($bcontent); $s++)
{
$btmp .= $bcontent[$s];
}
$bcontent = trim($btmp);
echo "test: ".$this->_tpl_rows[$tmp[1]]."<br />";
$atmp = explode(":", $this->_tpl_rows[$tmp[1]][$value]);
for($a=0; $a<count($atmp); $a++)
{
$bcontent = str_replace("{".$atmp[$a]."}", $atmp[$a], $bcontent);
}
$this->_tpl_content[$i] = $bcontent;
unset($bcontet);
unset($s);
unset($btmp);
unset($atmp);
}
}
foreach($this->_tpl_replace as $column => $value)
{
if(stripos($this->_tpl_content[$i], $column) !== false)
{
$this->_tpl_content[$i] = str_replace($column, $value, $this->_tpl_content[$i]);
}
}
}
}
function parsetpl()
{
for($i=0; $i<count($this->_tpl_content); $i++)
{
echo $this->_tpl_content[$i];
}
}
}
?>