Changeset 7521 for trunk/bp-members/bp-members-notifications.php
- Timestamp:
- 11/07/2013 05:15:51 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-members/bp-members-notifications.php
r7173 r7521 4 4 * BuddyPress Member Notifications 5 5 * 6 * Functions and filters used for member notification 6 * Backwards compatibility functions and filters used for member notifications. 7 * Use bp-notifications instead. 7 8 * 8 9 * @package BuddyPress … … 27 28 function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = 0, $date_notified = false ) { 28 29 29 if ( empty( $date_notified ) ) 30 $date_notified = bp_core_current_time(); 30 // Bail if notifications is not active 31 if ( ! bp_is_active( 'notifications' ) ) { 32 return false; 33 } 31 34 32 $notification = new BP_Core_Notification; 33 $notification->item_id = $item_id; 34 $notification->user_id = $user_id; 35 $notification->component_name = $component_name; 36 $notification->component_action = $component_action; 37 $notification->date_notified = $date_notified; 38 $notification->is_new = 1; 39 40 if ( !empty( $secondary_item_id ) ) 41 $notification->secondary_item_id = $secondary_item_id; 42 43 if ( $notification->save() ) 44 return true; 45 46 return false; 35 return bp_notifications_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = 0, $date_notified = false ); 47 36 } 48 37 … … 55 44 */ 56 45 function bp_core_delete_notification( $id ) { 57 if ( !bp_core_check_notification_access( bp_loggedin_user_id(), $id ) ) 46 47 // Bail if notifications is not active 48 if ( ! bp_is_active( 'notifications' ) ) { 58 49 return false; 50 } 59 51 60 return BP_Core_Notification::delete( $id );52 return bp_notifications_delete_notification( $id ); 61 53 } 62 54 … … 69 61 */ 70 62 function bp_core_get_notification( $id ) { 71 return new BP_Core_Notification( $id ); 63 64 // Bail if notifications is not active 65 if ( ! bp_is_active( 'notifications' ) ) { 66 return false; 67 } 68 69 return bp_notifications_get_notification( $id ); 72 70 } 73 71 … … 82 80 */ 83 81 function bp_core_get_notifications_for_user( $user_id, $format = 'simple' ) { 84 global $bp;85 82 86 $notifications = BP_Core_Notification::get_all_for_user( $user_id ); 87 $grouped_notifications = array(); // Notification groups 88 $renderable = array(); // Renderable notifications 89 90 // Group notifications by component and component_action and provide totals 91 for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) { 92 $notification = $notifications[$i]; 93 $grouped_notifications[$notification->component_name][$notification->component_action][] = $notification; 83 // Bail if notifications is not active 84 if ( ! bp_is_active( 'notifications' ) ) { 85 return false; 94 86 } 95 87 96 // Bail if no notification groups 97 if ( empty( $grouped_notifications ) ) 98 return false; 88 $renderable = bp_notifications_get_notifications_for_user( $user_id, $format ); 99 89 100 // Calculate a renderable output for each notification type101 foreach ( $grouped_notifications as $component_name => $action_arrays ) {102 103 // Skip if group is empty104 if ( empty( $action_arrays ) )105 continue;106 107 // Skip inactive components108 if ( !bp_is_active( $component_name ) )109 continue;110 111 // Loop through each actionable item and try to map it to a component112 foreach ( (array) $action_arrays as $component_action_name => $component_action_items ) {113 114 // Get the number of actionable items115 $action_item_count = count( $component_action_items );116 117 // Skip if the count is less than 1118 if ( $action_item_count < 1 )119 continue;120 121 // Callback function exists122 if ( isset( $bp->{$component_name}->notification_callback ) && is_callable( $bp->{$component_name}->notification_callback ) ) {123 124 // Function should return an object125 if ( 'object' == $format ) {126 127 // Retrieve the content of the notification using the callback128 $content = call_user_func(129 $bp->{$component_name}->notification_callback,130 $component_action_name,131 $component_action_items[0]->item_id,132 $component_action_items[0]->secondary_item_id,133 $action_item_count,134 'array'135 );136 137 // Create the object to be returned138 $notification_object = new stdClass;139 140 // Minimal backpat with non-compatible notification141 // callback functions142 if ( is_string( $content ) ) {143 $notification_object->content = $content;144 $notification_object->href = bp_loggedin_user_domain();145 } else {146 $notification_object->content = $content['text'];147 $notification_object->href = $content['link'];148 }149 150 $notification_object->id = $component_action_items[0]->id;151 $renderable[] = $notification_object;152 153 // Return an array of content strings154 } else {155 $content = call_user_func( $bp->{$component_name}->notification_callback, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count );156 $renderable[] = $content;157 }158 159 // @deprecated format_notification_function - 1.5160 } elseif ( isset( $bp->{$component_name}->format_notification_function ) && function_exists( $bp->{$component_name}->format_notification_function ) ) {161 $renderable[] = call_user_func( $bp->{$component_name}->format_notification_function, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count );162 }163 }164 }165 166 // If renderable is empty array, set to false167 if ( empty( $renderable ) )168 $renderable = false;169 170 // Filter and return171 90 return apply_filters( 'bp_core_get_notifications_for_user', $renderable, $user_id, $format ); 172 91 } … … 185 104 */ 186 105 function bp_core_delete_notifications_by_type( $user_id, $component_name, $component_action ) { 187 return BP_Core_Notification::delete_for_user_by_type( $user_id, $component_name, $component_action ); 106 107 // Bail if notifications is not active 108 if ( ! bp_is_active( 'notifications' ) ) { 109 return false; 110 } 111 112 return bp_notifications_delete_notifications_by_type( $user_id, $component_name, $component_action ); 188 113 } 189 114 … … 201 126 */ 202 127 function bp_core_delete_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) { 203 return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ); 128 129 // Bail if notifications is not active 130 if ( ! bp_is_active( 'notifications' ) ) { 131 return false; 132 } 133 134 return bp_notifications_delete_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ); 204 135 } 205 136 … … 216 147 */ 217 148 function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) { 218 return BP_Core_Notification::delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ); 149 150 // Bail if notifications is not active 151 if ( ! bp_is_active( 'notifications' ) ) { 152 return false; 153 } 154 155 bp_notifications_delete_all_notifications_by_type( $item_id, $component_name, $component_action, $secondary_item_id ); 219 156 } 220 157 … … 231 168 */ 232 169 function bp_core_delete_notifications_from_user( $user_id, $component_name, $component_action ) { 233 return BP_Core_Notification::delete_from_user_by_type( $user_id, $component_name, $component_action ); 170 171 // Bail if notifications is not active 172 if ( ! bp_is_active( 'notifications' ) ) { 173 return false; 174 } 175 176 return bp_notifications_delete_notifications_from_user( $user_id, $component_name, $component_action ); 234 177 } 235 178 … … 245 188 */ 246 189 function bp_core_check_notification_access( $user_id, $notification_id ) { 247 if ( !BP_Core_Notification::check_access( $user_id, $notification_id ) ) 190 191 // Bail if notifications is not active 192 if ( ! bp_is_active( 'notifications' ) ) { 248 193 return false; 194 } 249 195 250 return true;196 return bp_notifications_check_notification_access( $user_id, $notification_id ); 251 197 }
Note: See TracChangeset
for help on using the changeset viewer.