]> git.mxchange.org Git - friendica.git/blobdiff - include/template_processor.php
added spaces + some curly braces + some usage of dbm::is_result()
[friendica.git] / include / template_processor.php
index 6c5908d92e8d8f1d1c5f318bb868c3c6199d1f55..252375a0605270a934236d9cb9a2cc5c7b09ee6f 100644 (file)
@@ -1,9 +1,16 @@
 <?php
+/*
+ * This is the old template engine, now deprecated.
+ * Friendica's default template engine is Smarty3 (see include/friendica_smarty.php)
+ * 
+ */
+require_once 'object/TemplateEngine.php';
 
 define("KEY_NOT_EXISTS", '^R_key_not_Exists^');
 
-class Template {
-
+class Template implements ITemplateEngine {
+       static $name ="internal";
+       
        var $r;
        var $search;
        var $replace;
@@ -62,7 +69,7 @@ class Template {
         * {{ if <$var>==<val|$var> }}...[{{ else }} ...]{{ endif }}
         * {{ if <$var>!=<val|$var> }}...[{{ else }} ...]{{ endif }}
         */
-       private function _replcb_if($args) {
+       private function _replcb_if ($args) {
                if (strpos($args[2], "==") > 0) {
                        list($a, $b) = array_map("trim", explode("==", $args[2]));
                        $a = $this->_get_var($a);
@@ -88,7 +95,7 @@ class Template {
         * {{ for <$var> as $name }}...{{ endfor }}
         * {{ for <$var> as $key=>$name }}...{{ endfor }}
         */
-       private function _replcb_for($args) {
+       private function _replcb_for ($args) {
                $m = array_map('trim', explode(" as ", $args[2]));
                $x = explode("=>", $m[1]);
                if (count($x) == 1) {
@@ -102,14 +109,16 @@ class Template {
                //$vals = $this->r[$m[0]];
                $vals = $this->_get_var($m[0]);
                $ret = "";
-               if (!is_array($vals))
+               if (!is_array($vals)) {
                        return $ret;
+               }
                foreach ($vals as $k => $v) {
                        $this->_push_stack();
                        $r = $this->r;
                        $r[$varname] = $v;
-                       if ($keyname != '')
+                       if ($keyname != '') {
                                $r[$keyname] = (($k === 0) ? '0' : $k);
+                       }
                        $ret .= $this->replace($args[3], $r);
                        $this->_pop_stack();
                }
@@ -256,18 +265,19 @@ class Template {
                return $s;
        }
 
-       public function replace($s, $r) {
+       // TemplateEngine interface
+       public function replace_macros($s, $r) {
                $this->r = $r;
 
+               // remove comments block
+               $s = preg_replace('/{#(.*?\s*?)*?#}/', "", $s);
+
                $s = $this->_build_nodes($s);
 
                $s = preg_replace_callback('/\|\|([0-9]+)\|\|/', array($this, "_replcb_node"), $s);
                if ($s == Null)
                        $this->_preg_error();
 
-               // remove comments block
-               $s = preg_replace('/{#[^#]*#}/', "", $s);
-
                // replace strings recursively (limit to 10 loops)
                $os = "";
                $count = 0;
@@ -276,12 +286,18 @@ class Template {
                        $count++;
                        $s = $this->var_replace($s);
                }
-               return $s;
+               return template_unescape($s);
        }
-
+       
+       public function get_template_file($file, $root='') {
+               $a = get_app();
+               $template_file = get_template_file($a, $file, $root);
+               $content = file_get_contents($template_file);
+               return $content;                
+       }
+       
 }
 
-$t = new Template;
 
 function template_escape($s) {