From ea4f260705f0c3dc26da0a4678abd4347775bc85 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Tue, 11 Jun 2019 10:25:35 +0200 Subject: [PATCH] Use prepare_email_link() in print_email_link_with_subject() Refactoring as part of issue #25686. --- core/print_api.php | 48 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/core/print_api.php b/core/print_api.php index 543aac5858..245944e6ec 100644 --- a/core/print_api.php +++ b/core/print_api.php @@ -1651,48 +1651,24 @@ function print_email_link( $p_email, $p_text ) { * @param string $p_text Link text to display to user. * @param string $p_tooltip The tooltip to show. * @param string $p_bug_id The bug identifier. - * @param boolean $p_show_as_text By default, show link as button with envelope icon. + * @param boolean $p_show_as_button If true, show link as button with envelope + * icon, otherwise display a plain-text link. * @return void */ -function print_email_link_with_subject( $p_email, $p_text, $p_tooltip, $p_bug_id, $p_show_as_text = false ) +function print_email_link_with_subject( $p_email, $p_text, $p_tooltip, $p_bug_id, $p_show_as_button = true ) { - if( !is_blank( $p_tooltip ) && $p_tooltip != $p_text ) { - $t_tooltip = ' title="' . $p_tooltip . '"'; - } else { - $t_tooltip = ''; - } - + global $g_project_override; $t_bug = bug_get( $p_bug_id, true ); - $t_show_user_email_threshold = config_get( 'show_user_email_threshold', null, null, $t_bug->project_id ); - if( !access_has_project_level( $t_show_user_email_threshold, $t_bug->project_id ) ) { - if( $p_show_as_text && $p_text ) { - echo $t_tooltip ? '' . $p_text . '' : $p_text; - } - return; - } - # If we apply string_url() to the whole mailto: link then the @ - # gets turned into a %40 and you can't right click in browsers to - # do Copy Email Address. If we don't apply string_url() to the - # subject text then an ampersand (for example) will truncate the text - $t_subject = string_url( email_build_subject( $p_bug_id ) ); - $t_email = string_url( $p_email ); - $t_mailto = string_attribute( 'mailto:' . $t_email . '?subject=' . $t_subject ); - $t_text = string_display( $p_text ); + $g_project_override = $t_bug->project_id; - if( $p_show_as_text ) { - $t_class = ''; - } else { - $t_class = ' class="btn btn-primary btn-white btn-round btn-xs"'; - $t_text = '' . ( $t_text ? " $t_text" : '' ); - } - - printf( '%s', - $t_mailto, - $t_tooltip, - $t_class, - $t_text - ); + echo prepare_email_link( + $p_email, + $p_text, + email_build_subject( $p_bug_id ), + $p_tooltip, + $p_show_as_button + ); } /**