Ticket #3059: 3059.2.diff
File 3059.2.diff, 13.0 KB (added by , 12 years ago) |
---|
-
bp-forums/bp-forums-functions.php
function bp_forums_get_forum_topics( $args = '' ) { 80 80 'user_id' => false, 81 81 'page' => 1, 82 82 'per_page' => 15, 83 'offset' => false, 84 'number' => false, 83 85 'exclude' => false, 84 86 'show_stickies' => 'all', 85 87 'filter' => false // if $type = tag then filter is the tag name, otherwise it's terms to search on. … … function bp_forums_get_forum_topics( $args = '' ) { 91 93 if ( class_exists( 'BB_Query' ) ) { 92 94 switch ( $type ) { 93 95 case 'newest': 94 $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies ), 'get_latest_topics' );96 $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies, 'offset' => $offset, 'number' => $number ), 'get_latest_topics' ); 95 97 $topics =& $query->results; 96 98 break; 97 99 -
bp-forums/bp-forums-template.php
class BP_Forums_Template_Forum { 68 68 var $sort_by; 69 69 var $order; 70 70 71 function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) {72 $this->__construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms );71 function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) { 72 $this->__construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset, $number ); 73 73 } 74 74 75 function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) {75 function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) { 76 76 global $bp; 77 77 78 $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) :$page;79 $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) :$per_page;78 $this->pag_page = $page; 79 $this->pag_num = $per_page; 80 80 $this->type = $type; 81 81 $this->search_terms = $search_terms; 82 82 $this->forum_id = $forum_id; 83 $this->offset = $offset; 84 $this->number = $number; 83 85 84 86 switch ( $type ) { 85 case 'newest': default: 86 $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );87 case 'newest': default: 88 $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number ) ); 87 89 break; 88 90 89 91 case 'popular': … … class BP_Forums_Template_Forum { 111 113 } else if ( !empty( $bp->groups->current_group ) ) { 112 114 $topic_count = (int)groups_total_public_forum_topic_count( $type ); 113 115 } else { 114 $topic_count = count( $this->topics ); 116 // For forum directories, get a true count 117 $status = is_super_admin() ? 'all' : 'public'; // todo: member-of 118 $topic_count = (int)groups_total_forum_topic_count( $status ); 115 119 } 116 120 117 121 if ( !$max || $max >= $topic_count ) { … … class BP_Forums_Template_Forum { 119 123 } else { 120 124 $this->total_topic_count = (int)$max; 121 125 } 122 126 123 127 if ( $max ) { 124 128 if ( $max >= count($this->topics) ) { 125 129 $this->topic_count = count( $this->topics ); … … class BP_Forums_Template_Forum { 134 138 $this->topic_count = apply_filters_ref_array( 'bp_forums_template_topic_count', array( $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies ) ); 135 139 $this->total_topic_count = apply_filters_ref_array( 'bp_forums_template_total_topic_count', array( $this->total_topic_count, $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies ) ); 136 140 137 if ( !$no_stickies ) {138 $stickies = array();139 $standard = array();140 141 // Place stickies at the top - not sure why bbPress doesn't do this?142 foreach( (array)$this->topics as $topic ) {143 if ( isset( $topic->topic_sticky ) && 1 == (int)$topic->topic_sticky ) {144 $stickies[] = $topic;145 } else {146 $standard[] = $topic;147 }148 }149 150 $this->topics = array_merge( (array)$stickies, (array)$standard );151 }152 153 141 // Fetch extra information for topics, so we don't have to query inside the loop 154 142 $this->topics = bp_forums_get_topic_extras( $this->topics ); 155 143 … … function bp_has_forum_topics( $args = '' ) { 224 212 $user_id = 0; 225 213 $forum_id = false; 226 214 $search_terms = false; 227 $no_stickies = 'all';228 215 229 216 // User filtering 230 217 if ( !empty( $bp->displayed_user->id ) ) … … function bp_has_forum_topics( $args = '' ) { 254 241 // If $_GET['fs'] is set, let's auto populate the search_terms var 255 242 if ( bp_is_directory() && !empty( $_GET['fs'] ) ) 256 243 $search_terms = $_GET['fs']; 257 258 // Show stickies on a group forum259 if ( isset( $bp->groups->current_group ) )260 $no_stickies = null;244 245 // Get the pagination arguments from $_REQUEST 246 $page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 1; 247 $per_page = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : 20; 261 248 262 249 $defaults = array( 263 250 'type' => $type, 264 251 'forum_id' => $forum_id, 265 252 'user_id' => $user_id, 266 'page' => 1,267 'per_page' => 20,253 'page' => $page, 254 'per_page' => $per_page, 268 255 'max' => false, 269 'no_stickies' => $no_stickies, 256 'number' => false, 257 'offset' => false, 270 258 'search_terms' => $search_terms 271 259 ); 272 260 … … function bp_has_forum_topics( $args = '' ) { 279 267 $search_terms = $bp->action_variables[0]; 280 268 $type = 'tags'; 281 269 } 282 283 $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ); 270 271 // Fetch the stickies 272 $stickies_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, 0, 0, $max, 'sticky', $search_terms ); 273 274 // If stickies are found, try merging them 275 if ( $stickies_template->has_topics() ) { 276 277 // If stickies are for current $page 278 $page_start_num = ( ( $page - 1 ) * $per_page ) + 1; 279 $page_end_num = $page * $per_page <= $stickies_template->total_topic_count ? $page * $per_page : $stickies_template->total_topic_count; 280 281 // Calculate the number of sticky topics that will be shown on this page 282 if ( $stickies_template->topic_count < $page_start_num ) { 283 $this_page_stickies = 0; 284 } else { 285 $this_page_stickies = $stickies_template->topic_count - $per_page * floor( $stickies_template->topic_count / $per_page ) * ( $page - 1 ); // Total stickies minus sticky count through this page 286 287 // $this_page_stickies cannot be more than $per_page or less than 0 288 if ( $this_page_stickies > $per_page ) 289 $this_page_stickies = $per_page; 290 else if ( $this_page_stickies < 0 ) 291 $this_page_stickies = 0; 292 } 293 294 // Calculate the total number of topics that will be shown on this page 295 $this_page_topics = $stickies_template->total_topic_count >= ( $page * $per_page ) ? $per_page : $page_end_num - ( $page_start_num - 1 ); 296 297 // If the number of stickies to be shown is less than $per_page, fetch some non- 298 // stickies to fill in the rest 299 if ( $this_page_stickies < $this_page_topics ) { 300 // How many non-stickies do we need? 301 $non_sticky_number = $this_page_topics - $this_page_stickies; 302 303 // Calculate the non-sticky offset 304 // How many non-stickies on all pages up to this point? 305 $non_sticky_total = $page_end_num - $stickies_template->topic_count; 306 307 // The offset is the number of total non-stickies, less the number to be 308 // shown on this page 309 $non_sticky_offset = $non_sticky_total - $non_sticky_number; 310 311 // Fetch the non-stickies 312 $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, 1, $per_page, $max, 'no', $search_terms, $non_sticky_offset, $non_sticky_number ); 313 314 // If there are stickies to merge on this page, do it now 315 if ( $this_page_stickies ) { 316 // Correct the topic_count 317 $forum_template->topic_count += (int)$this_page_stickies; 318 319 // Figure out which stickies need to be included 320 $this_page_sticky_topics = array_slice( $stickies_template->topics, 0 - $this_page_stickies ); 321 322 // Merge these topics into the forum template 323 $forum_template->topics = array_merge( $this_page_sticky_topics, (array)$forum_template->topics ); 324 } 325 } else { 326 // This page has no non-stickies 327 $forum_template = $stickies_template; 328 329 // Adjust the topic count and trim the topics 330 $forum_template->topic_count = $this_page_stickies; 331 $forum_template->topics = array_slice( $forum_template->topics, $page - 1 ); 332 333 } 334 335 // Because we're using a manual offset and number for the topic query, we 336 // must set the page number manually, and recalculate the pagination links 337 $forum_template->pag_num = $per_page; 338 $forum_template->pag_page = $page; 339 340 $forum_template->pag_links = paginate_links( array( 341 'base' => add_query_arg( array( 'p' => '%#%', 'n' => $forum_template->pag_num ) ), 342 'format' => '', 343 'total' => ceil( (int)$forum_template->total_topic_count / (int)$forum_template->pag_num ), 344 'current' => $forum_template->pag_page, 345 'prev_text' => '←', 346 'next_text' => '→', 347 'mid_size' => 1 348 ) ); 349 350 } else { 351 // Fetch the non-sticky topics if no stickies were found 352 $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, 'all', $search_terms ); 353 } 354 284 355 return apply_filters( 'bp_has_topics', $forum_template->has_topics(), $forum_template ); 285 356 } 286 357 … … function bp_forum_topic_count( $user_id = 0 ) { 1280 1351 function bp_get_forum_topic_count( $user_id = 0 ) { 1281 1352 return apply_filters( 'bp_get_forum_topic_count', bp_forums_total_topic_count( $user_id ) ); 1282 1353 } 1283 ?> 1284 No newline at end of file 1354 ?> -
bp-groups/bp-groups-classes.php
Class BP_Groups_Group { 595 595 596 596 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) ); 597 597 } 598 599 600 /** 601 * Get a total count of all topics of a given status, across groups/forums 602 * 603 * @package BuddyPress 604 * @since 1.3 605 * 606 * @param str $status 'public', 'private', 'hidden', 'all' Which group types to count 607 * @return int The topic count 608 */ 609 function get_global_topic_count( $status = 'public' ) { 610 global $bbdb, $wpdb, $bp; 611 612 switch ( $status ) { 613 case 'all' : 614 $status_sql = ''; 615 break; 616 617 case 'hidden' : 618 $status_sql = $wpdb->prepare( "AND g.status = 'hidden'" ); 619 break; 620 621 case 'private' : 622 $status_sql = $wpdb->prepare( "AND g.status = 'private'" ); 623 break; 624 625 case 'public' : 626 default : 627 $status_sql = $wpdb->prepare( "AND g.status = 'public'" ); 628 break; 629 } 630 631 return $wpdb->get_var( "SELECT COUNT(t.topic_id) FROM {$bbdb->topics} AS t INNER JOIN {$bp->groups->table_name_groupmeta} AS gm ON t.forum_id = gm.meta_value INNER JOIN {$bp->groups->table_name} AS g ON gm.group_id = g.id WHERE gm.meta_key = 'forum_id' {$status_sql} AND t.topic_status = '0' AND t.topic_sticky != '2' " ); 632 } 598 633 } 599 634 600 635 Class BP_Groups_Member { -
bp-groups/bp-groups-forums.php
function groups_delete_group_forum_post( $post_id, $topic_id ) { 244 244 return false; 245 245 } 246 246 247 248 247 function groups_total_public_forum_topic_count( $type = 'newest' ) { 249 248 return apply_filters( 'groups_total_public_forum_topic_count', BP_Groups_Group::get_global_forum_topic_count( $type ) ); 250 249 } 251 250 251 /** 252 * Get a total count of all topics of a given status, across groups/forums 253 * 254 * @package BuddyPress 255 * @since 1.3 256 * 257 * @param str $status 'public', 'private', 'hidden', 'all' Which group types to count 258 * @return int The topic count 259 */ 260 function groups_total_forum_topic_count( $status = 'public' ) { 261 return apply_filters( 'groups_total_forum_topic_count', BP_Groups_Group::get_global_topic_count( $status ) ); 262 } 263 252 264 ?>