From c958155fb63667e1d54d6d31489bf17c0a180dab Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 24 Jun 2013 12:39:28 -0500 Subject: [feature/twig] Able to set chain of namespaces to search for loadTemplate() This is done so that when event template files are included, if they include files themselves, that namespace is checked first, then __main__ is checked to include the correct template file. Also, when template files are included from a particular namespace, this is done so that the files from that namespace are included first, then the main namespace is checked. We may want to change this behavior in the future to allow choosing which locations have priority, but for now, this is what I am doing to make sure the behavior is simple and always the same. PHPBB3-11598 --- phpBB/includes/template/twig/node/include.php | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 phpBB/includes/template/twig/node/include.php (limited to 'phpBB/includes/template/twig/node/include.php') diff --git a/phpBB/includes/template/twig/node/include.php b/phpBB/includes/template/twig/node/include.php new file mode 100644 index 0000000000..df7a95af44 --- /dev/null +++ b/phpBB/includes/template/twig/node/include.php @@ -0,0 +1,45 @@ +addDebugInfo($this); + + $location = $this->getNode('expr')->getAttribute('value'); + $namespace = false; + + if (strpos($location, '@') === 0) + { + $namespace = substr($location, 1, strpos($location, '/') - 1); + + $compiler + ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") + + // We set the namespace lookup order to be this namespace first, then the main path + ->write("\$this->env->setNamespaceLookUpOrder(array('" . $namespace . "', '__main__'));\n") + ; + } + + parent::compile($compiler); + + if ($namespace) + { + $compiler + ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") + ; + } + } +} -- cgit v1.2.1 From 658d1b6afe7816ba92c30e227ebdef0db427ce53 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 1 Jul 2013 09:20:46 -0500 Subject: [feature/twig] Fixing include node PHPBB3-11598 --- phpBB/includes/template/twig/node/include.php | 36 ++++++++++++++------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'phpBB/includes/template/twig/node/include.php') diff --git a/phpBB/includes/template/twig/node/include.php b/phpBB/includes/template/twig/node/include.php index df7a95af44..2a90dc19e4 100644 --- a/phpBB/includes/template/twig/node/include.php +++ b/phpBB/includes/template/twig/node/include.php @@ -18,28 +18,30 @@ class phpbb_template_twig_node_include extends Twig_Node_Include { $compiler->addDebugInfo($this); - $location = $this->getNode('expr')->getAttribute('value'); - $namespace = false; - - if (strpos($location, '@') === 0) - { - $namespace = substr($location, 1, strpos($location, '/') - 1); - - $compiler + $compiler + ->write("\$location = ") + ->subcompile($this->getNode('expr')) + ->raw(";\n") + ->write("\$namespace = false;\n") + ->write("if (strpos(\$location, '@') === 0) {\n") + ->indent() + ->write("\$namespace = substr(\$location, 1, strpos(\$location, '/') - 1);\n") ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") // We set the namespace lookup order to be this namespace first, then the main path - ->write("\$this->env->setNamespaceLookUpOrder(array('" . $namespace . "', '__main__'));\n") - ; - } + ->write("\$this->env->setNamespaceLookUpOrder(array(\$namespace, '__main__'));\n") + ->outdent() + ->write("}\n") + ; parent::compile($compiler); - if ($namespace) - { - $compiler - ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") - ; - } + $compiler + ->write("if (\$namespace) {\n") + ->indent() + ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") + ->outdent() + ->write("}\n") + ; } } -- cgit v1.2.1 From 57c2d99e65ce107208db10721cff5b815ee3403c Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 2 Jul 2013 12:34:16 -0500 Subject: [feature/twig] Fix indentation PHPBB3-11598 --- phpBB/includes/template/twig/node/include.php | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'phpBB/includes/template/twig/node/include.php') diff --git a/phpBB/includes/template/twig/node/include.php b/phpBB/includes/template/twig/node/include.php index 2a90dc19e4..a614cbe20f 100644 --- a/phpBB/includes/template/twig/node/include.php +++ b/phpBB/includes/template/twig/node/include.php @@ -9,14 +9,14 @@ class phpbb_template_twig_node_include extends Twig_Node_Include { - /** - * Compiles the node to PHP. - * - * @param Twig_Compiler A Twig_Compiler instance - */ - public function compile(Twig_Compiler $compiler) - { - $compiler->addDebugInfo($this); + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->addDebugInfo($this); $compiler ->write("\$location = ") @@ -26,15 +26,15 @@ class phpbb_template_twig_node_include extends Twig_Node_Include ->write("if (strpos(\$location, '@') === 0) {\n") ->indent() ->write("\$namespace = substr(\$location, 1, strpos(\$location, '/') - 1);\n") - ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") + ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") - // We set the namespace lookup order to be this namespace first, then the main path - ->write("\$this->env->setNamespaceLookUpOrder(array(\$namespace, '__main__'));\n") + // We set the namespace lookup order to be this namespace first, then the main path + ->write("\$this->env->setNamespaceLookUpOrder(array(\$namespace, '__main__'));\n") ->outdent() ->write("}\n") ; - parent::compile($compiler); + parent::compile($compiler); $compiler ->write("if (\$namespace) {\n") @@ -42,6 +42,6 @@ class phpbb_template_twig_node_include extends Twig_Node_Include ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") ->outdent() ->write("}\n") - ; - } + ; + } } -- cgit v1.2.1 From c5c34ff831faf96368d34012dc65bdb9451227aa Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Jul 2013 13:10:35 -0500 Subject: [feature/twig] Add check for defined IN_PHPBB in all new Twig related files PHPBB3-11598 --- phpBB/includes/template/twig/node/include.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'phpBB/includes/template/twig/node/include.php') diff --git a/phpBB/includes/template/twig/node/include.php b/phpBB/includes/template/twig/node/include.php index a614cbe20f..5c6ae1bbcf 100644 --- a/phpBB/includes/template/twig/node/include.php +++ b/phpBB/includes/template/twig/node/include.php @@ -7,6 +7,15 @@ * */ +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + + class phpbb_template_twig_node_include extends Twig_Node_Include { /** -- cgit v1.2.1