diff --git a/phpBB/includes/template/twig/environment.php b/phpBB/includes/template/twig/environment.php index 4c7f0002ba..616321e15a 100644 --- a/phpBB/includes/template/twig/environment.php +++ b/phpBB/includes/template/twig/environment.php @@ -20,6 +20,9 @@ class phpbb_template_twig_environment extends Twig_Environment /** @var array */ protected $phpbbExtensions; + /** @var phpbb_config */ + protected $phpbbConfig; + /** @var array **/ protected $namespaceLookUpOrder = array('__main__'); @@ -62,6 +65,29 @@ class phpbb_template_twig_environment extends Twig_Environment return $this; } + /** + * Get phpBB config + * + * @return phpbb_config + */ + public function get_phpbb_config() + { + return $this->phpbbConfig; + } + + /** + * Set phpBB config + * + * @param phpbb_config $config + * @return Twig_Environment + */ + public function set_phpbb_config($config) + { + $this->phpbbConfig = $config; + + return $this; + } + /** * Get the namespace look up order * diff --git a/phpBB/includes/template/twig/node/event.php b/phpBB/includes/template/twig/node/event.php index 12e6ef1329..358c68dae5 100644 --- a/phpBB/includes/template/twig/node/event.php +++ b/phpBB/includes/template/twig/node/event.php @@ -9,6 +9,7 @@ class phpbb_template_twig_node_event extends Twig_Node { + /** @var Twig_Environment */ protected $environment; public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null) diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php index 881636a326..f4c26affa4 100644 --- a/phpBB/includes/template/twig/node/includejs.php +++ b/phpBB/includes/template/twig/node/includejs.php @@ -9,8 +9,13 @@ class phpbb_template_twig_node_includejs extends Twig_Node { - public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) + /** @var Twig_Environment */ + protected $environment; + + public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null) { + $this->environment = $environment; + parent::__construct(array('expr' => $expr), array(), $lineno, $tag); } @@ -23,10 +28,12 @@ class phpbb_template_twig_node_includejs extends Twig_Node { $compiler->addDebugInfo($this); + $config = $this->environment->get_phpbb_config(); + $compiler ->write("\$context['SCRIPTS'] .= '';\n\n") ; } } diff --git a/phpBB/includes/template/twig/tokenparser/includejs.php b/phpBB/includes/template/twig/tokenparser/includejs.php index efa8692f4b..0b46f315d2 100644 --- a/phpBB/includes/template/twig/tokenparser/includejs.php +++ b/phpBB/includes/template/twig/tokenparser/includejs.php @@ -23,7 +23,7 @@ class phpbb_template_twig_tokenparser_includejs extends Twig_TokenParser $stream = $this->parser->getStream(); $stream->expect(Twig_Token::BLOCK_END_TYPE); - return new phpbb_template_twig_node_includejs($expr, $token->getLine(), $this->getTag()); + return new phpbb_template_twig_node_includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); } /** diff --git a/phpBB/includes/template/twig/twig.php b/phpBB/includes/template/twig/twig.php index e2c9afbc78..af8ab615e6 100644 --- a/phpBB/includes/template/twig/twig.php +++ b/phpBB/includes/template/twig/twig.php @@ -127,6 +127,9 @@ class phpbb_template_twig implements phpbb_template $this->twig->set_phpbb_extensions($this->extension_manager->all_enabled()); } + // Set config + $this->twig->set_phpbb_config($this->config); + // Clear previous cache files (while WIP) // @todo remove $this->clear_cache(); @@ -187,7 +190,7 @@ class phpbb_template_twig implements phpbb_template // Add admin namespace // @todo use phpbb_admin path - $loader->addPath($this->phpbb_root_path . 'adm/style/', 'admin'); + $this->twig->getLoader()->addPath($this->phpbb_root_path . 'adm/style/', 'admin'); // Add all namespaces for all extensions if ($this->extension_manager instanceof phpbb_extension_manager) @@ -439,16 +442,16 @@ class phpbb_template_twig implements phpbb_template $vars['L_' . strtoupper($key)] = $value; $vars['LA_' . strtoupper($key)] = addslashes($value); } - - $vars = array_merge( - $vars, - $this->context->get_rootref(), - array( - '_phpbb_blocks' => $this->context->get_tpldata(), - ) - ); } + $vars = array_merge( + $vars, + $this->context->get_rootref(), + array( + '_phpbb_blocks' => $this->context->get_tpldata(), + ) + ); + // Must do this so that works correctly // (only for the base loops, the rest are properly handled by the begin node) foreach ($this->context->get_tpldata() as $block_name => $block_values)