Changeset 3728 for trunk/bp-friends.php
- Timestamp:
- 01/18/2011 12:53:31 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-friends.php
r3633 r3728 1 1 <?php 2 2 3 // Required Files 4 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-classes.php' ); 5 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-templatetags.php' ); 6 3 7 define ( 'BP_FRIENDS_DB_VERSION', '1800' ); 4 8 5 / * Define the slug for the component */9 // Define the slug for the component 6 10 if ( !defined( 'BP_FRIENDS_SLUG' ) ) 7 11 define ( 'BP_FRIENDS_SLUG', 'friends' ); 8 12 9 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-classes.php' );10 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-templatetags.php' );11 12 13 function friends_setup_globals() { 13 14 global $bp; 14 15 15 / * For internal identification */16 // For internal identification 16 17 $bp->friends->id = 'friends'; 17 18 19 // Slug 18 20 $bp->friends->slug = BP_FRIENDS_SLUG; 19 21 22 // Table 20 23 $bp->friends->table_name = $bp->table_prefix . 'bp_friends'; 21 24 25 // Notifications 22 26 $bp->friends->format_notification_function = 'friends_format_notifications'; 23 27 24 / * Register this in the active components array */28 // Register this in the active components array 25 29 $bp->active_components[$bp->friends->slug] = $bp->friends->id; 26 30 … … 32 36 global $bp; 33 37 34 / * Add 'Friends' to the main navigation */38 // Add 'Friends' to the main navigation 35 39 bp_core_new_nav_item( array( 'name' => sprintf( __( 'Friends <span>(%d)</span>', 'buddypress' ), friends_get_total_friend_count() ), 'slug' => $bp->friends->slug, 'position' => 60, 'screen_function' => 'friends_screen_my_friends', 'default_subnav_slug' => 'my-friends', 'item_css_id' => $bp->friends->id ) ); 36 40 37 41 $friends_link = $bp->loggedin_user->domain . $bp->friends->slug . '/'; 38 42 39 / * Add the subnav items to the friends nav item */40 bp_core_new_subnav_item( array( 'name' => __( 'My Friends', 'buddypress' ), 'slug' => 'my-friends', 'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_my_friends', 'position' => 10, 'item_css_id' => 'friends-my-friends' ) );41 bp_core_new_subnav_item( array( 'name' => __( 'Requests', 'buddypress' ), 'slug' => 'requests', 'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_requests', 'position' => 20, 'user_has_access' => bp_is_my_profile()) );43 // Add the subnav items to the friends nav item 44 bp_core_new_subnav_item( array( 'name' => __( 'My Friends', 'buddypress' ), 'slug' => 'my-friends', 'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_my_friends', 'position' => 10, 'item_css_id' => 'friends-my-friends' ) ); 45 bp_core_new_subnav_item( array( 'name' => __( 'Requests', 'buddypress' ), 'slug' => 'requests', 'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_requests', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) ); 42 46 43 47 if ( $bp->current_component == $bp->friends->slug ) { … … 77 81 78 82 if ( isset( $bp->action_variables[0] ) && isset( $bp->action_variables[1] ) && 'accept' == $bp->action_variables[0] && is_numeric( $bp->action_variables[1] ) ) { 79 / * Check the nonce */83 // Check the nonce 80 84 check_admin_referer( 'friends_accept_friendship' ); 81 85 … … 88 92 89 93 } elseif ( isset( $bp->action_variables[0] ) && isset( $bp->action_variables[1] ) && 'reject' == $bp->action_variables[0] && is_numeric( $bp->action_variables[1] ) ) { 90 / * Check the nonce */94 // Check the nonce 91 95 check_admin_referer( 'friends_reject_friendship' ); 92 96 … … 110 114 global $bp; 111 115 112 $send_requests = get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_request', true ); 113 if ( !$send_requests ) 114 $send_requests = 'yes'; 115 116 $accept_requests = get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_accepted', true ); 117 if ( !$accept_requests ) 116 117 if ( !$send_requests = get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_request', true ) ) 118 $send_requests = 'yes'; 119 120 if ( !$accept_requests = get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_accepted', true ) ) 118 121 $accept_requests = 'yes'; 119 122 ?> 123 120 124 <table class="notification-settings zebra" id="friends-notification-settings"> 121 125 <thead> … … 143 147 144 148 <?php do_action( 'friends_screen_notification_settings' ); ?> 149 145 150 </tbody> 146 151 </table> 152 147 153 <?php 148 154 } … … 184 190 bp_core_add_message( __( 'Friendship requested', 'buddypress' ) ); 185 191 } 192 186 193 } else if ( 'is_friend' == $friendship_status ) { 187 194 bp_core_add_message( __( 'You are already friends with this user', 'buddypress' ), 'error' ); … … 222 229 bp_core_add_message( __( 'Friendship canceled', 'buddypress' ) ); 223 230 } 231 224 232 } else if ( 'is_friends' == $friendship_status ) { 225 233 bp_core_add_message( __( 'You are not yet friends with this user', 'buddypress' ), 'error' ); … … 248 256 return false; 249 257 250 $defaults = array (251 'user_id' => $bp->loggedin_user->id,252 'action' => '',253 'content' => '',254 'primary_link' => '',255 'component' => $bp->friends->id,256 'type' => false,257 'item_id' => false,258 $defaults = array ( 259 'user_id' => $bp->loggedin_user->id, 260 'action' => '', 261 'content' => '', 262 'primary_link' => '', 263 'component' => $bp->friends->id, 264 'type' => false, 265 'item_id' => false, 258 266 'secondary_item_id' => false, 259 'recorded_time' => bp_core_current_time(),260 'hide_sitewide' => false267 'recorded_time' => bp_core_current_time(), 268 'hide_sitewide' => false 261 269 ); 262 270 … … 300 308 return apply_filters( 'bp_friends_single_friendship_accepted_notification', '<a href="' . $user_url . '?new" title="' . $user_fullname .'\'s profile">' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $user_fullname ) . '</a>', $user_fullname ); 301 309 } 302 break;310 break; 303 311 304 312 case 'friendship_request': … … 310 318 return apply_filters( 'bp_friends_single_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests/?new" title="' . __( 'Friendship requests', 'buddypress' ) . '">' . sprintf( __('You have a friendship request from %s', 'buddypress' ), $user_fullname ) . '</a>', $user_fullname ); 311 319 } 312 break;320 break; 313 321 } 314 322 … … 337 345 338 346 $friendship->initiator_user_id = $initiator_userid; 339 $friendship->friend_user_id = $friend_userid;340 $friendship->is_confirmed = 0;341 $friendship->is_limited = 0;342 $friendship->date_created = bp_core_current_time();347 $friendship->friend_user_id = $friend_userid; 348 $friendship->is_confirmed = 0; 349 $friendship->is_limited = 0; 350 $friendship->date_created = bp_core_current_time(); 343 351 344 352 if ( $force_accept ) … … 370 378 371 379 $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid ); 372 $friendship = new BP_Friends_Friendship( $friendship_id );380 $friendship = new BP_Friends_Friendship( $friendship_id ); 373 381 374 382 // Remove the activity stream item for the user who canceled the friendship … … 427 435 428 436 do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id ); 437 429 438 return true; 430 439 } … … 456 465 } 457 466 467 // Returns - 'is_friend', 'not_friends', 'pending' 458 468 function friends_check_friendship_status( $user_id, $possible_friend_id ) { 459 /* Returns - 'is_friend', 'not_friends', 'pending' */460 469 return BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ); 461 470 } 462 471 463 function friends_get_total_friend_count( $user_id = false) {472 function friends_get_total_friend_count( $user_id = 0 ) { 464 473 global $bp; 465 474 … … 504 513 } 505 514 506 function friends_get_recently_active( $user_id, $per_page = false, $page = false, $filter = false) {515 function friends_get_recently_active( $user_id, $per_page = 0, $page = 0, $filter = '' ) { 507 516 return apply_filters( 'friends_get_recently_active', BP_Core_User::get_users( 'active', $per_page, $page, $user_id, $filter ) ); 508 517 } 509 518 510 function friends_get_alphabetically( $user_id, $per_page = false, $page = false, $filter = false) {519 function friends_get_alphabetically( $user_id, $per_page = 0, $page = 0, $filter = '' ) { 511 520 return apply_filters( 'friends_get_alphabetically', BP_Core_User::get_users( 'alphabetical', $per_page, $page, $user_id, $filter ) ); 512 521 } 513 522 514 function friends_get_newest( $user_id, $per_page = false, $page = false, $filter = false) {523 function friends_get_newest( $user_id, $per_page = 0, $page = 0, $filter = '' ) { 515 524 return apply_filters( 'friends_get_newest', BP_Core_User::get_users( 'newest', $per_page, $page, $user_id, $filter ) ); 516 525 } … … 520 529 } 521 530 522 function friends_get_friends_invite_list( $user_id = false) {531 function friends_get_friends_invite_list( $user_id = 0 ) { 523 532 global $bp; 524 533 … … 549 558 } 550 559 551 function friends_search_users( $search_terms, $user_id, $pag_num = false, $pag_page = false) {560 function friends_search_users( $search_terms, $user_id, $pag_num = 0, $pag_page = 0 ) { 552 561 global $bp; 553 562 … … 557 566 return false; 558 567 559 for ( $i = 0; $i < count( $user_ids); $i++ ) {568 for ( $i = 0; $i < count( $user_ids ); $i++ ) 560 569 $users[] = new BP_Core_User($user_ids[$i]); 561 } 562 563 return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count($search_terms) ); 570 571 return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count( $search_terms ) ); 564 572 } 565 573 … … 584 592 BP_Friends_Friendship::delete_all_for_user($user_id); 585 593 586 / * Remove usermeta */594 // Remove usermeta 587 595 delete_user_meta( $user_id, 'total_friend_count' ); 588 596 589 / * Remove friendship requests FROM user */597 // Remove friendship requests FROM user 590 598 bp_core_delete_notifications_from_user( $user_id, $bp->friends->id, 'friendship_request' ); 591 599 592 600 do_action( 'friends_remove_data', $user_id ); 593 601 } 594 add_action( 'wpmu_delete_user', 'friends_remove_data' );595 add_action( 'delete_user', 'friends_remove_data' );602 add_action( 'wpmu_delete_user', 'friends_remove_data' ); 603 add_action( 'delete_user', 'friends_remove_data' ); 596 604 add_action( 'bp_make_spam_user', 'friends_remove_data' ); 597 605 … … 608 616 return false; 609 617 610 wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' );611 wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id,'bp' );618 wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' ); 619 wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' ); 612 620 wp_cache_delete( 'bp_total_friend_count_' . $friendship->initiator_user_id, 'bp' ); 613 wp_cache_delete( 'bp_total_friend_count_' . $friendship->friend_user_id, 'bp' );621 wp_cache_delete( 'bp_total_friend_count_' . $friendship->friend_user_id, 'bp' ); 614 622 } 615 623 … … 624 632 // List actions to clear object caches on 625 633 add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' ); 626 add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' );634 add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' ); 627 635 628 636 // List actions to clear super cached pages on, if super cache is installed 629 add_action( 'friends_friendship_rejected', 'bp_core_clear_cache' );630 add_action( 'friends_friendship_accepted', 'bp_core_clear_cache' );631 add_action( 'friends_friendship_deleted', 'bp_core_clear_cache' );637 add_action( 'friends_friendship_rejected', 'bp_core_clear_cache' ); 638 add_action( 'friends_friendship_accepted', 'bp_core_clear_cache' ); 639 add_action( 'friends_friendship_deleted', 'bp_core_clear_cache' ); 632 640 add_action( 'friends_friendship_requested', 'bp_core_clear_cache' ); 633 641
Note: See TracChangeset
for help on using the changeset viewer.