private function parse_all(&$str)
    {
        // php include
//         $str = preg_replace ( "/\{include\s+(.+)\}/", "<?php include \\1;?\>", $str );
        
        // php code, 内容分析到 '}', 可能会有问题？
        $str = preg_replace ( "/\{php\s+([^\}]+)\}/", "<?php \\1?>", $str );
        
        // if else
        $str = preg_replace ( "/\{if\s+(.+?)\}/", "<?php if(\\1) { ?>", $str );
        $str = preg_replace ( "/\{else\}/", "<?php } else { ?>", $str );
        $str = preg_replace ( "/\{elseif\s+(.+?)\}/", "<?php } elseif (\\1) { ?>", $str );
        $str = preg_replace ( "/\{\/if\}/", "<?php } ?>", $str );
        
        // for : {for($i=1; $i<10; $i++)}
        $str = preg_replace("/\{for\s+\(?(.+?)\)?\}/","<?php for(\\1) { ?>", $str);
        $str = preg_replace("/\{\/for\}/", "<?php } ?>", $str);
        
        // foreach : 
        // 1. {foreach($array as [$key=>] $value)}
        // 2. {foreach $array $value}
        // 3. {foreach $array $key $value}
        $str = preg_replace("/\{(foreach|loop)\s+\(((\S+).+?)\)\}/","<?php if(isset(\\3) && is_array(\\3)) foreach(\\2) { ?>", $str);
        $str = preg_replace("/\{(foreach|loop)\s+(\S+)\s+(?:as\s+)*(\S+)\}/", "<?php if(isset(\\2) && is_array(\\2)) foreach(\\2 as \\3) {?>", $str );
        $str = preg_replace("/\{(foreach|loop)\s+(\S+)\s+(?:as\s+)*(\S+)\s+(\S+)\}/", "<?php if(isset(\\2) && is_array(\\2)) foreach(\\2 as \\3 => \\4){?>", $str );
        $str = preg_replace("/\{\/(foreach|loop)\}/", "<?php } ?>", $str );
        
        // ++ --
        $str = preg_replace("/\{\+\+(.+?)\}/", "<?php ++\\1; ?>", $str);
        $str = preg_replace("/\{\-\-(.+?)\}/", "<?php ++\\1; ?>", $str);
        $str = preg_replace("/\{(.+?)\+\+\}/", "<?php \\1++; ?>", $str);
        $str = preg_replace("/\{(.+?)\-\-\}/", "<?php \\1--; ?>", $str);
        
        // {widget:name action='method'...}  调用标签方法
        $str = preg_replace_callback("/\{widget:?([\w\:]+)?\s+([^}]+)\}/i", array($this,'widget_callback'), $str);
        $str = preg_replace_callback("/\{\/widget[^}]*\}/i", array($this, 'end_widget_callback'), $str);
        
        // include sub template: {include 'header'}
        $str = preg_replace_callback( "/\{(template|include|layout)\s+(.+)\}/", array($this, 'parse_callback'), $str );
        
        // function or var: {function(...)} or {$data}
        $str = $this->parse_fun_var($str);
        
        // add permission
        
        return $str;
    }