- Timestamp:
- 02/23/2023 12:39:47 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/10.0/src/bp-friends/classes/class-bp-friends-friendship.php
r13428 r13429 268 268 if ( empty( $user_id ) ) { 269 269 $user_id = bp_loggedin_user_id(); 270 }271 272 $friendships = array();273 $operator = strtoupper( $operator );274 275 if ( ! in_array( $operator, array( 'AND', 'OR', 'NOT' ), true ) ) {276 return $friendships;277 270 } 278 271 … … 310 303 } 311 304 312 $int_keys = array( 'id', 'initiator_user_id', 'friend_user_id' );313 $bool_keys = array( 'is_confirmed', 'is_limited' );314 315 305 // Assemble filter array. 316 306 $filters = wp_array_slice_assoc( $r, array( 'id', 'initiator_user_id', 'friend_user_id', 'is_confirmed', 'is_limited' ) ); … … 318 308 if ( is_null( $filter_value ) ) { 319 309 unset( $filters[ $filter_name ] ); 320 } elseif ( in_array( $filter_name, $int_keys, true ) ) {321 $filters[ $filter_name ] = (int) $filter_value;322 } else {323 $filters[ $filter_name ] = (bool) $filter_value;324 310 } 325 311 } 326 312 327 313 // Populate friendship array from cache, and normalize. 314 $friendships = array(); 315 $int_keys = array( 'id', 'initiator_user_id', 'friend_user_id' ); 316 $bool_keys = array( 'is_confirmed', 'is_limited' ); 328 317 foreach ( $friendship_ids as $friendship_id ) { 329 318 // Create a limited BP_Friends_Friendship object (don't fetch the user details). … … 346 335 347 336 // We need to support the same operators as wp_list_filter(). 348 if ( 'OR' == = $operator || 'NOT' === $operator ) {337 if ( 'OR' == $operator || 'NOT' == $operator ) { 349 338 $matched = 0; 350 339 351 340 foreach ( $filters as $filter_name => $filter_value ) { 352 if ( isset( $friendship->{$filter_name} ) && $filter_value == =$friendship->{$filter_name} ) {341 if ( isset( $friendship->{$filter_name} ) && $filter_value == $friendship->{$filter_name} ) { 353 342 $matched++; 354 343 } 355 344 } 356 345 357 if ( ( 'OR' == =$operator && $matched > 0 )358 || ( 'NOT' == = $operator && 0 === $matched ) ) {346 if ( ( 'OR' == $operator && $matched > 0 ) 347 || ( 'NOT' == $operator && 0 == $matched ) ) { 359 348 $friendships[ $friendship->id ] = $friendship; 360 349 } … … 366 355 */ 367 356 foreach ( $filters as $filter_name => $filter_value ) { 368 if ( ! isset( $friendship->{$filter_name} ) || $filter_value != =$friendship->{$filter_name} ) {357 if ( ! isset( $friendship->{$filter_name} ) || $filter_value != $friendship->{$filter_name} ) { 369 358 continue 2; 370 359 } … … 443 432 444 433 $friendships = self::get_friendships( $user_id, $args ); 445 $user_id = (int) $user_id;446 434 447 435 $fids = array(); 448 436 foreach ( $friendships as $friendship ) { 449 $friend_id = $friendship->friend_user_id;450 if ( $friendship->friend_user_id === $user_id ) {451 $friend_id = $friendship->initiator_user_id;452 }453 454 437 if ( ! empty( $assoc_arr ) ) { 455 $fids[] = array( 'user_id' => $friend_id );438 $fids[] = array( 'user_id' => ( $friendship->friend_user_id == $user_id ) ? $friendship->initiator_user_id : $friendship->friend_user_id ); 456 439 } else { 457 $fids[] = $friend_id;440 $fids[] = ( $friendship->friend_user_id == $user_id ) ? $friendship->initiator_user_id : $friendship->friend_user_id; 458 441 } 459 442 } … … 654 637 655 638 // Can't friend yourself. 656 if ( (int) $initiator_userid === (int)$possible_friend_userid ) {639 if ( $initiator_userid === $possible_friend_userid ) { 657 640 return 'not_friends'; 658 641 } … … 680 663 681 664 $bp = buddypress(); 682 $user_id = (int) $user_id;683 665 $possible_friend_ids = wp_parse_id_list( $possible_friend_ids ); 684 666 … … 958 940 $sql = $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE (friend_user_id = %d || initiator_user_id = %d) && is_confirmed = 1 ORDER BY rand() LIMIT %d", $user_id, $user_id, $total_friends ); 959 941 $results = $wpdb->get_results( $sql ); 960 $user_id = (int) $user_id;961 942 962 943 for ( $i = 0, $count = count( $results ); $i < $count; ++$i ) { 963 $friend_user_id = (int) $results[ $i ]->friend_user_id; 964 $initiator_user_id = (int) $results[ $i ]->initiator_user_id; 965 966 if ( $friend_user_id === $user_id ) { 967 $fids[] = $initiator_user_id; 968 } else { 969 $fids[] = $friend_user_id; 970 } 944 $fids[] = ( $results[ $i ]->friend_user_id === $user_id ) ? $results[ $i ]->initiator_user_id : $results[ $i ]->friend_user_id; 971 945 } 972 946 … … 1085 1059 global $wpdb; 1086 1060 1087 $bp = buddypress(); 1088 $user_id = (int) $user_id; 1061 $bp = buddypress(); 1089 1062 1090 1063 // Get all friendships, of any status, for the user. … … 1095 1068 $friendship_ids[] = $friendship->id; 1096 1069 if ( $friendship->is_confirmed ) { 1097 if ( $friendship->friend_user_id === $user_id ) { 1098 $friend_ids[] = $friendship->initiator_user_id; 1099 } else { 1100 $friend_ids[] = $friendship->friend_user_id; 1101 } 1070 $friend_ids[] = ( $friendship->friend_user_id == $user_id ) ? $friendship->initiator_user_id : $friendship->friend_user_id; 1102 1071 } 1103 1072 }
Note: See TracChangeset
for help on using the changeset viewer.