Skip to:
Content

BuddyPress.org

Ticket #3363: 3363.diff

File 3363.diff, 15.0 KB (added by boonebgorges, 13 years ago)
  • bp-activity/bp-activity-filters.php

    add_filter( 'bp_get_activity_latest_update', 'bp_activity_make_nofollow_ 
    7171add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
    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 ) {
    7781        global $allowedtags;
    function bp_activity_filter_kses( $content ) { 
    101105}
    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
    120119        foreach( (array)$usernames as $username ) {
    function bp_activity_at_name_filter( $activity ) { 
    126125                if ( empty( $user_id ) )
    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 ) {
    142164        return preg_replace_callback( '|<a (.+?)>|i', 'bp_activity_make_nofollow_filter_callback', $text );
  • bp-activity/bp-activity-notifications.php

     
    88 * @param int $poster_user_id The unique user_id of the user who sent the update
    99 * @param int $activity_id The id of the activity update
    1010 */
    11 function bp_activity_at_message_notification( $content, $poster_user_id, $activity_id ) {
     11function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) {
    1212        global $bp;
    1313
    14         /* Scan for @username strings in an activity update. Notify each user. */
    15         $pattern = '/[@]+([A-Za-z0-9-_\.@]+)/';
    16         preg_match_all( $pattern, $content, $usernames );
     14        $activity = new BP_Activity_Activity( $activity_id );
    1715
    18         /* Make sure there's only one instance of each username */
    19         if ( !$usernames = array_unique( $usernames[1] ) )
    20                 return false;
    21 
    22         foreach( (array)$usernames as $username ) {
    23                 if ( bp_is_username_compatibility_mode() )
    24                         $receiver_user_id = bp_core_get_userid( $username );
    25                 else
    26                         $receiver_user_id = bp_core_get_userid_from_nicename( $username );
     16        $subject = '';
     17        $message = '';
     18       
     19        // Add the BP notification
     20        bp_core_add_notification( $activity_id, $receiver_user_id, 'activity', 'new_at_mention', $activity->user_id );
     21                       
     22        // Now email the user with the contents of the message (if they have enabled email notifications)
     23        if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
     24                $poster_name = bp_core_get_user_displayname( $activity->user_id );
    2725
    28                 if ( empty( $receiver_user_id ) )
    29                         continue;
     26                $message_link = bp_activity_get_permalink( $activity_id );
     27                $settings_link = bp_core_get_user_domain( $receiver_user_id ) . bp_get_settings_slug() . '/notifications/';
    3028
    31                 bp_core_add_notification( $activity_id, $receiver_user_id, 'activity', 'new_at_mention', $poster_user_id );
    32 
    33                 $subject = '';
    34                 $message = '';
     29                $poster_name = stripslashes( $poster_name );
     30                $content = bp_activity_filter_kses( strip_tags( stripslashes( $activity->content ) ) );
    3531
    36                 // Now email the user with the contents of the message (if they have enabled email notifications)
    37                 if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
    38                         $poster_name = bp_core_get_user_displayname( $poster_user_id );
     32                // Set up and send the message
     33                $ud       = bp_core_get_core_userdata( $receiver_user_id );
     34                $to       = $ud->user_email;
     35                $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
     36                $subject  = '[' . $sitename . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name );
    3937
    40                         $message_link = bp_activity_get_permalink( $activity_id );
    41                         $settings_link = bp_core_get_user_domain( $receiver_user_id ) . bp_get_settings_slug() . '/notifications/';
     38                if ( bp_is_active( 'groups' ) && bp_is_group() ) {
     39                        $message = sprintf( __(
     40'%1$s mentioned you in the group "%2$s":
    4241
    43                         $poster_name = stripslashes( $poster_name );
    44                         $content = bp_activity_filter_kses( stripslashes($content) );
     42"%3$s"
    4543
    46                         // Set up and send the message
    47                         $ud       = bp_core_get_core_userdata( $receiver_user_id );
    48                         $to       = $ud->user_email;
    49                         $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
    50                         $subject  = '[' . $sitename . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name );
     44To view and respond to the message, log in and visit: %4$s
    5145
    52 $message = sprintf( __(
     46---------------------
     47', 'buddypress' ), $poster_name, bp_get_current_group_name(), $content, $message_link );
     48                } else {
     49                        $message = sprintf( __(
    5350'%1$s mentioned you in an update:
    5451
    5552"%2$s"
    To view and respond to the message, log in and visit: %3$s 
    5855
    5956---------------------
    6057', 'buddypress' ), $poster_name, $content, $message_link );
     58                }
    6159
    62                         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     60                $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    6361
    64                         /* Send the message */
    65                         $to = apply_filters( 'bp_activity_at_message_notification_to', $to );
    66                         $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
    67                         $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
     62                /* Send the message */
     63                $to      = apply_filters( 'bp_activity_at_message_notification_to', $to );
     64                $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
     65                $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
    6866
    69                         wp_mail( $to, $subject, $message );
    70                 }
    71                
    72                 do_action( 'bp_activity_sent_mention_email', $usernames, $subject, $message, $content, $poster_user_id, $activity_id );
     67                wp_mail( $to, $subject, $message );
    7368        }
     69       
     70        do_action( 'bp_activity_sent_mention_email', $activity, $subject, $message, $content );
    7471}
    75 add_action( 'bp_activity_posted_update', 'bp_activity_at_message_notification', 10, 3 );
    7672
    7773function bp_activity_new_comment_notification( $comment_id, $commenter_id, $params ) {
    7874        global $bp;
  • bp-core/deprecated/1.3.php

    function bp_log_out_link() { 
    249249        echo apply_filters( 'bp_logout_link', $logout_link );
    250250}
    251251
     252/**
     253 * Send an email and a BP notification on receipt of an @-mention in a group
     254 *
     255 * @deprecated 1.3
     256 * @deprecated Deprecated in favor of the more general bp_activity_at_message_notification()
     257 */
     258function groups_at_message_notification( $content, $poster_user_id, $group_id, $activity_id ) {
     259        global $bp;
     260       
     261        _deprecated_function( __FUNCTION__, '1.3', 'bp_activity_at_message_notification()' );
     262
     263        /* Scan for @username strings in an activity update. Notify each user. */
     264        $pattern = '/[@]+([A-Za-z0-9-_\.@]+)/';
     265        preg_match_all( $pattern, $content, $usernames );
     266
     267        /* Make sure there's only one instance of each username */
     268        if ( !$usernames = array_unique( $usernames[1] ) )
     269                return false;
     270
     271        $group = new BP_Groups_Group( $group_id );
     272
     273        foreach( (array)$usernames as $username ) {
     274                if ( !$receiver_user_id = bp_core_get_userid( $username ) )
     275                        continue;
     276
     277                /* Check the user is a member of the group before sending the update. */
     278                if ( !groups_is_user_member( $receiver_user_id, $group_id ) )
     279                        continue;
     280
     281                // Now email the user with the contents of the message (if they have enabled email notifications)
     282                if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
     283                        $poster_name = bp_core_get_user_displayname( $poster_user_id );
     284
     285                        $message_link = bp_activity_get_permalink( $activity_id );
     286                        $settings_link = bp_core_get_user_domain( $receiver_user_id ) . bp_get_settings_slug() . '/notifications/';
     287
     288                        $poster_name = stripslashes( $poster_name );
     289                        $content = bp_groups_filter_kses( stripslashes( $content ) );
     290
     291                        // Set up and send the message
     292                        $ud = bp_core_get_core_userdata( $receiver_user_id );
     293                        $to = $ud->user_email;
     294                        $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
     295                        $subject  = '[' . $sitename . '] ' . sprintf( __( '%1$s mentioned you in the group "%2$s"', 'buddypress' ), $poster_name, $group->name );
     296
     297$message = sprintf( __(
     298'%1$s mentioned you in the group "%2$s":
     299
     300"%3$s"
     301
     302To view and respond to the message, log in and visit: %4$s
     303
     304---------------------
     305', 'buddypress' ), $poster_name, $group->name, $content, $message_link );
     306
     307                        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     308
     309                        /* Send the message */
     310                        $to = apply_filters( 'groups_at_message_notification_to', $to );
     311                        $subject = apply_filters( 'groups_at_message_notification_subject', $subject, $group, $poster_name );
     312                        $message = apply_filters( 'groups_at_message_notification_message', $message, $group, $poster_name, $content, $message_link, $settings_link );
     313
     314                        wp_mail( $to, $subject, $message );
     315                }
     316        }
     317
     318        do_action( 'bp_groups_sent_mention_email', $usernames, $subject, $message, $content, $poster_user_id, $group_id, $activity_id );
     319}
    252320
    253321/** Theme *********************************************************************/
    254322
  • bp-groups/bp-groups-notifications.php

    To view %5$s\'s profile visit: %6$s 
    249249        }
    250250}
    251251
    252 function groups_at_message_notification( $content, $poster_user_id, $group_id, $activity_id ) {
    253         global $bp;
    254 
    255         /* Scan for @username strings in an activity update. Notify each user. */
    256         $pattern = '/[@]+([A-Za-z0-9-_\.@]+)/';
    257         preg_match_all( $pattern, $content, $usernames );
    258 
    259         /* Make sure there's only one instance of each username */
    260         if ( !$usernames = array_unique( $usernames[1] ) )
    261                 return false;
    262 
    263         $group = new BP_Groups_Group( $group_id );
    264 
    265         foreach( (array)$usernames as $username ) {
    266                 if ( !$receiver_user_id = bp_core_get_userid( $username ) )
    267                         continue;
    268 
    269                 /* Check the user is a member of the group before sending the update. */
    270                 if ( !groups_is_user_member( $receiver_user_id, $group_id ) )
    271                         continue;
    272 
    273                 // Now email the user with the contents of the message (if they have enabled email notifications)
    274                 if ( 'no' != bp_get_user_meta( $user_id, 'notification_activity_new_mention', true ) ) {
    275                         $poster_name = bp_core_get_user_displayname( $poster_user_id );
    276 
    277                         $message_link = bp_activity_get_permalink( $activity_id );
    278                         $settings_link = bp_core_get_user_domain( $receiver_user_id ) . bp_get_settings_slug() . '/notifications/';
    279 
    280                         $poster_name = stripslashes( $poster_name );
    281                         $content = bp_groups_filter_kses( stripslashes( $content ) );
    282 
    283                         // Set up and send the message
    284                         $ud = bp_core_get_core_userdata( $receiver_user_id );
    285                         $to = $ud->user_email;
    286                         $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
    287                         $subject  = '[' . $sitename . '] ' . sprintf( __( '%1$s mentioned you in the group "%2$s"', 'buddypress' ), $poster_name, $group->name );
    288 
    289 $message = sprintf( __(
    290 '%1$s mentioned you in the group "%2$s":
    291 
    292 "%3$s"
    293 
    294 To view and respond to the message, log in and visit: %4$s
    295 
    296 ---------------------
    297 ', 'buddypress' ), $poster_name, $group->name, $content, $message_link );
    298 
    299                         $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    300 
    301                         /* Send the message */
    302                         $to = apply_filters( 'groups_at_message_notification_to', $to );
    303                         $subject = apply_filters( 'groups_at_message_notification_subject', $subject, $group, $poster_name );
    304                         $message = apply_filters( 'groups_at_message_notification_message', $message, $group, $poster_name, $content, $message_link, $settings_link );
    305 
    306                         wp_mail( $to, $subject, $message );
    307                 }
    308         }
    309 
    310         do_action( 'bp_groups_sent_mention_email', $usernames, $subject, $message, $content, $poster_user_id, $group_id, $activity_id );
    311 }
    312 add_action( 'bp_groups_posted_update', 'groups_at_message_notification', 10, 4 );
    313 
    314 
    315252?>