addData($data); return $template->fillIn(); } public function __construct($name) { if (strpos($name, '../') !== false) throw new Exception("Template name contains illegal path component."); $this->path = $this->getPath($name); if ($this->path === false) throw new Exception("Template $name not found in templates/ directory."); if (!is_readable($this->path)) throw new Exception("Template $name not readable."); } public function id() { return $this->path; } protected function getPath($name) { $hallinta = Hallinta::instance(); $path = $hallinta->basedir() . 'masks/' . $hallinta->module() . '/templates/' . $name . '.phtml'; if (file_exists($path)) return $path; $path = $hallinta->basedir() . 'templates/' . $name . '.phtml'; if (file_exists($path)) return $path; return false; } public function add($name, $value) { $this->data[$name] = $value; } public function addData(Array $data) { foreach ($data as $name => $value) $this->data[$name] = $value; } public function fillIn() { extract($this->data); try { ob_start(); include($this->path); $text = ob_get_clean(); } catch (Exception $e) { $text = ob_get_clean(); throw new Exception($e->getMessage()); } catch (Error $e) { $text = ob_get_clean(); throw new Exception($e->getMessage()); } return $text; } public function ajaxLoad(Array $data) { $this->addData($data); return $this->fillIn(); } }