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