X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Ftemplate_processor.php;h=252375a0605270a934236d9cb9a2cc5c7b09ee6f;hb=05393a6faaa130450ee024a37aafd3f1508d2f9f;hp=ebc03b8d84404907e350ec4367bf19e9d40a0299;hpb=a5ac69c65e3910b4c645b1e544df217d7aca0fdd;p=friendica.git diff --git a/include/template_processor.php b/include/template_processor.php index ebc03b8d84..252375a060 100644 --- a/include/template_processor.php +++ b/include/template_processor.php @@ -1,9 +1,16 @@ == }}...[{{ else }} ...]{{ endif }} * {{ if <$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,7 +265,8 @@ class Template { return $s; } - public function replace($s, $r) { + // TemplateEngine interface + public function replace_macros($s, $r) { $this->r = $r; // remove comments block @@ -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) {