Skip to content

Commit

Permalink
Applied misc PR review comments from @atrol
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Apr 28, 2016
1 parent b1576be commit cf44da0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
2 changes: 2 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -4454,6 +4454,8 @@
'max_failed_login_count',
'max_file_size',
'max_lost_password_in_progress_count',
'mentions_enabled',
'mentions_tag',
'meta_include_file',
'min_refresh_delay',
'minimum_sponsorship_amount',
Expand Down
10 changes: 4 additions & 6 deletions core/bugnote_api.php
Expand Up @@ -194,27 +194,25 @@ function bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking = '0:00', $p_

antispam_check();

$t_bugnote_text = $p_bugnote_text;

if( REMINDER !== $p_type ) {
# Check if this is a time-tracking note
$t_time_tracking_enabled = config_get( 'time_tracking_enabled' );
if( ON == $t_time_tracking_enabled && $c_time_tracking > 0 ) {
$t_time_tracking_without_note = config_get( 'time_tracking_without_note' );
if( is_blank( $t_bugnote_text ) && OFF == $t_time_tracking_without_note ) {
if( is_blank( $p_bugnote_text ) && OFF == $t_time_tracking_without_note ) {
error_parameters( lang_get( 'bugnote' ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}
$c_type = TIME_TRACKING;
} else if( is_blank( $t_bugnote_text ) ) {
} else if( is_blank( $p_bugnote_text ) ) {
# This is not time tracking (i.e. it's a normal bugnote)
# @todo should we not trigger an error in this case ?
return false;
}
}

# Event integration
$t_bugnote_text = event_signal( 'EVENT_BUGNOTE_DATA', $t_bugnote_text, $c_bug_id );
$t_bugnote_text = event_signal( 'EVENT_BUGNOTE_DATA', $p_bugnote_text, $c_bug_id );

# insert bugnote text
$t_query = 'INSERT INTO {bugnote_text} ( note ) VALUES ( ' . db_param() . ' )';
Expand Down Expand Up @@ -273,7 +271,7 @@ function bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking = '0:00', $p_
mention_process_user_mentions(
$p_bug_id,
$t_filtered_mentioned_user_ids,
$p_bugnote_text,
$t_bugnote_text,
$t_removed_mentions_user_ids );

# Event integration
Expand Down
4 changes: 2 additions & 2 deletions core/email_api.php
Expand Up @@ -1326,8 +1326,8 @@ function email_user_mention( $p_bug_id, $p_mention_user_ids, $p_message, $p_remo
$t_user_id = auth_get_current_user_id();
$t_users_processed = array();

foreach( $p_removed_mention_user_ids as $t_remove_mention_user_id ) {
log_event( LOG_EMAIL_VERBOSE, 'skipped mention email for U' . $t_mention_user_id . ' (no access to issue or note).' );
foreach( $p_removed_mention_user_ids as $t_removed_mention_user_id ) {
log_event( LOG_EMAIL_VERBOSE, 'skipped mention email for U' . $t_removed_mention_user_id . ' (no access to issue or note).' );
}

$t_result = array();
Expand Down
49 changes: 23 additions & 26 deletions core/mention_api.php
Expand Up @@ -86,7 +86,7 @@ function mention_get_candidates( $p_text ) {
* feature is disabled.
*
* @param string $p_text The text to process.
* @return Array with valid usernames as keys and their ids as values.
* @return array with valid usernames as keys and their ids as values.
*/
function mention_get_users( $p_text ) {
if ( !mention_enabled() ) {
Expand Down Expand Up @@ -119,10 +119,11 @@ function mention_get_users( $p_text ) {
* @param int $p_bug_id The bug id.
* @param array $p_mentioned_user_ids An array of user ids
* @param string $p_message The message containing the mentions.
* @param array $p_removed_mentions_user_ids The list of ids removed due to lack of access to issue or note.
* @return void
*/
function mention_process_user_mentions( $p_bug_id, $p_mentioned_user_ids, $p_message = '' ) {
email_user_mention( $p_bug_id, $p_mentioned_user_ids, $p_message );
function mention_process_user_mentions( $p_bug_id, $p_mentioned_user_ids, $p_message, $p_removed_mentions_user_ids ) {
email_user_mention( $p_bug_id, $p_mentioned_user_ids, $p_message, $p_removed_mentions_user_ids );
}

/**
Expand All @@ -137,8 +138,6 @@ function mention_format_text( $p_text, $p_html = true ) {
return $p_text;
}

$t_text = $p_text;

$t_mentioned_users = mention_get_users( $p_text );
if( empty( $t_mentioned_users ) ) {
return $p_text;
Expand All @@ -148,29 +147,27 @@ function mention_format_text( $p_text, $p_html = true ) {
$t_formatted_mentions = array();

foreach( $t_mentioned_users as $t_username => $t_user_id ) {
if( user_exists( $t_user_id ) ) {
$t_mention = $t_mentions_tag . $t_username;

# Uncomment the line below to use realname / username based on settings
# The reason we always use username is to avoid confusing users by showing
# @ mentions using realname but only supporting it using usernames.
# We could support realnames if we assume they contain no spaces, but that
# is unlikely to be the case.
# $t_username = user_get_name( $t_user_id );

if( $p_html ) {
$t_username = string_display_line( $t_username );

if( user_exists( $t_user_id ) && user_get_field( $t_user_id, 'enabled' ) ) {
$t_user_url = '<a class="user" href="' . string_sanitize_url( 'view_user_page.php?id=' . $t_user_id, true ) . '">' . $t_mentions_tag . $t_username . '</a>';
} else {
$t_user_url = '<del class="user">' . $t_mentions_tag . $t_username . '</del>';
}

$t_formatted_mentions[$t_mention] = '<span class="mention">' . $t_user_url . '</span>';
$t_mention = $t_mentions_tag . $t_username;

# Uncomment the line below to use realname / username based on settings
# The reason we always use username is to avoid confusing users by showing
# @ mentions using realname but only supporting it using usernames.
# We could support realnames if we assume they contain no spaces, but that
# is unlikely to be the case.
# $t_username = user_get_name( $t_user_id );

if( $p_html ) {
$t_username = string_display_line( $t_username );

if( user_exists( $t_user_id ) && user_get_field( $t_user_id, 'enabled' ) ) {
$t_user_url = '<a class="user" href="' . string_sanitize_url( 'view_user_page.php?id=' . $t_user_id, true ) . '">' . $t_mentions_tag . $t_username . '</a>';
} else {
$t_formatted_mentions[$t_mention] = $t_mentions_tag . $t_username;
$t_user_url = '<del class="user">' . $t_mentions_tag . $t_username . '</del>';
}

$t_formatted_mentions[$t_mention] = '<span class="mention">' . $t_user_url . '</span>';
} else {
$t_formatted_mentions[$t_mention] = $t_mentions_tag . $t_username;
}
}

Expand Down

0 comments on commit cf44da0

Please sign in to comment.