mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-08 17:56:52 +02:00
[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
This commit is contained in:
@@ -25,6 +25,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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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 ' ?>';
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user