Skip to content

Commit

Permalink
Support inline playing of audio/video attachments
Browse files Browse the repository at this point in the history
Fixes #26095, #26102, #26096
  • Loading branch information
vboctor committed Oct 17, 2019
2 parents 8638acf + ea8963d commit 3ccb399
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 14 deletions.
4 changes: 4 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -3658,12 +3658,16 @@
'jpeg' => 'fa-file-image-o',
'log' => 'fa-file-text-o',
'lzh' => 'fa-file-archive-o',
'md' => 'fa-file-text-o',
'mhtml' => 'fa-file-code-o',
'mid' => 'fa-file-audio-o',
'midi' => 'fa-file-audio-o',
'mov' => 'fa-file-movie-o',
'mp3' => 'fa-file-audio-o',
'mp4' => 'fa-file-movie-o',
'msg' => 'fa-envelope-o',
'one' => 'fa-file-o',
'ogg' => 'fa-file-movie-o',
'patch' => 'fa-file-text-o',
'pcx' => 'fa-file-image-o',
'pdf' => 'fa-file-pdf-o',
Expand Down
18 changes: 13 additions & 5 deletions core/file_api.php
Expand Up @@ -418,13 +418,21 @@ function file_get_visible_attachments( $p_bug_id ) {
$t_ext = strtolower( pathinfo( $t_attachment['display_name'], PATHINFO_EXTENSION ) );
$t_attachment['alt'] = $t_ext;

if( $t_attachment['exists'] && $t_attachment['can_download'] && $t_filesize != 0 && $t_filesize <= config_get( 'preview_attachments_inline_max_size' ) ) {
if( in_array( $t_ext, $t_preview_text_ext, true ) ) {
$t_attachment['preview'] = true;
if( $t_attachment['exists'] && $t_attachment['can_download'] && $t_filesize != 0 ) {
$t_preview = $t_filesize <= config_get( 'preview_attachments_inline_max_size' );

if( stripos( $t_attachment['file_type'], 'text/' ) === 0 || in_array( $t_ext, $t_preview_text_ext, true ) ) {
$t_attachment['preview'] = $t_preview;
$t_attachment['type'] = 'text';
} else if( in_array( $t_ext, $t_preview_image_ext, true ) ) {
$t_attachment['preview'] = true;
} else if( stripos( $t_attachment['file_type'], 'image/' ) === 0 || in_array( $t_ext, $t_preview_image_ext, true ) ) {
$t_attachment['preview'] = $t_preview;
$t_attachment['type'] = 'image';
} else if( stripos( $t_attachment['file_type'], 'audio/' ) === 0 ) {
$t_attachment['preview'] = $t_preview;
$t_attachment['type'] = 'audio';
} else if( stripos( $t_attachment['file_type'], 'video/' ) === 0 ) {
$t_attachment['preview'] = $t_preview;
$t_attachment['type'] = 'video';
}
}

Expand Down
80 changes: 71 additions & 9 deletions core/print_api.php
Expand Up @@ -1878,10 +1878,15 @@ function print_bug_attachments_list( $p_bug_id, $p_security_token ) {
*/
function print_bug_attachment( array $p_attachment, $p_security_token ) {
echo '<div class="well well-xs">';
if( $p_attachment['preview'] ) {

if( $p_attachment['preview'] || $p_attachment['type'] === 'audio' || $p_attachment['type'] === 'video' ) {
$t_collapse_id = 'attachment_preview_' . $p_attachment['id'];
global $g_collapse_cache_token;
$g_collapse_cache_token[$t_collapse_id] = $p_attachment['type'] == 'image';
$g_collapse_cache_token[$t_collapse_id] =
$p_attachment['type'] == 'image' ||
$p_attachment['type'] == 'audio' ||
$p_attachment['type'] == 'video';

collapse_open( $t_collapse_id, '');
}

Expand All @@ -1890,17 +1895,48 @@ function print_bug_attachment( array $p_attachment, $p_security_token ) {
if( $p_attachment['preview'] ) {
echo lang_get( 'word_separator' );
collapse_icon( $t_collapse_id );
if( $p_attachment['type'] == 'text' ) {
print_bug_attachment_preview_text( $p_attachment );
} else if( $p_attachment['type'] === 'image' ) {
print_bug_attachment_preview_image( $p_attachment );

switch( $p_attachment['type'] ) {
case 'text':
print_bug_attachment_preview_text( $p_attachment );
break;
case 'image':
print_bug_attachment_preview_image( $p_attachment );
break;
case 'audio':
case 'video':
print_bug_attachment_preview_audio_video(
$p_attachment, $p_attachment['file_type'], $p_attachment['preview'] );
break;
}

collapse_closed( $t_collapse_id, '' );

print_bug_attachment_header( $p_attachment, $p_security_token );
echo lang_get( 'word_separator' );
collapse_icon( $t_collapse_id );
collapse_end( $t_collapse_id );
} else {
# Audio / Video support showing control without preloading.
if( $p_attachment['type'] === 'audio' || $p_attachment['type'] === 'video' ) {
echo lang_get( 'word_separator' );
collapse_icon( $t_collapse_id );

print_bug_attachment_preview_audio_video(
$p_attachment,
$p_attachment['file_type'],
$p_attachment['preview'] );

collapse_closed( $t_collapse_id );
print_bug_attachment_header( $p_attachment, $p_security_token );
echo lang_get( 'word_separator' );
collapse_icon( $t_collapse_id );
collapse_end( $t_collapse_id );
} else {
echo '<br />';
}
}

echo '</div>';
}

Expand All @@ -1912,7 +1948,8 @@ function print_bug_attachment( array $p_attachment, $p_security_token ) {
* a valid security token, previously generated by form_security_token().
* Use this to avoid performance issues when loading pages having many calls to
* this function, such as print_bug_attachments_list().
* @param array $p_attachment An attachment array from within the array returned by the file_get_visible_attachments() function.
* @param array $p_attachment An attachment array from within the array returned by
* the file_get_visible_attachments() function.
* @param string $p_security_token The security token to use for deleting attachments.
* @return void
*/
Expand Down Expand Up @@ -1950,7 +1987,8 @@ function print_bug_attachment_header( array $p_attachment, $p_security_token ) {

/**
* Prints the preview of a text file attachment.
* @param array $p_attachment An attachment array from within the array returned by the file_get_visible_attachments() function.
* @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_text( array $p_attachment ) {
Expand Down Expand Up @@ -1980,7 +2018,8 @@ function print_bug_attachment_preview_text( array $p_attachment ) {

/**
* Prints the preview of an image file attachment.
* @param array $p_attachment An attachment array from within the array returned by the file_get_visible_attachments() function.
* @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_image( array $p_attachment ) {
Expand All @@ -2004,6 +2043,29 @@ function print_bug_attachment_preview_image( array $p_attachment ) {
echo '</a></div>';
}

/**
* Prints the preview of an audio/video file attachment.
* @param array $p_attachment An attachment array from within the array returned by
* the file_get_visible_attachments() function.
* @param string $p_file_type mime type
* @param boolean $p_preload true to preload audio/video, false otherwise.
* @return void
*/
function print_bug_attachment_preview_audio_video( array $p_attachment, $p_file_type, $p_preload ) {
$t_file_url = $p_attachment['download_url'] . '&show_inline=1' . form_security_param( 'file_show_inline' );
$t_preload = $p_preload ? '' : ' preload="none"';

$t_type = $p_attachment['type'];

echo "\n<div class=\"bug-attachment-preview-" . $t_type . "\">";
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '">';
echo '<' . $t_type . ' controls="controls"' . $t_preload . '>';
echo '<source src="' . string_attribute( $t_file_url ) . '" type="' . string_attribute( $p_file_type ) . '">';
echo lang_get( 'browser_does_not_support_' . $t_type );
echo '</' . $t_type . '>';
echo "</a></div>";
}

/**
* Print the option list for time zones
* @param string $p_timezone Selected time zone.
Expand Down
14 changes: 14 additions & 0 deletions docbook/Admin_Guide/en-US/config/uploads.xml
Expand Up @@ -100,6 +100,20 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_preview_text_extensions</term>
<listitem>
<para>An array of file extensions (not including dots) for text files that can be previewed inline.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_preview_image_extensions</term>
<listitem>
<para>An array of file extensions (not including dots) for image files that can be previewed inline.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_fileinfo_magic_db_file</term>
<listitem>
Expand Down
2 changes: 2 additions & 0 deletions lang/strings_english.txt
Expand Up @@ -1283,6 +1283,8 @@ $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 audio tag.';
$s_browser_does_not_support_video = 'Your browser does not support video tag.';

# view_bug_page.php
$s_bug_view_title = 'View Issue Details';
Expand Down

0 comments on commit 3ccb399

Please sign in to comment.