Skip to:
Content

BuddyPress.org

Ticket #4045: 4045.03.diff

File 4045.03.diff, 9.5 KB (added by boonebgorges, 13 years ago)
  • bp-activity/bp-activity-classes.php

    diff --git bp-activity/bp-activity-classes.php bp-activity/bp-activity-classes.php
    index 0dbea41..2fac336 100644
    class BP_Activity_Activity { 
    136136                        'per_page'         => 25,         // Activity items per page
    137137                        'max'              => false,      // Max number of items to return
    138138                        'sort'             => 'DESC',     // ASC or DESC
     139                        'do_total_count'   => true,
    139140                        'exclude'          => false,      // Array of ids to exclude
    140141                        'in'               => false,      // Array of ids to limit query by (IN)
    141142                        'filter'           => false,      // See self::get_filter_sql()
    class BP_Activity_Activity { 
    227228                        $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $select_sql, $from_sql, $where_sql, $sort ) );
    228229                }
    229230
    230                 $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$index_hint_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $where_sql, $sort );
     231                if ( $do_total_count && apply_filters( 'bp_activity_allow_total_count', true, $r ) ) {
     232                        $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$index_hint_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $where_sql, $sort );
    231233
    232                 $total_activities = $wpdb->get_var( $total_activities_sql );
     234                        $total_activities = $wpdb->get_var( $total_activities_sql );
     235                } else {
     236                        $total_activities = -1;
     237                }
    233238
    234239                // Get the fullnames of users so we don't have to query in the loop
    235240                $activity_user_ids = array();
  • bp-activity/bp-activity-functions.php

    diff --git bp-activity/bp-activity-functions.php bp-activity/bp-activity-functions.php
    index ac7fc74..6040bf9 100644
    function bp_activity_get( $args = '' ) { 
    794794                'page'             => 1,            // page 1 without a per_page will result in no pagination.
    795795                'per_page'         => false,        // results per page
    796796                'sort'             => 'DESC',       // sort ASC or DESC
     797                'do_total_count'   => true,
    797798                'display_comments' => false,        // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
    798799
    799800                'search_terms'     => false,        // Pass search terms as a string
    function bp_activity_get( $args = '' ) { 
    820821        // Attempt to return a cached copy of the first page of sitewide activity.
    821822        if ( 1 == (int) $page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && empty( $exclude ) && empty( $in ) && 'DESC' == $sort && empty( $exclude ) && 'ham_only' == $spam ) {
    822823                if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
    823                         $args = array(
     824                        $get_args = array(
    824825                                'page'             => $page,
    825826                                'per_page'         => $per_page,
    826827                                'max'              => $max,
    827828                                'sort'             => $sort,
     829                                'do_total_count'   => $do_total_count,
    828830                                'search_terms'     => $search_terms,
    829831                                'filter'           => $filter,
    830832                                'display_comments' => $display_comments,
    831833                                'show_hidden'      => $show_hidden,
    832834                                'spam'             => $spam
    833835                        );
    834                         $activity = BP_Activity_Activity::get( $args );
     836                        $activity = BP_Activity_Activity::get( $get_args );
    835837                        wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
    836838                }
    837839
    838840        } else {
    839                 $args = array(
     841                $get_args = array(
    840842                        'page'             => $page,
    841843                        'per_page'         => $per_page,
    842844                        'max'              => $max,
    843845                        'sort'             => $sort,
     846                        'do_total_count'   => $do_total_count,
    844847                        'search_terms'     => $search_terms,
    845848                        'filter'           => $filter,
    846849                        'display_comments' => $display_comments,
    function bp_activity_get( $args = '' ) { 
    849852                        'in'               => $in,
    850853                        'spam'             => $spam
    851854                );
    852                 $activity = BP_Activity_Activity::get( $args );
     855                $activity = BP_Activity_Activity::get( $get_args );
    853856        }
    854857
    855858        return apply_filters_ref_array( 'bp_activity_get', array( &$activity, &$r ) );
  • bp-activity/bp-activity-template.php

    diff --git bp-activity/bp-activity-template.php bp-activity/bp-activity-template.php
    index 72d4987..35b098a 100644
    class BP_Activity_Template { 
    134134                                11 => 'spam',
    135135                                12 => 'page_arg'
    136136                        );
    137                        
     137
    138138                        $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
    139139                }
    140                
     140
    141141                $defaults = array(
    142142                        'page'             => 1,
    143143                        'per_page'         => 20,
    144144                        'page_arg'         => 'acpage',
    145145                        'max'              => false,
     146                        'do_total_count'   => true,
    146147                        'sort'             => false,
    147148                        'include'          => false,
    148149                        'exclude'          => false,
    class BP_Activity_Template { 
    171172
    172173                // Fetch all activity items
    173174                else
    174                         $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'spam' => $spam ) );
     175                        $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'do_total_count' => $do_total_count, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'spam' => $spam ) );
    175176
    176177                if ( !$max || $max >= (int) $this->activities['total'] )
    177178                        $this->total_activity_count = (int) $this->activities['total'];
    class BP_Activity_Template { 
    210211                        unset( $activity_parents );
    211212                }
    212213
    213                 if ( (int) $this->total_activity_count && (int) $this->pag_num ) {
    214                         $this->pag_links = paginate_links( array(
    215                                 'base'      => add_query_arg( $page_arg, '%#%' ),
    216                                 'format'    => '',
    217                                 'total'     => ceil( (int) $this->total_activity_count / (int) $this->pag_num ),
    218                                 'current'   => (int) $this->pag_page,
    219                                 'prev_text' => _x( '←', 'Activity pagination previous text', 'buddypress' ),
    220                                 'next_text' => _x( '→', 'Activity pagination next text', 'buddypress' ),
    221                                 'mid_size'  => 1
    222                         ) );
     214                // Pagination links
     215                if ( (int) $this->pag_num ) {
     216                        // If the total pagination count is -1, it means that do_total_count was
     217                        // false, and we should use simple 'Previous | Next' pagination links
     218                        if ( (int) $this->total_activity_count >= 0 ) {
     219                                $this->pag_links = paginate_links( array(
     220                                        'base'      => add_query_arg( $page_arg, '%#%' ),
     221                                        'format'    => '',
     222                                        'total'     => ceil( (int) $this->total_activity_count / (int) $this->pag_num ),
     223                                        'current'   => (int) $this->pag_page,
     224                                        'prev_text' => _x( '←', 'Activity pagination previous text', 'buddypress' ),
     225                                        'next_text' => _x( '→', 'Activity pagination next text', 'buddypress' ),
     226                                        'mid_size'  => 1
     227                                ) );
     228                        } else {
     229                                $this->pag_links = '';
     230                                if ( (int) $this->pag_page > 1 ) {
     231                                        $this->pag_links .= '<a href="' . add_query_arg( $page_arg, (int) $this->pag_page - 1 ) . '" class="ac-previous">' . __( 'Previous', 'buddypress' ) . '</a> | ';
     232                                }
     233                                $this->pag_links .= '<a href="' . add_query_arg( $page_arg, (int) $this->pag_page + 1 ) . '" class="ac-next">' . __( 'Next', 'buddypress' ) . '</a>';
     234                        }
    223235                }
    224236        }
    225237
    function bp_has_activities( $args = '' ) { 
    347359                'max'              => false,        // max number to return
    348360                'show_hidden'      => $show_hidden, // Show activity items that are hidden site-wide?
    349361                'spam'             => 'ham_only',   // Hide spammed items
     362                'do_total_count'   => true,         // Do you need a count of total activity items matching your query?
    350363
    351364                'page_arg'         => 'acpage',     // See https://buddypress.trac.wordpress.org/ticket/3679
    352365
    function bp_has_activities( $args = '' ) { 
    443456                'per_page'         => $per_page,
    444457                'page_arg'         => $page_arg,
    445458                'max'              => $max,
     459                'do_total_count'   => $do_total_count,
    446460                'sort'             => $sort,
    447461                'include'          => $include,
    448462                'exclude'          => $exclude,
    function bp_activity_pagination_count() { 
    516530
    517531                $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
    518532                $from_num  = bp_core_number_format( $start_num );
    519                 $to_num    = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );
    520533                $total     = bp_core_number_format( $activities_template->total_activity_count );
    521534
    522                 return sprintf( __( 'Viewing item %1$s to %2$s (of %3$s items)', 'buddypress' ), $from_num, $to_num, $total );
     535                if ( (float) $total >= 0 ) {
     536                        $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );
     537                        $text = sprintf( __( 'Viewing item %1$s to %2$s (of %3$s items)', 'buddypress' ), $from_num, $to_num, $total );
     538                } else {
     539                        $to_num = bp_core_number_format( $start_num + ( $activities_template->pag_num - 1 ) );
     540
     541                        $text = sprintf( __( 'Viewing item %1$s to %2$s', 'buddypress' ), $from_num, $to_num );
     542                }
     543
     544                return apply_filters( 'bp_get_activity_pagination_count', $text );
    523545        }
    524546
    525547/**