]> git.mxchange.org Git - friendica.git/blobdiff - include/template_processor.php
truncate overflow text on acl selector items (3 themes)
[friendica.git] / include / template_processor.php
index be40a31ab52b6c1ca595038809137ac52bd20bf7..83f680f0262a43983f11bbaaf2732e95b2ef4808 100644 (file)
@@ -7,6 +7,7 @@
                var $stack = array();
                var $nodes = array();
                var $done = false;
+               var $d = false;
                
                private function _preg_error(){
                        switch(preg_last_error()){
@@ -16,7 +17,8 @@
                            case PREG_BAD_UTF8_ERROR: die('PREG_BAD_UTF8_ERROR'); break;
                            case PREG_BAD_UTF8_OFFSET_ERROR: die('PREG_BAD_UTF8_OFFSET_ERROR'); break;
                            default:
-                                       die("Unknown preg error.");
+                                       //die("Unknown preg error.");
+                                       return;
                        }
                }
                
                }
                private function _pop_stack(){
                        list($this->r, $this->search, $this->replace, $this->nodes) = array_pop($this->stack);
+                       
                }
                
                private function _get_var($name){
-                       $keys = array_map('trim',explode(".",$name));                   
+                       $keys = array_map('trim',explode(".",$name));           
                        $val = $this->r;
                        foreach($keys as $k) {
                                $val = $val[$k];
@@ -57,7 +60,6 @@
                 * {{ if <$var>!=<val|$var> }}...[{{ else }} ...]{{ endif }}
                 */
                private function _replcb_if($args){
-                       
                        if (strpos($args[2],"==")>0){
                                list($a,$b) = array_map("trim",explode("==",$args[2]));
                                $a = $this->_get_var($a);
                        } else {
                                $val = $this->_get_var($args[2]);
                        }
-                       if (isset($args[4])) {
-                               list($strue, $sfalse)= explode($args[4], $args[3]);
-                       } else {
-                               $strue = $args[3]; $sfalse = "";
-                       }
-                       
+                       list($strue, $sfalse)= preg_split("|{{ *else *}}|", $args[3]);
                        return ($val?$strue:$sfalse);
                }
                
                                $s = "";
                        }
                        $s = preg_replace_callback('/\|\|([0-9]+)\|\|/', array($this, "_replcb_node"), $s);
-                       if ($s==Null) $this->_preg_error()      
                        return $s;
                }
                                                
                        #$s = str_replace(array("\n","\r"),array("§n§","§r§"),$s);
                        $s = $this->_build_nodes($s);
                        $s = preg_replace_callback('/\|\|([0-9]+)\|\|/', array($this, "_replcb_node"), $s);
-                       if ($s==Null) $this->_preg_error()
-                       $s = str_replace($this->search,$this->replace, $s);
+                       if ($s==Null) $this->_preg_error();
                        
+                       // replace strings recursively (limit to 10 loops)
+                       $os = ""; $count=0;
+                       while($os!=$s && $count<10){
+                               $os=$s; $count++;
+                               $s = str_replace($this->search,$this->replace, $s);
+                       }
                        return $s;
                }
        }