From 15114067e6c88e4ec8fa9d1ff66fd0de28b1144f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 10 Jun 2013 11:17:11 -0500 Subject: [feature/twig] Replace phpBB template code with Twig syntax, then parse w/Twig Fixing begin token/node, adding includejs token/node PHPBB3-11598 --- phpBB/includes/template/twig/node/includejs.php | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 phpBB/includes/template/twig/node/includejs.php (limited to 'phpBB/includes/template/twig/node/includejs.php') diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php new file mode 100644 index 0000000000..e30ab75125 --- /dev/null +++ b/phpBB/includes/template/twig/node/includejs.php @@ -0,0 +1,50 @@ + + */ +class phpbb_template_twig_node_includejs 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); + + $compiler + ->write("try {\n") + ->indent() + ; + + $this->addGetTemplate($compiler); + + $compiler->raw('->display('); + + $this->addTemplateArguments($compiler); + + $compiler->raw(");\n"); + + $compiler + ->write("} catch (Twig_Error_Loader \$e) {\n") + ->indent() + ->write("// ignore missing template\n") + ->outdent() + ->write("}\n\n") + ; + } +} -- cgit v1.2.1 From 95884edf08d962d0f8cf764f4870f910d4d65009 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 12 Jun 2013 12:32:56 -0500 Subject: [feature/twig] Correcting output of INCLUDEJS PHPBB3-11598 --- phpBB/includes/template/twig/node/includejs.php | 51 ++++++++----------------- 1 file changed, 16 insertions(+), 35 deletions(-) (limited to 'phpBB/includes/template/twig/node/includejs.php') diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php index e30ab75125..6fe8e155b7 100644 --- a/phpBB/includes/template/twig/node/includejs.php +++ b/phpBB/includes/template/twig/node/includejs.php @@ -1,22 +1,19 @@ - */ -class phpbb_template_twig_node_includejs extends Twig_Node_Include +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_template_twig_node_includejs extends Twig_Node { + public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) + { + parent::__construct(array('expr' => $expr), array(), $lineno, $tag); + } + /** * Compiles the node to PHP. * @@ -27,24 +24,8 @@ class phpbb_template_twig_node_includejs extends Twig_Node_Include $compiler->addDebugInfo($this); $compiler - ->write("try {\n") - ->indent() - ; - - $this->addGetTemplate($compiler); - - $compiler->raw('->display('); - - $this->addTemplateArguments($compiler); - - $compiler->raw(");\n"); - - $compiler - ->write("} catch (Twig_Error_Loader \$e) {\n") - ->indent() - ->write("// ignore missing template\n") - ->outdent() - ->write("}\n\n") - ; + ->write("\$context['SCRIPTS'] .= '';\n\n") ; } } -- cgit v1.2.1 From 156d5c671fb9db28fbbdcacb974093c2c52b0f5b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 2 Jul 2013 10:13:16 -0500 Subject: [feature/twig] INCLUDEJS now uses the definition class This had to be done because, like DEFINE, setting variables to $context only affected the local file and any children, not parent templates. PHPBB3-11598 --- phpBB/includes/template/twig/node/includejs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/template/twig/node/includejs.php') diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php index f4c26affa4..bba5d4ef91 100644 --- a/phpBB/includes/template/twig/node/includejs.php +++ b/phpBB/includes/template/twig/node/includejs.php @@ -31,9 +31,9 @@ class phpbb_template_twig_node_includejs extends Twig_Node $config = $this->environment->get_phpbb_config(); $compiler - ->write("\$context['SCRIPTS'] .= '';\n\n") + ->raw(" . '?assets_version=" . $config['assets_version'] . "\">');\n") ; } } -- cgit v1.2.1 From 59d13d0535ab3687725d36f2dbe2ee64de294df8 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 2 Jul 2013 11:02:55 -0500 Subject: [feature/twig] INCLUDEJS behavior now supports local relative paths This was done because T_TEMPLATE_PATH is not always correct for js files (e.g. the inheriting style does not include these). Now we use the Twig Loader to find the correct file to link to (most specific file first, then parent styles). Also allows using @namespace convention PHPBB3-11598 --- phpBB/includes/template/twig/node/includejs.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/template/twig/node/includejs.php') diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php index bba5d4ef91..91b24e8068 100644 --- a/phpBB/includes/template/twig/node/includejs.php +++ b/phpBB/includes/template/twig/node/includejs.php @@ -31,9 +31,17 @@ class phpbb_template_twig_node_includejs extends Twig_Node $config = $this->environment->get_phpbb_config(); $compiler - ->write("\$context['definition']->append('SCRIPTS', '');\n") + ->raw(";\n") + ->write("if (!file_exists(\$js_file)) {\n") + ->indent() + ->write("\$js_file = \$this->getEnvironment()->getLoader()->getCacheKey(\$js_file);\n") + ->outdent() + ->write("}\n") + ->write("\$context['definition']->append('SCRIPTS', '\n');\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/includejs.php | 36 ++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'phpBB/includes/template/twig/node/includejs.php') diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php index 91b24e8068..6d0d67c6c9 100644 --- a/phpBB/includes/template/twig/node/includejs.php +++ b/phpBB/includes/template/twig/node/includejs.php @@ -12,27 +12,27 @@ class phpbb_template_twig_node_includejs extends Twig_Node /** @var Twig_Environment */ protected $environment; - public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null) - { - $this->environment = $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); - } + parent::__construct(array('expr' => $expr), array(), $lineno, $tag); + } - /** - * 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); $config = $this->environment->get_phpbb_config(); - $compiler + $compiler ->write("\$js_file = ") - ->subcompile($this->getNode('expr')) + ->subcompile($this->getNode('expr')) ->raw(";\n") ->write("if (!file_exists(\$js_file)) {\n") ->indent() @@ -41,7 +41,7 @@ class phpbb_template_twig_node_includejs extends Twig_Node ->write("}\n") ->write("\$context['definition']->append('SCRIPTS', '\n');\n") - ; - } + ->raw(" . '?assets_version=" . $config['assets_version'] . "\">\n');\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/includejs.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'phpBB/includes/template/twig/node/includejs.php') diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php index 6d0d67c6c9..943eb89ace 100644 --- a/phpBB/includes/template/twig/node/includejs.php +++ b/phpBB/includes/template/twig/node/includejs.php @@ -7,6 +7,15 @@ * */ +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + + class phpbb_template_twig_node_includejs extends Twig_Node { /** @var Twig_Environment */ -- cgit v1.2.1 From ab5a79a823de50667798d4e49fc7758a3fd9f132 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 10 Jul 2013 13:19:34 -0500 Subject: [ticket/11388] includejs inherit from includeasset Copied from the INCLUDECSS PR, since this needed to be modified. Added checks for argument strings/anchors/http/https paths in asset files to load files properly PHPBB3-11388 --- phpBB/includes/template/twig/node/includejs.php | 38 +++++-------------------- 1 file changed, 7 insertions(+), 31 deletions(-) (limited to 'phpBB/includes/template/twig/node/includejs.php') diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php index 943eb89ace..fdf2bea3ed 100644 --- a/phpBB/includes/template/twig/node/includejs.php +++ b/phpBB/includes/template/twig/node/includejs.php @@ -7,25 +7,11 @@ * */ -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) +class phpbb_template_twig_node_includejs extends phpbb_template_twig_node_includeasset { - exit; -} - - -class phpbb_template_twig_node_includejs extends Twig_Node -{ - /** @var Twig_Environment */ - protected $environment; - - public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null) + public function get_definition_name() { - $this->environment = $environment; - - parent::__construct(array('expr' => $expr), array(), $lineno, $tag); + return 'SCRIPTS'; } /** @@ -33,24 +19,14 @@ class phpbb_template_twig_node_includejs extends Twig_Node * * @param Twig_Compiler A Twig_Compiler instance */ - public function compile(Twig_Compiler $compiler) + protected function append_asset(Twig_Compiler $compiler) { - $compiler->addDebugInfo($this); - $config = $this->environment->get_phpbb_config(); $compiler - ->write("\$js_file = ") - ->subcompile($this->getNode('expr')) - ->raw(";\n") - ->write("if (!file_exists(\$js_file)) {\n") - ->indent() - ->write("\$js_file = \$this->getEnvironment()->getLoader()->getCacheKey(\$js_file);\n") - ->outdent() - ->write("}\n") - ->write("\$context['definition']->append('SCRIPTS', '\n');\n") + ->raw("\n") ; } } -- cgit v1.2.1