Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sun, Apr 20, 4:13 PM

in-portal

Index: branches/5.0.x/core/kernel/parser/template_parser.php
===================================================================
--- branches/5.0.x/core/kernel/parser/template_parser.php (revision 12310)
+++ branches/5.0.x/core/kernel/parser/template_parser.php (nonexistent)
@@ -1,771 +0,0 @@
-<?php
-/**
-* @version $Id$
-* @package In-Portal
-* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
-* @license GNU/GPL
-* In-Portal is Open Source software.
-* This means that this software may have been modified pursuant
-* the GNU General Public License, and as distributed it includes
-* or is derivative of works licensed under the GNU General Public License
-* or other free or open source software licenses.
-* See http://www.in-portal.net/license/ for copyright notices and details.
-*/
-
-defined('FULL_PATH') or die('restricted access!');
-
-k4_include_once(KERNEL_PATH.'/parser/tags.php');
-k4_include_once(KERNEL_PATH.'/parser/construct_tags.php');
-
-class TemplateParser extends kBase {
- var $Template;
- var $Output = '';
- var $Position = 0;
- var $LastPosition = 0;
-
- var $Ses;
- var $Recursion = Array();
- var $RecursionIndex = 0;
- var $SkipMode = 0;
- var $Params = Array();
- var $Pattern = Array();
- var $ForSort = Array();
- var $Values = Array();
- var $Buffers = Array();
- var $Args;
-
- var $ParamsRecursionIndex = 0;
- var $ParamsStack = Array();
-
- var $CompiledBuffer;
-
- var $DataExists = false;
-
- var $FromPreParseCache = false;
-
- function TemplateParser()
- {
- parent::kBase();
- $this->Ses =& $this->Application->recallObject('Session');
- }
-
- function AddParam($pattern, $value, $dont_sort=0)
- {
- $this->ForSort[] = Array($pattern, $value);
- if (!$dont_sort) //used when mass-adding params, to escape sorting after every new param
- $this->SortParams(); //but do sort by default!
- }
-
- //We need to sort params by its name length desc, so that params starting with same word get parsed correctly
- function SortParams()
- {
- uasort($this->ForSort, array ("TemplateParser", "CmpParams"));
-
-// commented out by Kostja, otherwise when rednerElement is done into var (result_to_var) the other params are reset
-// $this->Pattern = Array();
-// $this->Values = Array();
- foreach($this->ForSort as $pair)
- {
- $this->Pattern[] = $pair[0];
- $this->Values[] = $pair[1];
- }
- }
-
- function CmpParams($a, $b)
- {
- $a_len = strlen($a[0]);
- $b_len = strlen($b[0]);
- if ($a_len == $b_len) return 0;
- return $a_len > $b_len ? -1 : 1;
- }
-
- 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
- }
- $this->SortParams(); //Sort once after adding is done
- }
-
- /**
- * Returns parser parameter value at specified deep level
- *
- * @param string $name
- * @param int $deep_level if greather then 0 then use from ParamsStack
- * @return mixed
- */
- function GetParam($name, $deep_level = 0)
- {
- if ($deep_level > 0) {
- return isset($this->ParamsStack[$deep_level][$name]) ? $this->ParamsStack[$deep_level][$name] : false;
- }
-
- return isset($this->Params[$name]) ? $this->Params[$name] : false;
- }
-
- /**
- * Set's template parser parameter, that could be retrieved from template
- *
- * @param string $name
- * @param mixed $value
- */
- function SetParam($name, $value)
- {
- $this->Params[strtolower($name)] = $value;
- $this->AddParam('/[{]{0,1}\$'.$name.'[}]{0,1}/i', $value, $this->FromPreParseCache);
- $this->ParamsStack[$this->ParamsRecursionIndex][$name] = $value;
- }
-
- function SetBuffer($body)
- {
- $this->Buffers[$this->RecursionIndex] = $body;
- }
-
- function GetBuffer()
- {
- return $this->Buffers[$this->RecursionIndex];
- }
-
- function GetCode()
- {
- return $this->Code[$this->RecursionIndex];
- }
-
- function AppendBuffer($append)
- {
- $this->Buffers[$this->RecursionIndex] .= $append;
- $this->AppendCode( $this->ConvertToCode($append) );
- }
-
- function AppendOutput($append, $append_code=false)
- {
- if ($this->SkipMode == parse) {
- $this->Output .= $append; //append to Ouput only if we are parsing
- if ($append_code) $this->AppendCompiledHTML($append);
- }
- elseif ($this->SkipMode == skip) {
- if ($append_code) $this->AppendCompiledHTML($append);
- }
- elseif ($this->SkipMode == skip_tags) {
- $this->AppendBuffer($append); //append to buffer if we are skipping tags
- }
- }
-
- function ConvertToCode($data)
- {
- $data = str_replace("\\", "\\\\", $data); // escape any "\"
- $data = str_replace("'", "\'", $data); // escape "'"
-
- $code = '$o .= \''. $data .'\';';
- $code = explode("\n", $code);
- return $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+$level_offset])) {
- $this->Code[$this->RecursionIndex+$level_offset] = Array();
- }
- if (is_array($code)) {
- foreach ($code as $line) {
- $this->Code[$this->RecursionIndex+$level_offset][] = rtrim($line, "\n")."\n";
- }
- }
- else {
- $this->Code[$this->RecursionIndex+$level_offset][] .= rtrim($code, "\n")."\n";
- }
- }
- }
-
- 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]) ||
- function_exists($real_name)
- )
- {
- if (!isset($this->Application->CompiledFunctions[$f_name])) {
- $real_name = $real_name.'_';
- }
- else {
- $real_name = $this->Application->CompiledFunctions[$f_name].'_';
- }
- }
-
- 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);
- }
-
- $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";
- }
- }
- else {
- $this->CompiledBuffer .= $code;
- }
- $this->CompiledBuffer .= "\t".'echo $o;'."\n\t".'$o = \'\';'."\n";
- }
- }
-
- function AppendCompiledHTML($append)
- {
- if (defined('EXPERIMENTAL_PRE_PARSE')) {
- $this->CompiledBuffer .= '?'.'>'."\n";
- $this->CompiledBuffer .= rtrim($append, "\t");
- $this->CompiledBuffer .= '<'.'?php'."\n";
- }
- }
-
- function ResetCode()
- {
- $this->Code[$this->RecursionIndex] = Array();
- }
-
- function FindTag2()
- {
- $openings = Array('<%' => '%>', '<inp2:' => Array('>', '/>'), '</inp2:' => '>', '</inp2>' => '', '<!--' => '-->');
-
- $tag_open_pos = false;
- foreach ($openings as $an_opening => $closings) {
- $pos = strpos($this->Template, $an_opening, $this->Position);
- if ($pos !== false && ($tag_open_pos === false || (int) $pos <= (int) $tag_open_pos)) {
- $tag_open_pos = $pos;
- $open_len = strlen($an_opening);
- $opening_tag = $an_opening;
- $tag_closings = $closings;
- }
- }
-
- if ($tag_open_pos === false) { //If no tags left - adding all other data
- $this->AppendOutput(substr($this->Template, $this->Position), true);
- return false;
- }
-
- //Adding all data before tag open
- $this->AppendOutput(substr($this->Template, $this->Position, $tag_open_pos - $this->Position), true);
-
- if (is_array($tag_closings)) {
- $tag_close_pos = false;
- foreach ($tag_closings as $a_closing) {
- $pos = strpos($this->Template, $a_closing, $tag_open_pos);
- if ($pos !== false && ($tag_close_pos === false || (int) $pos <= (int) $tag_close_pos)) {
- $tag_close_pos = $pos;
- $closing_tag = $a_closing;
- }
- }
- }
- elseif ($opening_tag == '</inp2>') {
- $closing_tag = '';
- $tag_close_pos = $tag_open_pos + $open_len;
- }
- else {
- $closing_tag = $tag_closings;
- $tag_close_pos = strpos($this->Template, $closing_tag, $tag_open_pos);
- }
- $close_len = strlen($closing_tag);
-
-
- // Cutting trailing line-breaks after tags (same way PHP does it)
- if (substr($this->Template, $tag_close_pos+$close_len, 2) == "\r\n") {
- $this->Template = substr_replace($this->Template, '', $tag_close_pos, 2);
- }
- elseif (substr($this->Template, $tag_close_pos+$close_len, 1) == "\n") {
- $this->Template = substr_replace($this->Template, '', $tag_close_pos, 1);
- }
-
-
- //Cutting out the tag itself
- $tag = substr($this->Template, $tag_open_pos + $open_len, $tag_close_pos - $tag_open_pos - $open_len);
-
-
- if ($opening_tag == '<inp2:') {
- //getting prefix_tag upto first space, tab or line break into regs[1]
- preg_match("/^([^ \t\n]*)(.*)/", $tag, $regs);
- $tag_part = $regs[1];
-
- if (strpos($tag_part, '_') !== false) {
- list($prefix, $the_tag) = explode('_', $tag, 2);
- /*preg_match('/(.*)_(.*)/', $tag_part, $rets);
- $prefix = $rets[1];
- $the_tag = $rets[2].$regs[2];*/
-
- $tag = $prefix.':'.$the_tag;
- }
- else {
- $the_tag = $tag;
- $tag = ':'.$tag;
- }
- }
-
- if ($opening_tag == '</inp2>') { //empty closing means old style in-portal if <inp2:tag>....</inp2>
- $tag = 'm:endif';
- }
-
- if ($opening_tag == '</inp2:') {
- preg_match("/^([^ \t\n]*)(.*)/", $tag, $regs);
- $tag_part = $regs[1];
- if (strpos($tag_part, '_') !== false) {
- list($prefix, $the_tag) = explode('_', $tag, 2);
- $tag = $prefix.':'.$the_tag;
- }
- $tag .= ' _closing_tag_="1"';
- }
-
- // if there is no prefix for the tag
- if (strpos($tag, ':') === 0) {
- $prefix = getArrayValue($this->Params, 'PrefixSpecial');
- $tag = $prefix.$tag.' _auto_prefix_="1"';
- }
-
- // temporary - for backward compatability with in-portal style if
- $compat_tags = array('m_if', 'm_DefineElement', 'm_Capture', 'm_RenderElement');
- if ($opening_tag == '<inp2:' && $closing_tag == '>' && !in_array($tag_part, $compat_tags)) {
- if (strpos($the_tag, ' ') !== false) {
- list($function, $params) = explode(' ', $the_tag, 2);
- }
- else {
- $function = $the_tag;
- $params = '';
- }
- $tag = 'm:if prefix="'.$prefix.'" function="'.$function.'" '.$params;
- }
-
- if ($opening_tag == '<!--') {
- if ($this->Application->IsAdmin()) {
- $this->AppendOutput('<!-- '.htmlspecialchars($tag). '-->');
- }
- else {
- $this->AppendOutput('<!-- '.$tag. '-->');
- $this->AppendCompiledHTML('<!-- '.$tag. '-->');
- }
- $tag = '__COMMENT__';
- }
-
- if ($closing_tag == '>') $tag .= ' _short_closing_="1"';
-
- $this->Position = $tag_close_pos + $close_len;
- return $tag;
- }
-
- function CurrentLineNumber()
- {
- return substr_count(substr($this->Template, 0, $this->Position), "\n")+1;
- }
-
- function SkipModeName()
- {
- switch ($this->SkipMode) {
- case skip: return 'skip';
- case skip_tags: return 'skip_tags';
- case parse: return 'parse';
- }
- }
-
- /**
- * Recursive mkdir
- *
- * @param string $dir
- * @param string $base_path base path to directory where folders should be created in
- */
- function CheckDir($dir, $base_path = '')
- {
- if (file_exists($dir)) {
- return;
- }
- else {
- // remove $base_path from beggining because it is already created during install
- $dir = preg_replace('/^'.preg_quote($base_path.'/', '/').'/', '', $dir, 1);
- $segments = explode('/', $dir);
- $cur_path = $base_path;
-
- foreach ($segments as $segment) {
- // do not add leading / for windows paths (c:\...)
- $cur_path .= preg_match('/^[a-zA-Z]{1}:/', $segment) ? $segment : '/'.$segment;
- if (!file_exists($cur_path)) {
- mkdir($cur_path);
- }
- }
- }
- }
-
- function ParseTemplate($name, $pre_parse = 1, $params=array(), $silent=0)
- {
- if ((strpos($name, '../') !== false) || (trim($name) !== $name)) {
- // when relative paths or special chars are found template names from url, then it's hacking attempt
- return false;
- }
-
- $this->FromPreParseCache = false;
- if ($this->GetParam('from_inportal')) $pre_parse = 0;
- if ($pre_parse) {
- $pre_parsed = $this->Application->TemplatesCache->GetPreParsed($name);
- if ($pre_parsed === false) {
- // template not found -> don't compile
- return '';
- }
-
- 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') {
- $this->TemplateName = str_replace(FULL_PATH, '', realpath($pre_parsed['fname']));
- 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";
-
- $body = $this->Application->TemplatesCache->GetTemplateBody($name, $silent);
- $this->TemplateName = $name;
- $output = $this->NewParse($body, $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, '<inp:') !== false) {
- $inp1_parser =& $this->Application->recallObject('Inp1Parser');
-// $name = $this->Application->TemplatesCache->GetTemplateFileName($name) . '-block:' . $name; // may be is needed (by Alex)
- $output = $inp1_parser->Parse($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;
- $this->TemplateName = $name;
- $this->Position = 0;
- $this->Output = '';
- $this->TagHolder = new MyTagHolder();
-
- $has_inp_tags = false;
-
- if ($this->GetParam('from_inportal')) $pre_parse = 0;
-
- if (defined('EXPERIMENTAL_PRE_PARSE') && $pre_parse) {
- $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), FULL_PATH.'/kernel/cache');
- }
-
- $tname = $this->Application->TemplatesCache->GetRealFilename($this->TemplateName).'.tpl';
- $output = '';
- $is_cached = false;
- ob_start();
- if (defined('SAFE_MODE') && SAFE_MODE) {
- $conn =& $this->Application->GetADODBConnection();
- $cached = $conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'Cache WHERE VarName = "'.$fname.'"');
- if ($cached !== false && $cached['Cached'] > filemtime($tname)) {
- eval('?'.'>'.$cached['Data']);
- $is_cached = true;
- }
- }
- else {
- if (file_exists($fname) && file_exists($tname) && filemtime($fname) > filemtime($tname)) {
- include($fname);
- $is_cached = true;
- }
- }
- $output = ob_get_contents();
- ob_end_clean();
-
- if ( $is_cached && !$this->GetParam('from_inportal') ) {
- if ( strpos($output, '<inp:') !== false) {
- $inp1_parser =& $this->Application->recallObject('Inp1Parser');
- $output = $inp1_parser->Parse($name, $output);
- }
- return $output;
- }
-
- $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";
- }
-
- 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 = new MyTag($tag_data, $this);
- $tag =& $this->TagHolder->GetTag($tag_data, $this);
-
- if (!$this->CheckRecursion($tag)) //we do NOT process closing tags
- {
- $tag->Process();
- }
- }
-
- if ( !$this->GetParam('from_inportal') ) {
- if ( strpos($this->Output, '<inp:') !== false) {
- $inp1_parser =& $this->Application->recallObject('Inp1Parser');
- $this->Output = $inp1_parser->Parse($name, $this->Output);
- $has_inp_tags = true;
- }
- }
-
-
- if (defined('EXPERIMENTAL_PRE_PARSE') && $pre_parse && !$has_inp_tags) {
-// $this->CompiledBuffer .= 'echo $o;'."\n";
- $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($fname).','.$conn->qstr($this->CompiledBuffer).','.adodb_mktime().')');
- }
- else {
- $compiled = fopen($fname, 'w');
- fwrite($compiled, $this->CompiledBuffer);
- fclose($compiled);
- }
- }
-
- return $this->Output;
- }
-
- function ParseBlock($params, $force_pass_params=0, $as_template=false)
- {
- if( $this->Application->isDebugMode() && constOn('DBG_SHOW_TAGS') )
- {
- global $debugger;
- $debugger->appendHTML('ParseBlock '.$params['name'].' pass_params is '.$params['pass_params'].' force is '.$force_pass_params.' in '.$debugger->getFileLink($debugger->getLocalFile(FULL_PATH.THEMES_PATH.'/'.$this->TemplateName).'.tpl', $this->CurrentLineNumber(), '', true));
-
- }
- /*if ( $this->Application->isDebugMode() && constOn('DBG_PRE_PARSE') ) {
- global $debugger;
- $debugger->CurrentPreParsedBlock = $params['name'];
- }*/
- if (defined('EXPERIMENTAL_PRE_PARSE')) {
- $this->MainParser = false;
- if (isset($this->Application->PreParsedBlocks[$params['name']]) ) {
-
- if ($this->ParamsRecursionIndex == 0) {
- $this->ParamsStack[$this->ParamsRecursionIndex] = $this->Params;
- }
-
- if (isset($params['pass_params']) || $force_pass_params) {
- $pass_params = array_merge($this->ParamsStack[$this->ParamsRecursionIndex], $params);
- }
- else {
- $pass_params = $params;
- }
-
- $this->ParamsStack[++$this->ParamsRecursionIndex] = $pass_params;
- $this->Params = $pass_params;
-
- $f = $this->Application->PreParsedBlocks[$params['name']];
-
-// $this->ParamsRecursionIndex--;
-
- //$this->SetParams($params);
- 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;
- return defined('DBG_DECORATE_BLOCKS') && DBG_DECORATE_BLOCKS ? $this->decorateBlock($ret, $pass_params) : $ret;
- }
- }
-
- $BlockParser =& $this->Application->makeClass('TemplateParser');
- if (isset($params['pass_params']) || $force_pass_params) {
- $BlockParser->SetParams(array_merge($this->Params, $params));
- }
- else
- $BlockParser->SetParams($params);
- $this->Application->Parser =& $BlockParser;
- if (!isset($params['name'])) {
- trigger_error('<b>***Error: Block name not passed to ParseBlock</b>', E_USER_ERROR);
- }
- $templates_cache =& $this->Application->recallObject('TemplatesCache');
-
- $template_name = $as_template ? $params['name'] : $templates_cache->GetTemplateFileName($params['name']) . '-block:'.$params['name'];
-
- $silent = getArrayValue($params, 'from_inportal') && !defined('DBG_TEMPLATE_FAILURE');
-
- $o = $BlockParser->Parse(
- $templates_cache->GetTemplateBody($params['name'], $silent),
- $template_name
- );
- if (getArrayValue($params, 'BlockNoData') && !$BlockParser->DataExists) {
- $template_name = $as_template ? $params['BlockNoData'] : $templates_cache->GetTemplateFileName($params['BlockNoData']) . '-block:'.$params['BlockNoData'];
- $o = $BlockParser->Parse(
- $templates_cache->GetTemplateBody($params['BlockNoData'], $silent),
- $template_name
- );
- }
-
- $this->Application->Parser =& $this;
- $this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists;
-
- return $o;
- }
-
- function decorateBlock(&$block_content, $block_params)
- {
- if (preg_match('/^(\s*)<td(.*?)>(.*)<\/td>(.*)$/is', $block_content, $regs)) {
- // block with td -> put div inside td
- return $regs[1].'<td '.$regs[2].'><div title="'.$block_params['name'].'" style="border: 1px solid blue;">'.$regs[3].'</div></td>'.$regs[4];
- }
-
- return '<div title="'.$block_params['name'].'" style="border: 1px solid red;">'.$block_content.'</div>';
- }
-
- function Recurve(&$tag)
- {
- $this->Recursion[++$this->RecursionIndex] =& $tag;
- }
-
- function CheckRecursion(&$tag)
- {
- if ($this->RecursionIndex > 0) { //If we are inside the recursion
- if ($this->Recursion[$this->RecursionIndex]->CheckRecursion($tag)) { //If we can close this recursion
- unset($this->Recursion[$this->RecursionIndex--]); //unsetting current recursion level and decreasing it at the same time
- return true; //we should inform not to process closing tag
- }
- }
- return false;
- }
-
- function SetSkipMode($mode)
- {
- $this->SkipMode = $mode;
- }
-}
\ No newline at end of file
Property changes on: branches/5.0.x/core/kernel/parser/template_parser.php
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.31.2.2
\ No newline at end of property
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
Index: branches/5.0.x/core/kernel/parser/tags.php
===================================================================
--- branches/5.0.x/core/kernel/parser/tags.php (revision 12310)
+++ branches/5.0.x/core/kernel/parser/tags.php (nonexistent)
@@ -1,475 +0,0 @@
-<?php
-/**
-* @version $Id$
-* @package In-Portal
-* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
-* @license GNU/GPL
-* In-Portal is Open Source software.
-* This means that this software may have been modified pursuant
-* the GNU General Public License, and as distributed it includes
-* or is derivative of works licensed under the GNU General Public License
-* or other free or open source software licenses.
-* See http://www.in-portal.net/license/ for copyright notices and details.
-*/
-
-defined('FULL_PATH') or die('restricted access!');
-
-define ('parse', 0);
-define ('skip', 1);
-define ('skip_tags', 2);
-
-class MyTagHolder extends kBase {
-
- var $_Tag;
-
- function MyTagHolder()
- {
-
- }
-
- function &GetTag($tag_data, &$parser, $inp_tag = 0)
- {
- if (!isset($this->_Tag)) {
- $this->_Tag = new Tag($tag_data, $parser, $inp_tag);
- }
- else {
-// $this->_Tag->Parser =& $parser;
- $this->_Tag->TagData = $tag_data;
- if ($tag_data != '') $this->_Tag->ParseTagData($tag_data);
- $this->_Tag->NP =& $this->_Tag->NamedParams;
- }
- $this->_Tag->TemplateName = $parser->TemplateName;
- return $this->_Tag;
- }
-
-}
-
-class Tag extends kBase {
- var $Processor;
- var $Tag;
- var $Params = Array();
- var $NamedParams = Array();
- var $NP;
- var $TemplateName;
- /**
- * Enter description here...
- *
- * @var TemplateParser
- */
- var $Parser;
- var $TagData = '';
-
- function Tag($tag_data, &$parser, $inp_tag=0)
- {
- parent::kBase();
- $this->Parser =& $parser;
- $this->TagData = $tag_data;
- if ($tag_data != '') $this->ParseTagData($tag_data);
- $this->NP =& $this->NamedParams;
- }
-
- function CopyFrom(&$tag)
- {
- $this->Processor = $tag->Processor;
- $this->Tag = $tag->Tag;
- $this->TagData = $tag->TagData;
- $this->Params = $tag->Params;
- $this->NamedParams = $tag->NamedParams;
- $this->Parser =& $tag->Parser;
- $this->TemplateName = $tag->TemplateName;
- }
-
- function GetFullTag()
- {
- return '<%'.$this->TagData.'%>';
- }
-
- function RebuildTagData()
- {
- $res = $this->Processor.':'.$this->Tag.' ';
- foreach ($this->NamedParams as $name => $value) {
- $res .= "$name='$value' ";
- }
- return $res;
- }
-
- /**
- * Escape chars in phrase translation, that could harm parser to process tag
- *
- * @param string $text
- * @return string
- * @access private
- */
- function EscapeReservedChars($text)
- {
- $reserved = Array('"',"'"); // =
- $replacement = Array('\"',"\'"); // \=
- return str_replace($reserved,$replacement,$text);
- }
-
-
- function ReplaceParams($tag_data)
- {
- //print_pre($this->Parser->Pattern, $tag_data);
- $values = $this->Parser->Values;
- foreach($values as $param_name => $param_value)
- {
- $values[$param_name] = $this->EscapeReservedChars($param_value);
- }
-
- if (is_array($this->Parser->Params)) {
- $tag_data = preg_replace($this->Parser->Pattern, $values, $tag_data);
- }
- //echo "got: $tag_data<br>";
- return $tag_data;
- }
-
- function PreParseReplaceParams($tag_data)
- {
- //print_pre($this->Parser->Pattern, $tag_data);
- $values = $this->Parser->Values;
- foreach($values as $param_name => $param_value)
- {
- $values[$param_name] = $this->EscapeReservedChars($param_value);
- }
-
- /*$patterns = Array();
- if ( is_array($this->Parser->Args) ) {
- foreach ($this->Parser->Args as $arg) {
-
- }
- }*/
-
- if ($this->Parser->SkipMode == parse) {
- if (is_array($this->Parser->Params)) {
- $tag_data = preg_replace($this->Parser->Pattern, $values, $tag_data);
- }
- }
- //echo "got: $tag_data<br>";
- return $tag_data;
- }
-
- function CmpParams($a, $b)
- {
- $a_len = strlen($a);
- $b_len = strlen($b);
- if ($a_len == $b_len) return 0;
- return $a_len > $b_len ? -1 : 1;
- }
-
- /**
- * Set's Prefix and Special for Tag object
- * based on ones from tagname
- *
- * @param string $tag_data
- * @access protected
- */
- function ParseTagData($tag_data)
- {
- if (defined('EXPERIMENTAL_PRE_PARSE') ) {
- $this->OriginalTagData = $tag_data;
- $tag_data = $this->PreParseReplaceParams($tag_data) . ' ';
- }
- else {
- $tag_data = $this->ReplaceParams($tag_data) . ' ';
-// $tag_data = $this->Application->ReplaceLanguageTags($tag_data);
- }
-
- list ($key_data, $params) = split("[ \t\n]{1}", $tag_data, 2);
- $key_data = trim($key_data);
-
- $tmp=explode(':',$key_data);
- $this->Tag=$tmp[1];
-
- $tmp=$this->Application->processPrefix($tmp[0]);
- $this->Prefix=$tmp['prefix'];
- $this->Special=$tmp['special'];
- $this->Processor=$this->Prefix;
-
- if ($params != '') {
- $this->ParseNamedParams($params);
- }
- else {
- $this->NamedParams = array();
- }
- }
-
- function ParseNamedParams($params_str)
- {
- $params = new Params($params_str);
- $this->NamedParams = $params->_Params;
- }
-
- function GetParam($param)
- {
- if (isset($this->NP[$param]))
- return $this->NP[$param];
- else
- return false;
- }
-
- /**
- * Process IF tags in specific way
- *
- */
- function Process()
- {
- $short_closing = false;
- if (isset($this->NP['_short_closing_'])) {
- unset($this->NP['_short_closing_']);
- $this->TagData = str_replace(' _short_closing_="1"', '', $this->TagData);
- $short_closing = true;
- }
- if ($this->Processor == 'm' || $this->Processor == 'm_TagProcessor') { //if we are procssing Main tags
- if ($this->Tag == 'block' || $this->Tag == 'DefineElement' || ($this->Tag == 'RenderElement' && $short_closing)) {
- $tag = new BlockTag('', $this->Parser);
- $tag->CopyFrom($this);
- $tag->Process();
- }
- elseif($this->Tag == 'Capture') {
- $tag = new CaptureTag('', $this->Parser);
- $tag->CopyFrom($this);
- $tag->Process();
- }
- elseif ($this->Parser->SkipMode == skip_tags) {
- return;
- }
- elseif (
- $this->Tag == 'if' ||
- $this->Tag == 'ifnot' ||
- $this->Tag == 'else' ||
- $this->Tag == 'elseif'
- )
- {
- if ( defined('EXPERIMENTAL_PRE_PARSE') ) {
- $this->Parser->AppendCompiledCode( $this->GetCode() );
- }
- $tag = new ConstructTag('', $this->Parser);
- $tag->CopyFrom($this);
- $tag->Process();
- }
- else {
- if ($this->Parser->SkipMode == skip) {
- if ( defined('EXPERIMENTAL_PRE_PARSE') ) {
- $this->Parser->AppendCompiledCode( $this->GetCode() );
- }
- return;
- }
- $this->ProcessTag();
- if ( defined('EXPERIMENTAL_PRE_PARSE') ) {
- $this->Parser->AppendCompiledCode( $this->GetCode() );
- }
- }
- }
- else { //normal tags - processors other than main
- if ($this->Parser->SkipMode == skip) { // inside if - add statements inside if to compiled code
- if ( defined('EXPERIMENTAL_PRE_PARSE') ) {
- $this->Parser->AppendCompiledCode( $this->GetCode() );
- }
- return;
- }
- elseif ($this->Parser->SkipMode == skip_tags) return; //do not parse if we skipping tags
- $this->ProcessTag();
- if ( defined('EXPERIMENTAL_PRE_PARSE') ) {
- $this->Parser->AppendCompiledCode( $this->GetCode() );
- }
- }
- }
-
- /**
- * Set's Prefix and Special for TagProcessor
- * based on tag beeing processed
- *
- * @return string
- * @access protected
- */
- function DoProcessTag()
- {
- // $tag->Prefix - l_TagProcessor
- $tmp = $this->Application->processPrefix($this->Processor);
-
- if (isset($this->NamedParams['_ignore_missing_'])) {
- if (!$this->Application->prefixRegistred($tmp['prefix'])) return '';
- }
-
- $processor =& $this->Application->recallObject($tmp['prefix'].'_TagProcessor'); // $this->Processor
-
- $tmp=explode('_',$tmp['prefix'],2);
- $processor->Prefix=$tmp[0];
- $processor->Special=$this->Special;
-
- // pass_params for non ParseBlock tags :)
- $parser_params = $this->Application->Parser->Params;
- if( getArrayValue($this->NamedParams,'pass_params') )
- {
- unset( $this->NamedParams['pass_params'] );
- $this->NamedParams = array_merge_recursive2($parser_params, $this->NamedParams);
- }
-
- return $processor->ProcessTag($this);
- }
-
- function ProcessTag()
- {
- $o = $this->DoProcessTag();
- if ($o !== false)
- {
- $this->Parser->AppendOutput($o);
- }
- else
- {
- trigger_error('can\'t process tag '.$this->Tag.' in '.$this->Prefix,E_USER_WARNING);
- }
- }
-
- function GetCode($echo=false)
- {
- $tmp_params = $this->NamedParams;
- $splited = split("[ \t\n]{1}", $this->OriginalTagData, 2);
- if (isset($splited[1]) && $splited[1]) {
- $this->ParseNamedParams($splited[1]);
- }
- $pass_params = $this->NamedParams;
- $this->NamedParams = $tmp_params;
-
- $code = Array();
-
- $to_pass = 'Array(';
- foreach ($pass_params as $name => $val) {
- $to_pass .= '"'.$name.'" => "'.str_replace('"', '\"', $val).'",';
- }
- $to_pass .= ')';
-
- if ($echo) $code[] = '$o = '."'';\n";
-
- switch ( strtolower($this->Tag) ) {
- case 'defaultparam':
- foreach ($this->NP as $key => $val) {
- $code[] = 'if (!isset($'.$key.')) $application->Parser->SetParam(\''.$key.'\', \''.$val.'\');';
- $code[] = '$'.$key.' = isset($'.$key.') ? $'.$key.' : \''.$val.'\';';
- }
- return $code;
- case 'param':
- case 'Param':
- $code[] = 'if (isset($application->LateParsed["'.$this->NP['name'].'"])) {';
- $code[] = '$__f = $application->PreParsedBlocks[\'capture_'.$this->NP['name'].'\'];';
- $code[] = '$application->Parser->SetParam(\''.$this->NP['name'].'\', $__f($params)'.');'; // array()
- $code[] = '$'.$this->NP['name'].' = $application->Parser->GetParam(\''.$this->NP['name'].'\');';
- $code[] = '$params[\''.$this->NP['name'].'\'] = $'.$this->NP['name'].';';
- $code[] = '}';
- $code[] = '$p =& $application->recallObject(\'m_TagProcessor\');';
- $code[] = '$tag_params = '.$to_pass.';';
- $param_code = '$o .= $p->PostProcess($params["'.$this->NP['name'].'"], $p->PreparePostProcess($tag_params))';
- if (isset($this->NP['plus'])) {
- $param_code .= ' + '.$this->NP['plus'];
- }
- $code[] = $param_code.';';
- return $code;
- case 'if':
- if (isset($this->NP['_closing_tag_'])) {
- $code[] = ' }';
- }
- else {
- $check = isset($pass_params['check']) && $pass_params['check'] ? $pass_params['check'] : false; // $this->GetParam('check');
- if ($check) {
- if (strpos($check, '_') !== false) {
- list($prefix, $function) = explode('_', $check, 2);
- }
- else {
- $function = $check;
- $prefix = '$PrefixSpecial'; // $this->Parser->GetParam('PrefixSpecial');
- }
- }
- else {
- $prefix = $pass_params['prefix']; // $this->GetParam('prefix');
- $function = $pass_params['function']; // $this->GetParam('function');
- }
-
- $code[] = '$tmp = $application->processPrefix("'.$prefix.'");'."\n";
- $code[] = '$__tp = $tmp[\'prefix\'].\'_TagProcessor\';'."\n";
- $code[] = '$p =& $application->recallObject($__tp);'."\n";
- $code[] = '$p->Prefix = $tmp[\'prefix\'];'."\n";
- $code[] = '$p->Special = $tmp[\'special\'];'."\n";
- $code[] = '$if_result = $p->ProcessParsedTag(\''.$function.'\', '.$to_pass.', "'.$prefix.'");'."\n";
- if (isset($pass_params['inverse'])) {
- $code[] = 'if (!$if_result) {';
- }
- else {
- $code[] = 'if ($if_result) {';
- }
- }
- return $code;
-
- case 'endif':
- $code[] = ' }';
- return $code;
-
- case 'else':
- $code[] = ' }';
- $code[] = ' else {';
- return $code;
- }
-
- /* $tmp_pref = $this->getPrefixSpecial();
- $tmp = $this->Application->processPrefix($tmp_pref);
- $tmp_processor = $tmp['prefix'].'_TagProcessor';
- if (strpos($tmp['prefix'], '$') !== false) {
- $processor_to_check = '{'.$tmp['prefix'].'}_TagProcessor';
- }
- else {
- $processor_to_check = $tmp_processor;
- } */
-
- if (isset($this->NamedParams['_auto_prefix_'])) {
- $prefix = '$PrefixSpecial';
- }
- else {
- // use original prefix_special found in templates (parameter names in form $ParamName found in it will not be replaced with values)
- list ($prefix, $tag) = explode(':', $splited[0], 2); //$prefix = $this->getPrefixSpecial();
-
- if (isset($this->NamedParams['_ignore_missing_'])) {
- if (!$this->Application->prefixRegistred($prefix)) return array();
- }
- }
-
- $code[] = '$tmp = $application->processPrefix("'.$prefix.'");'."\n";
-
- /*if (!isset($this->Application->CompilationCache[$this->getPrefixSpecial()])) {
- $code[] = '$tmp = $application->processPrefix("'.$this->getPrefixSpecial().'");'."\n";
- $code[] = '$__tp = $tmp[\'prefix\'].\'_TagProcessor\';'."\n";
- $code[] = '$application->CachedProcessors["'.$this->getPrefixSpecial().'"] =& $application->recallObject($__tp);'."\n";
- $this->Application->CompilationCache[$this->getPrefixSpecial()] = true;
-
- if (strpos($tmp_pref, '$') === false) {
- $this->Application->CachedProcessors[$this->getPrefixSpecial()] =& $this->Application->recallObject($tmp_processor);
- }
- }
-
- $this->Parser->UsedProcessors[] = $tmp['prefix'];*/
- $code[] = '$__tp = $tmp[\'prefix\'].\'_TagProcessor\';'."\n";
- $code[] = '$p =& $application->recallObject($__tp);'."\n";
- $code[] = '$p->Prefix = $tmp[\'prefix\'];'."\n";
- $code[] = '$p->Special = $tmp[\'special\'];'."\n";
-
- $tag_func = $this->Tag;
- if ($tag_func == 'include') $tag_func = 'MyInclude';
-
-// $code[] = '$o .= $application->CachedProcessors["'.$this->getPrefixSpecial().'"]->ProcessParsedTag(\''.$tag_func.'\', '.$to_pass.', "'.$this->Processor.'");'."\n";
-
- $code[] = '$o .= $p->ProcessParsedTag(\''.$tag_func.'\', '.$to_pass.', "'.$prefix.'");'."\n"; // $this->Processor
-
- /*$code = ' $processor =& $application->recallObject(\''.$this->Processor.'_TagProcessor\');
- $o .= $processor->ProcessParsedTag(\''.$this->Tag.'\', unserialize(\''.serialize($this->NP).'\'));';*/
-
- if (isset($pass_params['result_to_var'])) {
- $code[] = '$'.$pass_params['result_to_var'].' = $application->Parser->GetParam(\''.$pass_params['result_to_var'].'\');';
- $code[] = '$params[\''.$pass_params['result_to_var'].'\'] = $'.$pass_params['result_to_var'].';';
- $echo = false;
- }
-
- if ($echo) $code[] = ' echo $o;'."\n";
-
- return $code;
- //return '$o .= \'tag:'. $this->Tag .'\'';
- }
-}
\ No newline at end of file
Property changes on: branches/5.0.x/core/kernel/parser/tags.php
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.21.2.2
\ No newline at end of property
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
Index: branches/5.0.x/core/kernel/parser/construct_tags.php
===================================================================
--- branches/5.0.x/core/kernel/parser/construct_tags.php (revision 12310)
+++ branches/5.0.x/core/kernel/parser/construct_tags.php (nonexistent)
@@ -1,392 +0,0 @@
-<?php
-/**
-* @version $Id$
-* @package In-Portal
-* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
-* @license GNU/GPL
-* In-Portal is Open Source software.
-* This means that this software may have been modified pursuant
-* the GNU General Public License, and as distributed it includes
-* or is derivative of works licensed under the GNU General Public License
-* or other free or open source software licenses.
-* See http://www.in-portal.net/license/ for copyright notices and details.
-*/
-
-defined('FULL_PATH') or die('restricted access!');
-
-define('CM_PARSE', 1);
-define('CM_LATE_PARSE', 2);
-
-//Template language contruct tags (if, block...) which has opening and ending
-class ConstructTag extends Tag {
- var $StopTag = '';
- var $SkipMode = 0;
- var $Logic = 0;
-
-
- function SetStopTag($tag)
- {
- $this->StopTag = $tag;
- }
-
- function StoreSkipMode()
- {
- $this->SkipMode = $this->Parser->SkipMode;
- }
-
- function RestoreSkipMode()
- {
- $this->Parser->SetSkipMode($this->SkipMode);
- }
-
- function RestoreThisLevelSkipMode()
- {
- $this->SkipMode = $this->Parser->Recursion[$this->Parser->RecursionIndex]->SkipMode;
- }
-
- function SuggestSkipMode($mode)
- {
- if ($mode >= 1) //if we need to skip - always forcing it
- $this->Parser->SetSkipMode($mode);
- else { //if we need to turn of skipping
- if ($this->SkipMode == parse) //check if initially skipping was off
- $this->Parser->SetSkipMode(parse); //set it to off only then
- }
- }
-
- function GetLogic()
- {
- if ($this->Parser->SkipMode != parse) {
- $this->Logic = false;
- return;
- }
- $check = $this->GetParam('check');
- if ($check) {
- if (strpos($check, '_') !== false) {
- list($prefix, $function) = explode('_', $check, 2);
- }
- else {
- $function = $check;
- $prefix = $this->Parser->GetParam('PrefixSpecial');
- }
- }
- else {
- $prefix = $this->GetParam('prefix');
- $function = $this->GetParam('function');
- }
- $this->NP['prefix'] = $prefix;
- $this->NP['function'] = $function;
-
- $inverse = $this->GetParam('inverse');
-
- if ($prefix !== false) {
- $tag =& new Tag('', $this->Parser);
- $tag->Tag = $function;
-
- $tmp = $this->Application->processPrefix($prefix);
- $tag->Processor = $tmp['prefix'];
-
- $tag->Prefix=$tmp['prefix'];
- $tag->Special=$tmp['special'];
- $tag->NamedParams = $this->NP;
- $this->Logic = $tag->DoProcessTag();
- // echo " this->Logic : ".$this->Logic."<br>";
- }
- else
- {
- $this->Logic = $function;
- }
- if($inverse) $this->Logic = !$this->Logic;
- }
-
- function Process()
- {
- switch ($this->Tag) {
- case 'if':
- case 'ifnot':
- $this->GetLogic();
-
- $this->SetStopTag('endif'); //This recursion level should end when 'endif' is found
- $this->Parser->Recurve($this); //Saving current tag in parser recursion array
- $this->StoreSkipMode(); //Storing initial SkipMode
-
- if ($this->Logic) {
- $this->SuggestSkipMode(parse); //suggest we parse it
- }
- else {
- $this->SuggestSkipMode(skip); //suggest we don't parse it
- }
- break;
- case 'elseif':
- $if_logic = $this->Parser->Recursion[$this->Parser->RecursionIndex]->Logic;
- if (!$if_logic) { //if IF or ELSEIF above have not worked
- $this->GetLogic();
-
- if ($this->Logic) { //ELSEIF should run
- $this->Parser->Recursion[$this->Parser->RecursionIndex]->Logic = $this->Logic; //To escape running ELSE or ELSEIF below
- $this->SuggestSkipMode(parse);
- }
- else { //ELSEIF should NOT run
- $this->SuggestSkipMode(skip);
- }
- }
- else //IF or ELSEIF above HAVE worked - this ELSEIF should NOT run
- $this->SuggestSkipMode(skip);
- break;
- case 'else':
- $if_logic = $this->Parser->Recursion[$this->Parser->RecursionIndex]->Logic;
- $this->RestoreThisLevelSkipMode();
- if (!$if_logic) { //IF was false - ELSE should run
- $this->SuggestSkipMode(parse);
- }
- else { //IF was true - ELSE should not run
- $this->SuggestSkipMode(skip);
- }
- break;
- }
- }
-
- function CheckRecursion(&$tag)
- {
- if ($this->CheckEndRecursion($tag)) {
- if (defined('EXPERIMENTAL_PRE_PARSE')) {
- if ($tag->Tag == 'if' || $tag->Tag == 'endif') {
- $this->Parser->AppendCompiledCode('}');
- $this->Parser->ResetCode();
- }
- }
- $this->RestoreSkipMode(); //Restoring original SkipMode
- return true;
- }
- else {
- if (defined('EXPERIMENTAL_PRE_PARSE')) {
- // && ($tag->Tag != 'RenderElement' && isset($tag->NP['_short_closing_']))
- if ($tag->Tag != 'block' && $tag->Tag != 'DefineElement' && $tag->Tag != 'Capture' && !($tag->Tag == 'RenderElement' && isset($tag->NP['_short_closing_']))) {
- $this->Parser->AppendCode($tag->GetCode());
- }
-// $this->Parser->AppendCompiledCode( $tag->GetCode() );
- }
- }
- return false;
- }
-
- function CheckEndRecursion(&$tag)
- {
- if ($tag->GetParam('_closing_tag_') == 1 && $tag->Tag == $this->Tag) {
- return true;
- }
- return ($tag->Tag == $this->StopTag); //Tag matches StopTag we are waiting for to close current recursion
- }
-}
-
-class BlockTag extends ConstructTag {
- var $BlockName = '';
- var $InsideBlock = 0;
-
- function Process()
- {
- switch ($this->Tag) {
- case 'block':
- case 'DefineElement':
- case 'RenderElement':
- if ($this->Tag == 'DefineElement') {
- $this->SetStopTag('end_define'); //This recursion level should end when 'blockend' is found
- }
- else {
- $this->SetStopTag('blockend'); //This recursion level should end when 'blockend' is found
- }
- if ($this->Tag == 'RenderElement') {
- $this->NP['name'] = '__lambda_element_'.abs(crc32($this->TemplateName)).'_'.$this->Application->LambdaElements++;
- $RenderTag = new Tag($this->TagData.' name="'.$this->NP['name'].'"', $this->Parser);
- $this->Parser->AppendCode($RenderTag->GetCode());
- }
- $this->Parser->Recurve($this); //Saving current tag in parser recursion array
- $this->Parser->SetBuffer('');
- $this->BlockName = $this->NP['name']; //Stroing BlockName
- if (isset($this->NP['args']) ) {
- $this->Parser->Args = explode(',', $this->NP['args']);
- }
- $this->StoreSkipMode();
- $this->SuggestSkipMode(skip_tags); //We need to skip tags from now
- break;
- }
- }
-
- function CheckRecursion(&$tag)
- {
- if (parent::CheckRecursion($tag)) { //if endtag matches (SkipMode would be restored then)
- //Creating template from buffer
-
- //if (defined('EXPERIMENTAL_PRE_PARSE') && isset($this->Application->PreParsedBlocks[$this->BlockName])) return true;
-
- $template = new Template();
- $template->SetBody($this->Parser->GetBuffer());
-
- //Adding template to application' cache
- $this->Application->TemplatesCache->SetTemplate($this->BlockName, $template, $this->Parser->TemplateName);
-
- if (defined('EXPERIMENTAL_PRE_PARSE')) {
- $code = $this->Parser->GetCode();
-
- /*if ($this->Parser->UsedProcessors) {
- array_unshift($code, '$application->CheckProcessors(array("'.implode('", "', $this->Parser->UsedProcessors).'"));');
- }
- $this->Parser->UsedProcessors = null;*/
-
- // because of unshift the code is added from bottom to top here, so read from the bottom below:
- array_unshift($code, '$o = \'\';');
- array_unshift($code, '$application->Parser->SetParams($params, false);');
- array_unshift($code, '$application =& kApplication::Instance();');
- array_unshift($code, 'extract($params);');
-
- $defaults = '$defaults = Array(';
- foreach ($this->NP as $name => $val) {
- if ($name == 'name') continue;
- $defaults .= '"'.$name.'" => "'.str_replace('"', '\"', $val).'",';
- }
- $defaults .= ');';
- array_unshift($code, '$params = array_merge_recursive2($defaults, $params);');
- array_unshift($code, $defaults);
-
- // ^^^^ read up from here ^^^^
- $code[] = 'return $o;';
-
- global $debugger;
-
- $dbg_functions = $this->Application->isDebugMode() && constOn('DBG_PRINT_PREPARSED');
-
- $f_body = '';
- //echo "<pre>";
- $l = 0;
- if ($dbg_functions) echo "<b>function ".$this->BlockName." {</b><br>";
- foreach ($code as $line) {
- $l++;
- if ($dbg_functions) {
- echo $l.' '.$debugger->highlightString(trim($line)."\n", true);
- }
- $f_body .= "\t\t".rtrim($line, "\n")."\n";
- }
- if ($dbg_functions) echo "<b>} // function ".$this->BlockName." end</b><br><br>";
- //echo "</pre>";
-
- //caching func body
- $this->Application->PreParsedCache[$this->BlockName] = $f_body;
-
- $compile_body = preg_replace('/\/\*COMPILE-ONLY\*\/.*/m', '', $f_body);
-
- $func = create_function('$params', $compile_body);
- $this->Application->PreParsedBlocks[$this->BlockName] = $func;
- $this->Parser->Args = null;
- $this->Parser->ResetCode();
-
- $real_name = $this->Parser->AppendCompiledFunction($this->BlockName, $f_body);
-
- if ($this->Tag == 'RenderElement') {
- $RenderTag = new Tag($this->TagData.' name="'.$this->BlockName.'"', $this->Parser);
-// $this->Parser->AppendCompiledCode($RenderTag->GetCode());
-
- // for compilation run
- $RenderTag->Process();
- }
-
- }
- return true;
- }
- else {
- // append the tag itself to the block - while in block, we check every tag to be 'blockend'
- // if it is not - we need to append the tag to the buffer, which we'll parse later in 'parse_block'
- //if ($tag->Tag != 'block') {
- if (defined('EXPERIMENTAL_PRE_PARSE') && isset($this->Application->PreParsedBlocks[$this->BlockName])) {
- return;
- }
- if (defined('EXPERIMENTAL_PRE_PARSE')) {
- // $this->Parser->AppendCode($tag->GetCode());
- }
- else {
- $this->Parser->AppendOutput($tag->GetFullTag());
- }
- //}
- return false;
- }
- }
-}
-
-class CaptureTag extends ConstructTag {
- var $VarName = null;
- var $Mode = CM_LATE_PARSE;
-
- function Process()
- {
- switch ($this->Tag) {
- case 'Capture':
- $this->Parser->Recurve($this); //Saving current tag in parser recursion array
- $this->Parser->SetBuffer('');
- $this->VarName = $this->NP['to_var']; //Stroing BlockName
- $this->StoreSkipMode();
-
- if (isset($this->NP['mode']) && $this->NP['mode'] == 'parse_now') {
- $this->Mode = CM_PARSE;
- }
- $this->SuggestSkipMode(skip_tags);
- break;
- }
- }
-
- function RunCapture($f, $func, $cur_lambda)
- {
- $code = array();
- $code[] = '/*COMPILE-ONLY*/ '.$f[2];
- $code[] = '/*LAMBDA-ONLY*/ $application->PreParsedBlocks[\'capture_'.$this->VarName.'\'] = $application->PreParsedBlocks[\'capture_'.$this->VarName.$cur_lambda.'\'];';
- $code[] = '$__f = $application->PreParsedBlocks[\'capture_'.$this->VarName.'\'];';
- $code[] = '$application->Parser->SetParam(\''.$this->VarName.'\', $__f(array())'.');';
- $code[] = '$'.$this->VarName.' = $application->Parser->GetParam(\''.$this->VarName.'\');';
- $code[] = '$params[\''.$this->VarName.'\'] = $'.$this->VarName.';';
- if ($this->Parser->RecursionIndex > 1) {
- $this->Parser->AppendCode($code, -1);
- }
- else {
- $this->Application->Parser->SetParam($this->VarName, $func(array()));
- $this->Parser->AppendCompiledCode($code);
- }
- }
-
- function CheckRecursion(&$tag)
- {
- if (parent::CheckRecursion($tag)) { //if endtag matches (SkipMode would be restored then)
- $f_code = $this->Parser->GetCode();
- array_unshift($f_code, '$o = \'\';');
- array_unshift($f_code, '$application =& kApplication::Instance();');
- $f_code[] = 'return $o;';
-
- $f = $this->Parser->PrepareCompiledFunction('capture_'.$this->VarName, $f_code, false);
- $f_code = trim(join("\n\t", $f_code));
- $func = create_function('$params', $f_code);
- $this->Application->PreParsedBlocks['capture_'.$this->VarName] = $func;
- $cur_lambda = $this->Application->LambdaElements++;
- $this->Application->PreParsedBlocks['capture_'.$this->VarName.$cur_lambda] = $func;
-
- $this->Parser->AppendCompiledCode($f[1]);
-
- if ($this->Mode == CM_PARSE) {
- $this->RunCapture($f, $func, $cur_lambda);
- }
- elseif ($this->Mode == CM_LATE_PARSE) {
- $code = array();
- $code[] = '/*COMPILE-ONLY*/ '.$f[2];
- $code[] = '/*LAMBDA-ONLY*/ $application->PreParsedBlocks[\'capture_'.$this->VarName.'\'] = $application->PreParsedBlocks[\'capture_'.$this->VarName.$cur_lambda.'\'];';
- $code[] = '$application->LateParsed[\''.$this->VarName.'\'] = '.$cur_lambda.';';
- if ($this->Parser->RecursionIndex > 1) {
- $this->Parser->AppendCode($code, -1);
- }
- else {
- $this->Parser->AppendCompiledCode($code);
- }
- $this->Application->LateParsed[$this->VarName] = $cur_lambda;
- }
- $this->Parser->ResetCode();
- return true;
- }
- return ($tag->Tag == $this->StopTag); //Tag matches StopTag we are waiting for to close current recursion
- }
-
-}
\ No newline at end of file
Property changes on: branches/5.0.x/core/kernel/parser/construct_tags.php
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.14.2.2
\ No newline at end of property
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property

Event Timeline