Wordpress 3.1
[autoinstalls/wordpress.git] / wp-admin / network / edit.php
1 <?php
2 /**
3  * Action handler for Multisite administration panels.
4  *
5  * @package WordPress
6  * @subpackage Multisite
7  * @since 3.0.0
8  */
9
10 /** Load WordPress Administration Bootstrap */
11 require_once( './admin.php' );
12
13 if ( ! is_multisite() )
14         wp_die( __( 'Multisite support is not enabled.' ) );
15
16 if ( empty( $_GET['action'] ) ) {
17         wp_redirect( admin_url( 'index.php' ) );
18         exit;
19 }
20
21 function confirm_delete_users( $users ) {
22         $current_user = wp_get_current_user();
23         if ( !is_array( $users ) )
24                 return false;
25
26         screen_icon();
27         ?>
28         <h2><?php esc_html_e( 'Users' ); ?></h2>
29         <p><?php _e( 'Transfer or delete posts and links before deleting users.' ); ?></p>
30         <form action="edit.php?action=dodelete" method="post">
31         <input type="hidden" name="dodelete" />
32         <?php
33         wp_nonce_field( 'ms-users-delete' );
34         $site_admins = get_super_admins();
35         $admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>";
36
37         foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
38                 if ( $val != '' && $val != '0' ) {
39                         $delete_user = new WP_User( $val );
40
41                         if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
42                                 wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
43
44                         if ( in_array( $delete_user->user_login, $site_admins ) )
45                                 wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network admnistrator.' ), $delete_user->user_login ) );
46
47                         echo "<input type='hidden' name='user[]' value='{$val}'/>\n";
48                         $blogs = get_blogs_of_user( $val, true );
49
50                         if ( !empty( $blogs ) ) {
51                                 ?>
52                                 <br /><fieldset><p><legend><?php printf( __( "What should be done with posts and links owned by <em>%s</em>?" ), $delete_user->user_login ); ?></legend></p>
53                                 <?php
54                                 foreach ( (array) $blogs as $key => $details ) {
55                                         $blog_users = get_users( array( 'blog_id' => $details->userblog_id ) );
56                                         if ( is_array( $blog_users ) && !empty( $blog_users ) ) {
57                                                 $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
58                                                 $user_dropdown = "<select name='blog[$val][{$key}]'>";
59                                                 $user_list = '';
60                                                 foreach ( $blog_users as $user ) {
61                                                         if ( ! in_array( $user->ID, $allusers ) )
62                                                                 $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
63                                                 }
64                                                 if ( '' == $user_list )
65                                                         $user_list = $admin_out;
66                                                 $user_dropdown .= $user_list;
67                                                 $user_dropdown .= "</select>\n";
68                                                 ?>
69                                                 <ul style="list-style:none;">
70                                                         <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
71                                                         <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" />
72                                                         <?php _e( 'Delete all posts and links.' ); ?></label></li>
73                                                         <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" />
74                                                         <?php echo __( 'Attribute all posts and links to:' ) . '</label>' . $user_dropdown; ?></li>
75                                                 </ul>
76                                                 <?php
77                                         }
78                                 }
79                                 echo "</fieldset>";
80                         }
81                 }
82         }
83
84         submit_button( __('Confirm Deletion'), 'delete' );
85         ?>
86         </form>
87     <?php
88         return true;
89 }
90
91 do_action( 'wpmuadminedit' , '');
92
93 if ( isset( $_GET['id' ]) )
94         $id = intval( $_GET['id'] );
95 elseif ( isset( $_POST['id'] ) )
96         $id = intval( $_POST['id'] );
97
98 switch ( $_GET['action'] ) {
99         case 'siteoptions':
100                 check_admin_referer( 'siteoptions' );
101                 if ( ! current_user_can( 'manage_network_options' ) )
102                         wp_die( __( 'You do not have permission to access this page.' ) );
103
104                 if ( empty( $_POST ) )
105                         wp_die( sprintf( __( 'You probably need to go back to the <a href="%s">options page</a>.' ), esc_url( admin_url( 'settings.php' ) ) ) );
106
107                 if ( isset($_POST['WPLANG']) && ( '' === $_POST['WPLANG'] || in_array( $_POST['WPLANG'], get_available_languages() ) ) )
108                         update_site_option( 'WPLANG', $_POST['WPLANG'] );
109
110                 if ( is_email( $_POST['admin_email'] ) )
111                         update_site_option( 'admin_email', $_POST['admin_email'] );
112
113                 $illegal_names = split( ' ', $_POST['illegal_names'] );
114                 foreach ( (array) $illegal_names as $name ) {
115                         $name = trim( $name );
116                         if ( $name != '' )
117                                 $names[] = trim( $name );
118                 }
119                 update_site_option( 'illegal_names', $names );
120
121                 if ( $_POST['limited_email_domains'] != '' ) {
122                         $limited_email_domains = str_replace( ' ', "\n", $_POST['limited_email_domains'] );
123                         $limited_email_domains = split( "\n", stripslashes( $limited_email_domains ) );
124                         $limited_email = array();
125                         foreach ( (array) $limited_email_domains as $domain ) {
126                                         $domain = trim( $domain );
127                                 if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
128                                         $limited_email[] = trim( $domain );
129                         }
130                         update_site_option( 'limited_email_domains', $limited_email );
131                 } else {
132                         update_site_option( 'limited_email_domains', '' );
133                 }
134
135                 if ( $_POST['banned_email_domains'] != '' ) {
136                         $banned_email_domains = split( "\n", stripslashes( $_POST['banned_email_domains'] ) );
137                         $banned = array();
138                         foreach ( (array) $banned_email_domains as $domain ) {
139                                 $domain = trim( $domain );
140                                 if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
141                                         $banned[] = trim( $domain );
142                         }
143                         update_site_option( 'banned_email_domains', $banned );
144                 } else {
145                         update_site_option( 'banned_email_domains', '' );
146                 }
147
148                 $options = array( 'registrationnotification', 'registration', 'add_new_users', 'menu_items', 'mu_media_buttons', 'upload_space_check_disabled', 'blog_upload_space', 'upload_filetypes', 'site_name', 'first_post', 'first_page', 'first_comment', 'first_comment_url', 'first_comment_author', 'welcome_email', 'welcome_user_email', 'fileupload_maxk', 'global_terms_enabled' );
149                 $checked_options = array( 'mu_media_buttons' => array(), 'menu_items' => array(), 'registrationnotification' => 'no', 'upload_space_check_disabled' => 1, 'add_new_users' => 0 );
150                 foreach ( $checked_options as $option_name => $option_unchecked_value ) {
151                         if ( ! isset( $_POST[$option_name] ) )
152                                 $_POST[$option_name] = $option_unchecked_value;
153                 }
154                 foreach ( $options as $option_name ) {
155                         if ( ! isset($_POST[$option_name]) )
156                                 continue;
157                         $value = stripslashes_deep( $_POST[$option_name] );
158                         update_site_option( $option_name, $value );
159                 }
160
161                 // Update more options here
162                 do_action( 'update_wpmu_options' );
163
164                 wp_redirect( add_query_arg( 'updated', 'true', network_admin_url( 'settings.php' ) ) );
165                 exit();
166         break;
167
168         case 'updateblog':
169                 // No longer used.
170         break;
171
172         case 'deleteblog':
173                 check_admin_referer('deleteblog');
174                 if ( ! ( current_user_can( 'manage_sites' ) && current_user_can( 'delete_sites' ) ) )
175                         wp_die( __( 'You do not have permission to access this page.' ) );
176
177                 if ( $id != '0' && $id != $current_site->blog_id && current_user_can( 'delete_site', $id ) ) {
178                         wpmu_delete_blog( $id, true );
179                         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) );
180                 } else {
181                         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'not_deleted' ), wp_get_referer() ) );
182                 }
183
184                 exit();
185         break;
186
187         case 'allblogs':
188                 if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
189                         check_admin_referer( 'bulk-sites' );
190
191                         if ( ! current_user_can( 'manage_sites' ) )
192                                 wp_die( __( 'You do not have permission to access this page.' ) );
193
194                         if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
195                                 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
196
197                         $blogfunction = '';
198
199                         foreach ( (array) $_POST['allblogs'] as $key => $val ) {
200                                 if ( $val != '0' && $val != $current_site->blog_id ) {
201                                         switch ( $doaction ) {
202                                                 case 'delete':
203                                                         if ( ! current_user_can( 'delete_site', $val ) )
204                                                                 wp_die( __( 'You are not allowed to delete the site.' ) );
205                                                         $blogfunction = 'all_delete';
206                                                         wpmu_delete_blog( $val, true );
207                                                 break;
208
209                                                 case 'spam':
210                                                         $blogfunction = 'all_spam';
211                                                         update_blog_status( $val, 'spam', '1' );
212                                                         set_time_limit( 60 );
213                                                 break;
214
215                                                 case 'notspam':
216                                                         $blogfunction = 'all_notspam';
217                                                         update_blog_status( $val, 'spam', '0' );
218                                                         set_time_limit( 60 );
219                                                 break;
220                                         }
221                                 } else {
222                                         wp_die( __( 'You are not allowed to change the current site.' ) );
223                                 }
224                         }
225
226                         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $blogfunction ), wp_get_referer() ) );
227                 } else {
228                         wp_redirect( network_admin_url( 'sites.php' ) );
229                 }
230                 exit();
231         break;
232
233         case 'archiveblog':
234                 check_admin_referer( 'archiveblog' );
235                 if ( ! current_user_can( 'manage_sites' ) )
236                         wp_die( __( 'You do not have permission to access this page.' ) );
237
238                 update_blog_status( $id, 'archived', '1' );
239                 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'archive' ), wp_get_referer() ) );
240                 exit();
241         break;
242
243         case 'unarchiveblog':
244                 check_admin_referer( 'unarchiveblog' );
245                 if ( ! current_user_can( 'manage_sites' ) )
246                         wp_die( __( 'You do not have permission to access this page.' ) );
247
248                 update_blog_status( $id, 'archived', '0' );
249                 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unarchive' ), wp_get_referer() ) );
250                 exit();
251         break;
252
253         case 'activateblog':
254                 check_admin_referer( 'activateblog' );
255                 if ( ! current_user_can( 'manage_sites' ) )
256                         wp_die( __( 'You do not have permission to access this page.' ) );
257
258                 update_blog_status( $id, 'deleted', '0' );
259                 do_action( 'activate_blog', $id );
260                 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'activate' ), wp_get_referer() ) );
261                 exit();
262         break;
263
264         case 'deactivateblog':
265                 check_admin_referer( 'deactivateblog' );
266                 if ( ! current_user_can( 'manage_sites' ) )
267                         wp_die( __( 'You do not have permission to access this page.' ) );
268
269                 do_action( 'deactivate_blog', $id );
270                 update_blog_status( $id, 'deleted', '1' );
271                 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'deactivate' ), wp_get_referer() ) );
272                 exit();
273         break;
274
275         case 'unspamblog':
276                 check_admin_referer( 'unspamblog' );
277                 if ( ! current_user_can( 'manage_sites' ) )
278                         wp_die( __( 'You do not have permission to access this page.' ) );
279
280                 update_blog_status( $id, 'spam', '0' );
281                 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unspam' ), wp_get_referer() ) );
282                 exit();
283         break;
284
285         case 'spamblog':
286                 check_admin_referer( 'spamblog' );
287                 if ( ! current_user_can( 'manage_sites' ) )
288                         wp_die( __( 'You do not have permission to access this page.' ) );
289
290                 update_blog_status( $id, 'spam', '1' );
291                 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'spam' ), wp_get_referer() ) );
292                 exit();
293         break;
294
295         case 'unmatureblog':
296                 check_admin_referer( 'unmatureblog' );
297                 if ( ! current_user_can( 'manage_sites' ) )
298                         wp_die( __( 'You do not have permission to access this page.' ) );
299
300                 update_blog_status( $id, 'mature', '0' );
301                 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unmature' ), wp_get_referer() ) );
302                 exit();
303         break;
304
305         case 'matureblog':
306                 check_admin_referer( 'matureblog' );
307                 if ( ! current_user_can( 'manage_sites' ) )
308                         wp_die( __( 'You do not have permission to access this page.' ) );
309
310                 update_blog_status( $id, 'mature', '1' );
311                 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'mature' ), wp_get_referer() ) );
312                 exit();
313         break;
314
315         // Common
316         case 'confirm':
317                 check_admin_referer( 'confirm' );
318                 if ( !headers_sent() ) {
319                         nocache_headers();
320                         header( 'Content-Type: text/html; charset=utf-8' );
321                 }
322                 if ( $current_site->blog_id == $id )
323                         wp_die( __( 'You are not allowed to change the current site.' ) );
324                 ?>
325                 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
326                 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
327                         <head>
328                                 <title><?php _e( 'WordPress &rsaquo; Confirm your action' ); ?></title>
329
330                                 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
331                                 <?php
332                                 wp_admin_css( 'install', true );
333                                 wp_admin_css( 'ie', true );
334                                 ?>
335                         </head>
336                         <body>
337                                 <h1 id="logo"><img alt="WordPress" src="<?php echo esc_attr( admin_url( 'images/wordpress-logo.png' ) ); ?>" /></h1>
338                                 <form action="edit.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
339                                         <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
340                                         <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
341                                         <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
342                                         <?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
343                                         <p><?php echo esc_html( stripslashes( $_GET['msg'] ) ); ?></p>
344                                         <?php submit_button( __('Confirm'), 'button' ); ?>
345                                 </form>
346                         </body>
347                 </html>
348                 <?php
349                 exit();
350         break;
351
352         // Users
353         case 'deleteuser':
354                 if ( ! current_user_can( 'manage_network_users' ) )
355                         wp_die( __( 'You do not have permission to access this page.' ) );
356
357                 check_admin_referer( 'deleteuser' );
358
359                 if ( $id != '0' && $id != '1' ) {
360                         $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
361                         $title = __( 'Users' );
362                         $parent_file = 'users.php';
363                         require_once( '../admin-header.php' );
364                         echo '<div class="wrap">';
365                         confirm_delete_users( $_POST['allusers'] );
366                         echo '</div>';
367             require_once( '../admin-footer.php' );
368                 } else {
369                         wp_redirect( network_admin_url( 'users.php' ) );
370                 }
371                 exit();
372         break;
373
374         case 'allusers':
375                 if ( !current_user_can( 'manage_network_users' ) )
376                         wp_die( __( 'You do not have permission to access this page.' ) );
377
378                 if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
379                         check_admin_referer( 'bulk-users-network' );
380
381                         if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
382                                 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
383
384                         $userfunction = '';
385
386                         foreach ( (array) $_POST['allusers'] as $key => $val ) {
387                                 if ( !empty( $val ) ) {
388                                         switch ( $doaction ) {
389                                                 case 'delete':
390                                                         if ( ! current_user_can( 'delete_users' ) )
391                                                                 wp_die( __( 'You do not have permission to access this page.' ) );
392                                                         $title = __( 'Users' );
393                                                         $parent_file = 'users.php';
394                                                         require_once( '../admin-header.php' );
395                                                         echo '<div class="wrap">';
396                                                         confirm_delete_users( $_POST['allusers'] );
397                                                         echo '</div>';
398                                             require_once( '../admin-footer.php' );
399                                             exit();
400                                         break;
401
402                                                 case 'spam':
403                                                         $user = new WP_User( $val );
404                                                         if ( in_array( $user->user_login, get_super_admins() ) )
405                                                                 wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
406
407                                                         $userfunction = 'all_spam';
408                                                         $blogs = get_blogs_of_user( $val, true );
409                                                         foreach ( (array) $blogs as $key => $details ) {
410                                                                 if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
411                                                                         update_blog_status( $details->userblog_id, 'spam', '1' );
412                                                         }
413                                                         update_user_status( $val, 'spam', '1' );
414                                                 break;
415
416                                                 case 'notspam':
417                                                         $userfunction = 'all_notspam';
418                                                         $blogs = get_blogs_of_user( $val, true );
419                                                         foreach ( (array) $blogs as $key => $details )
420                                                                 update_blog_status( $details->userblog_id, 'spam', '0' );
421
422                                                         update_user_status( $val, 'spam', '0' );
423                                                 break;
424                                         }
425                                 }
426                         }
427
428                         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
429                 } else {
430                         $location = network_admin_url( 'users.php' );
431
432                         if ( ! empty( $_REQUEST['paged'] ) )
433                                 $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
434                         wp_redirect( $location );
435                 }
436                 exit();
437         break;
438
439         case 'dodelete':
440                 check_admin_referer( 'ms-users-delete' );
441                 if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
442                         wp_die( __( 'You do not have permission to access this page.' ) );
443
444                 if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
445                         foreach ( $_POST['blog'] as $id => $users ) {
446                                 foreach ( $users as $blogid => $user_id ) {
447                                         if ( ! current_user_can( 'delete_user', $id ) )
448                                                 continue;
449
450                                         if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
451                                                 remove_user_from_blog( $id, $blogid, $user_id );
452                                         else
453                                                 remove_user_from_blog( $id, $blogid );
454                                 }
455                         }
456                 }
457                 $i = 0;
458                 if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
459                         foreach( $_POST['user'] as $id ) {
460                                 if ( ! current_user_can( 'delete_user', $id ) )
461                                         continue;
462                                 wpmu_delete_user( $id );
463                                 $i++;
464                         }
465
466                 if ( $i == 1 )
467                         $deletefunction = 'delete';
468                 else
469                         $deletefunction = 'all_delete';
470
471                 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
472                 exit();
473         break;
474
475         default:
476                 // Let plugins use us as a post handler easily
477                 do_action( 'network_admin_edit_' . $_GET['action'] );
478                 wp_redirect( network_admin_url( 'index.php' ) );
479                 exit();
480         break;
481 }
482 ?>