Changeset 10323
- Timestamp:
- 11/02/2015 02:07:44 AM (9 years ago)
- Location:
- trunk/src/bp-friends
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-friends/bp-friends-activity.php
r10147 r10323 91 91 $bp = buddypress(); 92 92 93 // These two added in BP 1.6 93 // These two added in BP 1.6. 94 94 bp_activity_set_action( 95 95 $bp->friends->id, … … 110 110 ); 111 111 112 // < BP 1.6 backpat 112 // < BP 1.6 backpat. 113 113 bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) ); 114 114 … … 129 129 * @param string $action Activity action string. 130 130 * @param object $activity Activity data. 131 *132 131 * @return string $action Formatted activity action. 133 132 */ … … 140 139 // Backward compatibility for legacy filter 141 140 // The old filter has the $friendship object passed to it. We want to 142 // avoid having to build this object if it's not necessary 141 // avoid having to build this object if it's not necessary. 143 142 if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) { 144 143 $friendship = new BP_Friends_Friendship( $activity->item_id ); … … 164 163 * @param string $action Static activity action. 165 164 * @param object $activity Activity data. 166 *167 165 * @return string $action Formatted activity action. 168 166 */ … … 175 173 // Backward compatibility for legacy filter 176 174 // The old filter has the $friendship object passed to it. We want to 177 // avoid having to build this object if it's not necessary 175 // avoid having to build this object if it's not necessary. 178 176 if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) { 179 177 $friendship = new BP_Friends_Friendship( $activity->item_id ); … … 200 198 * 201 199 * @param array $activities Array of activity items. 202 *203 200 * @return array 204 201 */ … … 219 216 220 217 if ( ! empty( $friend_ids ) ) { 221 // Fire a user query to prime user caches 218 // Fire a user query to prime user caches. 222 219 new BP_User_Query( array( 223 220 'user_ids' => $friend_ids, … … 238 235 * @since 2.2.0 239 236 * 240 * @param array $retval Empty array by default 241 * @param array $filter Current activity arguments 242 * 237 * @param array $retval Empty array by default. 238 * @param array $filter Current activity arguments. 243 239 * @return array 244 240 */ 245 241 function bp_friends_filter_activity_scope( $retval = array(), $filter = array() ) { 246 242 247 // Determine the user_id 243 // Determine the user_id. 248 244 if ( ! empty( $filter['user_id'] ) ) { 249 245 $user_id = $filter['user_id']; … … 254 250 } 255 251 256 // Determine friends of user 252 // Determine friends of user. 257 253 $friends = friends_get_friend_user_ids( $user_id ); 258 254 if ( empty( $friends ) ) { … … 268 264 ), 269 265 270 // we should only be able to view sitewide activity content for friends266 // We should only be able to view sitewide activity content for friends. 271 267 array( 272 268 'column' => 'hide_sitewide', … … 274 270 ), 275 271 276 // overrides272 // Overrides. 277 273 'override' => array( 278 274 'filter' => array( 'user_id' => 0 ), … … 292 288 * @since 2.2.0 293 289 * 294 * @param array $retval Empty array by default 295 * @param array $filter Current activity arguments 290 * @param array $retval Empty array by default. 291 * @param array $filter Current activity arguments. 296 292 * 297 293 * @return array … … 299 295 function bp_friends_filter_activity_just_me_scope( $retval = array(), $filter = array() ) { 300 296 301 // Determine the user_id 297 // Determine the user_id. 302 298 if ( ! empty( $filter['user_id'] ) ) { 303 299 $user_id = $filter['user_id']; … … 308 304 } 309 305 310 // Get the requested action 306 // Get the requested action. 311 307 $action = $filter['filter']['action']; 312 308 313 // Make sure actions are listed in an array 309 // Make sure actions are listed in an array. 314 310 if ( ! is_array( $action ) ) { 315 311 $action = explode( ',', $filter['filter']['action'] ); … … 326 322 } 327 323 328 // Juggle existing override value 324 // Juggle existing override value. 329 325 $override = array(); 330 326 if ( ! empty( $retval['override'] ) ) { … … 354 350 ); 355 351 356 // Juggle back override value 352 // Juggle back override value. 357 353 if ( ! empty( $override ) ) { 358 354 $retval['override'] = $override; … … 369 365 * @since 1.9.0 370 366 * 371 * @param int $friendship_id 372 * @param int $initiator_user_id 373 * @param int $friend_user_id 374 * @param object|bool $friendship Optional 367 * @param int $friendship_id ID of the friendship. 368 * @param int $initiator_user_id ID of friendship initiator. 369 * @param int $friend_user_id ID of user whose friendship is requested. 370 * @param object|bool $friendship Optional Friendship object. 375 371 */ 376 372 function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_user_id, $friend_user_id, $friendship = false ) { … … 379 375 } 380 376 381 // Record in activity streams for the initiator 377 // Record in activity streams for the initiator. 382 378 friends_record_activity( array( 383 379 'user_id' => $initiator_user_id, -
trunk/src/bp-friends/bp-friends-cache.php
r10147 r10323 18 18 * @param int $friendship_id ID of the friendship whose two members should 19 19 * have their friends cache busted. 20 *21 20 * @return bool 22 21 */ … … 29 28 } 30 29 31 // List actions to clear object caches on 30 // List actions to clear object caches on. 32 31 add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' ); 33 32 add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' ); … … 69 68 * 70 69 * @param int $friendship_id The friendship ID. 71 * @param BP_Friends_Friendship $friendship 70 * @param BP_Friends_Friendship $friendship Friendship object. 72 71 */ 73 72 function bp_friends_clear_request_cache_on_remove( $friendship_id, BP_Friends_Friendship $friendship ) { … … 77 76 add_action( 'friends_friendship_rejected', 'bp_friends_clear_request_cache_on_remove', 10, 2 ); 78 77 79 // List actions to clear super cached pages on, if super cache is installed 78 // List actions to clear super cached pages on, if super cache is installed. 80 79 add_action( 'friends_friendship_rejected', 'bp_core_clear_cache' ); 81 80 add_action( 'friends_friendship_accepted', 'bp_core_clear_cache' ); -
trunk/src/bp-friends/bp-friends-filters.php
r10147 r10323 27 27 global $wpdb; 28 28 29 // stop if user isn't logged in29 // Stop if user isn't logged in. 30 30 if ( ! is_user_logged_in() ) { 31 31 return; … … 34 34 $bp = buddypress(); 35 35 36 // Fetch whether or not the user is a friend of the current user 36 // Fetch whether or not the user is a friend of the current user. 37 37 $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids_sql} ) ) OR (initiator_user_id IN ( {$user_ids_sql} ) AND friend_user_id = %d )", bp_loggedin_user_id(), bp_loggedin_user_id() ) ); 38 38 39 // Keep track of members that have a friendship status with the current user 39 // Keep track of members that have a friendship status with the current user. 40 40 $friend_user_ids = array(); 41 41 42 // The "friend" is the user ID in the pair who is *not* the logged in user 42 // The "friend" is the user ID in the pair who is *not* the logged in user. 43 43 foreach ( (array) $friend_status as $fs ) { 44 44 $friend_id = bp_loggedin_user_id() == $fs->initiator_user_id ? $fs->friend_user_id : $fs->initiator_user_id; … … 57 57 } 58 58 59 // The rest are not friends with the current user, so set status accordingly 59 // The rest are not friends with the current user, so set status accordingly. 60 60 $not_friends = array_diff( $user_query->user_ids, $friend_user_ids ); 61 61 foreach ( (array) $not_friends as $nf ) { -
trunk/src/bp-friends/bp-friends-functions.php
r10147 r10323 26 26 * When true, running friends_add_friend() will result in an accepted 27 27 * friendship, with no notifications being sent. Default: false. 28 *29 28 * @return bool True on success, false on failure. 30 29 */ … … 36 35 } 37 36 38 // Check if already friends, and bail if so 37 // Check if already friends, and bail if so. 39 38 if ( friends_check_friendship( $initiator_userid, $friend_userid ) ) { 40 39 return true; 41 40 } 42 41 43 // Setup the friendship data 42 // Setup the friendship data. 44 43 $friendship = new BP_Friends_Friendship; 45 44 $friendship->initiator_user_id = $initiator_userid; … … 53 52 } 54 53 55 // Bail if friendship could not be saved (how sad!) 54 // Bail if friendship could not be saved (how sad!). 56 55 if ( ! $friendship->save() ) { 57 56 return false; 58 57 } 59 58 60 // Send notifications 59 // Send notifications. 61 60 if ( empty( $force_accept ) ) { 62 61 $action = 'requested'; 63 62 64 // Update friend totals 63 // Update friend totals. 65 64 } else { 66 65 $action = 'accepted'; … … 93 92 * @param int $initiator_userid ID of the friendship initiator. 94 93 * @param int $friend_userid ID of the friend user. 95 *96 94 * @return bool True on success, false on failure. 97 95 */ … … 113 111 do_action( 'friends_before_friendship_delete', $friendship_id, $initiator_userid, $friend_userid ); 114 112 115 // Remove the activity stream items about the friendship id 113 // Remove the activity stream items about the friendship id. 116 114 friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_created', 'user_id' => 0 ) ); 117 115 … … 155 153 * 156 154 * @param int $friendship_id ID of the pending friendship object. 157 *158 155 * @return bool True on success, false on failure. 159 156 */ 160 157 function friends_accept_friendship( $friendship_id ) { 161 158 162 // Get the friendship data 159 // Get the friendship data. 163 160 $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 164 161 165 // Accepting friendship 162 // Accepting friendship. 166 163 if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::accept( $friendship_id ) ) { 167 164 168 // Bump the friendship counts 165 // Bump the friendship counts. 169 166 friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id ); 170 167 … … 191 188 * 192 189 * @param int $friendship_id ID of the pending friendship object. 193 *194 190 * @return bool True on success, false on failure. 195 191 */ … … 220 216 * user who requested the friendship, and is doing the withdrawing. 221 217 * @param int $friend_userid ID of the requested friend. 222 *223 218 * @return bool True on success, false on failure. 224 219 */ … … 253 248 * @param int $user_id ID of the first user. 254 249 * @param int $possible_friend_id ID of the other user. 255 *256 250 * @return bool Returns true if the two users are friends, otherwise false. 257 251 */ … … 271 265 * @param int $user_id ID of the first user. 272 266 * @param int $possible_friend_id ID of the other user. 273 *274 267 * @return string Friend status of the two users. 275 268 */ … … 277 270 global $members_template; 278 271 279 // check the BP_User_Query first280 // @see bp_friends_filter_user_query_populate_extras() 272 // Check the BP_User_Query first 273 // @see bp_friends_filter_user_query_populate_extras(). 281 274 if ( ! empty( $members_template->in_the_loop ) ) { 282 275 if ( isset( $members_template->member->friendship_status ) ) { … … 292 285 * 293 286 * @param int $user_id ID of the user whose friends are being counted. 294 *295 287 * @return int Friend count of the user. 296 288 */ … … 317 309 * 318 310 * @param int $user_id ID of the user whose friends are being checked. 319 *320 311 * @return bool True if the user has friends, otherwise false. 321 312 */ … … 337 328 * @param int $initiator_user_id ID of the first user. 338 329 * @param int $friend_user_id ID of the second user. 339 *340 330 * @return int|bool ID of the friendship if found, otherwise false. 341 331 */ … … 353 343 * 'user_id' => $user_id; false to get a one-dimensional 354 344 * array of user IDs. Default: false. 355 *356 345 * @return array 357 346 */ … … 369 358 * @param int $pag_page Optional. The page of results to return. Default: null (no 370 359 * pagination - return all results). 371 *372 360 * @return array|bool On success, an array: { 373 361 * @type array $friends IDs of friends returned by the query. … … 384 372 * 385 373 * @param int $user_id The ID of the user who has received the friendship requests. 386 *387 374 * @return array|bool An array of user IDs, or false if none are found. 388 375 */ … … 403 390 * @param string $filter Optional. Limit results to those matching a search 404 391 * string. 405 *406 392 * @return array See {@link BP_Core_User::get_users()}. 407 393 */ … … 433 419 * @param string $filter Optional. Limit results to those matching a search 434 420 * string. 435 *436 421 * @return array See {@link BP_Core_User::get_users()}. 437 422 */ … … 463 448 * @param string $filter Optional. Limit results to those matching a search 464 449 * string. 465 *466 450 * @return array See {@link BP_Core_User::get_users()}. 467 451 */ … … 488 472 * 489 473 * @param array $friend_ids See BP_Friends_Friendship::get_bulk_last_active(). 490 *491 474 * @return array $user_ids See BP_Friends_Friendship::get_bulk_last_active(). 492 475 */ … … 506 489 * ID of the logged-in user. 507 490 * @param int $group_id Group to check possible invitations against. 508 *509 491 * @return mixed False if no friends, array of users if friends. 510 492 */ 511 493 function friends_get_friends_invite_list( $user_id = 0, $group_id = 0 ) { 512 494 513 // Default to logged in user id 495 // Default to logged in user id. 514 496 if ( empty( $user_id ) ) 515 497 $user_id = bp_loggedin_user_id(); 516 498 517 // Only group admins can invited previously banned users 499 // Only group admins can invited previously banned users. 518 500 $user_is_admin = (bool) groups_is_user_admin( $user_id, $group_id ); 519 501 520 // Assume no friends 502 // Assume no friends. 521 503 $friends = array(); 522 504 … … 534 516 ) ); 535 517 536 // User has friends 518 // User has friends. 537 519 if ( bp_has_members( $args ) ) { 538 520 … … 547 529 while ( bp_members() ) : 548 530 549 // Load the member 531 // Load the member. 550 532 bp_the_member(); 551 533 552 // Get the user ID of the friend 534 // Get the user ID of the friend. 553 535 $friend_user_id = bp_get_member_user_id(); 554 536 555 // Skip friend if already in the group 537 // Skip friend if already in the group. 556 538 if ( groups_is_user_member( $friend_user_id, $group_id ) ) 557 539 continue; 558 540 559 // Skip friend if not group admin and user banned from group 541 // Skip friend if not group admin and user banned from group. 560 542 if ( ( false === $user_is_admin ) && groups_is_user_banned( $friend_user_id, $group_id ) ) 561 543 continue; 562 544 563 // Friend is safe, so add it to the array of possible friends 545 // Friend is safe, so add it to the array of possible friends. 564 546 $friends[] = array( 565 547 'id' => $friend_user_id, … … 570 552 } 571 553 572 // If no friends, explicitly set to false 554 // If no friends, explicitly set to false. 573 555 if ( empty( $friends ) ) 574 556 $friends = false; … … 597 579 * @param int $user_id ID of the user whose friends are being counted. 598 580 * @param int $group_id ID of the group friends are being invited to. 599 *600 581 * @return int $invitable_count Eligible friend count. 601 582 */ … … 609 590 * @param int $user_id Optional. ID of the user whose friendships you are 610 591 * counting. Default: displayed user (if any), otherwise logged-in user. 611 *612 592 * @return int Friend count for the user. 613 593 */ … … 625 605 * @param int $pag_page Number of the page being requested. Default: 0 (no 626 606 * pagination - show all results). 627 *628 607 * @return array Array of BP_Core_User objects corresponding to friends. 629 608 */ … … 646 625 * 647 626 * @param int $friendship_id The ID of the friendship being checked. 648 *649 627 * @return bool True if the friendship is confirmed, otherwise false. 650 628 */ … … 702 680 BP_Friends_Friendship::delete_all_for_user( $user_id ); 703 681 704 // Remove usermeta 682 // Remove usermeta. 705 683 bp_delete_user_meta( $user_id, 'total_friend_count' ); 706 684 … … 740 718 741 719 $friends_query = array( 742 'count_total' => '', // Prevents total count 720 'count_total' => '', // Prevents total count. 743 721 'populate_extras' => false, 744 722 -
trunk/src/bp-friends/bp-friends-loader.php
r10147 r10323 12 12 defined( 'ABSPATH' ) || exit; 13 13 14 /** 15 * Defines the BuddyPress Friends Component. 16 */ 14 17 class BP_Friends_Component extends BP_Component { 15 18 … … 75 78 } 76 79 77 // Define a slug, if necessary 80 // Define a slug, if necessary. 78 81 if ( ! defined( 'BP_FRIENDS_SLUG' ) ) { 79 82 define( 'BP_FRIENDS_SLUG', $this->id ); 80 83 } 81 84 82 // Global tables for the friends component 85 // Global tables for the friends component. 83 86 $global_tables = array( 84 87 'table_name' => $bp->table_prefix . 'bp_friends', … … 113 116 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 114 117 115 // Determine user to use 118 // Determine user to use. 116 119 if ( bp_displayed_user_domain() ) { 117 120 $user_domain = bp_displayed_user_domain(); … … 126 129 $friends_link = trailingslashit( $user_domain . $slug ); 127 130 128 // Add 'Friends' to the main navigation 131 // Add 'Friends' to the main navigation. 129 132 $count = friends_get_total_friend_count(); 130 133 $class = ( 0 === $count ) ? 'no-count' : 'count'; … … 138 141 ); 139 142 140 // Add the subnav items to the friends nav item 143 // Add the subnav items to the friends nav item. 141 144 $sub_nav[] = array( 142 145 'name' => _x( 'Friendships', 'Friends screen sub 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 $friends_link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() ); 181 184 182 // Pending friend requests 185 // Pending friend requests. 183 186 $count = count( friends_get_friendship_request_user_ids( 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 // My Friends 203 // My Friends. 201 204 $wp_admin_nav[] = array( 202 205 'parent' => 'my-account-' . $this->id, … … 206 209 ); 207 210 208 // Requests 211 // Requests. 209 212 $wp_admin_nav[] = array( 210 213 'parent' => 'my-account-' . $this->id, … … 223 226 public function setup_title() { 224 227 225 // Adjust title 228 // Adjust title. 226 229 if ( bp_is_friends_component() ) { 227 230 $bp = buddypress(); … … 249 252 public function setup_cache_groups() { 250 253 251 // Global groups 254 // Global groups. 252 255 wp_cache_add_global_groups( array( 253 256 'bp_friends_requests' -
trunk/src/bp-friends/bp-friends-notifications.php
r10147 r10323 24 24 * @param int $initiator_id ID of the user who initiated the request. 25 25 * @param int $friend_id ID of the request recipient. 26 *27 26 * @return bool 28 27 */ … … 40 39 $initiator_link = bp_core_get_user_domain( $initiator_id ); 41 40 42 // Set up and send the message 41 // Set up and send the message. 43 42 $to = $ud->user_email; 44 43 $subject = bp_get_email_subject( array( 'text' => sprintf( __( 'New friendship request from %s', 'buddypress' ), $initiator_name ) ) ); … … 53 52 ', 'buddypress' ), $initiator_name, $all_requests_link, $initiator_name, $initiator_link ); 54 53 55 // Only show the disable notifications line if the settings component is enabled 54 // Only show the disable notifications line if the settings component is enabled. 56 55 if ( bp_is_active( 'settings' ) ) { 57 56 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); … … 116 115 * @param int $initiator_id ID of the user who initiated the request. 117 116 * @param int $friend_id ID of the request recipient. 118 *119 117 * @return bool 120 118 */ … … 131 129 $settings_link = trailingslashit( bp_core_get_user_domain( $initiator_id ) . $settings_slug . '/notifications' ); 132 130 133 // Set up and send the message 131 // Set up and send the message. 134 132 $to = $ud->user_email; 135 133 $subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s accepted your friendship request', 'buddypress' ), $friend_name ) ) ); … … 142 140 ', 'buddypress' ), $friend_name, $friend_name, $friend_link ); 143 141 144 // Only show the disable notifications line if the settings component is enabled 142 // Only show the disable notifications line if the settings component is enabled. 145 143 if ( bp_is_active( 'settings' ) ) { 146 144 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); … … 207 205 * @param string $format 'string' for BuddyBar-compatible notifications; 208 206 * 'array' for WP Toolbar. Default: 'string'. 209 *210 207 * @return array|string 211 208 */ … … 219 216 $action = 'accepted'; 220 217 221 // Set up the string and the filter 218 // Set up the string and the filter. 222 219 if ( (int) $total_items > 1 ) { 223 220 $text = sprintf( __( '%d friends accepted your friendship requests', 'buddypress' ), (int) $total_items ); … … 235 232 $action = 'request'; 236 233 237 // Set up the string and the filter 234 // Set up the string and the filter. 238 235 if ( (int) $total_items > 1 ) { 239 236 $text = sprintf( __( 'You have %d pending friendship requests', 'buddypress' ), (int) $total_items ); … … 247 244 } 248 245 249 // Return either an HTML link or an array, depending on the requested format 246 // Return either an HTML link or an array, depending on the requested format. 250 247 if ( 'string' == $format ) { 251 248 … … 332 329 * 333 330 * @since 1.9.0 331 * 334 332 * @param int $friendship_id The unique ID of the friendship. 335 333 * @param int $initiator_user_id The friendship initiator user ID. … … 356 354 * @since 1.9.0 357 355 * 358 * @param int $friendship_id (not used)359 * @param object $friendship 356 * @param int $friendship_id Friendship ID (not used). 357 * @param object $friendship Friendship object. 360 358 */ 361 359 function bp_friends_mark_friendship_rejected_notifications_by_item_id( $friendship_id, $friendship ) { … … 377 375 function bp_friends_add_friendship_accepted_notification( $friendship_id, $initiator_user_id, $friend_user_id ) { 378 376 379 // Bail if notifications is not active 377 // Bail if notifications is not active. 380 378 if ( ! bp_is_active( 'notifications' ) ) { 381 379 return; 382 380 } 383 381 384 // Remove the friend request notice 382 // Remove the friend request notice. 385 383 bp_notifications_mark_notifications_by_item_id( $friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 386 384 387 // Add a friend accepted notice for the initiating user 385 // Add a friend accepted notice for the initiating user. 388 386 bp_notifications_add_notification( array( 389 387 'user_id' => $initiator_user_id, … … 403 401 * @since 1.9.0 404 402 * 405 * @param int $friendship_id (not used)406 * @param object $friendship 403 * @param int $friendship_id Friendship ID (not used). 404 * @param object $friendship Friendship Object. 407 405 */ 408 406 function bp_friends_mark_friendship_withdrawn_notifications_by_item_id( $friendship_id, $friendship ) { … … 418 416 * @since 1.9.0 419 417 * 420 * @param int $user_id 418 * @param int $user_id ID of the user whose notifications are removed. 421 419 */ 422 420 function bp_friends_remove_notifications_data( $user_id = 0 ) { -
trunk/src/bp-friends/bp-friends-screens.php
r10147 r10323 41 41 function friends_screen_requests() { 42 42 if ( bp_is_action_variable( 'accept', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) { 43 // Check the nonce 43 // Check the nonce. 44 44 check_admin_referer( 'friends_accept_friendship' ); 45 45 … … 52 52 53 53 } elseif ( bp_is_action_variable( 'reject', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) { 54 // Check the nonce 54 // Check the nonce. 55 55 check_admin_referer( 'friends_reject_friendship' ); 56 56 … … 63 63 64 64 } elseif ( bp_is_action_variable( 'cancel', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) { 65 // Check the nonce 65 // Check the nonce. 66 66 check_admin_referer( 'friends_withdraw_friendship' ); 67 67 -
trunk/src/bp-friends/bp-friends-template.php
r10147 r10323 263 263 * @param int $user_id Optional. If provided, the function will simply 264 264 * return this value. 265 *266 265 * @return int ID of potential friend. 267 266 */ … … 291 290 * @param int $user_id ID of the potential friend. Default: the value of 292 291 * {@link bp_get_potential_friend_id()}. 293 *294 292 * @return string 'is_friend', 'not_friends', or 'pending'. 295 293 */ … … 332 330 * applies. Default: value of {@link bp_get_potential_friend_id()}. 333 331 * @param bool $friend_status Not currently used. 334 *335 332 * @return string HTML for the Add Friend button. 336 333 */ … … 357 354 'link_text' => __( 'Cancel Friendship Request', 'buddypress' ), 358 355 'link_title' => __( 'Cancel Friendship Requested', 'buddypress' ), 359 'link_id' 360 'link_rel' 356 'link_id' => 'friend-' . $potential_friend_id, 357 'link_rel' => 'remove', 361 358 'link_class' => 'friendship-button pending_friend requested' 362 359 ); … … 430 427 * @param int $user_id Optional. Default: the displayed user's ID, or the 431 428 * logged-in user's ID. 432 *433 429 * @return string|bool A comma-separated list of friend IDs if any are found, 434 430 * otherwise false. … … 455 451 * @param int $user_id ID of the user whose requests are being retrieved. 456 452 * Defaults to displayed user. 457 *458 453 * @return array|int An array of user IDs if found, or a 0 if none are found. 459 454 */ … … 584 579 * 585 580 * @param int $user_id See {@link friends_get_total_friend_count()}. 586 *587 581 * @return int Total friend count. 588 582 */ … … 615 609 * @param int $user_id ID of the user whose requests are being counted. 616 610 * Default: ID of the logged-in user. 617 *618 611 * @return int Friend count. 619 612 */ … … 641 634 * @uses bp_friends_get_profile_stats() to get the stats. 642 635 * 643 * @param array|string $args before|after|user_id 636 * @param array|string $args before|after|user_id. 644 637 */ 645 638 function bp_friends_profile_stats( $args = '' ) { … … 653 646 * @since 2.0.0 654 647 * 655 * @param array|string $args before|after|user_id 656 * 648 * @param array|string $args before|after|user_id. 657 649 * @return string HTML for stats output. 658 650 */ 659 651 function bp_friends_get_profile_stats( $args = '' ) { 660 652 661 // Parse the args 653 // Parse the args. 662 654 $r = bp_parse_args( $args, array( 663 655 'before' => '<li class="bp-friends-profile-stats">', … … 668 660 ), 'friends_get_profile_stats' ); 669 661 670 // Allow completely overloaded output 662 // Allow completely overloaded output. 671 663 if ( empty( $r['output'] ) ) { 672 664 673 // Only proceed if a user ID was passed 665 // Only proceed if a user ID was passed. 674 666 if ( ! empty( $r['user_id'] ) ) { 675 667 676 // Get the user's friends 668 // Get the user's friends. 677 669 if ( empty( $r['friends'] ) ) { 678 670 $r['friends'] = absint( friends_get_total_friend_count( $r['user_id'] ) ); 679 671 } 680 672 681 // If friends exist, show some formatted output 673 // If friends exist, show some formatted output. 682 674 $r['output'] = $r['before'] . sprintf( _n( '%s friend', '%s friends', $r['friends'], 'buddypress' ), '<strong>' . $r['friends'] . '</strong>' ) . $r['after']; 683 675 } -
trunk/src/bp-friends/bp-friends-widgets.php
r10276 r10323 157 157 * @param array $new_instance The parameters saved by the user. 158 158 * @param array $old_instance The parameters as previously saved to the database. 159 *160 159 * @return array $instance The processed settings to save. 161 160 */ … … 174 173 * 175 174 * @param array $instance The saved widget settings. 176 * 177 * @return string 175 * @return void 178 176 */ 179 177 function form( $instance ) { … … 240 238 241 239 if ( bp_has_members( $members_args ) ) : ?> 242 <?php echo '0[[SPLIT]]'; // return valid result. TODO: remove this. ?>240 <?php echo '0[[SPLIT]]'; // Return valid result. TODO: remove this. ?> 243 241 <?php while ( bp_members() ) : bp_the_member(); ?> 244 242 <li class="vcard"> -
trunk/src/bp-friends/classes/class-bp-friends-friendship.php
r10248 r10323 149 149 do_action_ref_array( 'friends_friendship_before_save', array( &$this ) ); 150 150 151 // Update 151 // Update. 152 152 if (!empty( $this->id ) ) { 153 153 $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) ); 154 154 155 // Save 155 // Save. 156 156 } else { 157 157 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, %s )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) ); … … 171 171 } 172 172 173 /** 174 * Delete the current friendship from the database. 175 * 176 * @return bool|int 177 */ 173 178 public function delete() { 174 179 global $wpdb; … … 190 195 * keyed as 'user_id' => $user_id; false to get a one-dimensional 191 196 * array of user IDs. Default: false. 192 *193 197 * @return array $fids IDs of friends for provided user. 194 198 */ … … 224 228 * @param int $user_id The ID of the first user. 225 229 * @param int $friend_id The ID of the second user. 226 *227 230 * @return int|bool The ID of the friendship object if found, otherwise false. 228 231 */ … … 240 243 * @param int $user_id The ID of the user who has received the 241 244 * friendship requests. 242 *243 245 * @return array|bool An array of user IDs, or false if none are found. 244 246 */ … … 265 267 * are counting. Default: displayed user (if any), otherwise 266 268 * logged-in user. 267 *268 269 * @return int Friend count for the user. 269 270 */ … … 276 277 $bp = buddypress(); 277 278 278 /* This is stored in 'total_friend_count' usermeta. 279 This function will recalculate, update and return. */ 279 /* 280 * This is stored in 'total_friend_count' usermeta. 281 * This function will recalculate, update and return. 282 */ 280 283 281 284 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id ) ); 282 285 283 // Do not update meta if user has never had friends 286 // Do not update meta if user has never had friends. 284 287 if ( empty( $count ) && !bp_get_user_meta( $user_id, 'total_friend_count', true ) ) 285 288 return 0; … … 309 312 global $wpdb; 310 313 311 // TODO: Optimize this function. 314 /* 315 * TODO: Optimize this function. 316 */ 312 317 313 318 if ( empty( $user_id ) ) … … 315 320 316 321 // Only search for matching strings at the beginning of the 317 // name (@todo - figure out why this restriction) 322 // name (@todo - figure out why this restriction). 318 323 $search_terms_like = bp_esc_like( $filter ) . '%'; 319 324 … … 333 338 $bp = buddypress(); 334 339 335 // filter the user_ids based on the search criteria.340 // Filter the user_ids based on the search criteria. 336 341 if ( bp_is_active( 'xprofile' ) ) { 337 342 $sql = $wpdb->prepare( "SELECT DISTINCT user_id FROM {$bp->profile->table_name_data} WHERE user_id IN ({$fids}) AND value LIKE %s {$pag_sql}", $search_terms_like ); … … 357 362 * request to $possible_friend_userid that has not yet been approved, 358 363 * while 'awaiting_response' is the other way around ($possible_friend_userid 359 * sent the initial request) 364 * sent the initial request). 360 365 * 361 366 * @param int $initiator_userid The ID of the user who is the initiator … … 363 368 * @param int $possible_friend_userid The ID of the user who is the 364 369 * recipient of the potential friendship/request. 365 *366 370 * @return string $value The friendship status, from among 'not_friends', 367 371 * 'is_friend', 'pending', and 'awaiting_response'. … … 398 402 * @param array $user_ids IDs of users whose last_active meta is 399 403 * being queried. 400 *401 404 * @return array $retval Array of last_active values + user_ids. 402 405 */ … … 406 409 $last_activities = BP_Core_User::get_last_activity( $user_ids ); 407 410 408 // Sort and structure as expected in legacy function 411 // Sort and structure as expected in legacy function. 409 412 usort( $last_activities, create_function( '$a, $b', ' 410 413 if ( $a["date_recorded"] == $b["date_recorded"] ) { … … 431 434 * 432 435 * @param int $friendship_id ID of the friendship to be accepted. 433 *434 436 * @return int Number of database rows updated. 435 437 */ … … 446 448 * 447 449 * @param int $friendship_id ID of the friendship to be withdrawn. 448 *449 450 * @return int Number of database rows deleted. 450 451 */ … … 461 462 * 462 463 * @param int $friendship_id ID of the friendship to be rejected. 463 *464 464 * @return int Number of database rows deleted. 465 465 */ … … 482 482 * @param int $page Optional. Number of the page to return. Default: 483 483 * false (no pagination - return all results). 484 *485 484 * @return array $filtered_ids IDs of users who match the query. 486 485 */ … … 489 488 490 489 // Only search for matching strings at the beginning of the 491 // name (@todo - figure out why this restriction) 490 // name (@todo - figure out why this restriction). 492 491 $search_terms_like = bp_esc_like( $filter ) . '%'; 493 492 … … 501 500 $bp = buddypress(); 502 501 503 // filter the user_ids based on the search criteria.502 // Filter the user_ids based on the search criteria. 504 503 if ( bp_is_active( 'xprofile' ) ) { 505 504 $sql = $wpdb->prepare( "SELECT DISTINCT d.user_id as id FROM {$bp->profile->table_name_data} d, {$users_table} u WHERE d.user_id = u.id AND d.value LIKE %s ORDER BY d.value DESC {$pag_sql}", $search_terms_like ); … … 522 521 * 523 522 * @param string $filter Search term. 524 *525 523 * @return int Count of users matching the search term. 526 524 */ … … 529 527 530 528 // Only search for matching strings at the beginning of the 531 // name (@todo - figure out why this restriction) 529 // name (@todo - figure out why this restriction). 532 530 $search_terms_like = bp_esc_like( $filter ) . '%'; 533 531 … … 537 535 $bp = buddypress(); 538 536 539 // filter the user_ids based on the search criteria.537 // Filter the user_ids based on the search criteria. 540 538 if ( bp_is_active( 'xprofile' ) ) { 541 539 $sql = $wpdb->prepare( "SELECT COUNT(DISTINCT d.user_id) FROM {$bp->profile->table_name_data} d, {$users_table} u WHERE d.user_id = u.id AND d.value LIKE %s", $search_terms_like ); … … 558 556 * 559 557 * @param array $user_ids Array of user IDs. 560 *561 558 * @return array User IDs, sorted by the associated display names. 562 559 */ … … 580 577 * @param int $total_friends Optional. Number of random friends to get. 581 578 * Default: 5. 582 *583 579 * @return array|bool An array of random friend user IDs on success; 584 580 * false if none are found. … … 596 592 } 597 593 598 // remove duplicates594 // Remove duplicates. 599 595 if ( count( $fids ) > 0 ) 600 596 return array_flip( array_flip( $fids ) ); … … 614 610 * @param int $user_id ID of the user whose friends are being counted. 615 611 * @param int $group_id ID of the group friends are being invited to. 616 *617 612 * @return int $invitable_count Eligible friend count. 618 613 */ 619 614 public static function get_invitable_friend_count( $user_id, $group_id ) { 620 615 621 // Setup some data we'll use below 616 // Setup some data we'll use below. 622 617 $is_group_admin = BP_Groups_Member::check_is_admin( $user_id, $group_id ); 623 618 $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ); … … 626 621 for ( $i = 0, $count = count( $friend_ids ); $i < $count; ++$i ) { 627 622 628 // If already a member, they cannot be invited again 623 // If already a member, they cannot be invited again. 629 624 if ( BP_Groups_Member::check_is_member( (int) $friend_ids[$i], $group_id ) ) 630 625 continue; 631 626 632 // If user already has invite, they cannot be added 627 // If user already has invite, they cannot be added. 633 628 if ( BP_Groups_Member::check_has_invite( (int) $friend_ids[$i], $group_id ) ) 634 629 continue; 635 630 636 // If user is not group admin and friend is banned, they cannot be invited 631 // If user is not group admin and friend is banned, they cannot be invited. 637 632 if ( ( false === $is_group_admin ) && BP_Groups_Member::check_is_banned( (int) $friend_ids[$i], $group_id ) ) 638 633 continue; … … 648 643 * 649 644 * @param int $friendship_id ID of the friendship. 650 *651 645 * @return object friend_user_id and initiator_user_id. 652 646 */ … … 669 663 $bp = buddypress(); 670 664 671 // Get friends of $user_id 665 // Get friends of $user_id. 672 666 $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ); 673 667 674 // Delete all friendships related to $user_id 668 // Delete all friendships related to $user_id. 675 669 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id ) ); 676 670 … … 681 675 } 682 676 683 // Loop through friend_ids and update their counts 677 // Loop through friend_ids and update their counts. 684 678 foreach ( (array) $friend_ids as $friend_id ) { 685 679 BP_Friends_Friendship::total_friend_count( $friend_id );
Note: See TracChangeset
for help on using the changeset viewer.