Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachment to new tab #1994

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions config_defaults_inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,13 @@
*/
$g_allow_delete_own_attachments = OFF;

/**
* Controls whether attachment links redirect users t a new tab or not
* If turned off, a click on a link will not redirect to a new tab
* @global integer $g_attachment_to_new_tab
*/
$g_attachment_to_new_tab = OFF;

####################
# Field Visibility #
####################
Expand Down Expand Up @@ -5289,6 +5296,7 @@
'antispam_max_event_count',
'antispam_time_window_in_seconds',
'assign_sponsored_bugs_threshold',
'attachment_to_new_tab',
'auto_set_status_to_assigned',
'backward_year_count',
'bottom_include_page',
Expand Down
19 changes: 15 additions & 4 deletions core/print_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1981,15 +1981,15 @@ function print_bug_attachment( array $p_attachment, $p_security_token ) {
function print_bug_attachment_header( array $p_attachment, $p_security_token ) {
if( $p_attachment['exists'] ) {
if( $p_attachment['can_download'] ) {
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '">';
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '"' . print_attachment_link_target() . '>';
}
print_file_icon( $p_attachment['display_name'] );
if( $p_attachment['can_download'] ) {
echo '</a>';
}
echo lang_get( 'word_separator' );
if( $p_attachment['can_download'] ) {
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '">';
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '"' . print_attachment_link_target() . '>';
}
echo string_display_line( $p_attachment['display_name'] );
if( $p_attachment['can_download'] ) {
Expand Down Expand Up @@ -2065,7 +2065,7 @@ function print_bug_attachment_preview_image( array $p_attachment ) {
$t_image_url = $p_attachment['download_url'] . '&show_inline=1' . form_security_param( 'file_show_inline' );

echo "\n<div class=\"bug-attachment-preview-image\">";
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '">';
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '"' . print_attachment_link_target() . '>';
echo '<img src="' . string_attribute( $t_image_url ) . '" alt="' . string_attribute( $t_title ) . '" loading="lazy" style="' . string_attribute( $t_preview_style ) . '" />';
echo '</a></div>';
}
Expand All @@ -2085,7 +2085,7 @@ function print_bug_attachment_preview_audio_video( array $p_attachment, $p_file_
$t_type = $p_attachment['type'];

echo "\n<div class=\"bug-attachment-preview-" . $t_type . "\">";
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '">';
echo '<a href="' . string_attribute( $p_attachment['download_url'] ) . '"' . print_attachment_link_target() . '>';
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 );
Expand Down Expand Up @@ -2135,6 +2135,17 @@ function get_filesize_info( $p_size, $p_unit ) {
return sprintf( lang_get( 'max_file_size_info' ), number_format( $p_size ), $p_unit );
}

/**
* Returns target attribute to be added in attachment links
* @return string
*/
function print_attachment_link_target() {
if( config_get( 'attachment_to_new_tab' ) ) {
return ' target="_blank"';
}
return ' target="_self"';
}

/**
* Print maximum file size information.
*
Expand Down