From 094f536ab8c5d5e4094692aebf0a16ccab881566 Mon Sep 17 00:00:00 2001 From: Victor Boctor Date: Wed, 28 Aug 2019 18:32:26 -0700 Subject: [PATCH] Support inlnie playing of audio attachments Fixes #26095 --- config_defaults_inc.php | 9 +++++++++ core/file_api.php | 4 ++++ core/print_api.php | 19 +++++++++++++++++++ docbook/Admin_Guide/en-US/config/uploads.xml | 7 +++++++ lang/strings_english.txt | 1 + 5 files changed, 40 insertions(+) diff --git a/config_defaults_inc.php b/config_defaults_inc.php index a6c839a3c4..0249694435 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -2307,6 +2307,14 @@ 'bmp', 'png', 'gif', 'jpg', 'jpeg' ); +/** + * Extensions for audio files that can be played inline. + * @global array $g_preview_audio_extensions + */ +$g_preview_audio_extensions = array( + 'mp3', 'wav', 'ogg' +); + /** * Specifies the maximum width for the auto-preview feature. If no maximum * width should be imposed then it should be set to 0. @@ -4593,6 +4601,7 @@ 'plugins_enabled', 'plugins_force_installed', 'preview_attachments_inline_max_size', + 'preview_audio_extensions', 'preview_image_extensions', 'preview_max_height', 'preview_max_width', diff --git a/core/file_api.php b/core/file_api.php index 3ba6565a32..3dcdf21d43 100644 --- a/core/file_api.php +++ b/core/file_api.php @@ -372,6 +372,7 @@ function file_get_visible_attachments( $p_bug_id ) { $t_preview_text_ext = config_get( 'preview_text_extensions' ); $t_preview_image_ext = config_get( 'preview_image_extensions' ); + $t_preview_audio_ext = config_get( 'preview_audio_extensions' ); $t_image_previewed = false; for( $i = 0;$i < $t_attachments_count;$i++ ) { @@ -425,6 +426,9 @@ function file_get_visible_attachments( $p_bug_id ) { } else if( in_array( $t_ext, $t_preview_image_ext, true ) ) { $t_attachment['preview'] = true; $t_attachment['type'] = 'image'; + } else if( in_array( $t_ext, $t_preview_audio_ext, true ) ) { + $t_attachment['preview'] = true; + $t_attachment['type'] = 'audio'; } } diff --git a/core/print_api.php b/core/print_api.php index acb087984f..f1989cf870 100644 --- a/core/print_api.php +++ b/core/print_api.php @@ -1894,6 +1894,8 @@ function print_bug_attachment( array $p_attachment, $p_security_token ) { print_bug_attachment_preview_text( $p_attachment ); } else if( $p_attachment['type'] === 'image' ) { print_bug_attachment_preview_image( $p_attachment ); + } else if( $p_attachment['type'] === 'audio' ) { + print_bug_attachment_preview_audio( $p_attachment ); } collapse_closed( $t_collapse_id, '' ); print_bug_attachment_header( $p_attachment, $p_security_token ); @@ -2004,6 +2006,23 @@ function print_bug_attachment_preview_image( array $p_attachment ) { echo ''; } +/** + * Prints the preview of an audio file attachment. + * @param array $p_attachment An attachment array from within the array returned by the file_get_visible_attachments() function. + * @return void + */ +function print_bug_attachment_preview_audio( array $p_attachment ) { + $t_file_url = $p_attachment['download_url'] . '&show_inline=1' . form_security_param( 'file_show_inline' ); + + echo "\n
"; + echo ''; + echo ""; + echo "
"; +} + /** * Print the option list for time zones * @param string $p_timezone Selected time zone. diff --git a/docbook/Admin_Guide/en-US/config/uploads.xml b/docbook/Admin_Guide/en-US/config/uploads.xml index 0aef29a2c4..7fc5132ca7 100644 --- a/docbook/Admin_Guide/en-US/config/uploads.xml +++ b/docbook/Admin_Guide/en-US/config/uploads.xml @@ -114,6 +114,13 @@ + + $g_preview_audio_extensions + + An array of file extensions (not including dots) for audio files that can be played inline. + + + $g_fileinfo_magic_db_file diff --git a/lang/strings_english.txt b/lang/strings_english.txt index 05d206e362..9c51a3b679 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -1283,6 +1283,7 @@ $s_move_bug_button = 'Move'; $s_attached_files = 'Attached Files'; $s_publish = 'Publish'; $s_add_user_to_monitor = 'Add'; +$s_browser_does_not_support_audio = 'Your browser does not support playing audio files of this format.'; # view_bug_page.php $s_bug_view_title = 'View Issue Details';