Skip to:
Content

BuddyPress.org

Ticket #5272: 5272.patch

File 5272.patch, 8.3 KB (added by boonebgorges, 11 years ago)
  • bp-blogs/bp-blogs-classes.php

    diff --git bp-blogs/bp-blogs-classes.php bp-blogs/bp-blogs-classes.php
    index f41afea..05470f6 100644
    class BP_Blogs_Blog { 
    103103
    104104        /**
    105105         * Retrieve a set of blog-user associations.
    106          *
    107          * @param string $type The order in which results should be returned.
    108          *        'active', 'alphabetical', 'newest', or 'random'.
    109          * @param int|bool $limit Optional. The maximum records to return.
    110          *        Default: false.
    111          * @param int|bool $page Optional. The page of records to return.
    112          *        Default: false (unlimited results).
    113          * @param int $user_id Optional. ID of the user whose blogs are being
    114          *        retrieved. Default: 0.
    115          * @param string|bool $search_terms Optional. Search by text stored in
    116          *        blogmeta (such as the blog name). Default: false.
    117          * @return array Multidimensional results array, structured as follows:
    118          *           'blogs' - Array of located blog objects
    119          *           'total' - A count of the total blogs matching the filter params
     106         * @param array $args {
     107         *     An array of arguments. All items are optional.
     108         *     @type string $type The order in which results should be returned.
     109         *            'active', 'alphabetical', 'newest', or 'random'.
     110         *     @type int|bool $limit Optional. The maximum records to return.
     111         *            Default: false.
     112         *     @type int|bool $page Optional. The page of records to return.
     113         *            Default: false (unlimited results).
     114         *     @type int $user_id Optional. ID of the user whose blogs are being
     115         *            retrieved. Default: 0.
     116         *     @type string|bool $search_terms Optional. Search by text stored in
     117         *            blogmeta (such as the blog name). Default: false.
     118         * }
     119         * @return array {
     120         *     Multidimensional results array, structured as follows:
     121         *     @var array $blogs Array of located blog objects.
     122         *     @var int $total A count of the total blogs matching the filter params.
     123         * }
    120124         */
    121         public static function get( $type, $limit = false, $page = false, $user_id = 0, $search_terms = false ) {
     125        public static function get( $args = array() ) {
    122126                global $bp, $wpdb;
    123127
     128                // Backward compatibility with old method of passing arguments
     129                if ( !is_array( $args ) || func_num_args() > 1 ) {
     130                        _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     131                        $old_args_keys = array(
     132                                0 => 'type',
     133                                1 => 'per_page',
     134                                2 => 'page',
     135                                3 => 'user_id',
     136                                4 => 'search_terms',
     137                        );
     138
     139                        $func_args = func_get_args();
     140                        $args = bp_core_parse_args_array( $old_args_keys, $func_args );
     141                }
     142
     143                $defaults = array(
     144                        'type'         => 'active',
     145                        'per_page'     => false,
     146                        'page'         => false,
     147                        'user_id'      => 0,
     148                        'search_terms' => false,
     149                );
     150
     151                $r = wp_parse_args( $args, $defaults );
     152                extract( $r );
     153
    124154                if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
    125155                        $hidden_sql = "AND wb.public = 1";
    126156                else
    127157                        $hidden_sql = '';
    128158
    129                 $pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
     159                $pag_sql = ( $per_page && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) ) : '';
    130160
    131161                $user_sql = !empty( $user_id ) ? $wpdb->prepare( " AND b.user_id = %d", $user_id ) : '';
    132162
  • bp-blogs/bp-blogs-functions.php

    diff --git bp-blogs/bp-blogs-functions.php bp-blogs/bp-blogs-functions.php
    index d032cfb..cdfed2d 100644
    function bp_blogs_get_blogs( $args = '' ) { 
    5353        $params = wp_parse_args( $args, $defaults );
    5454        extract( $params, EXTR_SKIP );
    5555
    56         return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), $params );
     56        $args_n = array(
     57                'type'         => $type,
     58                'per_page'     => $per_page,
     59                'page'         => $page,
     60                'user_id'      => $user_id,
     61                'search_terms' => $search_terms,
     62        );
     63
     64        return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $args_n ), $params );
    5765}
    5866
    5967/**
  • bp-blogs/bp-blogs-template.php

    diff --git bp-blogs/bp-blogs-template.php bp-blogs/bp-blogs-template.php
    index cf1acdf..e5cf6c5 100644
    class BP_Blogs_Template { 
    161161         *
    162162         * @see BP_Blogs_Blog::get() for a description of parameters.
    163163         *
    164          * @param string $type See {@link BP_Blogs_Blog::get()}.
    165          * @param string $page See {@link BP_Blogs_Blog::get()}.
    166          * @param string $per_page See {@link BP_Blogs_Blog::get()}.
    167          * @param string $max See {@link BP_Blogs_Blog::get()}.
    168          * @param string $user_id See {@link BP_Blogs_Blog::get()}.
    169          * @param string $search_terms See {@link BP_Blogs_Blog::get()}.
    170          * @param string $page_arg The string used as a query parameter in
    171          *        pagination links. Default: 'bpage'.
     164         * @param array $args {
     165         *     An array of arguments. All items are optional.
     166         *     @param string $type See {@link BP_Blogs_Blog::get()}.
     167         *     @param string $page See {@link BP_Blogs_Blog::get()}.
     168         *     @param string $per_page See {@link BP_Blogs_Blog::get()}.
     169         *     @param string $max See {@link BP_Blogs_Blog::get()}.
     170         *     @param string $user_id See {@link BP_Blogs_Blog::get()}.
     171         *     @param string $search_terms See {@link BP_Blogs_Blog::get()}.
     172         *     @param string $page_arg The string used as a query parameter in
     173         *            pagination links. Default: 'bpage'.
     174         * }
    172175         */
    173         function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage' ) {
     176        function __construct( $args = array() ) {
     177                // Backward compatibility with old method of passing arguments
     178                if ( !is_array( $args ) || func_num_args() > 1 ) {
     179                        _deprecated_argument( __METHOD__, '2.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     180
     181                        $old_args_keys = array(
     182                                0 => 'type',
     183                                1 => 'page',
     184                                2 => 'per_page',
     185                                3 => 'max',
     186                                4 => 'user_id',
     187                                5 => 'search_terms',
     188                                6 => 'page_arg',
     189                        );
     190
     191                        $func_args = func_get_args();
     192                        $args = bp_core_parse_args_array( $old_args_keys, $func_args );
     193                }
     194
     195                $defaults = array(
     196                        'type'         => 'active',
     197                        'page'         => 1,
     198                        'per_page'     => 20,
     199                        'max'          => false,
     200                        'user_id'      => '0',
     201                        'search_terms' => false, // Pass search terms to filter on the blog title or description.
     202                        'page_arg'     => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679
     203                );
     204                $r = wp_parse_args( $args, $defaults );
     205                extract( $r );
    174206
    175                 $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
     207                $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[ $page_arg ] ) : $page;
    176208                $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    177209
    178                 if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
     210                if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
    179211                        $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
    180                 else
    181                         $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
     212                } else {
     213                        $this->blogs = bp_blogs_get_blogs( array(
     214                                'type'         => $type,
     215                                'per_page'     => $this->pag_num,
     216                                'page'         => $this->pag_page,
     217                                'user_id'      => $user_id,
     218                                'search_terms' => $search_terms,
     219                        ) );
     220                }
    182221
    183222                if ( !$max || $max >= (int) $this->blogs['total'] )
    184223                        $this->total_blog_count = (int) $this->blogs['total'];
    function bp_has_blogs( $args = '' ) { 
    378417                }
    379418        }
    380419
    381         $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg );
     420        $blogs_template = new BP_Blogs_Template( array(
     421                'type'         => $type,
     422                'page'         => $page,
     423                'per_page'     => $per_page,
     424                'max'          => $max,
     425                'user_id'      => $user_id,
     426                'search_terms' => $search_terms,
     427                'page_arg'     => $page_arg,
     428        ) );
     429
    382430        return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template );
    383431}
    384432