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()
{
$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."
";
}
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')) {
$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':
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
}
$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());
$templates_cache =& $this->Application->recallObject('TemplatesCache');
//Adding template to application' cache
$templates_cache->SetTemplate($this->BlockName, $template, $this->Parser->TemplateName);
if (defined('EXPERIMENTAL_PRE_PARSE')) {
$code = $this->Parser->GetCode();
array_unshift($code, '$o = \'\';');
array_unshift($code, '$application =& kApplication::Instance();');
array_unshift($code, 'extract($params);');
$code[] = 'return $o;';
global $debugger;
$dbg_functions = $this->Application->isDebugMode() && dbg_ConstOn('DBG_PRINT_PREPARSED');
$f_body = '';
//echo "
"; $l = 0; if ($dbg_functions) echo "function ".$this->BlockName." {"; //caching func body $this->Application->PreParsedCache[$this->BlockName] = $f_body; $func = create_function('$params', $f_body); $this->Application->PreParsedBlocks[$this->BlockName] = $func; $this->Parser->Args = null; $this->Parser->ResetCode(); $this->Parser->AppendCompiledFunction($this->BlockName, $f_body); } 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; } } } ?>
"; 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 "} // function ".$this->BlockName." end
"; //echo "