diff options
author | Chris Smith <toonarmy@phpbb.com> | 2009-06-11 16:53:45 +0000 |
---|---|---|
committer | Chris Smith <toonarmy@phpbb.com> | 2009-06-11 16:53:45 +0000 |
commit | 76cffeff0a043c3bd7d610c376e81c00899265dd (patch) | |
tree | 4e06e17c06a3265e07cb8bf677bb8c4430a506ad | |
parent | 92b6e5400ea1024f3463866be70244eb1fe79a82 (diff) | |
download | forums-76cffeff0a043c3bd7d610c376e81c00899265dd.tar forums-76cffeff0a043c3bd7d610c376e81c00899265dd.tar.gz forums-76cffeff0a043c3bd7d610c376e81c00899265dd.tar.bz2 forums-76cffeff0a043c3bd7d610c376e81c00899265dd.tar.xz forums-76cffeff0a043c3bd7d610c376e81c00899265dd.zip |
Dynamic template includes :)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9570 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/docs/CHANGELOG.html | 1 | ||||
-rw-r--r-- | phpBB/includes/functions_template.php | 43 |
2 files changed, 41 insertions, 3 deletions
diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index 93b81b1997..3c3d3b599a 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -101,6 +101,7 @@ <li>[Fix] Also remove data from friend/foe table when deleting user. (Bug #45345 - Patch by nickvergessen)</li> <li>[Change] Change the data format of the default file ACM to be more secure from tampering and have better performance.</li> <li>[Change] Add index on log_time to the log table to prevent slowdown on boards with many log entries. (Bug #44665 - Patch by bantu)</li> + <li>[Change] Template engine now permits to a limited extent variable includes.</li> <li>[Feature] Backported 3.2 captcha plugins.</li> <li>[Feature] Introduced new ACM plugins: <ul> 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('#<!-- PHP -->.*?<!-- ENDPHP -->#s', '<!-- PHP -->', $code); - preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches); + preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches); $include_blocks = $matches[1]; - $code = preg_replace('#<!-- INCLUDE [a-zA-Z0-9\_\-\+\./]+ -->#', '<!-- INCLUDE -->', $code); + $code = preg_replace('#<!-- INCLUDE (?:\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', '<!-- INCLUDE -->', $code); preg_match_all('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\./]+) -->#', $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[] = '<?php ' . $this->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');"; } |