Compare commits

..

1 commit

Author SHA1 Message Date
rxu
5d5d20f595
Merge 063f0aec45 into e34e1759c7 2025-06-14 11:45:50 +02:00
23 changed files with 20 additions and 358 deletions

View file

@ -339,14 +339,6 @@ class helper
protected function render_language_select($selected_language = null) protected function render_language_select($selected_language = null)
{ {
$langs = $this->lang_helper->get_available_languages(); $langs = $this->lang_helper->get_available_languages();
// The first language will be selected by default. Unless a user has consciously included
// other languages in the installation process, it will be British English anyway.
if ($selected_language === null && count($langs))
{
$selected_language = $langs[0]['iso'];
}
foreach ($langs as $lang) foreach ($langs as $lang)
{ {
$this->template->assign_block_vars('language_select_item', array( $this->template->assign_block_vars('language_select_item', array(

View file

@ -65,8 +65,6 @@ class language_file_helper
$available_languages[] = $this->get_language_data_from_json($data); $available_languages[] = $this->get_language_data_from_json($data);
} }
usort($available_languages, [$this, 'sort_by_local_name']);
return $available_languages; return $available_languages;
} }
@ -125,27 +123,4 @@ class language_file_helper
'turnstile_lang' => $data['extra']['turnstile-lang'] ?? '', 'turnstile_lang' => $data['extra']['turnstile-lang'] ?? '',
]; ];
} }
/**
* Sorts the languages by their name instead of iso code
*
* @param mixed $a First language data
* @param mixed $b Second language data
* @return int
*/
private static function sort_by_local_name(mixed $a, mixed $b): int
{
if ($a['local_name'] > $b['local_name'])
{
return 1;
}
else if ($a['local_name'] < $b['local_name'])
{
return -1;
}
else
{
return 0;
}
}
} }

View file

@ -161,16 +161,6 @@ class environment extends \Twig\Environment
return $this->assets_bag; return $this->assets_bag;
} }
/**
* Gets the event dispatcher instance
*
* @return dispatcher_interface
*/
public function get_phpbb_dispatcher()
{
return $this->phpbb_dispatcher;
}
/** /**
* Get the namespace look up order * Get the namespace look up order
* *

View file

@ -24,13 +24,9 @@ class event extends \Twig\Node\Node
/** @var \phpbb\template\twig\environment */ /** @var \phpbb\template\twig\environment */
protected $environment; protected $environment;
/** @var array */ public function __construct(\Twig\Node\Expression\AbstractExpression $expr, \phpbb\template\twig\environment $environment, $lineno, $tag = null)
protected $template_event_priority_array;
public function __construct(\Twig\Node\Expression\AbstractExpression $expr, \phpbb\template\twig\environment $environment, $lineno, $tag = null, $template_event_priority_array = [])
{ {
$this->environment = $environment; $this->environment = $environment;
$this->template_event_priority_array = $template_event_priority_array;
parent::__construct(array('expr' => $expr), array(), $lineno, $tag); parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
} }
@ -46,20 +42,10 @@ class event extends \Twig\Node\Node
$location = $this->listener_directory . $this->getNode('expr')->getAttribute('name'); $location = $this->listener_directory . $this->getNode('expr')->getAttribute('name');
$template_event_listeners = [];
// Group and sort extension template events in according to their priority (0 by default if not set)
foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path) foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path)
{ {
$ext_namespace = str_replace('/', '_', $ext_namespace); $ext_namespace = str_replace('/', '_', $ext_namespace);
$priority_key = intval($this->template_event_priority_array[$ext_namespace][$location] ?? 0);
$template_event_listeners[$priority_key][] = $ext_namespace;
}
krsort($template_event_listeners);
$template_event_listeners = array_merge(...$template_event_listeners);
foreach ($template_event_listeners as $ext_namespace)
{
if ($this->environment->isDebug()) if ($this->environment->isDebug())
{ {
// If debug mode is enabled, lets check for new/removed EVENT // If debug mode is enabled, lets check for new/removed EVENT
@ -68,7 +54,8 @@ class event extends \Twig\Node\Node
// purge the cache when a new event template file is added) // purge the cache when a new event template file is added)
$compiler $compiler
->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n") ->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n")
->indent(); ->indent()
;
} }
if ($this->environment->isDebug() || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) if ($this->environment->isDebug() || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html'))
@ -79,14 +66,16 @@ class event extends \Twig\Node\Node
// We set the namespace lookup order to be this extension first, then the main path // We set the namespace lookup order to be this extension first, then the main path
->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n") ->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n")
->write("\$this->env->loadTemplate(\$this->env->getTemplateClass('@{$ext_namespace}/{$location}.html'), '@{$ext_namespace}/{$location}.html')->display(\$context);\n") ->write("\$this->env->loadTemplate(\$this->env->getTemplateClass('@{$ext_namespace}/{$location}.html'), '@{$ext_namespace}/{$location}.html')->display(\$context);\n")
->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n"); ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n")
;
} }
if ($this->environment->isDebug()) if ($this->environment->isDebug())
{ {
$compiler $compiler
->outdent() ->outdent()
->write("}\n\n"); ->write("}\n\n")
;
} }
} }
} }

View file

@ -18,9 +18,6 @@ class event extends \Twig\TokenParser\AbstractTokenParser
/** @var \phpbb\template\twig\environment */ /** @var \phpbb\template\twig\environment */
protected $environment; protected $environment;
/** @var array */
protected $template_event_priority_array;
/** /**
* Constructor * Constructor
* *
@ -29,25 +26,6 @@ class event extends \Twig\TokenParser\AbstractTokenParser
public function __construct(\phpbb\template\twig\environment $environment) public function __construct(\phpbb\template\twig\environment $environment)
{ {
$this->environment = $environment; $this->environment = $environment;
$phpbb_dispatcher = $this->environment->get_phpbb_dispatcher();
$template_event_priority_array = [];
/**
* Allows assigning priority to template event listeners
*
* @event core.twig_event_tokenparser_constructor
* @var array template_event_priority_array Array with template event priority assignments per extension namespace
*
* @since 4.0.0-a1
*/
if ($phpbb_dispatcher)
{
$vars = ['template_event_priority_array'];
extract($phpbb_dispatcher->trigger_event('core.twig_event_tokenparser_constructor', compact($vars)));
}
$this->template_event_priority_array = $template_event_priority_array;
unset($template_event_priority_array);
} }
/** /**
@ -64,7 +42,7 @@ class event extends \Twig\TokenParser\AbstractTokenParser
$stream = $this->parser->getStream(); $stream = $this->parser->getStream();
$stream->expect(\Twig\Token::BLOCK_END_TYPE); $stream->expect(\Twig\Token::BLOCK_END_TYPE);
return new \phpbb\template\twig\node\event($expr, $this->environment, $token->getLine(), $this->getTag(), $this->template_event_priority_array); return new \phpbb\template\twig\node\event($expr, $this->environment, $token->getLine(), $this->getTag());
} }
/** /**

View file

@ -16,6 +16,8 @@
*/ */
class phpbb_functional_extension_controller_test extends phpbb_functional_test_case class phpbb_functional_extension_controller_test extends phpbb_functional_test_case
{ {
protected $phpbb_extension_manager;
private static $helper; private static $helper;
protected static $fixtures = array( protected static $fixtures = array(

View file

@ -16,6 +16,8 @@
*/ */
class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_case class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_case
{ {
protected $phpbb_extension_manager;
private static $helper; private static $helper;
protected static $fixtures = array( protected static $fixtures = array(

View file

@ -17,6 +17,8 @@ require_once __DIR__ . '/../../phpBB/includes/acp/acp_modules.php';
*/ */
class phpbb_functional_extension_module_test extends phpbb_functional_test_case class phpbb_functional_extension_module_test extends phpbb_functional_test_case
{ {
protected $phpbb_extension_manager;
private static $helper; private static $helper;
protected static $fixtures = array( protected static $fixtures = array(

View file

@ -16,6 +16,8 @@
*/ */
class phpbb_functional_extension_permission_lang_test extends phpbb_functional_test_case class phpbb_functional_extension_permission_lang_test extends phpbb_functional_test_case
{ {
protected $phpbb_extension_manager;
private static $helper; private static $helper;
protected static $fixtures = array( protected static $fixtures = array(

View file

@ -1,105 +0,0 @@
<?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.
*
*/
/**
* @group functional
*/
class phpbb_functional_extension_template_event_order_test extends phpbb_functional_test_case
{
static private $helper;
static protected $fixtures = [
'./',
];
static public function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::$helper = new phpbb_test_case_helpers(__CLASS__);
self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures);
}
static public function tearDownAfterClass(): void
{
parent::tearDownAfterClass();
self::$helper->restore_original_ext_dir();
}
protected function setUp(): void
{
parent::setUp();
$this->purge_cache();
}
protected function tearDown(): void
{
$this->uninstall_ext('foo/bar');
$this->uninstall_ext('foo/foo');
parent::tearDown();
}
protected static function setup_extensions()
{
return ['foo/bar', 'foo/foo'];
}
/**
* Check extensions template event listener prioritizing
*/
public function test_different_template_event_priority()
{
global $phpbb_root_path;
$crawler = self::request('GET', 'index.php');
$quick_links_menu = $crawler->filter('ul[role="menu"]')->eq(0);
$quick_links_menu_nodes_count = (int) $quick_links_menu->filter('li')->count();
// Ensure foo/foo template event goes before foo/bar one
$this->assertStringContainsString('FOO_FOO_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 4)->filter('span')->text());
$this->assertStringContainsString('FOO_BAR_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 3)->filter('span')->text());
// Change template events order to default, put foo/bar event before foo/foo one
$this->disable_ext('foo/bar');
$this->disable_ext('foo/foo');
$this->assertTrue(copy(__DIR__ . '/fixtures/ext/foo/bar/event/template_event_order_higher.php', $phpbb_root_path . 'ext/foo/bar/event/template_event_order.php'));
$this->assertTrue(copy(__DIR__ . '/fixtures/ext/foo/foo/event/template_event_order_lower.php', $phpbb_root_path . 'ext/foo/foo/event/template_event_order.php'));
$this->install_ext('foo/bar');
$this->install_ext('foo/foo');
$crawler = self::request('GET', 'index.php');
$quick_links_menu = $crawler->filter('ul[role="menu"]')->eq(0);
$quick_links_menu_nodes_count = (int) $quick_links_menu->filter('li')->count();
// Ensure foo/foo template event goes before foo/bar one
$this->assertStringContainsString('FOO_BAR_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 4)->filter('span')->text());
$this->assertStringContainsString('FOO_FOO_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 3)->filter('span')->text());
}
/**
* Check extensions template event listener equal (default - 0) priority rendering
* Should render in the order of reading listener files from the filesystem
*/
public function test_same_template_event_priority()
{
global $phpbb_root_path;
$crawler = self::request('GET', 'index.php');
// Ensure foo/bar template event goes before foo/foo one (assuming they have been read from the filesystem in alphabetical order)
$this->assertStringContainsString('FOO_BAR_FORUMLIST_BODY_BEFORE', $crawler->filter('p[id*="forumlist_body_before"]')->eq(0)->text());
$this->assertStringContainsString('FOO_FOO_FORUMLIST_BODY_BEFORE', $crawler->filter('p[id*="forumlist_body_before"]')->eq(1)->text());
}
}

View file

@ -14,13 +14,7 @@ services:
class: foo\bar\event\permission class: foo\bar\event\permission
tags: tags:
- { name: event.listener } - { name: event.listener }
foo_bar.listener.user_setup: foo_bar.listener.user_setup:
class: foo\bar\event\user_setup class: foo\bar\event\user_setup
tags: tags:
- { name: event.listener } - { name: event.listener }
foo_bar.listener.template_event_order:
class: foo\bar\event\template_event_order
tags:
- { name: event.listener }

View file

@ -1,38 +0,0 @@
<?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 foo\bar\event;
/**
* Event listener
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class template_event_order implements EventSubscriberInterface
{
static public function getSubscribedEvents()
{
return array(
'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
);
}
public function set_template_event_priority($event)
{
$template_event_priority_array = $event['template_event_priority_array'];
$template_event_priority_array['foo_bar'] = [
'event/navbar_header_quick_links_after' => -1,
];
$event['template_event_priority_array'] = $template_event_priority_array;
}
}

View file

@ -1,38 +0,0 @@
<?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 foo\bar\event;
/**
* Event listener
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class template_event_order implements EventSubscriberInterface
{
static public function getSubscribedEvents()
{
return array(
'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
);
}
public function set_template_event_priority($event)
{
$template_event_priority_array = $event['template_event_priority_array'];
$template_event_priority_array['foo_bar'] = [
'event/navbar_header_quick_links_after' => 1,
];
$event['template_event_priority_array'] = $template_event_priority_array;
}
}

View file

@ -1 +0,0 @@
<p id="foo_bar_forumlist_body_before">{{ lang('FOO_BAR_FORUMLIST_BODY_BEFORE') }}</p>

View file

@ -1 +0,0 @@
<li><span>{{ lang('FOO_BAR_QUICK_LINK') }}</span></li>

View file

@ -1,8 +1,3 @@
services: services:
foo_foo.controller: foo_foo.controller:
class: foo\foo\controller\controller class: foo\foo\controller\controller
foo_foo.listener.template_event_order:
class: foo\foo\event\template_event_order
tags:
- { name: event.listener }

View file

@ -1,38 +0,0 @@
<?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 foo\foo\event;
/**
* Event listener
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class template_event_order implements EventSubscriberInterface
{
static public function getSubscribedEvents()
{
return array(
'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
);
}
public function set_template_event_priority($event)
{
$template_event_priority_array = $event['template_event_priority_array'];
$template_event_priority_array['foo_foo'] = [
'event/navbar_header_quick_links_after' => 1,
];
$event['template_event_priority_array'] = $template_event_priority_array;
}
}

View file

@ -1,38 +0,0 @@
<?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 foo\foo\event;
/**
* Event listener
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class template_event_order implements EventSubscriberInterface
{
static public function getSubscribedEvents()
{
return array(
'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
);
}
public function set_template_event_priority($event)
{
$template_event_priority_array = $event['template_event_priority_array'];
$template_event_priority_array['foo_foo'] = [
'event/navbar_header_quick_links_after' => -1,
];
$event['template_event_priority_array'] = $template_event_priority_array;
}
}

View file

@ -1 +0,0 @@
<p id="foo_foo_forumlist_body_before">{{ lang('FOO_FOO_FORUMLIST_BODY_BEFORE') }}</p>

View file

@ -1 +0,0 @@
<li><span>{{ lang('FOO_FOO_QUICK_LINK') }}</span></li>

View file

@ -16,6 +16,8 @@
*/ */
class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case
{ {
protected $phpbb_extension_manager;
private static $helper; private static $helper;
protected static $fixtures = array( protected static $fixtures = array(

View file

@ -644,7 +644,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]');
// Wait for extension to be fully disabled // Wait for extension to be fully enabled
while (count($meta_refresh)) while (count($meta_refresh))
{ {
preg_match('#url=.+/(adm+.+)#', $meta_refresh->attr('content'), $match); preg_match('#url=.+/(adm+.+)#', $meta_refresh->attr('content'), $match);