Changeset 4738 for trunk/bp-activity/bp-activity-filters.php
- Timestamp:
- 07/20/2011 11:29:25 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-filters.php
r4733 r4738 72 72 add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' ); 73 73 74 add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' ); 74 add_filter( 'pre_comment_content', 'bp_activity_at_name_filter' ); 75 add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_name_filter' ); 76 add_filter( 'group_forum_post_text_before_save', 'bp_activity_at_name_filter' ); 77 78 add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' ); 75 79 76 80 function bp_activity_filter_kses( $content ) { … … 102 106 103 107 /** 104 * bp_activity_at_name_filter() 105 * 106 * Finds and links @-mentioned users in activity updates 108 * Finds and links @-mentioned users in the contents of activity items 107 109 * 108 110 * @package BuddyPress Activity 109 111 * 110 112 * @param string $content The activity content 113 * @param int $activity_id When $adjust_mention_count is true, you must provide an $activity_id, 114 * which will be added to the list of the user's unread mentions 111 115 */ 112 function bp_activity_at_name_filter( $activity ) { 113 // Only run this function once for a given activity item 114 remove_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter' ); 115 116 $content = $activity->content; 117 116 function bp_activity_at_name_filter( $content, $activity_id = 0 ) { 118 117 $usernames = bp_activity_find_mentions( $content ); 119 118 … … 127 126 continue; 128 127 129 // Increase the number of new @ mentions for the user 130 bp_activity_adjust_mention_count( $activity->id, 'add' ); 128 // If an activity_id is provided, we can send email and BP notifications 129 if ( $activity_id ) { 130 bp_activity_at_message_notification( $activity_id, $user_id ); 131 } 131 132 132 133 $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content ); 133 134 } 134 135 135 // Resave the activity item with the linked usernames 136 $activity->content = $content; 136 // Adjust the activity count for this item 137 if ( $activity_id ) 138 bp_activity_adjust_mention_count( $activity_id, 'add' ); 139 140 return $content; 141 } 142 143 /** 144 * Catch mentions in saved activity items 145 * 146 * @package BuddyPress 147 * @since 1.3 148 * 149 * @param obj $activity 150 */ 151 function bp_activity_at_name_filter_updates( $activity ) { 152 // Only run this function once for a given activity item 153 remove_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter_updates' ); 154 155 // Run the content through the linking filter, making sure to increment mention count 156 $activity->content = bp_activity_at_name_filter( $activity->content, $activity->id ); 157 158 // Resave the activity with the new content 137 159 $activity->save(); 138 160 } 139 add_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter ' );161 add_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter_updates' ); 140 162 141 163 function bp_activity_make_nofollow_filter( $text ) {
Note: See TracChangeset
for help on using the changeset viewer.