Make WordPress Core


Ignore:
Timestamp:
09/05/2010 09:26:27 PM (13 years ago)
Author:
scribu
Message:

introduce WP_List_Table::views(). See #14579

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/default-list-tables.php

    r15577 r15578  
    9595        else
    9696            echo $post_type_object->labels->not_found;
     97    }
     98
     99    function get_views() {
     100        global $post_type, $post_type_object, $locked_post_status, $avail_post_stati;
     101   
     102        if ( !empty($locked_post_status) )
     103            return array();
     104
     105        $status_links = array();
     106        $num_posts = wp_count_posts( $post_type, 'readable' );
     107        $class = '';
     108        $allposts = '';
     109
     110        $user_posts = false;
     111        if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
     112            $user_posts = true;
     113
     114            $user_posts_count = $wpdb->get_var( $wpdb->prepare( "
     115                SELECT COUNT( 1 ) FROM $wpdb->posts
     116                WHERE post_type = '%s' AND post_status NOT IN ( 'trash', 'auto-draft' )
     117                AND post_author = %d
     118            ", $post_type, get_current_user_id() ) );
     119
     120            if ( $user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) )
     121                $_REQUEST['author'] = get_current_user_id();
     122        }
     123
     124        if ( $user_posts ) {
     125            if ( isset( $_REQUEST['author'] ) && ( $_REQUEST['author'] == $current_user->ID ) )
     126                $class = ' class="current"';
     127            $status_links['author'] = "<li><a href='edit.php?post_type=$post_type&author=$current_user->ID'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $user_posts_count, 'posts' ), number_format_i18n( $user_posts_count ) ) . '</a>';
     128            $allposts = '&all_posts=1';
     129        }
     130
     131        $total_posts = array_sum( (array) $num_posts );
     132
     133        // Subtract post types that are not included in the admin all list.
     134        foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
     135            $total_posts -= $num_posts->$state;
     136
     137        $class = empty($class) && empty($_REQUEST['post_status']) ? ' class="current"' : '';
     138        $status_links['all'] = "<li><a href='edit.php?post_type=$post_type{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
     139
     140        foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
     141            $class = '';
     142
     143            $status_name = $status->name;
     144
     145            if ( !in_array( $status_name, $avail_post_stati ) )
     146                continue;
     147
     148            if ( empty( $num_posts->$status_name ) )
     149                continue;
     150
     151            if ( isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status'] )
     152                $class = ' class="current"';
     153
     154            $status_links[$status_name] = "<li><a href='edit.php?post_status=$status_name&amp;post_type=$post_type'$class>" . sprintf( _n( $status->label_count[0], $status->label_count[1], $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
     155        }
     156       
     157        return $status_links;
    97158    }
    98159
     
    9421003            'per_page' => $wp_query->query_vars['posts_per_page'],
    9431004        ) );
     1005    }
     1006
     1007    function get_views() {
     1008        global $wpdb, $post_mime_types, $detached, $avail_post_mime_types;
     1009
     1010        $type_links = array();
     1011        $_num_posts = (array) wp_count_attachments();
     1012        $_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
     1013        if ( !isset( $total_orphans ) )
     1014                $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
     1015        $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
     1016        foreach ( $matches as $type => $reals )
     1017            foreach ( $reals as $real )
     1018                $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
     1019
     1020        $class = ( empty($_GET['post_mime_type']) && !$detached && !isset($_GET['status']) ) ? ' class="current"' : '';
     1021        $type_links['all'] = "<li><a href='upload.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</a>';
     1022        foreach ( $post_mime_types as $mime_type => $label ) {
     1023            $class = '';
     1024
     1025            if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
     1026                continue;
     1027
     1028            if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
     1029                $class = ' class="current"';
     1030            if ( !empty( $num_posts[$mime_type] ) )
     1031                $type_links[$mime_type] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
     1032        }
     1033        $type_links['detached'] = '<li><a href="upload.php?detached=1"' . ( $detached ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>';
     1034
     1035        if ( !empty($_num_posts['trash']) )
     1036            $type_links['trash'] = '<li><a href="upload.php?status=trash"' . ( (isset($_GET['status']) && $_GET['status'] == 'trash' ) ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>';
     1037
     1038        return $type_links;
    9441039    }
    9451040
     
    16521747
    16531748    function WP_Users_Table() {
    1654         global $role, $usersearch;
    1655 
    16561749        parent::WP_List_Table( array(
    16571750            'screen' => 'users',
     
    16661759
    16671760    function prepare_items() {
     1761        global $role, $usersearch;
     1762
    16681763        $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    16691764
     
    17001795    function no_items() {
    17011796        _e( 'No matching users were found.' );
     1797    }
     1798
     1799    function get_views() {
     1800        global $wp_roles, $role;
     1801
     1802        $users_of_blog = count_users();
     1803        $total_users = $users_of_blog['total_users'];
     1804        $avail_roles =& $users_of_blog['avail_roles'];
     1805        unset($users_of_blog);
     1806
     1807        $current_role = false;
     1808        $class = empty($role) ? ' class="current"' : '';
     1809        $role_links = array();
     1810        $role_links['all'] = "<li><a href='users.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
     1811        foreach ( $wp_roles->get_names() as $this_role => $name ) {
     1812            if ( !isset($avail_roles[$this_role]) )
     1813                continue;
     1814
     1815            $class = '';
     1816
     1817            if ( $this_role == $role ) {
     1818                $current_role = $role;
     1819                $class = ' class="current"';
     1820            }
     1821
     1822            $name = translate_user_role( $name );
     1823            /* translators: User role name with count */
     1824            $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, $avail_roles[$this_role] );
     1825            $role_links[$this_role] = "<li><a href='users.php?role=$this_role'$class>$name</a>";
     1826        }
     1827
     1828        return $role_links;
    17021829    }
    17031830
     
    19562083            'per_page' => $comments_per_page,
    19572084        ) );
     2085    }
     2086
     2087    function get_views() {
     2088        global $post_id, $comment_status;
     2089
     2090        $status_links = array();
     2091        $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
     2092        //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
     2093        //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
     2094        $stati = array(
     2095                'all' => _nx_noop('All', 'All', 'comments'), // singular not used
     2096                'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>'),
     2097                'approved' => _n_noop('Approved', 'Approved'), // singular not used
     2098                'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>'),
     2099                'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>')
     2100            );
     2101
     2102        if ( !EMPTY_TRASH_DAYS )
     2103            unset($stati['trash']);
     2104
     2105        $link = 'edit-comments.php';
     2106        if ( !empty($comment_type) && 'all' != $comment_type )
     2107            $link = add_query_arg( 'comment_type', $comment_type, $link );
     2108
     2109        foreach ( $stati as $status => $label ) {
     2110            $class = ( $status == $comment_status ) ? ' class="current"' : '';
     2111
     2112            if ( !isset( $num_comments->$status ) )
     2113                $num_comments->$status = 10;
     2114            $link = add_query_arg( 'comment_status', $status, $link );
     2115            if ( $post_id )
     2116                $link = add_query_arg( 'p', absint( $post_id ), $link );
     2117            /*
     2118            // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
     2119            if ( !empty( $_REQUEST['s'] ) )
     2120                $link = add_query_arg( 's', esc_attr( stripslashes( $_REQUEST['s'] ) ), $link );
     2121            */
     2122            $status_links[$status] = "<li class='$status'><a href='$link'$class>" . sprintf(
     2123                _n( $label[0], $label[1], $num_comments->$status ),
     2124                number_format_i18n( $num_comments->$status )
     2125            ) . '</a>';
     2126        }
     2127
     2128        $status_links = apply_filters( 'comment_status_links', $status_links );
     2129        return $status_links;
    19582130    }
    19592131
     
    31703342    }
    31713343
     3344    function get_views() {
     3345        global $totals, $status;
     3346   
     3347        $status_links = array();
     3348        foreach ( $totals as $type => $count ) {
     3349            if ( !$count )
     3350                continue;
     3351
     3352            switch ( $type ) {
     3353                case 'all':
     3354                    $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
     3355                    break;
     3356                case 'active':
     3357                    $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
     3358                    break;
     3359                case 'recently_activated':
     3360                    $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
     3361                    break;
     3362                case 'inactive':
     3363                    $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
     3364                    break;
     3365                case 'network':
     3366                    $text = _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $count );
     3367                    break;
     3368                case 'mustuse':
     3369                    $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
     3370                    break;
     3371                case 'dropins':
     3372                    $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
     3373                    break;
     3374                case 'upgrade':
     3375                    $text = _n( 'Upgrade Available <span class="count">(%s)</span>', 'Upgrade Available <span class="count">(%s)</span>', $count );
     3376                    break;
     3377                case 'search':
     3378                    $text = _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $count );
     3379                    break;
     3380            }
     3381
     3382            $status_links[$type] = sprintf( "<li><a href='%s' %s>%s</a>",
     3383                add_query_arg('plugin_status', $type, 'plugins.php'),
     3384                ( $type == $status ) ? ' class="current"' : '',
     3385                sprintf( $text, number_format_i18n( $count ) )
     3386            );
     3387        }
     3388
     3389        return $status_links;
     3390    }
     3391
    31723392    function get_bulk_actions() {
    31733393        global $status;
     
    34283648    }
    34293649
     3650    function get_views() {
     3651        global $tabs, $tab;
     3652
     3653        $display_tabs = array();
     3654        foreach ( (array) $tabs as $action => $text ) {
     3655            $class = ( $action == $tab ) ? ' class="current"' : '';
     3656            $href = admin_url('plugin-install.php?tab=' . $action);
     3657            $display_tabs[$action] = "<a href='$href'$class>$text</a>";
     3658        }
     3659
     3660        return $display_tabs;
     3661    }
     3662
    34303663    function display_tablenav( $which ) {
    34313664        if ( 'top' ==  $which ) { ?>
     
    38004033        _e( 'No themes match your request.' );
    38014034    }
    3802    
     4035
     4036    function get_views() {
     4037        global $tabs, $tab;
     4038
     4039        $display_tabs = array();
     4040        foreach ( (array) $tabs as $action => $text ) {
     4041            $class = ( $action == $tab ) ? ' class="current"' : '';
     4042            $href = admin_url('theme-install.php?tab=' . $action);
     4043            $display_tabs[$action] = "<a href='$href'$class>$text</a>";
     4044        }
     4045
     4046        return $display_tabs;
     4047    }
     4048
    38034049    function get_columns() {
    38044050        return array();
Note: See TracChangeset for help on using the changeset viewer.