Changeset 10303
- Timestamp:
- 10/22/2015 06:02:55 AM (9 years ago)
- Location:
- trunk/src/bp-notifications
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-notifications/bp-notifications-actions.php
r10138 r10303 23 23 function bp_notifications_action_mark_read() { 24 24 25 // Bail if not the unread screen 25 // Bail if not the unread screen. 26 26 if ( ! bp_is_notifications_component() || ! bp_is_current_action( 'unread' ) ) { 27 27 return false; 28 28 } 29 29 30 // Get the action 30 // Get the action. 31 31 $action = !empty( $_GET['action'] ) ? $_GET['action'] : ''; 32 32 $nonce = !empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : ''; 33 33 $id = !empty( $_GET['notification_id'] ) ? $_GET['notification_id'] : ''; 34 34 35 // Bail if no action or no ID 35 // Bail if no action or no ID. 36 36 if ( ( 'read' !== $action ) || empty( $id ) || empty( $nonce ) ) { 37 37 return false; 38 38 } 39 39 40 // Check the nonce and mark the notification 40 // Check the nonce and mark the notification. 41 41 if ( bp_verify_nonce_request( 'bp_notification_mark_read_' . $id ) && bp_notifications_mark_notification( $id, false ) ) { 42 42 bp_core_add_message( __( 'Notification successfully marked read.', 'buddypress' ) ); … … 45 45 } 46 46 47 // Redirect 47 // Redirect. 48 48 bp_core_redirect( bp_displayed_user_domain() . bp_get_notifications_slug() . '/unread/' ); 49 49 } … … 59 59 function bp_notifications_action_mark_unread() { 60 60 61 // Bail if not the read screen 61 // Bail if not the read screen. 62 62 if ( ! bp_is_notifications_component() || ! bp_is_current_action( 'read' ) ) { 63 63 return false; 64 64 } 65 65 66 // Get the action 66 // Get the action. 67 67 $action = !empty( $_GET['action'] ) ? $_GET['action'] : ''; 68 68 $nonce = !empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : ''; 69 69 $id = !empty( $_GET['notification_id'] ) ? $_GET['notification_id'] : ''; 70 70 71 // Bail if no action or no ID 71 // Bail if no action or no ID. 72 72 if ( ( 'unread' !== $action ) || empty( $id ) || empty( $nonce ) ) { 73 73 return false; 74 74 } 75 75 76 // Check the nonce and mark the notification 76 // Check the nonce and mark the notification. 77 77 if ( bp_verify_nonce_request( 'bp_notification_mark_unread_' . $id ) && bp_notifications_mark_notification( $id, true ) ) { 78 78 bp_core_add_message( __( 'Notification successfully marked unread.', 'buddypress' ) ); … … 81 81 } 82 82 83 // Redirect 83 // Redirect. 84 84 bp_core_redirect( bp_displayed_user_domain() . bp_get_notifications_slug() . '/read/' ); 85 85 } … … 95 95 function bp_notifications_action_delete() { 96 96 97 // Bail if not the read or unread screen 97 // Bail if not the read or unread screen. 98 98 if ( ! bp_is_notifications_component() || ! ( bp_is_current_action( 'read' ) || bp_is_current_action( 'unread' ) ) ) { 99 99 return false; 100 100 } 101 101 102 // Get the action 102 // Get the action. 103 103 $action = !empty( $_GET['action'] ) ? $_GET['action'] : ''; 104 104 $nonce = !empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : ''; 105 105 $id = !empty( $_GET['notification_id'] ) ? $_GET['notification_id'] : ''; 106 106 107 // Bail if no action or no ID 107 // Bail if no action or no ID. 108 108 if ( ( 'delete' !== $action ) || empty( $id ) || empty( $nonce ) ) { 109 109 return false; 110 110 } 111 111 112 // Check the nonce and delete the notification 112 // Check the nonce and delete the notification. 113 113 if ( bp_verify_nonce_request( 'bp_notification_delete_' . $id ) && bp_notifications_delete_notification( $id ) ) { 114 114 bp_core_add_message( __( 'Notification successfully deleted.', 'buddypress' ) ); … … 117 117 } 118 118 119 // Redirect 119 // Redirect. 120 120 bp_core_redirect( bp_displayed_user_domain() . bp_get_notifications_slug() . '/' . bp_current_action() . '/' ); 121 121 } … … 136 136 } 137 137 138 // Get the action 138 // Get the action. 139 139 $action = !empty( $_POST['notification_bulk_action'] ) ? $_POST['notification_bulk_action'] : ''; 140 140 $nonce = !empty( $_POST['notifications_bulk_nonce'] ) ? $_POST['notifications_bulk_nonce'] : ''; … … 178 178 } 179 179 180 // Redirect 180 // Redirect. 181 181 bp_core_redirect( bp_displayed_user_domain() . bp_get_notifications_slug() . '/' . bp_current_action() . '/' ); 182 182 } -
trunk/src/bp-notifications/bp-notifications-adminbar.php
r10138 r10303 32 32 $menu_link = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() ); 33 33 34 // Add the top-level Notifications button 34 // Add the top-level Notifications button. 35 35 $wp_admin_bar->add_menu( array( 36 36 'parent' => 'top-secondary', -
trunk/src/bp-notifications/bp-notifications-cache.php
r10138 r10303 3 3 * Functions related to notifications caching. 4 4 * 5 * @since 2.0.06 *7 5 * @package BuddyPress 8 6 * @subpackage NotificationsCache 7 * @since 2.0.0 9 8 */ 10 9 … … 68 67 function bp_notifications_clear_all_for_user_cache_before_delete( $args ) { 69 68 70 // Pull up a list of items matching the args (those about te be deleted) 69 // Pull up a list of items matching the args (those about te be deleted). 71 70 $ns = BP_Notifications_Notification::get( $args ); 72 71 … … 93 92 function bp_notifications_clear_all_for_user_cache_before_update( $update_args, $where_args ) { 94 93 95 // User ID is passed in where arugments 94 // User ID is passed in where arugments. 96 95 if ( ! empty( $where_args['user_id'] ) ) { 97 96 bp_notifications_clear_all_for_user_cache( $where_args['user_id'] ); 98 97 99 // Get user ID from Notification ID 98 // Get user ID from Notification ID. 100 99 } elseif ( ! empty( $where_args['id'] ) ) { 101 100 $n = bp_notifications_get_notification( $where_args['id'] ); -
trunk/src/bp-notifications/bp-notifications-classes.php
r10138 r10303 7 7 * @package BuddyPress 8 8 * @subpackage NotificationsClasses 9 *10 9 * @since 1.9.0 11 10 */ -
trunk/src/bp-notifications/bp-notifications-functions.php
r10284 r10303 30 30 * } 31 31 * @return int|bool ID of the newly created notification on success, false 32 * on failure.32 * on failure. 33 33 */ 34 34 function bp_notifications_add_notification( $args = array() ) { … … 45 45 ), 'notifications_add_notification' );; 46 46 47 // Check for existing duplicate notifications 47 // Check for existing duplicate notifications. 48 48 if ( ! $r['allow_duplicate'] ) { 49 // date_notified, allow_duplicate don't count toward50 // duplicate status 49 // Date_notified, allow_duplicate don't count toward 50 // duplicate status. 51 51 $existing = BP_Notifications_Notification::get( array( 52 52 'user_id' => $r['user_id'], … … 63 63 } 64 64 65 // Setup the new notification 65 // Setup the new notification. 66 66 $notification = new BP_Notifications_Notification; 67 67 $notification->user_id = $r['user_id']; … … 73 73 $notification->is_new = $r['is_new']; 74 74 75 // Save the new notification 75 // Save the new notification. 76 76 return $notification->save(); 77 77 } … … 83 83 * 84 84 * @param int $id ID of the notification. 85 * 86 * @return BP_Notifications_Notification 85 * @return BP_Notifications_Notification Notification object for ID specified. 87 86 */ 88 87 function bp_notifications_get_notification( $id ) { … … 96 95 * 97 96 * @param int $id ID of the notification to delete. 98 *99 97 * @return bool True on success, false on failure. 100 98 */ … … 116 114 * @param int $id ID of the notification. 117 115 * @param int|bool $is_new 0 for read, 1 for unread. 118 *119 116 * @return bool True on success, false on failure. 120 117 */ … … 136 133 * 137 134 * @param int $user_id ID of the user whose notifications are being fetched. 138 * 139 * @return array 135 * @return array $notifications Array of notifications for user. 140 136 */ 141 137 function bp_notifications_get_all_notifications_for_user( $user_id = 0 ) { 142 138 143 // Default to displayed user if no ID is passed 139 // Default to displayed user if no ID is passed. 144 140 if ( empty( $user_id ) ) { 145 141 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 146 142 } 147 143 148 // Get notifications out of the cache, or query if necessary 144 // Get notifications out of the cache, or query if necessary. 149 145 $notifications = wp_cache_get( 'all_for_user_' . $user_id, 'bp_notifications' ); 150 146 if ( false === $notifications ) { … … 174 170 * @param string $format Format of the returned values. 'string' returns HTML, 175 171 * while 'object' returns a structured object for parsing. 176 *177 172 * @return mixed Object or array on success, false on failure. 178 173 */ 179 174 function bp_notifications_get_notifications_for_user( $user_id, $format = 'string' ) { 180 175 181 // Setup local variables 176 // Setup local variables. 182 177 $bp = buddypress(); 183 178 184 // Get notifications (out of the cache, or query if necessary) 179 // Get notifications (out of the cache, or query if necessary). 185 180 $notifications = bp_notifications_get_all_notifications_for_user( $user_id ); 186 $grouped_notifications = array(); // Notification groups 187 $renderable = array(); // Renderable notifications 188 189 // Group notifications by component and component_action and provide totals 181 $grouped_notifications = array(); // Notification groups. 182 $renderable = array(); // Renderable notifications. 183 184 // Group notifications by component and component_action and provide totals. 190 185 for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) { 191 186 $notification = $notifications[$i]; … … 193 188 } 194 189 195 // Bail if no notification groups 190 // Bail if no notification groups. 196 191 if ( empty( $grouped_notifications ) ) { 197 192 return false; 198 193 } 199 194 200 // Calculate a renderable output for each notification type 195 // Calculate a renderable output for each notification type. 201 196 foreach ( $grouped_notifications as $component_name => $action_arrays ) { 202 197 … … 209 204 } 210 205 211 // Skip if group is empty 206 // Skip if group is empty. 212 207 if ( empty( $action_arrays ) ) { 213 208 continue; 214 209 } 215 210 216 // Loop through each actionable item and try to map it to a component 211 // Loop through each actionable item and try to map it to a component. 217 212 foreach ( (array) $action_arrays as $component_action_name => $component_action_items ) { 218 213 219 // Get the number of actionable items 214 // Get the number of actionable items. 220 215 $action_item_count = count( $component_action_items ); 221 216 222 // Skip if the count is less than 1 217 // Skip if the count is less than 1. 223 218 if ( $action_item_count < 1 ) { 224 219 continue; 225 220 } 226 221 227 // Callback function exists 222 // Callback function exists. 228 223 if ( isset( $bp->{$component_name}->notification_callback ) && is_callable( $bp->{$component_name}->notification_callback ) ) { 229 224 230 // Function should return an object 225 // Function should return an object. 231 226 if ( 'object' === $format ) { 232 227 233 // Retrieve the content of the notification using the callback 228 // Retrieve the content of the notification using the callback. 234 229 $content = call_user_func( 235 230 $bp->{$component_name}->notification_callback, … … 241 236 ); 242 237 243 // Create the object to be returned 238 // Create the object to be returned. 244 239 $notification_object = $component_action_items[0]; 245 240 246 241 // Minimal backpat with non-compatible notification 247 // callback functions 242 // callback functions. 248 243 if ( is_string( $content ) ) { 249 244 $notification_object->content = $content; … … 256 251 $renderable[] = $notification_object; 257 252 258 // Return an array of content strings 253 // Return an array of content strings. 259 254 } else { 260 255 $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 ); … … 266 261 $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 ); 267 262 268 // Allow non BuddyPress components to hook in 263 // Allow non BuddyPress components to hook in. 269 264 } else { 270 265 271 // The array to reference with apply_filters_ref_array() 266 // The array to reference with apply_filters_ref_array(). 272 267 $ref_array = array( 273 268 $component_action_name, … … 278 273 ); 279 274 280 // Function should return an object 275 // Function should return an object. 281 276 if ( 'object' === $format ) { 282 277 … … 290 285 $content = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array ); 291 286 292 // Create the object to be returned 287 // Create the object to be returned. 293 288 $notification_object = $component_action_items[0]; 294 289 295 290 // Minimal backpat with non-compatible notification 296 // callback functions 291 // callback functions. 297 292 if ( is_string( $content ) ) { 298 293 $notification_object->content = $content; … … 305 300 $renderable[] = $notification_object; 306 301 307 // Return an array of content strings 302 // Return an array of content strings. 308 303 } else { 309 304 … … 315 310 } 316 311 317 // If renderable is empty array, set to false 312 // If renderable is empty array, set to false. 318 313 if ( empty( $renderable ) ) { 319 314 $renderable = false; … … 345 340 * @param string $component_name Name of the associated component. 346 341 * @param string $component_action Name of the associated action. 347 *348 342 * @return bool True on success, false on failure. 349 343 */ … … 369 363 * @param string $component_action Name of the associated action. 370 364 * @param int|bool $secondary_item_id ID of the secondary associated item. 371 *372 365 * @return bool True on success, false on failure. 373 366 */ … … 393 386 * @param string|bool $component_action Optional. Name of the associated action. 394 387 * @param int|bool $secondary_item_id Optional. ID of the secondary associated item. 395 *396 388 * @return bool True on success, false on failure. 397 389 */ … … 419 411 * @param string $component_name Name of the associated component. 420 412 * @param string $component_action Name of the associated action. 421 *422 413 * @return bool True on success, false on failure. 423 414 */ … … 444 435 * @param string $component_action Name of the associated action. 445 436 * @param int|bool $is_new 0 for read, 1 for unread. 446 *447 437 * @return bool True on success, false on failure. 448 438 */ … … 474 464 * @param int|bool $secondary_item_id ID of the secondary associated item. 475 465 * @param int|bool $is_new 0 for read, 1 for unread. 476 *477 466 * @return bool True on success, false on failure. 478 467 */ … … 504 493 * @param int|bool $secondary_item_id Optional. ID of the secondary associated item. 505 494 * @param int|bool $is_new 0 for read, 1 for unread. 506 *507 495 * @return bool True on success, false on failure. 508 496 */ … … 536 524 * @param string $component_action Name of the associated action. 537 525 * @param int|bool $is_new 0 for read, 1 for unread. 538 *539 526 * @return bool True on success, false on failure. 540 527 */ … … 563 550 * @param int $user_id ID of the user being checked. 564 551 * @param int $notification_id ID of the notification being checked. 565 *566 552 * @return bool True if the notification belongs to the user, otherwise false. 567 553 */ … … 577 563 * @param int $user_id ID of the user whose unread notifications are being 578 564 * counted. 579 *580 565 * @return int Unread notification count. 581 566 */ … … 602 587 * @see http://buddypress.trac.wordpress.org/ticket/5300 603 588 * 604 * @return array 589 * @return array $component_names Array of registered components. 605 590 */ 606 591 function bp_notifications_get_registered_components() { 607 592 608 // Load BuddyPress 593 // Load BuddyPress. 609 594 $bp = buddypress(); 610 595 611 // Setup return value 596 // Setup return value. 612 597 $component_names = array(); 613 598 614 // Get the active components 599 // Get the active components. 615 600 $active_components = array_keys( $bp->active_components ); 616 601 617 // Loop through components, look for callbacks, add to return value 602 // Loop through components, look for callbacks, add to return value. 618 603 foreach ( $active_components as $component ) { 619 604 if ( !empty( $bp->$component->notification_callback ) ) { … … 654 639 * deleted if the meta_value matches this parameter. 655 640 * @param bool $delete_all Optional. If true, delete matching metadata entries 656 * for all objects, ignoring the specified object_id. Otherwise, 657 * only delete matching metadata entries for the specified 658 * notification item. Default: false. 659 * 641 * for all objects, ignoring the specified object_id. Otherwise, 642 * only delete matching metadata entries for the specified 643 * notification item. Default: false. 660 644 * @return bool True on success, false on failure. 661 645 */ 662 646 function bp_notifications_delete_meta( $notification_id, $meta_key = '', $meta_value = '', $delete_all = false ) { 663 647 664 // Legacy - if no meta_key is passed, delete all for the item 648 // Legacy - if no meta_key is passed, delete all for the item. 665 649 if ( empty( $meta_key ) ) { 666 650 $all_meta = bp_notifications_get_meta( $notification_id ); … … 669 653 : array(); 670 654 671 // With no meta_key, ignore $delete_all 655 // With no meta_key, ignore $delete_all. 672 656 $delete_all = false; 673 657 } else { … … 698 682 * notification item will be fetched. 699 683 * @param bool $single Optional. If true, return only the first value of the 700 * specified meta_key. This parameter has no effect if meta_key is not 701 * specified. Default: true. 702 * 684 * specified meta_key. This parameter has no effect if meta_key is not 685 * specified. Default: true. 703 686 * @return mixed The meta value(s) being requested. 704 687 */ … … 733 716 * metadata entries with the specified value. 734 717 * Otherwise, update all entries. 735 *736 718 * @return bool|int Returns false on failure. On successful 737 719 * update of existing metadata, returns true. On … … 758 740 * for the given key. If true, and the object already has a value for 759 741 * the key, no change will be made. Default: false. 760 *761 742 * @return int|bool The meta ID on successful update, false on failure. 762 743 */ -
trunk/src/bp-notifications/bp-notifications-loader.php
r10138 r10303 13 13 defined( 'ABSPATH' ) || exit; 14 14 15 /** 16 * Extends the component class to set up the Notifications component. 17 */ 15 18 class BP_Notifications_Component extends BP_Component { 16 19 … … 66 69 $bp = buddypress(); 67 70 68 // Define a slug, if necessary 71 // Define a slug, if necessary. 69 72 if ( ! defined( 'BP_NOTIFICATIONS_SLUG' ) ) { 70 73 define( 'BP_NOTIFICATIONS_SLUG', $this->id ); 71 74 } 72 75 73 // Global tables for the notifications component 76 // Global tables for the notifications component. 74 77 $global_tables = array( 75 78 'table_name' => $bp->table_prefix . 'bp_notifications', … … 103 106 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 104 107 105 // Determine user to use 108 // Determine user to use. 106 109 if ( bp_displayed_user_domain() ) { 107 110 $user_domain = bp_displayed_user_domain(); … … 116 119 $notifications_link = trailingslashit( $user_domain . $slug ); 117 120 118 // Only grab count if we're on a user page and current user has access 121 // Only grab count if we're on a user page and current user has access. 119 122 if ( bp_is_user() && bp_user_has_access() ) { 120 123 $count = bp_notifications_get_unread_notification_count( bp_displayed_user_id() ); … … 125 128 } 126 129 127 // Add 'Notifications' to the main navigation 130 // Add 'Notifications' to the main navigation. 128 131 $main_nav = array( 129 132 'name' => $nav_name, … … 136 139 ); 137 140 138 // Add the subnav items to the notifications nav item 141 // Add the subnav items to the notifications nav item. 139 142 $sub_nav[] = array( 140 143 'name' => _x( 'Unread', 'Notification screen nav', 'buddypress' ), … … 174 177 public function setup_admin_bar( $wp_admin_nav = array() ) { 175 178 176 // Menus for logged in user 179 // Menus for logged in user. 177 180 if ( is_user_logged_in() ) { 178 181 179 // Setup the logged in user variables 182 // Setup the logged in user variables. 180 183 $notifications_link = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() ); 181 184 182 // Pending notification requests 185 // Pending notification requests. 183 186 $count = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ); 184 187 if ( ! empty( $count ) ) { … … 190 193 } 191 194 192 // Add the "My Account" sub menus 195 // Add the "My Account" sub menus. 193 196 $wp_admin_nav[] = array( 194 197 'parent' => buddypress()->my_account_menu_id, … … 198 201 ); 199 202 200 // Unread 203 // Unread. 201 204 $wp_admin_nav[] = array( 202 205 'parent' => 'my-account-' . $this->id, … … 206 209 ); 207 210 208 // Read 211 // Read. 209 212 $wp_admin_nav[] = array( 210 213 'parent' => 'my-account-' . $this->id, … … 225 228 public function setup_title() { 226 229 227 // Adjust title 230 // Adjust title. 228 231 if ( bp_is_notifications_component() ) { 229 232 $bp = buddypress(); … … 251 254 public function setup_cache_groups() { 252 255 253 // Global groups 256 // Global groups. 254 257 wp_cache_add_global_groups( array( 255 258 'bp_notifications', -
trunk/src/bp-notifications/bp-notifications-template.php
r10248 r10303 266 266 public function __construct( $args = array() ) { 267 267 268 // Parse arguments 268 // Parse arguments. 269 269 $r = wp_parse_args( $args, array( 270 270 'id' => false, … … 286 286 ) ); 287 287 288 // Overrides 289 290 // Sort order direction 288 // Sort order direction. 291 289 $orders = array( 'ASC', 'DESC' ); 292 290 if ( ! empty( $_GET['sort_order'] ) && in_array( $_GET['sort_order'], $orders ) ) { … … 296 294 } 297 295 298 // Setup variables 296 // Setup variables. 299 297 $this->pag_arg = sanitize_key( $r['page_arg'] ); 300 298 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] ); … … 322 320 ); 323 321 324 // Setup the notifications to loop through 322 // Setup the notifications to loop through. 325 323 $this->notifications = BP_Notifications_Notification::get( $this->query_vars ); 326 324 $this->total_notification_count = BP_Notifications_Notification::get_total_count( $this->query_vars ); … … 457 455 $this->notification = $this->next_notification(); 458 456 459 // loop has just started457 // Loop has just started. 460 458 if ( 0 === $this->current_notification ) { 461 459 … … 492 490 * Default: 'npage'. 493 491 * } 494 *495 492 * @return bool 496 493 */ 497 494 function bp_has_notifications( $args = '' ) { 498 495 499 // Get the default is_new argument 496 // Get the default is_new argument. 500 497 if ( bp_is_current_action( 'unread' ) ) { 501 498 $is_new = 1; … … 503 500 $is_new = 0; 504 501 505 // not on a notifications page? default to fetch new notifications502 // Not on a notifications page? default to fetch new notifications. 506 503 } else { 507 504 $is_new = 1; 508 505 } 509 506 510 // Get the user ID 507 // Get the user ID. 511 508 if ( bp_displayed_user_id() ) { 512 509 $user_id = bp_displayed_user_id(); … … 515 512 } 516 513 517 // Parse the args 514 // Parse the args. 518 515 $r = bp_parse_args( $args, array( 519 516 'id' => false, … … 531 528 'per_page' => 25, 532 529 533 // these are additional arguments that are not available in534 // BP_Notifications_Notification::get() 530 // These are additional arguments that are not available in 531 // BP_Notifications_Notification::get(). 535 532 'max' => false, 536 533 'page_arg' => 'npage', 537 534 ), 'has_notifications' ); 538 535 539 // Get the notifications 536 // Get the notifications. 540 537 $query_loop = new BP_Notifications_Template( $r ); 541 538 542 // Setup the global query loop 539 // Setup the global query loop. 543 540 buddypress()->notifications->query_loop = $query_loop; 544 541 … … 757 754 function bp_get_the_notification_time_since() { 758 755 759 // Get the notified date 756 // Get the notified date. 760 757 $date_notified = bp_get_the_notification_date_notified(); 761 758 762 // Notified date has legitimate data 759 // Notified date has legitimate data. 763 760 if ( '0000-00-00 00:00:00' !== $date_notified ) { 764 761 $retval = bp_core_time_since( $date_notified ); 765 762 766 // Notified date is empty, so return a fun string 763 // Notified date is empty, so return a fun string. 767 764 } else { 768 765 $retval = __( 'Date not found', 'buddypress' ); … … 799 796 $notification = $bp->notifications->query_loop->notification; 800 797 801 // Callback function exists 798 // Callback function exists. 802 799 if ( isset( $bp->{ $notification->component_name }->notification_callback ) && is_callable( $bp->{ $notification->component_name }->notification_callback ) ) { 803 800 $description = call_user_func( $bp->{ $notification->component_name }->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 ); … … 807 804 $description = call_user_func( $bp->{ $notification->component_name }->format_notification_function, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 ); 808 805 809 // Allow non BuddyPress components to hook in 806 // Allow non BuddyPress components to hook in. 810 807 } else { 811 808 … … 843 840 function bp_get_the_notification_mark_read_link() { 844 841 845 // Start the output buffer 842 // Start the output buffer. 846 843 ob_start(); ?> 847 844 … … 874 871 /** 875 872 * Return the URL used for marking a single notification as read. 876 873 * 877 874 * @since 2.1.0 878 875 */ 879 876 function bp_get_the_notification_mark_read_url() { 880 877 881 // Get the notification ID 878 // Get the notification ID. 882 879 $id = bp_get_the_notification_id(); 883 880 884 // Get the args to add to the URL 881 // Get the args to add to the URL. 885 882 $args = array( 886 883 'action' => 'read', … … 888 885 ); 889 886 890 // Add the args to the URL 887 // Add the args to the URL. 891 888 $url = add_query_arg( $args, bp_get_notifications_unread_permalink() ); 892 889 893 // Add the nonce 890 // Add the nonce. 894 891 $url = wp_nonce_url( $url, 'bp_notification_mark_read_' . $id ); 895 892 … … 921 918 function bp_get_the_notification_mark_unread_link() { 922 919 923 // Start the output buffer 920 // Start the output buffer. 924 921 ob_start(); ?> 925 922 … … 952 949 /** 953 950 * Return the URL used for marking a single notification as unread. 954 951 * 955 952 * @since 2.1.0 956 953 */ 957 954 function bp_get_the_notification_mark_unread_url() { 958 955 959 // Get the notification ID 956 // Get the notification ID. 960 957 $id = bp_get_the_notification_id(); 961 958 962 // Get the args to add to the URL 959 // Get the args to add to the URL. 963 960 $args = array( 964 961 'action' => 'unread', … … 966 963 ); 967 964 968 // Add the args to the URL 965 // Add the args to the URL. 969 966 $url = add_query_arg( $args, bp_get_notifications_read_permalink() ); 970 967 971 // Add the nonce 968 // Add the nonce. 972 969 $url = wp_nonce_url( $url, 'bp_notification_mark_unread_' . $id ); 973 970 … … 1032 1029 function bp_get_the_notification_delete_link() { 1033 1030 1034 // Start the output buffer 1031 // Start the output buffer. 1035 1032 ob_start(); ?> 1036 1033 … … 1071 1068 function bp_get_the_notification_delete_url() { 1072 1069 1073 // URL to add nonce to 1070 // URL to add nonce to. 1074 1071 if ( bp_is_current_action( 'unread' ) ) { 1075 1072 $link = bp_get_notifications_unread_permalink(); … … 1078 1075 } 1079 1076 1080 // Get the ID 1077 // Get the ID. 1081 1078 $id = bp_get_the_notification_id(); 1082 1079 1083 // Get the args to add to the URL 1080 // Get the args to add to the URL. 1084 1081 $args = array( 1085 1082 'action' => 'delete', … … 1087 1084 ); 1088 1085 1089 // Add the args 1086 // Add the args. 1090 1087 $url = add_query_arg( $args, $link ); 1091 1088 1092 // Add the nonce 1089 // Add the nonce. 1093 1090 $url = wp_nonce_url( $url, 'bp_notification_delete_' . $id ); 1094 1091 … … 1106 1103 * Output the action links for the current notification. 1107 1104 * 1105 * @since 1.9.0 1106 * 1108 1107 * @param array|string $args Array of arguments. 1109 * @since 1.9.01110 1108 */ 1111 1109 function bp_the_notification_action_links( $args = '' ) { … … 1123 1121 * @type array $links Array of links to implode by 'sep'. 1124 1122 * } 1125 *1126 1123 * @return string HTML links for actions to take on single notifications. 1127 1124 */ 1128 1125 function bp_get_the_notification_action_links( $args = '' ) { 1129 1126 1130 // Parse 1127 // Parse. 1131 1128 $r = wp_parse_args( $args, array( 1132 1129 'before' => '', … … 1139 1136 ) ); 1140 1137 1141 // Build the links 1138 // Build the links. 1142 1139 $retval = $r['before'] . implode( $r['links'], $r['sep'] ) . $r['after']; 1143 1140 … … 1226 1223 function bp_notifications_sort_order_form() { 1227 1224 1228 // Setup local variables 1225 // Setup local variables. 1229 1226 $orders = array( 'DESC', 'ASC' ); 1230 1227 $selected = 'DESC'; 1231 1228 1232 // Check for a custom sort_order 1229 // Check for a custom sort_order. 1233 1230 if ( !empty( $_REQUEST['sort_order'] ) ) { 1234 1231 if ( in_array( $_REQUEST['sort_order'], $orders ) ) { -
trunk/src/bp-notifications/classes/class-bp-notifications-notification.php
r10248 r10303 7 7 * @package BuddyPress 8 8 * @subpackage NotificationsClasses 9 *10 9 * @since 1.9.0 11 10 */ … … 115 114 public function save() { 116 115 117 // Return value 116 // Return value. 118 117 $retval = false; 119 118 120 // Default data and format 119 // Default data and format. 121 120 $data = array( 122 121 'user_id' => $this->user_id, … … 141 140 do_action_ref_array( 'bp_notification_before_save', array( &$this ) ); 142 141 143 // Update 142 // Update. 144 143 if ( ! empty( $this->id ) ) { 145 144 $result = self::_update( $data, array( 'ID' => $this->id ), $data_format, array( '%d' ) ); 146 145 147 // Insert 146 // Insert. 148 147 } else { 149 148 $result = self::_insert( $data, $data_format ); 150 149 } 151 150 152 // Set the notification ID if successful 151 // Set the notification ID if successful. 153 152 if ( ! empty( $result ) && ! is_wp_error( $result ) ) { 154 153 global $wpdb; … … 163 162 * @since 2.0.0 164 163 * 165 * @param BP_Notifications_Notification $value Current instance of the notification item being saved. Passed by reference. 164 * @param BP_Notifications_Notification $value Current instance of the notification item being saved. 165 * Passed by reference. 166 166 */ 167 167 do_action_ref_array( 'bp_notification_after_save', array( &$this ) ); 168 168 169 // Return the result 169 // Return the result. 170 170 return $retval; 171 171 } … … 184 184 $bp = buddypress(); 185 185 186 // Look for a notification 186 // Look for a notification. 187 187 $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->notifications->table_name} WHERE id = %d", $this->id ) ); 188 188 189 // Setup the notification data 189 // Setup the notification data. 190 190 if ( ! empty( $notification ) && ! is_wp_error( $notification ) ) { 191 191 $this->item_id = $notification->item_id; … … 240 240 * @param array $data_format See {@link wpdb::insert()}. 241 241 * @param array $where_format See {@link wpdb::insert()}. 242 *243 242 * @return int|false The number of rows updated, or false on error. 244 243 */ … … 259 258 * BP_Notification_Notification object. 260 259 * @param array $where_format See {@link wpdb::insert()}. 261 *262 260 * @return int|false The number of rows updated, or false on error. 263 261 */ … … 281 279 * @param string $join_sql SQL JOIN fragment. 282 280 * @param string $meta_query_sql SQL meta query fragment. 283 *284 281 * @return string WHERE clause. 285 282 */ … … 290 287 $where = ''; 291 288 292 // id289 // The id. 293 290 if ( ! empty( $args['id'] ) ) { 294 291 $id_in = implode( ',', wp_parse_id_list( $args['id'] ) ); … … 296 293 } 297 294 298 // user_id295 // The user_id. 299 296 if ( ! empty( $args['user_id'] ) ) { 300 297 $user_id_in = implode( ',', wp_parse_id_list( $args['user_id'] ) ); … … 302 299 } 303 300 304 // item_id301 // The item_id. 305 302 if ( ! empty( $args['item_id'] ) ) { 306 303 $item_id_in = implode( ',', wp_parse_id_list( $args['item_id'] ) ); … … 308 305 } 309 306 310 // secondary_item_id307 // The secondary_item_id. 311 308 if ( ! empty( $args['secondary_item_id'] ) ) { 312 309 $secondary_item_id_in = implode( ',', wp_parse_id_list( $args['secondary_item_id'] ) ); … … 314 311 } 315 312 316 // component_name313 // The component_name. 317 314 if ( ! empty( $args['component_name'] ) ) { 318 315 if ( ! is_array( $args['component_name'] ) ) { … … 331 328 } 332 329 333 // component_action330 // The component_action. 334 331 if ( ! empty( $args['component_action'] ) ) { 335 332 if ( ! is_array( $args['component_action'] ) ) { … … 348 345 } 349 346 350 // is_new347 // If is_new. 351 348 if ( ! empty( $args['is_new'] ) && 'both' !== $args['is_new'] ) { 352 349 $where_conditions['is_new'] = "is_new = 1"; … … 355 352 } 356 353 357 // search_terms354 // The search_terms. 358 355 if ( ! empty( $args['search_terms'] ) ) { 359 356 $search_terms_like = '%' . bp_esc_like( $args['search_terms'] ) . '%'; … … 361 358 } 362 359 363 // date query360 // The date query. 364 361 if ( ! empty( $args['date_query'] ) ) { 365 362 $where_conditions['date_query'] = self::get_date_query_sql( $args['date_query'] ); 366 363 } 367 364 368 // meta query365 // The meta query. 369 366 if ( ! empty( $meta_query_sql['where'] ) ) { 370 367 $where_conditions['meta_query'] = $meta_query_sql['where']; … … 385 382 $where_conditions = apply_filters( 'bp_notifications_get_where_conditions', $where_conditions, $args, $select_sql, $from_sql, $join_sql, $meta_query_sql ); 386 383 387 // Custom WHERE 384 // Custom WHERE. 388 385 if ( ! empty( $where_conditions ) ) { 389 386 $where = 'WHERE ' . implode( ' AND ', $where_conditions ); … … 403 400 * @param array $args See {@link BP_Notifications_Notification::get()} 404 401 * for more details. 405 *406 402 * @return string ORDER BY clause. 407 403 */ 408 404 protected static function get_order_by_sql( $args = array() ) { 409 405 410 // Setup local variable 406 // Setup local variable. 411 407 $conditions = array(); 412 408 $retval = ''; 413 409 414 // Order by 410 // Order by. 415 411 if ( ! empty( $args['order_by'] ) ) { 416 412 $order_by = implode( ', ', (array) $args['order_by'] ); … … 418 414 } 419 415 420 // Sort order direction 416 // Sort order direction. 421 417 if ( ! empty( $args['sort_order'] ) && in_array( $args['sort_order'], array( 'ASC', 'DESC' ) ) ) { 422 418 $sort_order = $args['sort_order']; … … 424 420 } 425 421 426 // Custom ORDER BY 422 // Custom ORDER BY. 427 423 if ( ! empty( $conditions ) ) { 428 424 $retval = 'ORDER BY ' . implode( ' ', $conditions ); … … 441 437 * @param array $args See {@link BP_Notifications_Notification::get()} 442 438 * for more details. 443 * 444 * @return string LIMIT clause. 439 * @return string $retval LIMIT clause. 445 440 */ 446 441 protected static function get_paged_sql( $args = array() ) { 447 442 global $wpdb; 448 443 449 // Setup local variable 444 // Setup local variable. 450 445 $retval = ''; 451 446 452 // Custom LIMIT 447 // Custom LIMIT. 453 448 if ( ! empty( $args['page'] ) && ! empty( $args['per_page'] ) ) { 454 449 $page = absint( $args['page'] ); … … 500 495 * See {@BP_Notifications_Notification::get()} 501 496 * for a breakdown. 502 *503 497 * @return array Associative array of 'data' and 'format' args. 504 498 */ … … 509 503 ); 510 504 511 // id505 // The id. 512 506 if ( ! empty( $args['id'] ) ) { 513 507 $where_clauses['data']['id'] = absint( $args['id'] ); … … 515 509 } 516 510 517 // user_id511 // The user_id. 518 512 if ( ! empty( $args['user_id'] ) ) { 519 513 $where_clauses['data']['user_id'] = absint( $args['user_id'] ); … … 521 515 } 522 516 523 // item_id517 // The item_id. 524 518 if ( ! empty( $args['item_id'] ) ) { 525 519 $where_clauses['data']['item_id'] = absint( $args['item_id'] ); … … 527 521 } 528 522 529 // secondary_item_id523 // The secondary_item_id. 530 524 if ( ! empty( $args['secondary_item_id'] ) ) { 531 525 $where_clauses['data']['secondary_item_id'] = absint( $args['secondary_item_id'] ); … … 533 527 } 534 528 535 // component_name529 // The component_name. 536 530 if ( ! empty( $args['component_name'] ) ) { 537 531 $where_clauses['data']['component_name'] = $args['component_name']; … … 539 533 } 540 534 541 // component_action535 // The component_action. 542 536 if ( ! empty( $args['component_action'] ) ) { 543 537 $where_clauses['data']['component_action'] = $args['component_action']; … … 545 539 } 546 540 547 // is_new541 // If is_new. 548 542 if ( isset( $args['is_new'] ) ) { 549 543 $where_clauses['data']['is_new'] = ! empty( $args['is_new'] ) ? 1 : 0; … … 563 557 * @param int $user_id ID of the user being checked. 564 558 * @param int $notification_id ID of the notification being checked. 565 *566 559 * @return bool True if the notification belongs to the user, otherwise 567 560 * false. … … 580 573 * @since 2.3.0 581 574 * 582 * @param mixed $args575 * @param mixed $args Args to parse. 583 576 * @return array 584 577 */ … … 643 636 global $wpdb; 644 637 645 // Parse the arguments 638 // Parse the arguments. 646 639 $r = self::parse_args( $args ); 647 640 648 // Get BuddyPress 641 // Get BuddyPress. 649 642 $bp = buddypress(); 650 643 651 // METADATA 644 // METADATA. 652 645 $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] ); 653 646 654 // SELECT 647 // SELECT. 655 648 $select_sql = "SELECT *"; 656 649 657 // FROM 650 // FROM. 658 651 $from_sql = "FROM {$bp->notifications->table_name} n "; 659 652 660 // JOIN 653 // JOIN. 661 654 $join_sql = $meta_query_sql['join']; 662 655 663 // WHERE 656 // WHERE. 664 657 $where_sql = self::get_where_sql( array( 665 658 'id' => $r['id'], … … 674 667 ), $select_sql, $from_sql, $join_sql, $meta_query_sql ); 675 668 676 // ORDER BY 669 // ORDER BY. 677 670 $order_sql = self::get_order_by_sql( array( 678 671 'order_by' => $r['order_by'], … … 680 673 ) ); 681 674 682 // LIMIT %d, %d 675 // LIMIT %d, %d. 683 676 $pag_sql = self::get_paged_sql( array( 684 677 'page' => $r['page'], … … 686 679 ) ); 687 680 688 // Concatenate query parts 681 // Concatenate query parts. 689 682 $sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} {$order_sql} {$pag_sql}"; 690 683 … … 697 690 * @since 1.9.0 698 691 * 699 * @see BP_Notifications_Notification::get() for a description of 700 * arguments. 692 * @see BP_Notifications_Notification::get() for a description of arguments. 701 693 * 702 694 * @param array $args See {@link BP_Notifications_Notification::get()}. 703 *704 695 * @return int Count of located items. 705 696 */ … … 707 698 global $wpdb; 708 699 709 // Parse the arguments 700 // Parse the arguments. 710 701 $r = self::parse_args( $args ); 711 702 712 // Load BuddyPress 703 // Load BuddyPress. 713 704 $bp = buddypress(); 714 705 715 // METADATA 706 // METADATA. 716 707 $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] ); 717 708 718 // SELECT 709 // SELECT. 719 710 $select_sql = "SELECT COUNT(*)"; 720 711 721 // FROM 712 // FROM. 722 713 $from_sql = "FROM {$bp->notifications->table_name} n "; 723 714 724 // JOIN 715 // JOIN. 725 716 $join_sql = $meta_query_sql['join']; 726 717 727 // WHERE 718 // WHERE. 728 719 $where_sql = self::get_where_sql( array( 729 720 'id' => $r['id'], … … 738 729 ), $select_sql, $from_sql, $join_sql, $meta_query_sql ); 739 730 740 // Concatenate query parts 731 // Concatenate query parts. 741 732 $sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql}"; 742 733 743 // Return the queried results 734 // Return the queried results. 744 735 return $wpdb->get_var( $sql ); 745 736 } … … 758 749 * @param array $meta_query An array of meta_query filters. See the 759 750 * documentation for WP_Meta_Query for details. 760 *761 751 * @return array $sql_array 'join' and 'where' clauses. 762 752 */ 763 753 public static function get_meta_query_sql( $meta_query = array() ) { 764 754 765 // Default array keys & empty values 755 // Default array keys & empty values. 766 756 $sql_array = array( 767 757 'join' => '', … … 769 759 ); 770 760 771 // Bail if no meta query 761 // Bail if no meta query. 772 762 if ( empty( $meta_query ) ) { 773 763 return $sql_array; 774 764 } 775 765 776 // WP_Meta_Query expects the table name at $wpdb->notificationmeta 766 // WP_Meta_Query expects the table name at $wpdb->notificationmeta. 777 767 $GLOBALS['wpdb']->notificationmeta = buddypress()->notifications->table_name_meta; 778 768 … … 780 770 $meta_sql = $n_meta_query->get_sql( 'notification', 'n', 'id' ); 781 771 782 // Strip the leading AND - it's handled in get() 772 // Strip the leading AND - it's handled in get(). 783 773 $sql_array['where'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] ); 784 774 $sql_array['join'] = $meta_sql['join']; … … 800 790 * @param array $date_query An array of date_query parameters. See the 801 791 * documentation for the first parameter of WP_Date_Query. 802 *803 792 * @return string 804 793 */ 805 794 public static function get_date_query_sql( $date_query = array() ) { 806 795 807 // Bail if not a proper date query format 796 // Bail if not a proper date query format. 808 797 if ( empty( $date_query ) || ! is_array( $date_query ) ) { 809 798 return ''; 810 799 } 811 800 812 // Date query 801 // Date query. 813 802 $date_query = new BP_Date_Query( $date_query, 'date_recorded' ); 814 803 815 // Strip the leading AND - it's handled in get() 804 // Strip the leading AND - it's handled in get(). 816 805 return preg_replace( '/^\sAND/', '', $date_query->get_sql() ); 817 806 } … … 827 816 * @param array $update_args Associative array of fields to update, 828 817 * and the values to update them to. Of the format 829 * array( 'user_id' => 4, 'component_name' => 'groups', ) 818 * array( 'user_id' => 4, 'component_name' => 'groups', ). 830 819 * @param array $where_args Associative array of columns/values, to 831 820 * determine which rows should be updated. Of the format 832 * array( 'item_id' => 7, 'component_action' => 'members', ) 833 * 821 * array( 'item_id' => 7, 'component_action' => 'members', ). 834 822 * @return int|bool Number of rows updated on success, false on failure. 835 823 */ … … 866 854 * @param array $args Associative array of columns/values, to determine 867 855 * which rows should be deleted. Of the format 868 * array( 'item_id' => 7, 'component_action' => 'members', ) 869 * 856 * array( 'item_id' => 7, 'component_action' => 'members', ). 870 857 * @return int|bool Number of rows deleted on success, false on failure. 871 858 */ … … 898 885 * 899 886 * @param int $id ID of the notification item to be deleted. 900 *901 887 * @return bool True on success, false on failure. 902 888 */ … … 916 902 * @param string $status Optional. Status of notifications to fetch. 917 903 * 'is_new' to get only unread items, 'all' to get all. 918 *919 904 * @return array Associative array of notification items. 920 905 */ … … 933 918 * @param int $user_id ID of the user whose notifications are being 934 919 * fetched. 935 *936 920 * @return array Associative array of unread notification items. 937 921 */ … … 950 934 * @param int $user_id ID of the user whose notifications are being 951 935 * fetched. 952 *953 936 * @return array Associative array of unread notification items. 954 937 */ … … 994 977 $notifications = self::get( $r ); 995 978 996 // Bail if no notifications 979 // Bail if no notifications. 997 980 if ( empty( $notifications ) ) { 998 981 return false; … … 1017 1000 * @param string $component_action Name of the component action. 1018 1001 * @param int $secondary_item_id The ID of the secondary item. 1019 *1020 1002 * @return bool|int False on failure to update. ID on success. 1021 1003 */ 1022 1004 public static function mark_all_for_user( $user_id, $is_new = 0, $item_id = 0, $component_name = '', $component_action = '', $secondary_item_id = 0 ) { 1023 1005 1024 // Values to be updated 1006 // Values to be updated. 1025 1007 $update_args = array( 1026 1008 'is_new' => $is_new, 1027 1009 ); 1028 1010 1029 // WHERE clauses 1011 // WHERE clauses. 1030 1012 $where_args = array( 1031 1013 'user_id' => $user_id, … … 1061 1043 * @param string $component_action Name of the component action. 1062 1044 * @param int $secondary_item_id The ID of the secondary item. 1063 *1064 1045 * @return bool|int 1065 1046 */ 1066 1047 public static function mark_all_from_user( $user_id, $is_new = 0, $component_name = '', $component_action = '', $secondary_item_id = 0 ) { 1067 1048 1068 // Values to be updated 1049 // Values to be updated. 1069 1050 $update_args = array( 1070 1051 'is_new' => $is_new, 1071 1052 ); 1072 1053 1073 // WHERE clauses 1054 // WHERE clauses. 1074 1055 $where_args = array( 1075 1056 'item_id' => $user_id, … … 1106 1087 * @param int $secondary_item_id Optional. ID of the secondary 1107 1088 * associated item. 1108 *1109 1089 * @return bool|int 1110 1090 */ 1111 1091 public static function mark_all_by_type( $item_id, $is_new = 0, $component_name = '', $component_action = '', $secondary_item_id = 0 ) { 1112 1092 1113 // Values to be updated 1093 // Values to be updated. 1114 1094 $update_args = array( 1115 1095 'is_new' => $is_new, 1116 1096 ); 1117 1097 1118 // WHERE clauses 1098 // WHERE clauses. 1119 1099 $where_args = array( 1120 1100 'item_id' => $item_id,
Note: See TracChangeset
for help on using the changeset viewer.