PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/buddypress/bp-activity/bp-activity-notifications.php

https://bitbucket.org/openfarmtech/weblog-content
PHP | 139 lines | 94 code | 32 blank | 13 comment | 16 complexity | 0c2363ab84c7f6d0decf1f572f33d838 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0
  1. <?php
  2. function bp_activity_at_message_notification( $content, $poster_user_id, $activity_id ) {
  3. global $bp;
  4. /* Scan for @username strings in an activity update. Notify each user. */
  5. $pattern = '/[@]+([A-Za-z0-9-_]+)/';
  6. preg_match_all( $pattern, $content, $usernames );
  7. /* Make sure there's only one instance of each username */
  8. if ( !$usernames = array_unique( $usernames[1] ) )
  9. return false;
  10. foreach( (array)$usernames as $username ) {
  11. if ( !$receiver_user_id = bp_core_get_userid( $username ) )
  12. continue;
  13. // Now email the user with the contents of the message (if they have enabled email notifications)
  14. if ( 'no' != get_usermeta( $receiver_user_id, 'notification_activity_new_mention' ) ) {
  15. $poster_name = bp_core_get_user_displayname( $poster_user_id );
  16. $message_link = bp_activity_get_permalink( $activity_id );
  17. $settings_link = bp_core_get_user_domain( $receiver_user_id ) . BP_SETTINGS_SLUG . '/notifications/';
  18. $poster_name = stripslashes( $poster_name );
  19. $content = bp_activity_filter_kses( stripslashes($content) );
  20. // Set up and send the message
  21. $ud = bp_core_get_core_userdata( $receiver_user_id );
  22. $to = $ud->user_email;
  23. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name );
  24. $message = sprintf( __(
  25. '%s mentioned you in an update:
  26. "%s"
  27. To view and respond to the message, log in and visit: %s
  28. ---------------------
  29. ', 'buddypress' ), $poster_name, $content, $message_link );
  30. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
  31. /* Send the message */
  32. $to = apply_filters( 'bp_activity_at_message_notification_to', $to );
  33. $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
  34. $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link );
  35. wp_mail( $to, $subject, $message );
  36. }
  37. }
  38. }
  39. add_action( 'bp_activity_posted_update', 'bp_activity_at_message_notification', 10, 3 );
  40. function bp_activity_new_comment_notification( $comment_id, $commenter_id, $params ) {
  41. global $bp;
  42. extract( $params );
  43. $original_activity = new BP_Activity_Activity( $activity_id );
  44. if ( $original_activity->user_id != $commenter_id && 'no' != get_usermeta( $original_activity->user_id, 'notification_activity_new_reply' ) ) {
  45. $poster_name = bp_core_get_user_displayname( $commenter_id );
  46. $thread_link = bp_activity_get_permalink( $activity_id );
  47. $settings_link = bp_core_get_user_domain( $original_activity->user_id ) . BP_SETTINGS_SLUG . '/notifications/';
  48. $poster_name = stripslashes( $poster_name );
  49. $content = bp_activity_filter_kses( stripslashes($content) );
  50. // Set up and send the message
  51. $ud = bp_core_get_core_userdata( $original_activity->user_id );
  52. $to = $ud->user_email;
  53. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name );
  54. $message = sprintf( __(
  55. '%s replied to one of your updates:
  56. "%s"
  57. To view your original update and all comments, log in and visit: %s
  58. ---------------------
  59. ', 'buddypress' ), $poster_name, $content, $thread_link );
  60. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
  61. /* Send the message */
  62. $to = apply_filters( 'bp_activity_new_comment_notification_to', $to );
  63. $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject, $poster_name );
  64. $message = apply_filters( 'bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link );
  65. wp_mail( $to, $subject, $message );
  66. }
  67. /***
  68. * If this is a reply to another comment, send an email notification to the
  69. * author of the immediate parent comment.
  70. */
  71. if ( $activity_id == $parent_id )
  72. return false;
  73. $parent_comment = new BP_Activity_Activity( $parent_id );
  74. if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != get_usermeta( $parent_comment->user_id, 'notification_activity_new_reply' ) ) {
  75. $poster_name = bp_core_get_user_displayname( $commenter_id );
  76. $thread_link = bp_activity_get_permalink( $activity_id );
  77. $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . BP_SETTINGS_SLUG . '/notifications/';
  78. // Set up and send the message
  79. $ud = bp_core_get_core_userdata( $parent_comment->user_id );
  80. $to = $ud->user_email;
  81. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name );
  82. $poster_name = stripslashes( $poster_name );
  83. $content = bp_activity_filter_kses( stripslashes( $content ) );
  84. $message = sprintf( __(
  85. '%s replied to one of your comments:
  86. "%s"
  87. To view the original activity, your comment and all replies, log in and visit: %s
  88. ---------------------
  89. ', 'buddypress' ), $poster_name, $content, $thread_link );
  90. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
  91. /* Send the message */
  92. $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );
  93. $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name );
  94. $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content );
  95. wp_mail( $to, $subject, $message );
  96. }
  97. }
  98. ?>