/wp-content/plugins/events-manager/buddypress/bp-em-activity.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net · PHP · 128 lines · 103 code · 5 blank · 20 comment · 26 complexity · 45302b2088867980e8092403cd71b29a MD5 · raw file

  1. <?php
  2. // This file handles hooks/filter requiring activity stream publications
  3. /**
  4. * bp_em_record_activity()
  5. *
  6. * If the activity stream component is installed, this function will record activity items for your
  7. * component.
  8. */
  9. function bp_em_record_activity( $args = '' ) {
  10. if ( !function_exists( 'bp_activity_add' ) )
  11. return false;
  12. $defaults = array(
  13. 'id' => false,
  14. 'user_id' => '',
  15. 'action' => '',
  16. 'content' => '',
  17. 'primary_link' => '',
  18. 'component' => 'events-manager',
  19. 'type' => false,
  20. 'item_id' => false,
  21. 'secondary_item_id' => false,
  22. 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
  23. 'hide_sitewide' => false
  24. );
  25. $r = wp_parse_args( $args, $defaults );
  26. extract( $r );
  27. return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
  28. }
  29. /**
  30. * Records new events to the activity stream.
  31. * @param unknown_type $result
  32. * @param unknown_type $EM_Event
  33. * @return unknown
  34. */
  35. function bp_em_record_activity_event_save( $result, $EM_Event ){
  36. if( $result && $EM_Event->event_status == 1 && empty($EM_Event->previous_status) ){
  37. $user = get_userdata($EM_Event->event_owner);
  38. $member_link = bp_core_get_user_domain($user->ID);
  39. if( empty($EM_Event->group_id) ){
  40. bp_em_record_activity( array(
  41. 'user_id' => $user->ID,
  42. 'action' => sprintf(__('%s added the event %s','dbem'), "<a href='".$member_link."'>".$user->display_name."</a>", $EM_Event->output('#_EVENTLINK') ),
  43. 'primary_link' => $EM_Event->output('#_EVENTURL'),
  44. 'type' => 'new_event',
  45. 'item_id' => $EM_Event->event_id,
  46. 'hide_sitewide' => $EM_Event->event_private
  47. ));
  48. }else{
  49. //tis a group event
  50. $group = new BP_Groups_Group($EM_Event->group_id);
  51. bp_em_record_activity( array(
  52. 'user_id' => $user->ID,
  53. 'action' => sprintf(__('%s added the event %s to %s.','dbem'), "<a href='".$member_link."'>".$user->display_name."</a>", $EM_Event->output('#_EVENTLINK'), '<a href="'.bp_get_group_permalink($group).'">'.bp_get_group_name($group).'</a>' ),
  54. 'component' => 'groups',
  55. 'type' => 'new_event',
  56. 'item_id' => $EM_Event->group_id,
  57. 'hide_sitewide' => $EM_Event->event_private
  58. ));
  59. }
  60. }
  61. return $result;
  62. }
  63. add_filter('em_event_save','bp_em_record_activity_event_save', 10, 2);
  64. /**
  65. * @param boolean $result
  66. * @param EM_Booking $EM_Booking
  67. * @return boolean
  68. */
  69. function bp_em_record_activity_booking_save( $result, $EM_Booking ){
  70. if( $result ){
  71. $rejected_statuses = array(0,2,3); //these statuses apply to rejected/cancelled bookings
  72. $user = $EM_Booking->get_person();
  73. $member_link = bp_core_get_user_domain($user->ID);
  74. $user_link = "<a href='".$member_link."/'>".$user->display_name."</a>";
  75. $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
  76. $status = $EM_Booking->booking_status;
  77. $EM_Event = $EM_Booking->get_event();
  78. if( empty($EM_Event->group_id) ){
  79. if( $status == 1 || (!get_option('dbem_bookings_approval') && $status < 2) ){
  80. $action = sprintf(__('%s is attending %s.','dbem'), $user_link, $event_link );
  81. }elseif( ($EM_Booking->previous_status == 1 || (!get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2)) && in_array($status, $rejected_statuses) ){
  82. $action = sprintf(__('%s will not be attending %s anymore.','dbem'), $user_link, $event_link );
  83. }
  84. }else{
  85. $group = new BP_Groups_Group($EM_Event->group_id);
  86. $group_link = '<a href="'.bp_get_group_permalink($group).'">'.bp_get_group_name($group).'</a>';
  87. if( $status == 1 || (!get_option('dbem_bookings_approval') && $status < 2) ){
  88. $action = sprintf(__('%s is attending %s of the group %s.','dbem'), $user_link, $event_link, $group_link );
  89. }elseif( ($EM_Booking->previous_status == 1 || (!get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2)) && in_array($status, $rejected_statuses) ){
  90. $action = sprintf(__('%s will not be attending %s of group %s anymore.','dbem'), $user_link, $event_link, $group_link );
  91. }
  92. }
  93. if( !empty($action) ){
  94. if( empty($EM_Event->group_id) ){
  95. bp_em_record_activity( array(
  96. 'user_id' => $EM_Booking->person->ID,
  97. 'action' => $action,
  98. 'primary_link' => $EM_Event->output('#_EVENTURL'),
  99. 'type' => 'new_booking',
  100. 'item_id' => $EM_Event->event_id,
  101. 'secondary_item_id' => $EM_Booking->booking_id,
  102. 'hide_sitewide' => $EM_Event->event_private
  103. ));
  104. }else{
  105. //tis a group event
  106. bp_em_record_activity( array(
  107. 'component' => 'groups',
  108. 'item_id' => $EM_Event->group_id,
  109. 'user_id' => $EM_Booking->person->ID,
  110. 'action' => $action,
  111. 'primary_link' => $EM_Event->output('#_EVENTURL'),
  112. 'type' => 'new_booking',
  113. 'secondary_item_id' => $EM_Booking->booking_id,
  114. 'hide_sitewide' => $EM_Event->event_private
  115. ));
  116. }
  117. }
  118. }
  119. return $result;
  120. }
  121. add_filter('em_booking_set_status','bp_em_record_activity_booking_save', 100, 2);
  122. add_filter('em_booking_save','bp_em_record_activity_booking_save', 100, 2);
  123. add_filter('em_booking_delete','bp_em_record_activity_booking_save', 100, 2);