Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/22/2016 10:11:20 PM (9 years ago)
Author:
r-a-y
Message:

Groups: Cast properties as integers where appropriate.

See #6977.

File:
1 edited

Legend:

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

    r10794 r11027  
    186186
    187187        if ( !empty( $member ) ) {
    188             $this->id            = $member->id;
    189             $this->group_id      = $member->group_id;
    190             $this->user_id       = $member->user_id;
    191             $this->inviter_id    = $member->inviter_id;
    192             $this->is_admin      = $member->is_admin;
    193             $this->is_mod        = $member->is_mod;
    194             $this->is_banned     = $member->is_banned;
     188            $this->id            = (int) $member->id;
     189            $this->group_id      = (int) $member->group_id;
     190            $this->user_id       = (int) $member->user_id;
     191            $this->inviter_id    = (int) $member->inviter_id;
     192            $this->is_admin      = (int) $member->is_admin;
     193            $this->is_mod        = (int) $member->is_mod;
     194            $this->is_banned     = (int) $member->is_banned;
    195195            $this->user_title    = $member->user_title;
    196196            $this->date_modified = $member->date_modified;
    197             $this->is_confirmed  = $member->is_confirmed;
     197            $this->is_confirmed  = (int) $member->is_confirmed;
    198198            $this->comments      = $member->comments;
    199             $this->invite_sent   = $member->invite_sent;
     199            $this->invite_sent   = (int) $member->invite_sent;
    200200
    201201            $this->user = new BP_Core_User( $this->user_id );
     
    787787     * @param string $type     If 'sent', results are limited to those invitations
    788788     *                         that have actually been sent (non-draft). Default: 'sent'.
    789      * @return int|null The ID of the invitation if found, otherwise null.
     789     * @return int|null The ID of the invitation if found; null if not found.
    790790     */
    791791    public static function check_has_invite( $user_id, $group_id, $type = 'sent' ) {
     
    801801            $sql .= " AND invite_sent = 1";
    802802
    803         return $wpdb->get_var( $wpdb->prepare( $sql, $user_id, $group_id ) );
     803        $query = $wpdb->get_var( $wpdb->prepare( $sql, $user_id, $group_id ) );
     804
     805        return is_numeric( $query ) ? (int) $query : $query;
    804806    }
    805807
     
    932934     * @param int $user_id  ID of the user.
    933935     * @param int $group_id ID of the group.
    934      * @return mixed
     936     * @return int|null int 1 if user is banned; int 0 if user is not banned;
     937     *                  null if user is not part of the group or if group doesn't exist.
    935938     */
    936939    public static function check_is_banned( $user_id, $group_id ) {
     
    942945        $bp = buddypress();
    943946
    944         return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
     947        $query = $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
     948
     949        return is_numeric( $query ) ? (int) $query : $query;
    945950    }
    946951
     
    952957     * @param int $user_id  ID of the user.
    953958     * @param int $group_id ID of the group.
    954      * @return int|null ID of the group if the user is the creator,
    955      *                  otherwise false.
     959     * @return int|null int of group ID if user is the creator; null on failure.
    956960     */
    957961    public static function check_is_creator( $user_id, $group_id ) {
     
    963967        $bp = buddypress();
    964968
    965         return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
     969        $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
     970
     971        return is_numeric( $query ) ? (int) $query : $query;
    966972    }
    967973
     
    973979     * @param int $user_id  ID of the user.
    974980     * @param int $group_id ID of the group.
    975      * @return int|null ID of the membership if found, otherwise false.
     981     * @return int Database ID of the membership if found; int 0 on failure.
    976982     */
    977983    public static function check_for_membership_request( $user_id, $group_id ) {
     
    10021008        // If the user is logged in and viewing their random groups, we can show hidden and private groups.
    10031009        if ( bp_is_my_profile() ) {
    1004             return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) );
     1010            return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) );
    10051011        } else {
    1006             return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) );
     1012            return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) );
    10071013        }
    10081014    }
     
    10211027        $bp = buddypress();
    10221028
    1023         return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) );
     1029        return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) ) );
    10241030    }
    10251031
     
    10441050        }
    10451051
     1052        // Integer casting.
     1053        foreach ( (array) $group_admins as $key => $data ) {
     1054            $group_admins[ $key ]->user_id = (int) $group_admins[ $key ]->user_id;
     1055        }
     1056
    10461057        return $group_admins;
    10471058    }
     
    10601071        $bp = buddypress();
    10611072
    1062         return $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_mod = 1 AND is_banned = 0", $group_id ) );
     1073        $group_mods = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_mod = 1 AND is_banned = 0", $group_id ) );
     1074
     1075        // Integer casting.
     1076        foreach ( (array) $group_mods as $key => $data ) {
     1077            $group_mods[ $key ]->user_id = (int) $group_mods[ $key ]->user_id;
     1078        }
     1079
     1080        return $group_mods;
    10631081    }
    10641082
     
    10931111        $bp = buddypress();
    10941112
    1095         return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 0 AND inviter_id = 0", $group_id ) );
     1113        return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 0 AND inviter_id = 0", $group_id ) ) );
    10961114    }
    10971115
Note: See TracChangeset for help on using the changeset viewer.