Skip to:
Content

BuddyPress.org

Ticket #5629: 5629.patch

File 5629.patch, 6.9 KB (added by boonebgorges, 5 years ago)
  • src/bp-activity/bp-activity-admin.php

    diff --git src/bp-activity/bp-activity-admin.php src/bp-activity/bp-activity-admin.php
    index 0150595..d4ec34f 100644
    class BP_Activity_List_Table extends WP_List_Table { 
    10571057                        'display_comments' => 'stream',
    10581058                        'show_hidden'      => true,
    10591059                        'spam'             => 'spam_only',
     1060                        'count_total'      => 'count_query',
    10601061                ) );
    10611062                $this->spam_count = $spams['total'];
    10621063                unset( $spams );
    class BP_Activity_List_Table extends WP_List_Table { 
    10721073                        'show_hidden'      => true,
    10731074                        //'sort'             => $sort,
    10741075                        'spam'             => $spam,
     1076                        'count_total'      => 'count_query',
    10751077                ) );
    10761078
    10771079                // If we're viewing a specific activity, flatten all activites into a single array.
  • src/bp-activity/bp-activity-classes.php

    diff --git src/bp-activity/bp-activity-classes.php src/bp-activity/bp-activity-classes.php
    index f1e6054..8881748 100644
    class BP_Activity_Activity { 
    311311                        'show_hidden'       => false,      // Show items marked hide_sitewide
    312312                        'spam'              => 'ham_only', // Spam status
    313313                        'update_meta_cache' => true,
     314                        'count_total'       => false,
    314315                );
    315316                $r = wp_parse_args( $args, $defaults );
    316317                extract( $r );
    class BP_Activity_Activity { 
    411412                $page     = absint( $page     );
    412413                $per_page = absint( $per_page );
    413414
     415                $retval = array(
     416                        'activities'     => null,
     417                        'total'          => null,
     418                        'has_more_items' => null,
     419                );
     420
    414421                // Filter and return true to use the legacy query structure (not recommended)
    415422                if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) {
    416423
    class BP_Activity_Activity { 
    431438                        $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}";
    432439
    433440                        if ( ! empty( $per_page ) && ! empty( $page ) ) {
    434                                 $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
     441                                $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 );
    435442                        }
    436443
    437444                        $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r );
    438445
    439446                        $activity_ids = $wpdb->get_col( $activity_ids_sql );
    440                         $activities   = self::get_activity_data( $activity_ids );
    441                 }
    442447
    443                 $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', "SELECT count(DISTINCT a.id) FROM {$bp->activity->table_name} a {$join_sql} {$where_sql}", $where_sql, $sort );
    444                 $total_activities     = $wpdb->get_var( $total_activities_sql );
     448                        $retval['has_more_items'] = ! empty( $per_page ) && count( $activity_ids ) > $per_page;
     449
     450                        // We don't need the last activity id anymore, so we
     451                        // trim it
     452                        array_pop( $activity_ids );
     453
     454                        $activities = self::get_activity_data( $activity_ids );
     455                }
    445456
    446457                // Get the fullnames of users so we don't have to query in the loop
    447458                $activities = self::append_user_fullnames( $activities );
    class BP_Activity_Activity { 
    465476                // Generate action strings
    466477                $activities = BP_Activity_Activity::generate_action_strings( $activities );
    467478
     479                $retval['activities'] = $activities;
     480
    468481                // If $max is set, only return up to the max results
    469                 if ( !empty( $max ) ) {
    470                         if ( (int) $total_activities > (int) $max )
    471                                 $total_activities = $max;
     482                if ( false !== $r['count_total'] ) {
     483
     484                        $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', "SELECT count(DISTINCT a.id) FROM {$bp->activity->table_name} a {$join_sql} {$where_sql}", $where_sql, $sort );
     485                        $total_activities     = $wpdb->get_var( $total_activities_sql );
     486
     487                        if ( !empty( $max ) ) {
     488                                if ( (int) $total_activities > (int) $max )
     489                                        $total_activities = $max;
     490                        }
     491
     492                        $retval['total'] = $total_activities;
    472493                }
    473494
    474                 return array( 'activities' => $activities, 'total' => (int) $total_activities );
     495                return $retval;
    475496        }
    476497
    477498        /**
  • src/bp-activity/bp-activity-functions.php

    diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php
    index 507387e..3454cf0 100644
    function bp_activity_get( $args = '' ) { 
    963963                'in'                => false,        // Comma-separated list or array of activity IDs to which you want to limit the query
    964964                'spam'              => 'ham_only',   // 'ham_only' (default), 'spam_only' or 'all'.
    965965                'update_meta_cache' => true,
     966                'count_total'       => false,
    966967
    967968                /**
    968969                 * Pass filters as an array -- all filter items can be multiple values comma separated:
    function bp_activity_get( $args = '' ) { 
    994995                                'show_hidden'       => $show_hidden,
    995996                                'spam'              => $spam,
    996997                                'update_meta_cache' => $update_meta_cache,
     998                                'count_total'       => $count_total,
    997999                        );
    9981000                        $activity = BP_Activity_Activity::get( $args );
    9991001                        wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
    function bp_activity_get( $args = '' ) { 
    10121014                        'show_hidden'      => $show_hidden,
    10131015                        'exclude'          => $exclude,
    10141016                        'in'               => $in,
    1015                         'spam'             => $spam
     1017                        'spam'             => $spam,
     1018                        'count_total'      => $count_total,
    10161019                );
    10171020                $activity = BP_Activity_Activity::get( $args );
    10181021        }
  • src/bp-activity/bp-activity-template.php

    diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php
    index 0a7ceeb..142f6e5 100644
    class BP_Activity_Template { 
    220220                        ) );
    221221                }
    222222
    223                 if ( !$max || $max >= (int) $this->activities['total'] )
    224                         $this->total_activity_count = (int) $this->activities['total'];
    225                 else
    226                         $this->total_activity_count = (int) $max;
     223                if ( ! is_null( $this->activities['total'] ) ) {
     224                        if ( !$max || $max >= (int) $this->activities['total'] )
     225                                $this->total_activity_count = (int) $this->activities['total'];
     226                        else
     227                                $this->total_activity_count = (int) $max;
     228                }
     229
     230                $this->has_more_items = $this->activities['has_more_items'];
    227231
    228232                $this->activities = $this->activities['activities'];
    229233
    function bp_activity_pagination_links() { 
    778782function bp_activity_has_more_items() {
    779783        global $activities_template;
    780784
    781         $remaining_pages = 0;
     785        if ( ! empty( $activities_template->has_more_items )  ) {
     786                $has_more_items = true;
     787        } else {
     788                $remaining_pages = 0;
    782789
    783         if ( ! empty( $activities_template->pag_page ) ) {
    784                 $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
    785         }
     790                if ( ! empty( $activities_template->pag_page ) ) {
     791                        $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
     792                }
    786793
    787         $has_more_items  = (int) $remaining_pages ? true : false;
     794                $has_more_items  = (int) $remaining_pages ? true : false;
     795        }
    788796
    789797        return apply_filters( 'bp_activity_has_more_items', $has_more_items );
    790798}