From 98f446df67161cb7fbc4af95060d7998625f9eb0 Mon Sep 17 00:00:00 2001 From: 3D-I Date: Sun, 10 Oct 2021 07:05:43 +0200 Subject: [PATCH 01/12] [ticket/16888] Add the list of allowed files in the attachment tab PHPBB3-16888 --- phpBB/includes/functions_posting.php | 5 +++++ phpBB/language/en/posting.php | 1 + phpBB/styles/prosilver/template/posting_attach_body.html | 1 + 3 files changed, 7 insertions(+) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 5c62378a06a..f885934ea82 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -818,6 +818,10 @@ function posting_gen_inline_attachments(&$attachment_data) function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true) { global $template, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher; + global $cache, $request; + + $forum_id = $request->variable('f', 0); + $allowed_attachments = array_keys($cache->obtain_attach_extensions($forum_id)['_allowed_']); // Some default template variables $template->assign_vars(array( @@ -826,6 +830,7 @@ function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_a 'FILESIZE' => $config['max_filesize'], 'FILE_COMMENT' => (isset($filename_data['filecomment'])) ? $filename_data['filecomment'] : '', 'MAX_ATTACHMENT_FILESIZE' => $config['max_filesize'] > 0 ? $user->lang('MAX_ATTACHMENT_FILESIZE', get_formatted_filesize($config['max_filesize'])) : '', + 'ALLOWED_ATTACHMENTS' => implode(', ', $allowed_attachments), )); if (count($attachment_data)) diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index 1a6866d5352..901cd0dad63 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -152,6 +152,7 @@ 'LOGIN_EXPLAIN_REPLY' => 'You need to login in order to reply to topics within this forum.', 'MAX_ATTACHMENT_FILESIZE' => 'Maximum filesize per attachment: %s.', + 'ALLOWED_ATTACHMENTS' => 'Allowed files', 'MAX_FONT_SIZE_EXCEEDED' => 'You may only use fonts up to size %d.', 'MAX_FLASH_HEIGHT_EXCEEDED' => array( 1 => 'Your flash files may only be up to %d pixel high.', diff --git a/phpBB/styles/prosilver/template/posting_attach_body.html b/phpBB/styles/prosilver/template/posting_attach_body.html index f304d727f2b..ceb93001c19 100644 --- a/phpBB/styles/prosilver/template/posting_attach_body.html +++ b/phpBB/styles/prosilver/template/posting_attach_body.html @@ -3,6 +3,7 @@

{L_ADD_ATTACHMENT_EXPLAIN}

{% if MAX_ATTACHMENT_FILESIZE is not empty %}

{{ MAX_ATTACHMENT_FILESIZE }}

{% endif %} + {% if ALLOWED_ATTACHMENTS is not empty %}

{{ lang('ALLOWED_ATTACHMENTS') ~ lang('COLON') }} {{ ALLOWED_ATTACHMENTS }}

{% endif %}
From 9ca70432d97c76459ecfc8c69d6ac7e3114c2aac Mon Sep 17 00:00:00 2001 From: 3D-I Date: Sun, 10 Oct 2021 13:26:16 +0200 Subject: [PATCH 02/12] [ticket/16888] Add the list of allowed files in the attachment tab Make sure we are checking both PMs and topics PHPBB3-16888 --- phpBB/includes/functions_posting.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index f885934ea82..e1cfb3145e5 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -820,7 +820,8 @@ function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_a global $template, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher; global $cache, $request; - $forum_id = $request->variable('f', 0); + // $forum_id when FALSE check for PMs if INT then check for forum id (topics|posts) + $forum_id = $request->variable('f', 0) ? $request->variable('f', 0) : false; $allowed_attachments = array_keys($cache->obtain_attach_extensions($forum_id)['_allowed_']); // Some default template variables @@ -830,7 +831,7 @@ function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_a 'FILESIZE' => $config['max_filesize'], 'FILE_COMMENT' => (isset($filename_data['filecomment'])) ? $filename_data['filecomment'] : '', 'MAX_ATTACHMENT_FILESIZE' => $config['max_filesize'] > 0 ? $user->lang('MAX_ATTACHMENT_FILESIZE', get_formatted_filesize($config['max_filesize'])) : '', - 'ALLOWED_ATTACHMENTS' => implode(', ', $allowed_attachments), + 'ALLOWED_ATTACHMENTS' => !empty($allowed_attachments) ? implode(', ', $allowed_attachments) : '', )); if (count($attachment_data)) From 52c931a8b653791330e76ef1e6e902b27a3f2f81 Mon Sep 17 00:00:00 2001 From: 3D-I Date: Sun, 10 Oct 2021 13:32:31 +0200 Subject: [PATCH 03/12] [ticket/16888] Add the list of allowed files in the attachment tab Request mixed content using shorthand Ternary PHPBB3-16888 --- phpBB/includes/functions_posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index e1cfb3145e5..30e7cbf451a 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -821,7 +821,7 @@ function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_a global $cache, $request; // $forum_id when FALSE check for PMs if INT then check for forum id (topics|posts) - $forum_id = $request->variable('f', 0) ? $request->variable('f', 0) : false; + $forum_id = $request->variable('f', 0) ?: false; $allowed_attachments = array_keys($cache->obtain_attach_extensions($forum_id)['_allowed_']); // Some default template variables From 4f3f91dfc380415a2a57beeb3770574a5939b0f4 Mon Sep 17 00:00:00 2001 From: 3D-I Date: Sun, 10 Oct 2021 14:00:27 +0200 Subject: [PATCH 04/12] [ticket/16888] Add the list of allowed files in the attachment tab PHPBB3-16888 --- phpBB/language/en/posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index 901cd0dad63..fd2789f752e 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -152,7 +152,7 @@ 'LOGIN_EXPLAIN_REPLY' => 'You need to login in order to reply to topics within this forum.', 'MAX_ATTACHMENT_FILESIZE' => 'Maximum filesize per attachment: %s.', - 'ALLOWED_ATTACHMENTS' => 'Allowed files', + 'ALLOWED_ATTACHMENTS' => 'Allowed file types', 'MAX_FONT_SIZE_EXCEEDED' => 'You may only use fonts up to size %d.', 'MAX_FLASH_HEIGHT_EXCEEDED' => array( 1 => 'Your flash files may only be up to %d pixel high.', From c0296d10db8724758c7e048ae053d830d395ab05 Mon Sep 17 00:00:00 2001 From: 3D-I Date: Sun, 10 Oct 2021 16:16:56 +0200 Subject: [PATCH 05/12] [ticket/16888] Add the list of allowed files in the attachment tab Using the accept attribute PHPBB3-16888 --- phpBB/includes/functions_posting.php | 2 +- phpBB/styles/prosilver/template/posting_attach_body.html | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 30e7cbf451a..22b15cd893a 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -831,7 +831,7 @@ function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_a 'FILESIZE' => $config['max_filesize'], 'FILE_COMMENT' => (isset($filename_data['filecomment'])) ? $filename_data['filecomment'] : '', 'MAX_ATTACHMENT_FILESIZE' => $config['max_filesize'] > 0 ? $user->lang('MAX_ATTACHMENT_FILESIZE', get_formatted_filesize($config['max_filesize'])) : '', - 'ALLOWED_ATTACHMENTS' => !empty($allowed_attachments) ? implode(', ', $allowed_attachments) : '', + 'ALLOWED_ATTACHMENTS' => !empty($allowed_attachments) ? implode(',', $allowed_attachments) : '', )); if (count($attachment_data)) diff --git a/phpBB/styles/prosilver/template/posting_attach_body.html b/phpBB/styles/prosilver/template/posting_attach_body.html index ceb93001c19..378fd118ccc 100644 --- a/phpBB/styles/prosilver/template/posting_attach_body.html +++ b/phpBB/styles/prosilver/template/posting_attach_body.html @@ -3,13 +3,12 @@

{L_ADD_ATTACHMENT_EXPLAIN}

{% if MAX_ATTACHMENT_FILESIZE is not empty %}

{{ MAX_ATTACHMENT_FILESIZE }}

{% endif %} - {% if ALLOWED_ATTACHMENTS is not empty %}

{{ lang('ALLOWED_ATTACHMENTS') ~ lang('COLON') }} {{ ALLOWED_ATTACHMENTS }}

{% endif %}
- +
From b29c0ca153fe400eed5d00f9572d13c5b83aeef8 Mon Sep 17 00:00:00 2001 From: 3D-I Date: Sun, 10 Oct 2021 16:26:26 +0200 Subject: [PATCH 06/12] [ticket/16888] Add the list of allowed files in the attachment tab PHPBB3-16888 --- phpBB/language/en/posting.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/language/en/posting.php b/phpBB/language/en/posting.php index fd2789f752e..1a6866d5352 100644 --- a/phpBB/language/en/posting.php +++ b/phpBB/language/en/posting.php @@ -152,7 +152,6 @@ 'LOGIN_EXPLAIN_REPLY' => 'You need to login in order to reply to topics within this forum.', 'MAX_ATTACHMENT_FILESIZE' => 'Maximum filesize per attachment: %s.', - 'ALLOWED_ATTACHMENTS' => 'Allowed file types', 'MAX_FONT_SIZE_EXCEEDED' => 'You may only use fonts up to size %d.', 'MAX_FLASH_HEIGHT_EXCEEDED' => array( 1 => 'Your flash files may only be up to %d pixel high.', From 161901412002ff02865b59aca10d6f279809d47d Mon Sep 17 00:00:00 2001 From: 3D-I Date: Mon, 11 Oct 2021 02:48:34 +0200 Subject: [PATCH 07/12] [ticket/16888] Add the list of allowed files in the attachment tab PHPBB3-16888 --- phpBB/includes/functions_posting.php | 7 +++---- phpBB/includes/ucp/ucp_pm_compose.php | 2 +- phpBB/posting.php | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 22b15cd893a..d3eb61b3e41 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -815,13 +815,12 @@ function posting_gen_inline_attachments(&$attachment_data) /** * Generate inline attachment entry */ -function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true) +function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true, $forum_id = false) { - global $template, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher; - global $cache, $request; + global $template, $cache, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher; // $forum_id when FALSE check for PMs if INT then check for forum id (topics|posts) - $forum_id = $request->variable('f', 0) ?: false; + $forum_id != false ?: (int) $forum_id; $allowed_attachments = array_keys($cache->obtain_attach_extensions($forum_id)['_allowed_']); // Some default template variables diff --git a/phpBB/includes/ucp/ucp_pm_compose.php b/phpBB/includes/ucp/ucp_pm_compose.php index 7cb4c85916d..0dae6444886 100644 --- a/phpBB/includes/ucp/ucp_pm_compose.php +++ b/phpBB/includes/ucp/ucp_pm_compose.php @@ -1390,7 +1390,7 @@ function compose_pm($id, $mode, $action, $user_folders = array()) } // Attachment entry - posting_gen_attachment_entry($attachment_data, $filename_data, $allowed); + posting_gen_attachment_entry($attachment_data, $filename_data, $allowed, false); // Message History if ($action == 'reply' || $action == 'quote' || $action == 'forward') diff --git a/phpBB/posting.php b/phpBB/posting.php index 6fc56abdd90..bc3e28ca43e 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -2078,7 +2078,7 @@ } // Attachment entry -posting_gen_attachment_entry($attachment_data, $filename_data, $allowed); +posting_gen_attachment_entry($attachment_data, $filename_data, $allowed, $forum_id); // Output page ... page_header($page_title); From 7a21a9032e56dd82c76ebdf98da891f66a84fe2c Mon Sep 17 00:00:00 2001 From: 3D-I Date: Mon, 11 Oct 2021 04:04:09 +0200 Subject: [PATCH 08/12] [ticket/16888] Add the list of allowed files in the attachment tab PHPBB3-16888 --- phpBB/includes/functions_posting.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index d3eb61b3e41..eaec554b943 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -813,13 +813,18 @@ function posting_gen_inline_attachments(&$attachment_data) } /** -* Generate inline attachment entry -*/ -function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true, $forum_id = false) + * Generate inline attachment entry + * + * @param array $attachment_data The attachment data + * @param string $filename_data The filename data (filecomment) + * @param bool $show_attach_box Whether to show the attach box + * @param mixed $forum_id The forum id to check or false if private message + * @return int + */ +function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true, $forum_id) { global $template, $cache, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher; - // $forum_id when FALSE check for PMs if INT then check for forum id (topics|posts) $forum_id != false ?: (int) $forum_id; $allowed_attachments = array_keys($cache->obtain_attach_extensions($forum_id)['_allowed_']); From 96c439bf108f20fd04ed87052ea094da0de512fa Mon Sep 17 00:00:00 2001 From: 3D-I Date: Mon, 11 Oct 2021 04:15:25 +0200 Subject: [PATCH 09/12] [ticket/16888] Add the list of allowed files in the attachment tab PHPBB3-16888 --- phpBB/includes/functions_posting.php | 4 ++-- phpBB/includes/ucp/ucp_pm_compose.php | 2 +- phpBB/posting.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index eaec554b943..15f0279c057 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -817,11 +817,11 @@ function posting_gen_inline_attachments(&$attachment_data) * * @param array $attachment_data The attachment data * @param string $filename_data The filename data (filecomment) - * @param bool $show_attach_box Whether to show the attach box * @param mixed $forum_id The forum id to check or false if private message + * @param bool $show_attach_box Whether to show the attach box * @return int */ -function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true, $forum_id) +function posting_gen_attachment_entry($attachment_data, &$filename_data, $forum_id, $show_attach_box = true) { global $template, $cache, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher; diff --git a/phpBB/includes/ucp/ucp_pm_compose.php b/phpBB/includes/ucp/ucp_pm_compose.php index 0dae6444886..c601e058cf4 100644 --- a/phpBB/includes/ucp/ucp_pm_compose.php +++ b/phpBB/includes/ucp/ucp_pm_compose.php @@ -1390,7 +1390,7 @@ function compose_pm($id, $mode, $action, $user_folders = array()) } // Attachment entry - posting_gen_attachment_entry($attachment_data, $filename_data, $allowed, false); + posting_gen_attachment_entry($attachment_data, $filename_data, false, $allowed); // Message History if ($action == 'reply' || $action == 'quote' || $action == 'forward') diff --git a/phpBB/posting.php b/phpBB/posting.php index bc3e28ca43e..34f93ef08fe 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -2078,7 +2078,7 @@ } // Attachment entry -posting_gen_attachment_entry($attachment_data, $filename_data, $allowed, $forum_id); +posting_gen_attachment_entry($attachment_data, $filename_data, $forum_id, $allowed); // Output page ... page_header($page_title); From c5814ddfaa60a643c4f870a12cdb68193b47665a Mon Sep 17 00:00:00 2001 From: 3D-I Date: Mon, 11 Oct 2021 04:24:11 +0200 Subject: [PATCH 10/12] [ticket/16888] Add the list of allowed files in the attachment tab PHPBB3-16888 --- phpBB/includes/functions_posting.php | 4 ++-- phpBB/includes/ucp/ucp_pm_compose.php | 2 +- phpBB/posting.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 15f0279c057..a65851ccd8a 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -817,11 +817,11 @@ function posting_gen_inline_attachments(&$attachment_data) * * @param array $attachment_data The attachment data * @param string $filename_data The filename data (filecomment) - * @param mixed $forum_id The forum id to check or false if private message * @param bool $show_attach_box Whether to show the attach box + * @param mixed $forum_id The forum id to check or false if private message * @return int */ -function posting_gen_attachment_entry($attachment_data, &$filename_data, $forum_id, $show_attach_box = true) +function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true, $forum_id = false) { global $template, $cache, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher; diff --git a/phpBB/includes/ucp/ucp_pm_compose.php b/phpBB/includes/ucp/ucp_pm_compose.php index c601e058cf4..7cb4c85916d 100644 --- a/phpBB/includes/ucp/ucp_pm_compose.php +++ b/phpBB/includes/ucp/ucp_pm_compose.php @@ -1390,7 +1390,7 @@ function compose_pm($id, $mode, $action, $user_folders = array()) } // Attachment entry - posting_gen_attachment_entry($attachment_data, $filename_data, false, $allowed); + posting_gen_attachment_entry($attachment_data, $filename_data, $allowed); // Message History if ($action == 'reply' || $action == 'quote' || $action == 'forward') diff --git a/phpBB/posting.php b/phpBB/posting.php index 34f93ef08fe..bc3e28ca43e 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -2078,7 +2078,7 @@ } // Attachment entry -posting_gen_attachment_entry($attachment_data, $filename_data, $forum_id, $allowed); +posting_gen_attachment_entry($attachment_data, $filename_data, $allowed, $forum_id); // Output page ... page_header($page_title); From a7385f0fbe3fdf9f563c050e5fa57589cbfb9f9c Mon Sep 17 00:00:00 2001 From: 3D-I Date: Mon, 11 Oct 2021 04:54:50 +0200 Subject: [PATCH 11/12] [ticket/16888] Add the list of allowed files in the attachment tab PHPBB3-16888 --- phpBB/includes/functions_posting.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index a65851ccd8a..8f3c0d6c44d 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -825,7 +825,6 @@ function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_a { global $template, $cache, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher; - $forum_id != false ?: (int) $forum_id; $allowed_attachments = array_keys($cache->obtain_attach_extensions($forum_id)['_allowed_']); // Some default template variables From 7355ee623a9d2a1aaa3eb6faec910fe4f2bbe6ce Mon Sep 17 00:00:00 2001 From: 3D-I Date: Mon, 11 Oct 2021 08:23:34 +0200 Subject: [PATCH 12/12] [ticket/16888] Add the list of allowed files in the attachment tab Add core.modify_default_attachments_template_vars PHPBB3-16888 --- phpBB/includes/functions_posting.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 8f3c0d6c44d..971bdfe475d 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -828,14 +828,27 @@ function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_a $allowed_attachments = array_keys($cache->obtain_attach_extensions($forum_id)['_allowed_']); // Some default template variables - $template->assign_vars(array( + $default_vars = [ 'S_SHOW_ATTACH_BOX' => $show_attach_box, 'S_HAS_ATTACHMENTS' => count($attachment_data), 'FILESIZE' => $config['max_filesize'], 'FILE_COMMENT' => (isset($filename_data['filecomment'])) ? $filename_data['filecomment'] : '', 'MAX_ATTACHMENT_FILESIZE' => $config['max_filesize'] > 0 ? $user->lang('MAX_ATTACHMENT_FILESIZE', get_formatted_filesize($config['max_filesize'])) : '', 'ALLOWED_ATTACHMENTS' => !empty($allowed_attachments) ? implode(',', $allowed_attachments) : '', - )); + ]; + + /** + * Modify default attachments template vars + * + * @event core.modify_default_attachments_template_vars + * @var array allowed_attachments Array containing allowed attachments data + * @var array default_vars Array containing default attachments template vars + * @since 3.3.6-RC1 + */ + $vars = ['allowed_attachments', 'default_vars']; + extract($phpbb_dispatcher->trigger_event('core.modify_default_attachments_template_vars', compact($vars))); + + $template->assign_vars($default_vars); if (count($attachment_data)) {