diff options
author | fabrixxm <fabrix.xm@gmail.com> | 2013-05-08 03:51:38 -0400 |
---|---|---|
committer | fabrixxm <fabrix.xm@gmail.com> | 2013-05-08 03:51:38 -0400 |
commit | 31a21ac24cd5cbe19e40ab3838fcc179d812da13 (patch) | |
tree | d556822e261cb2b8ff10452a7c5b07b0c2c793c7 /boot.php | |
parent | 51c27579ba79d32c26052c0d1f1218a16315234b (diff) | |
download | volse-hubzilla-31a21ac24cd5cbe19e40ab3838fcc179d812da13.tar.gz volse-hubzilla-31a21ac24cd5cbe19e40ab3838fcc179d812da13.tar.bz2 volse-hubzilla-31a21ac24cd5cbe19e40ab3838fcc179d812da13.zip |
use smarty3 as default template engine. add pluggable template system
Diffstat (limited to 'boot.php')
-rwxr-xr-x[-rw-r--r--] | boot.php | 84 |
1 files changed, 75 insertions, 9 deletions
diff --git a/boot.php b/boot.php index e230a13c6..b00419359 100644..100755 --- a/boot.php +++ b/boot.php @@ -546,9 +546,14 @@ class App { 'force_max_items' => 0, 'thread_allow' => true, 'stylesheet' => '', - 'template_engine' => 'internal', + 'template_engine' => 'smarty3', ); + // array of registered template engines ('name'=>'class name') + public $template_engines = array(); + // array of instanced template engines ('name'=>'instance') + public $template_engine_instance = array(); + private $ldelim = array( 'internal' => '', 'smarty3' => '{{' @@ -680,6 +685,16 @@ class App { $this->is_tablet = $mobile_detect->isTablet(); BaseObject::set_app($this); + + /** + * register template engines + */ + $dc = get_declared_classes(); + foreach ($dc as $k) { + if (in_array("ITemplateEngine", class_implements($k))){ + $this->register_template_engine($k); + } + } } function get_baseurl($ssl = false) { @@ -897,28 +912,79 @@ class App { return $this->curl_headers; } + + /** + * register template engine class + * if $name is "", is used class static property $class::$name + * @param string $class + * @param string $name + */ + function register_template_engine($class, $name = '') { + if ($name===""){ + $v = get_class_vars( $class ); + if(x($v,"name")) $name = $v['name']; + } + if ($name===""){ + echo "template engine <tt>$class</tt> cannot be registered without a name.\n"; + killme(); + } + $this->template_engines[$name] = $class; + } + + /** + * return template engine instance. If $name is not defined, + * return engine defined by theme, or default + * + * @param strin $name Template engine name + * @return object Template Engine instance + */ + function template_engine($name = ''){ + if ($name!=="") { + $template_engine = $name; + } else { + $template_engine = 'smarty3'; + if (x($this->theme, 'template_engine')) { + $template_engine = $this->theme['template_engine']; + } + } + + if (isset($this->template_engines[$template_engine])){ + if(isset($this->template_engine_instance[$template_engine])){ + return $this->template_engine_instance[$template_engine]; + } else { + $class = $this->template_engines[$template_engine]; + $obj = new $class; + $this->template_engine_instance[$template_engine] = $obj; + return $obj; + } + } + + echo "template engine <tt>$template_engine</tt> is not registered!\n"; killme(); + } + function get_template_engine() { return $this->theme['template_engine']; } - function set_template_engine($engine = 'internal') { + function set_template_engine($engine = 'smarty3') { - $this->theme['template_engine'] = 'internal'; + $this->theme['template_engine'] = $engine; - switch($engine) { + /*if ($engine) { case 'smarty3': - if(is_writable('view/tpl/smarty3/')) - $this->theme['template_engine'] = 'smarty3'; + if(!is_writable('view/tpl/smarty3/')) + echo "<b>ERROR</b> folder <tt>view/tpl/smarty3/</tt> must be writable by webserver."; killme(); + break; default: break; - } + }*/ } - function get_template_ldelim($engine = 'internal') { + function get_template_ldelim($engine = 'smarty3') { return $this->ldelim[$engine]; } - function get_template_rdelim($engine = 'internal') { + function get_template_rdelim($engine = 'smarty3') { return $this->rdelim[$engine]; } |