Skip to:
Content

bbPress.org

Changeset 6682


Ignore:
Timestamp:
09/09/2017 04:49:42 AM (4 years ago)
Author:
johnjamesjacoby
Message:

Template: adjust escaping of pagination count strings.

This change fixes a regression (in trunk only) that caused the filtered results of pagination counts to always be late escaped, but the intention was really only to escape the output of _n() which does not have an escaped equivalent function in the Gettext API.

I also tweaked the logic in bbp_get_topic_pagination_count() to not bail early. This brings it inline with bbp_get_forum_pagination_count() and allows the filter to run even when the text string is empty. Flexibility is the goal, so skipping the filter was also unintentional, and is now fixed.

Fixes #3162.

Location:
trunk/src/includes
Files:
2 edited

Legend:

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

    r6680 r6682  
    22382238 * Output the topic pagination count
    22392239 *
     2240 * The results are unescaped by design, to allow them to be filtered freely via
     2241 * the 'bbp_get_topic_pagination_count' filter.
     2242 *
    22402243 * @since 2.0.0 bbPress (r2519)
    22412244 *
    22422245 */
    22432246function bbp_topic_pagination_count() {
    2244     echo esc_html( bbp_get_topic_pagination_count() );
     2247    echo bbp_get_topic_pagination_count();
    22452248}
    22462249    /**
     
    22582261
    22592262        // Set pagination values
     2263        $count_int = intval( $bbp->reply_query->post_count     );
    22602264        $total_int = intval( $bbp->reply_query->found_posts    );
    22612265        $ppp_int   = intval( $bbp->reply_query->posts_per_page );
    22622266        $start_int = intval( ( $bbp->reply_query->paged - 1 ) * $ppp_int ) + 1;
    22632267        $to_int    = intval( ( $start_int + ( $ppp_int - 1 ) > $total_int )
    2264                 ? $total_int
    2265                 : $start_int + ( $ppp_int - 1 ) );
     2268            ? $total_int
     2269            : $start_int + ( $ppp_int - 1 ) );
    22662270
    22672271        // Format numbers for display
     2272        $count_num = bbp_number_format( $count_int );
    22682273        $total_num = bbp_number_format( $total_int );
    22692274        $from_num  = bbp_number_format( $start_int );
     
    22852290            // Several replies in a topic with several pages
    22862291            } else {
    2287                 $retstr = sprintf( _n( 'Viewing %2$s replies (of %4$s total)', 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress' ), $bbp->reply_query->post_count, $from_num, $to_num, $total_num );
     2292                $retstr = sprintf( _n( 'Viewing %2$s replies (of %4$s total)', 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', $count_int, 'bbpress' ), $count_num, $from_num, $to_num, $total_num );
    22882293            }
    22892294
     
    22972302            // Several posts in a topic with several pages
    22982303            } else {
    2299                 $retstr = sprintf( _n( 'Viewing %2$s post (of %4$s total)', 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress' ), $bbp->reply_query->post_count, $from_num, $to_num, $total_num );
     2304                $retstr = sprintf( _n( 'Viewing %2$s post (of %4$s total)', 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', $count_int, 'bbpress' ), $count_num, $from_num, $to_num, $total_num );
    23002305            }
    23012306        }
     2307
     2308        // Escape results of _n()
     2309        $retstr = esc_html( $retstr );
    23022310
    23032311        // Filter & return
  • trunk/src/includes/topics/template.php

    r6680 r6682  
    29172917 * Output the pagination count
    29182918 *
     2919 * The results are unescaped by design, to allow them to be filtered freely via
     2920 * the 'bbp_get_forum_pagination_count' filter.
     2921 *
    29192922 * @since 2.0.0 bbPress (r2519)
    29202923 */
    29212924function bbp_forum_pagination_count() {
    2922     echo esc_html( bbp_get_forum_pagination_count() );
     2925    echo bbp_get_forum_pagination_count();
    29232926}
    29242927    /**
     
    29322935        $bbp = bbpress();
    29332936
    2934         if ( empty( $bbp->topic_query ) ) {
    2935             return false;
    2936         }
    2937 
    2938         // Set pagination values
    2939         $start_num = intval( ( $bbp->topic_query->paged - 1 ) * $bbp->topic_query->posts_per_page ) + 1;
    2940         $from_num  = bbp_number_format( $start_num );
    2941         $to_num    = bbp_number_format( ( $start_num + ( $bbp->topic_query->posts_per_page - 1 ) > $bbp->topic_query->found_posts ) ? $bbp->topic_query->found_posts : $start_num + ( $bbp->topic_query->posts_per_page - 1 ) );
    2942         $total_int = (int) ! empty( $bbp->topic_query->found_posts ) ? $bbp->topic_query->found_posts : $bbp->topic_query->post_count;
    2943         $total     = bbp_number_format( $total_int );
    2944 
    2945         // Several topics in a forum with a single page
    2946         if ( empty( $to_num ) ) {
    2947             $retstr = sprintf( _n( 'Viewing %1$s topic', 'Viewing %1$s topics', $total_int, 'bbpress' ), $total );
    2948 
    2949         // Several topics in a forum with several pages
    2950         } else {
    2951             $retstr = sprintf( _n( 'Viewing topic %2$s (of %4$s total)', 'Viewing %1$s topics - %2$s through %3$s (of %4$s total)', $total_int, 'bbpress' ), $bbp->topic_query->post_count, $from_num, $to_num, $total );
     2937        // Define local variable(s)
     2938        $retstr = '';
     2939
     2940        // Topic query exists
     2941        if ( ! empty( $bbp->topic_query ) ) {
     2942
     2943            // Set pagination values
     2944            $count_int = intval( $bbp->topic_query->post_count );
     2945            $start_num = intval( ( $bbp->topic_query->paged - 1 ) * $bbp->topic_query->posts_per_page ) + 1;
     2946            $total_int = ! empty( $bbp->topic_query->found_posts )
     2947                ? (int) $bbp->topic_query->found_posts
     2948                : $count_int;
     2949
     2950            // Format numbers for display
     2951            $count_num = bbp_number_format( $count_int );
     2952            $from_num  = bbp_number_format( $start_num );
     2953            $total     = bbp_number_format( $total_int );
     2954            $to_num    = bbp_number_format( ( $start_num + ( $bbp->topic_query->posts_per_page - 1 ) > $bbp->topic_query->found_posts )
     2955                ? $bbp->topic_query->found_posts
     2956                : $start_num + ( $bbp->topic_query->posts_per_page - 1 ) );
     2957
     2958            // Several topics in a forum with a single page
     2959            if ( empty( $to_num ) ) {
     2960                $retstr = sprintf( _n( 'Viewing %1$s topic', 'Viewing %1$s topics', $total_int, 'bbpress' ), $total );
     2961
     2962            // Several topics in a forum with several pages
     2963            } else {
     2964                $retstr = sprintf( _n( 'Viewing topic %2$s (of %4$s total)', 'Viewing %1$s topics - %2$s through %3$s (of %4$s total)', $total_int, 'bbpress' ), $count_num, $from_num, $to_num, $total );
     2965            }
     2966
     2967            // Escape results of _n()
     2968            $retstr = esc_html( $retstr );
    29522969        }
    29532970
Note: See TracChangeset for help on using the changeset viewer.