mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
Merge remote-tracking branch 'EXreaction/ticket/11435-2' into develop
* EXreaction/ticket/11435-2: [ticket/11435] Enable spacing test as it should now pass [ticket/11435] Create new template filter option (cleanup)
This commit is contained in:
commit
4b0d51adea
3 changed files with 78 additions and 34 deletions
|
@ -32,6 +32,13 @@ class phpbb_template_compile
|
||||||
*/
|
*/
|
||||||
private $filter_params;
|
private $filter_params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of default parameters
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $default_filter_params;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -44,7 +51,7 @@ class phpbb_template_compile
|
||||||
*/
|
*/
|
||||||
public function __construct($allow_php, $style_names, $locator, $phpbb_root_path, $extension_manager = null, $user = null)
|
public function __construct($allow_php, $style_names, $locator, $phpbb_root_path, $extension_manager = null, $user = null)
|
||||||
{
|
{
|
||||||
$this->filter_params = array(
|
$this->filter_params = $this->default_filter_params = array(
|
||||||
'allow_php' => $allow_php,
|
'allow_php' => $allow_php,
|
||||||
'style_names' => $style_names,
|
'style_names' => $style_names,
|
||||||
'locator' => $locator,
|
'locator' => $locator,
|
||||||
|
@ -52,9 +59,31 @@ class phpbb_template_compile
|
||||||
'extension_manager' => $extension_manager,
|
'extension_manager' => $extension_manager,
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'template_compile' => $this,
|
'template_compile' => $this,
|
||||||
|
'cleanup' => true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set filter parameters
|
||||||
|
*
|
||||||
|
* @param array $params Array of parameters (will be merged onto $this->filter_params)
|
||||||
|
*/
|
||||||
|
public function set_filter_params($params)
|
||||||
|
{
|
||||||
|
$this->filter_params = array_merge(
|
||||||
|
$this->filter_params,
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset filter parameters to their default settings
|
||||||
|
*/
|
||||||
|
public function reset_filter_params()
|
||||||
|
{
|
||||||
|
$this->filter_params = $this->default_filter_params;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles template in $source_file and writes compiled template to
|
* Compiles template in $source_file and writes compiled template to
|
||||||
* cache directory
|
* cache directory
|
||||||
|
|
|
@ -75,6 +75,14 @@ class phpbb_template_filter extends php_user_filter
|
||||||
*/
|
*/
|
||||||
private $allow_php;
|
private $allow_php;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether cleanup will be performed on resulting code, see compile()
|
||||||
|
* (Preserve whitespace)
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $cleanup = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resource locator.
|
* Resource locator.
|
||||||
*
|
*
|
||||||
|
@ -183,6 +191,7 @@ class phpbb_template_filter extends php_user_filter
|
||||||
$this->phpbb_root_path = $this->params['phpbb_root_path'];
|
$this->phpbb_root_path = $this->params['phpbb_root_path'];
|
||||||
$this->style_names = $this->params['style_names'];
|
$this->style_names = $this->params['style_names'];
|
||||||
$this->extension_manager = $this->params['extension_manager'];
|
$this->extension_manager = $this->params['extension_manager'];
|
||||||
|
$this->cleanup = $this->params['cleanup'];
|
||||||
if (isset($this->params['user']))
|
if (isset($this->params['user']))
|
||||||
{
|
{
|
||||||
$this->user = $this->params['user'];
|
$this->user = $this->params['user'];
|
||||||
|
@ -223,6 +232,8 @@ class phpbb_template_filter extends php_user_filter
|
||||||
$data = preg_replace('~<!-- ENDPHP -->.*?$~', '', $data);
|
$data = preg_replace('~<!-- ENDPHP -->.*?$~', '', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->cleanup)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Preserve whitespace.
|
Preserve whitespace.
|
||||||
|
@ -258,6 +269,8 @@ class phpbb_template_filter extends php_user_filter
|
||||||
$data = preg_replace('~(?<!^)(<\?php.+(?<!/\*\*/)\?>)$~m', "$1\n", $data);
|
$data = preg_replace('~(?<!^)(<\?php.+(?<!/\*\*/)\?>)$~m', "$1\n", $data);
|
||||||
$data = str_replace('/**/?>', "?>\n", $data);
|
$data = str_replace('/**/?>', "?>\n", $data);
|
||||||
$data = str_replace('?><?php', '', $data);
|
$data = str_replace('?><?php', '', $data);
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -995,8 +1008,14 @@ class phpbb_template_filter extends php_user_filter
|
||||||
$all_compiled = '';
|
$all_compiled = '';
|
||||||
foreach ($files as $file)
|
foreach ($files as $file)
|
||||||
{
|
{
|
||||||
|
$this->template_compile->set_filter_params(array(
|
||||||
|
'cleanup' => false,
|
||||||
|
));
|
||||||
|
|
||||||
$compiled = $this->template_compile->compile_file($file);
|
$compiled = $this->template_compile->compile_file($file);
|
||||||
|
|
||||||
|
$this->template_compile->reset_filter_params();
|
||||||
|
|
||||||
if ($compiled === false)
|
if ($compiled === false)
|
||||||
{
|
{
|
||||||
if ($this->user)
|
if ($this->user)
|
||||||
|
|
|
@ -59,10 +59,6 @@ class phpbb_template_template_spacing_test extends phpbb_template_template_test_
|
||||||
*/
|
*/
|
||||||
public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected)
|
public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected)
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test will fail until PHPBB3-11435 is fixed'
|
|
||||||
);
|
|
||||||
|
|
||||||
// Reset the engine state
|
// Reset the engine state
|
||||||
$this->setup_engine_for_events($dataset, $style_names);
|
$this->setup_engine_for_events($dataset, $style_names);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue