Wordpress 3.0-scripts
[autoinstalls/wordpress.git] / wp-admin / ms-sites.php
1 <?php
2 /**
3  * Multisite sites administration panel.
4  *
5  * @package WordPress
6  * @subpackage Multisite
7  * @since 3.0.0
8  */
9
10 require_once( './admin.php' );
11
12 if ( ! is_multisite() )
13         wp_die( __( 'Multisite support is not enabled.' ) );
14
15 if ( ! current_user_can( 'manage_sites' ) )
16         wp_die( __( 'You do not have permission to access this page.' ) );
17
18 $title = __( 'Sites' );
19 $parent_file = 'ms-admin.php';
20
21 if ( isset( $_GET['action'] ) && 'editblog' == $_GET['action'] ) {
22         add_contextual_help($current_screen,
23                 '<p>' . __('This extensive list of options has five modules: Site Info, Site Options, allowing Site Themes for this given site, changing user roles and passwords for that site, adding a new user, and Miscellaneous Site Actions (upload size limits).') . '</p>' .
24                 '<p>' . __('Note that some fields in Site Options are grayed out and say Serialized Data. These are stored values in the database which you cannot change from here.') . '</p>' .
25                 '<p><strong>' . __('For more information:') . '</strong></p>' .
26                 '<p>' . __('<a href="http://codex.wordpress.org/Super_Admin_Sites_Edit_Site" target="_blank">Documentation on Editing Sites</a>') . '</p>' .
27                 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
28         );
29 } else {
30         add_contextual_help($current_screen,
31                 '<p>' . __('Add New takes you farther down on this same page. You can search for a site by Name, ID number, or IP address. Screen Options allows you to choose how many sites to display on one page.') . '</p>' .
32                 '<p>' . __('This is the main table of all sites on this network. Switch between list and excerpt views by using the icons above the right side of the table.') . '</p>' .
33                 '<p>' . __('Hovering over each site reveals seven options (three for the primary site):') . '</p>' .
34                 '<ul><li>' . __('an Edit link to a separate Edit Site screen.') . '</li>' .
35                 '<li>' . __('Backend means the Dashboard for that site.') . '</li>' .
36                 '<li>' . __('Deactivate, Archive, and Spam which lead to confirmation screens. These actions can be reversed later.') . '</li>' .
37                 '<li>' . __('Delete which is a permanent action after the confirmations screen.') . '</li>' .
38                 '<li>' . __('Visit to go to the frontend site live.') . '</li></ul>' .
39                 '<p>' . __('The site ID is used internally, and is not shown on the front end of the site or to users/viewers.') . '</p>' .
40                 '<p>' . __('Clicking on bold settings can re-sort this table. The upper right icons switch between list and excerpt views.') . '</p>' .
41                 '<p>' . __("Clicking on Add Site, after filling out the address, title, and admin's email address, adds the site instantly to the network and this table. You may want to then click on the action link to edit options for that site.") . '</p>' .
42                 '<p>' . __('If the admin email for the new site does not exist in the database, a new user will also be created.') . '</p>' .
43                 '<p><strong>' . __('For more information:') . '</strong></p>' .
44                 '<p>' . __('<a href="http://codex.wordpress.org/Super_Admin_Sites_SubPanel" target="_blank">Documentation on Sites</a>') . '</p>' .
45                 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
46         );
47 }
48
49 wp_enqueue_script( 'admin-forms' );
50
51 require_once( './admin-header.php' );
52
53 $id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
54
55 if ( isset( $_GET['updated'] ) && $_GET['updated'] == 'true' && ! empty( $_GET['action'] ) ) {
56         ?>
57         <div id="message" class="updated"><p>
58                 <?php
59                 switch ( $_GET['action'] ) {
60                         case 'all_notspam':
61                                 _e( 'Sites removed from spam.' );
62                         break;
63                         case 'all_spam':
64                                 _e( 'Sites marked as spam.' );
65                         break;
66                         case 'all_delete':
67                                 _e( 'Sites deleted.' );
68                         break;
69                         case 'delete':
70                                 _e( 'Site deleted.' );
71                         break;
72                         case 'add-blog':
73                                 _e( 'Site added.' );
74                         break;
75                         case 'archive':
76                                 _e( 'Site archived.' );
77                         break;
78                         case 'unarchive':
79                                 _e( 'Site unarchived.' );
80                         break;
81                         case 'activate':
82                                 _e( 'Site activated.' );
83                         break;
84                         case 'deactivate':
85                                 _e( 'Site deactivated.' );
86                         break;
87                         case 'unspam':
88                                 _e( 'Site removed from spam.' );
89                         break;
90                         case 'spam':
91                                 _e( 'Site marked as spam.' );
92                         break;
93                         default:
94                                 _e( 'Settings saved.' );
95                         break;
96                 }
97                 ?>
98         </p></div>
99         <?php
100 }
101
102 $action = isset( $_GET['action'] ) ? $_GET['action'] : 'list';
103
104 switch ( $action ) {
105         // Edit site
106         case 'editblog':
107                 $blog_prefix = $wpdb->get_blog_prefix( $id );
108                 $options = $wpdb->get_results( "SELECT * FROM {$blog_prefix}options WHERE option_name NOT LIKE '\_%' AND option_name NOT LIKE '%user_roles'" );
109                 $details = get_blog_details( $id );
110                 $editblog_roles = get_blog_option( $id, "{$blog_prefix}user_roles" );
111                 $is_main_site = is_main_site( $id );
112                 ?>
113                 <div class="wrap">
114                 <?php screen_icon(); ?>
115                 <h2><?php _e( 'Edit Site' ); ?> - <a href="<?php echo esc_url( get_home_url( $id ) ); ?>"><?php echo esc_url( get_home_url( $id ) ); ?></a></h2>
116                 <form method="post" action="ms-edit.php?action=updateblog">
117                         <?php wp_nonce_field( 'editblog' ); ?>
118                         <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
119                         <div class="metabox-holder" style="width:49%;float:left;">
120                                 <div id="blogedit_bloginfo" class="postbox">
121                                 <h3 class="hndle"><span><?php _e( 'Site info (wp_blogs)' ); ?></span></h3>
122                                 <div class="inside">
123                                         <table class="form-table">
124                                                 <tr class="form-field form-required">
125                                                         <th scope="row"><?php _e( 'Domain' ) ?></th>
126                                                         <?php
127                                                         $protocol = is_ssl() ? 'https://' : 'http://';
128                                                         if ( $is_main_site ) { ?>
129                                                         <td><code><?php echo $protocol; echo esc_attr( $details->domain ) ?></code></td>
130                                                         <?php } else { ?>
131                                                         <td><?php echo $protocol; ?><input name="blog[domain]" type="text" id="domain" value="<?php echo esc_attr( $details->domain ) ?>" size="33" /></td>
132                                                         <?php } ?>
133                                                 </tr>
134                                                 <tr class="form-field form-required">
135                                                         <th scope="row"><?php _e( 'Path' ) ?></th>
136                                                         <?php if ( $is_main_site ) { ?>
137                                                         <td><code><?php echo esc_attr( $details->path ) ?></code></td>
138                                                         <?php } else { ?>
139                                                         <td><input name="blog[path]" type="text" id="path" value="<?php echo esc_attr( $details->path ) ?>" size="40" style='margin-bottom:5px;' />
140                                                         <br /><input type="checkbox" style="width:20px;" name="update_home_url" value="update" <?php if ( get_blog_option( $id, 'siteurl' ) == untrailingslashit( get_blogaddress_by_id ($id ) ) || get_blog_option( $id, 'home' ) == untrailingslashit( get_blogaddress_by_id( $id ) ) ) echo 'checked="checked"'; ?> /> <?php _e( 'Update <code>siteurl</code> and <code>home</code> as well.' ); ?></td>
141                                                         <?php } ?>
142                                                 </tr>
143                                                 <tr class="form-field">
144                                                         <th scope="row"><?php _ex( 'Registered', 'site' ) ?></th>
145                                                         <td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" size="40" /></td>
146                                                 </tr>
147                                                 <tr class="form-field">
148                                                         <th scope="row"><?php _e('Last Updated') ?></th>
149                                                         <td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ) ?>" size="40" /></td>
150                                                 </tr>
151                                                 <?php
152                                                 $radio_fields = array( 'public' => __( 'Public' ) );
153                                                 if ( ! $is_main_site ) {
154                                                         $radio_fields['archived'] = __( 'Archived' );
155                                                         $radio_fields['spam']     = _x( 'Spam', 'site' );
156                                                         $radio_fields['deleted']  = __( 'Deleted' );
157                                                 }
158                                                 $radio_fields['mature'] = __( 'Mature' );
159                                                 foreach ( $radio_fields as $field_key => $field_label ) {
160                                                 ?>
161                                                 <tr>
162                                                         <th scope="row"><?php echo $field_label; ?></th>
163                                                         <td>
164                                                                 <input type="radio" name="blog[<?php echo $field_key; ?>]" id="blog_<?php echo $field_key; ?>_1" value="1"<?php checked( $details->$field_key, 1 ); ?> />
165                                                                 <label for="blog_<?php echo $field_key; ?>_1"><?php _e('Yes'); ?></label>
166                                                                 <input type="radio" name="blog[<?php echo $field_key; ?>]" id="blog_<?php echo $field_key; ?>_0" value="0"<?php checked( $details->$field_key, 0 ); ?> />
167                                                                 <label for="blog_<?php echo $field_key; ?>_0"><?php _e('No'); ?></label>
168                                                         </td>
169                                                 </tr>
170                                                 <?php } ?>
171                                         </table>
172                                         <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
173                                 </div>
174                                 </div>
175
176                                 <div id="blogedit_blogoptions" class="postbox" >
177                                 <h3 class="hndle"><span><?php printf( __( 'Site options (%soptions)' ), $blog_prefix ); ?></span></h3>
178                                 <div class="inside">
179                                         <table class="form-table">
180                                                 <?php
181                                                 $editblog_default_role = 'subscriber';
182                                                 foreach ( $options as $option ) {
183                                                         if ( $option->option_name == 'default_role' )
184                                                                 $editblog_default_role = $option->option_value;
185                                                         $disabled = false;
186                                                         $class = 'all-options';
187                                                         if ( is_serialized( $option->option_value ) ) {
188                                                                 if ( is_serialized_string( $option->option_value ) ) {
189                                                                         $option->option_value = esc_html( maybe_unserialize( $option->option_value ), 'single' );
190                                                                 } else {
191                                                                         $option->option_value = 'SERIALIZED DATA';
192                                                                         $disabled = true;
193                                                                         $class = 'all-options disabled';
194                                                                 }
195                                                         }
196                                                         if ( strpos( $option->option_value, "\n" ) !== false ) {
197                                                         ?>
198                                                                 <tr class="form-field">
199                                                                         <th scope="row"><?php echo ucwords( str_replace( "_", " ", $option->option_name ) ) ?></th>
200                                                                         <td><textarea class="<?php echo $class; ?>" rows="5" cols="40" name="option[<?php echo esc_attr( $option->option_name ) ?>]" id="<?php echo esc_attr( $option->option_name ) ?>"<?php disabled( $disabled ) ?>><?php wp_htmledit_pre( $option->option_value ) ?></textarea></td>
201                                                                 </tr>
202                                                         <?php
203                                                         } else {
204                                                         ?>
205                                                                 <tr class="form-field">
206                                                                         <th scope="row"><?php echo esc_html( ucwords( str_replace( "_", " ", $option->option_name ) ) ); ?></th>
207                                                                         <?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ) ) ) { ?>
208                                                                         <td><code><?php echo esc_html( $option->option_value ) ?></code></td>
209                                                                         <?php } else { ?>
210                                                                         <td><input class="<?php echo $class; ?>" name="option[<?php echo esc_attr( $option->option_name ) ?>]" type="text" id="<?php echo esc_attr( $option->option_name ) ?>" value="<?php echo esc_attr( $option->option_value ) ?>" size="40" <?php disabled( $disabled ) ?> /></td>
211                                                                         <?php } ?>
212                                                                 </tr>
213                                                         <?php
214                                                         }
215                                                 } // End foreach
216                                                 ?>
217                                         </table>
218                                         <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
219                                 </div>
220                                 </div>
221                         </div>
222
223                         <div class="metabox-holder" style="width:49%;float:right;">
224                                 <?php
225                                 // Site Themes
226                                 $themes = get_themes();
227                                 $blog_allowed_themes = wpmu_get_blog_allowedthemes( $id );
228                                 $allowed_themes = get_site_option( 'allowedthemes' );
229
230                                 if ( ! $allowed_themes )
231                                         $allowed_themes = array_keys( $themes );
232
233                                 $out = '';
234                                 foreach ( $themes as $key => $theme ) {
235                                         $theme_key = esc_html( $theme['Stylesheet'] );
236                                         if ( ! isset( $allowed_themes[$theme_key] ) ) {
237                                                 $checked = isset( $blog_allowed_themes[ $theme_key ] ) ? 'checked="checked"' : '';
238                                                 $out .= '<tr class="form-field form-required">
239                                                                 <th title="' . esc_attr( $theme["Description"] ).'" scope="row">' . esc_html( $key ) . '</th>
240                                                                 <td><label><input name="theme[' . esc_attr( $theme_key ) . ']" type="checkbox" style="width:20px;" value="on" '.$checked.'/> ' . __( 'Active' ) . '</label></td>
241                                                         </tr>';
242                                         }
243                                 }
244
245                                 if ( $out != '' ) {
246                                 ?>
247                                 <div id="blogedit_blogthemes" class="postbox">
248                                 <h3 class="hndle"><span><?php esc_html_e( 'Site Themes' ); ?></span></h3>
249                                 <div class="inside">
250                                         <p class="description"><?php _e( 'Activate the themename of an existing theme and hit "Update Options" to allow the theme for this site.' ) ?></p>
251                                         <table class="form-table">
252                                                 <?php echo $out; ?>
253                                         </table>
254                                         <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
255                                 </div></div>
256                                 <?php }
257
258                                 // Site users
259                                 $blogusers = get_users_of_blog( $id );
260                                 if ( is_array( $blogusers ) ) {
261                                         echo '<div id="blogedit_blogusers" class="postbox"><h3 class="hndle"><span>' . __( 'Site Users' ) . '</span></h3><div class="inside">';
262                                         echo '<table class="form-table">';
263                                         echo "<tr><th>" . __( 'User' ) . "</th><th>" . __( 'Role' ) . "</th><th>" . __( 'Password' ) . "</th><th>" . __( 'Remove' ) . "</th></tr>";
264                                         reset( $blogusers );
265                                         foreach ( (array) $blogusers as $key => $val ) {
266                                                 if ( isset( $val->meta_value ) && ! $val->meta_value )
267                                                         continue;
268                                                 $t = @unserialize( $val->meta_value );
269                                                 if ( is_array( $t ) ) {
270                                                         reset( $t );
271                                                         $existing_role = key( $t );
272                                                 }
273                                                 echo '<tr><td><a href="user-edit.php?user_id=' . $val->user_id . '">' . $val->user_login . '</a></td>';
274                                                 if ( $val->user_id != $current_user->data->ID ) {
275                                                         ?>
276                                                         <td>
277                                                                 <select name="role[<?php echo $val->user_id ?>]" id="new_role_1"><?php
278                                                                         foreach ( $editblog_roles as $role => $role_assoc ){
279                                                                                 $name = translate_user_role( $role_assoc['name'] );
280                                                                                 echo '<option ' . selected( $role, $existing_role, false ) . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>';
281                                                                         }
282                                                                         ?>
283                                                                 </select>
284                                                         </td>
285                                                         <td>
286                                                                 <input type="text" name="user_password[<?php echo esc_attr( $val->user_id ) ?>]" />
287                                                         </td>
288                                                         <?php
289                                                         echo '<td><input title="' . __( 'Click to remove user' ) . '" type="checkbox" name="blogusers[' . esc_attr( $val->user_id ) . ']" /></td>';
290                                                 } else {
291                                                         echo "<td><strong>" . __ ( 'N/A' ) . "</strong></td><td><strong>" . __ ( 'N/A' ) . "</strong></td><td><strong>" . __( 'N/A' ) . "</strong></td>";
292                                                 }
293                                                 echo '</tr>';
294                                         }
295                                         echo "</table>";
296                                         echo '<p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="' . esc_attr__( 'Update Options' ) . '" /></p>';
297                                         echo "</div></div>";
298                                 }
299                                 ?>
300
301                                 <div id="blogedit_blogadduser" class="postbox">
302                                 <h3 class="hndle"><span><?php _e( 'Add a new user' ); ?></span></h3>
303                                 <div class="inside">
304                                         <p class="description"><?php _e( 'Enter the username of an existing user and hit &#8220;Update Options&#8221; to add the user.' ) ?></p>
305                                         <table class="form-table">
306                                                         <tr>
307                                                                 <th scope="row"><?php _e( 'User&nbsp;Login:' ) ?></th>
308                                                                 <td><input type="text" name="newuser" id="newuser" /></td>
309                                                         </tr>
310                                                         <tr>
311                                                                 <th scope="row"><?php _e( 'Role:' ) ?></th>
312                                                                 <td>
313                                                                         <select name="new_role" id="new_role_0">
314                                                                         <?php
315                                                                         reset( $editblog_roles );
316                                                                         foreach ( $editblog_roles as $role => $role_assoc ){
317                                                                                 $name = translate_user_role( $role_assoc['name'] );
318                                                                                 $selected = ( $role == $editblog_default_role ) ? 'selected="selected"' : '';
319                                                                                 echo '<option ' . $selected . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>';
320                                                                         }
321                                                                         ?>
322                                                                         </select>
323                                                                 </td>
324                                                         </tr>
325                                                 </table>
326                                         <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
327                                 </div>
328                                 </div>
329
330                                 <div id="blogedit_miscoptions" class="postbox">
331                                 <h3 class="hndle"><span><?php _e( 'Misc Site Actions' ) ?></span></h3>
332                                 <div class="inside">
333                                         <table class="form-table">
334                                                         <?php do_action( 'wpmueditblogaction', $id ); ?>
335                                         </table>
336                                         <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
337                                 </div>
338                                 </div>
339                         </div>
340
341                         <div style="clear:both;"></div>
342                 </form>
343                 </div>
344                 <?php
345         break;
346
347         // List sites
348         case 'list':
349         default:
350                 $pagenum = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 0;
351                 if ( empty($pagenum) )
352                         $pagenum = 1;
353
354                 $per_page = (int) get_user_option( 'ms_sites_per_page' );
355                 if ( empty( $per_page ) || $per_page < 1 )
356                         $per_page = 15;
357
358                 $per_page = apply_filters( 'ms_sites_per_page', $per_page );
359
360                 $s = isset( $_GET['s'] ) ? stripslashes( trim( $_GET[ 's' ] ) ) : '';
361                 $like_s = esc_sql( like_escape( $s ) );
362
363                 $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
364
365                 if ( isset( $_GET['searchaction'] ) ) {
366                         if ( 'name' == $_GET['searchaction'] ) {
367                                 $query .= " AND ( {$wpdb->blogs}.domain LIKE '%{$like_s}%' OR {$wpdb->blogs}.path LIKE '%{$like_s}%' ) ";
368                         } elseif ( 'id' == $_GET['searchaction'] ) {
369                                 $query .= " AND {$wpdb->blogs}.blog_id = '{$like_s}' ";
370                         } elseif ( 'ip' == $_GET['searchaction'] ) {
371                                 $query = "SELECT *
372                                         FROM {$wpdb->blogs}, {$wpdb->registration_log}
373                                         WHERE site_id = '{$wpdb->siteid}'
374                                         AND {$wpdb->blogs}.blog_id = {$wpdb->registration_log}.blog_id
375                                         AND {$wpdb->registration_log}.IP LIKE ('%{$like_s}%')";
376                         }
377                 }
378
379                 $order_by = isset( $_GET['sortby'] ) ? $_GET['sortby'] : 'id';
380                 if ( $order_by == 'registered' ) {
381                         $query .= ' ORDER BY registered ';
382                 } elseif ( $order_by == 'lastupdated' ) {
383                         $query .= ' ORDER BY last_updated ';
384                 } elseif ( $order_by == 'blogname' ) {
385                         $query .= ' ORDER BY domain ';
386                 } else {
387                         $order_by = 'id';
388                         $query .= " ORDER BY {$wpdb->blogs}.blog_id ";
389                 }
390
391                 $order = ( isset( $_GET['order'] ) && 'DESC' == $_GET['order'] ) ? "DESC" : "ASC";
392                 $query .= $order;
393
394                 $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT(blog_id)', $query ) );
395
396                 $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
397                 $blog_list = $wpdb->get_results( $query, ARRAY_A );
398
399                 $num_pages = ceil($total / $per_page);
400                 $page_links = paginate_links( array(
401                         'base' => add_query_arg( 'paged', '%#%' ),
402                         'format' => '',
403                         'prev_text' => __( '&laquo;' ),
404                         'next_text' => __( '&raquo;' ),
405                         'total' => $num_pages,
406                         'current' => $pagenum
407                 ));
408
409                 if ( empty( $_GET['mode'] ) )
410                         $mode = 'list';
411                 else
412                         $mode = esc_attr( $_GET['mode'] );
413                 ?>
414
415                 <div class="wrap">
416                 <?php screen_icon(); ?>
417                 <h2><?php _e('Sites') ?>
418                 <a href="#form-add-site" class="button add-new-h2"><?php echo esc_html_x( 'Add New', 'sites' ); ?></a>
419                 <?php
420                 if ( isset( $_GET['s'] ) && $_GET['s'] )
421                 printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
422                 ?>
423                 </h2>
424
425                 <form action="ms-sites.php" method="get" id="ms-search">
426                 <p class="search-box">
427                 <input type="hidden" name="action" value="blogs" />
428                 <input type="text" name="s" value="<?php echo esc_attr( $s ); ?>" />
429                 <input type="submit" class="button" value="<?php esc_attr_e( 'Search Site by' ) ?>" />
430                 <select name="searchaction">
431                         <option value="name" selected="selected"><?php _e( 'Name' ); ?></option>
432                         <option value="id"><?php _e( 'ID' ); ?></option>
433                         <option value="ip"><?php _e( 'IP address' ); ?></option>
434                 </select>
435                 </p>
436                 </form>
437
438                 <form id="form-site-list" action="ms-edit.php?action=allblogs" method="post">
439                 <input type="hidden" name="mode" value="<?php echo esc_attr( $mode ); ?>" />
440                 <div class="tablenav">
441                 <div class="alignleft actions">
442                         <select name="action">
443                                 <option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
444                                 <option value="delete"><?php _e( 'Delete' ); ?></option>
445                                 <option value="spam"><?php _ex( 'Mark as Spam', 'site' ); ?></option>
446                                 <option value="notspam"><?php _ex( 'Not Spam', 'site' ); ?></option>
447                         </select>
448                         <input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction" id="doaction" class="button-secondary action" />
449                         <?php wp_nonce_field( 'bulk-ms-sites', '_wpnonce_bulk-ms-sites' ); ?>
450                 </div>
451
452                 <?php if ( $page_links ) { ?>
453                 <div class="tablenav-pages">
454                 <?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
455                 number_format_i18n( ( $pagenum - 1 ) * $per_page + 1 ),
456                 number_format_i18n( min( $pagenum * $per_page, $total ) ),
457                 number_format_i18n( $total ),
458                 $page_links
459                 ); echo $page_links_text; ?>
460                 </div>
461                 <?php } ?>
462
463                 <div class="view-switch">
464                         <a href="<?php echo esc_url( add_query_arg( 'mode', 'list', $_SERVER['REQUEST_URI'] ) ) ?>"><img <?php if ( 'list' == $mode ) echo 'class="current"'; ?> id="view-switch-list" src="<?php echo esc_url( includes_url( 'images/blank.gif' ) ); ?>" width="20" height="20" title="<?php _e( 'List View' ) ?>" alt="<?php _e( 'List View' ) ?>" /></a>
465                         <a href="<?php echo esc_url( add_query_arg( 'mode', 'excerpt', $_SERVER['REQUEST_URI'] ) ) ?>"><img <?php if ( 'excerpt' == $mode ) echo 'class="current"'; ?> id="view-switch-excerpt" src="<?php echo esc_url( includes_url( 'images/blank.gif' ) ); ?>" width="20" height="20" title="<?php _e( 'Excerpt View' ) ?>" alt="<?php _e( 'Excerpt View' ) ?>" /></a>
466                 </div>
467
468                 </div>
469
470                 <div class="clear"></div>
471
472                 <?php
473                 // define the columns to display, the syntax is 'internal name' => 'display name'
474                 $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
475                 $sites_columns = array(
476                         'id'           => __( 'ID' ),
477                         'blogname'     => $blogname_columns,
478                         'lastupdated'  => __( 'Last Updated'),
479                         'registered'   => _x( 'Registered', 'site' ),
480                         'users'        => __( 'Users' )
481                 );
482
483                 if ( has_filter( 'wpmublogsaction' ) )
484                         $sites_columns['plugins'] = __( 'Actions' );
485
486                 $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
487                 ?>
488
489                 <table class="widefat">
490                         <thead>
491                                 <tr>
492                                 <th class="manage-column column-cb check-column" id="cb" scope="col">
493                                         <input type="checkbox" />
494                                 </th>
495                                 <?php
496                                 $col_url = '';
497                                 foreach($sites_columns as $column_id => $column_display_name) {
498                                         $column_link = "<a href='";
499                                         $order2 = '';
500                                         if ( $order_by == $column_id )
501                                                 $order2 = ( $order == 'DESC' ) ? 'ASC' : 'DESC';
502
503                                         $column_link .= esc_url( add_query_arg( array( 'order' => $order2, 'paged' => $pagenum, 'sortby' => $column_id ), remove_query_arg( array('action', 'updated'), $_SERVER['REQUEST_URI'] ) ) );
504                                         $column_link .= "'>{$column_display_name}</a>";
505                                         $col_url .= '<th scope="col">' . ( ( $column_id == 'users' || $column_id == 'plugins' ) ? $column_display_name : $column_link ) . '</th>';
506                                 }
507                                 echo $col_url ?>
508                                 </tr>
509                         </thead>
510                         <tfoot>
511                                 <tr>
512                                 <th class="manage-column column-cb check-column" id="cb1" scope="col">
513                                         <input type="checkbox" />
514                                 </th>
515                                         <?php echo $col_url ?>
516                                 </tr>
517                         </tfoot>
518                         <tbody id="the-site-list" class="list:site">
519                         <?php
520                         $status_list = array( 'archived' => array( 'site-archived', __( 'Archived' ) ), 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), 'mature' => array( 'site-mature', __( 'Mature' ) ) );
521                         if ( $blog_list ) {
522                                 $class = '';
523                                 foreach ( $blog_list as $blog ) {
524                                         $class = ( 'alternate' == $class ) ? '' : 'alternate';
525                                         reset( $status_list );
526
527                                         $blog_states = array();
528                                         foreach ( $status_list as $status => $col ) {
529                                                 if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
530                                                         $class = $col[0];
531                                                         $blog_states[] = $col[1];
532                                                 }
533                                         }
534                                         $blog_state = '';
535                                         if ( ! empty( $blog_states ) ) {
536                                                 $state_count = count( $blog_states );
537                                                 $i = 0;
538                                                 $blog_state .= ' - ';
539                                                 foreach ( $blog_states as $state ) {
540                                                         ++$i;
541                                                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
542                                                         $blog_state .= "<span class='post-state'>$state$sep</span>";
543                                                 }
544                                         }
545                                         echo "<tr class='$class'>";
546
547                                         $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
548                                         foreach ( $sites_columns as $column_name=>$column_display_name ) {
549                                                 switch ( $column_name ) {
550                                                         case 'id': ?>
551                                                                 <th scope="row" class="check-column">
552                                                                         <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
553                                                                 </th>
554                                                                 <th valign="top" scope="row">
555                                                                         <?php echo $blog['blog_id'] ?>
556                                                                 </th>
557                                                         <?php
558                                                         break;
559
560                                                         case 'blogname': ?>
561                                                                 <td class="column-title">
562                                                                         <a href="<?php echo esc_url( admin_url( 'ms-sites.php?action=editblog&amp;id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a>
563                                                                         <?php
564                                                                         if ( 'list' != $mode )
565                                                                                 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>';
566
567                                                                         // Preordered.
568                                                                         $actions = array(
569                                                                                 'edit' => '', 'backend' => '',
570                                                                                 'activate' => '', 'deactivate' => '',
571                                                                                 'archive' => '', 'unarchive' => '',
572                                                                                 'spam' => '', 'unspam' => '',
573                                                                                 'delete' => '',
574                                                                                 'visit' => '',
575                                                                         );
576
577                                                                         $actions['edit']        = '<span class="edit"><a href="' . esc_url( admin_url( 'ms-sites.php?action=editblog&amp;id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
578                                                                         $actions['backend']     = "<span class='backend'><a href='" . esc_url( get_admin_url($blog['blog_id']) ) . "' class='edit'>" . __( 'Backend' ) . '</a></span>';
579                                                                         if ( $current_site->blog_id != $blog['blog_id'] ) {
580                                                                                 if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
581                                                                                         $actions['activate']    = '<span class="activate"><a href="' . esc_url( admin_url( 'ms-edit.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ) ) . '">' . __( 'Activate' ) . '</a></span>';
582                                                                                 else
583                                                                                         $actions['deactivate']  = '<span class="activate"><a href="' . esc_url( admin_url( 'ms-edit.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to deactivate the site %s' ), $blogname ) ) ) ) . '">' . __( 'Deactivate' ) . '</a></span>';
584
585                                                                                 if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
586                                                                                         $actions['unarchive']   = '<span class="archive"><a href="' . esc_url( admin_url( 'ms-edit.php?action=confirm&amp;action2=unarchiveblog&amp;id=' .  $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unarchive the site %s.' ), $blogname ) ) ) ) . '">' . __( 'Unarchive' ) . '</a></span>';
587                                                                                 else
588                                                                                         $actions['archive']     = '<span class="archive"><a href="' . esc_url( admin_url( 'ms-edit.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to archive the site %s.' ), $blogname ) ) ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a></span>';
589
590                                                                                 if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
591                                                                                         $actions['unspam']      = '<span class="spam"><a href="' . esc_url( admin_url( 'ms-edit.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to unspam the site %s.' ), $blogname ) ) ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a></span>';
592                                                                                 else
593                                                                                         $actions['spam']        = '<span class="spam"><a href="' . esc_url( admin_url( 'ms-edit.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 ) ) ) ) . '">' . _x( 'Spam', 'site' ) . '</a></span>';
594
595                                                                                 $actions['delete']      = '<span class="delete"><a href="' . esc_url( admin_url( 'ms-edit.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] . '&amp;msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ) ) . '">' . __( 'Delete' ) . '</a></span>';
596                                                                         }
597
598                                                                         $actions['visit']       = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'] ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
599                                                                         $actions = array_filter( $actions );
600                                                                         if ( count( $actions ) ) : ?>
601                                                                         <div class="row-actions">
602                                                                                 <?php echo implode( ' | ', $actions ); ?>
603                                                                         </div>
604                                                                         <?php endif; ?>
605                                                                 </td>
606                                                         <?php
607                                                         break;
608
609                                                         case 'lastupdated': ?>
610                                                                 <td valign="top">
611                                                                         <?php
612                                                                         if ( 'list' == $mode )
613                                                                                 $date = 'Y/m/d';
614                                                                         else
615                                                                                 $date = 'Y/m/d \<\b\r \/\> g:i:s a';
616                                                                         echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( __( $date ), $blog['last_updated'] ); ?>
617                                                                 </td>
618                                                         <?php
619                                                         break;
620                                                 case 'registered': ?>
621                                                                 <td valign="top">
622                                                                 <?php
623                                                                 if ( $blog['registered'] == '0000-00-00 00:00:00' )
624                                                                         echo '&#x2014;';
625                                                                 else
626                                                                         echo mysql2date( __( $date ), $blog['registered'] );
627                                                                 ?>
628                                                                 </td>
629                                                 <?php
630                                                 break;
631                                                         case 'users': ?>
632                                                                 <td valign="top">
633                                                                         <?php
634                                                                         $blogusers = get_users_of_blog( $blog['blog_id'] );
635                                                                         if ( is_array( $blogusers ) ) {
636                                                                                 $blogusers_warning = '';
637                                                                                 if ( count( $blogusers ) > 5 ) {
638                                                                                         $blogusers = array_slice( $blogusers, 0, 5 );
639                                                                                         $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( get_admin_url( $blog['blog_id'], 'users.php' ) ) . '">' . __( 'More' ) . '</a>';
640                                                                                 }
641                                                                                 foreach ( $blogusers as $key => $val ) {
642                                                                                         echo '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $val->user_id ) ) . '">' . esc_html( $val->user_login ) . '</a> ';
643                                                                                         if ( 'list' != $mode )
644                                                                                                 echo '(' . $val->user_email . ')';
645                                                                                         echo '<br />';
646                                                                                 }
647                                                                                 if ( $blogusers_warning != '' )
648                                                                                         echo '<strong>' . $blogusers_warning . '</strong><br />';
649                                                                         }
650                                                                         ?>
651                                                                 </td>
652                                                         <?php
653                                                         break;
654
655                                                         case 'plugins': ?>
656                                                                 <?php if ( has_filter( 'wpmublogsaction' ) ) { ?>
657                                                                 <td valign="top">
658                                                                         <?php do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
659                                                                 </td>
660                                                                 <?php } ?>
661                                                         <?php break;
662
663                                                         default: ?>
664                                                                 <?php if ( has_filter( 'manage_blogs_custom_column' ) ) { ?>
665                                                                 <td valign="top">
666                                                                         <?php do_action( 'manage_blogs_custom_column', $column_name, $blog['blog_id'] ); ?>
667                                                                 </td>
668                                                                 <?php } ?>
669                                                         <?php break;
670                                                 }
671                                         }
672                                         ?>
673                                         </tr>
674                                         <?php
675                                 }
676                         } else { ?>
677                                 <tr>
678                                         <td colspan="<?php echo (int) count( $sites_columns ); ?>"><?php _e( 'No sites found.' ) ?></td>
679                                 </tr>
680                         <?php
681                         } // end if ($blogs)
682                         ?>
683
684                         </tbody>
685                 </table>
686                 <div class="tablenav">
687                         <?php
688                         if ( $page_links )
689                                 echo "<div class='tablenav-pages'>$page_links_text</div>";
690                         ?>
691
692                         <div class="alignleft actions">
693                         <select name="action2">
694                                 <option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
695                                 <option value="delete"><?php _e( 'Delete' ); ?></option>
696                                 <option value="spam"><?php _ex( 'Mark as Spam', 'site' ); ?></option>
697                                 <option value="notspam"><?php _ex( 'Not Spam', 'site' ); ?></option>
698                         </select>
699                         <input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
700                         </div>
701                         <br class="clear" />
702                 </div>
703
704                 </form>
705                 </div>
706
707                 <div id="form-add-site" class="wrap">
708                         <h3><?php _e( 'Add Site' ) ?></h3>
709                         <form method="post" action="ms-edit.php?action=addblog">
710                                 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
711                                 <table class="form-table">
712                                         <tr class="form-field form-required">
713                                                 <th scope="row"><?php _e( 'Site Address' ) ?></th>
714                                                 <td>
715                                                 <?php if ( is_subdomain_install() ) { ?>
716                                                         <input name="blog[domain]" type="text" class="regular-text" title="<?php _e( 'Domain' ) ?>"/>.<?php echo preg_replace( '|^www\.|', '', $current_site->domain );?>
717                                                 <?php } else {
718                                                         echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php _e( 'Domain' ) ?>"/>
719                                                 <?php }
720                                                 echo '<p>' . __( 'Only the characters a-z and 0-9 recommended.' ) . '</p>';
721                                                 ?>
722                                                 </td>
723                                         </tr>
724                                         <tr class="form-field form-required">
725                                                 <th scope="row"><?php _e( 'Site Title' ) ?></th>
726                                                 <td><input name="blog[title]" type="text" class="regular-text" title="<?php _e( 'Title' ) ?>"/></td>
727                                         </tr>
728                                         <tr class="form-field form-required">
729                                                 <th scope="row"><?php _e( 'Admin Email' ) ?></th>
730                                                 <td><input name="blog[email]" type="text" class="regular-text" title="<?php _e( 'Email' ) ?>"/></td>
731                                         </tr>
732                                         <tr class="form-field">
733                                                 <td colspan="2"><?php _e( 'A new user will be created if the above email address is not in the database.' ) ?><br /><?php _e( 'The username and password will be mailed to this email address.' ) ?></td>
734                                         </tr>
735                                 </table>
736                                 <p class="submit">
737                                         <input class="button" type="submit" name="go" value="<?php esc_attr_e( 'Add Site' ) ?>" /></p>
738                         </form>
739                 </div>
740                 <?php
741         break;
742 } // end switch( $action )
743
744 include( './admin-footer.php' ); ?>