Changeset 12865
- Timestamp:
- 01/27/2010 01:48:37 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/network.php
r12859 r12865 3 3 * Network settings administration panel. 4 4 * 5 * @since 3.0 5 * A multi-step process allowing the user to enable a network of WordPress sites. 6 * 7 * @since 3.0.0 6 8 * 7 9 * @package WordPress … … 10 12 11 13 /** WordPress Administration Bootstrap */ 12 require_once( './admin.php');14 require_once( './admin.php' ); 13 15 14 16 if ( ! is_super_admin() ) 15 wp_die( __('You do not have sufficient permissions to manage options for this blog.'));16 17 $title = __( 'Network Settings');17 wp_die( __( 'You do not have sufficient permissions to manage options for this blog.' ) ); 18 19 $title = __( 'Network Settings' ); 18 20 $parent_file = 'tools.php'; 19 21 20 add_contextual_help($current_screen, __('<a href="http://codex.wordpress.org/Settings_Network_SubPanel" target="_blank">Network Settings</a>')); 21 22 include('./admin-header.php'); 23 /* 24 This option panel does not save data to the options table. 25 It contains a multi-step process allowing the user to enable a network of WordPress sites. 26 */ 27 28 $dirs = array( substr( ABSPATH, 0, -1), ABSPATH . "wp-content" ); 22 add_contextual_help( $current_screen, __( '<a href="http://codex.wordpress.org/Settings_Network_SubPanel" target="_blank">Network Settings</a>') ); 23 24 include( './admin-header.php' ); 25 26 $dirs = array( substr( ABSPATH, 0, -1 ), ABSPATH . 'wp-content' ); 29 27 ?> 30 28 <div class="wrap"> … … 34 32 <form method="post" action="network.php"> 35 33 <?php 34 /** 35 * Prints summary of server statistics in preparation for setting up a network. 36 * 37 * @since 3.0.0 38 */ 36 39 function filestats( $err ) { 37 40 ?> 38 <h2><?php esc_html_e( 'Server Summary'); ?></h2>39 <p><?php _e( 'If you post a message to the WordPress support forum at <a target="_blank" href="http://wordpress.org/support/">http://wordpress.org/support/</a> then copy and paste the following information into your message:'); ?></p>41 <h2><?php esc_html_e( 'Server Summary' ); ?></h2> 42 <p><?php _e( 'If you post a message to the WordPress support forum at <a target="_blank" href="http://wordpress.org/support/">http://wordpress.org/support/</a> then copy and paste the following information into your message:' ); ?></p> 40 43 <blockquote style="background: #eee; border: 1px solid #333; padding: 5px;"> 41 <br /><strong><?php echo __('ERROR:') . " $err"; ?></strong><br />44 <br /><strong><?php printf( __( 'ERROR: %s' ), $err ); ?></strong><br /> 42 45 <?php 43 46 clearstatcache(); 44 $files = array( "htaccess.dist", ".htaccess");47 $files = array( 'htaccess.dist', '.htaccess' ); 45 48 46 49 $indent = ' '; 47 50 foreach ( (array) $files as $val ) { 48 51 $stats = @stat( $val ); 49 if ( $stats ) {52 if ( $stats ) { 50 53 ?> 51 54 <h2><?php echo esc_html( $val ); ?></h2> 52 <?php echo $indent . sprintf( __( 'uid/gid: %1$s/%2$s'), $stats[ 'uid' ], $stats[ 'gid'] ); ?><br />53 <?php echo $indent . sprintf( __( 'size: %s'), $stats['size'] ); ?><br/>54 <?php echo $indent . sprintf( __( 'perms: %s'), substr( sprintf('%o', fileperms( $val ) ), -4 ) ); ?><br/>55 <?php echo $indent . sprintf( __( 'readable: %s'), is_readable( $val ) ? __('yes') : __('no') ); ?><br/>56 <?php echo $indent . sprintf( __( 'writeable: %s'), is_writeable( $val ) ? __('yes') : __('no') ); ?><br/>57 <?php 58 } elseif ( ! file_exists( $val ) ) {55 <?php echo $indent . sprintf( __( 'uid/gid: %1$s/%2$s' ), $stats['uid'], $stats['gid'] ); ?><br /> 56 <?php echo $indent . sprintf( __( 'size: %s' ), $stats['size'] ); ?><br/> 57 <?php echo $indent . sprintf( __( 'perms: %s' ), substr( sprintf( '%o', fileperms( $val ) ), -4 ) ); ?><br/> 58 <?php echo $indent . sprintf( __( 'readable: %s' ), is_readable( $val ) ? __( 'yes' ) : __( 'no' ) ); ?><br/> 59 <?php echo $indent . sprintf( __( 'writeable: %s' ), is_writeable( $val ) ? __( 'yes' ) : __( 'no' ) ); ?><br/> 60 <?php 61 } elseif ( ! file_exists( $val ) ) { 59 62 ?> 60 63 <h2><?php echo esc_html( $val ); ?></h2> 61 <?php echo $indent . sprintf( __( 'FILE NOT FOUND: %s'), $val ); ?><br/>64 <?php echo $indent . sprintf( __( 'FILE NOT FOUND: %s' ), $val ); ?><br/> 62 65 <?php 63 66 } … … 66 69 } 67 70 71 /** 72 * Prints .htaccess component of step 2 for network settings. 73 * 74 * @since 3.0.0 75 */ 68 76 function step2_htaccess() { 69 77 global $base; … … 71 79 // remove ending slash from $base and $url 72 80 $htaccess = ''; 73 if ( substr($base, -1 ) == '/') {74 $base = substr( $base, 0, -1);75 } 81 if ( substr( $base, -1 ) == '/' ) 82 $base = substr( $base, 0, -1 ); 83 76 84 $htaccess_sample = ABSPATH . 'wp-admin/includes/htaccess.ms'; 77 if ( ! file_exists( $htaccess_sample ) )78 wp_die( sprintf( __( 'Sorry, I need a %s to work from. Please re-upload this file to your WordPress installation.'), $htaccess_sample ) );85 if ( ! file_exists( $htaccess_sample ) ) 86 wp_die( sprintf( __( 'Sorry, I need a %s to work from. Please re-upload this file to your WordPress installation.' ), $htaccess_sample ) ); 79 87 80 88 $htaccess_file = file( $htaccess_sample ); 81 89 $fp = @fopen( $htaccess_sample, "r" ); 82 if ( $fp ) {83 while ( !feof( $fp ) ) {90 if ( $fp ) { 91 while ( ! feof( $fp ) ) { 84 92 $htaccess .= fgets( $fp, 4096 ); 85 93 } … … 87 95 $htaccess_file = str_replace( "BASE", $base, $htaccess ); 88 96 } else { 89 wp_die( sprintf( __( 'Sorry, I need to be able to read %s. Please check the permissions on this file.'), $htaccess_sample ) );97 wp_die( sprintf( __( 'Sorry, I need to be able to read %s. Please check the permissions on this file.' ), $htaccess_sample ) ); 90 98 } 91 99 92 100 //@todo: check for super-cache in use 93 101 ?> 94 <li><p><?php _e( 'Replace the contents of your <code>.htaccess</code> with the following:'); ?></p>102 <li><p><?php _e( 'Replace the contents of your <code>.htaccess</code> with the following:' ); ?></p> 95 103 <textarea name="htaccess" cols="120" rows="20"> 96 <?php echo $htaccess_file; ?>104 <?php echo wp_htmledit_pre( $htaccess_file ); ?> 97 105 </textarea> 98 106 </li> … … 100 108 } 101 109 110 /** 111 * Prints part of step 1 for network settings and checks for mod_rewrite. 112 * 113 * @since 3.0.0 114 * @return bool Whether mod_rewrite is enabled. 115 */ 102 116 function step1() { 103 117 $rewrite_enabled = false; 104 118 ?> 105 <h2><?php esc_html_e( 'Installing Network of WordPress Sites'); ?></h2>106 <p><?php _e( 'I will help you enable the features for creating a network of sites by asking you a few questions so that you can create configuration files and make a directory to store all your uploaded files.'); ?></p>107 108 <h2><?php esc_html_e( 'What do I need?'); ?></h2>119 <h2><?php esc_html_e( 'Installing Network of WordPress Sites' ); ?></h2> 120 <p><?php _e( 'I will help you enable the features for creating a network of sites by asking you a few questions so that you can create configuration files and make a directory to store all your uploaded files.' ); ?></p> 121 122 <h2><?php esc_html_e( 'What do I need?' ); ?></h2> 109 123 <ul> 110 124 <li><?php _e( 'Access to your server to change directory permissions. This can be done through ssh or ftp for example.' ); ?></li> 111 125 <li><?php _e( 'A valid email where your password and administrative emails will be sent.' ); ?></li> 112 <li><?php _e( "Wildcard dns records if you're going to use the virtual host (sub-domain) functionality. Check the <a href='http://trac.mu.wordpress.org/browser/trunk/README.txt'>README</a> for further details." ); ?></li>126 <li><?php _e( "Wildcard dns records if you're going to use the virtual host (sub-domain) functionality. Check the <a href='http://trac.mu.wordpress.org/browser/trunk/README.txt'>README</a> for further details." ); ?></li> 113 127 </ul> 114 128 <?php 115 $mod_rewrite_msg = "\n<p>" . __( "If the <code>mod_rewrite</code> module is disabled ask your administrator to enable that module, or look at the <a href='http://httpd.apache.org/docs/mod/mod_rewrite.html'>Apache documentation</a> or <a href='http://www.google.com/search?q=apache+mod_rewrite'>elsewhere</a> for help setting it up.") . '</p>';129 $mod_rewrite_msg = "\n<p>" . __( 'If the <code>mod_rewrite</code> module is disabled ask your administrator to enable that module, or look at the <a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">Apache documentation</a> or <a href="http://www.google.com/search?q=apache+mod_rewrite">elsewhere</a> for help setting it up.' ) . '</p>'; 116 130 117 131 if ( function_exists( 'apache_get_modules' ) ) { 118 132 $modules = apache_get_modules(); 119 133 if ( ! in_array( 'mod_rewrite', $modules ) ) 120 echo '<p>' . __( '<strong>Warning!</strong> It looks like mod_rewrite is not installed.') . '</p>' . $mod_rewrite_msg;134 echo '<p>' . __( '<strong>Warning!</strong> It looks like mod_rewrite is not installed.' ) . '</p>' . $mod_rewrite_msg; 121 135 else 122 136 $rewrite_enabled = true; … … 127 141 } 128 142 143 /** 144 * Prints most of step 1 for network settings. 145 * 146 * @since 3.0.0 147 * @param bool $rewrite_enabled Whether mod_rewrite is enabled. Default false. 148 */ 129 149 function printstep1form( $rewrite_enabled = false ) { 130 $weblog_title = sprintf( __( '%s Sites'), ucfirst( get_option( 'blogname' ) ) );150 $weblog_title = sprintf( __( '%s Sites' ), ucfirst( get_option( 'blogname' ) ) ); 131 151 $email = get_option( 'admin_email' ); 132 152 $hostname = get_clean_basedomain(); 133 if ( substr( $hostname, 0, 4 ) == 'www.' )153 if ( substr( $hostname, 0, 4 ) == 'www.' ) 134 154 $nowww = substr( $hostname, 4 ); 135 155 … … 139 159 <h2><?php esc_html_e( 'Site Addresses' ); ?></h2> 140 160 <p><?php _e( 'Please choose whether you would like sites in your WordPress install to use sub-domains or sub-directories. You cannot change this later.' ); ?></p> 141 <?php if ( ! $rewrite_enabled ) { ?>142 <p><?php _e( '<strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.' ); ?></p>161 <?php if ( ! $rewrite_enabled ) { ?> 162 <p><?php _e( '<strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.' ); ?></p> 143 163 <?php } ?> 144 164 <p class="blog-address"> 145 <label><input type='radio' name='vhost' value='yes'<?php if ( $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-domains (like <code>blog1.example.com</code>)' ); ?></label><br />146 <label><input type='radio' name='vhost' value='no'<?php if ( !$rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-directories (like <code>example.com/blog1</code>) '); ?></label>165 <label><input type='radio' name='vhost' value='yes'<?php if ( $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-domains (like <code>blog1.example.com</code>)' ); ?></label><br /> 166 <label><input type='radio' name='vhost' value='no'<?php if ( ! $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-directories (like <code>example.com/blog1</code>)' ); ?></label> 147 167 </p> 148 168 … … 183 203 } 184 204 205 /** 206 * Prints step 2 for network settings. 207 * 208 * @since 3.0.0 209 */ 185 210 function step2() { 186 211 ?> … … 195 220 } 196 221 222 /** 223 * Prints configuration file component of step 2 for network settings. 224 * 225 * @since 3.0.0 226 */ 197 227 function step2_config() { 198 228 global $base, $wpdb, $vhost; 199 229 200 $vhost = stripslashes( $_POST['vhost' ]);230 $vhost = stripslashes( $_POST['vhost' ] ); 201 231 $prefix = $wpdb->base_prefix; 202 232 203 233 $config_sample = ABSPATH . 'wp-admin/includes/wp-config.ms'; 204 if ( ! file_exists( $config_sample ) )234 if ( ! file_exists( $config_sample ) ) 205 235 wp_die( sprintf( __( 'Sorry, I need a <code>%s</code> to work from. Please re-upload this file to your WordPress installation.' ), $config_sample ) ); 206 236 … … 210 240 <textarea name="wp-config" cols="120" rows="20"> 211 241 <?php 212 foreach ( $wp_config_file as $line) {213 switch ( trim( substr( $line,0,16) ) ) {242 foreach ( $wp_config_file as $line ) { 243 switch ( trim( substr( $line, 0, 16 ) ) ) { 214 244 case "define('DB_NAME'": 215 $output = str_replace( "wordpress", DB_NAME, $line);245 $output = str_replace( "wordpress", DB_NAME, $line ); 216 246 break; 217 247 case "define('DB_USER'": 218 $output = str_replace( "username", DB_USER, $line);248 $output = str_replace( "username", DB_USER, $line ); 219 249 break; 220 250 case "define('DB_PASSW": 221 $output = str_replace( "password", DB_PASSWORD, $line);251 $output = str_replace( "password", DB_PASSWORD, $line ); 222 252 break; 223 253 case "define('DB_HOST'": 224 $output = str_replace( "localhost", DB_HOST, $line);254 $output = str_replace( "localhost", DB_HOST, $line ); 225 255 break; 226 256 case "define('VHOST',": 227 $output = str_replace( "VHOSTSETTING", $vhost, $line);257 $output = str_replace( "VHOSTSETTING", $vhost, $line ); 228 258 break; 229 259 case '$table_prefix =': 230 $output = str_replace( 'wp_', $prefix, $line);260 $output = str_replace( 'wp_', $prefix, $line ); 231 261 break; 232 262 case '$base = \'BASE\';': 233 $output = str_replace( 'BASE', $base, $line);263 $output = str_replace( 'BASE', $base, $line ); 234 264 break; 235 265 case "define('DOMAIN_C": 236 266 $domain = get_clean_basedomain(); 237 $output = str_replace( "current_site_domain", $domain, $line);267 $output = str_replace( "current_site_domain", $domain, $line ); 238 268 break; 239 269 case "define('PATH_CUR": 240 $output = str_replace( "current_site_path", $base, $line);270 $output = str_replace( "current_site_path", $base, $line ); 241 271 break; 242 272 case "define('AUTH_KEY": … … 250 280 else 251 281 $hash = md5( mt_rand() ) . md5( mt_rand() ); 252 $output = str_replace( 'put your unique phrase here', $hash, $line);282 $output = str_replace( 'put your unique phrase here', $hash, $line ); 253 283 break; 254 284 default: … … 264 294 } 265 295 296 /** 297 * Gets base domain of network. 298 * 299 * @since 3.0.0 300 */ 266 301 function get_clean_basedomain() { 267 302 global $wpdb; 268 $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );269 if ( strpos( $domain, '/' ) )303 $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) ); 304 if ( strpos( $domain, '/' ) ) 270 305 $domain = substr( $domain, 0, strpos( $domain, '/' ) ); 271 306 return $domain; 272 307 } 273 308 274 $action = isset($_POST[ 'action' ]) ? $_POST[ 'action' ] : null; 275 switch($action) { 276 case "step2": 309 $action = isset( $_POST[ 'action' ] ) ? $_POST[ 'action' ] : null; 310 311 switch( $action ) { 312 case 'step2': 277 313 check_admin_referer( 'install-network-1' ); 278 314 279 315 // Install! 280 $base = stripslashes( dirname( dirname( $_SERVER["SCRIPT_NAME"]) ) );281 if ( $base != "/")282 $base .= "/";316 $base = stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ); 317 if ( $base != '/' ) 318 $base .= '/'; 283 319 284 320 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); … … 286 322 $domain = get_clean_basedomain(); 287 323 install_network(); 288 populate_network( 1, $domain, sanitize_email( $_POST[ 'email' ] ), $_POST[ 'weblog_title' ], $base, $_POST[ 'vhost'] );324 populate_network( 1, $domain, sanitize_email( $_POST['email'] ), $_POST['weblog_title'], $base, $_POST['vhost'] ); 289 325 // create wp-config.php / htaccess 290 326 step2(); … … 293 329 //@todo: give an informative screen instead 294 330 if ( is_multisite() ) { 295 _e( 'Network already enabled');331 _e( 'Network already enabled.' ); 296 332 } else { 297 333 $rewrite_enabled = step1(); 298 printstep1form( $rewrite_enabled);334 printstep1form( $rewrite_enabled ); 299 335 } 300 336 break; … … 304 340 </div> 305 341 306 <?php include( './admin-footer.php'); ?>342 <?php include( './admin-footer.php' ); ?>
Note: See TracChangeset
for help on using the changeset viewer.