diff --git a/phpBB/config/default/container/services_twig.yml b/phpBB/config/default/container/services_twig.yml index 858a3a5e75..9d9436f89e 100644 --- a/phpBB/config/default/container/services_twig.yml +++ b/phpBB/config/default/container/services_twig.yml @@ -63,11 +63,15 @@ services: template.twig.extensions.implode: class: phpbb\template\twig\extension\implode + tags: + - { name: twig.extension } template.twig.extensions.macro: class: phpbb\template\twig\extension\macro arguments: - '@template.twig.environment' + tags: + - { name: twig.extension } template.twig.extensions.routing: class: phpbb\template\twig\extension\routing diff --git a/phpBB/phpbb/template/twig/extension/icon.php b/phpBB/phpbb/template/twig/extension/icon.php index f650438d66..1a6adc48f3 100644 --- a/phpBB/phpbb/template/twig/extension/icon.php +++ b/phpBB/phpbb/template/twig/extension/icon.php @@ -15,7 +15,7 @@ namespace phpbb\template\twig\extension; use phpbb\template\twig\environment; -abstract class icon extends \Twig\Extension\AbstractExtension +class icon extends \Twig\Extension\AbstractExtension { /** @var \phpbb\user */ protected $user; @@ -48,7 +48,7 @@ abstract class icon extends \Twig\Extension\AbstractExtension public function getFilters() { return [ - new \Twig\TwigFilter('Png_path', [$this, 'png_path'], ['needs_environment' => true]), + new \Twig\TwigFilter('png_path', [$this, 'png_path'], ['needs_environment' => true]), ]; } @@ -71,7 +71,7 @@ abstract class icon extends \Twig\Extension\AbstractExtension * @param string $icon The icon name * @return string */ - protected function png_path(environment $environment, $icon) + public function png_path(environment $environment, $icon) { $board_url = defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH; $web_path = $board_url ? generate_board_url() . '/' : $environment->get_web_root_path(); @@ -87,7 +87,7 @@ abstract class icon extends \Twig\Extension\AbstractExtension * @param string $icon The icon name * @return string */ - protected function svg_clean(environment $environment, $icon) + public function svg_clean(environment $environment, $icon) { try { @@ -110,8 +110,10 @@ abstract class icon extends \Twig\Extension\AbstractExtension return ''; } - foreach ($doc->childNodes as $child) { - if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { + foreach ($doc->childNodes as $child) + { + if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) + { $child->parentNode->removeChild($child); } } diff --git a/phpBB/phpbb/template/twig/extension/implode.php b/phpBB/phpbb/template/twig/extension/implode.php index 6d0ef58b3f..5c6d313a4d 100644 --- a/phpBB/phpbb/template/twig/extension/implode.php +++ b/phpBB/phpbb/template/twig/extension/implode.php @@ -13,7 +13,7 @@ namespace phpbb\template\twig\extension; -abstract class implode extends \Twig\Extension\AbstractExtension +class implode extends \Twig\Extension\AbstractExtension { /** * Returns the name of this extension. @@ -50,7 +50,7 @@ abstract class implode extends \Twig\Extension\AbstractExtension * @param mixed $arguments * @return string */ - protected function implode_attributes(...$arguments) + public function implode_attributes(...$arguments) { $string = ''; $attributes = []; @@ -71,13 +71,17 @@ abstract class implode extends \Twig\Extension\AbstractExtension } else if (is_array($value)) { - if (is_integer($key) && is_string($value)) + foreach ($value as $k => $v) { - $attributes[] = $value; - } - else - { - $attributes[$key] = $value; + if (is_integer($k) && is_string($v)) + { + $attributes[] = $v; + } + else + { + + $attributes[$k] = $v; + } } } else @@ -92,11 +96,13 @@ abstract class implode extends \Twig\Extension\AbstractExtension { if (is_string($attribute)) { + $value = is_bool($value) ? ($value ? 'true' : 'false') : $value; + $string .= ' ' . $attribute . '="' . $value . '"'; } else { - $string .= ' ' . $attribute; + $string .= ' ' . $value; } } @@ -129,7 +135,7 @@ abstract class implode extends \Twig\Extension\AbstractExtension * @param mixed $arguments * @return string The classes string prepended with a space */ - protected function implode_classes(...$arguments) + public function implode_classes(...$arguments) { $classes = []; diff --git a/phpBB/phpbb/template/twig/extension/macro.php b/phpBB/phpbb/template/twig/extension/macro.php index fa7614506a..f786a15de1 100644 --- a/phpBB/phpbb/template/twig/extension/macro.php +++ b/phpBB/phpbb/template/twig/extension/macro.php @@ -15,7 +15,7 @@ namespace phpbb\template\twig\extension; use phpbb\template\twig\environment; -abstract class macro extends \Twig\Extension\AbstractExtension implements \Twig\Extension\GlobalsInterface +class macro extends \Twig\Extension\AbstractExtension implements \Twig\Extension\GlobalsInterface { /** @var environment */ protected $twig; @@ -37,7 +37,7 @@ abstract class macro extends \Twig\Extension\AbstractExtension implements \Twig\ */ public function getName() { - return 'macro'; + return 'macros'; } /** diff --git a/phpBB/styles/all/template/macros.html b/phpBB/styles/all/template/macros.html index 5a62d5374e..637140c6dc 100644 --- a/phpBB/styles/all/template/macros.html +++ b/phpBB/styles/all/template/macros.html @@ -1,33 +1,5 @@ {# Wrapper function #} {% macro Icon(type, icon, classes = '', title = '', hidden = false, attributes = {}) %} {% set type = type|capitalize %} - - {% if type in ['Fa', 'Png', 'Svg'] %} - {{ attribute(_self, type, [icon, classes, title, hidden, attributes]) }} - {% endif %} - +Hello {% endmacro Icon %} - -{# FA icons #} -{% macro Fa(icon, classes = '', title = '', hidden = false, attributes = {}) %} - - {% if title %}{{ lang(title) }}{% endif %} -{% endmacro Fa %} - -{# PNG icons #} -{% macro Png(icon, classes = '', title = '', hidden = false, attributes = {}) %} - - {% if title %} -
- {TOTAL_USERS_ONLINE} ({L_ONLINE_EXPLAIN})
{RECORD_USERS}
+ {TOTAL_USERS_ONLINE} ({L_ONLINE_EXPLAIN})
{RECORD_USERS}
{LOGGED_IN_USER_LIST}
{L_LEGEND}{L_COLON} {LEGEND}