Skip to content

Commit

Permalink
Print email link as button with envelope icon
Browse files Browse the repository at this point in the history
In the View Issue Details section of view.php page, user names were
displayed with a mailto: link. This is not consistent with the way these
links are printed in other locations, where it goes to the User
Information page (view_user_page.php).

With this commit:
- username now links to view_user_page.php
- the mailto: link is available as a button next to the username

Fixes #25686
  • Loading branch information
dregad committed Jun 14, 2019
1 parent 8eeb25f commit 6a9869a
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions core/print_api.php
Expand Up @@ -220,17 +220,13 @@ function print_user_with_subject( $p_user_id, $p_bug_id ) {
return;
}

$t_username = user_get_username( $p_user_id );
$t_name = user_get_name( $p_user_id );
print_user( $p_user_id );

if( user_exists( $p_user_id ) && user_get_field( $p_user_id, 'enabled' ) ) {
if( user_exists( $p_user_id ) && user_is_enabled( $p_user_id ) ) {
$t_email = user_get_email( $p_user_id );
print_email_link_with_subject( $t_email, $t_name, $t_username, $p_bug_id );
} else {
$t_name = string_attribute( $t_name );
echo '<span style="text-decoration: line-through">';
echo '<a title="' . $t_name . '">' . $t_username . '</a>';
echo '</span>';

echo '&nbsp;';
print_email_link_with_subject( $t_email, '', '', $p_bug_id );
}
}

Expand Down Expand Up @@ -1662,37 +1658,52 @@ function get_email_link( $p_email, $p_text ) {
/**
* print a mailto: href link with subject
*
* @param string $p_email Email Address.
* @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 string $p_email Email Address.
* @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.
* @return void
*/
function print_email_link_with_subject( $p_email, $p_text, $p_tooltip, $p_bug_id ) {
function print_email_link_with_subject( $p_email, $p_text, $p_tooltip, $p_bug_id, $p_show_as_text = false )
{
if( !is_blank( $p_tooltip ) && $p_tooltip != $p_text ) {
$t_tooltip = ' title="' . $p_tooltip . '"';
} else {
$t_tooltip = '';
}

$t_bug = bug_get( $p_bug_id, true );
if( !access_has_project_level( config_get( 'show_user_email_threshold', null, null, $t_bug->project_id ), $t_bug->project_id ) ) {
echo $t_tooltip != '' ? '<a' . $t_tooltip . '>' . $p_text . '</a>' : $p_text;
$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 ? '<a' . $t_tooltip . '>' . $p_text . '</a>' : $p_text;
}
return;
}

$t_subject = email_build_subject( $p_bug_id );

# 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( $t_subject );
$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 );

echo '<a href="' . $t_mailto . '"' . $t_tooltip . '>' . $t_text . '</a>';
if( $p_show_as_text ) {
$t_class = '';
} else {
$t_class = ' class="btn btn-primary btn-white btn-round btn-xs"';
$t_text = '<i class="fa fa-envelope-o"></i>' . ( $t_text ? "&nbsp;$t_text" : '' );
}

printf( '<a href="%s"%s%s>%s</a>',
$t_mailto,
$t_tooltip,
$t_class,
$t_text
);
}

/**
Expand Down

0 comments on commit 6a9869a

Please sign in to comment.