Skip to content

Commit

Permalink
Handle tooltip and button display in prepare_email_link()
Browse files Browse the repository at this point in the history
Refactoring as part of issue #25686.
  • Loading branch information
dregad committed Jun 14, 2019
1 parent 6e2edf1 commit 6ada072
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions core/prepare_api.php
Expand Up @@ -68,21 +68,45 @@ function prepare_mailto_url ( $p_email, $p_subject = '' ) {
/**
* return an HTML link with mailto: href.
*
* @param string $p_email Email address to prepare.
* @param string $p_text Display text for the hyperlink.
* @param string $p_subject Optional e-mail subject
* If user does not have access level required to see email addresses, the
* function will only return the display text (with tooltip if provided).
*
* @param string $p_email Email address to prepare.
* @param string $p_text Display text for the hyperlink.
* @param string $p_subject Optional e-mail subject
* @param string $p_tooltip Optional tooltip to show.
* @param boolean $p_show_as_button If true, show link as button with envelope
* icon, otherwise display a plain-text link.
*
* @return string
*/
function prepare_email_link( $p_email, $p_text, $p_subject = '' ) {
function prepare_email_link( $p_email, $p_text, $p_subject = '', $p_tooltip ='', $p_show_as_button = false ) {
$t_text = string_display_line( $p_text );
if( !is_blank( $p_tooltip ) && $p_tooltip != $p_text ) {
$t_tooltip = ' title="' . string_display_line( $p_tooltip ) . '"';
} else {
$t_tooltip = '';
}

if( !access_has_project_level( config_get( 'show_user_email_threshold' ) ) ) {
return string_display_line( $p_text );
return $t_tooltip ? '<a' . $t_tooltip . '>' . $t_text . '</a>' : $t_text;
}

$t_mailto = prepare_mailto_url( $p_email, $p_subject );
$p_text = string_display_line( $p_text );

return '<a href="' . $t_mailto . '">' . $p_text . '</a>';
if( $p_show_as_button ) {
$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" : '' );
} else {
$t_class = '';
}

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

/**
Expand Down

0 comments on commit 6ada072

Please sign in to comment.