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-core/deprecated/1.3.php

    r4723 r4738  
    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 *********************************************************************/
Note: See TracChangeset for help on using the changeset viewer.