ok ho trovato la funzione compile... è un po' lunghetta; prima di capire dove sostituisce gli elementi inclusi in { } nei template diventerò vecchio

[supersaibal]
Codice PHP:
    function compile($code$do_not_echo false$retvar '')
    {
        
// replace \ with \\ and then ' with \'.
        
$code str_replace('\\''\\\\'$code);
        
$code str_replace('\'''\\\''$code);

        
// change template varrefs into PHP varrefs

        // This one will handle varrefs WITH namespaces
        
$varrefs = array();
        
preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is'$code$varrefs);
        
$varcount sizeof($varrefs[1]);
        for (
$i 0$i $varcount$i++)
        {
            
$namespace $varrefs[1][$i];
            
$varname $varrefs[3][$i];
            
$new $this->generate_block_varref($namespace$varname);

            
$code str_replace($varrefs[0][$i], $new$code);
        }

        
// This will handle the remaining root-level varrefs
        
$code preg_replace('#\{([a-z0-9\-_]*?)\}#is''\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \''$code);

        
// Break it up into lines.
        
$code_lines explode("\n"$code);

        
$block_nesting_level 0;
        
$block_names = array();
        
$block_names[0] = ".";

        
// Second: prepend echo ', append ' . "\n"; to each line.
        
$line_count sizeof($code_lines);
        for (
$i 0$i $line_count$i++)
        {
            
$code_lines[$i] = chop($code_lines[$i]);
            if (
preg_match('##'$code_lines[$i], $m))
            {
                
$n[0] = $m[0];
                
$n[1] = $m[1];

                
// Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think. :)
                
if ( preg_match('##'$code_lines[$i], $n) )
                {
                    
$block_nesting_level++;
                    
$block_names[$block_nesting_level] = $m[1];
                    if (
$block_nesting_level 2)
                    {
                        
// Block is not nested.
                        
$code_lines[$i] = '$_' $n[1] . '_count = ( isset($this->_tpldata[\'' $n[1] . '.\']) ) ?  sizeof($this->_tpldata[\'' $n[1] . '.\']) : 0;';
                        
$code_lines[$i] .= "\n" 'for ($_' $n[1] . '_i = 0; $_' $n[1] . '_i < $_' $n[1] . '_count; $_' $n[1] . '_i++)';
                        
$code_lines[$i] .= "\n" '{';
                    }
                    else
                    {
                        
// This block is nested.

                        // Generate a namespace string for this block.
                        
$namespace implode('.'$block_names);
                        
// strip leading period from root level..
                        
$namespace substr($namespace2);
                        
// Get a reference to the data array for this block that depends on the
                        // current indices of all parent blocks.
                        
$varref $this->generate_block_data_ref($namespacefalse);
                        
// Create the for loop code to iterate over this block.
                        
$code_lines[$i] = '$_' $n[1] . '_count = ( isset(' $varref ') ) ? sizeof(' $varref ') : 0;';
                        
$code_lines[$i] .= "\n" 'for ($_' $n[1] . '_i = 0; $_' $n[1] . '_i < $_' $n[1] . '_count; $_' $n[1] . '_i++)';
                        
$code_lines[$i] .= "\n" '{';
                    }

                    
// We have the end of a block.
                    
unset($block_names[$block_nesting_level]);
                    
$block_nesting_level--;
                    
$code_lines[$i] .= '} // END ' $n[1];
                    
$m[0] = $n[0];
                    
$m[1] = $n[1];
                }
                else
                {
                    
// We have the start of a block.
                    
$block_nesting_level++;
                    
$block_names[$block_nesting_level] = $m[1];
                    if (
$block_nesting_level 2)
                    {
                        
// Block is not nested.
                        
$code_lines[$i] = '$_' $m[1] . '_count = ( isset($this->_tpldata[\'' $m[1] . '.\']) ) ? sizeof($this->_tpldata[\'' $m[1] . '.\']) : 0;';
                        
$code_lines[$i] .= "\n" 'for ($_' $m[1] . '_i = 0; $_' $m[1] . '_i < $_' $m[1] . '_count; $_' $m[1] . '_i++)';
                        
$code_lines[$i] .= "\n" '{';
                    }
                    else
                    {
                        
// This block is nested.

                        // Generate a namespace string for this block.
                        
$namespace implode('.'$block_names);
                        
// strip leading period from root level..
                        
$namespace substr($namespace2);
                        
// Get a reference to the data array for this block that depends on the
                        // current indices of all parent blocks.
                        
$varref $this->generate_block_data_ref($namespacefalse);
                        
// Create the for loop code to iterate over this block.
                        
$code_lines[$i] = '$_' $m[1] . '_count = ( isset(' $varref ') ) ? sizeof(' $varref ') : 0;';
                        
$code_lines[$i] .= "\n" 'for ($_' $m[1] . '_i = 0; $_' $m[1] . '_i < $_' $m[1] . '_count; $_' $m[1] . '_i++)';
                        
$code_lines[$i] .= "\n" '{';
                    }
                }
            }
            else if (
preg_match('##'$code_lines[$i], $m))
            {
                
// We have the end of a block.
                
unset($block_names[$block_nesting_level]);
                
$block_nesting_level--;
                
$code_lines[$i] = '} // END ' $m[1];
            }
            else
            {
                
// We have an ordinary line of code.
                
if (!$do_not_echo)
                {
                    
$code_lines[$i] = 'echo \'' $code_lines[$i] . '\' . "\\n";';
                }
                else
                {
                    
$code_lines[$i] = '$' $retvar '.= \'' $code_lines[$i] . '\' . "\\n";'
                }
            }
        }

        
// Bring it back into a single string of lines of code.
        
$code implode("\n"$code_lines);
        return 
$code    ;

    } 
[/supersaibal]