Fixes a template parsing error.

git-svn-id: file:///svn/phpbb/trunk@847 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
dougk_ff7 2001-08-13 04:08:02 +00:00
parent 1e1eaa8146
commit 0073e1ffe4

View file

@ -324,32 +324,73 @@ class Template {
$code_lines[$i] = chop($code_lines[$i]); $code_lines[$i] = chop($code_lines[$i]);
if (preg_match('#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m)) if (preg_match('#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m))
{ {
// We have the start of a block. $n[0] = $m[0];
$block_nesting_level++; $n[1] = $m[1];
$block_names[$block_nesting_level] = $m[1];
if ($block_nesting_level < 2) // Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think. :)
if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $n))
{ {
// Block is not nested. $block_nesting_level++;
$code_lines[$i] = '$_' . $m[1] . '_count = sizeof($this->_tpldata[\'' . $m[1] . '.\']);'; $block_names[$block_nesting_level] = $m[1];
$code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)'; if ($block_nesting_level < 2)
$code_lines[$i] .= "\n" . '{'; {
// Block is not nested.
$code_lines[$i] = '$_' . $a[1] . '_count = sizeof($this->_tpldata[\'' . $n[1] . '.\']);';
$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($namespace, 2);
// 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($namespace, false);
// Create the for loop code to iterate over this block.
$code_lines[$i] = '$_' . $a[1] . '_count = sizeof(' . $varref . ');';
$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 else
{ {
// This block is nested. // 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 = sizeof($this->_tpldata[\'' . $m[1] . '.\']);';
$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. // Generate a namespace string for this block.
$namespace = implode('.', $block_names); $namespace = implode('.', $block_names);
// strip leading period from root level.. // strip leading period from root level..
$namespace = substr($namespace, 2); $namespace = substr($namespace, 2);
// Get a reference to the data array for this block that depends on the // Get a reference to the data array for this block that depends on the
// current indices of all parent blocks. // current indices of all parent blocks.
$varref = $this->generate_block_data_ref($namespace, false); $varref = $this->generate_block_data_ref($namespace, false);
// Create the for loop code to iterate over this block. // Create the for loop code to iterate over this block.
$code_lines[$i] = '$_' . $m[1] . '_count = sizeof(' . $varref . ');'; $code_lines[$i] = '$_' . $m[1] . '_count = sizeof(' . $varref . ');';
$code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)'; $code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)';
$code_lines[$i] .= "\n" . '{'; $code_lines[$i] .= "\n" . '{';
}
} }
} }
else if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $m)) else if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $m))
@ -367,12 +408,10 @@ class Template {
$code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";'; $code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";';
} }
} }
} }
// Bring it back into a single string of lines of code. // Bring it back into a single string of lines of code.
$code = implode("\n", $code_lines); $code = implode("\n", $code_lines);
return $code ; return $code ;
} }