From f5bb065a4d02ac6daca5b48064585aeed11646ff Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 25 Jun 2024 16:36:49 +0100 Subject: [PATCH 01/14] [ticket/17326] Add font icon field for custom BBCodes Adds a new field to the custom BBCode add/edit form that allows admins to define a Font Awesome icon to be displayed instead of the BBCodes name on the posting.php editor page. PHPBB-17326 --- phpBB/adm/style/acp_bbcodes.html | 11 ++++ phpBB/adm/style/admin.js | 5 ++ phpBB/includes/acp/acp_bbcodes.php | 16 +++++- phpBB/includes/functions_display.php | 3 +- phpBB/language/en/acp/posting.php | 3 ++ phpBB/language/en/common.php | 1 + .../data/v400/add_bbcode_font_icon.php | 51 +++++++++++++++++++ .../prosilver/template/posting_buttons.html | 6 ++- 8 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 phpBB/phpbb/db/migration/data/v400/add_bbcode_font_icon.php diff --git a/phpBB/adm/style/acp_bbcodes.html b/phpBB/adm/style/acp_bbcodes.html index 234ec5a42b..8bc0b5fdc2 100644 --- a/phpBB/adm/style/acp_bbcodes.html +++ b/phpBB/adm/style/acp_bbcodes.html @@ -47,6 +47,17 @@ +
+ {{ lang('APPEARANCE') }} +
+

{{ lang('BBCODE_FONT_ICON_EXPLAIN') }}
+
+ + {{ Icon('font', BBCODE_FONT_ICON, '', false, '', {'id':'bbcode_icon_preview'}) }} +
+
+
+
diff --git a/phpBB/adm/style/admin.js b/phpBB/adm/style/admin.js index a5c090d8c0..1ff1b02d74 100644 --- a/phpBB/adm/style/admin.js +++ b/phpBB/adm/style/admin.js @@ -277,5 +277,10 @@ function parse_document(container) $('.actions a:has(i.acp-icon)').mouseover(function () { $(this).css("text-decoration", "none"); }); + + // Live update BBCode font icon preview + $('#bbcode_font_icon').on('keyup', function(e) { + $('#bbcode_icon_preview').attr('class', "o-icon o-icon-font fa-fw fas icon fa-" + $(this).val()); + }); }); })(jQuery); diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index a905354040..66ef3627ab 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -44,12 +44,12 @@ class acp_bbcodes switch ($action) { case 'add': - $bbcode_match = $bbcode_tpl = $bbcode_helpline = ''; + $bbcode_match = $bbcode_tpl = $bbcode_helpline = $bbcode_font_icon = ''; $display_on_posting = 0; break; case 'edit': - $sql = 'SELECT bbcode_match, bbcode_tpl, display_on_posting, bbcode_helpline + $sql = 'SELECT bbcode_match, bbcode_tpl, display_on_posting, bbcode_helpline, bbcode_font_icon FROM ' . BBCODES_TABLE . ' WHERE bbcode_id = ' . $bbcode_id; $result = $db->sql_query($sql); @@ -65,6 +65,7 @@ class acp_bbcodes $bbcode_tpl = htmlspecialchars($row['bbcode_tpl'], ENT_COMPAT); $display_on_posting = $row['display_on_posting']; $bbcode_helpline = $row['bbcode_helpline']; + $bbcode_font_icon = $row['bbcode_font_icon']; break; case 'modify': @@ -88,6 +89,7 @@ class acp_bbcodes $bbcode_match = $request->variable('bbcode_match', ''); $bbcode_tpl = html_entity_decode($request->variable('bbcode_tpl', '', true), ENT_COMPAT); $bbcode_helpline = $request->variable('bbcode_helpline', '', true); + $bbcode_font_icon = $request->variable('bbcode_font_icon', ''); break; } @@ -106,6 +108,7 @@ class acp_bbcodes 'BBCODE_MATCH' => $bbcode_match, 'BBCODE_TPL' => $bbcode_tpl, 'BBCODE_HELPLINE' => $bbcode_helpline, + 'BBCODE_FONT_ICON' => $bbcode_font_icon, 'DISPLAY_ON_POSTING' => $display_on_posting, ); @@ -157,6 +160,7 @@ class acp_bbcodes * @var string bbcode_match The bbcode usage string to match * @var string bbcode_tpl The bbcode HTML replacement string * @var string bbcode_helpline The bbcode help line string + * @var string bbcode_font_icon The name of the Font Awesome BBCode icon * @var array hidden_fields Array of hidden fields for use when * submitting form when $warn_unsafe is true * @since 3.1.0-a3 @@ -169,6 +173,7 @@ class acp_bbcodes 'bbcode_match', 'bbcode_tpl', 'bbcode_helpline', + 'bbcode_font_icon', 'hidden_fields', ); extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_modify_create', compact($vars))); @@ -232,6 +237,11 @@ class acp_bbcodes trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); } + if (strlen($bbcode_font_icon) > 50) + { + trigger_error($user->lang['BBCODE_FONT_ICON_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); + } + /** * Replace Emojis and other 4bit UTF-8 chars not allowed by MySQL to UCR/NCR. * Using their Numeric Character Reference's Hexadecimal notation. @@ -244,6 +254,7 @@ class acp_bbcodes 'bbcode_tpl' => $bbcode_tpl, 'display_on_posting' => $display_on_posting, 'bbcode_helpline' => $bbcode_helpline, + 'bbcode_font_icon' => $bbcode_font_icon, 'first_pass_match' => $data['first_pass_match'], 'first_pass_replace' => $data['first_pass_replace'], 'second_pass_match' => $data['second_pass_match'], @@ -328,6 +339,7 @@ class acp_bbcodes 'bbcode_match' => $bbcode_match, 'bbcode_tpl' => htmlspecialchars($bbcode_tpl, ENT_COMPAT), 'bbcode_helpline' => $bbcode_helpline, + 'bbcode_font_icon' => $bbcode_font_icon, 'display_on_posting' => $display_on_posting, ))) , 'confirm_bbcode.html'); diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 7a4e70f944..e8f49f0329 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1081,7 +1081,7 @@ function display_custom_bbcodes() $num_predefined_bbcodes = NUM_PREDEFINED_BBCODES; $sql_ary = [ - 'SELECT' => 'b.bbcode_id, b.bbcode_tag, b.bbcode_helpline, b.bbcode_match', + 'SELECT' => 'b.bbcode_id, b.bbcode_tag, b.bbcode_helpline, b.bbcode_font_icon, b.bbcode_match', 'FROM' => [BBCODES_TABLE => 'b'], 'WHERE' => 'b.display_on_posting = 1', 'ORDER_BY' => 'b.bbcode_tag', @@ -1124,6 +1124,7 @@ function display_custom_bbcodes() 'BBCODE_TAG' => $row['bbcode_tag'], 'BBCODE_TAG_CLEAN' => str_replace('=', '-', $row['bbcode_tag']), 'BBCODE_HELPLINE' => $row['bbcode_helpline'], + 'BBCODE_FONT_ICON' => $row['bbcode_font_icon'], ]; /** diff --git a/phpBB/language/en/acp/posting.php b/phpBB/language/en/acp/posting.php index f252864eb6..c219b1a46a 100644 --- a/phpBB/language/en/acp/posting.php +++ b/phpBB/language/en/acp/posting.php @@ -53,6 +53,9 @@ $lang = array_merge($lang, array( 'BBCODE_HELPLINE_EXPLAIN' => 'This field contains the mouse over text of the BBCode.', 'BBCODE_HELPLINE_TEXT' => 'Help line text', 'BBCODE_HELPLINE_TOO_LONG' => 'The help line you entered is too long.', + 'BBCODE_FONT_ICON' => 'BBCode icon', + 'BBCODE_FONT_ICON_EXPLAIN' => 'Enter the name of a Font Awesome icon (without the fa prefix) to display instead of the BBCode name appearing on the button. Click here to view the list of available icons.', + 'BBCODE_FONT_ICON_TOO_LONG' => 'The icon name you have entered is too long.', 'BBCODE_INVALID_TAG_NAME' => 'The BBCode tag name that you selected already exists.', 'BBCODE_INVALID' => 'Your BBCode is constructed in an invalid form.', diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index d528ef9b2b..20e7acff91 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -78,6 +78,7 @@ $lang = array_merge($lang, array( 'ALL_TOPICS' => 'All Topics', 'ALT_TEXT' => 'Alternative text', 'AND' => 'And', + 'APPEARANCE' => 'Appearance', 'ARE_WATCHING_FORUM' => 'You have subscribed to be notified of new posts in this forum.', 'ARE_WATCHING_TOPIC' => 'You have subscribed to be notified of new posts in this topic.', 'ASCENDING' => 'Ascending', diff --git a/phpBB/phpbb/db/migration/data/v400/add_bbcode_font_icon.php b/phpBB/phpbb/db/migration/data/v400/add_bbcode_font_icon.php new file mode 100644 index 0000000000..1a580dde8c --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v400/add_bbcode_font_icon.php @@ -0,0 +1,51 @@ + +* @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\db\migration\data\v400; + +class add_bbcode_font_icon extends \phpbb\db\migration\migration +{ + public function effectively_installed() + { + return $this->db_tools->sql_column_exists($this->table_prefix . 'bbcodes', 'bbcode_font_icon'); + } + + public static function depends_on() + { + return [ + '\phpbb\db\migration\data\v400\dev' + ]; + } + + public function update_schema() + { + return [ + 'add_columns' => [ + $this->table_prefix . 'bbcodes' => [ + 'bbcode_font_icon' => ['VCHAR:50', ''], + ], + ], + ]; + } + + public function revert_schema() + { + return [ + 'drop_columns' => [ + $this->table_prefix . 'bbcodes' => [ + 'bbcode_font_icon', + ], + ], + ]; + } +} diff --git a/phpBB/styles/prosilver/template/posting_buttons.html b/phpBB/styles/prosilver/template/posting_buttons.html index ee98cb57ce..03824ee7c7 100644 --- a/phpBB/styles/prosilver/template/posting_buttons.html +++ b/phpBB/styles/prosilver/template/posting_buttons.html @@ -97,7 +97,11 @@ From 1729e3f52b3dcbd7c35cdff6241f38192e997515 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Wed, 26 Jun 2024 13:19:00 +0100 Subject: [PATCH 02/14] [ticket/17326] Add missing ending tag from template file PHPBB-17326 --- phpBB/styles/prosilver/template/posting_buttons.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/styles/prosilver/template/posting_buttons.html b/phpBB/styles/prosilver/template/posting_buttons.html index 03824ee7c7..85e05a0d49 100644 --- a/phpBB/styles/prosilver/template/posting_buttons.html +++ b/phpBB/styles/prosilver/template/posting_buttons.html @@ -101,7 +101,7 @@ {{ Icon('font', custom_tags.BBCODE_FONT_ICON, '', false, custom_tags.BBCODE_TAG_CLEAN) }} {% else %} {{ custom_tags.BBCODE_TAG }} - {% + {% endif %} From c2725b441cf40c7f025bbe745e0180223552e1b6 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 12 Aug 2024 20:57:23 +0100 Subject: [PATCH 03/14] [ticket/17326] Change column length of icon and update ACP language PHPBB-17326 --- phpBB/adm/style/acp_bbcodes.html | 2 +- phpBB/includes/acp/acp_bbcodes.php | 13 +++++++------ phpBB/language/en/acp/posting.php | 2 +- .../db/migration/data/v400/add_bbcode_font_icon.php | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/phpBB/adm/style/acp_bbcodes.html b/phpBB/adm/style/acp_bbcodes.html index 8bc0b5fdc2..af957ed372 100644 --- a/phpBB/adm/style/acp_bbcodes.html +++ b/phpBB/adm/style/acp_bbcodes.html @@ -50,7 +50,7 @@
{{ lang('APPEARANCE') }}
-

{{ lang('BBCODE_FONT_ICON_EXPLAIN') }}
+

{L_BBCODE_FONT_ICON_EXPLAIN}
{{ Icon('font', BBCODE_FONT_ICON, '', false, '', {'id':'bbcode_icon_preview'}) }} diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 66ef3627ab..e28c1f6155 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -104,12 +104,13 @@ class acp_bbcodes 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . '&action=' . (($action == 'add') ? 'create' : 'modify') . (($bbcode_id) ? "&bbcode=$bbcode_id" : ''), - 'L_BBCODE_USAGE_EXPLAIN'=> sprintf($user->lang['BBCODE_USAGE_EXPLAIN'], '', ''), - 'BBCODE_MATCH' => $bbcode_match, - 'BBCODE_TPL' => $bbcode_tpl, - 'BBCODE_HELPLINE' => $bbcode_helpline, - 'BBCODE_FONT_ICON' => $bbcode_font_icon, - 'DISPLAY_ON_POSTING' => $display_on_posting, + 'L_BBCODE_USAGE_EXPLAIN' => sprintf($user->lang['BBCODE_USAGE_EXPLAIN'], '', ''), + 'L_BBCODE_FONT_ICON_EXPLAIN' => sprintf($user->lang['BBCODE_USAGE_EXPLAIN'], '', ''), + 'BBCODE_MATCH' => $bbcode_match, + 'BBCODE_TPL' => $bbcode_tpl, + 'BBCODE_HELPLINE' => $bbcode_helpline, + 'BBCODE_FONT_ICON' => $bbcode_font_icon, + 'DISPLAY_ON_POSTING' => $display_on_posting, ); $bbcode_tokens = array('TEXT', 'SIMPLETEXT', 'INTTEXT', 'IDENTIFIER', 'NUMBER', 'EMAIL', 'URL', 'LOCAL_URL', 'RELATIVE_URL', 'COLOR'); diff --git a/phpBB/language/en/acp/posting.php b/phpBB/language/en/acp/posting.php index c219b1a46a..b03a83956f 100644 --- a/phpBB/language/en/acp/posting.php +++ b/phpBB/language/en/acp/posting.php @@ -54,7 +54,7 @@ $lang = array_merge($lang, array( 'BBCODE_HELPLINE_TEXT' => 'Help line text', 'BBCODE_HELPLINE_TOO_LONG' => 'The help line you entered is too long.', 'BBCODE_FONT_ICON' => 'BBCode icon', - 'BBCODE_FONT_ICON_EXPLAIN' => 'Enter the name of a Font Awesome icon (without the fa prefix) to display instead of the BBCode name appearing on the button. Click here to view the list of available icons.', + 'BBCODE_FONT_ICON_EXPLAIN' => 'Enter the name of a Font Awesome icon (without the fa prefix) to display instead of the BBCode name appearing on the button. %1$sClick here%2$s to view the list of available icons. Only solid style icons are supported.', 'BBCODE_FONT_ICON_TOO_LONG' => 'The icon name you have entered is too long.', 'BBCODE_INVALID_TAG_NAME' => 'The BBCode tag name that you selected already exists.', diff --git a/phpBB/phpbb/db/migration/data/v400/add_bbcode_font_icon.php b/phpBB/phpbb/db/migration/data/v400/add_bbcode_font_icon.php index 1a580dde8c..183b5d91db 100644 --- a/phpBB/phpbb/db/migration/data/v400/add_bbcode_font_icon.php +++ b/phpBB/phpbb/db/migration/data/v400/add_bbcode_font_icon.php @@ -32,7 +32,7 @@ class add_bbcode_font_icon extends \phpbb\db\migration\migration return [ 'add_columns' => [ $this->table_prefix . 'bbcodes' => [ - 'bbcode_font_icon' => ['VCHAR:50', ''], + 'bbcode_font_icon' => ['VCHAR:64', ''], ], ], ]; From bb956539a46b53092ff8fd8c0bc61da10a2099a4 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 12 Aug 2024 21:01:09 +0100 Subject: [PATCH 04/14] [ticket/17326] Add php preg check on bbcode font icon name PHPBB-17326 --- phpBB/includes/acp/acp_bbcodes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index e28c1f6155..d9a4ae9822 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -238,7 +238,7 @@ class acp_bbcodes trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); } - if (strlen($bbcode_font_icon) > 50) + if (strlen($bbcode_font_icon) > 64 && preg_match('/^[A-Za-z0-9-]+$/', $bbcode_font_icon)) { trigger_error($user->lang['BBCODE_FONT_ICON_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); } From 53d7fff391cc9dc0b1dfa097b431ddadd43f544b Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 12 Aug 2024 21:05:09 +0100 Subject: [PATCH 05/14] [ticket/17326] Update regex checks for font icon in php and js files PHPBB-17326 --- phpBB/adm/style/admin.js | 5 ++++- phpBB/includes/acp/acp_bbcodes.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/phpBB/adm/style/admin.js b/phpBB/adm/style/admin.js index 1ff1b02d74..2ae75db062 100644 --- a/phpBB/adm/style/admin.js +++ b/phpBB/adm/style/admin.js @@ -280,7 +280,10 @@ function parse_document(container) // Live update BBCode font icon preview $('#bbcode_font_icon').on('keyup', function(e) { - $('#bbcode_icon_preview').attr('class', "o-icon o-icon-font fa-fw fas icon fa-" + $(this).val()); + const iconName = $(this).val(); + if (iconName.match(/^[\w-]+$/)) { + $('#bbcode_icon_preview').attr('class', "o-icon o-icon-font fa-fw fas icon fa-" + $(this).val()); + } }); }); })(jQuery); diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index d9a4ae9822..58d86c940d 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -238,7 +238,7 @@ class acp_bbcodes trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); } - if (strlen($bbcode_font_icon) > 64 && preg_match('/^[A-Za-z0-9-]+$/', $bbcode_font_icon)) + if (strlen($bbcode_font_icon) > 64 && preg_match('/^[\w-]+$/', $bbcode_font_icon)) { trigger_error($user->lang['BBCODE_FONT_ICON_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); } From fe3750bfb2a45884a71e91ce3d40f3ff0b13dea3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Aug 2024 21:39:53 +0200 Subject: [PATCH 06/14] [ticket/17326] Move HTML to acp_bbcodes.html PHPBB-17326 --- phpBB/adm/style/acp_bbcodes.html | 4 ++-- phpBB/includes/acp/acp_bbcodes.php | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/acp_bbcodes.html b/phpBB/adm/style/acp_bbcodes.html index af957ed372..cb3480f946 100644 --- a/phpBB/adm/style/acp_bbcodes.html +++ b/phpBB/adm/style/acp_bbcodes.html @@ -14,7 +14,7 @@
{L_BBCODE_USAGE} -

{L_BBCODE_USAGE_EXPLAIN}

+

{{ lang('BBCODE_USAGE_EXPLAIN', '', '') }}



{L_BBCODE_USAGE_EXAMPLE}
@@ -50,7 +50,7 @@
{{ lang('APPEARANCE') }}
-

{L_BBCODE_FONT_ICON_EXPLAIN}
+

{{ lang('BBCODE_FONT_ICON_EXPLAIN', '', '') }}
{{ Icon('font', BBCODE_FONT_ICON, '', false, '', {'id':'bbcode_icon_preview'}) }} diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 58d86c940d..ee97631d2e 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -104,8 +104,6 @@ class acp_bbcodes 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . '&action=' . (($action == 'add') ? 'create' : 'modify') . (($bbcode_id) ? "&bbcode=$bbcode_id" : ''), - 'L_BBCODE_USAGE_EXPLAIN' => sprintf($user->lang['BBCODE_USAGE_EXPLAIN'], '', ''), - 'L_BBCODE_FONT_ICON_EXPLAIN' => sprintf($user->lang['BBCODE_USAGE_EXPLAIN'], '', ''), 'BBCODE_MATCH' => $bbcode_match, 'BBCODE_TPL' => $bbcode_tpl, 'BBCODE_HELPLINE' => $bbcode_helpline, From 97728da9be70a90bb7da3786aa9faded1c67eea1 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 1 Sep 2024 16:10:45 +0100 Subject: [PATCH 07/14] [ticket/17326] Replace language string for invalid icon names PHPBB-17326 --- phpBB/includes/acp/acp_bbcodes.php | 4 ++-- phpBB/language/en/acp/posting.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index ee97631d2e..291151ab6f 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -236,9 +236,9 @@ class acp_bbcodes trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); } - if (strlen($bbcode_font_icon) > 64 && preg_match('/^[\w-]+$/', $bbcode_font_icon)) + if (strlen($bbcode_font_icon) > 64 || preg_match('/^[\w-]+$/', $bbcode_font_icon)) { - trigger_error($user->lang['BBCODE_FONT_ICON_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($user->lang['BBCODE_FONT_ICON_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } /** diff --git a/phpBB/language/en/acp/posting.php b/phpBB/language/en/acp/posting.php index b03a83956f..5ce331388d 100644 --- a/phpBB/language/en/acp/posting.php +++ b/phpBB/language/en/acp/posting.php @@ -55,7 +55,7 @@ $lang = array_merge($lang, array( 'BBCODE_HELPLINE_TOO_LONG' => 'The help line you entered is too long.', 'BBCODE_FONT_ICON' => 'BBCode icon', 'BBCODE_FONT_ICON_EXPLAIN' => 'Enter the name of a Font Awesome icon (without the fa prefix) to display instead of the BBCode name appearing on the button. %1$sClick here%2$s to view the list of available icons. Only solid style icons are supported.', - 'BBCODE_FONT_ICON_TOO_LONG' => 'The icon name you have entered is too long.', + 'BBCODE_FONT_ICON_INVALID' => 'The icon name you have entered is too long.', 'BBCODE_INVALID_TAG_NAME' => 'The BBCode tag name that you selected already exists.', 'BBCODE_INVALID' => 'Your BBCode is constructed in an invalid form.', From 220b655150b5c950a7b69a6e428492c772d40ced Mon Sep 17 00:00:00 2001 From: Daniel James Date: Fri, 7 Feb 2025 17:02:26 +0000 Subject: [PATCH 08/14] [ticket/17326] Updated js to use same as pages ext and fixed icon bug PHPBB-17326 --- phpBB/adm/style/acp_bbcodes.html | 2 +- phpBB/adm/style/admin.js | 23 ++++++++++++++++++----- phpBB/includes/acp/acp_bbcodes.php | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/phpBB/adm/style/acp_bbcodes.html b/phpBB/adm/style/acp_bbcodes.html index cb3480f946..aade2f8aac 100644 --- a/phpBB/adm/style/acp_bbcodes.html +++ b/phpBB/adm/style/acp_bbcodes.html @@ -53,7 +53,7 @@

{{ lang('BBCODE_FONT_ICON_EXPLAIN', '', '') }}
- {{ Icon('font', BBCODE_FONT_ICON, '', false, '', {'id':'bbcode_icon_preview'}) }} + {{ Icon('font', ' ', '', false, '', {'id':'bbcode_icon_preview'}) }}
diff --git a/phpBB/adm/style/admin.js b/phpBB/adm/style/admin.js index 2ae75db062..f53329b5a7 100644 --- a/phpBB/adm/style/admin.js +++ b/phpBB/adm/style/admin.js @@ -279,11 +279,24 @@ function parse_document(container) }); // Live update BBCode font icon preview - $('#bbcode_font_icon').on('keyup', function(e) { - const iconName = $(this).val(); - if (iconName.match(/^[\w-]+$/)) { - $('#bbcode_icon_preview').attr('class', "o-icon o-icon-font fa-fw fas icon fa-" + $(this).val()); - } + const updateIconClass = (element, newClass) => { + element.classList.forEach(className => { + if (className.startsWith('fa-') && className !== 'fa-fw') { + element.classList.remove(className); + } + }); + + element.classList.add(`fa-${newClass}`); + }; + + const pageIconFont = document.getElementById('bbcode_font_icon'); + + pageIconFont.addEventListener('keyup', function() { + updateIconClass(this.nextElementSibling, this.value); + }); + + pageIconFont.addEventListener('blur', function() { + updateIconClass(this.nextElementSibling, this.value); }); }); })(jQuery); diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 291151ab6f..6fb2dfbb9a 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -103,7 +103,7 @@ class acp_bbcodes 'S_EDIT_BBCODE' => true, 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . '&action=' . (($action == 'add') ? 'create' : 'modify') . (($bbcode_id) ? "&bbcode=$bbcode_id" : ''), - + 'L_BBCODE_USAGE_EXPLAIN' => sprintf($user->lang['BBCODE_USAGE_EXPLAIN'], '', ''), 'BBCODE_MATCH' => $bbcode_match, 'BBCODE_TPL' => $bbcode_tpl, 'BBCODE_HELPLINE' => $bbcode_helpline, From bf15d1ea420ebe7bd69bcd58520d73197ef2d871 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 15 Feb 2025 10:42:47 +0100 Subject: [PATCH 09/14] [ticket/17326] Check for existence of font icon element before use PHPBB-17326 --- phpBB/adm/style/admin.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/phpBB/adm/style/admin.js b/phpBB/adm/style/admin.js index f53329b5a7..f308bf9c12 100644 --- a/phpBB/adm/style/admin.js +++ b/phpBB/adm/style/admin.js @@ -291,12 +291,14 @@ function parse_document(container) const pageIconFont = document.getElementById('bbcode_font_icon'); - pageIconFont.addEventListener('keyup', function() { - updateIconClass(this.nextElementSibling, this.value); - }); + if (pageIconFont) { + pageIconFont.addEventListener('keyup', function () { + updateIconClass(this.nextElementSibling, this.value); + }); - pageIconFont.addEventListener('blur', function() { - updateIconClass(this.nextElementSibling, this.value); - }); + pageIconFont.addEventListener('blur', function () { + updateIconClass(this.nextElementSibling, this.value); + }); + } }); })(jQuery); From 29c19bb764da89eea691bdd9aeabcfaa13d1cc9a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 15 Feb 2025 10:44:08 +0100 Subject: [PATCH 10/14] [ticket/17326] Differentiate between invalid and too long icon name PHPBB-17326 --- phpBB/includes/acp/acp_bbcodes.php | 7 ++++++- phpBB/language/en/acp/posting.php | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 6fb2dfbb9a..ee3dffd461 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -236,7 +236,12 @@ class acp_bbcodes trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); } - if (strlen($bbcode_font_icon) > 64 || preg_match('/^[\w-]+$/', $bbcode_font_icon)) + if (strlen($bbcode_font_icon) > 64) + { + trigger_error($user->lang['BBCODE_FONT_ICON_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + if (!empty($bbcode_font_icon) && !preg_match('/^[\w-]+$/', $bbcode_font_icon)) { trigger_error($user->lang['BBCODE_FONT_ICON_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } diff --git a/phpBB/language/en/acp/posting.php b/phpBB/language/en/acp/posting.php index 5ce331388d..6420f9aa19 100644 --- a/phpBB/language/en/acp/posting.php +++ b/phpBB/language/en/acp/posting.php @@ -55,8 +55,8 @@ $lang = array_merge($lang, array( 'BBCODE_HELPLINE_TOO_LONG' => 'The help line you entered is too long.', 'BBCODE_FONT_ICON' => 'BBCode icon', 'BBCODE_FONT_ICON_EXPLAIN' => 'Enter the name of a Font Awesome icon (without the fa prefix) to display instead of the BBCode name appearing on the button. %1$sClick here%2$s to view the list of available icons. Only solid style icons are supported.', - 'BBCODE_FONT_ICON_INVALID' => 'The icon name you have entered is too long.', - + 'BBCODE_FONT_ICON_INVALID' => 'The icon name you have entered is invalid.', + 'BBCODE_FONT_ICON_TOO_LONG' => 'The icon name you have entered is too long.', 'BBCODE_INVALID_TAG_NAME' => 'The BBCode tag name that you selected already exists.', 'BBCODE_INVALID' => 'Your BBCode is constructed in an invalid form.', 'BBCODE_INVALID_TEMPLATE' => 'Your BBCode’s template is invalid.', From 68c4e22886ec239f6d45f3f432df1eabebd8f5fa Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 15 Feb 2025 11:09:22 +0100 Subject: [PATCH 11/14] [ticket/17326] Extend acp bbcodes test for font icon PHPBB-17326 --- tests/functional/acp_bbcodes_test.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/functional/acp_bbcodes_test.php b/tests/functional/acp_bbcodes_test.php index bdf7920615..ac73091a79 100644 --- a/tests/functional/acp_bbcodes_test.php +++ b/tests/functional/acp_bbcodes_test.php @@ -24,8 +24,9 @@ class phpbb_functional_acp_bbcodes_test extends phpbb_functional_test_case // Create the BBCode $crawler = self::request('GET', 'adm/index.php?i=acp_bbcodes&sid=' . $this->sid . '&mode=bbcodes&action=add'); $form = $crawler->selectButton('Submit')->form(array( - 'bbcode_match' => '[mod="{TEXT1}"]{TEXT2}[/mod]', - 'bbcode_tpl' => '
{TEXT1}
{TEXT2}
' + 'bbcode_match' => '[mod="{TEXT1}"]{TEXT2}[/mod]', + 'bbcode_tpl' => '
{TEXT1}
{TEXT2}
', + 'bbcode_font_icon' => 'user', )); self::submit($form); @@ -47,15 +48,16 @@ class phpbb_functional_acp_bbcodes_test extends phpbb_functional_test_case /** * @dataProvider get_bbcode_error_tests */ - public function test_bbcode_error($match, $tpl, $error) + public function test_bbcode_error($match, $tpl, $icon, $error) { $this->login(); $this->admin_login(); $crawler = self::request('GET', 'adm/index.php?i=acp_bbcodes&sid=' . $this->sid . '&mode=bbcodes&action=add'); $form = $crawler->selectButton('Submit')->form([ - 'bbcode_match' => $match, - 'bbcode_tpl' => $tpl + 'bbcode_match' => $match, + 'bbcode_tpl' => $tpl, + 'bbcode_font_icon' => $icon, ]); $crawler = self::submit($form); @@ -69,18 +71,33 @@ class phpbb_functional_acp_bbcodes_test extends phpbb_functional_test_case [ 'XXX', '', + '', 'BBCode is constructed in an invalid form' ], [ '[x]{TEXT}[/x]', '{TEXT}', + '', 'unsafe' ], + 'icon name too long' => [ + '[mod2="{TEXT1}"]{TEXT2}[/mod2]', + '
{TEXT1}
{TEXT2}
', + str_repeat('a', 65), + 'is too long', + ], + 'icon name invalid' => [ + '[mod2="{TEXT1}"]{TEXT2}[/mod2]', + '
{TEXT1}
{TEXT2}
', + 'Not a valid icon name', + 'is invalid', + ], ]; } } From 67e2b328163f63af0949b54c023206e6fbab6aa6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 15 Feb 2025 20:21:25 +0100 Subject: [PATCH 12/14] [ticket/17326] Ignore invalid class names PHPBB-17326 --- phpBB/adm/style/admin.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpBB/adm/style/admin.js b/phpBB/adm/style/admin.js index f308bf9c12..3d37b0c331 100644 --- a/phpBB/adm/style/admin.js +++ b/phpBB/adm/style/admin.js @@ -280,6 +280,12 @@ function parse_document(container) // Live update BBCode font icon preview const updateIconClass = (element, newClass) => { + // Ignore invalid class names + const faIconRegex = /^(?!-)(?!.*--)[a-z0-9-]+(? { if (className.startsWith('fa-') && className !== 'fa-fw') { element.classList.remove(className); From 1e76b0df0e1450c35bab6160b703d32bfb267324 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 15 Feb 2025 20:24:07 +0100 Subject: [PATCH 13/14] [ticket/17326] Use same regex in icon name validation in PHP PHPBB-17326 --- phpBB/includes/acp/acp_bbcodes.php | 2 +- tests/functional/acp_bbcodes_test.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index ee3dffd461..723a13d1db 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -241,7 +241,7 @@ class acp_bbcodes trigger_error($user->lang['BBCODE_FONT_ICON_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING); } - if (!empty($bbcode_font_icon) && !preg_match('/^[\w-]+$/', $bbcode_font_icon)) + if (!empty($bbcode_font_icon) && !preg_match('/^(?!-)(?!.*--)[a-z0-9-]+(?lang['BBCODE_FONT_ICON_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } diff --git a/tests/functional/acp_bbcodes_test.php b/tests/functional/acp_bbcodes_test.php index ac73091a79..dd0d356a58 100644 --- a/tests/functional/acp_bbcodes_test.php +++ b/tests/functional/acp_bbcodes_test.php @@ -98,6 +98,18 @@ class phpbb_functional_acp_bbcodes_test extends phpbb_functional_test_case 'Not a valid icon name', 'is invalid', ], + 'icon name invalid double dash' => [ + '[mod2="{TEXT1}"]{TEXT2}[/mod2]', + '
{TEXT1}
{TEXT2}
', + 'us--er', + 'is invalid', + ], + 'icon name invalid trailing dash' => [ + '[mod2="{TEXT1}"]{TEXT2}[/mod2]', + '
{TEXT1}
{TEXT2}
', + 'user-', + 'is invalid', + ], ]; } } From 183110789a05d9a3ae8f6739c64c39e9b5c109ff Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 16 Feb 2025 09:13:26 +0100 Subject: [PATCH 14/14] [ticket/17326] Add changed info for core.acp_bbcodes_modify_create event PHPBB-17326 --- phpBB/includes/acp/acp_bbcodes.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 723a13d1db..b49d74985f 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -163,6 +163,7 @@ class acp_bbcodes * @var array hidden_fields Array of hidden fields for use when * submitting form when $warn_unsafe is true * @since 3.1.0-a3 + * @changed 4.0.0-a1 Added bbcode_font_icon */ $vars = array( 'action',