From 29c17fd906b002daecd8a19a15ab1b97961d50df Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Sat, 9 Nov 2013 20:37:46 +0000 Subject: [PATCH] Add the template class. --- resources/classes/template.php | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 resources/classes/template.php diff --git a/resources/classes/template.php b/resources/classes/template.php new file mode 100644 index 0000000000..57bd6510d6 --- /dev/null +++ b/resources/classes/template.php @@ -0,0 +1,93 @@ + + Copyright (C) 2013 + All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +include "root.php"; + +//define the template class + if (!class_exists('template')) { + class template { + //variables + public $engine; + public $name; + public $template_dir; + public $cache_dir; + private $object; + private $x = 0; + + public function __construct() { + if ($this->engine === 'smarty') { + include "resources/smarty/Smarty.class.php"; + $this->object = new Smarty(); + $this->object->setTemplateDir($template_dir); + $this->object->setCompileDir($compile_dir); + $this->object->setCacheDir($cache_dir); + } + if ($this->engine === 'raintpl') { + include "resources/raintpl/rain.tpl.class.php"; + $this->object = new RainTPL(); + raintpl::configure( 'tpl_dir', $this->template_dir); + raintpl::configure( 'cache_dir', $this->cache_dir); + } + if ($this->engine === 'twig') { + require_once "resources/twig/Autoloader.php"; + Twig_Autoloader::register(); + $loader = new Twig_Loader_Filesystem($template_dir); + $this->object = new Twig_Environment($loader); + } + } + + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } + } + + public function assign($key, $value) { + if ($this->engine === 'smarty') { + $this->object->assign($key, $value); + } + if ($this->engine === 'raintpl') { + $this->object->assign($key, $value); + } + if ($this->engine === 'twig') { + $this->var_array[$this->x][$key] = $value; + $this->x++; + } + } + + public function render() { + if ($this->engine === 'smarty') { + return $this->object->fetch($this->name); + } + if ($this->engine === 'raintpl') { + return $this->object-> draw($this->name, 'return_string=true'); + } + if ($this->engine === 'twig') { + return $twig->render($this->name,$this->var_array); + } + } + + } + } \ No newline at end of file