~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-admin/ms-sites.php

  • Committer: Andrew Glen-Young
  • Date: 2011-03-08 14:47:51 UTC
  • Revision ID: andrew.glen-young@canonical.com-20110308144751-1n6spqgayztf9h77
[AGY] import 3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
require_once( './admin.php' );
11
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
 
                if ( $details->site_id != $wpdb->siteid )
111
 
                        wp_die( __( 'You do not have permission to access this page.' ) );
112
 
 
113
 
                $editblog_roles = get_blog_option( $id, "{$blog_prefix}user_roles" );
114
 
                $is_main_site = is_main_site( $id );
115
 
                ?>
116
 
                <div class="wrap">
117
 
                <?php screen_icon(); ?>
118
 
                <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>
119
 
                <form method="post" action="ms-edit.php?action=updateblog">
120
 
                        <?php wp_nonce_field( 'editblog' ); ?>
121
 
                        <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
122
 
                        <div class="metabox-holder" style="width:49%;float:left;">
123
 
                                <div id="blogedit_bloginfo" class="postbox">
124
 
                                <h3 class="hndle"><span><?php _e( 'Site info (wp_blogs)' ); ?></span></h3>
125
 
                                <div class="inside">
126
 
                                        <table class="form-table">
127
 
                                                <tr class="form-field form-required">
128
 
                                                        <th scope="row"><?php _e( 'Domain' ) ?></th>
129
 
                                                        <?php
130
 
                                                        $protocol = is_ssl() ? 'https://' : 'http://';
131
 
                                                        if ( $is_main_site ) { ?>
132
 
                                                        <td><code><?php echo $protocol; echo esc_attr( $details->domain ) ?></code></td>
133
 
                                                        <?php } else { ?>
134
 
                                                        <td><?php echo $protocol; ?><input name="blog[domain]" type="text" id="domain" value="<?php echo esc_attr( $details->domain ) ?>" size="33" /></td>
135
 
                                                        <?php } ?>
136
 
                                                </tr>
137
 
                                                <tr class="form-field form-required">
138
 
                                                        <th scope="row"><?php _e( 'Path' ) ?></th>
139
 
                                                        <?php if ( $is_main_site ) { ?>
140
 
                                                        <td><code><?php echo esc_attr( $details->path ) ?></code></td>
141
 
                                                        <?php } else { ?>
142
 
                                                        <td><input name="blog[path]" type="text" id="path" value="<?php echo esc_attr( $details->path ) ?>" size="40" style='margin-bottom:5px;' />
143
 
                                                        <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>
144
 
                                                        <?php } ?>
145
 
                                                </tr>
146
 
                                                <tr class="form-field">
147
 
                                                        <th scope="row"><?php _ex( 'Registered', 'site' ) ?></th>
148
 
                                                        <td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" size="40" /></td>
149
 
                                                </tr>
150
 
                                                <tr class="form-field">
151
 
                                                        <th scope="row"><?php _e('Last Updated') ?></th>
152
 
                                                        <td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ) ?>" size="40" /></td>
153
 
                                                </tr>
154
 
                                                <?php
155
 
                                                $radio_fields = array( 'public' => __( 'Public' ) );
156
 
                                                if ( ! $is_main_site ) {
157
 
                                                        $radio_fields['archived'] = __( 'Archived' );
158
 
                                                        $radio_fields['spam']     = _x( 'Spam', 'site' );
159
 
                                                        $radio_fields['deleted']  = __( 'Deleted' );
160
 
                                                }
161
 
                                                $radio_fields['mature'] = __( 'Mature' );
162
 
                                                foreach ( $radio_fields as $field_key => $field_label ) {
163
 
                                                ?>
164
 
                                                <tr>
165
 
                                                        <th scope="row"><?php echo $field_label; ?></th>
166
 
                                                        <td>
167
 
                                                                <input type="radio" name="blog[<?php echo $field_key; ?>]" id="blog_<?php echo $field_key; ?>_1" value="1"<?php checked( $details->$field_key, 1 ); ?> />
168
 
                                                                <label for="blog_<?php echo $field_key; ?>_1"><?php _e('Yes'); ?></label>
169
 
                                                                <input type="radio" name="blog[<?php echo $field_key; ?>]" id="blog_<?php echo $field_key; ?>_0" value="0"<?php checked( $details->$field_key, 0 ); ?> />
170
 
                                                                <label for="blog_<?php echo $field_key; ?>_0"><?php _e('No'); ?></label>
171
 
                                                        </td>
172
 
                                                </tr>
173
 
                                                <?php } ?>
174
 
                                        </table>
175
 
                                        <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
176
 
                                </div>
177
 
                                </div>
178
 
 
179
 
                                <div id="blogedit_blogoptions" class="postbox" >
180
 
                                <h3 class="hndle"><span><?php printf( __( 'Site options (%soptions)' ), $blog_prefix ); ?></span></h3>
181
 
                                <div class="inside">
182
 
                                        <table class="form-table">
183
 
                                                <?php
184
 
                                                $editblog_default_role = 'subscriber';
185
 
                                                foreach ( $options as $option ) {
186
 
                                                        if ( $option->option_name == 'default_role' )
187
 
                                                                $editblog_default_role = $option->option_value;
188
 
                                                        $disabled = false;
189
 
                                                        $class = 'all-options';
190
 
                                                        if ( is_serialized( $option->option_value ) ) {
191
 
                                                                if ( is_serialized_string( $option->option_value ) ) {
192
 
                                                                        $option->option_value = esc_html( maybe_unserialize( $option->option_value ), 'single' );
193
 
                                                                } else {
194
 
                                                                        $option->option_value = 'SERIALIZED DATA';
195
 
                                                                        $disabled = true;
196
 
                                                                        $class = 'all-options disabled';
197
 
                                                                }
198
 
                                                        }
199
 
                                                        if ( strpos( $option->option_value, "\n" ) !== false ) {
200
 
                                                        ?>
201
 
                                                                <tr class="form-field">
202
 
                                                                        <th scope="row"><?php echo ucwords( str_replace( "_", " ", $option->option_name ) ) ?></th>
203
 
                                                                        <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 echo wp_htmledit_pre( $option->option_value ) ?></textarea></td>
204
 
                                                                </tr>
205
 
                                                        <?php
206
 
                                                        } else {
207
 
                                                        ?>
208
 
                                                                <tr class="form-field">
209
 
                                                                        <th scope="row"><?php echo esc_html( ucwords( str_replace( "_", " ", $option->option_name ) ) ); ?></th>
210
 
                                                                        <?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ) ) ) { ?>
211
 
                                                                        <td><code><?php echo esc_html( $option->option_value ) ?></code></td>
212
 
                                                                        <?php } else { ?>
213
 
                                                                        <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>
214
 
                                                                        <?php } ?>
215
 
                                                                </tr>
216
 
                                                        <?php
217
 
                                                        }
218
 
                                                } // End foreach
219
 
                                                ?>
220
 
                                        </table>
221
 
                                        <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
222
 
                                </div>
223
 
                                </div>
224
 
                        </div>
225
 
 
226
 
                        <div class="metabox-holder" style="width:49%;float:right;">
227
 
                                <?php
228
 
                                // Site Themes
229
 
                                $themes = get_themes();
230
 
                                $blog_allowed_themes = wpmu_get_blog_allowedthemes( $id );
231
 
                                $allowed_themes = get_site_option( 'allowedthemes' );
232
 
 
233
 
                                if ( ! $allowed_themes )
234
 
                                        $allowed_themes = array_keys( $themes );
235
 
 
236
 
                                $out = '';
237
 
                                foreach ( $themes as $key => $theme ) {
238
 
                                        $theme_key = esc_html( $theme['Stylesheet'] );
239
 
                                        if ( ! isset( $allowed_themes[$theme_key] ) ) {
240
 
                                                $checked = isset( $blog_allowed_themes[ $theme_key ] ) ? 'checked="checked"' : '';
241
 
                                                $out .= '<tr class="form-field form-required">
242
 
                                                                <th title="' . esc_attr( $theme["Description"] ).'" scope="row">' . esc_html( $key ) . '</th>
243
 
                                                                <td><label><input name="theme[' . esc_attr( $theme_key ) . ']" type="checkbox" style="width:20px;" value="on" '.$checked.'/> ' . __( 'Active' ) . '</label></td>
244
 
                                                        </tr>';
245
 
                                        }
246
 
                                }
247
 
 
248
 
                                if ( $out != '' ) {
249
 
                                ?>
250
 
                                <div id="blogedit_blogthemes" class="postbox">
251
 
                                <h3 class="hndle"><span><?php esc_html_e( 'Site Themes' ); ?></span></h3>
252
 
                                <div class="inside">
253
 
                                        <p class="description"><?php _e( 'Activate the themename of an existing theme and hit "Update Options" to allow the theme for this site.' ) ?></p>
254
 
                                        <table class="form-table">
255
 
                                                <?php echo $out; ?>
256
 
                                        </table>
257
 
                                        <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
258
 
                                </div></div>
259
 
                                <?php }
260
 
 
261
 
                                // Site users
262
 
                                $blogusers = get_users_of_blog( $id );
263
 
                                if ( is_array( $blogusers ) ) {
264
 
                                        echo '<div id="blogedit_blogusers" class="postbox"><h3 class="hndle"><span>' . __( 'Site Users' ) . '</span></h3><div class="inside">';
265
 
                                        echo '<table class="form-table">';
266
 
                                        echo "<tr><th>" . __( 'User' ) . "</th><th>" . __( 'Role' ) . "</th><th>" . __( 'Password' ) . "</th><th>" . __( 'Remove' ) . "</th></tr>";
267
 
                                        reset( $blogusers );
268
 
                                        foreach ( (array) $blogusers as $key => $val ) {
269
 
                                                if ( isset( $val->meta_value ) && ! $val->meta_value )
270
 
                                                        continue;
271
 
                                                $t = @unserialize( $val->meta_value );
272
 
                                                if ( is_array( $t ) ) {
273
 
                                                        reset( $t );
274
 
                                                        $existing_role = key( $t );
275
 
                                                }
276
 
                                                echo '<tr><td><a href="user-edit.php?user_id=' . $val->user_id . '">' . $val->user_login . '</a></td>';
277
 
                                                if ( $val->user_id != $current_user->data->ID ) {
278
 
                                                        ?>
279
 
                                                        <td>
280
 
                                                                <select name="role[<?php echo $val->user_id ?>]" id="new_role_1"><?php
281
 
                                                                        foreach ( $editblog_roles as $role => $role_assoc ){
282
 
                                                                                $name = translate_user_role( $role_assoc['name'] );
283
 
                                                                                echo '<option ' . selected( $role, $existing_role, false ) . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>';
284
 
                                                                        }
285
 
                                                                        ?>
286
 
                                                                </select>
287
 
                                                        </td>
288
 
                                                        <td>
289
 
                                                                <input type="text" name="user_password[<?php echo esc_attr( $val->user_id ) ?>]" />
290
 
                                                        </td>
291
 
                                                        <?php
292
 
                                                        echo '<td><input title="' . __( 'Click to remove user' ) . '" type="checkbox" name="blogusers[' . esc_attr( $val->user_id ) . ']" /></td>';
293
 
                                                } else {
294
 
                                                        echo "<td><strong>" . __ ( 'N/A' ) . "</strong></td><td><strong>" . __ ( 'N/A' ) . "</strong></td><td><strong>" . __( 'N/A' ) . "</strong></td>";
295
 
                                                }
296
 
                                                echo '</tr>';
297
 
                                        }
298
 
                                        echo "</table>";
299
 
                                        echo '<p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="' . esc_attr__( 'Update Options' ) . '" /></p>';
300
 
                                        echo "</div></div>";
301
 
                                }
302
 
                                ?>
303
 
 
304
 
                                <div id="blogedit_blogadduser" class="postbox">
305
 
                                <h3 class="hndle"><span><?php _e( 'Add a new user' ); ?></span></h3>
306
 
                                <div class="inside">
307
 
                                        <p class="description"><?php _e( 'Enter the username of an existing user and hit &#8220;Update Options&#8221; to add the user.' ) ?></p>
308
 
                                        <table class="form-table">
309
 
                                                        <tr>
310
 
                                                                <th scope="row"><?php _e( 'User&nbsp;Login:' ) ?></th>
311
 
                                                                <td><input type="text" name="newuser" id="newuser" /></td>
312
 
                                                        </tr>
313
 
                                                        <tr>
314
 
                                                                <th scope="row"><?php _e( 'Role:' ) ?></th>
315
 
                                                                <td>
316
 
                                                                        <select name="new_role" id="new_role_0">
317
 
                                                                        <?php
318
 
                                                                        reset( $editblog_roles );
319
 
                                                                        foreach ( $editblog_roles as $role => $role_assoc ){
320
 
                                                                                $name = translate_user_role( $role_assoc['name'] );
321
 
                                                                                $selected = ( $role == $editblog_default_role ) ? 'selected="selected"' : '';
322
 
                                                                                echo '<option ' . $selected . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>';
323
 
                                                                        }
324
 
                                                                        ?>
325
 
                                                                        </select>
326
 
                                                                </td>
327
 
                                                        </tr>
328
 
                                                </table>
329
 
                                        <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
330
 
                                </div>
331
 
                                </div>
332
 
 
333
 
                                <div id="blogedit_miscoptions" class="postbox">
334
 
                                <h3 class="hndle"><span><?php _e( 'Misc Site Actions' ) ?></span></h3>
335
 
                                <div class="inside">
336
 
                                        <table class="form-table">
337
 
                                                        <?php do_action( 'wpmueditblogaction', $id ); ?>
338
 
                                        </table>
339
 
                                        <p class="submit" style="text-align:center;"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Update Options' ) ?>" /></p>
340
 
                                </div>
341
 
                                </div>
342
 
                        </div>
343
 
 
344
 
                        <div style="clear:both;"></div>
345
 
                </form>
346
 
                </div>
347
 
                <?php
348
 
        break;
349
 
 
350
 
        // List sites
351
 
        case 'list':
352
 
        default:
353
 
                $pagenum = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 0;
354
 
                if ( empty($pagenum) )
355
 
                        $pagenum = 1;
356
 
 
357
 
                $per_page = (int) get_user_option( 'ms_sites_per_page' );
358
 
                if ( empty( $per_page ) || $per_page < 1 )
359
 
                        $per_page = 15;
360
 
 
361
 
                $per_page = apply_filters( 'ms_sites_per_page', $per_page );
362
 
 
363
 
                $s = isset( $_GET['s'] ) ? stripslashes( trim( $_GET[ 's' ] ) ) : '';
364
 
                $like_s = esc_sql( like_escape( $s ) );
365
 
 
366
 
                $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
367
 
 
368
 
                if ( isset( $_GET['searchaction'] ) ) {
369
 
                        if ( 'name' == $_GET['searchaction'] ) {
370
 
                                $query .= " AND ( {$wpdb->blogs}.domain LIKE '%{$like_s}%' OR {$wpdb->blogs}.path LIKE '%{$like_s}%' ) ";
371
 
                        } elseif ( 'id' == $_GET['searchaction'] ) {
372
 
                                $query .= " AND {$wpdb->blogs}.blog_id = '{$like_s}' ";
373
 
                        } elseif ( 'ip' == $_GET['searchaction'] ) {
374
 
                                $query = "SELECT *
375
 
                                        FROM {$wpdb->blogs}, {$wpdb->registration_log}
376
 
                                        WHERE site_id = '{$wpdb->siteid}'
377
 
                                        AND {$wpdb->blogs}.blog_id = {$wpdb->registration_log}.blog_id
378
 
                                        AND {$wpdb->registration_log}.IP LIKE ('%{$like_s}%')";
379
 
                        }
380
 
                }
381
 
 
382
 
                $order_by = isset( $_GET['sortby'] ) ? $_GET['sortby'] : 'id';
383
 
                if ( $order_by == 'registered' ) {
384
 
                        $query .= ' ORDER BY registered ';
385
 
                } elseif ( $order_by == 'lastupdated' ) {
386
 
                        $query .= ' ORDER BY last_updated ';
387
 
                } elseif ( $order_by == 'blogname' ) {
388
 
                        $query .= ' ORDER BY domain ';
389
 
                } else {
390
 
                        $order_by = 'id';
391
 
                        $query .= " ORDER BY {$wpdb->blogs}.blog_id ";
392
 
                }
393
 
 
394
 
                $order = ( isset( $_GET['order'] ) && 'DESC' == $_GET['order'] ) ? "DESC" : "ASC";
395
 
                $query .= $order;
396
 
 
397
 
                $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT(blog_id)', $query ) );
398
 
 
399
 
                $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
400
 
                $blog_list = $wpdb->get_results( $query, ARRAY_A );
401
 
 
402
 
                $num_pages = ceil($total / $per_page);
403
 
                $page_links = paginate_links( array(
404
 
                        'base' => add_query_arg( 'paged', '%#%' ),
405
 
                        'format' => '',
406
 
                        'prev_text' => __( '&laquo;' ),
407
 
                        'next_text' => __( '&raquo;' ),
408
 
                        'total' => $num_pages,
409
 
                        'current' => $pagenum
410
 
                ));
411
 
 
412
 
                if ( empty( $_GET['mode'] ) )
413
 
                        $mode = 'list';
414
 
                else
415
 
                        $mode = esc_attr( $_GET['mode'] );
416
 
                ?>
417
 
 
418
 
                <div class="wrap">
419
 
                <?php screen_icon(); ?>
420
 
                <h2><?php _e('Sites') ?>
421
 
                <a href="#form-add-site" class="button add-new-h2"><?php echo esc_html_x( 'Add New', 'sites' ); ?></a>
422
 
                <?php
423
 
                if ( isset( $_GET['s'] ) && $_GET['s'] )
424
 
                printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
425
 
                ?>
426
 
                </h2>
427
 
 
428
 
                <form action="ms-sites.php" method="get" id="ms-search">
429
 
                <p class="search-box">
430
 
                <input type="hidden" name="action" value="blogs" />
431
 
                <input type="text" name="s" value="<?php echo esc_attr( $s ); ?>" />
432
 
                <input type="submit" class="button" value="<?php esc_attr_e( 'Search Site by' ) ?>" />
433
 
                <select name="searchaction">
434
 
                        <option value="name" selected="selected"><?php _e( 'Name' ); ?></option>
435
 
                        <option value="id"><?php _e( 'ID' ); ?></option>
436
 
                        <option value="ip"><?php _e( 'IP address' ); ?></option>
437
 
                </select>
438
 
                </p>
439
 
                </form>
440
 
 
441
 
                <form id="form-site-list" action="ms-edit.php?action=allblogs" method="post">
442
 
                <input type="hidden" name="mode" value="<?php echo esc_attr( $mode ); ?>" />
443
 
                <div class="tablenav">
444
 
                <div class="alignleft actions">
445
 
                        <select name="action">
446
 
                                <option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
447
 
                                <option value="delete"><?php _e( 'Delete' ); ?></option>
448
 
                                <option value="spam"><?php _ex( 'Mark as Spam', 'site' ); ?></option>
449
 
                                <option value="notspam"><?php _ex( 'Not Spam', 'site' ); ?></option>
450
 
                        </select>
451
 
                        <input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction" id="doaction" class="button-secondary action" />
452
 
                        <?php wp_nonce_field( 'bulk-ms-sites', '_wpnonce_bulk-ms-sites' ); ?>
453
 
                </div>
454
 
 
455
 
                <?php if ( $page_links ) { ?>
456
 
                <div class="tablenav-pages">
457
 
                <?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
458
 
                number_format_i18n( ( $pagenum - 1 ) * $per_page + 1 ),
459
 
                number_format_i18n( min( $pagenum * $per_page, $total ) ),
460
 
                number_format_i18n( $total ),
461
 
                $page_links
462
 
                ); echo $page_links_text; ?>
463
 
                </div>
464
 
                <?php } ?>
465
 
 
466
 
                <div class="view-switch">
467
 
                        <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>
468
 
                        <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>
469
 
                </div>
470
 
 
471
 
                </div>
472
 
 
473
 
                <div class="clear"></div>
474
 
 
475
 
                <?php
476
 
                // define the columns to display, the syntax is 'internal name' => 'display name'
477
 
                $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
478
 
                $sites_columns = array(
479
 
                        'id'           => __( 'ID' ),
480
 
                        'blogname'     => $blogname_columns,
481
 
                        'lastupdated'  => __( 'Last Updated'),
482
 
                        'registered'   => _x( 'Registered', 'site' ),
483
 
                        'users'        => __( 'Users' )
484
 
                );
485
 
 
486
 
                if ( has_filter( 'wpmublogsaction' ) )
487
 
                        $sites_columns['plugins'] = __( 'Actions' );
488
 
 
489
 
                $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns );
490
 
                ?>
491
 
 
492
 
                <table class="widefat">
493
 
                        <thead>
494
 
                                <tr>
495
 
                                <th class="manage-column column-cb check-column" id="cb" scope="col">
496
 
                                        <input type="checkbox" />
497
 
                                </th>
498
 
                                <?php
499
 
                                $col_url = '';
500
 
                                foreach($sites_columns as $column_id => $column_display_name) {
501
 
                                        $column_link = "<a href='";
502
 
                                        $order2 = '';
503
 
                                        if ( $order_by == $column_id )
504
 
                                                $order2 = ( $order == 'DESC' ) ? 'ASC' : 'DESC';
505
 
 
506
 
                                        $column_link .= esc_url( add_query_arg( array( 'order' => $order2, 'paged' => $pagenum, 'sortby' => $column_id ), remove_query_arg( array('action', 'updated'), $_SERVER['REQUEST_URI'] ) ) );
507
 
                                        $column_link .= "'>{$column_display_name}</a>";
508
 
                                        $col_url .= '<th scope="col">' . ( ( $column_id == 'users' || $column_id == 'plugins' ) ? $column_display_name : $column_link ) . '</th>';
509
 
                                }
510
 
                                echo $col_url ?>
511
 
                                </tr>
512
 
                        </thead>
513
 
                        <tfoot>
514
 
                                <tr>
515
 
                                <th class="manage-column column-cb check-column" id="cb1" scope="col">
516
 
                                        <input type="checkbox" />
517
 
                                </th>
518
 
                                        <?php echo $col_url ?>
519
 
                                </tr>
520
 
                        </tfoot>
521
 
                        <tbody id="the-site-list" class="list:site">
522
 
                        <?php
523
 
                        $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' ) ) );
524
 
                        if ( $blog_list ) {
525
 
                                $class = '';
526
 
                                foreach ( $blog_list as $blog ) {
527
 
                                        $class = ( 'alternate' == $class ) ? '' : 'alternate';
528
 
                                        reset( $status_list );
529
 
 
530
 
                                        $blog_states = array();
531
 
                                        foreach ( $status_list as $status => $col ) {
532
 
                                                if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) {
533
 
                                                        $class = $col[0];
534
 
                                                        $blog_states[] = $col[1];
535
 
                                                }
536
 
                                        }
537
 
                                        $blog_state = '';
538
 
                                        if ( ! empty( $blog_states ) ) {
539
 
                                                $state_count = count( $blog_states );
540
 
                                                $i = 0;
541
 
                                                $blog_state .= ' - ';
542
 
                                                foreach ( $blog_states as $state ) {
543
 
                                                        ++$i;
544
 
                                                        ( $i == $state_count ) ? $sep = '' : $sep = ', ';
545
 
                                                        $blog_state .= "<span class='post-state'>$state$sep</span>";
546
 
                                                }
547
 
                                        }
548
 
                                        echo "<tr class='$class'>";
549
 
 
550
 
                                        $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
551
 
                                        foreach ( $sites_columns as $column_name=>$column_display_name ) {
552
 
                                                switch ( $column_name ) {
553
 
                                                        case 'id': ?>
554
 
                                                                <th scope="row" class="check-column">
555
 
                                                                        <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" />
556
 
                                                                </th>
557
 
                                                                <th valign="top" scope="row">
558
 
                                                                        <?php echo $blog['blog_id'] ?>
559
 
                                                                </th>
560
 
                                                        <?php
561
 
                                                        break;
562
 
 
563
 
                                                        case 'blogname': ?>
564
 
                                                                <td class="column-title">
565
 
                                                                        <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>
566
 
                                                                        <?php
567
 
                                                                        if ( 'list' != $mode )
568
 
                                                                                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>';
569
 
 
570
 
                                                                        // Preordered.
571
 
                                                                        $actions = array(
572
 
                                                                                'edit' => '', 'backend' => '',
573
 
                                                                                'activate' => '', 'deactivate' => '',
574
 
                                                                                'archive' => '', 'unarchive' => '',
575
 
                                                                                'spam' => '', 'unspam' => '',
576
 
                                                                                'delete' => '',
577
 
                                                                                'visit' => '',
578
 
                                                                        );
579
 
 
580
 
                                                                        $actions['edit']        = '<span class="edit"><a href="' . esc_url( admin_url( 'ms-sites.php?action=editblog&amp;id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>';
581
 
                                                                        $actions['backend']     = "<span class='backend'><a href='" . esc_url( get_admin_url($blog['blog_id']) ) . "' class='edit'>" . __( 'Backend' ) . '</a></span>';
582
 
                                                                        if ( $current_site->blog_id != $blog['blog_id'] ) {
583
 
                                                                                if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' )
584
 
                                                                                        $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>';
585
 
                                                                                else
586
 
                                                                                        $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>';
587
 
 
588
 
                                                                                if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' )
589
 
                                                                                        $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>';
590
 
                                                                                else
591
 
                                                                                        $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>';
592
 
 
593
 
                                                                                if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' )
594
 
                                                                                        $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>';
595
 
                                                                                else
596
 
                                                                                        $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>';
597
 
 
598
 
                                                                                $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>';
599
 
                                                                        }
600
 
 
601
 
                                                                        $actions['visit']       = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'] ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>';
602
 
                                                                        $actions = array_filter( $actions );
603
 
                                                                        if ( count( $actions ) ) : ?>
604
 
                                                                        <div class="row-actions">
605
 
                                                                                <?php echo implode( ' | ', $actions ); ?>
606
 
                                                                        </div>
607
 
                                                                        <?php endif; ?>
608
 
                                                                </td>
609
 
                                                        <?php
610
 
                                                        break;
611
 
 
612
 
                                                        case 'lastupdated': ?>
613
 
                                                                <td valign="top">
614
 
                                                                        <?php
615
 
                                                                        if ( 'list' == $mode )
616
 
                                                                                $date = 'Y/m/d';
617
 
                                                                        else
618
 
                                                                                $date = 'Y/m/d \<\b\r \/\> g:i:s a';
619
 
                                                                        echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( __( $date ), $blog['last_updated'] ); ?>
620
 
                                                                </td>
621
 
                                                        <?php
622
 
                                                        break;
623
 
                                                case 'registered': ?>
624
 
                                                                <td valign="top">
625
 
                                                                <?php
626
 
                                                                if ( $blog['registered'] == '0000-00-00 00:00:00' )
627
 
                                                                        echo '&#x2014;';
628
 
                                                                else
629
 
                                                                        echo mysql2date( __( $date ), $blog['registered'] );
630
 
                                                                ?>
631
 
                                                                </td>
632
 
                                                <?php
633
 
                                                break;
634
 
                                                        case 'users': ?>
635
 
                                                                <td valign="top">
636
 
                                                                        <?php
637
 
                                                                        $blogusers = get_users_of_blog( $blog['blog_id'] );
638
 
                                                                        if ( is_array( $blogusers ) ) {
639
 
                                                                                $blogusers_warning = '';
640
 
                                                                                if ( count( $blogusers ) > 5 ) {
641
 
                                                                                        $blogusers = array_slice( $blogusers, 0, 5 );
642
 
                                                                                        $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( get_admin_url( $blog['blog_id'], 'users.php' ) ) . '">' . __( 'More' ) . '</a>';
643
 
                                                                                }
644
 
                                                                                foreach ( $blogusers as $key => $val ) {
645
 
                                                                                        echo '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $val->user_id ) ) . '">' . esc_html( $val->user_login ) . '</a> ';
646
 
                                                                                        if ( 'list' != $mode )
647
 
                                                                                                echo '(' . $val->user_email . ')';
648
 
                                                                                        echo '<br />';
649
 
                                                                                }
650
 
                                                                                if ( $blogusers_warning != '' )
651
 
                                                                                        echo '<strong>' . $blogusers_warning . '</strong><br />';
652
 
                                                                        }
653
 
                                                                        ?>
654
 
                                                                </td>
655
 
                                                        <?php
656
 
                                                        break;
657
 
 
658
 
                                                        case 'plugins': ?>
659
 
                                                                <?php if ( has_filter( 'wpmublogsaction' ) ) { ?>
660
 
                                                                <td valign="top">
661
 
                                                                        <?php do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
662
 
                                                                </td>
663
 
                                                                <?php } ?>
664
 
                                                        <?php break;
665
 
 
666
 
                                                        default: ?>
667
 
                                                                <?php if ( has_filter( 'manage_blogs_custom_column' ) ) { ?>
668
 
                                                                <td valign="top">
669
 
                                                                        <?php do_action( 'manage_blogs_custom_column', $column_name, $blog['blog_id'] ); ?>
670
 
                                                                </td>
671
 
                                                                <?php } ?>
672
 
                                                        <?php break;
673
 
                                                }
674
 
                                        }
675
 
                                        ?>
676
 
                                        </tr>
677
 
                                        <?php
678
 
                                }
679
 
                        } else { ?>
680
 
                                <tr>
681
 
                                        <td colspan="<?php echo (int) count( $sites_columns ); ?>"><?php _e( 'No sites found.' ) ?></td>
682
 
                                </tr>
683
 
                        <?php
684
 
                        } // end if ($blogs)
685
 
                        ?>
686
 
 
687
 
                        </tbody>
688
 
                </table>
689
 
                <div class="tablenav">
690
 
                        <?php
691
 
                        if ( $page_links )
692
 
                                echo "<div class='tablenav-pages'>$page_links_text</div>";
693
 
                        ?>
694
 
 
695
 
                        <div class="alignleft actions">
696
 
                        <select name="action2">
697
 
                                <option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
698
 
                                <option value="delete"><?php _e( 'Delete' ); ?></option>
699
 
                                <option value="spam"><?php _ex( 'Mark as Spam', 'site' ); ?></option>
700
 
                                <option value="notspam"><?php _ex( 'Not Spam', 'site' ); ?></option>
701
 
                        </select>
702
 
                        <input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
703
 
                        </div>
704
 
                        <br class="clear" />
705
 
                </div>
706
 
 
707
 
                </form>
708
 
                </div>
709
 
 
710
 
                <div id="form-add-site" class="wrap">
711
 
                        <h3><?php _e( 'Add Site' ) ?></h3>
712
 
                        <form method="post" action="ms-edit.php?action=addblog">
713
 
                                <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
714
 
                                <table class="form-table">
715
 
                                        <tr class="form-field form-required">
716
 
                                                <th scope="row"><?php _e( 'Site Address' ) ?></th>
717
 
                                                <td>
718
 
                                                <?php if ( is_subdomain_install() ) { ?>
719
 
                                                        <input name="blog[domain]" type="text" class="regular-text" title="<?php _e( 'Domain' ) ?>"/>.<?php echo preg_replace( '|^www\.|', '', $current_site->domain );?>
720
 
                                                <?php } else {
721
 
                                                        echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php _e( 'Domain' ) ?>"/>
722
 
                                                <?php }
723
 
                                                echo '<p>' . __( 'Only the characters a-z and 0-9 recommended.' ) . '</p>';
724
 
                                                ?>
725
 
                                                </td>
726
 
                                        </tr>
727
 
                                        <tr class="form-field form-required">
728
 
                                                <th scope="row"><?php _e( 'Site Title' ) ?></th>
729
 
                                                <td><input name="blog[title]" type="text" class="regular-text" title="<?php _e( 'Title' ) ?>"/></td>
730
 
                                        </tr>
731
 
                                        <tr class="form-field form-required">
732
 
                                                <th scope="row"><?php _e( 'Admin Email' ) ?></th>
733
 
                                                <td><input name="blog[email]" type="text" class="regular-text" title="<?php _e( 'Email' ) ?>"/></td>
734
 
                                        </tr>
735
 
                                        <tr class="form-field">
736
 
                                                <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>
737
 
                                        </tr>
738
 
                                </table>
739
 
                                <p class="submit">
740
 
                                        <input class="button" type="submit" name="go" value="<?php esc_attr_e( 'Add Site' ) ?>" /></p>
741
 
                        </form>
742
 
                </div>
743
 
                <?php
744
 
        break;
745
 
} // end switch( $action )
746
 
 
747
 
include( './admin-footer.php' ); ?>
 
12
wp_redirect( network_admin_url('sites.php') );
 
13
exit;
 
14
 
 
15
?>