Skip to:
Content

BuddyPress.org

Changeset 7052


Ignore:
Timestamp:
05/11/2013 11:42:36 AM (12 years ago)
Author:
boonebgorges
Message:

Don't use extract() in BP_Groups_Group::get()

extract() is not cool.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r7021 r7052  
    346346
    347347        $r = wp_parse_args( $args, $defaults );
    348         extract( $r );
    349348
    350349        $sql       = array();
     
    354353        $sql['from']   = " FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2,";
    355354
    356         if ( !empty( $user_id ) )
     355        if ( !empty( $r['user_id'] ) )
    357356            $sql['members_from'] = " {$bp->groups->table_name_members} m,";
    358357
    359358        $sql['group_from'] = " {$bp->groups->table_name} g WHERE";
    360359
    361         if ( !empty( $user_id ) )
     360        if ( !empty( $r['user_id'] ) )
    362361            $sql['user_where'] = " g.id = m.group_id AND";
    363362
    364363        $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'";
    365364
    366         if ( empty( $show_hidden ) )
     365        if ( empty( $r['show_hidden'] ) )
    367366            $sql['hidden'] = " AND g.status != 'hidden'";
    368367
    369         if ( !empty( $search_terms ) ) {
    370             $search_terms = esc_sql( like_escape( $search_terms ) );
     368        if ( !empty( $r['search_terms'] ) ) {
     369            $search_terms = esc_sql( like_escape( $r['search_terms'] ) );
    371370            $sql['search'] = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
    372371        }
    373372
    374         $meta_query_sql = self::get_meta_query_sql( $meta_query );
     373        $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] );
    375374
    376375        if ( ! empty( $meta_query_sql['join'] ) ) {
     
    383382        }
    384383
    385         if ( !empty( $user_id ) )
    386             $sql['user'] = $wpdb->prepare( " AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id );
    387 
    388         if ( !empty( $include ) ) {
     384        if ( !empty( $r['user_id'] ) )
     385            $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'] ) ) {
    389388            $include        = wp_parse_id_list( $r['include'] );
    390389            $include        = $wpdb->escape( implode( ',', $include ) );
     
    392391        }
    393392
    394         if ( !empty( $exclude ) ) {
     393        if ( !empty( $r['exclude'] ) ) {
    395394            $exclude        = wp_parse_id_list( $r['exclude'] );
    396395            $exclude        = $wpdb->escape( implode( ',', $exclude ) );
     
    398397        }
    399398
    400         switch ( $type ) {
     399        switch ( $r['type'] ) {
    401400            case 'newest': default:
    402401                $sql['order'] = " ORDER BY g.date_created DESC";
     
    416415        }
    417416
    418         if ( !empty( $per_page ) && !empty( $page ) )
    419             $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page), intval( $per_page ) );
     417        if ( !empty( $r['per_page'] ) && !empty( $r['page'] ) )
     418            $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['per_page']), intval( $r['per_page'] ) );
    420419
    421420        // Get paginated results
     
    425424        $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";
    426425
    427         if ( !empty( $user_id ) )
     426        if ( !empty( $r['user_id'] ) )
    428427            $total_sql['select'] .= ", {$bp->groups->table_name_members} m";
    429428
     
    434433            $total_sql['where'][] = "( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
    435434
    436         if ( !empty( $user_id ) )
     435        if ( !empty( $r['user_id'] ) )
    437436            $total_sql['where'][] = "m.group_id = g.id AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0";
    438437
     
    464463
    465464        // Populate some extra information instead of querying each time in the loop
    466         if ( !empty( $populate_extras ) ) {
     465        if ( !empty( $r['populate_extras'] ) ) {
    467466            $group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
    468             $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $type );
     467            $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $r['type'] );
    469468        }
    470469
Note: See TracChangeset for help on using the changeset viewer.