This is an enhancement for revision r10051 (INC template variable)

Within the mentioned revision INC was only able to be applied to defined template variables.
I extended it now to work on all supported variables (template vars, defines, loops, defines in loops)
I also added a DEC template variable to logically complete this.

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10054 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2009-08-25 09:48:44 +00:00
parent 17f40511bf
commit b47b35a07d
3 changed files with 30 additions and 12 deletions

View file

@ -282,7 +282,7 @@
<li>[Feature] Separate PM Reply and PM Reply to all in prosilver.</li> <li>[Feature] Separate PM Reply and PM Reply to all in prosilver.</li>
<li>[Feature] Place debug notices during captcha rendering in the error log - useful for debugging output already started errors.</li> <li>[Feature] Place debug notices during captcha rendering in the error log - useful for debugging output already started errors.</li>
<li>[Feature] Ability to define constant PHPBB_USE_BOARD_URL_PATH to use board url for images/avatars/ranks/imageset...</li> <li>[Feature] Ability to define constant PHPBB_USE_BOARD_URL_PATH to use board url for images/avatars/ranks/imageset...</li>
<li>[Feature] Added INC command to template syntax.</li> <li>[Feature] Added INC/DEC command to template syntax, applicable to DEFINES and normal template variables, including loops.</li>
</ul> </ul>
<a name="v304"></a><h3>1.ii. Changes since 3.0.4</h3> <a name="v304"></a><h3>1.ii. Changes since 3.0.4</h3>

View file

@ -1169,17 +1169,25 @@ append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;
<div class="codebox"><pre> <div class="codebox"><pre>
<span class="comment">&lt;!-- INCLUDE {FILE_VAR} --&gt;</span> <span class="comment">&lt;!-- INCLUDE {FILE_VAR} --&gt;</span>
</pre></div> </pre></div>
<p>Template defined variables can also be utilised. <p>Template defined variables can also be utilised.
<div class="codebox"><pre> <div class="codebox"><pre>
<span class="comment">&lt;!-- DEFINE $SOME_VAR = 'my_file.html' --&gt;</span> <span class="comment">&lt;!-- DEFINE $SOME_VAR = 'my_file.html' --&gt;</span>
<span class="comment">&lt;!-- INCLUDE {$SOME_VAR} --&gt;</span> <span class="comment">&lt;!-- INCLUDE {$SOME_VAR} --&gt;</span>
</pre></div> </pre></div>
<p>Also added in <strong>3.0.6</strong> 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).</p> <p>Also added in <strong>3.0.6</strong> 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 <strong>current</strong> state of a defined var and then increment/decrement it by one (postincrement/postdecrement).</p>
<div class="codebox"><pre> <div class="codebox"><pre>
<span class="comment">&lt;!-- DEFINE $SOME_VAR = 1 --&gt;</span> <span class="comment">&lt;!-- DEFINE $SOME_VAR = 1 --&gt;</span>
<span class="comment">&lt;!-- INC $SOME_VAR --&gt;</span> <span class="comment">&lt;!-- INC $SOME_VAR --&gt;</span>
Result: 1<br />
<span class="comment">{$SOME_VAR}</span>
Result: 2<br />
</pre></div> </pre></div>
<h4>PHP</h4> <h4>PHP</h4>
<p>A contentious decision has seen the ability to include PHP within the template introduced. This is achieved by enclosing the PHP within relevant tags:</p> <p>A contentious decision has seen the ability to include PHP within the template introduced. This is achieved by enclosing the PHP within relevant tags:</p>

View file

@ -192,9 +192,13 @@ class template_compile
break; break;
case 'INC': case 'INC':
$compile_blocks[] = '<?php ' . $this->compile_tag_counter($block_val[2], true) . ' ?>'; $compile_blocks[] = '<?php ' . $this->compile_tag_counter($block_val[2], '++') . ' ?>';
break; break;
case 'DEC':
$compile_blocks[] = '<?php ' . $this->compile_tag_counter($block_val[2], '--') . ' ?>';
break;
case 'INCLUDE': case 'INCLUDE':
$temp = array_shift($include_blocks); $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 * @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); preg_match('#^((?:[a-z0-9\-_]+\.)+)?(\$)?(?=[A-Z])([A-Z0-9\-_]+)#s', $tag_args, $varrefs);
if (empty($match[1]))
if (empty($varrefs[0]))
{ {
return ''; 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 * Compile INCLUDE tag
* @access private * @access private