Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/09/2012 09:38:45 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Remove a bunch of unneeded globals and clean up some code in Core component. See #3989.

File:
1 edited

Legend:

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

    r5595 r5683  
    137137     * Populate the instantiated class with data based on the User ID provided.
    138138     *
    139      * @global object $bp Global BuddyPress settings object
    140139     * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id
    141140     * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text
     
    146145     */
    147146    function populate() {
    148         global $bp;
    149147
    150148        if ( bp_is_active( 'xprofile' ) )
     
    178176    /**
    179177     * Populates extra fields such as group and friendship counts.
    180      *
    181      * @global object $bp Global BuddyPress settings object
    182178     */
    183179    function populate_extras() {
    184         global $bp;
    185 
    186         if ( bp_is_active( 'friends' ) )
     180
     181        if ( bp_is_active( 'friends' ) ) {
    187182            $this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );
     183        }
    188184
    189185        if ( bp_is_active( 'groups' ) ) {
     
    206202        $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
    207203
    208         if ( 'active' == $type || 'online' == $type || 'newest' == $type  )
     204        if ( 'active' == $type || 'online' == $type || 'newest' == $type  ) {
    209205            $sql['select_active'] = ", um.meta_value as last_activity";
    210 
    211         if ( 'popular' == $type )
     206        }
     207
     208        if ( 'popular' == $type ) {
    212209            $sql['select_popular'] = ", um.meta_value as total_friend_count";
    213 
    214         if ( 'alphabetical' == $type )
     210        }
     211
     212        if ( 'alphabetical' == $type ) {
    215213            $sql['select_alpha'] = ", pd.value as fullname";
     214        }
    216215
    217216        if ( $meta_key ) {
    218217            $sql['select_meta'] = ", umm.meta_key";
    219218
    220             if ( $meta_value )
     219            if ( $meta_value ) {
    221220                $sql['select_meta'] .= ", umm.meta_value";
     221            }
    222222        }
    223223
     
    225225
    226226        // We search against xprofile fields, so we must join the table
    227         if ( $search_terms && bp_is_active( 'xprofile' ) )
     227        if ( $search_terms && bp_is_active( 'xprofile' ) ) {
    228228            $sql['join_profiledata_search'] = "LEFT JOIN {$bp->profile->table_name_data} spd ON u.ID = spd.user_id";
     229        }
    229230
    230231        // Alphabetical sorting is done by the xprofile Full Name field
    231         if ( 'alphabetical' == $type )
     232        if ( 'alphabetical' == $type ) {
    232233            $sql['join_profiledata_alpha'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
    233 
    234         if ( $meta_key )
     234        }
     235
     236        if ( $meta_key ) {
    235237            $sql['join_meta'] = "LEFT JOIN {$wpdb->usermeta} umm ON umm.user_id = u.ID";
     238        }
    236239
    237240        $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
    238241
    239         if ( 'active' == $type || 'online' == $type || 'newest' == $type )
     242        if ( 'active' == $type || 'online' == $type || 'newest' == $type ) {
    240243            $sql['where_active'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'last_activity' ) );
    241 
    242         if ( 'popular' == $type )
     244        }
     245
     246        if ( 'popular' == $type ) {
    243247            $sql['where_popular'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'total_friend_count' ) );
    244 
    245         if ( 'online' == $type )
     248        }
     249
     250        if ( 'online' == $type ) {
    246251            $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
    247 
    248         if ( 'alphabetical' == $type )
     252        }
     253
     254        if ( 'alphabetical' == $type ) {
    249255            $sql['where_alpha'] = "AND pd.field_id = 1";
    250 
    251         if ( !empty( $exclude ) )
     256        }
     257
     258        if ( !empty( $exclude ) ) {
    252259            $sql['where_exclude'] = "AND u.ID NOT IN ({$exclude})";
     260        }
    253261
    254262        if ( $include ) {
    255             if ( is_array( $include ) )
     263            if ( is_array( $include ) ) {
    256264                $uids = $wpdb->escape( implode( ',', (array)$include ) );
    257             else
     265            } else {
    258266                $uids = $wpdb->escape( $include );
    259 
    260             if ( !empty( $uids ) )
     267            }
     268
     269            if ( !empty( $uids ) ) {
    261270                $sql['where_users'] = "AND u.ID IN ({$uids})";
    262         }
    263 
    264         else if ( $user_id && bp_is_active( 'friends' ) ) {
     271            }
     272        } elseif ( $user_id && bp_is_active( 'friends' ) ) {
    265273            $friend_ids = friends_get_friend_user_ids( $user_id );
    266274            $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
    267275
    268             if ( !empty( $friend_ids ) )
     276            if ( !empty( $friend_ids ) ) {
    269277                $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
    270278
    271279            // User has no friends, return false since there will be no users to fetch.
    272             else
     280            } else {
    273281                return false;
    274 
     282            }
    275283        }
    276284
     
    307315        }
    308316
    309         if ( $limit && $page )
     317        if ( $limit && $page ) {
    310318            $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     319        }
    311320
    312321        // Get paginated results
     
    317326        unset( $sql['select_main'] );
    318327
    319         if ( !empty( $sql['select_active'] ) )
     328        if ( !empty( $sql['select_active'] ) ) {
    320329            unset( $sql['select_active'] );
    321 
    322         if ( !empty( $sql['select_popular'] ) )
     330        }
     331
     332        if ( !empty( $sql['select_popular'] ) ) {
    323333            unset( $sql['select_popular'] );
    324 
    325         if ( !empty( $sql['select_alpha'] ) )
     334        }
     335
     336        if ( !empty( $sql['select_alpha'] ) ) {
    326337            unset( $sql['select_alpha'] );
    327 
    328         if ( !empty( $sql['pagination'] ) )
     338        }
     339
     340        if ( !empty( $sql['pagination'] ) ) {
    329341            unset( $sql['pagination'] );
     342        }
    330343
    331344        array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
     
    342355            $user_ids = array();
    343356
    344             foreach ( (array)$paged_users as $user )
     357            foreach ( (array)$paged_users as $user ) {
    345358                $user_ids[] = $user->id;
     359            }
    346360
    347361            $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     
    372386
    373387        $pag_sql = '';
    374         if ( $limit && $page )
     388        if ( $limit && $page ) {
    375389            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     390        }
    376391
    377392        // Multibyte compliance
     
    398413
    399414        /***
    400          * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
    401          * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     415         * Lets fetch some other useful data in a separate queries, this will be
     416         * faster than querying the data for every user in a list. We can't add
     417         * these to the main query above since only users who have this
     418         * information will be returned (since the much of the data is in
     419         * usermeta and won't support any type of directional join)
    402420         */
    403421        $user_ids = array();
     
    407425        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
    408426
    409         /* Add additional data to the returned results */
    410         if ( $populate_extras )
     427        // Add additional data to the returned results
     428        if ( $populate_extras ) {
    411429            $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
     430        }
    412431
    413432        return array( 'users' => $paged_users, 'total' => $total_users );
     
    417436     * Get details of specific users from the database
    418437     *
    419      * @global object $bp Global BuddyPress settings object
    420438     * @global wpdb $wpdb WordPress database object
    421439     * @param array $user_ids The user IDs of the users who we wish to fetch information on.
     
    427445     */
    428446    function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {
    429         global $bp, $wpdb;
     447        global $wpdb;
    430448
    431449        $pag_sql = '';
     
    433451            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    434452
     453        // @todo remove? $user_sql is not used here
    435454        $user_sql   = " AND user_id IN ( " . $wpdb->escape( $user_ids ) . " ) ";
    436455        $status_sql = bp_core_get_status_sql();
     
    443462
    444463        /***
    445          * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
    446          * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
     464         * Lets fetch some other useful data in a separate queries, this will be
     465         * faster than querying the data for every user in a list. We can't add
     466         * these to the main query above since only users who have this
     467         * information will be returned (since the much of the data is in
     468         * usermeta and won't support any type of directional join)
    447469         */
    448470
    449         /* Add additional data to the returned results */
    450         if ( $populate_extras )
     471        // Add additional data to the returned results
     472        if ( !empty( $populate_extras ) ) {
    451473            $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
     474        }
    452475
    453476        return array( 'users' => $paged_users, 'total' => $total_users );
     
    10281051
    10291052            // Wrapper ID
    1030             if ( !empty( $wrapper_id ) )
     1053            if ( !empty( $wrapper_id ) ) {
    10311054                $this->wrapper_id    = ' id="' . $wrapper_id . '"';
     1055            }
    10321056
    10331057            // Wrapper class
    1034             if ( !empty( $wrapper_class ) )
     1058            if ( !empty( $wrapper_class ) ) {
    10351059                $this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"';
    1036             else
     1060            } else {
    10371061                $this->wrapper_class = ' class="generic-button"';
     1062            }
    10381063
    10391064            // Set before and after
     
    11741199            foreach ( $handlers as $hid => $handler ) {
    11751200                if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
    1176                     if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
     1201                    if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) {
    11771202                        return apply_filters( 'embed_handler_html', $return, $url, $attr );
     1203                    }
    11781204                }
    11791205            }
Note: See TracChangeset for help on using the changeset viewer.