diff options
author | Igor Wiedler <igor@wiedler.ch> | 2011-07-10 00:35:07 +0200 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2011-07-10 00:35:07 +0200 |
commit | ae53623230a45eeedf50cc3f6220164d8cd256c3 (patch) | |
tree | 130080560cc500d1da9b1e83f05c29d29a688e64 /phpBB/includes/template | |
parent | ee0bba3ab65f68a24942a650b9414b8f2ad700b4 (diff) | |
download | forums-ae53623230a45eeedf50cc3f6220164d8cd256c3.tar forums-ae53623230a45eeedf50cc3f6220164d8cd256c3.tar.gz forums-ae53623230a45eeedf50cc3f6220164d8cd256c3.tar.bz2 forums-ae53623230a45eeedf50cc3f6220164d8cd256c3.tar.xz forums-ae53623230a45eeedf50cc3f6220164d8cd256c3.zip |
[feature/template-engine] Refactor $config dependency out of the filter
The template stream filter no longer depends on the $config global.
Instead it uses a 'allow_php' param that is passed via
stream_bucket_append's last argument.
Tests also adjusted.
PHPBB3-9726
Diffstat (limited to 'phpBB/includes/template')
-rw-r--r-- | phpBB/includes/template/compile.php | 14 | ||||
-rw-r--r-- | phpBB/includes/template/filter.php | 25 | ||||
-rw-r--r-- | phpBB/includes/template/template.php | 2 |
3 files changed, 31 insertions, 10 deletions
diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index 59ab9e654e..647e8ccf8a 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -26,6 +26,18 @@ stream_filter_register('phpbb_template', 'phpbb_template_filter'); class phpbb_template_compile { /** + * Whether <!-- PHP --> tags are allowed + * + * @var bool + */ + private $allow_php; + + public function __construct($allow_php) + { + $this->allow_php = $allow_php; + } + + /** * Compiles template in $source_file and writes compiled template to * cache directory * @param string $handle Template handle to compile @@ -96,7 +108,7 @@ class phpbb_template_compile */ private function compile_stream_to_stream($source_stream, $dest_stream) { - stream_filter_append($source_stream, 'phpbb_template'); + stream_filter_append($source_stream, 'phpbb_template', null, array('allow_php' => $this->allow_php)); stream_copy_to_stream($source_stream, $dest_stream); } } diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index c0943ae8c0..42700500a7 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -65,6 +65,18 @@ class phpbb_template_filter extends php_user_filter */ private $in_php; + /** + * Whether <!-- PHP --> tags are allowed + * + * @var bool + */ + private $allow_php; + + public function __construct($allow_php) + { + $this->allow_php = $allow_php; + } + public function filter($in, $out, &$consumed, $closing) { $written = false; @@ -111,6 +123,7 @@ class phpbb_template_filter extends php_user_filter { $this->chunk = ''; $this->in_php = false; + $this->allow_php = $this->params['allow_php']; return true; } @@ -121,10 +134,8 @@ class phpbb_template_filter extends php_user_filter $data = preg_replace('#<(?:[\\?%]|script)#s', '<?php echo\'\\0\';?>', $data); $data = preg_replace_callback(self::REGEX_TOKENS, array($this, 'replace'), $data); - global $config; - // Remove php - if (!$config['tpl_allow_php']) + if (!$this->allow_php) { if ($block_start_in_php && $this->in_php @@ -195,8 +206,6 @@ class phpbb_template_filter extends php_user_filter return $this->compile_var_tags($matches[0]); } - global $config; - switch ($matches[1]) { case 'BEGIN': @@ -243,11 +252,11 @@ class phpbb_template_filter extends php_user_filter break; case 'INCLUDEPHP': - return ($config['tpl_allow_php']) ? '<?php ' . $this->compile_tag_include_php($matches[2]) . ' ?>' : ''; + return ($this->allow_php) ? '<?php ' . $this->compile_tag_include_php($matches[2]) . ' ?>' : ''; break; case 'PHP': - if ($config['tpl_allow_php']) + if ($this->allow_php) { $this->in_php = true; return '<?php '; @@ -256,7 +265,7 @@ class phpbb_template_filter extends php_user_filter break; case 'ENDPHP': - if ($config['tpl_allow_php']) + if ($this->allow_php) { $this->in_php = false; return ' ?>'; diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 935605b12a..2c121d7247 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -376,7 +376,7 @@ class phpbb_template $source_file = $this->_source_file_for_handle($handle); - $compile = new phpbb_template_compile(); + $compile = new phpbb_template_compile($this->config['tpl_allow_php']); $output_file = $this->_compiled_file_for_handle($handle); if ($compile->compile_file_to_file($source_file, $output_file) !== false) |