Skip to:
Content

bbPress.org

Changeset 4480


Ignore:
Timestamp:
11/23/2012 10:50:13 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Extract:

  • Remove extract() calls from some statistics functions.
  • See #2056.
Location:
trunk/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/admin/metaboxes.php

    r4438 r4480  
    3636
    3737        // Get the statistics and extract them
    38         extract( bbp_get_statistics(), EXTR_SKIP ); ?>
     38        $r = bbp_get_statistics(); ?>
    3939
    4040        <div class="table table_content">
    … …  
    4747
    4848                                <?php
    49                                         $num  = $forum_count;
    50                                         $text = _n( 'Forum', 'Forums', $forum_count, 'bbpress' );
     49                                        $num  = $r['forum_count'];
     50                                        $text = _n( 'Forum', 'Forums', $r['forum_count'], 'bbpress' );
    5151                                        if ( current_user_can( 'publish_forums' ) ) {
    5252                                                $link = add_query_arg( array( 'post_type' => bbp_get_forum_post_type() ), get_admin_url( null, 'edit.php' ) );
    … …  
    6464
    6565                                <?php
    66                                         $num  = $topic_count;
    67                                         $text = _n( 'Topic', 'Topics', $topic_count, 'bbpress' );
     66                                        $num  = $r['topic_count'];
     67                                        $text = _n( 'Topic', 'Topics', $r['topic_count'], 'bbpress' );
    6868                                        if ( current_user_can( 'publish_topics' ) ) {
    6969                                                $link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), get_admin_url( null, 'edit.php' ) );
    … …  
    8181
    8282                                <?php
    83                                         $num  = $reply_count;
    84                                         $text = _n( 'Reply', 'Replies', $reply_count, 'bbpress' );
     83                                        $num  = $r['reply_count'];
     84                                        $text = _n( 'Reply', 'Replies', $r['reply_count'], 'bbpress' );
    8585                                        if ( current_user_can( 'publish_replies' ) ) {
    8686                                                $link = add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), get_admin_url( null, 'edit.php' ) );
    … …  
    100100
    101101                                        <?php
    102                                                 $num  = $topic_tag_count;
    103                                                 $text = _n( 'Topic Tag', 'Topic Tags', $topic_tag_count, 'bbpress' );
     102                                                $num  = $r['topic_tag_count'];
     103                                                $text = _n( 'Topic Tag', 'Topic Tags', $r['topic_tag_count'], 'bbpress' );
    104104                                                if ( current_user_can( 'manage_topic_tags' ) ) {
    105105                                                        $link = add_query_arg( array( 'taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type() ), get_admin_url( null, 'edit-tags.php' ) );
    … …  
    132132
    133133                                <?php
    134                                         $num  = $user_count;
    135                                         $text = _n( 'User', 'Users', $user_count, 'bbpress' );
     134                                        $num  = $r['user_count'];
     135                                        $text = _n( 'User', 'Users', $r['user_count'], 'bbpress' );
    136136                                        if ( current_user_can( 'edit_users' ) ) {
    137137                                                $link = get_admin_url( null, 'users.php' );
    … …  
    146146                        </tr>
    147147
    148                         <?php if ( isset( $topic_count_hidden ) ) : ?>
     148                        <?php if ( isset( $r['topic_count_hidden'] ) ) : ?>
    149149
    150150                                <tr>
    151151
    152152                                        <?php
    153                                                 $num  = $topic_count_hidden;
    154                                                 $text = _n( 'Hidden Topic', 'Hidden Topics', $topic_count_hidden, 'bbpress' );
     153                                                $num  = $r['topic_count_hidden'];
     154                                                $text = _n( 'Hidden Topic', 'Hidden Topics', $r['topic_count_hidden'], 'bbpress' );
    155155                                                $link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), get_admin_url( null, 'edit.php' ) );
    156156                                                if ( '0' != $num ) {
    157157                                                        $link = add_query_arg( array( 'post_status' => bbp_get_spam_status_id() ), $link );
    158158                                                }
    159                         $num  = '<a href="' . $link . '" title="' . esc_attr( $hidden_topic_title ) . '">' . $num  . '</a>';
    160                                                 $text = '<a class="waiting" href="' . $link . '" title="' . esc_attr( $hidden_topic_title ) . '">' . $text . '</a>';
     159                        $num  = '<a href="' . $link . '" title="' . esc_attr( $r['hidden_topic_title'] ) . '">' . $num  . '</a>';
     160                                                $text = '<a class="waiting" href="' . $link . '" title="' . esc_attr( $r['hidden_topic_title'] ) . '">' . $text . '</a>';
    161161                                        ?>
    162162
    … …  
    168168                        <?php endif; ?>
    169169
    170                         <?php if ( isset( $reply_count_hidden ) ) : ?>
     170                        <?php if ( isset( $r['reply_count_hidden'] ) ) : ?>
    171171
    172172                                <tr>
    173173
    174174                                        <?php
    175                                                 $num  = $reply_count_hidden;
    176                                                 $text = _n( 'Hidden Reply', 'Hidden Replies', $reply_count_hidden, 'bbpress' );
     175                                                $num  = $r['reply_count_hidden'];
     176                                                $text = _n( 'Hidden Reply', 'Hidden Replies', $r['reply_count_hidden'], 'bbpress' );
    177177                                                $link = add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), get_admin_url( null, 'edit.php' ) );
    178178                                                if ( '0' != $num ) {
    179179                                                        $link = add_query_arg( array( 'post_status' => bbp_get_spam_status_id() ), $link );
    180180                                                }
    181                         $num  = '<a href="' . $link . '" title="' . esc_attr( $hidden_reply_title ) . '">' . $num  . '</a>';
    182                                                 $text = '<a class="waiting" href="' . $link . '" title="' . esc_attr( $hidden_reply_title ) . '">' . $text . '</a>';
     181                        $num  = '<a href="' . $link . '" title="' . esc_attr( $r['hidden_reply_title'] ) . '">' . $num  . '</a>';
     182                                                $text = '<a class="waiting" href="' . $link . '" title="' . esc_attr( $r['hidden_reply_title'] ) . '">' . $text . '</a>';
    183183                                        ?>
    184184
    … …  
    190190                        <?php endif; ?>
    191191
    192                         <?php if ( bbp_allow_topic_tags() && isset( $empty_topic_tag_count ) ) : ?>
     192                        <?php if ( bbp_allow_topic_tags() && isset( $r['empty_topic_tag_count'] ) ) : ?>
    193193
    194194                                <tr>
    195195
    196196                                        <?php
    197                                                 $num  = $empty_topic_tag_count;
    198                                                 $text = _n( 'Empty Topic Tag', 'Empty Topic Tags', $empty_topic_tag_count, 'bbpress' );
     197                                                $num  = $r['empty_topic_tag_count'];
     198                                                $text = _n( 'Empty Topic Tag', 'Empty Topic Tags', $r['empty_topic_tag_count'], 'bbpress' );
    199199                                                $link = add_query_arg( array( 'taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type() ), get_admin_url( null, 'edit-tags.php' ) );
    200200                                                $num  = '<a href="' . $link . '">' . $num  . '</a>';
  • trunk/includes/common/functions.php

    r4361 r4480  
    244244
    245245        // Are we appending the view=all vars?
    246         if ( bbp_get_view_all() || !empty( $force ) )
     246        if ( bbp_get_view_all() || !empty( $force ) ) {
    247247                $link = add_query_arg( array( 'view' => 'all' ), $original_link );
    248         else
     248        } else {
    249249                $link = $original_link;
     250        }
    250251
    251252        return apply_filters( 'bbp_add_view_all', $link, $original_link );
    … …  
    430431function bbp_get_statistics( $args = '' ) {
    431432
    432         $defaults = array (
     433        // Parse arguments
     434        $r = bbp_parse_args( $args, array(
    433435                'count_users'           => true,
    434436                'count_forums'          => true,
    … …  
    443445                'count_tags'            => true,
    444446                'count_empty_tags'      => true
    445         );
    446         $r = bbp_parse_args( $args, $defaults, 'get_statistics' );
    447         extract( $r );
     447        ), 'get_statistics' );
     448
     449        // Defaults
     450        $user_count            = 0;
     451        $forum_count           = 0;
     452        $topic_count           = 0;
     453        $topic_count_hidden    = 0;
     454        $reply_count           = 0;
     455        $reply_count_hidden    = 0;
     456        $topic_tag_count       = 0;
     457        $empty_topic_tag_count = 0;
    448458
    449459        // Users
    450         if ( !empty( $count_users ) )
     460        if ( !empty( $r['count_users'] ) ) {
    451461                $user_count = bbp_get_total_users();
     462        }
    452463
    453464        // Forums
    454         if ( !empty( $count_forums ) ) {
    455                 $forum_count = wp_count_posts( bbp_get_forum_post_type() );
    456                 $forum_count = $forum_count->publish;
     465        if ( !empty( $r['count_forums'] ) ) {
     466                $forum_count = wp_count_posts( bbp_get_forum_post_type() )->publish;
    457467        }
    458468
    … …  
    464474
    465475        // Topics
    466         if ( !empty( $count_topics ) ) {
    467 
     476        if ( !empty( $r['count_topics'] ) ) {
    468477                $all_topics  = wp_count_posts( bbp_get_topic_post_type() );
    469478
    … …  
    474483
    475484                        // Private
    476                         $topics['private'] = ( !empty( $count_private_topics ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->{$private} : 0;
     485                        $topics['private'] = ( !empty( $r['count_private_topics'] ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->{$private} : 0;
    477486
    478487                        // Spam
    479                         $topics['spammed'] = ( !empty( $count_spammed_topics ) && current_user_can( 'edit_others_topics'  ) ) ? (int) $all_topics->{$spam}    : 0;
     488                        $topics['spammed'] = ( !empty( $r['count_spammed_topics'] ) && current_user_can( 'edit_others_topics'  ) ) ? (int) $all_topics->{$spam}    : 0;
    480489
    481490                        // Trash
    482                         $topics['trashed'] = ( !empty( $count_trashed_topics ) && current_user_can( 'view_trash'          ) ) ? (int) $all_topics->{$trash}   : 0;
     491                        $topics['trashed'] = ( !empty( $r['count_trashed_topics'] ) && current_user_can( 'view_trash'          ) ) ? (int) $all_topics->{$trash}   : 0;
    483492
    484493                        // Total hidden (private + spam + trash)
    … …  
    496505
    497506        // Replies
    498         if ( !empty( $count_replies ) ) {
     507        if ( !empty( $r['count_replies'] ) ) {
    499508
    500509                $all_replies = wp_count_posts( bbp_get_reply_post_type() );
    … …  
    506515
    507516                        // Private
    508                         $replies['private'] = ( !empty( $count_private_replies ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->{$private} : 0;
     517                        $replies['private'] = ( !empty( $r['count_private_replies'] ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->{$private} : 0;
    509518
    510519                        // Spam
    511                         $replies['spammed'] = ( !empty( $count_spammed_replies ) && current_user_can( 'edit_others_replies'  ) ) ? (int) $all_replies->{$spam}    : 0;
     520                        $replies['spammed'] = ( !empty( $r['count_spammed_replies'] ) && current_user_can( 'edit_others_replies'  ) ) ? (int) $all_replies->{$spam}    : 0;
    512521
    513522                        // Trash
    514                         $replies['trashed'] = ( !empty( $count_trashed_replies ) && current_user_can( 'view_trash'           ) ) ? (int) $all_replies->{$trash}   : 0;
     523                        $replies['trashed'] = ( !empty( $r['count_trashed_replies'] ) && current_user_can( 'view_trash'           ) ) ? (int) $all_replies->{$trash}   : 0;
    515524
    516525                        // Total hidden (private + spam + trash)
    … …  
    529538
    530539        // Topic Tags
    531         if ( !empty( $count_tags ) && bbp_allow_topic_tags() ) {
     540        if ( !empty( $r['count_tags'] ) && bbp_allow_topic_tags() ) {
    532541
    533542                // Get the count
    … …  
    535544
    536545                // Empty tags
    537                 if ( !empty( $count_empty_tags ) && current_user_can( 'edit_topic_tags' ) ) {
     546                if ( !empty( $r['count_empty_tags'] ) && current_user_can( 'edit_topic_tags' ) ) {
    538547                        $empty_topic_tag_count = wp_count_terms( bbp_get_topic_tag_tax_id() ) - $topic_tag_count;
    539548                }
    … …  
    541550
    542551        // Tally the tallies
    543         $statistics = compact( 'user_count', 'forum_count', 'topic_count', 'topic_count_hidden', 'reply_count', 'reply_count_hidden', 'topic_tag_count', 'empty_topic_tag_count' );
    544         $statistics = array_map( 'absint',             $statistics );
    545         $statistics = array_map( 'number_format_i18n', $statistics );
    546 
     552        $statistics = array_map( 'number_format_i18n', array_map( 'absint', array(
     553                $user_count,
     554                $forum_count,
     555                $topic_count,
     556                $topic_count_hidden,
     557                $reply_count,
     558                $reply_count_hidden,
     559                $topic_tag_count,
     560                $empty_topic_tag_count
     561        ) ) );
     562       
    547563        // Add the hidden (topic/reply) count title attribute strings because we don't need to run the math functions on these (see above)
    548564        if ( isset( $hidden_topic_title ) )
Note: See TracChangeset for help on using the changeset viewer.