]> git.mxchange.org Git - friendica.git/commitdiff
template: add support for variable filters
authorFabio Comuni <fabrix.xm@gmail.com>
Tue, 21 Feb 2012 10:25:22 +0000 (11:25 +0100)
committerFabio Comuni <fabrix.xm@gmail.com>
Tue, 21 Feb 2012 10:25:22 +0000 (11:25 +0100)
include/template_processor.php

index 25f7703a2192cfe4b41a76c958c35514bb75fe45..0d476f0e6e63f54a15f88dc69ebd514f58a22934 100755 (executable)
@@ -10,7 +10,7 @@
                var $done = false;
                var $d = false;
                var $lang = null;
-               
+               var $debug=false;
                
                private function _preg_error(){
                        switch(preg_last_error()){
                        return $s;
                }
 
+               private function _str_replace($str){
+                       #$this->search,$this->replace,
+                       $searchs = $this->search;
+                       foreach($searchs as $search){
+                               $search = "|".preg_quote($search)."(\|[a-zA-Z0-9_]*)*|";
+                               $m = array();
+                               if (preg_match_all($search, $str,$m)){
+                                       foreach ($m[0] as $match){
+                                               $toks = explode("|",$match);
+                                               $val = $this->_get_var($toks[0]);
+                                               for($k=1; $k<count($toks); $k++){
+                                                       $func = $toks[$k];
+                                                       if (function_exists($func)) $val = $func($val);
+                                               }
+                                               if (count($toks)>1){
+                                                       $str = str_replace( $match, $val, $str);
+                                               } 
+                                       }
+                               }
+                               
+                       }
+                       return str_replace($this->search,$this->replace, $str);
+               }
+
        
                public function replace($s, $r) {
                        $this->r = $r;
                        $os = ""; $count=0;
                        while($os!=$s && $count<10){
                                $os=$s; $count++;
-                               $s = str_replace($this->search,$this->replace, $s);
+                               $s = $this->_str_replace($s);
                        }
                        return template_unescape($s);
                }