PageRenderTime 108ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://bitbucket.org/openfarmtech/weblog-content
PHP | 299 lines | 204 code | 76 blank | 19 comment | 21 complexity | 684d29ea908615efffe9635ac011bc15 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 groups_notification_group_updated( $group_id ) {
  3. global $bp;
  4. $group = new BP_Groups_Group( $group_id );
  5. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . __( 'Group Details Updated', 'buddypress' );
  6. $user_ids = BP_Groups_Member::get_group_member_ids( $group->id );
  7. foreach ( (array)$user_ids as $user_id ) {
  8. if ( 'no' == get_usermeta( $user_id, 'notification_groups_group_updated' ) ) continue;
  9. $ud = bp_core_get_core_userdata( $user_id );
  10. // Set up and send the message
  11. $to = $ud->user_email;
  12. $group_link = site_url( $bp->groups->slug . '/' . $group->slug );
  13. $settings_link = bp_core_get_user_domain( $user_id ) . BP_SETTINGS_SLUG . '/notifications/';
  14. $message = sprintf( __(
  15. 'Group details for the group "%s" were updated:
  16. To view the group: %s
  17. ---------------------
  18. ', 'buddypress' ), $group->name, $group_link );
  19. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
  20. /* Send the message */
  21. $to = apply_filters( 'groups_notification_group_updated_to', $to );
  22. $subject = apply_filters( 'groups_notification_group_updated_subject', $subject, &$group );
  23. $message = apply_filters( 'groups_notification_group_updated_message', $message, &$group, $group_link );
  24. wp_mail( $to, $subject, $message );
  25. unset( $message, $to );
  26. }
  27. }
  28. function groups_notification_new_membership_request( $requesting_user_id, $admin_id, $group_id, $membership_id ) {
  29. global $bp;
  30. bp_core_add_notification( $requesting_user_id, $admin_id, 'groups', 'new_membership_request', $group_id );
  31. if ( 'no' == get_usermeta( $admin_id, 'notification_groups_membership_request' ) )
  32. return false;
  33. $requesting_user_name = bp_core_get_user_displayname( $requesting_user_id );
  34. $group = new BP_Groups_Group( $group_id );
  35. $ud = bp_core_get_core_userdata($admin_id);
  36. $requesting_ud = bp_core_get_core_userdata($requesting_user_id);
  37. $group_requests = bp_get_group_permalink( $group ) . 'admin/membership-requests';
  38. $profile_link = bp_core_get_user_domain( $requesting_user_id );
  39. $settings_link = bp_core_get_user_domain( $requesting_user_id ) . BP_SETTINGS_SLUG . '/notifications/';
  40. // Set up and send the message
  41. $to = $ud->user_email;
  42. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'Membership request for group: %s', 'buddypress' ), $group->name );
  43. $message = sprintf( __(
  44. '%s wants to join the group "%s".
  45. Because you are the administrator of this group, you must either accept or reject the membership request.
  46. To view all pending membership requests for this group, please visit:
  47. %s
  48. To view %s\'s profile: %s
  49. ---------------------
  50. ', 'buddypress' ), $requesting_user_name, $group->name, $group_requests, $requesting_user_name, $profile_link );
  51. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
  52. /* Send the message */
  53. $to = apply_filters( 'groups_notification_new_membership_request_to', $to );
  54. $subject = apply_filters( 'groups_notification_new_membership_request_subject', $subject, &$group );
  55. $message = apply_filters( 'groups_notification_new_membership_request_message', $message, &$group, $requesting_user_name, $profile_link, $group_requests );
  56. wp_mail( $to, $subject, $message );
  57. }
  58. function groups_notification_membership_request_completed( $requesting_user_id, $group_id, $accepted = true ) {
  59. global $bp;
  60. // Post a screen notification first.
  61. if ( $accepted )
  62. bp_core_add_notification( $group_id, $requesting_user_id, 'groups', 'membership_request_accepted' );
  63. else
  64. bp_core_add_notification( $group_id, $requesting_user_id, 'groups', 'membership_request_rejected' );
  65. if ( 'no' == get_usermeta( $requesting_user_id, 'notification_membership_request_completed' ) )
  66. return false;
  67. $group = new BP_Groups_Group( $group_id );
  68. $ud = bp_core_get_core_userdata($requesting_user_id);
  69. $group_link = bp_get_group_permalink( $group );
  70. $settings_link = bp_core_get_user_domain( $requesting_user_id ) . BP_SETTINGS_SLUG . '/notifications/';
  71. // Set up and send the message
  72. $to = $ud->user_email;
  73. if ( $accepted ) {
  74. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'Membership request for group "%s" accepted', 'buddypress' ), $group->name );
  75. $message = sprintf( __(
  76. 'Your membership request for the group "%s" has been accepted.
  77. To view the group please login and visit: %s
  78. ---------------------
  79. ', 'buddypress' ), $group->name, $group_link );
  80. } else {
  81. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'Membership request for group "%s" rejected', 'buddypress' ), $group->name );
  82. $message = sprintf( __(
  83. 'Your membership request for the group "%s" has been rejected.
  84. To submit another request please log in and visit: %s
  85. ---------------------
  86. ', 'buddypress' ), $group->name, $group_link );
  87. }
  88. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
  89. /* Send the message */
  90. $to = apply_filters( 'groups_notification_membership_request_completed_to', $to );
  91. $subject = apply_filters( 'groups_notification_membership_request_completed_subject', $subject, &$group );
  92. $message = apply_filters( 'groups_notification_membership_request_completed_message', $message, &$group, $group_link );
  93. wp_mail( $to, $subject, $message );
  94. }
  95. function groups_notification_promoted_member( $user_id, $group_id ) {
  96. global $bp;
  97. if ( groups_is_user_admin( $user_id, $group_id ) ) {
  98. $promoted_to = __( 'an administrator', 'buddypress' );
  99. $type = 'member_promoted_to_admin';
  100. } else {
  101. $promoted_to = __( 'a moderator', 'buddypress' );
  102. $type = 'member_promoted_to_mod';
  103. }
  104. // Post a screen notification first.
  105. bp_core_add_notification( $group_id, $user_id, 'groups', $type );
  106. if ( 'no' == get_usermeta( $user_id, 'notification_groups_admin_promotion' ) )
  107. return false;
  108. $group = new BP_Groups_Group( $group_id );
  109. $ud = bp_core_get_core_userdata($user_id);
  110. $group_link = bp_get_group_permalink( $group );
  111. $settings_link = bp_core_get_user_domain( $user_id ) . BP_SETTINGS_SLUG . '/notifications/';
  112. // Set up and send the message
  113. $to = $ud->user_email;
  114. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'You have been promoted in the group: "%s"', 'buddypress' ), $group->name );
  115. $message = sprintf( __(
  116. 'You have been promoted to %s for the group: "%s".
  117. To view the group please visit: %s
  118. ---------------------
  119. ', 'buddypress' ), $promoted_to, $group->name, $group_link );
  120. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
  121. /* Send the message */
  122. $to = apply_filters( 'groups_notification_promoted_member_to', $to );
  123. $subject = apply_filters( 'groups_notification_promoted_member_subject', $subject, &$group );
  124. $message = apply_filters( 'groups_notification_promoted_member_message', $message, &$group, $promoted_to, $group_link );
  125. wp_mail( $to, $subject, $message );
  126. }
  127. add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10, 2 );
  128. function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {
  129. global $bp;
  130. $inviter_ud = bp_core_get_core_userdata( $inviter_user_id );
  131. $inviter_name = bp_core_get_userlink( $inviter_user_id, true, false, true );
  132. $inviter_link = bp_core_get_user_domain( $inviter_user_id );
  133. $group_link = bp_get_group_permalink( $group );
  134. if ( !$member->invite_sent ) {
  135. $invited_user_id = $member->user_id;
  136. // Post a screen notification first.
  137. bp_core_add_notification( $group->id, $invited_user_id, 'groups', 'group_invite' );
  138. if ( 'no' == get_usermeta( $invited_user_id, 'notification_groups_invite' ) )
  139. return false;
  140. $invited_ud = bp_core_get_core_userdata($invited_user_id);
  141. $settings_link = bp_core_get_user_domain( $invited_user_id ) . BP_SETTINGS_SLUG . '/notifications/';
  142. $invited_link = bp_core_get_user_domain( $invited_user_id );
  143. $invites_link = $invited_link . $bp->groups->slug . '/invites';
  144. // Set up and send the message
  145. $to = $invited_ud->user_email;
  146. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'You have an invitation to the group: "%s"', 'buddypress' ), $group->name );
  147. $message = sprintf( __(
  148. 'One of your friends %s has invited you to the group: "%s".
  149. To view your group invites visit: %s
  150. To view the group visit: %s
  151. To view %s\'s profile visit: %s
  152. ---------------------
  153. ', 'buddypress' ), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link );
  154. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
  155. /* Send the message */
  156. $to = apply_filters( 'groups_notification_group_invites_to', $to );
  157. $subject = apply_filters( 'groups_notification_group_invites_subject', $subject, &$group );
  158. $message = apply_filters( 'groups_notification_group_invites_message', $message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link );
  159. wp_mail( $to, $subject, $message );
  160. }
  161. }
  162. function groups_at_message_notification( $content, $poster_user_id, $group_id, $activity_id ) {
  163. global $bp;
  164. /* Scan for @username strings in an activity update. Notify each user. */
  165. $pattern = '/[@]+([A-Za-z0-9-_]+)/';
  166. preg_match_all( $pattern, $content, $usernames );
  167. /* Make sure there's only one instance of each username */
  168. if ( !$usernames = array_unique( $usernames[1] ) )
  169. return false;
  170. $group = new BP_Groups_Group( $group_id );
  171. foreach( (array)$usernames as $username ) {
  172. if ( !$receiver_user_id = bp_core_get_userid($username) )
  173. continue;
  174. /* Check the user is a member of the group before sending the update. */
  175. if ( !groups_is_user_member( $receiver_user_id, $group_id ) )
  176. continue;
  177. // Now email the user with the contents of the message (if they have enabled email notifications)
  178. if ( 'no' != get_usermeta( $user_id, 'notification_activity_new_mention' ) ) {
  179. $poster_name = bp_core_get_user_displayname( $poster_user_id );
  180. $message_link = bp_activity_get_permalink( $activity_id );
  181. $settings_link = bp_core_get_user_domain( $receiver_user_id ) . BP_SETTINGS_SLUG . '/notifications/';
  182. $poster_name = stripslashes( $poster_name );
  183. $content = bp_groups_filter_kses( stripslashes( $content ) );
  184. // Set up and send the message
  185. $ud = bp_core_get_core_userdata( $receiver_user_id );
  186. $to = $ud->user_email;
  187. $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in the group "%s"', 'buddypress' ), $poster_name, $group->name );
  188. $message = sprintf( __(
  189. '%s mentioned you in the group "%s":
  190. "%s"
  191. To view and respond to the message, log in and visit: %s
  192. ---------------------
  193. ', 'buddypress' ), $poster_name, $group->name, $content, $message_link );
  194. $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
  195. /* Send the message */
  196. $to = apply_filters( 'groups_at_message_notification_to', $to );
  197. $subject = apply_filters( 'groups_at_message_notification_subject', $subject, &$group, $poster_name );
  198. $message = apply_filters( 'groups_at_message_notification_message', $message, &$group, $poster_name, $content, $message_link );
  199. wp_mail( $to, $subject, $message );
  200. }
  201. }
  202. }
  203. add_action( 'bp_groups_posted_update', 'groups_at_message_notification', 10, 4 );
  204. ?>