Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support inlnie playing of audio attachments
Fixes #26095
  • Loading branch information
vboctor committed Oct 17, 2019
1 parent 6a6b83f commit 094f536
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions core/file_api.php
Expand Up @@ -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++ ) {
Expand Down Expand Up @@ -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';
}
}

Expand Down
19 changes: 19 additions & 0 deletions core/print_api.php
Expand Up @@ -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 );
Expand Down Expand Up @@ -2004,6 +2006,23 @@ function print_bug_attachment_preview_image( array $p_attachment ) {
echo '</a></div>';
}

/**
* 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<div class=\"bug-attachment-preview-audio\">";
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '">';
echo "<audio controls>";
echo "<source src=\"" . string_attribute( $t_file_url ) . "\" type=\"audio/mpeg\">";
echo lang_get( 'browser_does_not_support_audio' );
echo "</audio>";
echo "</a></div>";
}

/**
* Print the option list for time zones
* @param string $p_timezone Selected time zone.
Expand Down
7 changes: 7 additions & 0 deletions docbook/Admin_Guide/en-US/config/uploads.xml
Expand Up @@ -114,6 +114,13 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_preview_audio_extensions</term>
<listitem>
<para>An array of file extensions (not including dots) for audio files that can be played inline.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_fileinfo_magic_db_file</term>
<listitem>
Expand Down
1 change: 1 addition & 0 deletions lang/strings_english.txt
Expand Up @@ -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';
Expand Down

0 comments on commit 094f536

Please sign in to comment.