Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/20/2011 11:29:25 PM (15 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-notifications.php

    r4638 r4738  
    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;
     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 );
    2125
    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 );
     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/';
    2728
    28                 if ( empty( $receiver_user_id ) )
    29                         continue;
     29                $poster_name = stripslashes( $poster_name );
     30                $content = bp_activity_filter_kses( strip_tags( stripslashes( $activity->content ) ) );
    3031
    31                 bp_core_add_notification( $activity_id, $receiver_user_id, 'activity', 'new_at_mention', $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 );
    3237
    33                 $subject = '';
    34                 $message = '';
     38                if ( bp_is_active( 'groups' ) && bp_is_group() ) {
     39                        $message = sprintf( __(
     40'%1$s mentioned you in the group "%2$s":
    3541
    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 );
     42"%3$s"
    3943
    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/';
     44To view and respond to the message, log in and visit: %4$s
    4245
    43                         $poster_name = stripslashes( $poster_name );
    44                         $content = bp_activity_filter_kses( stripslashes($content) );
    45 
    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 );
    51 
    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
     
    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 ) {
Note: See TracChangeset for help on using the changeset viewer.