Changeset 6680
- Timestamp:
- 09/07/2017 05:40:59 AM (8 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/core/abstraction.php
r6601 r6680 190 190 191 191 /** 192 * Remove the first-page from a pagination links result set, ensuring that it 193 * points to the canonical first page URL. 194 * 195 * This is a bit of an SEO hack, to guarantee that the first page in a loop will 196 * never have pagination appended to the end of it, regardless of what the other 197 * functions have decided for us. 198 * 199 * @since 2.6.0 bbPress (r6678) 200 * 201 * @param string $pagination_links The HTML links used for pagination 202 * 203 * @return string 204 */ 205 function bbp_make_first_page_canonical( $pagination_links = '' ) { 206 207 // Default value 208 $retval = $pagination_links; 209 210 // Remove first page from pagination 211 if ( ! empty( $pagination_links ) ) { 212 $retval = bbp_use_pretty_urls() 213 ? str_replace( bbp_get_paged_slug() . '/1/', '', $pagination_links ) 214 : preg_replace( '/&paged=1(?=[^0-9])/m', '', $pagination_links ); 215 } 216 217 // Filter & return 218 return apply_filters( 'bbp_make_first_page_canonical', $retval, $pagination_links ); 219 } 220 221 /** 222 * A convenient wrapper for common calls to paginate_links(), complete with 223 * support for parameters that aren't used internally by bbPress. 224 * 225 * @since 2.6.0 bbPress (r6679) 226 * 227 * @param array $args 228 * 229 * @return string 230 */ 231 function bbp_paginate_links( $args = array() ) { 232 233 // Maybe add view-all args 234 $add_args = empty( $args['add_args'] ) && bbp_get_view_all() 235 ? array( 'view' => 'all' ) 236 : false; 237 238 // Pagination settings with filter 239 $r = bbp_parse_args( $args, array( 240 241 // Used by callers 242 'base' => '', 243 'total' => 1, 244 'current' => bbp_get_paged(), 245 'prev_next' => true, 246 'prev_text' => is_rtl() ? '→' : '←', 247 'next_text' => is_rtl() ? '←' : '→', 248 'mid_size' => 1, 249 'end_size' => 3, 250 'add_args' => $add_args, 251 252 // Unused by callers 253 'show_all' => false, 254 'type' => 'plain', 255 'format' => '', 256 'add_fragment' => '', 257 'before_page_number' => '', 258 'after_page_number' => '' 259 ), 'paginate_links' ); 260 261 // Return paginated links 262 return bbp_make_first_page_canonical( paginate_links( $r ) ); 263 } 264 265 /** 192 266 * Is the environment using pretty URLs? 193 267 * -
trunk/src/includes/replies/template.php
r6627 r6680 172 172 173 173 // Set posts_per_page value if replies are threaded 174 $replies_per_page = $r['posts_per_page'];174 $replies_per_page = (int) $r['posts_per_page']; 175 175 if ( true === $r['hierarchical'] ) { 176 176 $r['posts_per_page'] = -1; … … 184 184 185 185 // Add pagination values to query object 186 $bbp->reply_query->posts_per_page = $replies_per_page;187 $bbp->reply_query->paged = $r['paged'];186 $bbp->reply_query->posts_per_page = (int) $replies_per_page; 187 $bbp->reply_query->paged = (int) $r['paged']; 188 188 189 189 // Never home, regardless of what parse_query says … … 196 196 197 197 // Only add reply to if query returned results 198 if ( (int) $bbp->reply_query->found_posts) {198 if ( ! empty( $bbp->reply_query->found_posts ) ) { 199 199 200 200 // Get reply to for each reply … … 217 217 218 218 // Only add pagination if query returned results 219 if ( (int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) { 220 221 // If pretty permalinks are enabled, make our pagination pretty 222 if ( bbp_use_pretty_urls() ) { 223 224 // User's replies 225 if ( bbp_is_single_user_replies() ) { 226 $base = bbp_get_user_replies_created_url( bbp_get_displayed_user_id() ); 227 228 // Root profile page 229 } elseif ( bbp_is_single_user() ) { 230 $base = bbp_get_user_profile_url( bbp_get_displayed_user_id() ); 231 232 // Page or single post 233 } elseif ( is_page() || is_single() ) { 234 $base = get_permalink(); 235 236 // Single topic 237 } else { 238 $base = get_permalink( bbp_get_topic_id() ); 239 } 240 241 $base = trailingslashit( $base ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); 242 243 // Unpretty permalinks 244 } else { 245 $base = add_query_arg( 'paged', '%#%' ); 246 } 219 if ( ! empty( $bbp->reply_query->found_posts ) && ! empty( $bbp->reply_query->posts_per_page ) ) { 247 220 248 221 // Figure out total pages 249 222 if ( true === $r['hierarchical'] ) { 250 223 $walker = new BBP_Walker_Reply; 251 $total_pages = ceil( (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ) / (int) $replies_per_page );224 $total_pages = ceil( $walker->get_number_of_root_elements( $bbp->reply_query->posts ) / $bbp->reply_query->posts_per_page ); 252 225 } else { 253 $total_pages = ceil( (int) $bbp->reply_query->found_posts / (int) $replies_per_page ); 226 227 // Total for pagination boundaries 228 $total_pages = ( $bbp->reply_query->posts_per_page === $bbp->reply_query->found_posts ) 229 ? 1 230 : ceil( $bbp->reply_query->found_posts / $bbp->reply_query->posts_per_page ); 231 232 // Pagination settings with filter 233 $bbp_replies_pagination = apply_filters( 'bbp_replies_pagination', array( 234 'base' => bbp_get_replies_pagination_base( bbp_get_topic_id() ), 235 'total' => $total_pages, 236 'current' => $bbp->reply_query->paged 237 ) ); 254 238 255 239 // Add pagination to query object 256 $bbp->reply_query->pagination_links = paginate_links( apply_filters( 'bbp_replies_pagination', array( 257 'base' => $base, 258 'format' => '', 259 'total' => $total_pages, 260 'current' => (int) $bbp->reply_query->paged, 261 'prev_text' => is_rtl() ? '→' : '←', 262 'next_text' => is_rtl() ? '←' : '→', 263 'mid_size' => 1, 264 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false 265 ) ) ); 266 267 // Remove first page from pagination 268 if ( bbp_use_pretty_urls() ) { 269 $bbp->reply_query->pagination_links = str_replace( bbp_get_paged_slug() . '/1/', '', $bbp->reply_query->pagination_links ); 270 } else { 271 $bbp->reply_query->pagination_links = preg_replace( '/&paged=1(?=[^0-9])/m', '', $bbp->reply_query->pagination_links ); 272 } 240 $bbp->reply_query->pagination_links = bbp_paginate_links( $bbp_replies_pagination ); 273 241 } 274 242 } … … 2224 2192 } 2225 2193 2194 /** Pagination ****************************************************************/ 2195 2196 /** 2197 * Return the base URL used inside of pagination links 2198 * 2199 * @since 2.6.0 bbPress (r6679) 2200 * 2201 * @param int $topic_id 2202 * @return string 2203 */ 2204 function bbp_get_replies_pagination_base( $topic_id = 0 ) { 2205 2206 // If pretty permalinks are enabled, make our pagination pretty 2207 if ( bbp_use_pretty_urls() ) { 2208 2209 // User's replies 2210 if ( bbp_is_single_user_replies() ) { 2211 $base = bbp_get_user_replies_created_url( bbp_get_displayed_user_id() ); 2212 2213 // Root profile page 2214 } elseif ( bbp_is_single_user() ) { 2215 $base = bbp_get_user_profile_url( bbp_get_displayed_user_id() ); 2216 2217 // Page or single post 2218 } elseif ( is_page() || is_single() ) { 2219 $base = get_permalink(); 2220 2221 // Single topic 2222 } else { 2223 $base = get_permalink( $topic_id ); 2224 } 2225 2226 $base = trailingslashit( $base ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); 2227 2228 // Unpretty permalinks 2229 } else { 2230 $base = add_query_arg( 'paged', '%#%' ); 2231 } 2232 2233 // Filter & return 2234 return apply_filters( 'bbp_get_replies_pagination_base', $base, $topic_id ); 2235 } 2236 2226 2237 /** 2227 2238 * Output the topic pagination count -
trunk/src/includes/search/template.php
r6672 r6680 77 77 78 78 // Add pagination values to query object 79 $bbp->search_query->posts_per_page = $r['posts_per_page'];80 $bbp->search_query->paged = $r['paged'];79 $bbp->search_query->posts_per_page = (int) $r['posts_per_page']; 80 $bbp->search_query->paged = (int) $r['paged']; 81 81 82 82 // Never home, regardless of what parse_query says … … 86 86 if ( ! empty( $bbp->search_query->found_posts ) && ! empty( $bbp->search_query->posts_per_page ) ) { 87 87 88 // Array of arguments to add after pagination links 89 $add_args = array(); 90 91 // If pretty permalinks are enabled, make our pagination pretty 92 if ( bbp_use_pretty_urls() ) { 93 94 // Shortcode territory 95 if ( is_page() || is_single() ) { 96 $base = trailingslashit( get_permalink() ); 97 98 // Default search location 99 } else { 100 $base = trailingslashit( bbp_get_search_results_url() ); 101 } 102 103 // Add pagination base 104 $base = $base . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); 105 106 // Unpretty permalinks 107 } else { 108 $base = add_query_arg( 'paged', '%#%' ); 109 } 110 111 // Add args 112 if ( bbp_get_view_all() ) { 113 $add_args['view'] = 'all'; 114 } 88 // Total for pagination boundaries 89 $total_pages = ( $bbp->search_query->posts_per_page === $bbp->search_query->found_posts ) 90 ? 1 91 : ceil( $bbp->search_query->found_posts / $bbp->search_query->posts_per_page ); 92 93 // Pagination settings with filter 94 $bbp_search_pagination = apply_filters( 'bbp_search_results_pagination', array( 95 'base' => bbp_get_search_pagination_base(), 96 'total' => $total_pages, 97 'current' => $bbp->search_query->paged 98 ) ); 115 99 116 100 // Add pagination to query object 117 $bbp->search_query->pagination_links = paginate_links( 118 apply_filters( 'bbp_search_results_pagination', array( 119 'base' => $base, 120 'format' => '', 121 'total' => ceil( (int) $bbp->search_query->found_posts / (int) $r['posts_per_page'] ), 122 'current' => (int) $bbp->search_query->paged, 123 'prev_text' => is_rtl() ? '→' : '←', 124 'next_text' => is_rtl() ? '←' : '→', 125 'mid_size' => 1, 126 'add_args' => $add_args, 127 ) ) 128 ); 129 130 // Remove first page from pagination 131 if ( bbp_use_pretty_urls() ) { 132 $bbp->search_query->pagination_links = str_replace( bbp_get_paged_slug() . '/1/', '', $bbp->search_query->pagination_links ); 133 } else { 134 $bbp->search_query->pagination_links = preg_replace( '/&paged=1(?=[^0-9])/m', '', $bbp->search_query->pagination_links ); 135 } 101 $bbp->search_query->pagination_links = bbp_paginate_links( $bbp_search_pagination ); 136 102 } 137 103 … … 343 309 return apply_filters( 'bbp_get_search_terms', $search_terms, $passed_terms ); 344 310 } 311 312 /** Pagination ****************************************************************/ 313 314 /** 315 * Return the base URL used inside of pagination links 316 * 317 * @since 2.6.0 bbPress (r6679) 318 * 319 * @return string 320 */ 321 function bbp_get_search_pagination_base() { 322 323 // If pretty permalinks are enabled, make our pagination pretty 324 if ( bbp_use_pretty_urls() ) { 325 326 // Shortcode territory 327 if ( is_page() || is_single() ) { 328 $base = trailingslashit( get_permalink() ); 329 330 // Default search location 331 } else { 332 $base = trailingslashit( bbp_get_search_results_url() ); 333 } 334 335 // Add pagination base 336 $base = $base . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); 337 338 // Unpretty permalinks 339 } else { 340 $base = add_query_arg( 'paged', '%#%' ); 341 } 342 343 // Filter & return 344 return apply_filters( 'bbp_get_search_pagination_base', $base ); 345 } 345 346 346 347 /** -
trunk/src/includes/topics/template.php
r6644 r6680 203 203 // Limited the number of pages shown 204 204 if ( ! empty( $r['max_num_pages'] ) ) { 205 $bbp->topic_query->max_num_pages = $r['max_num_pages'];205 $bbp->topic_query->max_num_pages = (int) $r['max_num_pages']; 206 206 } 207 207 … … 223 223 224 224 // Only add pagination if query returned results 225 if ( ( (int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts ) && (int) $bbp->topic_query->posts_per_page) {225 if ( ( ! empty( $bbp->topic_query->post_count ) || ! empty( $bbp->topic_query->found_posts ) ) && ! empty( $bbp->topic_query->posts_per_page ) ) { 226 226 227 227 // Limit the number of topics shown based on maximum allowed pages … … 231 231 232 232 // Total topics for pagination boundaries 233 $total = ( $r['posts_per_page']=== $bbp->topic_query->found_posts )233 $total_pages = ( $bbp->topic_query->posts_per_page === $bbp->topic_query->found_posts ) 234 234 ? 1 235 : ceil( (int) $bbp->topic_query->found_posts / (int) $r['posts_per_page'] ); 235 : ceil( $bbp->topic_query->found_posts / $bbp->topic_query->posts_per_page ); 236 237 // Maybe add view-all args 238 $add_args = bbp_get_view_all() 239 ? array( 'view' => 'all' ) 240 : false; 236 241 237 242 // Pagination settings with filter … … 239 244 'base' => bbp_get_topics_pagination_base( $r['post_parent'] ), 240 245 'format' => '', 241 'total' => (int) $total,242 'current' => (int)$bbp->topic_query->paged,246 'total' => $total_pages, 247 'current' => $bbp->topic_query->paged, 243 248 'prev_text' => is_rtl() ? '→' : '←', 244 249 'next_text' => is_rtl() ? '←' : '→', 245 'mid_size' => 1 250 'mid_size' => 1, 251 'add_args' => $add_args, 246 252 ) ); 247 253 248 254 // Add pagination to query object 249 $bbp->topic_query->pagination_links = paginate_links( $bbp_topic_pagination ); 250 251 // Remove first page from pagination 252 $bbp->topic_query->pagination_links = str_replace( bbp_get_paged_slug() . "/1/'", "'", $bbp->topic_query->pagination_links ); 255 $bbp->topic_query->pagination_links = bbp_paginate_links( $bbp_topic_pagination ); 253 256 } 254 257 … … 781 784 782 785 // If pretty permalinks are enabled, make our pagination pretty 783 if ( bbp_use_pretty_urls() ) { 784 $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); 785 } else { 786 $base = add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) ); 787 } 786 $base = bbp_use_pretty_urls() 787 ? trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ) 788 : add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) ); 788 789 789 790 // Get total and add 1 if topic is included in the reply loop … … 794 795 $total++; 795 796 } 797 798 // Total for pagination boundaries 799 $total_pages = ceil( $total / bbp_get_replies_per_page() ); 796 800 797 801 // Maybe add view-all args … … 800 804 : false; 801 805 802 // Add pagination to query object803 $ pagination_links = paginate_links(array(806 // Pagination settings with filter 807 $bbp_topic_pagination = apply_filters( 'bbp_get_topic_pagination', array( 804 808 'base' => $base, 805 'format' => '', 806 'total' => ceil( (int) $total / (int) bbp_get_replies_per_page() ), 809 'total' => $total_pages, 807 810 'current' => 0, 808 811 'prev_next' => false, 809 812 'mid_size' => 2, 810 'end_size' => 3,813 'end_size' => 2, 811 814 'add_args' => $add_args 812 815 ) ); 813 816 817 // Add pagination to query object 818 $pagination_links = bbp_paginate_links( $bbp_topic_pagination ); 819 820 // Maybe add before and after to pagination links 814 821 if ( ! empty( $pagination_links ) ) { 815 816 // Remove first page from pagination817 if ( bbp_use_pretty_urls() ) {818 $pagination_links = str_replace( bbp_get_paged_slug() . '/1/', '', $pagination_links );819 } else {820 $pagination_links = preg_replace( '/&paged=1(?=[^0-9])/m', '', $pagination_links );821 }822 823 // Add before and after to pagination links824 822 $pagination_links = $r['before'] . $pagination_links . $r['after']; 825 823 } … … 2913 2911 2914 2912 // Filter & return 2915 return apply_filters( 'bbp_get_topics_pagination_base', $base );2913 return apply_filters( 'bbp_get_topics_pagination_base', $base, $forum_id ); 2916 2914 } 2917 2915
Note: See TracChangeset
for help on using the changeset viewer.