Skip to:
Content

BuddyPress.org

Changeset 11023


Ignore:
Timestamp:
08/22/2016 09:34:15 PM (8 years ago)
Author:
r-a-y
Message:

Blogs: Cast blog properties as integers where appropriate.

See #6977.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/classes/class-bp-blogs-blog.php

    r10426 r11023  
    4949    public function __construct( $id = null ) {
    5050        if ( !empty( $id ) ) {
    51             $this->id = $id;
     51            $this->id = (int) $id;
    5252            $this->populate();
    5353        }
     
    6464        $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
    6565
    66         $this->user_id = $blog->user_id;
    67         $this->blog_id = $blog->blog_id;
     66        $this->user_id = (int) $blog->user_id;
     67        $this->blog_id = (int) $blog->blog_id;
    6868    }
    6969
     
    244244        $paged_blogs = BP_Blogs_Blog::get_blog_extras( $paged_blogs, $blog_ids, $type );
    245245
     246        // Integer casting.
     247        foreach ( (array) $paged_blogs as $key => $data ) {
     248            $paged_blogs[ $key ]->blog_id       = (int) $paged_blogs[ $key ]->blog_id;
     249            $paged_blogs[ $key ]->admin_user_id = (int) $paged_blogs[ $key ]->admin_user_id;
     250        }
     251
    246252        if ( $update_meta_cache ) {
    247253            bp_blogs_update_meta_cache( $blog_ids );
     
    339345        foreach ( (array) $blogs as $blog ) {
    340346            $user_blogs[$blog->blog_id] = new stdClass;
    341             $user_blogs[$blog->blog_id]->id = $blog->id;
    342             $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
     347            $user_blogs[$blog->blog_id]->id = (int) $blog->id;
     348            $user_blogs[$blog->blog_id]->blog_id = (int) $blog->blog_id;
    343349            $user_blogs[$blog->blog_id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
    344350            $user_blogs[$blog->blog_id]->name = $blog->name;
     
    365371            $user_id = bp_displayed_user_id();
    366372
    367         return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
     373        return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) ) );
    368374    }
    369375
     
    380386        $bp = buddypress();
    381387
    382         return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
     388        $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
     389
     390        return is_numeric( $query ) ? (int) $query : $query;
    383391    }
    384392
     
    445453        $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND {$search_terms_sql} ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" );
    446454
    447         return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     455        // Integer casting.
     456        foreach ( (array) $paged_blogs as $key => $data ) {
     457            $paged_blogs[ $key ]->blog_id = (int) $paged_blogs[ $key ]->blog_id;
     458        }
     459
     460        return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs );
    448461    }
    449462
     
    473486        $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql}" );
    474487
    475         return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     488        // Integer casting.
     489        foreach ( (array) $paged_blogs as $key => $data ) {
     490            $paged_blogs[ $key ]->blog_id = (int) $paged_blogs[ $key ]->blog_id;
     491        }
     492
     493        return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs );
    476494    }
    477495
     
    510528        $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND {$letter_sql} {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" );
    511529
    512         return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     530        // Integer casting.
     531        foreach ( (array) $paged_blogs as $key => $data ) {
     532            $paged_blogs[ $key ]->blog_id = (int) $paged_blogs[ $key ]->blog_id;
     533        }
     534
     535        return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs );
    513536    }
    514537
Note: See TracChangeset for help on using the changeset viewer.