]> git.mxchange.org Git - friendica.git/commitdiff
template proc: add variable filters
authorFabio Comuni <fabrix.xm@gmail.com>
Fri, 2 Mar 2012 16:22:16 +0000 (17:22 +0100)
committerFabio Comuni <fabrix.xm@gmail.com>
Fri, 2 Mar 2012 16:22:16 +0000 (17:22 +0100)
include/template_processor.php

index 111fc5849a7b8af9041ffe465653722bfd3b464e..90c6b2e650374cf52232a96b2d0ed3ebe5c703a0 100755 (executable)
 
                private function var_replace($s){
                        $m = array();
-                       if (preg_match_all('/\$\[{0,1}([a-zA-Z0-9-_]+\.*)+\]{0,1}/', $s,$m)){
-                               foreach($m[0] as $var){
-                                       $varn = str_replace(array("[","]"), array("",""), $var);
-                                       $val = $this->_get_var($varn, true);
+                       if (preg_match_all('/(\$\[{0,1}([a-zA-Z0-9-_]+\.*)+)(\|[a-zA-Z0-9-_]+)*\]{0,1}/', $s,$m)){
+                               foreach($m[1] as $id=>$var){
+                                       $var = str_replace("[", "", $var);
+                                       $val = $this->_get_var($var, true);
+                                       
+                                       // apply filters
+                                       if ($m[3][$id]!=""){
+                                               $filters = explode("|",trim($m[3][$id],"|"));
+                                               foreach($filters as $filter)
+                                                       if (function_exists($filter)) 
+                                                               $val=$filter($val);
+                                       }
                                        if ($val!=KEY_NOT_EXISTS)
-                                               $s = str_replace($var, $val, $s);
+                                               $s = str_replace($m[0][$id], $val, $s);
                                }
                        }
                        
+                       
+                       
                        return $s;
                }