<?
class tpl
{
    var 
$vars = array();
    var 
$path "./tpl/";

    function 
set_var($name$value)
    {
        
$this->vars[$name] = $value;
    }

    function 
set_array($name$value)
    {
        for (
$i 0$i count($value); $i++)
            
$this->vars[$name."[".$i."]"] = $value[$i];
    }

    function 
clear_vars()
    {
        
$this->vars = array();
    }

    function 
load_vars($vars)
    {
        foreach (
$vars as $key => $val)
        {
            
$this->vars[$key] = $val;
        }
    }
    
    function 
parse_imports($str)
    {
        if (
is_array($str))
            
$str file_get_contents($this->path.$str[1]);
        return 
preg_replace_callback("/@import\(([^\s]+)\);?/", array($this"parse_imports"), $str);
    }

    function 
process($tpl)
    {
        
$x file_get_contents($this->path.$tpl);
        
$x $this->parse_imports($x);
        return 
preg_replace("/%([^\s\"]+)%/e""\$this->vars[\"\\1\"]"$x);
    }
}
?>