[ Index ] |
WordPress Cross Reference |
[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( $args = array() ) { 13 parent::__construct( array( 14 'plural' => 'sites', 15 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 16 ) ); 17 } 18 19 function ajax_user_can() { 20 return current_user_can( 'manage_sites' ); 21 } 22 23 function prepare_items() { 24 global $s, $mode, $wpdb; 25 26 $current_site = get_current_site(); 27 28 $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode']; 29 30 $per_page = $this->get_items_per_page( 'sites_network_per_page' ); 31 32 $pagenum = $this->get_pagenum(); 33 34 $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST[ 's' ] ) ) : ''; 35 $wild = ''; 36 if ( false !== strpos($s, '*') ) { 37 $wild = '%'; 38 $s = trim($s, '*'); 39 } 40 41 $like_s = esc_sql( like_escape( $s ) ); 42 43 // If the network is large and a search is not being performed, show only the latest blogs with no paging in order 44 // to avoid expensive count queries. 45 if ( !$s && wp_is_large_network() ) { 46 if ( !isset($_REQUEST['orderby']) ) 47 $_GET['orderby'] = $_REQUEST['orderby'] = ''; 48 if ( !isset($_REQUEST['order']) ) 49 $_GET['order'] = $_REQUEST['order'] = 'DESC'; 50 } 51 52 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' "; 53 54 if ( empty($s) ) { 55 // Nothing to do. 56 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || 57 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || 58 preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || 59 preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { 60 // IPv4 address 61 $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" ); 62 63 if ( !$reg_blog_ids ) 64 $reg_blog_ids = array( 0 ); 65 66 $query = "SELECT * 67 FROM {$wpdb->blogs} 68 WHERE site_id = '{$wpdb->siteid}' 69 AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")"; 70 } else { 71 if ( is_numeric($s) && empty( $wild ) ) { 72 $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )"; 73 } elseif ( is_subdomain_install() ) { 74 $blog_s = str_replace( '.' . $current_site->domain, '', $like_s ); 75 $blog_s .= $wild . '.' . $current_site->domain; 76 $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) "; 77 } else { 78 if ( $like_s != trim('/', $current_site->path) ) 79 $blog_s = $current_site->path . $like_s . $wild . '/'; 80 else 81 $blog_s = $like_s; 82 $query .= " AND ( {$wpdb->blogs}.path LIKE '$blog_s' )"; 83 } 84 } 85 86 $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : ''; 87 if ( $order_by == 'registered' ) { 88 $query .= ' ORDER BY registered '; 89 } elseif ( $order_by == 'lastupdated' ) { 90 $query .= ' ORDER BY last_updated '; 91 } elseif ( $order_by == 'blogname' ) { 92 if ( is_subdomain_install() ) 93 $query .= ' ORDER BY domain '; 94 else 95 $query .= ' ORDER BY path '; 96 } elseif ( $order_by == 'blog_id' ) { 97 $query .= ' ORDER BY blog_id '; 98 } else { 99 $order_by = null; 100 } 101 102 if ( isset( $order_by ) ) { 103 $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC"; 104 $query .= $order; 105 } 106 107 // Don't do an unbounded count on large networks 108 if ( ! wp_is_large_network() ) 109 $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) ); 110 111 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page ); 112 $this->items = $wpdb->get_results( $query, ARRAY_A ); 113 114 if ( wp_is_large_network() ) 115 $total = count($this->items); 116 117 $this->set_pagination_args( array( 118 'total_items' => $total, 119 'per_page' => $per_page, 120 ) ); 121 } 122 123 function no_items() { 124 _e( 'No sites found.' ); 125 } 126 127 function get_bulk_actions() { 128 $actions = array(); 129 if ( current_user_can( 'delete_sites' ) ) 130 $actions['delete'] = __( 'Delete' ); 131 $actions['spam'] = _x( 'Mark as Spam', 'site' ); 132 $actions['notspam'] = _x( 'Not Spam', 'site' ); 133 134 return $actions; 135 } 136 137 function pagination( $which ) { 138 global $mode; 139 140 parent::pagination( $which ); 141 142 if ( 'top' == $which ) 143 $this->view_switcher( $mode ); 144 } 145 146 function get_columns() { 147 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' ); 148 $sites_columns = array( 149 'cb' => '<input type="checkbox" />', 150 'blogname' => $blogname_columns, 151 'lastupdated' => __( 'Last Updated' ), 152 'registered' => _x( 'Registered', 'site' ), 153 'users' => __( 'Users' ) 154 ); 155 156 if ( has_filter( 'wpmublogsaction' ) ) 157 $sites_columns['plugins'] = __( 'Actions' ); 158 159 /** 160 * Filter the displayed site columns in Sites list table. 161 * 162 * @since MU 163 * 164 * @param array $sites_columns An array of displayed site columns. Default 'cb', 165 * 'blogname', 'lastupdated', 'registered', 'users'. 166 */ 167 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns ); 168 169 return $sites_columns; 170 } 171 172 function get_sortable_columns() { 173 return array( 174 'blogname' => 'blogname', 175 'lastupdated' => 'lastupdated', 176 'registered' => 'blog_id', 177 ); 178 } 179 180 function display_rows() { 181 global $mode; 182 183 $status_list = array( 184 'archived' => array( 'site-archived', __( 'Archived' ) ), 185 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), 186 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), 187 'mature' => array( 'site-mature', __( 'Mature' ) ) 188 ); 189 190 $class = ''; 191 foreach ( $this->items as $blog ) { 192 $class = ( 'alternate' == $class ) ? '' : 'alternate'; 193 reset( $status_list ); 194 195 $blog_states = array(); 196 foreach ( $status_list as $status => $col ) { 197 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) { 198 $class = $col[0]; 199 $blog_states[] = $col[1]; 200 } 201 } 202 $blog_state = ''; 203 if ( ! empty( $blog_states ) ) { 204 $state_count = count( $blog_states ); 205 $i = 0; 206 $blog_state .= ' - '; 207 foreach ( $blog_states as $state ) { 208 ++$i; 209 ( $i == $state_count ) ? $sep = '' : $sep = ', '; 210 $blog_state .= "<span class='post-state'>$state$sep</span>"; 211 } 212 } 213 echo "<tr class='$class'>"; 214 215 $blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path']; 216 217 list( $columns, $hidden ) = $this->get_column_info(); 218 219 foreach ( $columns as $column_name => $column_display_name ) { 220 $style = ''; 221 if ( in_array( $column_name, $hidden ) ) 222 $style = ' style="display:none;"'; 223 224 switch ( $column_name ) { 225 case 'cb': ?> 226 <th scope="row" class="check-column"> 227 <?php if ( ! is_main_site( $blog['blog_id'] ) ) : ?> 228 <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label> 229 <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" /> 230 <?php endif; ?> 231 </th> 232 <?php 233 break; 234 235 case 'id':?> 236 <th valign="top" scope="row"> 237 <?php echo $blog['blog_id'] ?> 238 </th> 239 <?php 240 break; 241 242 case 'blogname': 243 echo "<td class='column-$column_name $column_name'$style>"; ?> 244 <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a> 245 <?php 246 if ( 'list' != $mode ) { 247 switch_to_blog( $blog['blog_id'] ); 248 echo '<p>' . sprintf( _x( '%1$s – <em>%2$s</em>', '%1$s: site name. %2$s: site tagline.' ), get_option( 'blogname' ), get_option( 'blogdescription ' ) ) . '</p>'; 249 restore_current_blog(); 250 } 251 252 // Preordered. 253 $actions = array( 254 'edit' => '', 'backend' => '', 255 'activate' => '', 'deactivate' => '', 256 'archive' => '', 'unarchive' => '', 257 'spam' => '', 'unspam' => '', 258 'delete' => '', 259 'visit' => '', 260 ); 261 262 $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>'; 263 $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>'; 264 if ( get_current_site()->blog_id != $blog['blog_id'] ) { 265 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' ) 266 $actions['activate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.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>'; 267 else 268 $actions['deactivate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.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>'; 269 270 if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' ) 271 $actions['unarchive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.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>'; 272 else 273 $actions['archive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.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>'; 274 275 if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' ) 276 $actions['unspam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.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>'; 277 else 278 $actions['spam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.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>'; 279 280 if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) 281 $actions['delete'] = '<span class="delete"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.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>'; 282 } 283 284 $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>'; 285 286 /** 287 * Filter the action links displayed for each site in the Sites list table. 288 * 289 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by 290 * default for each site. The site's status determines whether to show the 291 * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and 292 * 'Not Spam' or 'Spam' link for each site. 293 * 294 * @since 3.1.0 295 * 296 * @param array $actions An array of action links to be displayed. 297 * @param int $blog_id The site ID. 298 * @param string $blogname Site path, formatted depending on whether it is a sub-domain 299 * or subdirectory multisite install. 300 */ 301 $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); 302 echo $this->row_actions( $actions ); 303 ?> 304 </td> 305 <?php 306 break; 307 308 case 'lastupdated': 309 echo "<td valign='top' class='$column_name column-$column_name'$style>"; 310 if ( 'list' == $mode ) 311 $date = 'Y/m/d'; 312 else 313 $date = 'Y/m/d \<\b\r \/\> g:i:s a'; 314 echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?> 315 </td> 316 <?php 317 break; 318 case 'registered': 319 echo "<td valign='top' class='$column_name column-$column_name'$style>"; 320 if ( $blog['registered'] == '0000-00-00 00:00:00' ) 321 echo '—'; 322 else 323 echo mysql2date( $date, $blog['registered'] ); 324 ?> 325 </td> 326 <?php 327 break; 328 case 'users': 329 echo "<td valign='top' class='$column_name column-$column_name'$style>"; 330 $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) ); 331 if ( is_array( $blogusers ) ) { 332 $blogusers_warning = ''; 333 if ( count( $blogusers ) > 5 ) { 334 $blogusers = array_slice( $blogusers, 0, 5 ); 335 $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>'; 336 } 337 foreach ( $blogusers as $user_object ) { 338 echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> '; 339 if ( 'list' != $mode ) 340 echo '( ' . $user_object->user_email . ' )'; 341 echo '<br />'; 342 } 343 if ( $blogusers_warning != '' ) 344 echo '<strong>' . $blogusers_warning . '</strong><br />'; 345 } 346 ?> 347 </td> 348 <?php 349 break; 350 351 case 'plugins': ?> 352 <?php if ( has_filter( 'wpmublogsaction' ) ) { 353 echo "<td valign='top' class='$column_name column-$column_name'$style>"; 354 /** 355 * Fires inside the auxiliary 'Actions' column of the Sites list table. 356 * 357 * By default this column is hidden unless something is hooked to the action. 358 * 359 * @since MU 360 * 361 * @param int $blog_id The site ID. 362 */ 363 do_action( 'wpmublogsaction', $blog['blog_id'] ); ?> 364 </td> 365 <?php } 366 break; 367 368 default: 369 echo "<td class='$column_name column-$column_name'$style>"; 370 /** 371 * Fires for each registered custom column in the Sites list table. 372 * 373 * @since 3.1.0 374 * 375 * @param string $column_name The name of the column to display. 376 * @param int $blog_id The site ID. 377 */ 378 do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] ); 379 echo "</td>"; 380 break; 381 } 382 } 383 ?> 384 </tr> 385 <?php 386 } 387 } 388 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 25 01:41:18 2014 | WordPress honlapkészítés: online1.hu |