Changeset 7053
- Timestamp:
- 05/11/2013 11:42:40 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r7052 r7053 353 353 $sql['from'] = " FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2,"; 354 354 355 if ( ! empty( $r['user_id'] ) )355 if ( ! empty( $r['user_id'] ) ) { 356 356 $sql['members_from'] = " {$bp->groups->table_name_members} m,"; 357 } 357 358 358 359 $sql['group_from'] = " {$bp->groups->table_name} g WHERE"; 359 360 360 if ( ! empty( $r['user_id'] ) )361 if ( ! empty( $r['user_id'] ) ) { 361 362 $sql['user_where'] = " g.id = m.group_id AND"; 363 } 362 364 363 365 $sql['where'] = " g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'"; 364 366 365 if ( empty( $r['show_hidden'] ) ) 367 if ( empty( $r['show_hidden'] ) ) { 366 368 $sql['hidden'] = " AND g.status != 'hidden'"; 367 368 if ( !empty( $r['search_terms'] ) ) { 369 } 370 371 if ( ! empty( $r['search_terms'] ) ) { 369 372 $search_terms = esc_sql( like_escape( $r['search_terms'] ) ); 370 373 $sql['search'] = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )"; … … 382 385 } 383 386 384 if ( ! empty( $r['user_id'] ) )387 if ( ! empty( $r['user_id'] ) ) { 385 388 $sql['user'] = $wpdb->prepare( " AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $r['user_id'] ); 386 387 if ( !empty( $r['include'] ) ) { 389 } 390 391 if ( ! empty( $r['include'] ) ) { 388 392 $include = wp_parse_id_list( $r['include'] ); 389 393 $include = $wpdb->escape( implode( ',', $include ) ); … … 391 395 } 392 396 393 if ( ! empty( $r['exclude'] ) ) {397 if ( ! empty( $r['exclude'] ) ) { 394 398 $exclude = wp_parse_id_list( $r['exclude'] ); 395 399 $exclude = $wpdb->escape( implode( ',', $exclude ) ); … … 398 402 399 403 switch ( $r['type'] ) { 400 case 'newest': default: 404 case 'newest': 405 default: 401 406 $sql['order'] = " ORDER BY g.date_created DESC"; 402 407 break; … … 415 420 } 416 421 417 if ( ! empty( $r['per_page'] ) && !empty( $r['page'] ) )422 if ( ! empty( $r['per_page'] ) && ! empty( $r['page'] ) ) { 418 423 $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['per_page']), intval( $r['per_page'] ) ); 424 } 419 425 420 426 // Get paginated results … … 424 430 $total_sql['select'] = "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name} g, {$bp->groups->table_name_members} gm1, {$bp->groups->table_name_groupmeta} gm2"; 425 431 426 if ( ! empty( $r['user_id'] ) )432 if ( ! empty( $r['user_id'] ) ) { 427 433 $total_sql['select'] .= ", {$bp->groups->table_name_members} m"; 428 429 if ( !empty( $sql['hidden'] ) ) 434 } 435 436 if ( ! empty( $sql['hidden'] ) ) { 430 437 $total_sql['where'][] = "g.status != 'hidden'"; 431 432 if ( !empty( $sql['search'] ) ) 438 } 439 440 if ( ! empty( $sql['search'] ) ) { 433 441 $total_sql['where'][] = "( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )"; 434 435 if ( !empty( $r['user_id'] ) ) 442 } 443 444 if ( ! empty( $r['user_id'] ) ) { 436 445 $total_sql['where'][] = "m.group_id = g.id AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0"; 446 } 437 447 438 448 // Already escaped in the paginated results block 439 if ( ! empty( $include ) ) 449 if ( ! empty( $include ) ) { 440 450 $total_sql['where'][] = "g.id IN ({$include})"; 451 } 441 452 442 453 // Already escaped in the paginated results block 443 if ( ! empty( $exclude ) ) 454 if ( ! empty( $exclude ) ) { 444 455 $total_sql['where'][] = "g.id NOT IN ({$exclude})"; 456 } 445 457 446 458 $total_sql['where'][] = "g.id = gm1.group_id"; … … 450 462 $t_sql = $total_sql['select']; 451 463 452 if ( ! empty( $total_sql['where'] ) )464 if ( ! empty( $total_sql['where'] ) ) { 453 465 $t_sql .= " WHERE " . join( ' AND ', (array) $total_sql['where'] ); 466 } 454 467 455 468 // Get total group results
Note: See TracChangeset
for help on using the changeset viewer.