Skip to:
Content

BuddyPress.org

Changeset 4770


Ignore:
Timestamp:
07/21/2011 10:27:09 PM (13 years ago)
Author:
djpaul
Message:

Tune up 'for' loops. Fixes #2985, props cnorris23 and r-a-y

Location:
trunk
Files:
18 edited

Legend:

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

    r4619 r4770  
    446446        $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
    447447
    448         for ( $i = 0; $i < count($activities); $i++ ) {
     448        for ( $i = 0, $count = count( $activities ); $i < $count; ++$i ) {
    449449                $title = explode( '<span', $activities[$i]['content'] );
    450450
  • trunk/bp-blogs/bp-blogs-classes.php

    r4398 r4770  
    251251            return $paged_blogs;
    252252
    253         for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
     253        for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
    254254            $blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id );
    255255            $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
     
    259259        $blog_descs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" ) );
    260260
    261         for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
     261        for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
    262262            foreach ( (array)$blog_descs as $desc ) {
    263263                if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
  • trunk/bp-core/bp-core-classes.php

    r4709 r4770  
    510510        if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) {
    511511            $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", bp_xprofile_fullname_field_name() ) );
    512             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     512            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    513513                foreach ( (array)$names as $name ) {
    514514                    if ( $name->id == $paged_users[$i]->id )
     
    521521        if ( 'popular' != $type ) {
    522522            $friend_count = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as total_friend_count FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'total_friend_count' ) ) );
    523             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     523            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    524524                foreach ( (array)$friend_count as $count ) {
    525525                    if ( $count->id == $paged_users[$i]->id )
     
    532532        if ( bp_is_active( 'friends' ) ) {
    533533            $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", $bp->loggedin_user->id, $bp->loggedin_user->id ) );
    534             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     534            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    535535                foreach ( (array)$friend_status as $status ) {
    536536                    if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
     
    542542        if ( 'active' != $type ) {
    543543            $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) );
    544             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     544            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    545545                foreach ( (array)$user_activity as $activity ) {
    546546                    if ( $activity->id == $paged_users[$i]->id )
     
    553553        if ( 'active' != $type ) {
    554554            $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) );
    555             for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     555            for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    556556                foreach ( (array)$user_activity as $activity ) {
    557557                    if ( $activity->id == $paged_users[$i]->id )
     
    563563        // Fetch the user's latest update
    564564        $user_update = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as latest_update FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'bp_latest_update' ) ) );
    565         for ( $i = 0; $i < count( $paged_users ); $i++ ) {
     565        for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    566566            foreach ( (array)$user_update as $update ) {
    567567                if ( $update->id == $paged_users[$i]->id )
  • trunk/bp-core/bp-core-functions.php

    r4727 r4770  
    643643
    644644        // Step one: the first chunk
    645         for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
     645        for ( $i = 0, $j = count( $chunks ); $i < $j; ++$i ) {
    646646            $seconds = $chunks[$i][0];
    647647
  • trunk/bp-forums/bp-forums-functions.php

    r4764 r4770  
    321321    // Fetch the topic's last poster details
    322322    $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, t.topic_last_poster, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u, {$bbdb->topics} t WHERE u.ID = t.topic_last_poster AND t.topic_id IN ( {$topic_ids} )" ) );
    323     for ( $i = 0; $i < count( $topics ); $i++ ) {
     323    for ( $i = 0, $count = count( $topics ); $i < $count; ++$i ) {
    324324        foreach ( (array)$poster_details as $poster ) {
    325325            if ( $poster->topic_id == $topics[$i]->topic_id ) {
     
    335335    if ( bp_is_active( 'xprofile' ) ) {
    336336        $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) );
    337         for ( $i = 0; $i < count( $topics ); $i++ ) {
     337        for ( $i = 0, $count = count( $topics ); $i < $count; ++$i ) {
    338338            foreach ( (array)$poster_names as $name ) {
    339339                if ( $name->topic_id == $topics[$i]->topic_id )
     
    439439    $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u WHERE u.ID IN ( {$user_ids} )" ) );
    440440
    441     for ( $i = 0; $i < count( $posts ); $i++ ) {
     441    for ( $i = 0, $count = count( $posts ); $i < $count; ++$i ) {
    442442        foreach ( (array)$poster_details as $poster ) {
    443443            if ( $poster->user_id == $posts[$i]->poster_id ) {
     
    453453    if ( bp_is_active( 'xprofile' ) ) {
    454454        $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) );
    455         for ( $i = 0; $i < count( $posts ); $i++ ) {
     455        for ( $i = 0, $count = count( $posts ); $i < $count; ++$i ) {
    456456            foreach ( (array)$poster_names as $name ) {
    457457                if ( isset( $topics[$i] ) && $name->user_id == $topics[$i]->user_id )
  • trunk/bp-friends/bp-friends-classes.php

    r4634 r4770  
    9999        $fids = array();
    100100
    101         for ( $i = 0; $i < count($friends); $i++ ) {
     101        for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) {
    102102            if ( $assoc_arr )
    103103                $fids[] = array( 'user_id' => ( $friends[$i]->friend_user_id == $user_id ) ? $friends[$i]->initiator_user_id : $friends[$i]->friend_user_id );
     
    281281        $results = $wpdb->get_results($sql);
    282282
    283         for ( $i = 0; $i < count($results); $i++ ) {
     283        for ( $i = 0, $count = count( $results ); $i < $count; ++$i ) {
    284284            $fids[] = ( $results[$i]->friend_user_id == $user_id ) ? $results[$i]->initiator_user_id : $results[$i]->friend_user_id;
    285285        }
    286286
    287287        // remove duplicates
    288         if ( count($fids) > 0 )
     288        if ( count( $fids ) > 0 )
    289289            return array_flip(array_flip($fids));
    290290        else
     
    298298
    299299        $invitable_count = 0;
    300         for ( $i = 0; $i < count($friend_ids); $i++ ) {
     300        for ( $i = 0, $count = count( $friend_ids ); $i < $count; ++$i ) {
    301301
    302302            if ( BP_Groups_Member::check_is_member( (int)$friend_ids[$i], $group_id ) )
  • trunk/bp-friends/bp-friends-functions.php

    r4605 r4770  
    245245        return false;
    246246
    247     for ( $i = 0; $i < count( $user_ids ); $i++ )
    248         $users[] = new BP_Core_User($user_ids[$i]);
     247    for ( $i = 0, $count = count( $user_ids ); $i < $count; ++$i )
     248        $users[] = new BP_Core_User( $user_ids[$i] );
    249249
    250250    return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count( $search_terms ) );
  • trunk/bp-friends/bp-friends-template.php

    r4675 r4770  
    9393            <ul class="horiz-gallery">
    9494
    95             <?php for ( $i = 0; $i < count( $friend_ids ); $i++ ) { ?>
     95            <?php for ( $i = 0, $count = count( $friend_ids ); $i < $count; ++$i ) { ?>
    9696
    9797                <li>
     
    139139        <ul class="item-list" id="random-members-list">
    140140
    141         <?php for ( $i = 0; $i < count( $user_ids['users'] ); $i++ ) { ?>
     141        <?php for ( $i = 0, $count = count( $user_ids['users'] ); $i < $count; ++$i ) { ?>
    142142
    143143            <li>
  • trunk/bp-groups/bp-groups-classes.php

    r4764 r4770  
    542542        /* Fetch the logged in users status within each group */
    543543        $user_status = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_confirmed = 1 AND is_banned = 0", $bp->loggedin_user->id ) );
    544         for ( $i = 0; $i < count( $paged_groups ); $i++ ) {
     544        for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
    545545            $paged_groups[$i]->is_member = false;
    546546
     
    552552
    553553        $user_banned = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE is_banned = 1 AND user_id = %d AND group_id IN ( {$group_ids} )", $bp->loggedin_user->id ) );
    554         for ( $i = 0; $i < count( $paged_groups ); $i++ ) {
     554        for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
    555555            $paged_groups[$i]->is_banned = false;
    556556
     
    11061106        if ( bp_is_active( 'friends' ) ) {
    11071107            $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", $bp->loggedin_user->id, $bp->loggedin_user->id ) );
    1108             for ( $i = 0; $i < count( $members ); $i++ ) {
     1108            for ( $i = 0, $count = count( $members ); $i < $count; ++$i ) {
    11091109                foreach ( (array)$friend_status as $status ) {
    11101110                    if ( $status->initiator_user_id == $members[$i]->user_id || $status->friend_user_id == $members[$i]->user_id )
  • trunk/bp-groups/bp-groups-functions.php

    r4729 r4770  
    645645    $group = new BP_Groups_Group( $group_id );
    646646
    647     for ( $i = 0; $i < count( $invited_users ); $i++ ) {
     647    for ( $i = 0, $count = count( $invited_users ); $i < $count; ++$i ) {
    648648        $member = new BP_Groups_Member( $invited_users[$i], $group_id );
    649649
     
    779779
    780780        // Saved okay, now send the email notification
    781         for ( $i = 0; $i < count( $admins ); $i++ )
     781        for ( $i = 0, $count = count( $admins ); $i < $count; ++$i )
    782782            groups_notification_new_membership_request( $requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id );
    783783
  • trunk/bp-groups/bp-groups-template.php

    r4729 r4770  
    22002200            $invites = groups_get_invites_for_group( $bp->loggedin_user->id, $group_id );
    22012201
    2202             for ( $i = 0; $i < count( $friends ); $i++ ) {
     2202            for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) {
    22032203                $checked = '';
    22042204
  • trunk/bp-members/bp-members-buddybar.php

    r4761 r4770  
    2121    if ( $notifications ) {
    2222        $counter = 0;
    23         for ( $i = 0; $i < count($notifications); $i++ ) {
     23        for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) {
    2424            $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
    2525
  • trunk/bp-members/bp-members-notifications.php

    r4624 r4770  
    5050
    5151    // Group notifications by component and component_action and provide totals
    52     for ( $i = 0; $i < count($notifications); $i++ ) {
     52    for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) {
    5353        $notification = $notifications[$i];
    5454        $grouped_notifications[$notification->component_name][$notification->component_action][] = $notification;
  • trunk/bp-messages/bp-messages-classes.php

    r4736 r4770  
    176176
    177177        $count = 0;
    178         for ( $i = 0; $i < count( $unread_counts ); $i++ ) {
     178        for ( $i = 0, $count = count( $unread_counts ); $i < $count; ++$i ) {
    179179            $count += $unread_counts[$i]->unread_count;
    180180        }
     
    342342
    343343        if ( is_array( $recipient_usernames ) ) {
    344             for ( $i = 0; $i < count($recipient_usernames); $i++ ) {
     344            for ( $i = 0, $count = count( $recipient_usernames ); $i < $count; ++$i ) {
    345345                if ( $rid = bp_core_get_userid( trim($recipient_usernames[$i]) ) )
    346346                    $recipient_ids[] = $rid;
  • trunk/bp-messages/bp-messages-functions.php

    r4628 r4770  
    136136    if ( is_array( $thread_ids ) ) {
    137137        $error = 0;
    138         for ( $i = 0; $i < count( $thread_ids ); $i++ ) {
     138        for ( $i = 0, $count = count( $thread_ids ); $i < $count; ++$i ) {
    139139            if ( !$status = BP_Messages_Thread::delete( $thread_ids[$i]) )
    140140                $error = 1;
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r4710 r4770  
    559559        $thread_ids = explode( ',', $_POST['thread_ids'] );
    560560
    561         for ( $i = 0; $i < count($thread_ids); $i++ ) {
     561        for ( $i = 0, $count = count( $thread_ids ); $i < $count; ++$i ) {
    562562            BP_Messages_Thread::mark_as_unread($thread_ids[$i]);
    563563        }
     
    575575        $thread_ids = explode( ',', $_POST['thread_ids'] );
    576576
    577         for ( $i = 0; $i < count($thread_ids); $i++ ) {
     577        for ( $i = 0, $count = count( $thread_ids ); $i < $count; ++$i ) {
    578578            BP_Messages_Thread::mark_as_read($thread_ids[$i]);
    579579        }
     
    591591        $thread_ids = explode( ',', $_POST['thread_ids'] );
    592592
    593         for ( $i = 0; $i < count($thread_ids); $i++ )
     593        for ( $i = 0, $count = count( $thread_ids ); $i < $count; ++$i )
    594594            BP_Messages_Thread::delete($thread_ids[$i]);
    595595
    596         _e('Messages deleted.', 'buddypress');
     596        _e( 'Messages deleted.', 'buddypress' );
    597597    }
    598598}
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r4634 r4770  
    7373            if ( BP_XProfile_Field::delete_for_group( $this->id ) ) {
    7474                /* Remove profile data for the groups fields */
    75                 for ( $i = 0; $i < count( $this->fields ); $i++ ) {
     75                for ( $i = 0, $count = count( $this->fields ); $i < $count; ++$i ) {
    7676                    BP_XProfile_ProfileData::delete_for_field( $this->fields[$i]->id );
    7777                }
     
    587587                        );
    588588
    589                         $i++;
     589                        ++$i;
    590590                    }
    591591                }
    592592
    593593                if ( !empty( $options ) ) {
    594                     for ( $i = 0; $i < count( $options ); $i++ ) {
     594                    for ( $i = 0, $count = count( $options ); $i < $count; ++$i ) {
    595595                        $j = $i + 1;
    596596
     
    911911
    912912        if ( is_array( $fields ) ) {
    913             for ( $i = 0; $i < count( $fields ); $i++ ) {
     913            for ( $i = 0, $count = count( $fields ); $i < $count; ++$i ) {
    914914                if ( $i == 0 )
    915915                    $field_sql .= $wpdb->prepare( "AND ( f.name = %s ", $fields[$i] );
     
    931931
    932932        if ( is_array( $fields ) ) {
    933             for ( $i = 0; $i < count( $values ); $i++ ) {
     933            for ( $i = 0, $count = count( $values ); $i < $count; ++$i ) {
    934934                for ( $j = 0; $j < count( $fields ); $j++ ) {
    935935                    if ( $values[$i]->name == $fields[$j] )
  • trunk/bp-xprofile/bp-xprofile-template.php

    r4678 r4770  
    103103        $has_data = false;
    104104
    105         for ( $i = 0; $i < count( $this->group->fields ); $i++ ) {
     105        for ( $i = 0, $count = count( $this->group->fields ); $i < $count; ++$i ) {
    106106            $field = &$this->group->fields[$i];
    107107
     
    548548                        $html .= '<option value=""' . selected( $day, '', false ) . '>--</option>';
    549549
    550                         for ( $i = 1; $i < 32; $i++ ) {
     550                        for ( $i = 1; $i < 32; ++$i ) {
    551551                            $html .= '<option value="' . $i .'"' . selected( $day, $i, false ) . '>' . $i . '</option>';
    552552                        }
     
    564564                        $html .= '<option value=""' . selected( $month, '', false ) . '>------</option>';
    565565
    566                         for ( $i = 0; $i < 12; $i++ ) {
     566                        for ( $i = 0; $i < 12; ++$i ) {
    567567                            $html .= '<option value="' . $eng_months[$i] . '"' . selected( $month, $eng_months[$i], false ) . '>' . $months[$i] . '</option>';
    568568                        }
     
    634634
    635635    $tabs = array();
    636     for ( $i = 0, $count = count( $groups ); $i < $count; $i++ ) {
     636    for ( $i = 0, $count = count( $groups ); $i < $count; ++$i ) {
    637637        if ( $group_name == $groups[$i]->name )
    638638            $selected = ' class="current"';
Note: See TracChangeset for help on using the changeset viewer.