<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [2463] trunk: Fixes #1638</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2463</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-01-27 11:24:01 +0000 (Wed, 27 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fixes #1638</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivitynotificationsphp">trunk/bp-activity/bp-activity-notifications.php</a></li>
<li><a href="#trunkbpactivitybpactivitytemplatetagsphp">trunk/bp-activity/bp-activity-templatetags.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsnotificationsphp">trunk/bp-groups/bp-groups-notifications.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivitynotificationsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-notifications.php (2462 => 2463)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-notifications.php        2010-01-27 11:06:15 UTC (rev 2462)
+++ trunk/bp-activity/bp-activity-notifications.php        2010-01-27 11:24:01 UTC (rev 2463)
</span><span class="lines">@@ -20,10 +20,10 @@
</span><span class="cx">                         $poster_name = bp_core_get_user_displayname( $poster_user_id );
</span><span class="cx"> 
</span><span class="cx">                         $message_link = bp_activity_get_permalink( $activity_id );
</span><del>-                        $settings_link = bp_core_get_user_domain( $user_id ) . 'settings/notifications/';
</del><ins>+                        $settings_link = bp_core_get_user_domain( $receiver_user_id ) . 'settings/notifications/';
</ins><span class="cx"> 
</span><span class="cx">                         // Set up and send the message
</span><del>-                        $ud = get_userdata( $receiver_user_id );
</del><ins>+                        $ud = bp_core_get_core_userdata( $receiver_user_id );
</ins><span class="cx">                         $to = $ud-&gt;user_email;
</span><span class="cx">                         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), stripslashes($poster_name) );
</span><span class="cx"> 
</span><span class="lines">@@ -62,7 +62,7 @@
</span><span class="cx">                 $settings_link = bp_core_get_user_domain( $original_activity-&gt;user_id ) . 'settings/notifications/';
</span><span class="cx"> 
</span><span class="cx">                 // Set up and send the message
</span><del>-                $ud = get_userdata( $original_activity-&gt;user_id );
</del><ins>+                $ud = bp_core_get_core_userdata( $original_activity-&gt;user_id );
</ins><span class="cx">                 $to = $ud-&gt;user_email;
</span><span class="cx">                 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), stripslashes_deep( $poster_name ) );
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpactivitybpactivitytemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-templatetags.php (2462 => 2463)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-templatetags.php        2010-01-27 11:06:15 UTC (rev 2462)
+++ trunk/bp-activity/bp-activity-templatetags.php        2010-01-27 11:24:01 UTC (rev 2463)
</span><span class="lines">@@ -366,14 +366,15 @@
</span><span class="cx">         function bp_get_activity_content() {
</span><span class="cx">                 global $activities_template;
</span><span class="cx"> 
</span><del>-                if ( empty( $activities_template-&gt;activity-&gt;action ) )
-                        $content = bp_activity_content_filter( $activities_template-&gt;activity-&gt;content, $activities_template-&gt;activity-&gt;date_recorded );
-                else {
-                        $content = bp_activity_content_filter( $activities_template-&gt;activity-&gt;action, $activities_template-&gt;activity-&gt;date_recorded );
-                        $content .= $activities_template-&gt;activity-&gt;content;
-                }
</del><ins>+                /***
+                 * If you want to filter activity update content, please use
+                 * the filter 'bp_get_activity_content_body'
+                 *
+                 * This function is mainly for backwards comptibility.
+                 */
</ins><span class="cx"> 
</span><del>-                return apply_filters( 'bp_get_activity_content', $content, $activities_template-&gt;activity-&gt;component, $activities_template-&gt;activity-&gt;type );
</del><ins>+                $content = bp_get_activity_action() . bp_get_activity_content_body();
+                return apply_filters( 'bp_get_activity_content', $content );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> function bp_activity_content_filter( $content, $date_recorded ) {
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsnotificationsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-notifications.php (2462 => 2463)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-notifications.php        2010-01-27 11:06:15 UTC (rev 2462)
+++ trunk/bp-groups/bp-groups-notifications.php        2010-01-27 11:24:01 UTC (rev 2463)
</span><span class="lines">@@ -9,7 +9,7 @@
</span><span class="cx">         foreach ( $group-&gt;user_dataset as $user ) {
</span><span class="cx">                 if ( 'no' == get_usermeta( $user-&gt;user_id, 'notification_groups_group_updated' ) ) continue;
</span><span class="cx"> 
</span><del>-                $ud = get_userdata( $user-&gt;user_id );
</del><ins>+                $ud = bp_core_get_core_userdata( $user-&gt;user_id );
</ins><span class="cx"> 
</span><span class="cx">                 // Set up and send the message
</span><span class="cx">                 $to = $ud-&gt;user_email;
</span><span class="lines">@@ -45,8 +45,8 @@
</span><span class="cx">         $requesting_user_name = bp_core_get_user_displayname( $requesting_user_id );
</span><span class="cx">         $group = new BP_Groups_Group( $group_id, false, false );
</span><span class="cx"> 
</span><del>-        $ud = get_userdata($admin_id);
-        $requesting_ud = get_userdata($requesting_user_id);
</del><ins>+        $ud = bp_core_get_core_userdata($admin_id);
+        $requesting_ud = bp_core_get_core_userdata($requesting_user_id);
</ins><span class="cx"> 
</span><span class="cx">         $group_requests = bp_get_group_permalink( $group ) . 'admin/membership-requests';
</span><span class="cx">         $profile_link = bp_core_get_user_domain( $requesting_user_id );
</span><span class="lines">@@ -89,7 +89,7 @@
</span><span class="cx"> 
</span><span class="cx">         $group = new BP_Groups_Group( $group_id, false, false );
</span><span class="cx"> 
</span><del>-        $ud = get_userdata($requesting_user_id);
</del><ins>+        $ud = bp_core_get_core_userdata($requesting_user_id);
</ins><span class="cx"> 
</span><span class="cx">         $group_link = bp_get_group_permalink( $group );
</span><span class="cx">         $settings_link = bp_core_get_user_domain( $requesting_user_id ) . 'settings/notifications/';
</span><span class="lines">@@ -142,7 +142,7 @@
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         $group = new BP_Groups_Group( $group_id, false, false );
</span><del>-        $ud = get_userdata($user_id);
</del><ins>+        $ud = bp_core_get_core_userdata($user_id);
</ins><span class="cx"> 
</span><span class="cx">         $group_link = bp_get_group_permalink( $group );
</span><span class="cx">         $settings_link = bp_core_get_user_domain( $user_id ) . 'settings/notifications/';
</span><span class="lines">@@ -170,7 +170,7 @@
</span><span class="cx"> function groups_notification_group_invites( &amp;$group, &amp;$member, $inviter_user_id ) {
</span><span class="cx">         global $bp;
</span><span class="cx"> 
</span><del>-        $inviter_ud = get_userdata( $inviter_user_id );
</del><ins>+        $inviter_ud = bp_core_get_core_userdata( $inviter_user_id );
</ins><span class="cx">         $inviter_name = bp_core_get_userlink( $inviter_user_id, true, false, true );
</span><span class="cx">         $inviter_link = bp_core_get_user_domain( $inviter_user_id );
</span><span class="cx"> 
</span><span class="lines">@@ -185,7 +185,7 @@
</span><span class="cx">                 if ( 'no' == get_usermeta( $invited_user_id, 'notification_groups_invite' ) )
</span><span class="cx">                         return false;
</span><span class="cx"> 
</span><del>-                $invited_ud = get_userdata($invited_user_id);
</del><ins>+                $invited_ud = bp_core_get_core_userdata($invited_user_id);
</ins><span class="cx"> 
</span><span class="cx">                 $settings_link = bp_core_get_user_domain( $invited_user_id ) . 'settings/notifications/';
</span><span class="cx">                 $invited_link = bp_core_get_user_domain( $invited_user_id );
</span><span class="lines">@@ -215,4 +215,57 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function groups_at_message_notification( $content, $poster_user_id, $group_id, $activity_id ) {
+        global $bp;
+
+        /* Scan for @username strings in an activity update. Notify each user. */
+        $pattern = '/[@]+([A-Za-z0-9-_]+)/';
+        preg_match_all( $pattern, $content, $usernames );
+
+        /* Make sure there's only one instance of each username */
+        if ( !$usernames = array_unique( $usernames[1] ) )
+                return false;
+
+        $group = new BP_Groups_Group( $group_id, false, false );
+
+        foreach( (array)$usernames as $username ) {
+                if ( !$receiver_user_id = bp_core_get_userid($username) )
+                        continue;
+
+                /* Check the user is a member of the group before sending the update. */
+                if ( !groups_is_user_member( $receiver_user_id, $group_id ) )
+                        continue;
+
+                // Now email the user with the contents of the message (if they have enabled email notifications)
+                if ( !get_usermeta( $user_id, 'notification_activity_new_mention' ) || 'yes' == get_usermeta( $user_id, 'notification_activity_new_mention' ) ) {
+                        $poster_name = bp_core_get_user_displayname( $poster_user_id );
+
+                        $message_link = bp_activity_get_permalink( $activity_id );
+                        $settings_link = bp_core_get_user_domain( $receiver_user_id ) . 'settings/notifications/';
+
+                        // Set up and send the message
+                        $ud = bp_core_get_core_userdata( $receiver_user_id );
+                        $to = $ud-&gt;user_email;
+                        $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in the group &quot;%s&quot;', 'buddypress' ), stripslashes( $poster_name ), wp_filter_kses( stripslashes( $group-&gt;name ) ) );
+
+$message = sprintf( __(
+'%s mentioned you in the group &quot;%s&quot;:
+
+&quot;%s&quot;
+
+To view and respond to the message, log in and visit: %s
+
+---------------------
+', 'buddypress' ), $poster_name, wp_filter_kses( stripslashes( $group-&gt;name ) ), wp_filter_kses( stripslashes($content) ), $message_link );
+
+                        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
+
+                        // Send it
+                        wp_mail( $to, $subject, $message );
+                }
+        }
+}
+add_action( 'bp_groups_posted_update', 'groups_at_message_notification', 10, 4 );
+
+
</ins><span class="cx"> ?&gt;
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (2462 => 2463)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2010-01-27 11:06:15 UTC (rev 2462)
+++ trunk/bp-groups.php        2010-01-27 11:24:01 UTC (rev 2463)
</span><span class="lines">@@ -1364,7 +1364,7 @@
</span><span class="cx">                                 return apply_filters( 'bp_groups_multiple_new_membership_requests_notification', '&lt;a href=&quot;' . $group_link . '/admin/membership-requests/?n=1&quot; title=&quot;' . __( 'Group Membership Requests', 'buddypress' ) . '&quot;&gt;' . sprintf( __('%d new membership requests for the group &quot;%s&quot;', 'buddypress' ), (int)$total_items, $group-&gt;name ) . '&lt;/a&gt;', $group_link, $total_items, $group-&gt;name );
</span><span class="cx">                         } else {
</span><span class="cx">                                 $user_fullname = bp_core_get_user_displayname( $requesting_user_id );
</span><del>-                                return apply_filters( 'bp_groups_single_new_membership_request_notification', '&lt;a href=&quot;' . $group_link . '/admin/membership-requests/?n=1&quot; title=&quot;' . $user_fullname .' requests group membership&quot;&gt;' . sprintf( __('%s requests membership for the group &quot;%s&quot;', 'buddypress' ), $user_fullname, $group-&gt;name ) . '&lt;/a&gt;', $group_link, $user_fullname, $group-&gt;name );
</del><ins>+                                return apply_filters( 'bp_groups_single_new_membership_request_notification', '&lt;a href=&quot;' . $group_link . 'admin/membership-requests/?n=1&quot; title=&quot;' . $user_fullname .' requests group membership&quot;&gt;' . sprintf( __('%s requests membership for the group &quot;%s&quot;', 'buddypress' ), $user_fullname, $group-&gt;name ) . '&lt;/a&gt;', $group_link, $user_fullname, $group-&gt;name );
</ins><span class="cx">                         }
</span><span class="cx">                 break;
</span><span class="cx"> 
</span><span class="lines">@@ -1377,7 +1377,7 @@
</span><span class="cx">                         if ( (int)$total_items &gt; 1 ) {
</span><span class="cx">                                 return apply_filters( 'bp_groups_multiple_membership_request_accepted_notification', '&lt;a href=&quot;' . $bp-&gt;loggedin_user-&gt;domain . $bp-&gt;groups-&gt;slug . '/?n=1&quot; title=&quot;' . __( 'Groups', 'buddypress' ) . '&quot;&gt;' . sprintf( __('%d accepted group membership requests', 'buddypress' ), (int)$total_items, $group-&gt;name ) . '&lt;/a&gt;', $total_items, $group_name );
</span><span class="cx">                         } else {
</span><del>-                                return apply_filters( 'bp_groups_single_membership_request_accepted_notification', '&lt;a href=&quot;' . $group_link . '/?n=1&quot;&gt;' . sprintf( __('Membership for group &quot;%s&quot; accepted'), $group-&gt;name ) . '&lt;/a&gt;', $group_link, $group-&gt;name );
</del><ins>+                                return apply_filters( 'bp_groups_single_membership_request_accepted_notification', '&lt;a href=&quot;' . $group_link . '?n=1&quot;&gt;' . sprintf( __('Membership for group &quot;%s&quot; accepted'), $group-&gt;name ) . '&lt;/a&gt;', $group_link, $group-&gt;name );
</ins><span class="cx">                         }
</span><span class="cx">                 break;
</span><span class="cx"> 
</span><span class="lines">@@ -1390,7 +1390,7 @@
</span><span class="cx">                         if ( (int)$total_items &gt; 1 ) {
</span><span class="cx">                                 return apply_filters( 'bp_groups_multiple_membership_request_rejected_notification', '&lt;a href=&quot;' . site_url() . '/' . BP_MEMBERS_SLUG . '/' . $bp-&gt;groups-&gt;slug . '/?n=1&quot; title=&quot;' . __( 'Groups', 'buddypress' ) . '&quot;&gt;' . sprintf( __('%d rejected group membership requests', 'buddypress' ), (int)$total_items, $group-&gt;name ) . '&lt;/a&gt;', $total_items, $group-&gt;name );
</span><span class="cx">                         } else {
</span><del>-                                return apply_filters( 'bp_groups_single_membership_request_rejected_notification', '&lt;a href=&quot;' . $group_link . '/?n=1&quot;&gt;' . sprintf( __('Membership for group &quot;%s&quot; rejected'), $group-&gt;name ) . '&lt;/a&gt;', $group_link, $group-&gt;name );
</del><ins>+                                return apply_filters( 'bp_groups_single_membership_request_rejected_notification', '&lt;a href=&quot;' . $group_link . '?n=1&quot;&gt;' . sprintf( __('Membership for group &quot;%s&quot; rejected'), $group-&gt;name ) . '&lt;/a&gt;', $group_link, $group-&gt;name );
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                 break;
</span><span class="lines">@@ -1404,7 +1404,7 @@
</span><span class="cx">                         if ( (int)$total_items &gt; 1 ) {
</span><span class="cx">                                 return apply_filters( 'bp_groups_multiple_member_promoted_to_admin_notification', '&lt;a href=&quot;' . $bp-&gt;loggedin_user-&gt;domain . $bp-&gt;groups-&gt;slug . '/?n=1&quot; title=&quot;' . __( 'Groups', 'buddypress' ) . '&quot;&gt;' . sprintf( __('You were promoted to an admin in %d groups', 'buddypress' ), (int)$total_items ) . '&lt;/a&gt;', $total_items );
</span><span class="cx">                         } else {
</span><del>-                                return apply_filters( 'bp_groups_single_member_promoted_to_admin_notification', '&lt;a href=&quot;' . $group_link . '/?n=1&quot;&gt;' . sprintf( __('You were promoted to an admin in the group %s'), $group-&gt;name ) . '&lt;/a&gt;', $group_link, $group-&gt;name );
</del><ins>+                                return apply_filters( 'bp_groups_single_member_promoted_to_admin_notification', '&lt;a href=&quot;' . $group_link . '?n=1&quot;&gt;' . sprintf( __('You were promoted to an admin in the group %s'), $group-&gt;name ) . '&lt;/a&gt;', $group_link, $group-&gt;name );
</ins><span class="cx">                         }
</span><span class="cx">                 break;
</span><span class="cx"> 
</span><span class="lines">@@ -1417,7 +1417,7 @@
</span><span class="cx">                         if ( (int)$total_items &gt; 1 ) {
</span><span class="cx">                                 return apply_filters( 'bp_groups_multiple_member_promoted_to_mod_notification', '&lt;a href=&quot;' . $bp-&gt;loggedin_user-&gt;domain . $bp-&gt;groups-&gt;slug . '/?n=1&quot; title=&quot;' . __( 'Groups', 'buddypress' ) . '&quot;&gt;' . sprintf( __('You were promoted to a mod in %d groups', 'buddypress' ), (int)$total_items ) . '&lt;/a&gt;', $total_items );
</span><span class="cx">                         } else {
</span><del>-                                return apply_filters( 'bp_groups_single_member_promoted_to_mod_notification', '&lt;a href=&quot;' . $group_link . '/?n=1&quot;&gt;' . sprintf( __('You were promoted to a mod in the group %s'), $group-&gt;name ) . '&lt;/a&gt;', $group_link, $group-&gt;name );
</del><ins>+                                return apply_filters( 'bp_groups_single_member_promoted_to_mod_notification', '&lt;a href=&quot;' . $group_link . '?n=1&quot;&gt;' . sprintf( __('You were promoted to a mod in the group %s'), $group-&gt;name ) . '&lt;/a&gt;', $group_link, $group-&gt;name );
</ins><span class="cx">                         }
</span><span class="cx">                 break;
</span><span class="cx"> 
</span><span class="lines">@@ -1907,6 +1907,9 @@
</span><span class="cx">                 'item_id' =&gt; $bp-&gt;groups-&gt;current_group-&gt;id
</span><span class="cx">         ) );
</span><span class="cx"> 
</span><ins>+         /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
+        require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' );
+
</ins><span class="cx">         do_action( 'bp_groups_posted_update', $content, $user_id, $group_id, $activity_id );
</span><span class="cx"> 
</span><span class="cx">         return $activity_id;
</span></span></pre>
</div>
</div>

</body>
</html>