Changeset 2168 for trunk/bp-friends.php
- Timestamp:
- 12/14/2009 03:24:05 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/bp-friends.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-friends.php
r2120 r2168 9 9 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-classes.php' ); 10 10 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-templatetags.php' ); 11 12 /* Include deprecated functions if settings allow */13 if ( !defined( 'BP_IGNORE_DEPRECATED' ) )14 require ( BP_PLUGIN_DIR . '/bp-friends/deprecated/bp-friends-deprecated.php' );15 11 16 12 function friends_install() { … … 71 67 72 68 /* Add 'Friends' to the main navigation */ 73 bp_core_new_nav_item( array( 'name' => __('Friends', 'buddypress'), 'slug' => $bp->friends->slug, 'position' => 60, 'screen_function' => 'friends_screen_my_friends', 'default_subnav_slug' => 'my-friends', 'item_css_id' => $bp->friends->id ) );69 bp_core_new_nav_item( array( 'name' => sprintf( __( 'Friends (%d)', '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 ) ); 74 70 75 71 $friends_link = $bp->loggedin_user->domain . $bp->friends->slug . '/'; … … 110 106 do_action( 'friends_screen_my_friends' ); 111 107 112 bp_core_load_template( apply_filters( 'friends_template_my_friends', ' friends/index' ) );108 bp_core_load_template( apply_filters( 'friends_template_my_friends', 'members/single/friends' ) ); 113 109 } 114 110 … … 131 127 check_admin_referer( 'friends_reject_friendship' ); 132 128 133 134 129 if ( friends_reject_friendship( $bp->action_variables[1] ) ) { 135 130 bp_core_add_message( __( 'Friendship rejected', 'buddypress' ) ); … … 142 137 do_action( 'friends_screen_requests' ); 143 138 144 bp_core_load_template( apply_filters( 'friends_template_requests', 'friends/requests' ) ); 145 } 146 147 function friends_screen_friend_finder() { 148 do_action( 'friends_screen_friend_finder' ); 149 bp_core_load_template( apply_filters( 'friends_template_friend_finder', 'friends/friend-finder' ) ); 139 bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/friends' ) ); 150 140 } 151 141 … … 354 344 */ 355 345 356 function friends_check_user_has_friends( $user_id ) {357 $friend_count = get_usermeta( $user_id, 'total_friend_count');358 359 if ( empty( $friend_count ) )360 return false;361 362 if ( !(int)$friend_count )363 return false;364 365 return true;366 }367 368 function friends_get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false, $filter = false ) {369 return BP_Friends_Friendship::get_friend_user_ids( $user_id, $friend_requests_only, $assoc_arr, $filter );370 }371 372 function friends_get_friendship_ids( $user_id, $friend_requests_only = false ) {373 return BP_Friends_Friendship::get_friendship_ids( $user_id, $friend_requests_only );374 }375 376 function friends_search_friends( $search_terms, $user_id, $pag_num = 10, $pag_page = 1 ) {377 return BP_Friends_Friendship::search_friends( $search_terms, $user_id, $pag_num, $pag_page );378 }379 380 function friends_get_friendship_requests( $user_id ) {381 $fship_ids = friends_get_friendship_ids( $user_id, true );382 383 return array( 'requests' => $fship_ids, 'total' => count($fship_ids) );384 }385 386 function friends_get_recently_active( $user_id, $pag_num = false, $pag_page = false, $filter = false ) {387 if ( $filter )388 $friend_ids = friends_search_friends( $filter, $user_id, false );389 else390 $friend_ids = friends_get_friend_user_ids( $user_id );391 392 if ( !$friend_ids )393 return false;394 395 if ( $filter )396 $friend_ids = $friend_ids['friends'];397 398 $ids_and_activity = friends_get_bulk_last_active( implode( ',', (array)$friend_ids ) );399 400 if ( !$ids_and_activity )401 return false;402 403 $total_friends = count( $ids_and_activity );404 405 if ( $pag_num && $pag_page )406 return array( 'friends' => array_slice( $ids_and_activity, intval( ( $pag_page - 1 ) * $pag_num), intval( $pag_num ) ), 'total' => $total_friends );407 else408 return array( 'friends' => $ids_and_activity, 'total' => $total_friends );409 }410 411 function friends_get_alphabetically( $user_id, $pag_num = false, $pag_page = false, $filter = false ) {412 if ( $filter )413 $friend_ids = friends_search_friends( $filter, $user_id, false );414 else415 $friend_ids = friends_get_friend_user_ids( $user_id );416 417 if ( !$friend_ids )418 return false;419 420 if ( $filter )421 $friend_ids = $friend_ids['friends'];422 423 $sorted_ids = BP_Friends_Friendship::sort_by_name( implode( ',', $friend_ids ) );424 425 if ( !$sorted_ids )426 return false;427 428 $total_friends = count( $sorted_ids );429 430 if ( $pag_num && $pag_page )431 return array( 'friends' => array_slice( $sorted_ids, intval( ( $pag_page - 1 ) * $pag_num), intval( $pag_num ) ), 'total' => $total_friends );432 else433 return array( 'friends' => $sorted_ids, 'total' => $total_friends );434 }435 436 function friends_get_newest( $user_id, $pag_num = false, $pag_page = false, $filter = false ) {437 if ( $filter )438 $friend_ids = friends_search_friends( $filter, $user_id, false );439 else440 $friend_ids = friends_get_friend_user_ids( $user_id );441 442 if ( !$friend_ids )443 return false;444 445 if ( $filter )446 $friend_ids = $friend_ids['friends'];447 448 $total_friends = count( $friend_ids );449 450 if ( $pag_num && $pag_page )451 return array( 'friends' => array_slice( $friend_ids, intval( ( $pag_page - 1 ) * $pag_num), intval( $pag_num ) ), 'total' => $total_friends );452 else453 return array( 'friends' => $friend_ids, 'total' => $total_friends );454 }455 456 function friends_get_bulk_last_active( $friend_ids ) {457 return BP_Friends_Friendship::get_bulk_last_active( $friend_ids );458 }459 460 function friends_get_friends_list( $user_id ) {461 global $bp;462 463 $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );464 465 if ( !$friend_ids )466 return false;467 468 for ( $i = 0; $i < count($friend_ids); $i++ ) {469 if ( function_exists('bp_user_fullname') )470 $display_name = bp_core_get_user_displayname( $friend_ids[$i] );471 472 if ( $display_name != ' ' ) {473 $friends[] = array(474 'id' => $friend_ids[$i],475 'full_name' => $display_name476 );477 }478 }479 480 if ( $friends && is_array($friends) )481 usort($friends, 'friends_sort_by_name');482 483 if ( !$friends )484 return false;485 486 return $friends;487 }488 489 function friends_sort_by_name($a, $b) {490 return strcasecmp($a['full_name'], $b['full_name']);491 }492 493 function friends_get_friends_invite_list( $user_id = false, $group_id ) {494 global $bp;495 496 if ( !$user_id )497 $user_id = $bp->loggedin_user->id;498 499 $friend_ids = friends_get_alphabetically( $user_id );500 501 if ( (int) $friend_ids['total'] < 1 )502 return false;503 504 for ( $i = 0; $i < count($friend_ids['friends']); $i++ ) {505 if ( groups_check_user_has_invite( $friend_ids['friends'][$i]->user_id, $group_id ) || groups_is_user_member( $friend_ids['friends'][$i]->user_id, $group_id ) )506 continue;507 508 $display_name = bp_core_get_user_displayname( $friend_ids['friends'][$i]->user_id );509 510 if ( $display_name != ' ' ) {511 $friends[] = array(512 'id' => $friend_ids['friends'][$i]->user_id,513 'full_name' => $display_name514 );515 }516 }517 518 if ( !$friends )519 return false;520 521 return $friends;522 }523 524 function friends_count_invitable_friends( $user_id, $group_id ) {525 return BP_Friends_Friendship::get_invitable_friend_count( $user_id, $group_id );526 }527 528 function friends_get_friend_count_for_user( $user_id ) {529 return BP_Friends_Friendship::total_friend_count( $user_id );530 }531 532 function friends_search_users( $search_terms, $user_id, $pag_num = false, $pag_page = false ) {533 global $bp;534 535 $user_ids = BP_Friends_Friendship::search_users( $search_terms, $user_id, $pag_num, $pag_page );536 537 if ( !$user_ids )538 return false;539 540 for ( $i = 0; $i < count($user_ids); $i++ ) {541 $users[] = new BP_Core_User($user_ids[$i]);542 }543 544 return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count($search_terms) );545 }546 547 function friends_check_friendship( $user_id, $possible_friend_id ) {548 global $bp;549 550 if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) )551 return true;552 553 return false;554 }555 556 346 function friends_add_friend( $initiator_userid, $friend_userid, $force_accept = false ) { 557 347 global $bp; … … 676 466 } 677 467 468 function friends_check_friendship( $user_id, $possible_friend_id ) { 469 global $bp; 470 471 if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) ) 472 return true; 473 474 return false; 475 } 476 477 function friends_get_total_friend_count( $user_id = false ) { 478 global $bp; 479 480 if ( !$user_id ) 481 $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id; 482 483 return apply_filters( 'friends_get_total_friend_count', get_usermeta( $user_id, 'total_friend_count' ) ); 484 } 485 486 function friends_check_user_has_friends( $user_id ) { 487 $friend_count = friends_get_total_friend_count( $user_id ); 488 489 if ( empty( $friend_count ) ) 490 return false; 491 492 if ( !(int)$friend_count ) 493 return false; 494 495 return true; 496 } 497 498 function friends_get_friendship_id( $initiator_user_id, $friend_user_id ) { 499 return BP_Friends_Friendship::get_friendship_id( $initiator_user_id, $friend_user_id ); 500 } 501 502 function friends_get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false, $filter = false ) { 503 return BP_Friends_Friendship::get_friend_user_ids( $user_id, $friend_requests_only, $assoc_arr, $filter ); 504 } 505 506 function friends_search_friends( $search_terms, $user_id, $pag_num = 10, $pag_page = 1 ) { 507 return BP_Friends_Friendship::search_friends( $search_terms, $user_id, $pag_num, $pag_page ); 508 } 509 510 function friends_get_friendship_request_user_ids( $user_id ) { 511 return BP_Friends_Friendship::get_friendship_request_user_ids( $user_id ); 512 } 513 514 function friends_get_recently_active( $user_id, $per_page = false, $page = false, $filter = false ) { 515 return apply_filters( 'friends_get_recently_active', BP_Core_User::get_users( 'active', $per_page, $page, $user_id, $filter ) ); 516 } 517 518 function friends_get_alphabetically( $user_id, $per_page = false, $page = false, $filter = false ) { 519 return apply_filters( 'friends_get_alphabetically', BP_Core_User::get_users( 'alphabetical', $per_page, $page, $user_id, $filter ) ); 520 } 521 522 function friends_get_newest( $user_id, $per_page = false, $page = false, $filter = false ) { 523 return apply_filters( 'friends_get_newest', BP_Core_User::get_users( 'newest', $per_page, $page, $user_id, $filter ) ); 524 } 525 526 function friends_get_bulk_last_active( $friend_ids ) { 527 return BP_Friends_Friendship::get_bulk_last_active( $friend_ids ); 528 } 529 530 function friends_get_friends_list( $user_id ) { 531 global $bp; 532 533 $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ); 534 535 if ( !$friend_ids ) 536 return false; 537 538 for ( $i = 0; $i < count($friend_ids); $i++ ) { 539 if ( function_exists('bp_user_fullname') ) 540 $display_name = bp_core_get_user_displayname( $friend_ids[$i] ); 541 542 if ( $display_name != ' ' ) { 543 $friends[] = array( 544 'id' => $friend_ids[$i], 545 'full_name' => $display_name 546 ); 547 } 548 } 549 550 if ( $friends && is_array($friends) ) 551 usort($friends, 'friends_sort_by_name'); 552 553 if ( !$friends ) 554 return false; 555 556 return $friends; 557 } 558 559 function friends_sort_by_name($a, $b) { 560 return strcasecmp($a['full_name'], $b['full_name']); 561 } 562 563 function friends_get_friends_invite_list( $user_id = false, $group_id ) { 564 global $bp; 565 566 if ( !$user_id ) 567 $user_id = $bp->loggedin_user->id; 568 569 $friend_ids = friends_get_alphabetically( $user_id ); 570 571 if ( (int) $friend_ids['total'] < 1 ) 572 return false; 573 574 for ( $i = 0; $i < count($friend_ids['friends']); $i++ ) { 575 if ( groups_check_user_has_invite( $friend_ids['friends'][$i]->user_id, $group_id ) || groups_is_user_member( $friend_ids['friends'][$i]->user_id, $group_id ) ) 576 continue; 577 578 $display_name = bp_core_get_user_displayname( $friend_ids['friends'][$i]->user_id ); 579 580 if ( $display_name != ' ' ) { 581 $friends[] = array( 582 'id' => $friend_ids['friends'][$i]->user_id, 583 'full_name' => $display_name 584 ); 585 } 586 } 587 588 if ( !$friends ) 589 return false; 590 591 return $friends; 592 } 593 594 function friends_count_invitable_friends( $user_id, $group_id ) { 595 return BP_Friends_Friendship::get_invitable_friend_count( $user_id, $group_id ); 596 } 597 598 function friends_get_friend_count_for_user( $user_id ) { 599 return BP_Friends_Friendship::total_friend_count( $user_id ); 600 } 601 602 function friends_search_users( $search_terms, $user_id, $pag_num = false, $pag_page = false ) { 603 global $bp; 604 605 $user_ids = BP_Friends_Friendship::search_users( $search_terms, $user_id, $pag_num, $pag_page ); 606 607 if ( !$user_ids ) 608 return false; 609 610 for ( $i = 0; $i < count($user_ids); $i++ ) { 611 $users[] = new BP_Core_User($user_ids[$i]); 612 } 613 614 return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count($search_terms) ); 615 } 616 678 617 function friends_is_friendship_confirmed( $friendship_id ) { 679 618 $friendship = new BP_Friends_Friendship( $friendship_id ); … … 691 630 } 692 631 632 /** 633 * friends_filter_template_paths() 634 * 635 * Add fallback for the bp-sn-parent theme template locations used in BuddyPress versions 636 * older than 1.2. 637 * 638 * @package BuddyPress Core 639 */ 640 function friends_filter_template_paths() { 641 if ( 'bp-sn-parent' != basename( TEMPLATEPATH ) && !defined( 'BP_CLASSIC_TEMPLATE_STRUCTURE' ) ) 642 return false; 643 644 add_filter( 'friends_template_my_friends', create_function( '', 'return "friends/index";' ) ); 645 add_filter( 'friends_template_requests', create_function( '', 'return "friends/requests";' ) ); 646 } 647 add_action( 'init', 'friends_filter_template_paths' ); 648 693 649 function friends_remove_data( $user_id ) { 694 650 BP_Friends_Friendship::delete_all_for_user($user_id);
Note: See TracChangeset
for help on using the changeset viewer.