Skip to:
Content

bbPress.org

Changeset 6380


Ignore:
Timestamp:
03/17/2017 05:55:58 PM (5 years ago)
Author:
johnjamesjacoby
Message:

Mentions: Balance tags before making things clickable.

Then, make mentions clickable without "requiring" prepending whitespace. This allows other types of characters to be immediately before the @ control character.

See #2963.

Location:
trunk/src/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/formatting.php

    r6347 r6380  
    460460 */
    461461function bbp_make_mentions_clickable( $text = '' ) {
    462     return preg_replace_callback( '#([\s>])@([0-9a-zA-Z-_]+)#i', 'bbp_make_mentions_clickable_callback', $text );
     462    return preg_replace_callback( '#@([0-9a-zA-Z-_]+)#i', 'bbp_make_mentions_clickable_callback', $text );
    463463}
    464464
     
    468468 * @since 2.6.0 (r6014)
    469469 *
    470  * @param array $matches Single Regex Match.
    471  *
    472  * @return string HTML A tag with link to user profile.
     470 * @param array $matches Regular expression matches in the current text blob.
     471 *
     472 * @return string Original text if no user exists, or link to user profile.
    473473 */
    474474function bbp_make_mentions_clickable_callback( $matches = array() ) {
    475475
    476476    // Get user; bail if not found
    477     $user = get_user_by( 'slug', $matches[2] );
     477    $user = get_user_by( 'slug', $matches[1] );
    478478    if ( empty( $user ) || bbp_is_user_inactive( $user->ID ) ) {
    479479        return $matches[0];
     
    488488    // Escape & implode if not empty, otherwise an empty string
    489489    $class_str = ! empty( $classes )
    490         ? implode( ' ', array_map( 'esc_attr', $classes ) )
     490        ? implode( ' ', array_map( 'sanitize_html_class', $classes ) )
    491491        : '';
    492492
    493493    // Create the link to the user's profile
    494494    $url    = bbp_get_user_profile_url( $user->ID );
    495     $clicky = '<a href="%1$s" class="' . $class_str . '">@%2$s</a>';
    496     $anchor = sprintf( $clicky, esc_url( $url ), esc_html( $user->user_nicename ) );
     495    $clicky = '<a href="%1$s" class="' . esc_attr( $class_str ) . '">%2$s</a>';
     496    $anchor = sprintf( $clicky, esc_url( $url ), esc_html( $matches[0] ) );
    497497    $link   = bbp_rel_nofollow( $anchor );
    498498
    499     return $matches[1] . $link;
     499    return $link;
    500500}
    501501
  • trunk/src/includes/core/filters.php

    r6338 r6380  
    144144
    145145// Run filters on reply content
    146 add_filter( 'bbp_get_reply_content', 'bbp_make_clickable', 4    );
    147 add_filter( 'bbp_get_reply_content', 'wptexturize',        6    );
    148 add_filter( 'bbp_get_reply_content', 'convert_chars',      8    );
    149 add_filter( 'bbp_get_reply_content', 'capital_P_dangit',   10  );
    150 add_filter( 'bbp_get_reply_content', 'convert_smilies',    20  );
    151 add_filter( 'bbp_get_reply_content', 'force_balance_tags', 30  );
    152 add_filter( 'bbp_get_reply_content', 'wpautop',            40  );
    153 add_filter( 'bbp_get_reply_content', 'bbp_rel_nofollow',   50  );
     146add_filter( 'bbp_get_reply_content', 'wptexturize',        6  );
     147add_filter( 'bbp_get_reply_content', 'convert_chars',      8  );
     148add_filter( 'bbp_get_reply_content', 'capital_P_dangit',   10 );
     149add_filter( 'bbp_get_reply_content', 'convert_smilies',    20 );
     150add_filter( 'bbp_get_reply_content', 'force_balance_tags', 30 );
     151add_filter( 'bbp_get_reply_content', 'bbp_make_clickable', 40 );
     152add_filter( 'bbp_get_reply_content', 'wpautop',            50 );
     153add_filter( 'bbp_get_reply_content', 'bbp_rel_nofollow',   60 );
    154154
    155155// Run filters on topic content
    156 add_filter( 'bbp_get_topic_content', 'bbp_make_clickable', 4    );
    157 add_filter( 'bbp_get_topic_content', 'wptexturize',        6    );
    158 add_filter( 'bbp_get_topic_content', 'convert_chars',      8    );
    159 add_filter( 'bbp_get_topic_content', 'capital_P_dangit',   10  );
    160 add_filter( 'bbp_get_topic_content', 'convert_smilies',    20  );
    161 add_filter( 'bbp_get_topic_content', 'force_balance_tags', 30  );
    162 add_filter( 'bbp_get_topic_content', 'wpautop',            40  );
    163 add_filter( 'bbp_get_topic_content', 'bbp_rel_nofollow',   50  );
     156add_filter( 'bbp_get_topic_content', 'wptexturize',        6  );
     157add_filter( 'bbp_get_topic_content', 'convert_chars',      8  );
     158add_filter( 'bbp_get_topic_content', 'capital_P_dangit',   10 );
     159add_filter( 'bbp_get_topic_content', 'convert_smilies',    20 );
     160add_filter( 'bbp_get_topic_content', 'force_balance_tags', 30 );
     161add_filter( 'bbp_get_topic_content', 'bbp_make_clickable', 40 );
     162add_filter( 'bbp_get_topic_content', 'wpautop',            50 );
     163add_filter( 'bbp_get_topic_content', 'bbp_rel_nofollow',   60 );
    164164
    165165// Form textarea output - undo the code-trick done pre-save, and sanitize
Note: See TracChangeset for help on using the changeset viewer.