diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 3e9c7d33d8..268fd46da4 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -324,32 +324,73 @@ class Template { $code_lines[$i] = chop($code_lines[$i]); if (preg_match('##', $code_lines[$i], $m)) { - // We have the start of a block. - $block_nesting_level++; - $block_names[$block_nesting_level] = $m[1]; - - if ($block_nesting_level < 2) + $n[0] = $m[0]; + $n[1] = $m[1]; + + // Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think. :) + if (preg_match('##', $code_lines[$i], $n)) { - // 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" . '{'; + $block_nesting_level++; + $block_names[$block_nesting_level] = $m[1]; + if ($block_nesting_level < 2) + { + // 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 { - // 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] = '$_' . $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" . '{'; + // 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. + $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] = '$_' . $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" . '{'; + } } } else if (preg_match('##', $code_lines[$i], $m)) @@ -367,12 +408,10 @@ class Template { $code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";'; } } - } // Bring it back into a single string of lines of code. - $code = implode("\n", $code_lines); - + $code = implode("\n", $code_lines); return $code ; }