Skip to:
Content

bbPress.org


Ignore:
Timestamp:
10/19/2012 07:42:49 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Number Formatting:

  • Introduce $integer parameter to template-tags to switch filter for integer usage.
  • Use absint() where appropriate when getting counts.
  • Smarter int type casting.
  • Fixes bug where calculations were being done against formatted strings.
  • Fixes #1974.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bbp-includes/topics/template-tags.php

    r4255 r4258  
    737737
    738738        // Get total and add 1 if topic is included in the reply loop
    739         $total = bbp_get_topic_reply_count( $topic_id );
     739        $total = bbp_get_topic_reply_count( $topic_id, true );
    740740
    741741        // Bump if topic is in loop
     
    918918 * @return string Topic revision count
    919919 */
    920 function bbp_get_topic_revision_count( $topic_id = 0 ) {
    921     return apply_filters( 'bbp_get_topic_revisions', count( bbp_get_topic_revisions( $topic_id ) ), $topic_id );
     920function bbp_get_topic_revision_count( $topic_id = 0, $integer = false ) {
     921    $count  = absint( count( bbp_get_topic_revisions( $topic_id ) ) );
     922    $filter = ( true === $integer ) ? 'bbp_get_topic_revision_count_int' : 'bbp_get_topic_revision_count';
     923
     924    return apply_filters( $filter, $count, $topic_id );
    922925}
    923926
     
    18551858        $topic    = bbp_get_topic( bbp_get_topic_id( (int) $topic_id ) );
    18561859        $topic_id = $topic->ID;
    1857         $replies  = bbp_get_topic_reply_count( $topic_id );
    1858         $replies  = sprintf( _n( '%s reply', '%s replies', $replies, 'bbpress' ), $replies );
     1860        $replies  = sprintf( _n( '%s reply', '%s replies', bbp_get_topic_reply_count( $topic_id, true ), 'bbpress' ), bbp_get_topic_reply_count( $topic_id ) );
    18591861        $retval   = '';
    18601862
     
    18931895 *
    18941896 * @param int $topic_id Optional. Topic id
     1897 * @param boolean $integer Optional. Whether or not to format the result
    18951898 * @uses bbp_get_topic_reply_count() To get the topic reply count
    18961899 */
    1897 function bbp_topic_reply_count( $topic_id = 0 ) {
    1898     echo bbp_get_topic_reply_count( $topic_id );
     1900function bbp_topic_reply_count( $topic_id = 0, $integer = false ) {
     1901    echo bbp_get_topic_reply_count( $topic_id, $integer );
    18991902}
    19001903    /**
     
    19041907     *
    19051908     * @param int $topic_id Optional. Topic id
     1909     * @param boolean $integer Optional. Whether or not to format the result
    19061910     * @uses bbp_get_topic_id() To get the topic id
    19071911     * @uses get_post_meta() To get the topic reply count meta
     
    19101914     * @return int Reply count
    19111915     */
    1912     function bbp_get_topic_reply_count( $topic_id = 0 ) {
     1916    function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) {
    19131917        $topic_id = bbp_get_topic_id( $topic_id );
    1914         $replies  = get_post_meta( $topic_id, '_bbp_reply_count', true );
    1915 
    1916         return apply_filters( 'bbp_get_topic_reply_count', (int) $replies, $topic_id );
     1918        $replies  = absint( get_post_meta( $topic_id, '_bbp_reply_count', true ) );
     1919        $filter   = ( true === $integer ) ? 'bbp_get_topic_reply_count_int' : 'bbp_get_topic_reply_count';
     1920
     1921        return apply_filters( $filter, $replies, $topic_id );
    19171922    }
    19181923
     
    19231928 *
    19241929 * @param int $topic_id Optional. Topic id
     1930 * @param boolean $integer Optional. Whether or not to format the result
    19251931 * @uses bbp_get_topic_post_count() To get the topic post count
    19261932 */
    1927 function bbp_topic_post_count( $topic_id = 0 ) {
    1928     echo bbp_get_topic_post_count( $topic_id );
     1933function bbp_topic_post_count( $topic_id = 0, $integer = false ) {
     1934    echo bbp_get_topic_post_count( $topic_id, $integer );
    19291935}
    19301936    /**
     
    19341940     *
    19351941     * @param int $topic_id Optional. Topic id
     1942     * @param boolean $integer Optional. Whether or not to format the result
    19361943     * @uses bbp_get_topic_id() To get the topic id
    19371944     * @uses get_post_meta() To get the topic post count meta
     
    19401947     * @return int Post count
    19411948     */
    1942     function bbp_get_topic_post_count( $topic_id = 0 ) {
     1949    function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) {
    19431950        $topic_id = bbp_get_topic_id( $topic_id );
    1944         $replies  = get_post_meta( $topic_id, '_bbp_reply_count', true );
    1945 
    1946         return apply_filters( 'bbp_get_topic_post_count', (int) $replies + 1, $topic_id );
     1951        $replies  = absint( get_post_meta( $topic_id, '_bbp_reply_count', true ) ) + 1;
     1952        $filter   = ( true === $integer ) ? 'bbp_get_topic_post_count_int' : 'bbp_get_topic_post_count';
     1953
     1954        return apply_filters( $filter, $replies, $topic_id );
    19471955    }
    19481956
     
    19541962 *
    19551963 * @param int $topic_id Optional. Topic id
     1964 * @param boolean $integer Optional. Whether or not to format the result
    19561965 * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden reply count
    19571966 */
    1958 function bbp_topic_reply_count_hidden( $topic_id = 0 ) {
    1959     echo bbp_get_topic_reply_count_hidden( $topic_id );
     1967function bbp_topic_reply_count_hidden( $topic_id = 0, $integer = false ) {
     1968    echo bbp_get_topic_reply_count_hidden( $topic_id, $integer );
    19601969}
    19611970    /**
     
    19661975     *
    19671976     * @param int $topic_id Optional. Topic id
     1977     * @param boolean $integer Optional. Whether or not to format the result
    19681978     * @uses bbp_get_topic_id() To get the topic id
    19691979     * @uses get_post_meta() To get the hidden reply count
     
    19721982     * @return int Topic hidden reply count
    19731983     */
    1974     function bbp_get_topic_reply_count_hidden( $topic_id = 0 ) {
     1984    function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) {
    19751985        $topic_id = bbp_get_topic_id( $topic_id );
    1976         $replies  = get_post_meta( $topic_id, '_bbp_reply_count_hidden', true );
    1977 
    1978         return (int) apply_filters( 'bbp_get_topic_reply_count_hidden', (int) $replies, $topic_id );
     1986        $replies  = absint( get_post_meta( $topic_id, '_bbp_reply_count_hidden', true ) );
     1987        $filter   = ( true === $integer ) ? 'bbp_get_topic_reply_count_hidden_int' : 'bbp_get_topic_reply_count_hidden';
     1988
     1989        return apply_filters( $filter, $replies, $topic_id );
    19791990    }
    19801991
     
    19871998 * @uses bbp_get_topic_voice_count() To get the topic voice count
    19881999 */
    1989 function bbp_topic_voice_count( $topic_id = 0 ) {
    1990     echo bbp_get_topic_voice_count( $topic_id );
     2000function bbp_topic_voice_count( $topic_id = 0, $integer = false ) {
     2001    echo bbp_get_topic_voice_count( $topic_id, $integer );
    19912002}
    19922003    /**
     
    20022013     * @return int Voice count of the topic
    20032014     */
    2004     function bbp_get_topic_voice_count( $topic_id = 0 ) {
     2015    function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) {
    20052016        $topic_id = bbp_get_topic_id( $topic_id );
    2006         $voices   = get_post_meta( $topic_id, '_bbp_voice_count', true );
    2007 
    2008         return apply_filters( 'bbp_get_topic_voice_count', (int) $voices, $topic_id );
     2017        $voices   = absint( get_post_meta( $topic_id, '_bbp_voice_count', true ) );
     2018        $filter   = ( true === $integer ) ? 'bbp_get_topic_voice_count_int' : 'bbp_get_topic_voice_count';
     2019
     2020        return apply_filters( $filter, $voices, $topic_id );
    20092021    }
    20102022
Note: See TracChangeset for help on using the changeset viewer.