Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/20/2011 11:29:25 PM (13 years ago)
Author:
boonebgorges
Message:

Fixes at-mentions so that they are turned into links in contexts other than activity updates. Fixes #3363. Deprecates groups_at_mention_notification() in favor of bp_activity_at_message_notification(). Reconfigures at-mention notification so that BP notifications and email notifications are receieved for a wider variety of activity item types.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-filters.php

    r4733 r4738  
    7272add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
    7373
    74 add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
     74add_filter( 'pre_comment_content',                   'bp_activity_at_name_filter' );
     75add_filter( 'group_forum_topic_text_before_save',    'bp_activity_at_name_filter' );
     76add_filter( 'group_forum_post_text_before_save',     'bp_activity_at_name_filter' );
     77
     78add_filter( 'bp_get_activity_parent_content',        'bp_create_excerpt' );
    7579
    7680function bp_activity_filter_kses( $content ) {
     
    102106
    103107/**
    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
    107109 *
    108110 * @package BuddyPress Activity
    109111 *
    110112 * @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
    111115 */
    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 
     116function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
    118117    $usernames = bp_activity_find_mentions( $content );
    119118
     
    127126            continue;
    128127
    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        }
    131132
    132133        $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
    133134    }
    134135
    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 */
     151function 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
    137159    $activity->save();
    138160}
    139 add_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter' );
     161add_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter_updates' );
    140162
    141163function bp_activity_make_nofollow_filter( $text ) {
Note: See TracChangeset for help on using the changeset viewer.