mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +00:00
[feature/template-engine] Add back IN_PHPBB preamble.
PHPBB3-9726
This commit is contained in:
parent
49cf28a9c4
commit
0462ab3a4a
3 changed files with 53 additions and 1 deletions
|
@ -54,6 +54,7 @@ class phpbb_template_filter extends php_user_filter
|
||||||
public function filter($in, $out, &$consumed, $closing)
|
public function filter($in, $out, &$consumed, $closing)
|
||||||
{
|
{
|
||||||
$written = false;
|
$written = false;
|
||||||
|
$first = false;
|
||||||
|
|
||||||
while ($bucket = stream_bucket_make_writeable($in))
|
while ($bucket = stream_bucket_make_writeable($in))
|
||||||
{
|
{
|
||||||
|
@ -71,7 +72,13 @@ class phpbb_template_filter extends php_user_filter
|
||||||
|
|
||||||
$written = true;
|
$written = true;
|
||||||
|
|
||||||
$bucket->data = $this->compile($data);
|
$data = $this->compile($data);
|
||||||
|
if (!$first)
|
||||||
|
{
|
||||||
|
$data = $this->prepend_preamble($data);
|
||||||
|
$first = false;
|
||||||
|
}
|
||||||
|
$bucket->data = $data;
|
||||||
$bucket->datalen = strlen($bucket->data);
|
$bucket->datalen = strlen($bucket->data);
|
||||||
stream_bucket_append($out, $bucket);
|
stream_bucket_append($out, $bucket);
|
||||||
}
|
}
|
||||||
|
@ -150,6 +157,18 @@ class phpbb_template_filter extends php_user_filter
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepends a preamble to compiled template.
|
||||||
|
* Currently preamble checks if IN_PHPBB is defined and calls exit() if it is not.
|
||||||
|
* @param string $data Compiled template chunk
|
||||||
|
* @return string Compiled template chunk with preamble prepended
|
||||||
|
*/
|
||||||
|
private function prepend_preamble($data)
|
||||||
|
{
|
||||||
|
$data = "<?php if (!defined('IN_PHPBB')) exit;" . ((strncmp($data, '<?php', 5) === 0) ? substr($data, 5) : ' ?>' . $data);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
private function replace($matches)
|
private function replace($matches)
|
||||||
{
|
{
|
||||||
if ($this->in_php && $matches[1] != 'ENDPHP')
|
if ($this->in_php && $matches[1] != 'ENDPHP')
|
||||||
|
|
32
tests/template/template_compile_test.php
Normal file
32
tests/template/template_compile_test.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2008 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||||
|
require_once dirname(__FILE__) . '/../../phpBB/includes/template.php';
|
||||||
|
|
||||||
|
class phpbb_template_template_compile_test extends phpbb_test_case
|
||||||
|
{
|
||||||
|
private $template_compile;
|
||||||
|
private $template_path;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->template_compile = new phpbb_template_compile();
|
||||||
|
$this->template_path = dirname(__FILE__) . '/templates';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_in_phpbb()
|
||||||
|
{
|
||||||
|
$output = $this->template_compile->compile_file($this->template_path . '/trivial.html');
|
||||||
|
$this->assertTrue(strlen($output) > 0);
|
||||||
|
$statements = explode(';', $output);
|
||||||
|
$first_statement = $statements[0];
|
||||||
|
$this->assertTrue(!!preg_match('#if.*defined.*IN_PHPBB.*exit#', $first_statement));
|
||||||
|
}
|
||||||
|
}
|
1
tests/template/templates/trivial.html
Normal file
1
tests/template/templates/trivial.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This is a trivial template.
|
Loading…
Add table
Reference in a new issue