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 { |
1057 | 1057 | 'display_comments' => 'stream', |
1058 | 1058 | 'show_hidden' => true, |
1059 | 1059 | 'spam' => 'spam_only', |
| 1060 | 'count_total' => 'count_query', |
1060 | 1061 | ) ); |
1061 | 1062 | $this->spam_count = $spams['total']; |
1062 | 1063 | unset( $spams ); |
… |
… |
class BP_Activity_List_Table extends WP_List_Table { |
1072 | 1073 | 'show_hidden' => true, |
1073 | 1074 | //'sort' => $sort, |
1074 | 1075 | 'spam' => $spam, |
| 1076 | 'count_total' => 'count_query', |
1075 | 1077 | ) ); |
1076 | 1078 | |
1077 | 1079 | // If we're viewing a specific activity, flatten all activites into a single array. |
diff --git src/bp-activity/bp-activity-classes.php src/bp-activity/bp-activity-classes.php
index f1e6054..8881748 100644
|
|
class BP_Activity_Activity { |
311 | 311 | 'show_hidden' => false, // Show items marked hide_sitewide |
312 | 312 | 'spam' => 'ham_only', // Spam status |
313 | 313 | 'update_meta_cache' => true, |
| 314 | 'count_total' => false, |
314 | 315 | ); |
315 | 316 | $r = wp_parse_args( $args, $defaults ); |
316 | 317 | extract( $r ); |
… |
… |
class BP_Activity_Activity { |
411 | 412 | $page = absint( $page ); |
412 | 413 | $per_page = absint( $per_page ); |
413 | 414 | |
| 415 | $retval = array( |
| 416 | 'activities' => null, |
| 417 | 'total' => null, |
| 418 | 'has_more_items' => null, |
| 419 | ); |
| 420 | |
414 | 421 | // Filter and return true to use the legacy query structure (not recommended) |
415 | 422 | if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) { |
416 | 423 | |
… |
… |
class BP_Activity_Activity { |
431 | 438 | $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}"; |
432 | 439 | |
433 | 440 | 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 ); |
435 | 442 | } |
436 | 443 | |
437 | 444 | $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r ); |
438 | 445 | |
439 | 446 | $activity_ids = $wpdb->get_col( $activity_ids_sql ); |
440 | | $activities = self::get_activity_data( $activity_ids ); |
441 | | } |
442 | 447 | |
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 | } |
445 | 456 | |
446 | 457 | // Get the fullnames of users so we don't have to query in the loop |
447 | 458 | $activities = self::append_user_fullnames( $activities ); |
… |
… |
class BP_Activity_Activity { |
465 | 476 | // Generate action strings |
466 | 477 | $activities = BP_Activity_Activity::generate_action_strings( $activities ); |
467 | 478 | |
| 479 | $retval['activities'] = $activities; |
| 480 | |
468 | 481 | // 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; |
472 | 493 | } |
473 | 494 | |
474 | | return array( 'activities' => $activities, 'total' => (int) $total_activities ); |
| 495 | return $retval; |
475 | 496 | } |
476 | 497 | |
477 | 498 | /** |
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 = '' ) { |
963 | 963 | 'in' => false, // Comma-separated list or array of activity IDs to which you want to limit the query |
964 | 964 | 'spam' => 'ham_only', // 'ham_only' (default), 'spam_only' or 'all'. |
965 | 965 | 'update_meta_cache' => true, |
| 966 | 'count_total' => false, |
966 | 967 | |
967 | 968 | /** |
968 | 969 | * Pass filters as an array -- all filter items can be multiple values comma separated: |
… |
… |
function bp_activity_get( $args = '' ) { |
994 | 995 | 'show_hidden' => $show_hidden, |
995 | 996 | 'spam' => $spam, |
996 | 997 | 'update_meta_cache' => $update_meta_cache, |
| 998 | 'count_total' => $count_total, |
997 | 999 | ); |
998 | 1000 | $activity = BP_Activity_Activity::get( $args ); |
999 | 1001 | wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' ); |
… |
… |
function bp_activity_get( $args = '' ) { |
1012 | 1014 | 'show_hidden' => $show_hidden, |
1013 | 1015 | 'exclude' => $exclude, |
1014 | 1016 | 'in' => $in, |
1015 | | 'spam' => $spam |
| 1017 | 'spam' => $spam, |
| 1018 | 'count_total' => $count_total, |
1016 | 1019 | ); |
1017 | 1020 | $activity = BP_Activity_Activity::get( $args ); |
1018 | 1021 | } |
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php
index cad209f..d846944 100644
|
|
class BP_Activity_Template { |
98 | 98 | |
99 | 99 | var $in_the_loop; |
100 | 100 | |
| 101 | /** |
| 102 | * URL parameter key for activity pagination. Default: 'acpage'. |
| 103 | * |
| 104 | * @since BuddyPress (2.1.0) |
| 105 | * @var string |
| 106 | */ |
| 107 | var $pag_arg; |
| 108 | |
101 | 109 | var $pag_page; |
102 | 110 | var $pag_num; |
103 | 111 | var $pag_links; |
… |
… |
class BP_Activity_Template { |
131 | 139 | * @type string|bool $display_comments Default: 'threaded'. |
132 | 140 | * } |
133 | 141 | */ |
134 | | function __construct( $args ) { |
135 | | global $bp; |
| 142 | function __construct( $args ) { global $bp; |
136 | 143 | |
137 | 144 | // Backward compatibility with old method of passing arguments |
138 | 145 | if ( !is_array( $args ) || func_num_args() > 1 ) { |
… |
… |
class BP_Activity_Template { |
178 | 185 | $r = wp_parse_args( $args, $defaults ); |
179 | 186 | extract( $r ); |
180 | 187 | |
181 | | $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page; |
| 188 | $this->pag_arg = $r['page_arg']; |
| 189 | $this->pag_page = isset( $_REQUEST[ $this->pag_arg ] ) ? intval( $_REQUEST[ $this->pag_arg ] ) : $page; |
182 | 190 | $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; |
183 | 191 | |
184 | 192 | // Check if blog/forum replies are disabled |
… |
… |
class BP_Activity_Template { |
220 | 228 | ) ); |
221 | 229 | } |
222 | 230 | |
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; |
| 231 | if ( ! is_null( $this->activities['total'] ) ) { |
| 232 | if ( !$max || $max >= (int) $this->activities['total'] ) |
| 233 | $this->total_activity_count = (int) $this->activities['total']; |
| 234 | else |
| 235 | $this->total_activity_count = (int) $max; |
| 236 | } |
| 237 | |
| 238 | $this->has_more_items = $this->activities['has_more_items']; |
227 | 239 | |
228 | 240 | $this->activities = $this->activities['activities']; |
229 | 241 | |
… |
… |
class BP_Activity_Template { |
268 | 280 | 'mid_size' => 1 |
269 | 281 | ) ); |
270 | 282 | } |
271 | | } |
| 283 | } |
272 | 284 | |
273 | 285 | /** |
274 | 286 | * Whether there are activity items available in the loop. |
… |
… |
function bp_the_activity() { |
706 | 718 | } |
707 | 719 | |
708 | 720 | /** |
| 721 | * Output the URL for the Load More link. |
| 722 | * |
| 723 | * @since BuddyPress (2.1.0) |
| 724 | */ |
| 725 | function bp_activity_load_more_link() { |
| 726 | echo bp_get_activity_load_more_link(); |
| 727 | } |
| 728 | function bp_get_activity_load_more_link() { |
| 729 | global $activities_template; |
| 730 | |
| 731 | $link = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() ); |
| 732 | $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $link ); |
| 733 | |
| 734 | return apply_filters( 'bp_get_activity_load_more_link', $link ); |
| 735 | } |
| 736 | |
| 737 | /** |
709 | 738 | * Output the activity pagination count. |
710 | 739 | * |
711 | 740 | * @since BuddyPress (1.0) |
… |
… |
function bp_activity_pagination_links() { |
778 | 807 | function bp_activity_has_more_items() { |
779 | 808 | global $activities_template; |
780 | 809 | |
781 | | $remaining_pages = 0; |
| 810 | if ( ! empty( $activities_template->has_more_items ) ) { |
| 811 | $has_more_items = true; |
| 812 | } else { |
| 813 | $remaining_pages = 0; |
| 814 | |
| 815 | if ( ! empty( $activities_template->pag_page ) ) { |
| 816 | $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) ); |
| 817 | } |
782 | 818 | |
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 ) ); |
| 819 | $has_more_items = (int) $remaining_pages ? true : false; |
785 | 820 | } |
786 | 821 | |
787 | | $has_more_items = (int) $remaining_pages ? true : false; |
788 | | |
789 | 822 | return apply_filters( 'bp_activity_has_more_items', $has_more_items ); |
790 | 823 | } |
791 | 824 | |
diff --git src/bp-templates/bp-legacy/buddypress/activity/activity-loop.php src/bp-templates/bp-legacy/buddypress/activity/activity-loop.php
index 6134ff6..bc675ae 100644
|
|
|
2 | 2 | |
3 | 3 | <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) ) ) : ?> |
4 | 4 | |
5 | | <?php /* Show pagination if JS is not enabled, since the "Load More" link will do nothing */ ?> |
6 | | <noscript> |
7 | | <div class="pagination"> |
8 | | <div class="pag-count"><?php bp_activity_pagination_count(); ?></div> |
9 | | <div class="pagination-links"><?php bp_activity_pagination_links(); ?></div> |
10 | | </div> |
11 | | </noscript> |
12 | | |
13 | 5 | <?php if ( empty( $_POST['page'] ) ) : ?> |
14 | 6 | |
15 | 7 | <ul id="activity-stream" class="activity-list item-list"> |
… |
… |
|
25 | 17 | <?php if ( bp_activity_has_more_items() ) : ?> |
26 | 18 | |
27 | 19 | <li class="load-more"> |
28 | | <a href="#more"><?php _e( 'Load More', 'buddypress' ); ?></a> |
| 20 | <a href="<?php bp_activity_load_more_link() ?>"><?php _e( 'Load More', 'buddypress' ); ?></a> |
29 | 21 | </li> |
30 | 22 | |
31 | 23 | <?php endif; ?> |
… |
… |
|
54 | 46 | |
55 | 47 | </form> |
56 | 48 | |
57 | | <?php endif; ?> |
58 | | No newline at end of file |
| 49 | <?php endif; ?> |