Changeset 4955 for trunk/bp-forums/bp-forums-template.php
- Timestamp:
- 08/09/2011 06:40:20 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/bp-forums/bp-forums-template.php (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-forums/bp-forums-template.php
r4907 r4955 102 102 } 103 103 104 function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) { 104 function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) { 105 105 global $bp; 106 106 … … 114 114 115 115 switch ( $type ) { 116 case 'newest': default: 116 case 'newest': default: 117 117 $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 ) ); 118 118 break; … … 153 153 $this->total_topic_count = (int)$max; 154 154 } 155 155 156 156 if ( $max ) { 157 157 if ( $max >= count($this->topics) ) { … … 177 177 'total' => ceil( (int)$this->total_topic_count / (int)$this->pag_num), 178 178 'current' => $this->pag_page, 179 'prev_text' => '←',180 'next_text' => '→',179 'prev_text' => _x( '←', 'Forum topic pagination previous text', 'buddypress' ), 180 'next_text' => _x( '→', 'Forum topic pagination next text', 'buddypress' ), 181 181 'mid_size' => 1 182 182 ) ); … … 261 261 if ( !empty( $bp->displayed_user->id ) ) 262 262 $user_id = $bp->displayed_user->id; 263 263 264 264 // "Replied" query must be manually modified 265 265 if ( 'replies' == bp_current_action() ) { 266 266 $user_id = 0; // User id must be handled manually by the filter, not by BB_Query 267 267 268 268 add_filter( 'get_topics_distinct', 'bp_forums_add_replied_distinct_sql', 20 ); 269 269 add_filter( 'get_topics_join', 'bp_forums_add_replied_join_sql', 20 ); … … 286 286 if ( bp_is_directory() && !empty( $_GET['fs'] ) ) 287 287 $search_terms = $_GET['fs']; 288 288 289 289 // Get the pagination arguments from $_REQUEST 290 290 $page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 1; 291 291 $per_page = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : 20; 292 292 293 293 // Unless set otherwise, stickies appear in normal order on the global forum directory 294 294 if ( bp_is_directory() && bp_is_forums_component() && !bp_forums_enable_global_directory_stickies() ) … … 316 316 $type = 'tags'; 317 317 } 318 318 319 319 /** Sticky logic ******************************************************************/ 320 320 321 321 if ( $do_stickies ) { 322 322 // Fetch the stickies 323 323 $stickies_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, 0, 0, $max, 'sticky', $search_terms ); 324 324 325 325 // If stickies are found, try merging them 326 326 if ( $stickies_template->has_topics() ) { 327 328 // If stickies are for current $page 327 328 // If stickies are for current $page 329 329 $page_start_num = ( ( $page - 1 ) * $per_page ) + 1; 330 330 $page_end_num = $page * $per_page <= $stickies_template->total_topic_count ? $page * $per_page : $stickies_template->total_topic_count; 331 331 332 332 // Calculate the number of sticky topics that will be shown on this page 333 333 if ( $stickies_template->topic_count < $page_start_num ) { 334 334 $this_page_stickies = 0; 335 } else { 335 } else { 336 336 $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 337 337 338 338 // $this_page_stickies cannot be more than $per_page or less than 0 339 339 if ( $this_page_stickies > $per_page ) … … 342 342 $this_page_stickies = 0; 343 343 } 344 344 345 345 // Calculate the total number of topics that will be shown on this page 346 346 $this_page_topics = $stickies_template->total_topic_count >= ( $page * $per_page ) ? $per_page : $page_end_num - ( $page_start_num - 1 ); 347 347 348 348 // If the number of stickies to be shown is less than $per_page, fetch some 349 349 // non-stickies to fill in the rest … … 351 351 // How many non-stickies do we need? 352 352 $non_sticky_number = $this_page_topics - $this_page_stickies; 353 354 // Calculate the non-sticky offset 353 354 // Calculate the non-sticky offset 355 355 // How many non-stickies on all pages up to this point? 356 356 $non_sticky_total = $page_end_num - $stickies_template->topic_count; 357 357 358 358 // The offset is the number of total non-stickies, less the number 359 359 // to be shown on this page 360 360 $non_sticky_offset = $non_sticky_total - $non_sticky_number; 361 361 362 362 // Fetch the non-stickies 363 363 $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 ); 364 364 365 365 // If there are stickies to merge on this page, do it now 366 366 if ( $this_page_stickies ) { 367 367 // Correct the topic_count 368 368 $forum_template->topic_count += (int)$this_page_stickies; 369 369 370 370 // Figure out which stickies need to be included 371 371 $this_page_sticky_topics = array_slice( $stickies_template->topics, 0 - $this_page_stickies ); 372 372 373 373 // Merge these topics into the forum template 374 374 $forum_template->topics = array_merge( $this_page_sticky_topics, (array)$forum_template->topics ); … … 377 377 // This page has no non-stickies 378 378 $forum_template = $stickies_template; 379 379 380 380 // Adjust the topic count and trim the topics 381 381 $forum_template->topic_count = $this_page_stickies; 382 $forum_template->topics = array_slice( $forum_template->topics, $page - 1 ); 382 $forum_template->topics = array_slice( $forum_template->topics, $page - 1 ); 383 383 } 384 384 385 385 // Because we're using a manual offset and number for the topic query, we 386 386 // must set the page number manually, and recalculate the pagination links 387 387 $forum_template->pag_num = $per_page; 388 388 $forum_template->pag_page = $page; 389 389 390 390 $forum_template->pag_links = paginate_links( array( 391 391 'base' => add_query_arg( array( 'p' => '%#%', 'n' => $forum_template->pag_num ) ), … … 393 393 'total' => ceil( (int)$forum_template->total_topic_count / (int)$forum_template->pag_num ), 394 394 'current' => $forum_template->pag_page, 395 'prev_text' => '←',396 'next_text' => '→',395 'prev_text' => _x( '←', 'Forum topic pagination previous text', 'buddypress' ), 396 'next_text' => _x( '→', 'Forum topic pagination next text', 'buddypress' ), 397 397 'mid_size' => 1 398 398 ) ); 399 399 400 400 } else { 401 401 // Fetch the non-sticky topics if no stickies were found … … 406 406 $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, 'all', $search_terms ); 407 407 } 408 408 409 409 return apply_filters( 'bp_has_topics', $forum_template->has_topics(), $forum_template ); 410 410 } … … 865 865 function bp_forums_tag_name() { 866 866 echo bp_get_forums_tag_name(); 867 } 867 } 868 868 /** 869 869 * Outputs the currently viewed tag name … … 874 874 function bp_get_forums_tag_name() { 875 875 $tag_name = bp_is_directory() && bp_is_forums_component() ? bp_action_variable( 0 ) : false; 876 876 877 877 return apply_filters( 'bp_get_forums_tag_name', $tag_name ); 878 878 } … … 940 940 $this->__construct( $topic_id, $per_page, $max, $order ); 941 941 } 942 942 943 943 function __construct( $topic_id, $per_page, $max, $order ) { 944 944 global $bp, $current_user, $forum_template; … … 974 974 } 975 975 } 976 976 977 977 // Load topic tags 978 978 $this->topic_tags = bb_get_topic_tags( $this->topic_id ); … … 984 984 'total' => ceil( (int)$this->total_post_count / (int)$this->pag_num ), 985 985 'current' => $this->pag_page, 986 'prev_text' => '←',987 'next_text' => '→',986 'prev_text' => _x( '←', 'Forum thread pagination previous text', 'buddypress' ), 987 'next_text' => _x( '→', 'Forum thread pagination next text', 'buddypress' ), 988 988 'mid_size' => 1 989 989 ) ); … … 1069 1069 return false; 1070 1070 } 1071 1071 1072 1072 return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), $topic_template ); 1073 1073 } … … 1335 1335 function bp_get_forum_topic_tag_list( $format = 'string' ) { 1336 1336 global $topic_template; 1337 1337 1338 1338 $tags_data = !empty( $topic_template->topic_tags ) ? $topic_template->topic_tags : false; 1339 1339 1340 1340 $tags = array(); 1341 1341 1342 1342 if ( $tags_data ) { 1343 1343 foreach( $tags_data as $tag_data ) { … … 1345 1345 } 1346 1346 } 1347 1347 1348 1348 if ( 'string' == $format ) 1349 1349 $tags = implode( ', ', $tags ); 1350 1350 1351 1351 return apply_filters( 'bp_forum_topic_tag_list', $tags, $format ); 1352 1352 } … … 1362 1362 function bp_forum_topic_has_tags() { 1363 1363 global $topic_template; 1364 1364 1365 1365 $has_tags = false; 1366 1366 1367 1367 if ( !empty( $topic_template->topic_tags ) ) 1368 1368 $has_tags = true; 1369 1369 1370 1370 return apply_filters( 'bp_forum_topic_has_tags', $has_tags ); 1371 1371 }
Note: See TracChangeset
for help on using the changeset viewer.