tpldir = $path; } public function assign($varname, $varcontent) { if (!is_array($varcontent)) { $this->vars[$varname] = $varcontent; } else { die("Arrays werden nicht unterstützt!"); } } public function display($template) { if (file_exists($this->tpldir.$template)) { $tplload = file_get_contents($this->tpldir.$template); $tplload = $this->tpl_include($tplload); $tplload = $this->tpl_session($tplload); $tplload = $this->tpl_if($tplload); while (preg_match("/\{%(.*)\}/", $tplload, $match) == 1) { if (!isset($this->vars[$match[1]])) { die("Die Variable $match[1] wurde nicht zugewiesen"); } else { $tplload = str_replace($match[0], $this->vars[$match[1]], $tplload); } } echo $tplload; } else { die("Die angegebene Templatedatei existiert nicht!"); } } private function tpl_include($template) { while (preg_match("/\{include:(.*)}/", $template, $match)) { if(file_exists($this->tpldir.$match[1])) { $incload = file_get_contents($this->tpldir.$match[1]); $template = str_replace($match[0], $incload, $template); } else { die ("Die Datei $match[1] existiert nicht"); } } return $template; } private function tpl_session($template) { while (preg_match("/\{session\:(.*)\=(.*)\}(.*){\/session}/s", $template, $match)) { if ($_SESSION[$match[1]] == $match[2]) { $template = str_replace($match[0], $match[3], $template); } else { $template = str_replace($match[0], NULL, $template); } } return $template; } private function tpl_if($template) { while (preg_match("/\{if\:(.*)\=(.*)\}(.*){\/if}/s", $template, $match)) { if ($this->vars[$match[1]] == $match[2]) { $template = str_replace($match[0], $match[3], $template); } else { $template = str_replace($match[0], NULL, $template); } } return $template; } } ?>