]> git.mxchange.org Git - friendica.git/blobdiff - include/template_processor.php
Mostly some checks in order to avoid Notices; 1 real bugfix in /mod/network.php
[friendica.git] / include / template_processor.php
index 0d476f0e6e63f54a15f88dc69ebd514f58a22934..7a4cba64e93b4e5aab9f5d817d315cb4e410faed 100755 (executable)
        
                        if(is_array($r) && count($r)) {
                                foreach ($r as $k => $v ) {
-                                       if (is_array($v))
+                                       if (is_array($v)) {
                                                $this->_build_replace($v, "$prefix$k.");
-                                       
-                                       $this->search[] =  $prefix . $k;
-                                       $this->replace[] = $v;
+                                       } else {
+                                               $this->search[] =  $prefix . $k;
+                                               $this->replace[] = $v;
+                                       }
                                }
                        }
                } 
@@ -53,7 +54,7 @@
                        $keys = array_map('trim',explode(".",$name));           
                        $val = $this->r;
                        foreach($keys as $k) {
-                               $val = $val[$k];
+                               $val = (isset($val[$k]) ? $val[$k] : null);
                        }
                        return $val;
                }
@@ -79,8 +80,8 @@
                        } else {
                                $val = $this->_get_var($args[2]);
                        }
-                       list($strue, $sfalse)= preg_split("|{{ *else *}}|", $args[3]);
-                       return ($val?$strue:$sfalse);
+                       $x = preg_split("|{{ *else *}}|", $args[3]);
+                       return ( $val ? $x[0] : (isset($x[1]) ? $x[1] : ""));
                }
                
                /**
                 */
                private function _replcb_for($args){
                        $m = array_map('trim', explode(" as ", $args[2]));
-                       list($keyname, $varname) = explode("=>",$m[1]);
-                       if (is_null($varname)) { $varname=$keyname; $keyname=""; }
+                       $x = explode("=>",$m[1]);
+                       if (count($x) == 1) {
+                               $varname = $x[0];
+                               $keyname = "";
+                       } else {
+                               list($keyname, $varname) = $x;
+                       }
                        if ($m[0]=="" || $varname=="" || is_null($varname)) die("template error: 'for ".$m[0]." as ".$varname."'") ;
                        //$vals = $this->r[$m[0]];
                        $vals = $this->_get_var($m[0]);
                        krsort($this->nodes);
                        return $s;
                }
-
+               
+        /*
                private function _str_replace($str){
                        #$this->search,$this->replace,
                        $searchs = $this->search;
                                
                        }
                        return str_replace($this->search,$this->replace, $str);
-               }
+               }*/
 
        
                public function replace($s, $r) {
                        $os = ""; $count=0;
                        while($os!=$s && $count<10){
                                $os=$s; $count++;
-                               $s = $this->_str_replace($s);
+                               //$s = $this->_str_replace($s);
+                               $s = str_replace($this->search, $this->replace, $s);
                        }
                        return template_unescape($s);
                }