Changeset 7890 for trunk/bp-activity/bp-activity-filters.php
- Timestamp:
- 02/16/2014 03:58:37 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-filters.php
r7397 r7890 196 196 197 197 /** 198 * Finds and links @-mentioned users in the contents of a given item. 199 * 200 * @since BuddyPress (1.2) 201 * 202 * @uses bp_activity_find_mentions() 203 * @uses bp_core_get_user_domain() 198 * Find and link @-mentioned users in the contents of a given item. 199 * 200 * @since BuddyPress (1.2.0) 204 201 * 205 202 * @param string $content The contents of a given item. … … 221 218 return $content; 222 219 220 // We don't want to link @mentions that are inside of links, so we 221 // temporarily remove them 222 $replace_count = 0; 223 $replacements = array(); 224 foreach ( $usernames as $username ) { 225 // prevent @ name linking inside <a> tags 226 preg_match_all( '/(<a.*?(?!<\/a>)@' . $username . '.*?<\/a>)/', $content, $content_matches ); 227 if ( ! empty( $content_matches[1] ) ) { 228 foreach ( $content_matches[1] as $replacement ) { 229 $replacements[ '#BPAN' . $replace_count ] = $replacement; 230 $content = str_replace( $replacement, '#BPAN' . $replace_count, $content ); 231 $replace_count++; 232 } 233 } 234 } 235 223 236 // Linkify the mentions with the username 224 foreach ( (array) $usernames as $user_id => $username ) {237 foreach ( (array) $usernames as $user_id => $username ) { 225 238 $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content ); 239 } 240 241 // put everything back 242 if ( ! empty( $replacements ) ) { 243 foreach ( $replacements as $placeholder => $original ) { 244 $content = str_replace( $placeholder, $original, $content ); 245 } 226 246 } 227 247
Note: See TracChangeset
for help on using the changeset viewer.