Compare commits

...

48 commits

Author SHA1 Message Date
lionel-rowe
82ede62260
Merge 18a63b6d7d into b8c49f9711 2025-06-16 11:34:30 +02:00
Marc Alexander
b8c49f9711
Merge branch '3.3.x' 2025-06-16 10:37:08 +02:00
Marc Alexander
2f43c1facd
[ticket/17399] Fix docblock and use space-ship operator
PHPBB-17399
2025-06-16 10:34:38 +02:00
Marc Alexander
9c49a2b86b
[ticket/17399] Fix declaration to be in line with PHP documentation
PHPBB-17399
2025-06-15 19:59:13 +02:00
Marc Alexander
d017eff8f1
Merge branch '3.3.x' 2025-06-15 09:10:57 +02:00
Marc Alexander
d4a3311b76
Merge pull request #6829 from battye/ticket/17399
[ticket/17399] Fix selected language bug in installer
2025-06-15 09:08:49 +02:00
Marc Alexander
bc470285fc
Merge pull request #6770 from rxu/ticket/15214
[ticket/15214] Add event & functionality for assigning template event priority
2025-06-15 08:59:31 +02:00
rxu
1d7543c778
[ticket/15214] Address code review issues, add equal priority events test
PHPBB3-15214
2025-06-15 01:35:31 +07:00
battye
8411da1819 [ticket/17399] Fix selected language in installer
This fixes a bug where a user could have other languages in the installer
but the language dropdown did not match the language shown.

PHPBB-17399
2025-06-14 14:35:18 +00:00
Marc Alexander
e34e1759c7 Merge branch '3.3.x' 2025-06-14 07:00:39 +00:00
Marc Alexander
8f8a93fa71
Merge pull request #6818 from rxu/ticket/17515
[ticket/17515] Add template event before PM text - 3.3.x
2025-06-14 08:51:41 +02:00
Marc Alexander
f1d8255aca
Merge pull request #6819 from rxu/ticket/17515-master
[ticket/17515] Add template event before PM text - master
2025-06-14 08:51:36 +02:00
Marc Alexander
851de03961
Merge pull request #6821 from rxu/ticket/17509
[ticket/17509] Bump DBMS supported versions
2025-06-14 08:50:03 +02:00
Marc Alexander
0a86130f7f
Merge pull request #6817 from iMattPro/ticket/17513
[ticket/17513] Wrap async logic inside event.waitUntil in push worker
2025-06-14 08:46:57 +02:00
Marc Alexander
083ae1102b Merge branch '3.3.x' 2025-06-13 18:52:53 +00:00
Marc Alexander
c726382d84
Merge pull request #6824 from iMattPro/ticket/17519
[ticket/17519] Correctly encode cron task urls
2025-06-13 20:41:22 +02:00
Marc Alexander
db19a4a578
Merge pull request #6828 from marc1706/ticket/17519-master
[ticket/17519] Correctly encode cron task urls -- master version
2025-06-13 20:41:18 +02:00
Marc Alexander
0b3897b8c3
[ticket/17519] Adapt wrapper test for master
PHPBB-17519
2025-06-12 21:38:55 +02:00
Marc Alexander
b2d48b679f
Merge branch 'ticket/17519' into ticket/17519-master 2025-06-12 21:15:38 +02:00
Marc Alexander
5deeea025f
[ticket/17519] Add unit tests for task wrapper
PHPBB-17519
2025-06-12 21:00:24 +02:00
Matt Friedman
6947dc8c92 [ticket/17519] Correctly encode cron task urls
PHPBB-17519
2025-06-03 04:21:24 +00:00
rxu
f23af6f485
[ticket/17509] Add MariaDB version requirement check
PHPBB-17509
2025-05-30 11:54:32 +07:00
rxu
b8e5caedbf
[ticket/17509] Fix tests
PHPBB-17509
2025-05-30 11:20:25 +07:00
rxu
50e7103080
[ticket/17509] Output db tools error test
PHPBB-17509
2025-05-29 23:15:47 +07:00
rxu
d8bbe3e58c
[ticket/17509] Upgrade Doctrine dbal to the v.3.9
PHPBB-17509
2025-05-29 22:13:32 +07:00
rxu
bf2c22354a
[ticket/17509] Add installer DBMS version checks
PHPBB-17509
2025-05-29 20:27:47 +07:00
rxu
215d1bf1eb
[ticket/17509] Bump DBMS supported versions
PHPBB-17509
2025-05-29 17:45:32 +07:00
rxu
759f061656
Merge branch 'ticket/17515' into ticket/17515-master 2025-05-22 14:02:28 +07:00
rxu
ddc7f1df34
[ticket/17515] Add template event before PM text
PHPBB-17515
2025-05-22 13:29:47 +07:00
rxu
ccbdfb49c7
[ticket/15214] Adjust core event name and docblock
PHPBB3-15214
2025-05-21 11:25:35 +07:00
rxu
43cf7b73bd
[ticket/15214] Adjust event node logic
PHPBB3-15214
2025-05-21 10:47:27 +07:00
Matt Friedman
6b6b5ffc28
[ticket/17513] Fix JS linting
PHPBB-17513
2025-05-20 12:11:39 -07:00
Matt Friedman
4f66ec8758
[ticket/17513] Wrap async logic inside event.waitUntil in push worker
PHPBB-17513
2025-05-20 10:23:00 -07:00
rxu
3a5247d01b
[ticket/15214] Get event dispatcher from environment rather than as dependency
Also this will allow to significantly reduce unrelated tests changes.

PHPBB3-15214
2025-05-20 17:36:15 +07:00
rxu
5e0dc9ef2e
[ticket/15214] Fix rebasing and some other issues
PHPBB3-15214
2025-05-20 16:24:38 +07:00
rxu
8338ff9e56
[ticket/15214] Fix Windows tests
PHPBB3-15214
2025-05-20 16:24:37 +07:00
toxyy
84e7e34a66
[ticket/15214] Fix tests again
Adding per rxu's recommendation

PHPBB3-15214
2025-05-20 16:24:37 +07:00
rxu
18bae795f0
[ticket/15214] Fix Windows tests
Purge Twig compiled cache in Windows.
Set appropriate folder access control options to do that.

PHPBB3-15214
2025-05-20 16:24:36 +07:00
rxu
09fd86ffb0
[ticket/15214] Fix test foo/foo extension listener
PHPBB3-15214
2025-05-20 16:24:34 +07:00
rxu
4a00212f2d
[ticket/15214] Optimize event node code and add template event order tests
PHPBB3-15214
2025-05-20 16:24:34 +07:00
toxyy
cb47d78d26
[ticket/15214] Update block, restart tests
Make docblock look a bit cleaner and restart the tests

PHPBB3-15214
2025-05-20 16:24:33 +07:00
toxyy
0eb98d51e2
[ticket/15214] Provide usage example within event docblock
Adds similar usage examples like the event core.permissions has

PHPBB3-15214
2025-05-20 16:24:32 +07:00
toxyy
82a5e20f3e
[ticket/15214] Replace arrow functions with anonymous functions
Arrow functions aren't added until PHP 7.4, so we can't use them yet.
Anonymous functions have been added since PHP 5.3

PHPBB3-15214
2025-05-20 16:24:32 +07:00
toxyy
71fe9d60c4
[ticket/15214] Add fixes for various other tests
Add new dispatch parameter to the template\twig\extension calls

PHPBB3-15214
2025-05-20 16:24:31 +07:00
toxyy
59b482a222
[ticket/15214] Test fix for test_bbcode_firstpass
Add new dispatch parameter to the template\twig\extension call

PHPBB3-15214
2025-05-20 16:24:30 +07:00
toxyy
d934c8c4b7
[ticket/15214] Test fix for test_helper_url_no_rewrite
Add new dispatch parameter to the template\twig\extension call

PHPBB3-15214
2025-05-20 16:24:29 +07:00
toxyy
d07aeb00d8
[ticket/15214] Add event & functionality for assigning template event priority
Event added to allow template events to be assigned priority per extension,
event location chosen so that it only fires once.
Twig node event class refactored to allow template event priority assignment,
compile calls are deferred until all locations are processed
per extension namespace.
Priority precedence mirrors Symfony priority, with higher numbers
being placed at the beginning of the array.
Duplicate priority assignment will currently have the later events
compiled before the others.

PHPBB3-15214
2025-05-20 16:24:24 +07:00
lionel-rowe
18a63b6d7d [ticket/16985] Fix MYSQLi bug - Incorrect string value for non-BMP chars
PHPBB3-16985
2022-04-13 19:25:55 +01:00
40 changed files with 625 additions and 112 deletions

View file

@ -20,7 +20,7 @@
<form method="post" action="#" id="language_selector">
<fieldset class="nobg">
<label for="language">{L_SELECT_LANG}{L_COLON}</label>
<select id="language" name="language">
<select id="language" name="language">
<!-- BEGIN language_select_item -->
<option value="{language_select_item.VALUE}"<!-- IF language_select_item.SELECTED --> selected="selected"<!-- ENDIF -->>{language_select_item.NAME}</option>
<!-- END language_select_item -->

View file

@ -36,7 +36,7 @@
"composer/composer": "^2.0",
"composer/installers": "^1.9",
"composer/package-versions-deprecated": "^1.11",
"doctrine/dbal": "~3.3.6",
"doctrine/dbal": "^3.9",
"google/recaptcha": "~1.1",
"guzzlehttp/guzzle": " ^7.0",
"marc1706/fast-image-size": "^1.1",

38
phpBB/composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5ed4369e5ba29297443f428dd3001fae",
"content-hash": "39f3a7c03ba85a8c7892e5c076372eb0",
"packages": [
{
"name": "bantu/ini-get-wrapper",
@ -1128,38 +1128,38 @@
},
{
"name": "doctrine/dbal",
"version": "3.3.8",
"version": "3.9.4",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "f873a820227bc352d023791775a01f078a30dfe1"
"reference": "ec16c82f20be1a7224e65ac67144a29199f87959"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/f873a820227bc352d023791775a01f078a30dfe1",
"reference": "f873a820227bc352d023791775a01f078a30dfe1",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/ec16c82f20be1a7224e65ac67144a29199f87959",
"reference": "ec16c82f20be1a7224e65ac67144a29199f87959",
"shasum": ""
},
"require": {
"composer-runtime-api": "^2",
"doctrine/cache": "^1.11|^2.0",
"doctrine/deprecations": "^0.5.3|^1",
"doctrine/event-manager": "^1.0",
"php": "^7.3 || ^8.0",
"doctrine/event-manager": "^1|^2",
"php": "^7.4 || ^8.0",
"psr/cache": "^1|^2|^3",
"psr/log": "^1|^2|^3"
},
"require-dev": {
"doctrine/coding-standard": "9.0.0",
"jetbrains/phpstorm-stubs": "2022.1",
"phpstan/phpstan": "1.8.2",
"phpstan/phpstan-strict-rules": "^1.3",
"phpunit/phpunit": "9.5.21",
"psalm/plugin-phpunit": "0.17.0",
"squizlabs/php_codesniffer": "3.7.1",
"symfony/cache": "^5.2|^6.0",
"symfony/console": "^2.7|^3.0|^4.0|^5.0|^6.0",
"vimeo/psalm": "4.24.0"
"doctrine/coding-standard": "12.0.0",
"fig/log-test": "^1",
"jetbrains/phpstorm-stubs": "2023.1",
"phpstan/phpstan": "2.1.1",
"phpstan/phpstan-strict-rules": "^2",
"phpunit/phpunit": "9.6.22",
"slevomat/coding-standard": "8.13.1",
"squizlabs/php_codesniffer": "3.10.2",
"symfony/cache": "^5.4|^6.0|^7.0",
"symfony/console": "^4.4|^5.4|^6.0|^7.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
@ -1219,7 +1219,7 @@
],
"support": {
"issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.3.8"
"source": "https://github.com/doctrine/dbal/tree/3.9.4"
},
"funding": [
{
@ -1235,7 +1235,7 @@
"type": "tidelift"
}
],
"time": "2022-08-05T15:35:35+00:00"
"time": "2025-01-16T08:28:55+00:00"
},
{
"name": "doctrine/deprecations",

View file

@ -2821,6 +2821,13 @@ ucp_pm_viewmessage_custom_fields_before
* Purpose: Add data before the custom fields on the user profile when viewing
a private message
ucp_pm_viewmessage_message_content_before
===
* Locations:
+ styles/prosilver/template/ucp_pm_viewmessage.html
* Since: 3.3.16-RC1
* Purpose: Add content before the private message text
ucp_pm_viewmessage_options_before
===
* Locations:

View file

@ -70,11 +70,11 @@ $lang = array_merge($lang, array(
<p>phpBB supports the following databases:</p>
<ul>
<li>MySQL 4.1.3 or above (MySQLi required)</li>
<li>PostgreSQL 8.3+</li>
<li>SQLite 3.6.15+</li>
<li>MS SQL Server 2000 or above (directly or via ODBC)</li>
<li>MS SQL Server 2005 or above (native)</li>
<li>MySQL 5.6 or above</li>
<li>MariaDB 10.2.7 or above</li>
<li>PostgreSQL 9.4 or above</li>
<li>SQLite 3.8.3 or above</li>
<li>MS SQL Server 2012 or above (via ODBC or the native adapter)</li>
<li>Oracle</li>
</ul>
@ -184,9 +184,9 @@ $lang = array_merge($lang, array(
'TABLE_PREFIX_EXPLAIN' => 'The prefix must start with a letter and must only contain letters, numbers and underscores.',
// Database options
'DB_OPTION_MSSQL_ODBC' => 'MSSQL Server 2000+ via ODBC',
'DB_OPTION_MSSQLNATIVE' => 'MSSQL Server 2005+ [ Native ]',
'DB_OPTION_MYSQLI' => 'MySQL with MySQLi Extension',
'DB_OPTION_MSSQL_ODBC' => 'MSSQL Server via ODBC',
'DB_OPTION_MSSQLNATIVE' => 'MSSQL Server [ Native ]',
'DB_OPTION_MYSQLI' => 'MySQL',
'DB_OPTION_ORACLE' => 'Oracle',
'DB_OPTION_POSTGRES' => 'PostgreSQL',
'DB_OPTION_SQLITE3' => 'SQLite 3',
@ -202,10 +202,13 @@ $lang = array_merge($lang, array(
'INST_ERR_DB_NO_WRITABLE' => 'Both the database and the directory containing it must be writable.',
'INST_ERR_DB_NO_ERROR' => 'No error message given.',
'INST_ERR_PREFIX' => 'Tables with the specified prefix already exist, please choose an alternative.',
'INST_ERR_DB_NO_MYSQLI' => 'The version of MySQL installed on this machine is incompatible with the “MySQL with MySQLi Extension” option you have selected. Please try the “MySQL” option instead.',
'INST_ERR_DB_NO_SQLITE3' => 'The version of the SQLite extension you have installed is too old, it must be upgraded to at least 3.6.15.',
'INST_ERR_DB_NO_ORACLE' => 'The version of Oracle installed on this machine requires you to set the <var>NLS_CHARACTERSET</var> parameter to <var>UTF8</var>. Either upgrade your installation to 9.2+ or change the parameter.',
'INST_ERR_DB_NO_POSTGRES' => 'The database you have selected was not created in <var>UNICODE</var> or <var>UTF8</var> encoding. Try installing with a database in <var>UNICODE</var> or <var>UTF8</var> encoding.',
'INST_ERR_DB_NO_MARIADB' => 'The version of MariaDB installed on this machine is too old, it must be upgraded to at least 10.2.7.',
'INST_ERR_DB_NO_MYSQLI' => 'The version of MySQL installed on this machine is too old, it must be upgraded to at least 5.6.',
'INST_ERR_DB_NO_MSSQL' => 'The version of Microsoft SQL Server installed on this machine is too old, it must be upgraded to at least SQL Server 2012 (11.0.2100.60)',
'INST_ERR_DB_NO_SQLITE3' => 'The version of the SQLite extension you have installed is too old, it must be upgraded to at least 3.8.3.',
'INST_ERR_DB_NO_ORACLE' => 'The version of Oracle installed is too old, it must be upgraded to at least 12.1.0.2.',
'INST_ERR_DB_NO_POSTGRES' => 'The version of the PostgreSQL you have installed is too old, it must be upgraded to at least 9.4.',
'INST_ERR_DB_NO_POSTGRES_UTF8' => 'The database you have selected was not created in <var>UNICODE</var> or <var>UTF8</var> encoding. Try installing with a database in <var>UNICODE</var> or <var>UTF8</var> encoding.',
'INST_SCHEMA_FILE_NOT_WRITABLE' => 'The schema file is not writable',
//

View file

@ -79,7 +79,7 @@ class connection_parameter_factory
string|null $name = null,
string|null $port = null) : array
{
if ($params['driver'] === 'pdo_sqlite')
if (in_array($params['driver'], ['pdo_sqlite', 'sqlite3']))
{
return self::enrich_parameters(
self::build_sqlite_parameters($params, $host, $user, $password)

View file

@ -336,7 +336,10 @@ class mysqli extends \phpbb\db\driver\mysql_base
*/
function sql_escape($msg)
{
return @mysqli_real_escape_string($this->db_connect_id, $msg);
return @mysqli_real_escape_string(
$this->db_connect_id,
utf8_encode_ucr($msg)
);
}
/**

View file

@ -15,7 +15,7 @@ namespace phpbb\db\driver;
/**
* SQLite3 Database Abstraction Layer
* Minimum Requirement: 3.6.15+
* Minimum Requirement: 3.8.3+
*/
class sqlite3 extends \phpbb\db\driver\driver
{

View file

@ -289,6 +289,12 @@ class doctrine implements tools_interface
if (count($primary_key_indexes))
{
// For PostgreSQL, drop primary index first to avoid "Dependent objects still exist" error
if (stripos($this->get_schema_manager()->getDatabasePlatform()->getname(), 'postgresql') !== false)
{
$this->get_schema_manager()->dropIndex('"primary"', $table_name);
}
$ret = $this->alter_schema(
function (Schema $schema) use ($table_name, $column_name): void
{
@ -478,7 +484,7 @@ class doctrine implements tools_interface
catch (Exception $e)
{
// @todo: check if it makes sense to properly handle the exception
return false;
return [$e->getMessage()];
}
}

View file

@ -339,6 +339,14 @@ class helper
protected function render_language_select($selected_language = null)
{
$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)
{
$this->template->assign_block_vars('language_select_item', array(

View file

@ -39,7 +39,7 @@ class database
// Note: php 5.5 alpha 2 deprecated mysql.
// Keep mysqli before mysql in this list.
'mysqli' => array(
'LABEL' => 'MySQL with MySQLi Extension',
'LABEL' => 'MySQL',
'SCHEMA' => 'mysql_41',
'MODULE' => 'mysqli',
'DOCTRINE' => ['pdo_mysql'],
@ -59,7 +59,7 @@ class database
'2.0.x' => true,
),
'mssqlnative' => array(
'LABEL' => 'MS SQL Server 2005+ [ Native ]',
'LABEL' => 'MS SQL Server [ Native ]',
'SCHEMA' => 'mssql',
'MODULE' => 'sqlsrv',
'DOCTRINE' => ['pdo_sqlsrv'],
@ -78,7 +78,7 @@ class database
'2.0.x' => false,
),
'postgres' => array(
'LABEL' => 'PostgreSQL 8.3+',
'LABEL' => 'PostgreSQL',
'SCHEMA' => 'postgres',
'MODULE' => 'pgsql',
'DOCTRINE' => ['pdo_pgsql'],
@ -405,10 +405,29 @@ class database
}
// Check if database version is supported
/** @psalm-suppress UndefinedInterfaceMethod */
$db_server_version = $doctrine_db->getWrappedConnection()->getServerVersion();
switch ($dbms)
{
case 'mysqli':
if (stripos($db->sql_server_info(), 'mariadb') !== false && version_compare($db_server_version, '10.2.7', '<'))
{
$errors[] = array(
'title' => 'INST_ERR_DB_NO_MARIADB',
);
}
else
{
if (version_compare($db_server_version, '5.6', '<'))
{
$errors[] = array(
'title' => 'INST_ERR_DB_NO_MYSQLI',
);
}
}
break;
case 'sqlite3':
if (version_compare($db->sql_server_info(true), '3.6.15', '<'))
if (version_compare($db_server_version, '3.8.3', '<'))
{
$errors[] = array(
'title' => 'INST_ERR_DB_NO_SQLITE3',
@ -416,20 +435,7 @@ class database
}
break;
case 'oracle':
$sql = "SELECT *
FROM NLS_DATABASE_PARAMETERS
WHERE PARAMETER = 'NLS_RDBMS_VERSION'
OR PARAMETER = 'NLS_CHARACTERSET'";
$result = $db->sql_query($sql);
$stats = [];
while ($row = $db->sql_fetchrow($result))
{
$stats[$row['parameter']] = $row['value'];
}
$db->sql_freeresult($result);
if (version_compare($stats['NLS_RDBMS_VERSION'], '9.2', '<') && $stats['NLS_CHARACTERSET'] !== 'UTF8')
if (version_compare($db_server_version, '12.1.0.2', '<'))
{
$errors[] = array(
'title' => 'INST_ERR_DB_NO_ORACLE',
@ -437,17 +443,35 @@ class database
}
break;
case 'postgres':
$sql = "SHOW server_encoding;";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8')
if (version_compare($db_server_version, '9.4', '<'))
{
$errors[] = array(
'title' => 'INST_ERR_DB_NO_POSTGRES',
);
}
else
{
$sql = "SHOW server_encoding;";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8')
{
$errors[] = array(
'title' => 'INST_ERR_DB_NO_POSTGRES_UTF8',
);
}
}
break;
case 'mssqlnative':
case 'mssql_odbc':
if (version_compare($db_server_version, '11.0.2100.60', '<'))
{
$errors[] = array(
'title' => 'INST_ERR_DB_NO_MSSQL',
);
}
break;
}
}

View file

@ -65,6 +65,8 @@ class language_file_helper
$available_languages[] = $this->get_language_data_from_json($data);
}
usort($available_languages, [$this, 'sort_by_local_name']);
return $available_languages;
}
@ -123,4 +125,16 @@ class language_file_helper
'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
{
return $a['local_name'] <=> $b['local_name'];
}
}

View file

@ -161,6 +161,16 @@ class environment extends \Twig\Environment
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
*

View file

@ -24,9 +24,13 @@ class event extends \Twig\Node\Node
/** @var \phpbb\template\twig\environment */
protected $environment;
public function __construct(\Twig\Node\Expression\AbstractExpression $expr, \phpbb\template\twig\environment $environment, $lineno, $tag = null)
/** @var array */
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->template_event_priority_array = $template_event_priority_array;
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
}
@ -42,10 +46,20 @@ class event extends \Twig\Node\Node
$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)
{
$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 debug mode is enabled, lets check for new/removed EVENT
@ -54,8 +68,7 @@ class event extends \Twig\Node\Node
// purge the cache when a new event template file is added)
$compiler
->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'))
@ -66,16 +79,14 @@ class event extends \Twig\Node\Node
// 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->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())
{
$compiler
->outdent()
->write("}\n\n")
;
->write("}\n\n");
}
}
}

View file

@ -18,6 +18,9 @@ class event extends \Twig\TokenParser\AbstractTokenParser
/** @var \phpbb\template\twig\environment */
protected $environment;
/** @var array */
protected $template_event_priority_array;
/**
* Constructor
*
@ -26,6 +29,25 @@ class event extends \Twig\TokenParser\AbstractTokenParser
public function __construct(\phpbb\template\twig\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);
}
/**
@ -42,7 +64,7 @@ class event extends \Twig\TokenParser\AbstractTokenParser
$stream = $this->parser->getStream();
$stream->expect(\Twig\Token::BLOCK_END_TYPE);
return new \phpbb\template\twig\node\event($expr, $this->environment, $token->getLine(), $this->getTag());
return new \phpbb\template\twig\node\event($expr, $this->environment, $token->getLine(), $this->getTag(), $this->template_event_priority_array);
}
/**

View file

@ -34,41 +34,48 @@ self.addEventListener('push', event => {
notificationVersion = parseInt(notificationData.version, 10);
pushToken = notificationData.token;
} catch {
self.registration.showNotification(event.data.text());
event.waitUntil(self.registration.showNotification(event.data.text()));
return;
}
const getNotificationUrl = '{{ U_WEBPUSH_GET_NOTIFICATION }}';
const assetsVersion = parseInt('{{ ASSETS_VERSION }}', 10);
event.waitUntil((async() => {
const getNotificationUrl = '{{ U_WEBPUSH_GET_NOTIFICATION }}';
const assetsVersion = parseInt('{{ ASSETS_VERSION }}', 10);
// Force update if versions differ
if (assetsVersion !== notificationVersion) {
self.registration.update();
}
// Force update if versions differ
if (assetsVersion !== notificationVersion) {
await self.registration.update();
}
const formData = new FormData();
formData.append('item_id', itemId.toString(10));
formData.append('type_id', typeId.toString(10));
formData.append('user_id', userId.toString(10));
formData.append('token', pushToken);
const formData = new FormData();
formData.append('item_id', itemId.toString(10));
formData.append('type_id', typeId.toString(10));
formData.append('user_id', userId.toString(10));
formData.append('token', pushToken);
fetch(getNotificationUrl, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
body: formData,
})
.then(response => response.json())
.then(response => {
const responseBody = response.title + '\n' + response.text;
try {
const response = await fetch(getNotificationUrl, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
body: formData,
});
const responseData = await response.json();
const responseBody = responseData.title + '\n' + responseData.text;
const options = {
body: responseBody,
data: response,
icon: response.avatar.src,
data: responseData,
icon: responseData.avatar.src,
};
self.registration.showNotification(response.heading, options);
});
await self.registration.showNotification(responseData.heading, options);
} catch (e) {
console.error('Push error:', e);
}
})());
});
/**

View file

@ -4,4 +4,4 @@
to hide visually and `aria-hidden="true"` to hide from screen-readers; using
`hidden` or `display: none` would prevent the task from running.
#}
<img class="sr-only" aria-hidden="true" src="{{ CRON_TASK_URL|e('html_attr') }}" width="1" height="1" alt="">
<img class="sr-only" aria-hidden="true" src="{{ CRON_TASK_URL|e('url') }}" width="1" height="1" alt="">

View file

@ -149,6 +149,7 @@
<!-- IF S_BCC_RECIPIENT --><br /><strong>{L_BCC}{L_COLON}</strong> <!-- BEGIN bcc_recipient --><!-- IF bcc_recipient.NAME_FULL -->{bcc_recipient.NAME_FULL}<!-- ELSE --><a href="{bcc_recipient.U_VIEW}"<!-- IF bcc_recipient.COLOUR --> style="color:{bcc_recipient.COLOUR};"<!-- ENDIF -->><strong>{bcc_recipient.NAME}</strong></a><!-- ENDIF -->&nbsp;<!-- END bcc_recipient --><!-- ENDIF -->
</p>
{% EVENT ucp_pm_viewmessage_message_content_before %}
<div class="content">{MESSAGE}</div>

131
tests/cron/wrapper_test.php Normal file
View file

@ -0,0 +1,131 @@
<?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.
*
*/
require_once __DIR__ . '/../template/template_test_case.php';
class phpbb_cron_wrapper_test extends phpbb_template_template_test_case
{
private $task;
private $routing_helper;
private $wrapper;
protected function setUp(): void
{
global $phpbb_root_path;
$this->setup_engine([], $phpbb_root_path . 'styles/all/template');
global $phpbb_filesystem;
$phpbb_filesystem = new \phpbb\filesystem\filesystem();
$this->task = $this->createMock(\phpbb\cron\task\task::class);
$this->routing_helper = $this->createMock(\phpbb\routing\helper::class);
$this->wrapper = new \phpbb\cron\task\wrapper(
$this->task,
$this->routing_helper,
$this->template
);
}
public function test_generate_template_pagination()
{
$this->task = $this->createMock(\phpbb\cron\task\parametrized::class);
$this->task->expects($this->any())
->method('get_parameters')
->willReturn(['f' => '5']);
$this->task->expects($this->any())
->method('get_name')
->willReturn('test_task');
$this->routing_helper = $this->createMock(\phpbb\routing\helper::class);
$this->routing_helper->expects($this->any())
->method('route')
->with('phpbb_cron_run', ['cron_type' => 'test_task', 'f' => '5'])
->willReturn('app.php/cron/foo?f=5');
$this->wrapper = new \phpbb\cron\task\wrapper(
$this->task,
$this->routing_helper,
$this->template
);
$this->assertEquals('<img class="sr-only" aria-hidden="true" src="app.php%2Fcron%2Ffoo%3Ff%3D5" width="1" height="1" alt="">', str_replace(["\n", "\t"], '', $this->wrapper->get_html_tag()));
}
public function test_is_parametrized_false()
{
$this->assertFalse($this->wrapper->is_parametrized());
}
public function test_is_ready()
{
$this->task->method('is_runnable')->willReturn(true);
$this->task->method('should_run')->willReturn(true);
$this->assertTrue($this->wrapper->is_ready());
}
public function test_get_url_non_parametrized()
{
$this->task->method('get_name')->willReturn('test_task');
$this->routing_helper->expects($this->once())
->method('route')
->with('phpbb_cron_run', ['cron_type' => 'test_task'])
->willReturn('/cron/url');
$this->assertEquals('/cron/url', $this->wrapper->get_url());
}
public function test_get_html_tag()
{
$this->template = $this->createMock(\phpbb\template\template::class);
$this->wrapper = new \phpbb\cron\task\wrapper(
$this->task,
$this->routing_helper,
$this->template
);
$this->template->expects($this->once())
->method('set_filenames');
$this->template->expects($this->once())
->method('assign_var');
$this->template->expects($this->once())
->method('assign_display')
->willReturn('<img src="cron">');
$this->assertEquals('<img src="cron">', $this->wrapper->get_html_tag());
}
public function test_call_forwards_to_task()
{
$this->task = $this->getMockBuilder(\phpbb\cron\task\task::class)
->disableOriginalConstructor()
->setMethods(['get_name', 'run', 'is_runnable', 'should_run', 'some_method'])
->getMock();
$this->routing_helper = $this->createMock(\phpbb\routing\helper::class);
$this->wrapper = new \phpbb\cron\task\wrapper(
$this->task,
$this->routing_helper,
$this->template
);
$this->task->expects($this->once())
->method('some_method')
->with('arg1', 'arg2')
->willReturn('result');
$result = $this->wrapper->some_method('arg1', 'arg2');
$this->assertEquals('result', $result);
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,105 @@
<?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,7 +14,13 @@ services:
class: foo\bar\event\permission
tags:
- { name: event.listener }
foo_bar.listener.user_setup:
class: foo\bar\event\user_setup
tags:
- { name: event.listener }
foo_bar.listener.template_event_order:
class: foo\bar\event\template_event_order
tags:
- { name: event.listener }

View file

@ -0,0 +1,38 @@
<?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

@ -0,0 +1,38 @@
<?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

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

View file

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

View file

@ -1,3 +1,8 @@
services:
foo_foo.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

@ -0,0 +1,38 @@
<?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

@ -0,0 +1,38 @@
<?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

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

View file

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

View file

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

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/template_test_case.php';
class phpbb_template_extension_test extends phpbb_template_template_test_case
{
protected function setup_engine(array $new_config = [])
protected function setup_engine(array $new_config = [], string $template_path = '')
{
global $config, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;

View file

@ -21,7 +21,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
/** @var string */
protected $parent_template_path;
protected function setup_engine(array $new_config = array())
protected function setup_engine(array $new_config = array(), string $template_path = '')
{
global $phpbb_root_path, $phpEx, $user;

View file

@ -1,4 +1,7 @@
<?php
use phpbb\template\twig\twig;
/**
*
* This file is part of the phpBB Forum Software package.
@ -14,6 +17,7 @@
class phpbb_template_template_test_case extends phpbb_test_case
{
protected $lang;
/** @var twig */
protected $template;
protected $template_path;
protected $user;
@ -68,7 +72,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
return $defaults;
}
protected function setup_engine(array $new_config = array())
protected function setup_engine(array $new_config = array(), string $template_path = '')
{
global $phpbb_root_path, $phpEx;
@ -90,7 +94,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
$phpEx
);
$this->template_path = $this->test_path . '/templates';
$this->template_path = $template_path ?: $this->test_path . '/templates';
$cache_path = $phpbb_root_path . 'cache/twig';
$context = new \phpbb\template\context();

View file

@ -21,7 +21,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
/** @var string */
protected $parent_template_path;
protected function setup_engine(array $new_config = array())
protected function setup_engine(array $new_config = [], string $template_path = '')
{
global $phpbb_root_path, $phpEx, $user;

View file

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