Skip to:
Content

bbPress.org


Ignore:
Timestamp:
02/21/2017 11:25:09 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Pagination: prefer intval() for numeric values, and always format numbers used for display.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/search/template.php

    r6228 r6300  
    402402
    403403        // Set pagination values
    404         $start_num = intval( ( $bbp->search_query->paged - 1 ) * $bbp->search_query->posts_per_page ) + 1;
    405         $from_num  = bbp_number_format( $start_num );
    406         $to_num    = bbp_number_format( ( $start_num + ( $bbp->search_query->posts_per_page - 1 ) > $bbp->search_query->found_posts ) ? $bbp->search_query->found_posts : $start_num + ( $bbp->search_query->posts_per_page - 1 ) );
    407         $total_int = (int) $bbp->search_query->found_posts;
    408         $total     = bbp_number_format( $total_int );
     404        $total_int = intval( $bbp->search_query->found_posts    );
     405        $ppp_int   = intval( $bbp->search_query->posts_per_page );
     406        $start_int = intval( ( $bbp->search_query->paged - 1 ) * $ppp_int ) + 1;
     407        $to_int    = intval( ( $start_int + ( $ppp_int - 1 ) > $total_int )
     408                ? $total_int
     409                : $start_int + ( $ppp_int - 1 ) );
     410
     411        // Format numbers for display
     412        $total_num = bbp_number_format( $total_int );
     413        $from_num  = bbp_number_format( $start_int );
     414        $to_num    = bbp_number_format( $to_int    );
    409415
    410416        // Single page of results
    411417        if ( empty( $to_num ) ) {
    412             $retstr = sprintf( _n( 'Viewing %1$s result', 'Viewing %1$s results', $total_int, 'bbpress' ), $total );
     418            $retstr = sprintf( _n( 'Viewing %1$s result', 'Viewing %1$s results', $total_int, 'bbpress' ), $total_num );
    413419
    414420        // Several pages of results
    415421        } else {
    416             $retstr = sprintf( _n( 'Viewing %2$s results (of %4$s total)', 'Viewing %1$s results - %2$s through %3$s (of %4$s total)', $bbp->search_query->post_count, 'bbpress' ), $bbp->search_query->post_count, $from_num, $to_num, $total );
    417 
     422            $retstr = sprintf( _n( 'Viewing %2$s results (of %4$s total)', 'Viewing %1$s results - %2$s through %3$s (of %4$s total)', $bbp->search_query->post_count, 'bbpress' ), $bbp->search_query->post_count, $from_num, $to_num, $total_num );
    418423        }
    419424
Note: See TracChangeset for help on using the changeset viewer.