From 02e5a7afc49558b0925378dce825e8f8dae84ddd Mon Sep 17 00:00:00 2001 From: Marc Alexander <admin@m-a-styles.de> Date: Thu, 7 Oct 2021 21:19:35 +0200 Subject: [PATCH] [ticket/13508] Add include_css() and fix include_js() code linting issues PHPBB3-13508 --- phpBB/phpbb/template/twig/extension.php | 1 + .../template/twig/tokenparser/include_css.php | 27 ++++++++++++++ .../template/twig/tokenparser/include_js.php | 5 --- tests/template/templates/include_css.html | 10 ++++++ tests/template/templates/include_js.html | 36 +++++++++++++++++++ 5 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 phpBB/phpbb/template/twig/tokenparser/include_css.php create mode 100644 tests/template/templates/include_css.html create mode 100644 tests/template/templates/include_js.html diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 6bce7c791f..4b4771c8aa 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -62,6 +62,7 @@ class extension extends \Twig\Extension\AbstractExtension new \phpbb\template\twig\tokenparser\includeparser, new \phpbb\template\twig\tokenparser\include_js, new \phpbb\template\twig\tokenparser\includejs, + new \phpbb\template\twig\tokenparser\include_css, new \phpbb\template\twig\tokenparser\includecss, new \phpbb\template\twig\tokenparser\event($this->environment), new \phpbb\template\twig\tokenparser\includephp($this->environment), diff --git a/phpBB/phpbb/template/twig/tokenparser/include_css.php b/phpBB/phpbb/template/twig/tokenparser/include_css.php new file mode 100644 index 0000000000..353fb26c9c --- /dev/null +++ b/phpBB/phpbb/template/twig/tokenparser/include_css.php @@ -0,0 +1,27 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\template\twig\tokenparser; + +class include_css extends includecss +{ + /** + * Gets the tag name associated with this token parser. + * + * @return string The tag name + */ + public function getTag(): string + { + return 'include_css'; + } +} diff --git a/phpBB/phpbb/template/twig/tokenparser/include_js.php b/phpBB/phpbb/template/twig/tokenparser/include_js.php index 861ed1d209..5b57fb4d6f 100644 --- a/phpBB/phpbb/template/twig/tokenparser/include_js.php +++ b/phpBB/phpbb/template/twig/tokenparser/include_js.php @@ -13,11 +13,6 @@ namespace phpbb\template\twig\tokenparser; -use Twig\Error\SyntaxError; -use Twig\Node\Node; -use Twig\Token; -use Twig\TokenParser\AbstractTokenParser; - class include_js extends includejs { /** diff --git a/tests/template/templates/include_css.html b/tests/template/templates/include_css.html new file mode 100644 index 0000000000..23e3c426d7 --- /dev/null +++ b/tests/template/templates/include_css.html @@ -0,0 +1,10 @@ +<!-- IF TEST === 1 --> + <!-- INCLUDECSS child_only.css --> +<!-- ELSEIF TEST === 2 --> + <!-- INCLUDECSS parent_only.css --> +<!-- ELSEIF TEST === 3 --> + <!-- INCLUDECSS @include_css/test.css --> +<!-- ELSEIF TEST === 4 --> + <!-- INCLUDECSS @include_css/child_only.css --> +<!-- ENDIF --> +{$STYLESHEETS} diff --git a/tests/template/templates/include_js.html b/tests/template/templates/include_js.html new file mode 100644 index 0000000000..0bcdf1a815 --- /dev/null +++ b/tests/template/templates/include_js.html @@ -0,0 +1,36 @@ +<!-- IF TEST === 1 --> + <!-- INCLUDEJS parent_and_child.js --> +<!-- ELSEIF TEST === 2 --> + <!-- INCLUDEJS parent_and_child.js?assets_version=0 --> +<!-- ELSEIF TEST === 3 --> + <!-- INCLUDEJS parent_and_child.js?test=1&assets_version=0 --> +<!-- ELSEIF TEST === 4 --> + <!-- INCLUDEJS parent_and_child.js?test=1&assets_version=0 --> +<!-- ELSEIF TEST === 6 --> + <!-- INCLUDEJS {PARENT} --> +<!-- ELSEIF TEST === 7 --> + <!-- DEFINE $TEST = 'child_only.js' --> + <!-- INCLUDEJS {$TEST} --> +<!-- ELSEIF TEST === 8 --> + <!-- INCLUDEJS subdir/{PARENT} --> +<!-- ELSEIF TEST === 9 --> + <!-- INCLUDEJS {SUBDIR}/subsubdir/{PARENT} --> +<!-- ELSEIF TEST === 10 --> + <!-- INCLUDEJS {SUBDIR}/parent_only.{EXT} --> +<!-- ELSEIF TEST === 11 --> + <!-- DEFINE $TEST = 'child_only.js?test1=1&test2=2#test3' --> + <!-- INCLUDEJS {$TEST} --> +<!-- ELSEIF TEST === 12 --> + <!-- INCLUDEJS parent_only.js?test1=1&test2=2#test3 --> +<!-- ELSEIF TEST === 14 --> + <!-- INCLUDEJS parent_only.js?test1="#test3 --> +<!-- ELSEIF TEST === 15 --> + <!-- INCLUDEJS http://phpbb.com/b.js?c=d#f --> +<!-- ELSEIF TEST === 16 --> + <!-- INCLUDEJS http://phpbb.com/b.js?c=d&assets_version=2#f --> +<!-- ELSEIF TEST === 17 --> + <!-- INCLUDEJS //phpbb.com/b.js --> +<!-- ELSEIF TEST === 18 --> + <!-- INCLUDEJS parent_and_child.js?test=1&test2=0 --> +<!-- ENDIF --> +{$SCRIPTS}