zmienne normalnie chodza
moze dam template.php? bo do konca nie rozumiem cie
Kod
<?php
class template
{
protected $template_dir;
protected $cache_dir;
protected $values = array();
public function template_dir($template_dir)
{
$this->template_dir = $template_dir;
}
public function cache_dir($cache_dir)
{
$this->cache_dir = $cache_dir;
}
public function setvar($key, $value)
{
$this->values[$key] = $value;
}
public function convert($file)
{
if (!file_exists($this->template_dir.$file))
{
$sname = basename($_SERVER['SCRIPT_FILENAME']);
echo("<b>TemplateEngine Error:</b> File <b>".$this->template_dir.$file."</b> doesn't exist. Error in <b>".$sname."</b>.<br />");
return 0;
}
if (!file_Exists($this->cache_dir."cache.".$file))
{
$output = file_get_contents($this->template_dir.$file);
foreach ($this->values as $key => $value)
{
$replacement = "{".$key."}";
$output = str_replace($replacement, $value, $output);
}
$replacement = "{if=";
$replaced = "<?php if(";
$output = str_replace($replacement, $replaced, $output);
$replacement = "/}";
$replaced = ") { ?>";
$output = str_replace($replacement, $replaced, $output);
$replacement = "{elseif}";
$replaced = "<?php } else { ?>";
$output = str_replace($replacement, $replaced, $output);
$replacement = "{elseif=";
$replaced = "<?php } else if(";
$output = str_replace($replacement, $replaced, $output);
$replacement = "{/if}";
$replaced = "<?php } ?>";
$output = str_replace($replacement, $replaced, $output);
$fp = fopen($this->cache_dir."cache.".$file, "w+");
fwrite($fp, $output);
fclose($fp);
}
}
public function show($file)
{
if (!file_exists($this->cache_dir."cache.".$file))
{
$sname = basename($_SERVER['SCRIPT_FILENAME']);
echo("<b>TemplateEngine Error:</b> File <b>".$this->template_dir.$file."</b> doesn't exist. Error in <b>".$sname."</b>.<br />");
return 0;
}
include($this->cache_dir."cache.".$file);
}
}
?>
i co o tym sadzicie?