Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ticket/16888] List allowed attachment types using accept attribute #6306

Merged
merged 12 commits into from Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 28 additions & 6 deletions phpBB/includes/functions_posting.php
Expand Up @@ -813,20 +813,42 @@ function posting_gen_inline_attachments(&$attachment_data)
}

/**
* Generate inline attachment entry
*/
function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true)
* 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 = false)
{
global $template, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher;
global $template, $cache, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher;

$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))
{
Expand Down
2 changes: 1 addition & 1 deletion phpBB/posting.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion phpBB/styles/prosilver/template/posting_attach_body.html
Expand Up @@ -8,7 +8,7 @@
<dl>
<dt><label for="fileupload">{L_FILENAME}{L_COLON}</label></dt>
<dd>
<input type="file" name="fileupload" id="fileupload" class="inputbox autowidth" />
<input type="file" accept="{{ ALLOWED_ATTACHMENTS }}" name="fileupload" id="fileupload" class="inputbox autowidth" />
<input type="submit" name="add_file" value="{L_ADD_FILE}" class="button2" onclick="upload = true;" />
</dd>
</dl>
Expand Down