diff --git a/phpBB/includes/template/twig/environment.php b/phpBB/includes/template/twig/environment.php index 616321e15a..d9b56a56f6 100644 --- a/phpBB/includes/template/twig/environment.php +++ b/phpBB/includes/template/twig/environment.php @@ -39,6 +39,8 @@ class phpbb_template_twig_environment extends Twig_Environment return false; } + // @todo correct cache file name handling + return $this->getCache() . '/' . preg_replace('#[^a-zA-Z0-9_/]#', '_', $name) . '.php'; } diff --git a/phpBB/includes/template/twig/extension.php b/phpBB/includes/template/twig/extension.php index ff37a38c29..c9b719546f 100644 --- a/phpBB/includes/template/twig/extension.php +++ b/phpBB/includes/template/twig/extension.php @@ -31,6 +31,7 @@ class phpbb_template_twig_extension extends Twig_Extension new phpbb_template_twig_tokenparser_include, new phpbb_template_twig_tokenparser_includejs, new phpbb_template_twig_tokenparser_event, + new phpbb_template_twig_tokenparser_php, ); } diff --git a/phpBB/includes/template/twig/node/php.php b/phpBB/includes/template/twig/node/php.php new file mode 100644 index 0000000000..cf60ef33fc --- /dev/null +++ b/phpBB/includes/template/twig/node/php.php @@ -0,0 +1,40 @@ +environment = $environment; + + parent::__construct(array('text' => $text), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->addDebugInfo($this); + + $config = $this->environment->get_phpbb_config(); + + if ($config['tpl_allow_php']) + { + $compiler + ->raw($this->getNode('text')->getAttribute('data')) + ; + } + } +} diff --git a/phpBB/includes/template/twig/tokenparser/php.php b/phpBB/includes/template/twig/tokenparser/php.php new file mode 100644 index 0000000000..7db57081e2 --- /dev/null +++ b/phpBB/includes/template/twig/tokenparser/php.php @@ -0,0 +1,46 @@ +parser->getStream(); + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + $body = $this->parser->subparse(array($this, 'decideEnd'), true); + + $stream->expect(Twig_Token::BLOCK_END_TYPE); + + return new phpbb_template_twig_node_php($body, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); + } + + public function decideEnd(Twig_Token $token) + { + return $token->test('ENDPHP'); + } + + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag() + { + return 'PHP'; + } +}