Changeset 9471 for trunk/src/bp-friends/bp-friends-classes.php
- Timestamp:
- 02/10/2015 02:49:16 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-friends/bp-friends-classes.php
r9351 r9471 113 113 */ 114 114 public function populate() { 115 global $wpdb, $bp; 115 global $wpdb; 116 117 $bp = buddypress(); 116 118 117 119 if ( $friendship = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) ) ) { … … 138 140 */ 139 141 public function save() { 140 global $wpdb, $bp; 142 global $wpdb; 143 144 $bp = buddypress(); 141 145 142 146 $this->initiator_user_id = apply_filters( 'friends_friendship_initiator_user_id_before_save', $this->initiator_user_id, $this->id ); … … 178 182 179 183 public function delete() { 180 global $wpdb, $bp; 184 global $wpdb; 185 186 $bp = buddypress(); 187 181 188 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) ); 182 189 } … … 195 202 */ 196 203 public static function get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) { 197 global $wpdb , $bp;204 global $wpdb; 198 205 199 206 if ( !empty( $friend_requests_only ) ) { … … 205 212 } 206 213 214 $bp = buddypress(); 207 215 $friends = $wpdb->get_results( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} {$friend_sql} {$oc_sql} ORDER BY date_created DESC" ); 208 216 $fids = array(); … … 228 236 */ 229 237 public static function get_friendship_id( $user_id, $friend_id ) { 230 global $wpdb, $bp; 238 global $wpdb; 239 240 $bp = buddypress(); 231 241 232 242 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->friends->table_name} WHERE ( initiator_user_id = %d AND friend_user_id = %d ) OR ( initiator_user_id = %d AND friend_user_id = %d ) AND is_confirmed = 1", $user_id, $friend_id, $friend_id, $user_id ) ); … … 244 254 245 255 if ( false === $friend_requests ) { 246 global $wpdb, $bp; 256 global $wpdb; 257 258 $bp = buddypress(); 247 259 248 260 $friend_requests = $wpdb->get_col( $wpdb->prepare( "SELECT initiator_user_id FROM {$bp->friends->table_name} WHERE friend_user_id = %d AND is_confirmed = 0", $user_id ) ); … … 263 275 */ 264 276 public static function total_friend_count( $user_id = 0 ) { 265 global $wpdb , $bp;277 global $wpdb; 266 278 267 279 if ( empty( $user_id ) ) 268 280 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 281 282 $bp = buddypress(); 269 283 270 284 /* This is stored in 'total_friend_count' usermeta. … … 298 312 */ 299 313 public static function search_friends( $filter, $user_id, $limit = null, $page = null ) { 300 global $wpdb , $bp;314 global $wpdb; 301 315 302 316 // TODO: Optimize this function. … … 321 335 if ( empty( $fids ) ) 322 336 return false; 337 338 $bp = buddypress(); 323 339 324 340 // filter the user_ids based on the search criteria. … … 356 372 */ 357 373 public static function check_is_friend( $initiator_userid, $possible_friend_userid ) { 358 global $wpdb , $bp;374 global $wpdb; 359 375 360 376 if ( empty( $initiator_userid ) || empty( $possible_friend_userid ) ) { 361 377 return false; 362 378 } 379 380 $bp = buddypress(); 363 381 364 382 $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, initiator_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $initiator_userid, $possible_friend_userid, $possible_friend_userid, $initiator_userid ) ); … … 419 437 */ 420 438 public static function accept($friendship_id) { 421 global $wpdb, $bp; 439 global $wpdb; 440 441 $bp = buddypress(); 442 422 443 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, bp_loggedin_user_id() ) ); 423 444 } … … 430 451 */ 431 452 public static function withdraw($friendship_id) { 432 global $wpdb, $bp; 453 global $wpdb; 454 455 $bp = buddypress(); 456 433 457 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND initiator_user_id = %d", $friendship_id, bp_loggedin_user_id() ) ); 434 458 } … … 441 465 */ 442 466 public static function reject($friendship_id) { 443 global $wpdb, $bp; 467 global $wpdb; 468 469 $bp = buddypress(); 470 444 471 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND friend_user_id = %d", $friendship_id, bp_loggedin_user_id() ) ); 445 472 } … … 458 485 */ 459 486 public static function search_users( $filter, $user_id, $limit = null, $page = null ) { 460 global $wpdb , $bp;487 global $wpdb; 461 488 462 489 // Only search for matching strings at the beginning of the … … 470 497 if ( !empty( $limit ) && !empty( $page ) ) 471 498 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) ); 499 500 $bp = buddypress(); 472 501 473 502 // filter the user_ids based on the search criteria. … … 495 524 */ 496 525 public static function search_users_count( $filter ) { 497 global $wpdb , $bp;526 global $wpdb; 498 527 499 528 // Only search for matching strings at the beginning of the … … 503 532 $usermeta_table = $wpdb->prefix . 'usermeta'; 504 533 $users_table = $wpdb->base_prefix . 'users'; 534 535 $bp = buddypress(); 505 536 506 537 // filter the user_ids based on the search criteria. … … 528 559 */ 529 560 public static function sort_by_name( $user_ids ) { 530 global $wpdb , $bp;561 global $wpdb; 531 562 532 563 if ( !bp_is_active( 'xprofile' ) ) 533 564 return false; 565 566 $bp = buddypress(); 534 567 535 568 $user_ids = implode( ',', wp_parse_id_list( $user_ids ) ); … … 548 581 */ 549 582 public static function get_random_friends( $user_id, $total_friends = 5 ) { 550 global $wpdb, $bp; 551 583 global $wpdb; 584 585 $bp = buddypress(); 552 586 $fids = array(); 553 587 $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 ); … … 612 646 */ 613 647 public static function get_user_ids_for_friendship( $friendship_id ) { 614 global $wpdb, $bp; 648 global $wpdb; 649 650 $bp = buddypress(); 651 615 652 return $wpdb->get_row( $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE id = %d", $friendship_id ) ); 616 653 } … … 622 659 */ 623 660 public static function delete_all_for_user( $user_id ) { 624 global $wpdb, $bp; 661 global $wpdb; 662 663 $bp = buddypress(); 625 664 626 665 // Get friends of $user_id
Note: See TracChangeset
for help on using the changeset viewer.