Файл: system/template.php
Строк: 23
<?php
/**
*    Author: Elime;
*    ICQ: 618878;
*    E-mail: elime4@gmail.com;
*/
class Template
{
    private $path;
    private $template;
    private $extension = '.html';
    private $var = array();
    
    
    /* Устанавливаем путь */
    public function __construct($path = '')
    {
        $this->path = $path.'/';
    }
    
    /* Выводим шаблон */
    public function display($template, $var = '', $strip = true)
    {
        /* Полный путь к шаблону */
        $this->template = $this->path.$template.$this->extension;
        if (!file_exists($this->template))
        {
            die('Шаблон <b>'.$this->template.'</b> не существует!');
        }
        ob_start();
        
        /* Создаем переменные из массива */
        extract($var, EXTR_REFS);
        
        /* Подключаем шаблон */
        include $this->template;
        
        /* Фильтрация */
        if($strip)
        {
            echo $this->strip(ob_get_clean());
        }
        else
        {
            echo ob_get_clean();
        }
    }
    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);
    }
}
?>