Ticket #5629: 5629.03.patch
| File 5629.03.patch, 9.4 KB (added by , 12 years ago) |
|---|
-
src/bp-activity/bp-activity-admin.php
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 ); … … 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. -
src/bp-activity/bp-activity-classes.php
267 267 * @type string $spam Spam status. Default: 'ham_only'. 268 268 * @type bool $update_meta_cache Whether to pre-fetch metadata for 269 269 * queried activity items. Default: true. 270 * @type bool $count_total If true, an additional DB query is run to 271 * count the total activity items for the query. Default: false. 270 272 * } 271 273 * @return array The array returned has two keys: 272 274 * - 'total' is the count of located activities … … 311 313 'show_hidden' => false, // Show items marked hide_sitewide 312 314 'spam' => 'ham_only', // Spam status 313 315 'update_meta_cache' => true, 316 'count_total' => false, 314 317 ); 315 318 $r = wp_parse_args( $args, $defaults ); 316 319 extract( $r ); … … 411 414 $page = absint( $page ); 412 415 $per_page = absint( $per_page ); 413 416 417 $retval = array( 418 'activities' => null, 419 'total' => null, 420 'has_more_items' => null, 421 ); 422 414 423 // Filter and return true to use the legacy query structure (not recommended) 415 424 if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) { 416 425 … … 431 440 $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}"; 432 441 433 442 if ( ! empty( $per_page ) && ! empty( $page ) ) { 434 $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );443 $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 ); 435 444 } 436 445 437 446 $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r ); 438 447 439 448 $activity_ids = $wpdb->get_col( $activity_ids_sql ); 440 $activities = self::get_activity_data( $activity_ids );441 }442 449 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 ); 450 $retval['has_more_items'] = ! empty( $per_page ) && count( $activity_ids ) > $per_page; 451 452 // We don't need the last activity id anymore, so we 453 // trim it 454 array_pop( $activity_ids ); 455 456 $activities = self::get_activity_data( $activity_ids ); 457 } 445 458 446 459 // Get the fullnames of users so we don't have to query in the loop 447 460 $activities = self::append_user_fullnames( $activities ); … … 465 478 // Generate action strings 466 479 $activities = BP_Activity_Activity::generate_action_strings( $activities ); 467 480 481 $retval['activities'] = $activities; 482 468 483 // 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; 484 if ( false !== $r['count_total'] ) { 485 486 $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 ); 487 $total_activities = $wpdb->get_var( $total_activities_sql ); 488 489 if ( !empty( $max ) ) { 490 if ( (int) $total_activities > (int) $max ) 491 $total_activities = $max; 492 } 493 494 $retval['total'] = $total_activities; 472 495 } 473 496 474 return array( 'activities' => $activities, 'total' => (int) $total_activities );497 return $retval; 475 498 } 476 499 477 500 /** -
src/bp-activity/bp-activity-functions.php
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: … … 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' ); … … 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 } -
src/bp-activity/bp-activity-template.php
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; … … 178 186 $r = wp_parse_args( $args, $defaults ); 179 187 extract( $r ); 180 188 181 $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page; 189 $this->pag_arg = $r['page_arg']; 190 $this->pag_page = isset( $_REQUEST[ $this->pag_arg ] ) ? intval( $_REQUEST[ $this->pag_arg ] ) : $page; 182 191 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 183 192 184 193 // Check if blog/forum replies are disabled … … 220 229 ) ); 221 230 } 222 231 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; 232 if ( ! is_null( $this->activities['total'] ) ) { 233 if ( !$max || $max >= (int) $this->activities['total'] ) 234 $this->total_activity_count = (int) $this->activities['total']; 235 else 236 $this->total_activity_count = (int) $max; 237 } 238 239 $this->has_more_items = $this->activities['has_more_items']; 227 240 228 241 $this->activities = $this->activities['activities']; 229 242 … … 268 281 'mid_size' => 1 269 282 ) ); 270 283 } 271 }284 } 272 285 273 286 /** 274 287 * Whether there are activity items available in the loop. … … 706 719 } 707 720 708 721 /** 722 * Output the URL for the Load More link. 723 * 724 * @since BuddyPress (2.1.0) 725 */ 726 function bp_activity_load_more_link() { 727 echo bp_get_activity_load_more_link(); 728 } 729 function bp_get_activity_load_more_link() { 730 global $activities_template; 731 732 $link = bp_get_requested_url(); 733 $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $link ); 734 735 return apply_filters( 'bp_get_activity_load_more_link', $link ); 736 } 737 738 /** 709 739 * Output the activity pagination count. 710 740 * 711 741 * @since BuddyPress (1.0) … … 778 808 function bp_activity_has_more_items() { 779 809 global $activities_template; 780 810 781 $remaining_pages = 0; 811 if ( ! empty( $activities_template->has_more_items ) ) { 812 $has_more_items = true; 813 } else { 814 $remaining_pages = 0; 815 816 if ( ! empty( $activities_template->pag_page ) ) { 817 $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) ); 818 } 782 819 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 ) ); 820 $has_more_items = (int) $remaining_pages ? true : false; 785 821 } 786 822 787 $has_more_items = (int) $remaining_pages ? true : false;788 789 823 return apply_filters( 'bp_activity_has_more_items', $has_more_items ); 790 824 } 791 825 -
src/bp-templates/bp-legacy/buddypress/activity/activity-loop.php
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; ?>