From 76cffeff0a043c3bd7d610c376e81c00899265dd Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 11 Jun 2009 16:53:45 +0000 Subject: Dynamic template includes :) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9570 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_template.php | 43 ++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_template.php') diff --git a/phpBB/includes/functions_template.php b/phpBB/includes/functions_template.php index 42a5eb3248..d9d9abfe46 100644 --- a/phpBB/includes/functions_template.php +++ b/phpBB/includes/functions_template.php @@ -128,9 +128,9 @@ class template_compile $php_blocks = $matches[1]; $code = preg_replace('#.*?#s', '', $code); - preg_match_all('##', $code, $matches); + preg_match_all('##', $code, $matches); $include_blocks = $matches[1]; - $code = preg_replace('##', '', $code); + $code = preg_replace('##', '', $code); preg_match_all('##', $code, $matches); $includephp_blocks = $matches[1]; @@ -193,8 +193,39 @@ class template_compile case 'INCLUDE': $temp = array_shift($include_blocks); + + // Dynamic includes + // Cheap match rather than a full blown regexp, we already know + // the format of the input so just use string manipulation. + if ($temp[0] == '{') + { + $file = false; + + if ($temp[1] == '$') + { + $var = substr($temp, 2, -1); + //$file = $this->template->_tpldata['DEFINE']['.'][$var]; + $temp = "\$this->_tpldata['DEFINE']['.']['$var']"; + } + else + { + $var = substr($temp, 1, -1); + //$file = $this->template->_rootref[$var]; + $temp = "\$this->_rootref['$var']"; + } + } + else + { + $file = $temp; + } + $compile_blocks[] = 'compile_tag_include($temp) . ' ?>'; - $this->template->_tpl_include($temp, false); + + // No point in checking variable includes + if ($file) + { + $this->template->_tpl_include($file, false); + } break; case 'INCLUDEPHP': @@ -594,6 +625,12 @@ class template_compile */ function compile_tag_include($tag_args) { + // Process dynamic includes + if ($tag_args[0] == '$') + { + return "if (isset($tag_args)) { \$this->_tpl_include($tag_args); }"; + } + return "\$this->_tpl_include('$tag_args');"; } -- cgit v1.2.1 From 7d605da65bda85c26d13c810bbfc051b3495b76d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Jun 2009 22:07:27 +0000 Subject: Fix bug #45805 - INCLUDEPHP not depending on phpbb_root_path Authorised by: acydburn git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9633 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_template.php') diff --git a/phpBB/includes/functions_template.php b/phpBB/includes/functions_template.php index d9d9abfe46..a951579db5 100644 --- a/phpBB/includes/functions_template.php +++ b/phpBB/includes/functions_template.php @@ -640,7 +640,7 @@ class template_compile */ function compile_tag_include_php($tag_args) { - return "include('" . $tag_args . "');"; + return "\$this->_php_include('$tag_args');"; } /** -- cgit v1.2.1 From b613781d3af6d7c5e5d9d0fa1592e78b54647c0f Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 21 Jul 2009 10:58:31 +0000 Subject: Preserve newlines in template files (one newline had been always dropped after a template variable due to PHP's handling of closing tags) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9811 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_template.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_template.php') diff --git a/phpBB/includes/functions_template.php b/phpBB/includes/functions_template.php index a951579db5..1d3a4d74f8 100644 --- a/phpBB/includes/functions_template.php +++ b/phpBB/includes/functions_template.php @@ -251,15 +251,22 @@ class template_compile $template_php .= (!$no_echo) ? (($trim_check_text != '') ? $text_blocks[$i] : '') . ((isset($compile_blocks[$i])) ? $compile_blocks[$i] : '') : (($trim_check_text != '') ? $text_blocks[$i] : '') . ((isset($compile_blocks[$i])) ? $compile_blocks[$i] : ''); } + // Remove unused opening/closing tags + $template_php = str_replace(' ?>([\r\n])#', '?>\1\1', $template_php); + // There will be a number of occasions where we switch into and out of // PHP mode instantaneously. Rather than "burden" the parser with this // we'll strip out such occurences, minimising such switching if ($no_echo) { - return "\$$echo_var .= '" . str_replace(' ?> Date: Mon, 24 Aug 2009 15:12:40 +0000 Subject: Add INC (working name) to template syntax git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10051 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_template.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'phpBB/includes/functions_template.php') diff --git a/phpBB/includes/functions_template.php b/phpBB/includes/functions_template.php index 1d3a4d74f8..23b09a87f7 100644 --- a/phpBB/includes/functions_template.php +++ b/phpBB/includes/functions_template.php @@ -191,6 +191,10 @@ class template_compile $compile_blocks[] = 'compile_tag_define($block_val[2], false) . ' ?>'; break; + case 'INC': + $compile_blocks[] = 'compile_tag_counter($block_val[2], true) . ' ?>'; + break; + case 'INCLUDE': $temp = array_shift($include_blocks); @@ -626,6 +630,22 @@ class template_compile return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ' = ' . $match[4] . ';'; } + + /** + * Compile INC tags + * @access private + */ + function compile_tag_counter($tag_args) + { + preg_match('#^\$(?=[A-Z])([A-Z0-9_\-]*)$#', $tag_args, $match); + if (empty($match[1])) + { + return ''; + } + + return 'echo $this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[1] . '\']++'; + } + /** * Compile INCLUDE tag * @access private -- cgit v1.2.1 From b47b35a07d47435ecb35aa386783c42721bb4764 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 25 Aug 2009 09:48:44 +0000 Subject: 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 --- phpBB/includes/functions_template.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/functions_template.php') 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 -- cgit v1.2.1 From fd24241044338f9210319398ae10bc6ad02983ea Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 30 Aug 2009 11:15:24 +0000 Subject: Revert INC/DEC feature. It is not consistent with the other template variables - bad idea. ;) We will get to it though... but not now. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10064 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_template.php | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'phpBB/includes/functions_template.php') diff --git a/phpBB/includes/functions_template.php b/phpBB/includes/functions_template.php index f22a48bddb..1d3a4d74f8 100644 --- a/phpBB/includes/functions_template.php +++ b/phpBB/includes/functions_template.php @@ -191,14 +191,6 @@ class template_compile $compile_blocks[] = 'compile_tag_define($block_val[2], false) . ' ?>'; break; - case 'INC': - $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); @@ -634,28 +626,6 @@ class template_compile return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ' = ' . $match[4] . ';'; } - - /** - * 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, $operation = '++') - { - preg_match('#^((?:[a-z0-9\-_]+\.)+)?(\$)?(?=[A-Z])([A-Z0-9\-_]+)#s', $tag_args, $varrefs); - - if (empty($varrefs[0])) - { - return ''; - } - - // 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 -- cgit v1.2.1