Ticket #5395: 5395.patch
| File 5395.patch, 12.6 KB (added by , 12 years ago) |
|---|
-
bp-activity/bp-activity-functions.php
diff --git bp-activity/bp-activity-functions.php bp-activity/bp-activity-functions.php index 6cbf3b4..9e3d1fe 100644
function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 1549 1549 } 1550 1550 1551 1551 /** 1552 * Get the IDs of users participating in an activity comment thread. 1553 * 1554 * @since BuddyPress (2.0.0) 1555 * 1556 * @param int $activity_id ID of the top-level activity ID. 1557 * @return array 1558 */ 1559 function bp_activity_get_thread_participants( $activity_id ) { 1560 $activity = bp_activity_get( array( 1561 'id' => $activity_id, 1562 'display_comments' => 'thread', 1563 ) ); 1564 1565 $user_ids = wp_list_pluck( $activity['activities'], 'user_id' ); 1566 1567 // Force unique and sanitize 1568 $user_ids = wp_parse_id_list( array_unique( $user_ids ) ); 1569 1570 // Reset indexes 1571 $user_ids = array_values( $user_ids ); 1572 1573 return wp_parse_id_list( array_unique( $user_ids ) ); 1574 } 1575 1576 /** 1552 1577 * Hide a user's activity. 1553 1578 * 1554 1579 * @since BuddyPress (1.2) -
bp-activity/bp-activity-notifications.php
diff --git bp-activity/bp-activity-notifications.php bp-activity/bp-activity-notifications.php index 237c048..ca3fd9c 100644
To view and respond to the message, log in and visit: %3$s 115 115 * 116 116 * @since BuddyPress (1.2) 117 117 * 118 * @uses bp_get_user_meta()119 * @uses bp_core_get_user_displayname()120 * @uses bp_activity_get_permalink()121 * @uses bp_core_get_user_domain()122 * @uses bp_get_settings_slug()123 * @uses bp_activity_filter_kses()124 * @uses bp_core_get_core_userdata()125 * @uses wp_specialchars_decode()126 * @uses get_blog_option()127 * @uses bp_get_root_blog_id()128 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook129 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook130 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook131 * @uses wp_mail()132 * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook133 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook134 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook135 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook136 * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook137 *138 118 * @param int $comment_id The comment id. 139 119 * @param int $commenter_id The ID of the user who posted the comment. 140 120 * @param array $params {@link bp_activity_new_comment()} … … function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 147 127 148 128 extract( $params ); 149 129 130 // Fetch data that'll be needed for all participants 150 131 $original_activity = new BP_Activity_Activity( $activity_id ); 132 $parent_comment = new BP_Activity_Activity( $parent_id ); 133 $thread_link = bp_activity_get_permalink( $activity_id ); 134 $activity_name = stripslashes( bp_core_get_user_displayname( $original_activity->user_id ) ); 135 $poster_name = stripslashes( bp_core_get_user_displayname( $commenter_id ) ); 136 $content = bp_activity_filter_kses( stripslashes( $content ) ); 137 138 // Fetch list of unique participants 139 $participants = new BP_User_Query( array( 140 'user_ids' => bp_activity_get_thread_participants( $activity_id ), 141 ) ); 142 143 foreach ( $participants->results as $participant ) { 144 145 // Bail if the user has disabled reply notifications globally 146 if ( 'no' === bp_get_user_meta( $participant->ID, 'notification_activity_new_reply' ) ) { 147 continue; 148 } 151 149 152 if ( $original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) { 153 $poster_name = bp_core_get_user_displayname( $commenter_id ); 154 $thread_link = bp_activity_get_permalink( $activity_id ); 155 $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings'; 156 $settings_link = bp_core_get_user_domain( $original_activity->user_id ) . $settings_slug . '/notifications/'; 150 // Each participant will be either (a) the original activity 151 // author, (b) the author of the comment being directly replied 152 // to, or (c) another participant. Handle each case separately 157 153 158 $poster_name = stripslashes( $poster_name ); 159 $content = bp_activity_filter_kses( stripslashes($content) ); 154 // Root activity author 155 if ( $participant->ID == $original_activity->user_id ) { 156 $subject = bp_get_email_subject( array( 157 'text' => sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name ), 158 ) ); 160 159 161 // Set up and send the message 162 $ud = bp_core_get_core_userdata( $original_activity->user_id ); 163 $to = $ud->user_email; 164 $subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name ) ) ); 165 $message = sprintf( __( 160 $message = sprintf( __( 166 161 '%1$s replied to one of your updates: 167 162 168 163 "%2$s" … … To view your original update and all comments, log in and visit: %3$s 172 167 --------------------- 173 168 ', 'buddypress' ), $poster_name, $content, $thread_link ); 174 169 175 // Only show the disable notifications line if the settings component is enabled 176 if ( bp_is_active( 'settings' ) ) { 177 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); 178 } 170 // Only show the disable notifications line if the settings component is enabled 171 if ( bp_is_active( 'settings' ) ) { 172 $settings_link = bp_core_get_user_domain( $participant->ID ) . bp_get_settings_slug() . '/notifications/'; 173 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); 174 } 179 175 180 /* Send the message */ 181 $to = apply_filters( 'bp_activity_new_comment_notification_to', $to ); 182 $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject, $poster_name ); 183 $message = apply_filters( 'bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link ); 176 $to = apply_filters( 'bp_activity_new_comment_notification_to', $participant->user_id ); 177 $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject, $poster_name ); 178 $message = apply_filters( 'bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link ); 184 179 185 wp_mail( $to, $subject, $message);180 do_action( 'bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params ); 186 181 187 do_action( 'bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );188 }182 // Author of comment being replied to 183 } else if ( $participant->ID == $original_activity->user_id ) { 189 184 190 /*** 191 * If this is a reply to another comment, send an email notification to the 192 * author of the immediate parent comment. 193 */ 194 if ( empty( $parent_id ) || ( $activity_id == $parent_id ) ) { 195 return false; 196 } 185 $subject = bp_get_email_subject( array( 186 'text' => sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name ), 187 ) ); 188 189 $message = sprintf( __( 190 '%1$s replied to one of your comments: 197 191 198 $parent_comment = new BP_Activity_Activity( $parent_id ); 192 "%2$s" 199 193 200 if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) { 201 $poster_name = bp_core_get_user_displayname( $commenter_id ); 202 $thread_link = bp_activity_get_permalink( $activity_id ); 203 $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings'; 204 $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . $settings_slug . '/notifications/'; 194 To view your original update and all comments, log in and visit: %3$s 205 195 206 // Set up and send the message 207 $ud = bp_core_get_core_userdata( $parent_comment->user_id ); 208 $to = $ud->user_email; 209 $subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name ) ) ); 196 --------------------- 197 ', 'buddypress' ), $poster_name, $content, $thread_link ); 210 198 211 $poster_name = stripslashes( $poster_name ); 212 $content = bp_activity_filter_kses( stripslashes( $content ) ); 199 // Only show the disable notifications line if the settings component is enabled 200 if ( bp_is_active( 'settings' ) ) { 201 $settings_link = bp_core_get_user_domain( $participant->ID ) . bp_get_settings_slug() . '/notifications/'; 202 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); 203 } 213 204 214 $message = sprintf( __( 215 '%1$s replied to one of your comments: 205 $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $participant->user_email ); 206 $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name ); 207 $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link ); 216 208 217 "%2$s" 209 do_action( 'bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params ); 218 210 219 To view the original activity, your comment and all replies, log in and visit: %3$s 211 // Another participant 212 } else { 213 $subject = bp_get_email_subject( array( 214 'text' => sprintf( __( '%1$s replied to %2$s’s update', 'buddypress' ), $poster_name, $activity_name ), 215 ) ); 216 217 $message = sprintf( __( 218 '%1$s replied to %2$s’s update 219 220 "%3$s" 221 222 To view your original update and all comments, log in and visit: %4$s 220 223 221 224 --------------------- 222 ', 'buddypress' ), $poster_name, $ content, $thread_link );225 ', 'buddypress' ), $poster_name, $activity_name, $content, $thread_link ); 223 226 224 // Only show the disable notifications line if the settings component is enabled225 if ( bp_is_active( 'settings' ) ) {226 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );227 $to = apply_filters( 'bp_activity_new_comment_notification_participant_author_to', $participant->user_email ); 228 $subject = apply_filters( 'bp_activity_new_comment_notification_participant_author_subject', $subject, $poster_name ); 229 $message = apply_filters( 'bp_activity_new_comment_notification_participant_author_message', $message, $poster_name, $content, $settings_link, $thread_link ); 227 230 } 228 231 229 /* Send the message */230 $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );231 $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name );232 $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link );233 234 232 wp_mail( $to, $subject, $message ); 235 236 do_action( 'bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );237 233 } 238 234 } 239 235 -
tests/testcases/activity/functions.php
diff --git tests/testcases/activity/functions.php tests/testcases/activity/functions.php index 24a7dd5..709ac81 100644
Bar!'; 540 540 remove_filter( 'bp_is_username_compatibility_mode', '__return_true' ); 541 541 } 542 542 543 /** 544 * @group bp_activity_get_thread_participants 545 */ 546 public function test_bp_activity_get_thread_participants() { 547 $u1 = $this->create_user(); 548 $u2 = $this->create_user(); 549 $u3 = $this->create_user(); 550 $u4 = $this->create_user(); 551 $parent = $this->factory->activity->create( array( 552 'user_id' => $u1, 553 ) ); 554 555 $comment1 = $this->factory->activity->create( array( 556 'type' => 'activity_comment', 557 'user_id' => $u2, 558 'item_id' => $parent, 559 'secondary_item_id' => $parent, 560 ) ); 561 562 $comment2 = $this->factory->activity->create( array( 563 'type' => 'activity_comment', 564 'user_id' => $u1, 565 'item_id' => $parent, 566 'secondary_item_id' => $comment1, 567 ) ); 568 569 $comment3 = $this->factory->activity->create( array( 570 'type' => 'activity_comment', 571 'user_id' => $u4, 572 'item_id' => $parent, 573 'secondary_item_id' => $parent, 574 ) ); 575 576 $expected = array( $u1, $u2, $u4 ); 577 578 $this->assertEquals( $expected, bp_activity_get_thread_participants( $a1 ) ); 579 } 543 580 }