[ticket/16863] Support playing video attachments

PHPBB3-16863
This commit is contained in:
3D-I 2021-08-30 21:28:45 +02:00
parent 3dc446d5ce
commit 80f3d7b0aa
10 changed files with 139 additions and 1 deletions

View file

@ -637,6 +637,7 @@ class acp_attachments
ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'], ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'], ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
ATTACHMENT_CATEGORY_AUDIO => $user->lang('CAT_AUDIO_FILES'), ATTACHMENT_CATEGORY_AUDIO => $user->lang('CAT_AUDIO_FILES'),
ATTACHMENT_CATEGORY_VIDEO => $user->lang('CAT_VIDEO_FILES'),
); );
$group_id = $request->variable('g', 0); $group_id = $request->variable('g', 0);
@ -1412,6 +1413,7 @@ class acp_attachments
ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'], ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'], ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
ATTACHMENT_CATEGORY_AUDIO => $user->lang('CAT_AUDIO_FILES'), ATTACHMENT_CATEGORY_AUDIO => $user->lang('CAT_AUDIO_FILES'),
ATTACHMENT_CATEGORY_VIDEO => $user->lang('CAT_VIDEO_FILES'),
); );
if ($group_id) if ($group_id)

View file

@ -162,6 +162,7 @@ define('ATTACHMENT_CATEGORY_NONE', 0);
define('ATTACHMENT_CATEGORY_IMAGE', 1); // Inline Images define('ATTACHMENT_CATEGORY_IMAGE', 1); // Inline Images
define('ATTACHMENT_CATEGORY_THUMB', 4); // Not used within the database, only while displaying posts define('ATTACHMENT_CATEGORY_THUMB', 4); // Not used within the database, only while displaying posts
define('ATTACHMENT_CATEGORY_AUDIO', 7); // Browser-playable audio files define('ATTACHMENT_CATEGORY_AUDIO', 7); // Browser-playable audio files
define('ATTACHMENT_CATEGORY_VIDEO', 8); // Browser-playable video files
// BBCode UID length // BBCode UID length
define('BBCODE_UID_LEN', 8); define('BBCODE_UID_LEN', 8);

View file

@ -1323,6 +1323,15 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
$update_count_ary[] = $attachment['attach_id']; $update_count_ary[] = $attachment['attach_id'];
break; break;
// Audio files
case ATTACHMENT_CATEGORY_VIDEO:
$block_array += [
'S_VIDEO_FILE' => true,
];
$update_count_ary[] = $attachment['attach_id'];
break;
default: default:
$l_downloaded_viewed = 'DOWNLOAD_COUNTS'; $l_downloaded_viewed = 'DOWNLOAD_COUNTS';

View file

@ -777,6 +777,7 @@ INSERT INTO phpbb_extension_groups (group_name, cat_id, allow_group, upload_icon
INSERT INTO phpbb_extension_groups (group_name, cat_id, allow_group, upload_icon, max_filesize, allowed_forums) VALUES ('DOCUMENTS', 0, 0, '', 0, ''); INSERT INTO phpbb_extension_groups (group_name, cat_id, allow_group, upload_icon, max_filesize, allowed_forums) VALUES ('DOCUMENTS', 0, 0, '', 0, '');
INSERT INTO phpbb_extension_groups (group_name, cat_id, allow_group, upload_icon, max_filesize, allowed_forums) VALUES ('DOWNLOADABLE_FILES', 0, 0, '', 0, ''); INSERT INTO phpbb_extension_groups (group_name, cat_id, allow_group, upload_icon, max_filesize, allowed_forums) VALUES ('DOWNLOADABLE_FILES', 0, 0, '', 0, '');
INSERT INTO phpbb_extension_groups (group_name, cat_id, allow_group, upload_icon, max_filesize, allowed_forums) VALUES ('AUDIO_FILES', 7, 0, '', 0, ''); INSERT INTO phpbb_extension_groups (group_name, cat_id, allow_group, upload_icon, max_filesize, allowed_forums) VALUES ('AUDIO_FILES', 7, 0, '', 0, '');
INSERT INTO phpbb_extension_groups (group_name, cat_id, allow_group, upload_icon, max_filesize, allowed_forums) VALUES ('VIDEO_FILES', 8, 0, '', 0, '');
# -- extensions # -- extensions
INSERT INTO phpbb_extensions (group_id, extension) VALUES (1, 'gif'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (1, 'gif');
@ -842,6 +843,11 @@ INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'm4a');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'ogg'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'ogg');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'webm'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'webm');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'mp4');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'ogg');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'webm');
# Add default profile fields # Add default profile fields
INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_location', 'profilefields.type.string', 'phpbb_location', '20', '2', '100', '', '', '.*', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, '', ''); INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_location', 'profilefields.type.string', 'phpbb_location', '20', '2', '100', '', '', '.*', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, '', '');
INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_website', 'profilefields.type.url', 'phpbb_website', '40', '12', '255', '', '', '', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 2, 1, 'VISIT_WEBSITE', '%s'); INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_website', 'profilefields.type.url', 'phpbb_website', '40', '12', '255', '', '', '', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 2, 1, 'VISIT_WEBSITE', '%s');

View file

@ -69,6 +69,7 @@ $lang = array_merge($lang, array(
'ATTACH_TO_POST' => 'Attach file to post', 'ATTACH_TO_POST' => 'Attach file to post',
'CAT_AUDIO_FILES' => 'Audio files', 'CAT_AUDIO_FILES' => 'Audio files',
'CAT_VIDEO_FILES' => 'Video files',
'CAT_IMAGES' => 'Images', 'CAT_IMAGES' => 'Images',
'CHECK_CONTENT' => 'Check attachment files', 'CHECK_CONTENT' => 'Check attachment files',
'CHECK_CONTENT_EXPLAIN' => 'Some browsers can be tricked to assume an incorrect mimetype for uploaded files. This option ensures that such files likely to cause this are rejected.', 'CHECK_CONTENT_EXPLAIN' => 'Some browsers can be tricked to assume an incorrect mimetype for uploaded files. This option ensures that such files likely to cause this are rejected.',

View file

@ -0,0 +1,86 @@
<?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 phpbb\db\migration\data\v400;
class add_video_files_attachment_group extends \phpbb\db\migration\migration
{
public static function depends_on()
{
return ['\phpbb\db\migration\data\v400\dev'];
}
public function update_data()
{
return [
['custom', [[$this, 'add_video_files']]],
];
}
public function add_video_files()
{
$sql = 'SELECT group_id
FROM ' . $this->table_prefix . 'extension_groups
WHERE ' . $this->db->sql_build_array('SELECT', ['group_name' => 'VIDEO_FILES']);
$result = $this->db->sql_query($sql);
$video_group_id = $this->db->sql_fetchfield('group_id');
$this->db->sql_freeresult($result);
if ($video_group_id === false)
{
$sql = 'INSERT INTO ' . $this->table_prefix . 'extension_groups ' . $this->db->sql_build_array('INSERT', [
'group_name' => 'VIDEO_FILES',
'cat_id' => ATTACHMENT_CATEGORY_VIDEO,
'allow_group' => 0,
'upload_icon' => '',
'max_filesize' => 0,
'allowed_forums' => '',
]);
$this->db->sql_query($sql);
$video_group_id = $this->db->sql_nextid();
}
else
{
$sql = 'UPDATE ' . $this->table_prefix . 'extension_groups SET cat_id = ' . ATTACHMENT_CATEGORY_VIDEO . '
WHERE ' . $this->db->sql_build_array('SELECT', ['group_id' => $video_group_id]);
$this->db->sql_query($sql);
}
$video_extensions = ['mp4', 'ogg', 'webm'];
foreach ($video_extensions as $video_extension)
{
$sql = 'SELECT group_id
FROM ' . $this->table_prefix . 'extensions
WHERE ' . $this->db->sql_build_array('SELECT', ['extension' => $video_extension]);
$result = $this->db->sql_query($sql);
$extension_group_id = $this->db->sql_fetchfield('group_id');
$this->db->sql_freeresult($result);
if ($extension_group_id === false)
{
$sql = 'INSERT INTO ' . $this->table_prefix . 'extensions ' . $this->db->sql_build_array('INSERT', [
'group_id' => $video_group_id,
'extension' => $video_extension,
]);
$this->db->sql_query($sql);
}
else if ($extension_group_id != $video_group_id)
{
$sql = 'UPDATE ' . $this->table_prefix . "extensions SET group_id = $video_group_id
WHERE " . $this->db->sql_build_array('SELECT', ['extension' => $video_extension]);
$this->db->sql_query($sql);
}
}
}
}

View file

@ -253,6 +253,7 @@ class extension_guesser extends guesser_base
'omc' => 'application/x-omc', 'omc' => 'application/x-omc',
'oga' => 'audio/ogg', 'oga' => 'audio/ogg',
'ogg' => 'audio/ogg', 'ogg' => 'audio/ogg',
'ogg' => 'video/ogg',
'ogm' => 'video/ogg', 'ogm' => 'video/ogg',
'omcd' => 'application/x-omcdatamaker', 'omcd' => 'application/x-omcdatamaker',
'omcr' => 'application/x-omcregerator', 'omcr' => 'application/x-omcregerator',
@ -426,6 +427,7 @@ class extension_guesser extends guesser_base
'wbmp' => 'image/vnd.wap.wbmp', 'wbmp' => 'image/vnd.wap.wbmp',
'web' => 'application/vnd.xara', 'web' => 'application/vnd.xara',
'webm' => 'audio/webm', 'webm' => 'audio/webm',
'webm' => 'video/webm',
'wiz' => 'application/msword', 'wiz' => 'application/msword',
'wk1' => 'application/x-123', 'wk1' => 'application/x-123',
'wmf' => 'windows/metafile', 'wmf' => 'windows/metafile',

View file

@ -254,7 +254,8 @@ class attachment extends controller
$response->headers->set('Content-Type', $attachment['mimetype']); $response->headers->set('Content-Type', $attachment['mimetype']);
// Display images in browser and force download for other file types // Display images in browser and force download for other file types
if (strpos($attachment['mimetype'], 'image') !== false || strpos($attachment['mimetype'], 'audio') !== false) if (strpos($attachment['mimetype'], 'image') !== false || strpos($attachment['mimetype'], 'audio') !== false ||
strpos($attachment['mimetype'], 'video') !== false)
{ {
$disposition = $response->headers->makeDisposition( $disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_INLINE, ResponseHeaderBag::DISPOSITION_INLINE,

View file

@ -49,6 +49,26 @@
</dl> </dl>
{% endif %} {% endif %}
{% if _file.S_VIDEO_FILE %}
<dl class="file">
<dt class="c-file-header">
<video class="c-file-video-controls" controls="controls" preload="metadata">
<source class="c-file-video-source" src="{{ _file.U_DOWNLOAD_LINK }}" type="{{ _file.MIMETYPE }}">
</video>
</dt>
{% if _file.COMMENT %}
<dd class="c-file-comment">{{ _file.COMMENT }}</dd>
{% endif %}
<dd class="c-file-actions">
{% if _file.UPLOAD_ICON %}
<span class="o-icon c-file-icon">{{ _file.UPLOAD_ICON }}</span>
{% endif %}
<a class="c-file-actions-link postlink" href="{{ _file.U_DOWNLOAD_LINK }}" download>{{ _file.DOWNLOAD_NAME }}</a>
<span class="c-file-actions-meta">({{ _file.FILESIZE }} {{ _file.SIZE_LANG }}) {{ _file.L_DOWNLOAD_COUNT }}</span>
</dd>
</dl>
{% endif %}
<!-- EVENT attachment_file_append --> <!-- EVENT attachment_file_append -->
<!-- ENDIF --> <!-- ENDIF -->
<!-- END _file --> <!-- END _file -->

View file

@ -688,6 +688,16 @@ dl.thumbnail dt a:hover img {
max-width: 100%; max-width: 100%;
} }
.c-file-audio-source {
}
.c-file-video-controls {
max-width: 100%;
}
.c-file-video-source {
}
/* Post poll styles /* Post poll styles
---------------------------------------- */ ---------------------------------------- */
fieldset.polls { fieldset.polls {