[ticket/14771] Support playing audio attachments

Add Audio attachments category, Audio attachments group.
add most audio supported extensions to the audio group.
presserve audio extensions MIMEtypes.
modify the attachment style file to view the audio attachment in
AUDIO HTML5 tag.

PHPBB3-14771
This commit is contained in:
hubaishan 2018-11-15 13:02:34 +03:00 committed by Marc Alexander
parent 2f8e5b7248
commit 8fab32abd7
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
8 changed files with 45 additions and 4 deletions

View file

@ -1410,6 +1410,7 @@ class acp_attachments
$types = array( $types = array(
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'],
); );
if ($group_id) if ($group_id)

View file

@ -161,6 +161,7 @@ define('CONFIRM_REPORT', 4);
define('ATTACHMENT_CATEGORY_NONE', 0); 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
// BBCode UID length // BBCode UID length
define('BBCODE_UID_LEN', 8); define('BBCODE_UID_LEN', 8);

View file

@ -1228,6 +1228,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
$block_array += array( $block_array += array(
'UPLOAD_ICON' => $upload_icon, 'UPLOAD_ICON' => $upload_icon,
'FILESIZE' => $filesize['value'], 'FILESIZE' => $filesize['value'],
'MIMETYPE' => $attachment['mimetype'],
'SIZE_LANG' => $filesize['unit'], 'SIZE_LANG' => $filesize['unit'],
'DOWNLOAD_NAME' => utf8_basename($attachment['real_filename']), 'DOWNLOAD_NAME' => utf8_basename($attachment['real_filename']),
'COMMENT' => $comment, 'COMMENT' => $comment,
@ -1315,6 +1316,19 @@ 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_AUDIO:
$inline_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $attachment['attach_id']);
$block_array += array(
'S_AUDIO_FILE' => true,
'U_FORUM' => generate_board_url(),
'ATTACH_ID' => $attachment['attach_id'],
);
// Heard File ... update the download count
$update_count_ary[] = $attachment['attach_id'];
break;
default: default:
$l_downloaded_viewed = 'DOWNLOAD_COUNTS'; $l_downloaded_viewed = 'DOWNLOAD_COUNTS';

View file

@ -783,6 +783,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 ('PLAIN_TEXT', 0, 0, '', 0, ''); INSERT INTO phpbb_extension_groups (group_name, cat_id, allow_group, upload_icon, max_filesize, allowed_forums) VALUES ('PLAIN_TEXT', 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 ('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, '');
# -- extensions # -- extensions
INSERT INTO phpbb_extensions (group_id, extension) VALUES (1, 'gif'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (1, 'gif');
@ -838,12 +839,15 @@ INSERT INTO phpbb_extensions (group_id, extension) VALUES (4, 'ods');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (4, 'odt'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (4, 'odt');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (4, 'rtf'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (4, 'rtf');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (5, 'mp3');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (5, 'mpeg'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (5, 'mpeg');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (5, 'mpg'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (5, 'mpg');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (5, 'ogg');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (5, 'ogm'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (5, 'ogm');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'mp3');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'wav');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'm4a');
INSERT INTO phpbb_extensions (group_id, extension) VALUES (6, 'ogg');
# 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

@ -68,6 +68,7 @@ $lang = array_merge($lang, array(
'ATTACH_QUOTA_EXPLAIN' => 'Maximum drive space available for attachments for the whole board, with 0 being unlimited.', 'ATTACH_QUOTA_EXPLAIN' => 'Maximum drive space available for attachments for the whole board, with 0 being unlimited.',
'ATTACH_TO_POST' => 'Attach file to post', 'ATTACH_TO_POST' => 'Attach file to post',
'CAT_AUDIO_FILES' => 'Audio 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.',
@ -100,6 +101,7 @@ $lang = array_merge($lang, array(
'EXT_GROUP_DOWNLOADABLE_FILES' => 'Downloadable Files', 'EXT_GROUP_DOWNLOADABLE_FILES' => 'Downloadable Files',
'EXT_GROUP_IMAGES' => 'Images', 'EXT_GROUP_IMAGES' => 'Images',
'EXT_GROUP_PLAIN_TEXT' => 'Plain Text', 'EXT_GROUP_PLAIN_TEXT' => 'Plain Text',
'EXT_GROUP_AUDIO_FILES' => 'Audio Files',
'FILES_GONE' => 'Some of the attachments you selected for deletion do not exist. They may have been already deleted. Attachments that did exist were deleted.', 'FILES_GONE' => 'Some of the attachments you selected for deletion do not exist. They may have been already deleted. Attachments that did exist were deleted.',
'FILES_STATS_WRONG' => 'Your file statistics are likely inaccurate and need to be resynchronised. Actual values: number of attachments = %1$d, total size of attachments = %2$s.<br />Click %3$shere%4$s to resynchronise them.', 'FILES_STATS_WRONG' => 'Your file statistics are likely inaccurate and need to be resynchronised. Actual values: number of attachments = %1$d, total size of attachments = %2$s.<br />Click %3$shere%4$s to resynchronise them.',

View file

@ -196,6 +196,8 @@ class extension_guesser extends guesser_base
'm2a' => 'audio/mpeg', 'm2a' => 'audio/mpeg',
'm2v' => 'video/mpeg', 'm2v' => 'video/mpeg',
'm3u' => 'audio/x-mpequrl', 'm3u' => 'audio/x-mpequrl',
'm4a' => 'audio/mp4',
'm4v' => 'video/mp4',
'man' => 'application/x-troff-man', 'man' => 'application/x-troff-man',
'map' => 'application/x-navimap', 'map' => 'application/x-navimap',
'mar' => 'text/plain', 'mar' => 'text/plain',
@ -220,7 +222,8 @@ class extension_guesser extends guesser_base
'mov' => 'video/quicktime', 'mov' => 'video/quicktime',
'movie' => 'video/x-sgi-movie', 'movie' => 'video/x-sgi-movie',
'mp2' => 'audio/x-mpeg', 'mp2' => 'audio/x-mpeg',
'mp3' => 'audio/x-mpeg-3', 'mp3' => 'audio/mpeg',
'mp4' => 'video/mp4',
'mpa' => 'audio/mpeg', 'mpa' => 'audio/mpeg',
'mpc' => 'application/x-project', 'mpc' => 'application/x-project',
'mpe' => 'video/mpeg', 'mpe' => 'video/mpeg',
@ -248,6 +251,9 @@ class extension_guesser extends guesser_base
'o' => 'application/octet-stream', 'o' => 'application/octet-stream',
'oda' => 'application/oda', 'oda' => 'application/oda',
'omc' => 'application/x-omc', 'omc' => 'application/x-omc',
'oga' => 'audio/ogg',
'ogg' => 'audio/ogg',
'ogm' => 'video/ogg',
'omcd' => 'application/x-omcdatamaker', 'omcd' => 'application/x-omcdatamaker',
'omcr' => 'application/x-omcregerator', 'omcr' => 'application/x-omcregerator',
'p' => 'text/x-pascal', 'p' => 'text/x-pascal',

View file

@ -254,7 +254,7 @@ 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) if (strpos($attachment['mimetype'], 'image') !== false || strpos($attachment['mimetype'], 'audio') !== false)
{ {
$disposition = $response->headers->makeDisposition( $disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_INLINE, ResponseHeaderBag::DISPOSITION_INLINE,

View file

@ -29,6 +29,19 @@
</dl> </dl>
<!-- ENDIF --> <!-- ENDIF -->
<!-- IF _file.S_AUDIO_FILE -->
<dl class="file">
<dt><!-- IF _file.UPLOAD_ICON -->{_file.UPLOAD_ICON} <!-- ENDIF --><a class="postlink" href="{_file.U_DOWNLOAD_LINK}">{_file.DOWNLOAD_NAME}</a></dt>
<!-- IF _file.COMMENT --><dd><em>{_file.COMMENT}</em></dd><!-- ENDIF -->
<dd>{_file.DOWNLOAD_NAME} ({_file.FILESIZE} {_file.SIZE_LANG}) {_file.L_DOWNLOAD_COUNT}</dd>
<dd>
<audio controls="controls" preload="none" style="max-width:100%;width:360px">
<source src="{_file.U_DOWNLOAD_LINK}" type="{_file.MIMETYPE}">
</audio>
</dd>
</dl>
<!-- ENDIF -->
<!-- EVENT attachment_file_append --> <!-- EVENT attachment_file_append -->
<!-- ENDIF --> <!-- ENDIF -->
<!-- END _file --> <!-- END _file -->