Index: branches/unlabeled/unlabeled-1.24.2/core/kernel/parser/template_parser.php =================================================================== diff -u -r5437 -r5726 --- branches/unlabeled/unlabeled-1.24.2/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 5437) +++ branches/unlabeled/unlabeled-1.24.2/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 5726) @@ -61,14 +61,16 @@ return $a_len > $b_len ? -1 : 1; } - function SetParams($params) + function SetParams($params, $for_parsing=true) { if (!is_array($params)) $params = Array(); $this->ForSort = array(); $this->Params = $params; $this->ParamsStack[$this->ParamsRecursionIndex] = $params; + if (!$for_parsing) return ; + foreach ($params as $key => $val) { $this->AddParam('/[{]{0,1}\$'.$key.'[}]{0,1}/i', $val, 1); //Do not sort every time } @@ -90,7 +92,7 @@ function SetParam($name, $value) { $this->Params[strtolower($name)] = $value; - $this->AddParam('/[{]{0,1}\$'.$name.'[}]{0,1}/i', $val, 0); + $this->AddParam('/[{]{0,1}\$'.$name.'[}]{0,1}/i', $value, $this->FromPreParseCache); } function SetBuffer($body) @@ -352,6 +354,97 @@ } } + function ParseTemplate($name, $pre_parse = 1, $params=array()) + { + $this->FromPreParseCache = false; + if ($this->GetParam('from_inportal')) $pre_parse = 0; + if ($pre_parse) { + $pre_parsed = $this->Application->TemplatesCache->GetPreParsed($name); + if ($pre_parsed && $pre_parsed['active']) { // active means good (not expired) pre-parsed cache + $this->FromPreParseCache = true; + $this->SetParams($params, 0); // 0 to disable params sorting and regexp generation - not needed when processing pre-parsed + ob_start(); + if ($pre_parsed['mode'] == 'file') { + include($pre_parsed['fname']); + } + else { + eval('?'.'>'.$pre_parsed['content']); + } + $output = ob_get_contents(); + ob_end_clean(); + } + else { + $this->SetParams($params); + + $this->CompiledBuffer .= '<'.'?php'."\n"; + $this->CompiledBuffer .= 'global $application;'."\n"; + + $this->CompiledBuffer .= '$params =& $application->Parser->Params;'."\n"; + $this->CompiledBuffer .= 'extract($params);'."\n"; + + $this->CompiledBuffer .= '$o = \'\';'."\n"; + + $output = $this->NewParse($this->Application->TemplatesCache->GetTemplateBody($name), $name); + + $this->CompiledBuffer .= '?'.'>'."\n"; + + if (defined('SAFE_MODE') && SAFE_MODE) { + if (!isset($conn)) $conn =& $this->Application->GetADODBConnection(); + $conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ('.$conn->qstr($pre_parsed['fname']).','.$conn->qstr($this->CompiledBuffer).','.adodb_mktime().')'); + } + else { + $compiled = fopen($pre_parsed['fname'], 'w'); + fwrite($compiled, $this->CompiledBuffer); + fclose($compiled); + } + + } + if ( !$this->GetParam('from_inportal') && strpos($output, 'Application->recallObject('Inp1Parser'); + $output = $inp1_parser->NewParse($name, $output); + } + return $output; + } + + // pre-parse is OFF + $this->SetParams($params); + return $this->NewParse($this->Application->TemplatesCache->GetTemplateBody($name), $name, $pre_parse); + } + + function NewParse($template, $name='unknown', $pre_parse = 1) + { + $this->Template = $template; + $this->TemplateName = $name; + $this->Position = 0; + $this->Output = ''; + $this->TagHolder = new MyTagHolder(); + + $has_inp_tags = false; + + if (!getArrayValue($this->Params, 'PrefixSpecial')) { + $this->Params['PrefixSpecial'] = '$PrefixSpecial'; + } + + //While we have more tags + while ($tag_data = $this->FindTag2()) + { + if ($tag_data == '__COMMENT__') continue; + //Create tag object from passed tag data + if( $this->Application->isDebugMode() && constOn('DBG_SHOW_TAGS') ) + { + global $debugger; + $debugger->appendHTML('mode: '.$this->SkipModeName().' tag '.$debugger->highlightString($tag_data).' in '.$debugger->getFileLink($debugger->getLocalFile(FULL_PATH.THEMES_PATH.'/'.$this->TemplateName).'.tpl', $this->CurrentLineNumber(), '', true)); + } + $tag =& $this->TagHolder->GetTag($tag_data, $this); + + if (!$this->CheckRecursion($tag)) //we do NOT process closing tags + { + $tag->Process(); + } + } + return $this->Output; + } + function Parse($template, $name='unknown', $pre_parse = 1) { $this->Template = $template; @@ -365,16 +458,15 @@ if ($this->GetParam('from_inportal')) $pre_parse = 0; if (defined('EXPERIMENTAL_PRE_PARSE') && $pre_parse) { - $template_cache =& $this->Application->recallObject('TemplatesCache'); - $fname = $template_cache->GetRealFilename($this->TemplateName).'.php'; + $fname = $this->Application->TemplatesCache->GetRealFilename($this->TemplateName).'.php'; $fname = str_replace(FULL_PATH, FULL_PATH.'/kernel/cache', $fname); if (!defined('SAFE_MODE') || !SAFE_MODE) { $this->CheckDir(dirname($fname)); } - $tname = $template_cache->GetRealFilename($this->TemplateName).'.tpl'; + $tname = $this->Application->TemplatesCache->GetRealFilename($this->TemplateName).'.tpl'; $output = ''; $is_cached = false; ob_start();