diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index 0d9409b142..0922372a78 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -282,7 +282,7 @@
<!-- INCLUDE {FILE_VAR} -->
Template defined variables can also be utilised. +
<!-- DEFINE $SOME_VAR = 'my_file.html' --> <!-- INCLUDE {$SOME_VAR} -->
Also added in 3.0.6 is the ability to increment an variable on use. This can be used for instances like tabindexes, where the amount of entries is not statically known. -The INC command will print the current state of a defined var and then increment it by one (postincrement).
+ +Also added in 3.0.6 is the ability to increment or decrement a variable on use. This can be used for instances like tabindexes, where the amount of entries is not statically known. +The INC (for incrementing) and DEC (for decrementing) commands will print the current state of a defined var and then increment/decrement it by one (postincrement/postdecrement).
+<!-- DEFINE $SOME_VAR = 1 --> <!-- INC $SOME_VAR --> +Result: 1
+{$SOME_VAR} +Result: 2
A contentious decision has seen the ability to include PHP within the template introduced. This is achieved by enclosing the PHP within relevant tags:
diff --git a/phpBB/includes/functions_template.php b/phpBB/includes/functions_template.php index 23b09a87f7..f22a48bddb 100644 --- a/phpBB/includes/functions_template.php +++ b/phpBB/includes/functions_template.php @@ -192,9 +192,13 @@ class template_compile break; case 'INC': - $compile_blocks[] = 'compile_tag_counter($block_val[2], true) . ' ?>'; + $compile_blocks[] = 'compile_tag_counter($block_val[2], '++') . ' ?>'; break; - + + case 'DEC': + $compile_blocks[] = 'compile_tag_counter($block_val[2], '--') . ' ?>'; + break; + case 'INCLUDE': $temp = array_shift($include_blocks); @@ -632,20 +636,26 @@ class template_compile /** - * Compile INC tags + * Compile INC/DEC tags + * INC/DEC tags support defined template variables as well as normal template variables * @access private */ - function compile_tag_counter($tag_args) + function compile_tag_counter($tag_args, $operation = '++') { - preg_match('#^\$(?=[A-Z])([A-Z0-9_\-]*)$#', $tag_args, $match); - if (empty($match[1])) + preg_match('#^((?:[a-z0-9\-_]+\.)+)?(\$)?(?=[A-Z])([A-Z0-9\-_]+)#s', $tag_args, $varrefs); + + if (empty($varrefs[0])) { return ''; } - - return 'echo $this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[1] . '\']++'; + + // Build token + $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[2]) . '[\'' . $varrefs[3] . '\']' : (($varrefs[2]) ? '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[3] . '\']' : '$this->_rootref[\'' . $varrefs[3] . '\']'); + + // Increase or decrease token ;) + return "echo {$token}{$operation};"; } - + /** * Compile INCLUDE tag * @access private