Skip to:
Content

BuddyPress.org

Ticket #4680: 4680.diff

File 4680.diff, 1.7 KB (added by ninnypants, 11 years ago)
  • bp-activity/bp-activity-filters.php

    diff --git bp-activity/bp-activity-filters.php bp-activity/bp-activity-filters.php
    index 603924f..f84873f 100644
    function bp_activity_at_name_filter( $content, $activity_id = 0 ) { 
    220220        if ( empty( $usernames ) )
    221221                return $content;
    222222
     223        // hide username content inside tags
     224        $replace_count = 0;
     225        $replacements = array();
     226        foreach ( $usernames as $username ) {
     227                // prevent @ name linking in opening a tags
     228                preg_match_all( '/(<a[^>]+' . $username . '[^>]+>)/', $content, $tag_matches );
     229                if ( !empty( $tag_matches[1] ) ) {
     230                        foreach ( $tag_matches[1] as $replacement ) {
     231                                $replacements[ '#BPAN' . $replace_count ] = $replacement;
     232                                $content = str_replace( $replacement, '#BPAN' . $replace_count, $content );
     233                                $replace_count++;
     234                        }
     235                }
     236
     237                // prevent @ name linking inside a tags
     238                preg_match_all( '/(<a[^>]+>.*?(?!<\/a>)@' . $username . '.*?<\/a>)/', $content, $content_matches );
     239                if ( !empty( $content_matches[1] ) ) {
     240                        foreach ( $content_matches[1] as $replacement ) {
     241                                $replacements[ '#BPAN' . $replace_count ] = $replacement;
     242                                $content = str_replace( $replacement, '#BPAN' . $replace_count, $content );
     243                                $replace_count++;
     244                        }
     245                }
     246        }
     247
    223248        // Linkify the mentions with the username
    224249        foreach( (array) $usernames as $user_id => $username ) {
    225250                $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
    226251        }
    227252
     253        // put everything back
     254        if ( ! empty( $replacements ) ) {
     255                foreach ( $replacements as $placeholder => $original ) {
     256                        $content = str_replace( $placeholder, $original, $content );
     257                }
     258        }
     259
    228260        // Return the content
    229261        return $content;
    230262}