<?php
class Template
{
static private $instance = NULL;
private $path='templates/';
private $template;
private $extension = '.html';
private $var = array();
static function a(){
if(self::$instance==NULL)self::$instance=new Template();
return self::$instance;
}
public function set($var,$text)
{
$this->var[$var]=$text;
}
public function setTitle($text)
{
$this->var['title']=$text;
}
public function display($template, $strip = true)
{
$this->template = $this->path.$template.$this->extension;
if (!file_exists($this->template))
{
die('Шаблон <b>'.$this->template.'</b> не существует!');
}
ob_start();
extract($this->var, EXTR_REFS);
include 'templates/head.html';
include $this->template;
include 'templates/footer.html';
if($strip)
{
echo $this->strip(ob_get_clean());
}
else
{
echo ob_get_clean();
}
die();
}
private function strip($data)
{
$lit = array("\\t", "\\n", "\\n\\r", "\\r\\n", " ");
$sp = array('', '', '', '', '');
return str_replace($lit, $sp, $data);
}
public function xss($data)
{
if (is_array($data))
{
$escaped = array();
foreach ($data as $key => $value)
{
$escaped[$key] = $this->xss($value);
}
return $escaped;
}
return htmlspecialchars($data, ENT_QUOTES);
}
}
?>