aboutsummaryrefslogtreecommitdiffstats
path: root/boot.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-05-08 02:11:17 -0700
committerfriendica <info@friendica.com>2013-05-08 02:11:17 -0700
commitcdcbe9772423d5373f6d0d4aa33700446a989340 (patch)
tree2f1f1c7540c62c049dd314b0155380c6cb4526b5 /boot.php
parent51c27579ba79d32c26052c0d1f1218a16315234b (diff)
parent5e1980becf69a4c65489bed6f94fa730ec8ef4bf (diff)
downloadvolse-hubzilla-cdcbe9772423d5373f6d0d4aa33700446a989340.tar.gz
volse-hubzilla-cdcbe9772423d5373f6d0d4aa33700446a989340.tar.bz2
volse-hubzilla-cdcbe9772423d5373f6d0d4aa33700446a989340.zip
Merge pull request #50 from fabrixxm/newtemplatesystem
New template system
Diffstat (limited to 'boot.php')
-rwxr-xr-x[-rw-r--r--]boot.php84
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];
}