setPath($path); $this->vars[self::GLOBAL_KEY] = array(); } /** * Присвоить переменную только * * @param string $name - имя переменной * @param mixed $value - значение переменной * @param string $template - шаблон, если не указан, то переменная глобальная */ public function assign($name, $value, $template = self::GLOBAL_KEY) { $this->vars[$template][$name] = $value; } /** * Очистить стек переменных * @param boolean $with_local - включая локальные переменные */ public function clear($template = self::GLOBAL_KEY) { $this->vars[$template] = array(); } /** * Обработать шаблон * * @param string $template - относительный путь до шаблона * @return string - обработанное содержимое шаблона */ public function fetch($template) { $this->template = $template; //дабы экстракт не перезатер нам переменную. Это важно! $this то он не перезатрет :) extract($this->vars[self::GLOBAL_KEY]); if (isset($this->vars[$this->template])) { extract($this->vars[$this->template], EXTR_OVERWRITE); } ob_start(); if (!(include $this->path.'/'.$this->template) == 'OK') { throw new MJException('Template '.$this->path.'/'.$this->template.' not found'); } return ob_get_clean(); } /** * Установать путь до шаблонов * * @param string $path - путь до шаблонов */ public function setPath($path) { $this->path = $path; } //Функции для вызова из шаблонов. protected function addHead($str) { $this->head_array[] = $str; } protected function getHead() { return $this->head_array; } /** * обрезает текст до заданной длинны * * @param string $text * @param int $count * @param string $postfix */ protected function trimString($text, $count = 15, $postfix = "...") { return mb_substr($text, 0, $count).$postfix; } } ?>