Index: trunk/core/kernel/parser/template_parser.php =================================================================== diff -u -N -r8358 -r8605 --- trunk/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 8358) +++ trunk/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 8605) @@ -28,7 +28,7 @@ var $DataExists = false; var $FromPreParseCache = false; - + function TemplateParser() { parent::kBase(); @@ -155,26 +155,28 @@ return $code; } - function AppendCode($code) + function AppendCode($code, $level_offset=0) { + if ($this->RecursionIndex+$level_offset <= 0 ) $level_offset = 0; if (defined('EXPERIMENTAL_PRE_PARSE')) { - if (!isset($this->Code[$this->RecursionIndex])) { - $this->Code[$this->RecursionIndex] = Array(); + if (!isset($this->Code[$this->RecursionIndex+$level_offset])) { + $this->Code[$this->RecursionIndex+$level_offset] = Array(); } if (is_array($code)) { foreach ($code as $line) { - $this->Code[$this->RecursionIndex][] = rtrim($line, "\n")."\n"; + $this->Code[$this->RecursionIndex+$level_offset][] = rtrim($line, "\n")."\n"; } } else { - $this->Code[$this->RecursionIndex][] .= rtrim($code, "\n")."\n"; + $this->Code[$this->RecursionIndex+$level_offset][] .= rtrim($code, "\n")."\n"; } } } - function AppendCompiledFunction($f_name, $f_body) + function PrepareCompiledFunction($f_name, $f_body, $add_reference=true) { $real_name = 'f_'.abs(crc32($this->TemplateName)).'_'.$f_name; + $real_code = ''; if (defined('EXPERIMENTAL_PRE_PARSE')) { // if such function already compiled if ( isset($this->Application->CompiledFunctions[$f_name]) || @@ -189,29 +191,50 @@ } } - $this->CompiledBuffer .= "\t".'$application->PreParsedBlocks[\''.$f_name.'\'] = \''.$real_name.'\';'."\n"; - $this->CompiledBuffer .= 'if (!function_exists(\''.$real_name.'\')) {'."\n"; - $this->CompiledBuffer .= "\t".'function '.$real_name.'($params)'."\n\t{\n"; - $this->CompiledBuffer .= $f_body; - $this->CompiledBuffer .= "\t}\n\n"; - $this->CompiledBuffer .= '}'."\n"; + if (is_array($f_body)) { + $real_body = ''; + foreach ($f_body as $line) { + if (preg_match('/^\/\*LAMBDA-ONLY\*\//', $line)) continue; + $real_body .= "\t\t".rtrim($line, "\n")."\n"; + }; + $f_body = $real_body; + } + else { + $f_body = preg_replace('/\/\*LAMBDA-ONLY\*\/.*/m', '', $f_body); + } - $this->Application->CompiledFunctions[$f_name] = $real_name; + $ref = "\t".'$application->PreParsedBlocks[\''.$f_name.'\'] = \''.$real_name.'\';'."\n"; + if ($add_reference) $real_code .= $ref; + $real_code .= 'if (!function_exists(\''.$real_name.'\')) {'."\n"; + $real_code .= "\t".'function '.$real_name.'($params)'."\n\t{\n"; + $real_code .= $f_body; + $real_code .= "\t}\n\n"; + $real_code .= '}'."\n"; /*if (defined('DEBUG_MODE') && DEBUG_MODE && defined('DBG_PRE_PARSE') && DBG_PRE_PARSE) { // this shows newly compiled functions (blocks) global $debugger; $f_body = "\t".'function '.$real_name.'($params)'."\n\t{\n".$f_body."\t}\n\n"; $debugger->appendHTML($debugger->highlightString($f_body)); }*/ + $this->Application->CompiledFunctions[$f_name] = $real_name; + + return array($real_name, $real_code, $ref); } } + function AppendCompiledFunction($f_name, $f_body) + { + $f = $this->PrepareCompiledFunction($f_name, $f_body); + $this->CompiledBuffer .= $f[1]; + } + function AppendCompiledCode($code) { if (defined('EXPERIMENTAL_PRE_PARSE')) { if (is_array($code)) { foreach ($code as $line) { + if (preg_match('/^\/\*LAMBDA-ONLY\*\//', $line)) continue; $this->CompiledBuffer .= "\t".rtrim($line, "\n")."\n"; } } @@ -333,7 +356,8 @@ } // temporary - for backward compatability with in-portal style if - if ($opening_tag == '' && $tag_part != 'm_if' && $tag_part != 'm_DefineElement') { + $compat_tags = array('m_if', 'm_DefineElement', 'm_Capture', 'm_RenderElement'); + if ($opening_tag == '' && !in_array($tag_part, $compat_tags)) { if (strpos($the_tag, ' ') !== false) { list($function, $params) = explode(' ', $the_tag, 2); } @@ -355,6 +379,8 @@ $tag = '__COMMENT__'; } + if ($closing_tag == '>') $tag .= ' _short_closing_="1"'; + $this->Position = $tag_close_pos + $close_len; return $tag; } @@ -642,11 +668,11 @@ if( !isset($pass_params['PrefixSpecial']) && isset($pass_params['prefix']) ) $pass_params['PrefixSpecial'] = $pass_params['prefix']; $ret = $f($pass_params); - + if (isset($params['return_params']) && $params['return_params']) { $this->ParamsStack[$this->ParamsRecursionIndex - 1] = array_merge($this->ParamsStack[$this->ParamsRecursionIndex - 1], $this->ParamsStack[$this->ParamsRecursionIndex]); } - + unset($this->ParamsStack[$this->ParamsRecursionIndex--]); $this->Params = $this->ParamsStack[$this->ParamsRecursionIndex]; $this->MainParser = true; @@ -681,10 +707,10 @@ $template_name ); } - + $this->Application->Parser =& $this; $this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists; - + return $o; }