Skip to:
Content

bbPress.org

Changeset 6354


Ignore:
Timestamp:
03/03/2017 03:58:52 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Hidden: Revert part of r6303, and improve some surrounding code:

  • Tiny function-call optimizations
  • Use integers for _n() and formatted strings for output
  • Type casting, phpdoc, and code formatting improvements

Fixes #3077.

Location:
trunk/src/includes
Files:
2 edited

Legend:

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

    r6352 r6354  
    12691269     * @param int $forum_id Optional. Topic id
    12701270     * @uses bbp_get_forum_id() To get the forum id
    1271      * @uses bbp_get_forum() To get the forum
     1271     * @uses bbp_get_forum_permalink() To get the forum permalink
    12721272     * @uses bbp_get_forum_topic_count() To get the forum topic count
    1273      * @uses bbp_get_forum_permalink() To get the forum permalink
    12741273     * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden
    12751274     *                                           topic count
     
    12801279     */
    12811280    function bbp_get_forum_topics_link( $forum_id = 0 ) {
    1282         $forum    = bbp_get_forum( $forum_id );
    1283         $forum_id = $forum->ID;
    1284         $topics   = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, false ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id ) );
    1285         $retval   = '';
     1281        $forum_id = bbp_get_forum_id( $forum_id );
     1282        $link     = bbp_get_forum_permalink( $forum_id );
     1283        $topics   = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, true ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id, true, false ) );
    12861284
    12871285        // First link never has view=all
    1288         if ( bbp_get_view_all( 'edit_others_topics' ) ) {
    1289             $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_forum_permalink( $forum_id ) ) ) . "'>" . esc_html( $topics ) . "</a>";
    1290         } else {
    1291             $retval .= esc_html( $topics );
    1292         }
     1286        $retval = bbp_get_view_all( 'edit_others_topics' )
     1287            ? "<a href='" . esc_url( bbp_remove_view_all( $link ) ) . "'>" . esc_html( $topics ) . "</a>"
     1288            : esc_html( $topics );
    12931289
    12941290        // Get deleted topics
    1295         $deleted = bbp_get_forum_topic_count_hidden( $forum_id );
     1291        $deleted_int = bbp_get_forum_topic_count_hidden( $forum_id, true );
    12961292
    12971293        // This forum has hidden topics
    1298         if ( ! empty( $deleted ) && current_user_can( 'edit_others_topics' ) ) {
    1299 
    1300             // Extra text
    1301             $extra = ' ' . sprintf( _n( '(%d hidden)', '(%d hidden)', $deleted, 'bbpress' ), $deleted );
    1302 
    1303             // No link
    1304             if ( bbp_get_view_all() ) {
    1305                 $retval .= " $extra";
    1306 
    1307             // Link
    1308             } else {
    1309                 $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_forum_permalink( $forum_id ), true ) ) . "'>" . esc_html( $extra ) . "</a>";
    1310             }
     1294        if ( ! empty( $deleted_int ) && current_user_can( 'edit_others_topics' ) ) {
     1295
     1296            // Hidden text
     1297            $deleted_num = bbp_get_forum_topic_count_hidden( $forum_id, false );
     1298            $extra       = ' ' . sprintf( _n( '(+%s hidden)', '(+%s hidden)', $deleted_int, 'bbpress' ), $deleted_num );
     1299
     1300            // Hidden link
     1301            $retval .= ! bbp_get_view_all()
     1302                ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . "</a>"
     1303                : " {$extra}";
    13111304        }
    13121305
  • trunk/src/includes/topics/template.php

    r6352 r6354  
    22112211     * @param int $topic_id Optional. Topic id
    22122212     * @uses bbp_get_topic_id() To get the topic id
    2213      * @uses bbp_get_topic() To get the topic
     2213     * @uses bbp_get_topic_permalink() To get the topic permalink
    22142214     * @uses bbp_get_topic_reply_count() To get the topic reply count
    2215      * @uses bbp_get_topic_permalink() To get the topic permalink
    22162215     * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden
    22172216     *                                           reply count
     
    22222221     */
    22232222    function bbp_get_topic_replies_link( $topic_id = 0 ) {
    2224 
    2225         $topic    = bbp_get_topic( $topic_id );
    2226         $topic_id = $topic->ID;
    2227         $replies  = sprintf( _n( '%s reply', '%s replies', bbp_get_topic_reply_count( $topic_id, true ), 'bbpress' ), bbp_get_topic_reply_count( $topic_id ) );
    2228         $retval   = '';
     2223        $topic_id = bbp_get_topic_id( $topic_id );
     2224        $link     = bbp_get_topic_permalink( $topic_id );
     2225        $replies  = sprintf( _n( '%s reply', '%s replies', bbp_get_topic_reply_count( $topic_id, true ), 'bbpress' ), bbp_get_topic_reply_count( $topic_id, false ) );
    22292226
    22302227        // First link never has view=all
    2231         if ( bbp_get_view_all( 'edit_others_replies' ) ) {
    2232             $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_topic_permalink( $topic_id ) ) ) . "'>" . esc_html( $replies ) . "</a>";
    2233         } else {
    2234             $retval .= $replies;
    2235         }
     2228        $retval = bbp_get_view_all( 'edit_others_replies' )
     2229            ? "<a href='" . esc_url( bbp_remove_view_all( $link ) ) . "'>" . esc_html( $replies ) . "</a>"
     2230            : $replies;
    22362231
    22372232        // Any deleted replies?
    2238         $deleted = bbp_get_topic_reply_count_hidden( $topic_id );
    2239 
    2240         // This forum has hidden topics
    2241         if ( ! empty( $deleted ) && current_user_can( 'edit_others_replies' ) ) {
    2242 
    2243             // Extra text
    2244             $extra = ' ' . sprintf( _n( '(%d hidden)', '(%d hidden)', $deleted, 'bbpress' ), $deleted );
    2245 
    2246             // No link
    2247             if ( bbp_get_view_all() ) {
    2248                 $retval .= " $extra";
    2249 
    2250             // Link
    2251             } else {
    2252                 $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_topic_permalink( $topic_id ), true ) ) . "'>" . esc_html( $extra ) . "</a>";
    2253             }
     2233        $deleted_int = bbp_get_topic_reply_count_hidden( $topic_id, true  );
     2234
     2235        // This topic has hidden replies
     2236        if ( ! empty( $deleted_int ) && current_user_can( 'edit_others_replies' ) ) {
     2237
     2238            // Hidden replies
     2239            $deleted_num = bbp_get_topic_reply_count_hidden( $topic_id, false );
     2240            $extra       = ' ' . sprintf( _n( '(+%s hidden)', '(+%s hidden)', $deleted_int, 'bbpress' ), $deleted_num );
     2241
     2242            // Hidden link
     2243            $retval .= ! bbp_get_view_all()
     2244                ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . "</a>"
     2245                : " {$extra}";
    22542246        }
    22552247
Note: See TracChangeset for help on using the changeset viewer.