Skip to:
Content

bbPress.org


Ignore:
Timestamp:
04/15/2015 02:14:20 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Topics: Audit template.php:

  • Add filters to is_sticky functions
  • Pass $args into more filters
  • Escape more gettext output
  • Fix a few bbp_parse_args filter names copied from forums component
  • Un-nest a few complex-looking lines
File:
1 edited

Legend:

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

    r5676 r5680  
    258258                    $sticky_offset++;
    259259
    260                     $sticky = $bbp->topic_query->posts[$post_offset];
     260                    $sticky = $bbp->topic_query->posts[ $post_offset ];
    261261
    262262                    // Remove sticky from current position
     
    267267
    268268                    // Cleanup
    269                     unset( $stickies[$sticky_index] );
     269                    unset( $stickies[ $sticky_index ] );
    270270                    unset( $sticky );
    271271                }
     
    406406
    407407        // Pagination settings with filter
    408         $bbp_topic_pagination = apply_filters( 'bbp_topic_pagination', array (
     408        $bbp_topic_pagination = apply_filters( 'bbp_topic_pagination', array(
    409409            'base'      => $base,
    410410            'format'    => '',
     
    895895        }
    896896
    897         // Pagination settings
    898         $pagination = array(
     897        // Add pagination to query object
     898        $pagination_links = paginate_links( array(
    899899            'base'      => $base,
    900900            'format'    => '',
     
    905905            'end_size'  => 3,
    906906            'add_args'  => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false
    907         );
    908 
    909         // Add pagination to query object
    910         $pagination_links = paginate_links( $pagination );
     907        ) );
     908
    911909        if ( ! empty( $pagination_links ) ) {
    912910
     
    979977     */
    980978    function bbp_get_topic_revision_log( $topic_id = 0 ) {
     979
    981980        // Create necessary variables
    982981        $topic_id     = bbp_get_topic_id( $topic_id );
     
    992991        }
    993992
    994         $r = "\n\n" . '<ul id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '" class="bbp-topic-revision-log">' . "\n\n";
     993        $retval = "\n\n" . '<ul id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '" class="bbp-topic-revision-log">' . "\n\n";
    995994
    996995        // Loop through revisions
    997996        foreach ( (array) $revisions as $revision ) {
    998997
    999             if ( empty( $revision_log[$revision->ID] ) ) {
     998            if ( empty( $revision_log[ $revision->ID ] ) ) {
    1000999                $author_id = $revision->post_author;
    10011000                $reason    = '';
    10021001            } else {
    1003                 $author_id = $revision_log[$revision->ID]['author'];
    1004                 $reason    = $revision_log[$revision->ID]['reason'];
     1002                $author_id = $revision_log[ $revision->ID ]['author'];
     1003                $reason    = $revision_log[ $revision->ID ]['reason'];
    10051004            }
    10061005
     
    10081007            $since  = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) );
    10091008
    1010             $r .= "\t" . '<li id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-topic-revision-log-item">' . "\n";
     1009            $retval .= "\t" . '<li id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-topic-revision-log-item">' . "\n";
    10111010            if ( ! empty( $reason ) ) {
    1012                 $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n";
     1011                $retval .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n";
    10131012            } else {
    1014                 $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n";
     1013                $retval .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s.',              'bbpress' ), esc_html( $since ), $author ) . "\n";
    10151014            }
    1016             $r .= "\t" . '</li>' . "\n";
    1017 
    1018         }
    1019 
    1020         $r .= "\n" . '</ul>' . "\n\n";
    1021 
    1022         return apply_filters( 'bbp_get_topic_revision_log', $r, $topic_id );
     1015            $retval .= "\t" . '</li>' . "\n";
     1016        }
     1017
     1018        $retval .= "\n" . '</ul>' . "\n\n";
     1019
     1020        return apply_filters( 'bbp_get_topic_revision_log', $retval, $topic_id );
    10231021    }
    10241022        /**
     
    11591157    $forum_id = bbp_get_topic_forum_id( $topic_id );
    11601158    $stickies = bbp_get_stickies( $forum_id );
    1161 
    1162     if ( in_array( $topic_id, $stickies ) || ( ! empty( $check_super ) && bbp_is_topic_super_sticky( $topic_id ) ) ) {
    1163         return true;
    1164     }
    1165 
    1166     return false;
     1159    $retval   = in_array( $topic_id, $stickies );
     1160
     1161    // Maybe check super stickies
     1162    if ( ( false === $retval ) && ( true === $check_super ) ) {
     1163        $retval = bbp_is_topic_super_sticky( $topic_id );
     1164    }
     1165
     1166    return (bool) apply_filters( 'bbp_is_topic_sticky', $retval, $topic_id, $check_super );
    11671167}
    11681168
     
    11801180    $topic_id = bbp_get_topic_id( $topic_id );
    11811181    $stickies = bbp_get_super_stickies( $topic_id );
    1182 
    1183     return in_array( $topic_id, $stickies );
     1182    $retval   = in_array( $topic_id, $stickies );
     1183
     1184    return (bool) apply_filters( 'bbp_is_topic_super_sticky', $retval, $topic_id );
    11841185}
    11851186
     
    11961197 */
    11971198function bbp_is_topic_published( $topic_id = 0 ) {
    1198     $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_public_status_id();
     1199    $topic_id     = bbp_get_topic_id( $topic_id );
     1200    $status       = bbp_get_public_status_id();
     1201    $topic_status = bbp_get_topic_status( $topic_id ) === $status;
     1202
    11991203    return (bool) apply_filters( 'bbp_is_topic_published', (bool) $topic_status, $topic_id );
    12001204}
     
    12121216 */
    12131217function bbp_is_topic_spam( $topic_id = 0 ) {
    1214     $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_spam_status_id();
     1218    $topic_id     = bbp_get_topic_id( $topic_id );
     1219    $status       = bbp_get_spam_status_id();
     1220    $topic_status = bbp_get_topic_status( $topic_id ) === $status;
     1221
    12151222    return (bool) apply_filters( 'bbp_is_topic_spam', (bool) $topic_status, $topic_id );
    12161223}
     
    12281235 */
    12291236function bbp_is_topic_trash( $topic_id = 0 ) {
    1230     $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_trash_status_id();
     1237    $topic_id     = bbp_get_topic_id( $topic_id );
     1238    $status       = bbp_get_trash_status_id();
     1239    $topic_status = bbp_get_topic_status( $topic_id ) === $status;
     1240
    12311241    return (bool) apply_filters( 'bbp_is_topic_trash', (bool) $topic_status, $topic_id );
    12321242}
     
    12441254 */
    12451255function bbp_is_topic_pending( $topic_id = 0 ) {
    1246     $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_pending_status_id();
     1256    $topic_id     = bbp_get_topic_id( $topic_id );
     1257    $status       = bbp_get_pending_status_id();
     1258    $topic_status = bbp_get_topic_status( $topic_id ) === $status;
     1259
    12471260    return (bool) apply_filters( 'bbp_is_topic_pending', (bool) $topic_status, $topic_id );
    12481261}
     
    12601273 */
    12611274function bbp_is_topic_private( $topic_id = 0 ) {
    1262     $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_private_status_id();
     1275    $topic_id     = bbp_get_topic_id( $topic_id );
     1276    $status       = bbp_get_private_status_id();
     1277    $topic_status = bbp_get_topic_status( $topic_id ) === $status;
     1278
    12631279    return (bool) apply_filters( 'bbp_is_topic_private', (bool) $topic_status, $topic_id );
    12641280}
     
    15361552            // Tweak link title if empty
    15371553            if ( empty( $r['link_title'] ) ) {
    1538                 $link_title = sprintf( empty( $anonymous ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_topic_author_display_name( $topic_id ) );
     1554                $title      = empty( $anonymous ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' );
     1555                $author     = bbp_get_topic_author_display_name( $topic_id );
     1556                $link_title = sprintf( $title, $author );
    15391557
    15401558            // Use what was passed if not
     
    17211739        ), 'get_topic_author_role' );
    17221740
    1723         $topic_id    = bbp_get_topic_id( $r['topic_id'] );
    1724         $role        = bbp_get_user_display_role( bbp_get_topic_author_id( $topic_id ) );
     1741        $topic_id = bbp_get_topic_id( $r['topic_id'] );
     1742        $role     = bbp_get_user_display_role( bbp_get_topic_author_id( $topic_id ) );
    17251743
    17261744        // Backwards compatibilty with old 'class' argument
     
    19101928            'before'      => '&nbsp;|&nbsp;',
    19111929            'after'       => '',
    1912             'subscribe'   => __( 'Subscribe',   'bbpress' ),
    1913             'unsubscribe' => __( 'Unsubscribe', 'bbpress' )
    1914         ), 'get_forum_subscribe_link' );
     1930            'subscribe'   => esc_html__( 'Subscribe',   'bbpress' ),
     1931            'unsubscribe' => esc_html__( 'Unsubscribe', 'bbpress' )
     1932        ), 'get_topic_subscribe_link' );
    19151933
    19161934        // Get the link
    19171935        $retval = bbp_get_user_subscribe_link( $r );
    19181936
    1919         return apply_filters( 'bbp_get_topic_subscribe_link', $retval, $r );
     1937        return apply_filters( 'bbp_get_topic_subscribe_link', $retval, $r, $args );
    19201938    }
    19211939
     
    19551973            'before'    => '',
    19561974            'after'     => '',
    1957             'favorite'  => __( 'Favorite',   'bbpress' ),
    1958             'favorited' => __( 'Unfavorite', 'bbpress' )
    1959         ), 'get_forum_favorite_link' );
     1975            'favorite'  => esc_html__( 'Favorite',   'bbpress' ),
     1976            'favorited' => esc_html__( 'Unfavorite', 'bbpress' )
     1977        ), 'get_topic_favorite_link' );
    19601978
    19611979        // Get the link
    19621980        $retval = bbp_get_user_favorites_link( $r );
    19631981
    1964         return apply_filters( 'bbp_get_topic_favorite_link', $retval, $r );
     1982        return apply_filters( 'bbp_get_topic_favorite_link', $retval, $r, $args );
    19651983    }
    19661984
     
    20232041    function bbp_get_topic_last_reply_title( $topic_id = 0 ) {
    20242042        $topic_id = bbp_get_topic_id( $topic_id );
    2025         return apply_filters( 'bbp_get_topic_last_topic_title', bbp_get_reply_title( bbp_get_topic_last_reply_id( $topic_id ) ), $topic_id );
     2043        $reply_id = bbp_get_topic_last_reply_id( $topic_id );
     2044        $retval   = bbp_get_reply_title( $reply_id );
     2045
     2046        return apply_filters( 'bbp_get_topic_last_topic_title', $retval, $topic_id, $reply_id );
    20262047    }
    20272048
     
    20522073    function bbp_get_topic_last_reply_permalink( $topic_id = 0 ) {
    20532074        $topic_id = bbp_get_topic_id( $topic_id );
    2054         return apply_filters( 'bbp_get_topic_last_reply_permalink', bbp_get_reply_permalink( bbp_get_topic_last_reply_id( $topic_id ) ) );
     2075        $reply_id = bbp_get_topic_last_reply_id( $topic_id );
     2076        $retval   = bbp_get_reply_permalink( $reply_id );
     2077
     2078        return apply_filters( 'bbp_get_topic_last_reply_permalink', $retval, $topic_id, $reply_id );
    20552079    }
    20562080
     
    20902114        }
    20912115
    2092         return apply_filters( 'bbp_get_topic_last_reply_url', $reply_url );
     2116        return apply_filters( 'bbp_get_topic_last_reply_url', $reply_url, $topic_id, $reply_id );
    20932117    }
    20942118
     
    21292153            $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
    21302154        } else {
    2131             $anchor = __( 'No Replies', 'bbpress' );
     2155            $anchor = esc_html__( 'No Replies', 'bbpress' );
    21322156        }
    21332157
     
    21872211
    21882212            // Extra text
    2189             $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted );
     2213            $extra = sprintf( esc_html__( ' (+ %d hidden)', 'bbpress' ), $deleted );
    21902214
    21912215            // No link
     
    24792503
    24802504        // Parse arguments against default values
    2481         $r = bbp_parse_args( $args, array (
     2505        $r = bbp_parse_args( $args, array(
    24822506            'id'     => bbp_get_topic_id(),
    24832507            'before' => '<span class="bbp-admin-links">',
     
    27582782            'link_after'  => '',
    27592783            'sep'         => ' | ',
    2760             'close_text'  => _x( 'Close', 'Topic Status', 'bbpress' ),
    2761             'open_text'   => _x( 'Open',  'Topic Status', 'bbpress' )
     2784            'close_text'  => esc_html_x( 'Close', 'Topic Status', 'bbpress' ),
     2785            'open_text'   => esc_html_x( 'Open',  'Topic Status', 'bbpress' )
    27622786        ), 'get_topic_close_link' );
    27632787
     
    28192843            'link_after'     => '',
    28202844            'sep'            => ' | ',
    2821             'approve_text'   => _x( 'Approve',   'Pending Status', 'bbpress' ),
    2822             'unapprove_text' => _x( 'Unapprove', 'Pending Status', 'bbpress' )
     2845            'approve_text'   => esc_html_x( 'Approve',   'Pending Status', 'bbpress' ),
     2846            'unapprove_text' => esc_html_x( 'Unapprove', 'Pending Status', 'bbpress' )
    28232847        ), 'get_topic_approve_link' );
    28242848
     
    30893113 */
    30903114function bbp_forum_pagination_count() {
    3091     echo bbp_get_forum_pagination_count();
     3115    echo esc_html( bbp_get_forum_pagination_count() );
    30923116}
    30933117    /**
     
    31253149
    31263150        // Filter and return
    3127         return apply_filters( 'bbp_get_forum_pagination_count', esc_html( $retstr ) );
     3151        return apply_filters( 'bbp_get_forum_pagination_count', $retstr );
    31283152    }
    31293153
     
    33093333
    33103334        // Return the results
    3311         return apply_filters( 'bbp_get_form_topic_type_dropdown', ob_get_clean(), $r );
     3335        return apply_filters( 'bbp_get_form_topic_type_dropdown', ob_get_clean(), $r, $args );
    33123336    }
    33133337
     
    33923416
    33933417        // Return the results
    3394         return apply_filters( 'bbp_get_form_topic_status_dropdown', ob_get_clean(), $r );
     3418        return apply_filters( 'bbp_get_form_topic_status_dropdown', ob_get_clean(), $r, $args );
    33953419    }
    33963420
     
    34773501
    34783502        // Return filtered result
    3479         return apply_filters( 'bbp_get_single_topic_description', $retstr, $r );
     3503        return apply_filters( 'bbp_get_single_topic_description', $retstr, $r, $args );
    34803504    }
    34813505
     
    35823606        }
    35833607
    3584         return (int) apply_filters( 'bbp_get_topic_tag_id', (int) $retval, $tag );
     3608        return (int) apply_filters( 'bbp_get_topic_tag_id', (int) $retval, $tag, $term );
    35853609    }
    35863610
     
    36263650        }
    36273651
    3628         return apply_filters( 'bbp_get_topic_tag_name', $retval );
     3652        return apply_filters( 'bbp_get_topic_tag_name', $retval, $tag, $term );
    36293653    }
    36303654
     
    36703694        }
    36713695
    3672         return apply_filters( 'bbp_get_topic_tag_slug', $retval );
     3696        return apply_filters( 'bbp_get_topic_tag_slug', $retval, $tag, $term );
    36733697    }
    36743698
     
    37143738        }
    37153739
    3716         return apply_filters( 'bbp_get_topic_tag_link', $retval, $tag );
     3740        return apply_filters( 'bbp_get_topic_tag_link', $retval, $tag, $term );
    37173741    }
    37183742
     
    37673791        }
    37683792
    3769         return apply_filters( 'bbp_get_topic_tag_edit_link', $retval, $tag );
     3793        return apply_filters( 'bbp_get_topic_tag_edit_link', $retval, $tag, $term );
    37703794    }
    37713795
     
    38203844        }
    38213845
    3822         return apply_filters( 'bbp_get_topic_tag_description', $retval, $r );
     3846        return apply_filters( 'bbp_get_topic_tag_description', $retval, $r, $args, $tag, $term );
    38233847    }
    38243848
Note: See TracChangeset for help on using the changeset viewer.