aboutsummaryrefslogtreecommitdiffstats
path: root/include/template_processor.php
diff options
context:
space:
mode:
authorFabio Comuni <fabrix.xm@gmail.com>2011-04-14 09:22:38 +0200
committerFabio Comuni <fabrix.xm@gmail.com>2011-04-14 09:22:38 +0200
commit0afef6b17e622d1fabd0f499ac206e8924278dfb (patch)
tree41266ee82eaa60335a38b9509692eb0ef4b5a724 /include/template_processor.php
parentf70dd1ee927ab57afd4382552e32fef86f277be3 (diff)
downloadvolse-hubzilla-0afef6b17e622d1fabd0f499ac206e8924278dfb.tar.gz
volse-hubzilla-0afef6b17e622d1fabd0f499ac206e8924278dfb.tar.bz2
volse-hubzilla-0afef6b17e622d1fabd0f499ac206e8924278dfb.zip
arrays and simple conditional blocks in template, template for nav, load templates from themes
Diffstat (limited to 'include/template_processor.php')
-rw-r--r--include/template_processor.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/include/template_processor.php b/include/template_processor.php
new file mode 100644
index 000000000..f6d0264df
--- /dev/null
+++ b/include/template_processor.php
@@ -0,0 +1,50 @@
+<?php
+
+
+ class Template {
+ var $s;
+ var $r;
+ var $search;
+ var $replace;
+
+ private function _build_replace($r, $prefix){
+
+ if(is_array($r) && count($r)) {
+ foreach ($r as $k => $v ) {
+ if (is_array($v))
+ $this->_build_replace($v, "$prefix$k.");
+
+ $this->search[] = $prefix . $k;
+ $this->replace[] = $v;
+ }
+ }
+ }
+
+ private function _replcb_if($m){
+ //echo "<pre>"; var_dump($m);
+ $keys = explode(".",$m[1]);
+ $val = $this->r;
+ foreach($keys as $k) {
+ $val = $val[$k];
+ }
+
+ //echo $val;
+ return ($val?$m[2]:"");
+ }
+
+ public function replace($s, $r) {
+ $this->s = $s;
+ $this->r = $r;
+ $this->search = array();
+ $this->replace = array();
+
+ $this->_build_replace($r, "");
+
+
+ $s = preg_replace_callback("|{{ *if *([^ }]*) *}}([^{]*){{ *endif *}}|", array($this, "_replcb_if"), $s);
+
+ return str_replace($this->search,$this->replace,$s);
+ }
+
+ }
+ $t = new Template;