Make WordPress Core

source: tags/3.3.2/wp-admin/includes/class-wp-ms-sites-list-table.php

Last change on this file was 18871, checked in by ryan, 13 years ago

Consolidate larg network criteria into wp_is_large_network(). Allow plugins to change this criteria via filter. Props PeteMall. fixes #18464

  • Property svn:eol-style set to native
File size: 12.8 KB
Line 
1<?php
2/**
3 * Sites List Table class.
4 *
5 * @package WordPress
6 * @subpackage List_Table
7 * @since 3.1.0
8 * @access private
9 */
10class WP_MS_Sites_List_Table extends WP_List_Table {
11
12        function __construct() {
13                parent::__construct( array(
14                        'plural' => 'sites',
15                ) );
16        }
17
18        function ajax_user_can() {
19                return current_user_can( 'manage_sites' );
20        }
21
22        function prepare_items() {
23                global $s, $mode, $wpdb, $current_site;
24
25                $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode'];
26
27                $per_page = $this->get_items_per_page( 'sites_network_per_page' );
28
29                $pagenum = $this->get_pagenum();
30
31                $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
32                $wild = '';
33                if ( false !== strpos($s, '*') ) {
34                        $wild = '%';
35                        $s = trim($s, '*');
36                }
37
38                $like_s = esc_sql( like_escape( $s ) );
39
40                // If the network is large and a search is not being performed, show only the latest blogs with no paging in order
41                // to avoid expensive count queries.
42                if ( !$s && wp_is_large_network() ) {
43                        if ( !isset($_REQUEST['orderby']) )
44                                $_GET['orderby'] = $_REQUEST['orderby'] = '';
45                        if ( !isset($_REQUEST['order']) )
46                                $_GET['order'] = $_REQUEST['order'] = 'DESC';
47                }
48
49                $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
50
51                if ( empty($s) ) {
52                        // Nothing to do.
53                } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
54                                        preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
55                                        preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
56                                        preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
57                        // IPv4 address
58                        $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" );
59
60                        if ( !$reg_blog_ids )
61                                $reg_blog_ids = array( 0 );
62
63                        $query = "SELECT *
64                                FROM {$wpdb->blogs}
65                                WHERE site_id = '{$wpdb->siteid}'
66                                AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
67                } else {
68                        if ( is_numeric($s) && empty( $wild ) ) {
69                                $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )";
70                        } elseif ( is_subdomain_install() ) {
71                                $blog_s = str_replace( '.' . $current_site->domain, '', $like_s );
72                                $blog_s .= $wild . '.' . $current_site->domain;
73                                $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) ";
74                        } else {
75                                if ( $like_s != trim('/', $current_site->path) )
76                                        $blog_s = $current_site->path . $like_s . $wild . '/';
77                                else
78                                        $blog_s = $like_s;
79                                $query .= " AND  ( {$wpdb->blogs}.path LIKE '$blog_s' )";
80                        }
81                }
82
83                $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
84                if ( $order_by == 'registered' ) {
85                        $query .= ' ORDER BY registered ';
86                } elseif ( $order_by == 'lastupdated' ) {
87                        $query .= ' ORDER BY last_updated ';
88                } elseif ( $order_by == 'blogname' ) {
89                        if ( is_subdomain_install() )
90                                $query .= ' ORDER BY domain ';
91                        else
92                                $query .= ' ORDER BY path ';
93                } elseif ( $order_by == 'blog_id' ) {
94                        $query .= ' ORDER BY blog_id ';
95                } else {
96                        $order_by = null;
97                }
98
99                if ( isset( $order_by ) ) {
100                        $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
101                        $query .= $order;
102                }
103
104                // Don't do an unbounded count on large networks
105                if ( ! wp_is_large_network() )
106                        $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
107
108                $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
109                $this->items = $wpdb->get_results( $query, ARRAY_A );
110
111                if ( wp_is_large_network() )
112                        $total = count($this->items);
113
114                $this->set_pagination_args( array(
115                        'total_items' => $total,
116                        'per_page' => $per_page,
117                ) );
118        }
119
120        function no_items() {
121                _e( 'No sites found.' );
122        }
123
124        function get_bulk_actions() {
125                $actions = array();
126                if ( current_user_can( 'delete_sites' ) )
127                        $actions['delete'] = __( 'Delete' );
128                $actions['spam'] = _x( 'Mark as Spam', 'site' );
129                $actions['notspam'] = _x( 'Not Spam', 'site' );
130
131                return $actions;
132        }
133
134        function pagination( $which ) {
135                global $mode;
136
137                parent::pagination( $which );
138
139                if ( 'top' == $which )
140                        $this->view_switcher( $mode );
141        }
142
143        function get_columns() {
144                $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
145                $sites_columns = array(
146                        'cb'          => '<input type="checkbox" />',
147                        'blogname'    => $blogname_columns,
148                        'lastupdated' => __( 'Last Updated' ),
149                        'registered'  => _x( 'Registered', 'site' ),
150                        'users'       => __( 'Users' )
151                );
152
153                if ( has_filter( 'wpmublogsaction' ) )
154                        $sites_columns['plugins'] = __( 'Actions' );
155
156                $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
157
158                return $sites_columns;
159        }
160
161        function get_sortable_columns() {
162                return array(
163                        'blogname'    => 'blogname',
164                        'lastupdated' => 'lastupdated',
165                        'registered'  => 'blog_id',
166                );
167        }
168
169        function display_rows() {
170                global $current_site, $mode;
171
172                $status_list = array(
173                        'archived' => array( 'site-archived', __( 'Archived' ) ),
174                        'spam'     => array( 'site-spammed', _x( 'Spam', 'site' ) ),
175                        'deleted'  => array( 'site-deleted', __( 'Deleted' ) ),
176                        'mature'   => array( 'site-mature', __( 'Mature' ) )
177                );
178
179                $class = '';
180                foreach ( $this->items as $blog ) {
181                        $class = ( 'alternate' == $class ) ? '' : 'alternate';
182                        reset( $status_list );
183
184                        $blog_states = array();
185                        foreach ( $status_list as $status => $col ) {
186                                if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
187                                        $class = $col[0];
188                                        $blog_states[] = $col[1];
189                                }
190                        }
191                        $blog_state = '';
192                        if ( ! empty( $blog_states ) ) {
193                                $state_count = count( $blog_states );
194                                $i = 0;
195                                $blog_state .= ' - ';
196                                foreach ( $blog_states as $state ) {
197                                        ++$i;
198                                        ( $i == $state_count ) ? $sep = '' : $sep = ', ';
199                                        $blog_state .= "<span class='post-state'>$state$sep</span>";
200                                }
201                        }
202                        echo "<tr class='$class'>";
203
204                        $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
205
206                        list( $columns, $hidden ) = $this->get_column_info();
207
208                        foreach ( $columns as $column_name => $column_display_name ) {
209                                $style = '';
210                                if ( in_array( $column_name, $hidden ) )
211                                        $style = ' style="display:none;"';
212
213                                switch ( $column_name ) {
214                                        case 'cb': ?>
215                                                <th scope="row" class="check-column">
216                                                        <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
217                                                </th>
218                                        <?php
219                                        break;
220
221                                        case 'id':?>
222                                                <th valign="top" scope="row">
223                                                        <?php echo $blog['blog_id'] ?>
224                                                </th>
225                                        <?php
226                                        break;
227
228                                        case 'blogname':
229                                                echo "<td class='column-$column_name $column_name'$style>"; ?>
230                                                        <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
231                                                        <?php
232                                                        if ( 'list' != $mode )
233                                                                echo '<p>' . sprintf( _x( '%1$s &#8211; <em>%2$s</em>', '%1$s: site name. %2$s: site tagline.' ), get_blog_option( $blog['blog_id'], 'blogname' ), get_blog_option( $blog['blog_id'], 'blogdescription ' ) ) . '</p>';
234
235                                                        // Preordered.
236                                                        $actions = array(
237                                                                'edit' => '', 'backend' => '',
238                                                                'activate' => '', 'deactivate' => '',
239                                                                'archive' => '', 'unarchive' => '',
240                                                                'spam' => '', 'unspam' => '',
241                                                                'delete' => '',
242                                                                'visit' => '',
243                                                        );
244
245                                                        $actions['edit']        = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
246                                                        $actions['backend']     = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>';
247                                                        if ( $current_site->blog_id != $blog['blog_id'] ) {
248                                                                if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
249                                                                        $actions['activate']    = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Activate' ) . '</a></span>';
250                                                                else
251                                                                        $actions['deactivate']  = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to deactivate the site %s' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Deactivate' ) . '</a></span>';
252
253                                                                if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
254                                                                        $actions['unarchive']   = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' .  $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unarchive the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Unarchive' ) . '</a></span>';
255                                                                else
256                                                                        $actions['archive']     = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to archive the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Archive', 'verb; site' ) . '</a></span>';
257
258                                                                if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
259                                                                        $actions['unspam']      = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unspam the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Not Spam', 'site' ) . '</a></span>';
260                                                                else
261                                                                        $actions['spam']        = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to mark the site %s as spam.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Spam', 'site' ) . '</a></span>';
262
263                                                                if ( current_user_can( 'delete_site', $blog['blog_id'] ) )
264                                                                        $actions['delete']      = '<span class="delete"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Delete' ) . '</a></span>';
265                                                        }
266
267                                                        $actions['visit']       = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'] ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
268
269                                                        $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
270                                                        echo $this->row_actions( $actions );
271                                        ?>
272                                                </td>
273                                        <?php
274                                        break;
275
276                                        case 'lastupdated':
277                                                echo "<td valign='top' class='$column_name column-$column_name'$style>";
278                                                        if ( 'list' == $mode )
279                                                                $date = 'Y/m/d';
280                                                        else
281                                                                $date = 'Y/m/d \<\b\r \/\> g:i:s a';
282                                                        echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?>
283                                                </td>
284                                        <?php
285                                        break;
286                                case 'registered':
287                                                echo "<td valign='top' class='$column_name column-$column_name'$style>";
288                                                if ( $blog['registered'] == '0000-00-00 00:00:00' )
289                                                        echo '&#x2014;';
290                                                else
291                                                        echo mysql2date( $date, $blog['registered'] );
292                                                ?>
293                                                </td>
294                                        <?php
295                                        break;
296                                case 'users':
297                                                echo "<td valign='top' class='$column_name column-$column_name'$style>";
298                                                        $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) );
299                                                        if ( is_array( $blogusers ) ) {
300                                                                $blogusers_warning = '';
301                                                                if ( count( $blogusers ) > 5 ) {
302                                                                        $blogusers = array_slice( $blogusers, 0, 5 );
303                                                                        $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>';
304                                                                }
305                                                                foreach ( $blogusers as $user_object ) {
306                                                                        echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
307                                                                        if ( 'list' != $mode )
308                                                                                echo '( ' . $user_object->user_email . ' )';
309                                                                        echo '<br />';
310                                                                }
311                                                                if ( $blogusers_warning != '' )
312                                                                        echo '<strong>' . $blogusers_warning . '</strong><br />';
313                                                        }
314                                                        ?>
315                                                </td>
316                                        <?php
317                                        break;
318
319                                case 'plugins': ?>
320                                        <?php if ( has_filter( 'wpmublogsaction' ) ) {
321                                        echo "<td valign='top' class='$column_name column-$column_name'$style>";
322                                                do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
323                                        </td>
324                                        <?php }
325                                        break;
326
327                                default:
328                                        echo "<td class='$column_name column-$column_name'$style>";
329                                        do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
330                                        echo "</td>";
331                                        break;
332                                }
333                        }
334                        ?>
335                        </tr>
336                        <?php
337                }
338        }
339}
340
341?>
Note: See TracBrowser for help on using the repository browser.