2010-01-18 19:18:52 -05:00
< ? php
/**
* Network settings administration panel .
*
2010-01-27 08:48:37 -05:00
* A multi - step process allowing the user to enable a network of WordPress sites .
*
* @ since 3.0 . 0
2010-01-18 19:18:52 -05:00
*
* @ package WordPress
* @ subpackage Administration
*/
/** WordPress Administration Bootstrap */
2010-01-27 08:48:37 -05:00
require_once ( './admin.php' );
2010-01-18 19:18:52 -05:00
if ( ! is_super_admin () )
2010-01-27 08:48:37 -05:00
wp_die ( __ ( 'You do not have sufficient permissions to manage options for this blog.' ) );
2010-01-18 19:18:52 -05:00
2010-01-27 08:48:37 -05:00
$title = __ ( 'Network Settings' );
2010-01-25 18:07:49 -05:00
$parent_file = 'tools.php' ;
2010-01-18 19:18:52 -05:00
2010-01-27 08:48:37 -05:00
add_contextual_help ( $current_screen , __ ( '<a href="http://codex.wordpress.org/Settings_Network_SubPanel" target="_blank">Network Settings</a>' ) );
2010-01-18 19:18:52 -05:00
2010-01-27 08:48:37 -05:00
include ( './admin-header.php' );
2010-01-18 19:18:52 -05:00
2010-01-27 08:48:37 -05:00
$dirs = array ( substr ( ABSPATH , 0 , - 1 ), ABSPATH . 'wp-content' );
2010-01-18 19:18:52 -05:00
?>
< div class = " wrap " >
< ? php screen_icon (); ?>
< h2 >< ? php echo esc_html ( $title ); ?> </h2>
2010-01-25 18:07:49 -05:00
< form method = " post " action = " network.php " >
2010-01-18 19:18:52 -05:00
< ? php
2010-01-27 08:48:37 -05:00
/**
* Prints summary of server statistics in preparation for setting up a network .
*
* @ since 3.0 . 0
*/
2010-01-18 19:18:52 -05:00
function filestats ( $err ) {
2010-01-23 14:06:15 -05:00
?>
2010-01-27 08:48:37 -05:00
< h2 >< ? php esc_html_e ( 'Server Summary' ); ?> </h2>
< 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>
2010-01-23 14:06:15 -05:00
< blockquote style = " background: #eee; border: 1px solid #333; padding: 5px; " >
2010-01-27 08:48:37 -05:00
< br />< strong >< ? php printf ( __ ( 'ERROR: %s' ), $err ); ?> </strong><br />
2010-01-23 14:06:15 -05:00
< ? php
2010-01-18 19:18:52 -05:00
clearstatcache ();
2010-01-27 08:48:37 -05:00
$files = array ( 'htaccess.dist' , '.htaccess' );
2010-01-26 17:49:05 -05:00
2010-01-23 14:06:15 -05:00
$indent = ' ' ;
2010-01-18 19:18:52 -05:00
foreach ( ( array ) $files as $val ) {
$stats = @ stat ( $val );
2010-01-27 08:48:37 -05:00
if ( $stats ) {
2010-01-23 14:06:15 -05:00
?>
< h2 >< ? php echo esc_html ( $val ); ?> </h2>
2010-01-27 08:48:37 -05:00
< ? php echo $indent . sprintf ( __ ( 'uid/gid: %1$s/%2$s' ), $stats [ 'uid' ], $stats [ 'gid' ] ); ?> <br />
< ? php echo $indent . sprintf ( __ ( 'size: %s' ), $stats [ 'size' ] ); ?> <br/>
< ? php echo $indent . sprintf ( __ ( 'perms: %s' ), substr ( sprintf ( '%o' , fileperms ( $val ) ), - 4 ) ); ?> <br/>
< ? php echo $indent . sprintf ( __ ( 'readable: %s' ), is_readable ( $val ) ? __ ( 'yes' ) : __ ( 'no' ) ); ?> <br/>
< ? php echo $indent . sprintf ( __ ( 'writeable: %s' ), is_writeable ( $val ) ? __ ( 'yes' ) : __ ( 'no' ) ); ?> <br/>
2010-01-23 14:06:15 -05:00
< ? php
2010-01-27 08:48:37 -05:00
} elseif ( ! file_exists ( $val ) ) {
2010-01-23 14:06:15 -05:00
?>
< h2 >< ? php echo esc_html ( $val ); ?> </h2>
2010-01-27 08:48:37 -05:00
< ? php echo $indent . sprintf ( __ ( 'FILE NOT FOUND: %s' ), $val ); ?> <br/>
2010-01-23 14:06:15 -05:00
< ? php
2010-01-18 19:18:52 -05:00
}
}
2010-01-23 14:06:15 -05:00
echo " </blockquote> " ;
2010-01-18 19:18:52 -05:00
}
2010-01-27 08:48:37 -05:00
/**
* Prints . htaccess component of step 2 for network settings .
*
* @ since 3.0 . 0
*/
2010-01-18 19:18:52 -05:00
function step2_htaccess () {
global $base ;
// remove ending slash from $base and $url
$htaccess = '' ;
2010-01-27 08:48:37 -05:00
if ( substr ( $base , - 1 ) == '/' )
$base = substr ( $base , 0 , - 1 );
2010-01-18 19:18:52 -05:00
$htaccess_sample = ABSPATH . 'wp-admin/includes/htaccess.ms' ;
2010-01-27 08:48:37 -05:00
if ( ! file_exists ( $htaccess_sample ) )
wp_die ( sprintf ( __ ( 'Sorry, I need a %s to work from. Please re-upload this file to your WordPress installation.' ), $htaccess_sample ) );
2010-01-18 19:18:52 -05:00
$htaccess_file = file ( $htaccess_sample );
$fp = @ fopen ( $htaccess_sample , " r " );
2010-01-27 08:48:37 -05:00
if ( $fp ) {
while ( ! feof ( $fp ) ) {
2010-01-18 19:18:52 -05:00
$htaccess .= fgets ( $fp , 4096 );
}
fclose ( $fp );
$htaccess_file = str_replace ( " BASE " , $base , $htaccess );
} else {
2010-01-27 08:48:37 -05:00
wp_die ( sprintf ( __ ( 'Sorry, I need to be able to read %s. Please check the permissions on this file.' ), $htaccess_sample ) );
2010-01-18 19:18:52 -05:00
}
//@todo: check for super-cache in use
?>
2010-01-27 08:48:37 -05:00
< li >< p >< ? php _e ( 'Replace the contents of your <code>.htaccess</code> with the following:' ); ?> </p>
2010-01-18 19:18:52 -05:00
< textarea name = " htaccess " cols = " 120 " rows = " 20 " >
2010-01-27 08:48:37 -05:00
< ? php echo wp_htmledit_pre ( $htaccess_file ); ?>
2010-01-18 19:18:52 -05:00
</ textarea >
</ li >
< ? php
}
2010-01-27 08:48:37 -05:00
/**
* Prints part of step 1 for network settings and checks for mod_rewrite .
*
* @ since 3.0 . 0
* @ return bool Whether mod_rewrite is enabled .
*/
2010-01-18 19:18:52 -05:00
function step1 () {
$rewrite_enabled = false ;
?>
2010-01-27 08:48:37 -05:00
< h2 >< ? php esc_html_e ( 'Installing Network of WordPress Sites' ); ?> </h2>
< 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>
2010-01-26 17:49:05 -05:00
2010-01-27 08:48:37 -05:00
< h2 >< ? php esc_html_e ( 'What do I need?' ); ?> </h2>
2010-01-18 19:18:52 -05:00
< ul >
2010-01-23 14:06:15 -05:00
< li >< ? php _e ( 'Access to your server to change directory permissions. This can be done through ssh or ftp for example.' ); ?> </li>
< li >< ? php _e ( 'A valid email where your password and administrative emails will be sent.' ); ?> </li>
2010-01-27 08:48:37 -05:00
< 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>
2010-01-18 19:18:52 -05:00
</ ul >
< ? php
2010-01-27 08:48:37 -05:00
$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>' ;
2010-01-26 17:49:05 -05:00
2010-01-23 14:06:15 -05:00
if ( function_exists ( 'apache_get_modules' ) ) {
2010-01-18 19:18:52 -05:00
$modules = apache_get_modules ();
2010-01-23 14:06:15 -05:00
if ( ! in_array ( 'mod_rewrite' , $modules ) )
2010-01-27 08:48:37 -05:00
echo '<p>' . __ ( '<strong>Warning!</strong> It looks like mod_rewrite is not installed.' ) . '</p>' . $mod_rewrite_msg ;
2010-01-23 14:06:15 -05:00
else
2010-01-18 19:18:52 -05:00
$rewrite_enabled = true ;
} else {
2010-01-23 14:06:15 -05:00
echo '<p>' . __ ( 'Please make sure <code>mod_rewrite</code> is installed as it will be activated at the end of this install.' ) . '</p>' . $mod_rewrite_msg ;
2010-01-18 19:18:52 -05:00
}
return $rewrite_enabled ;
}
2010-01-27 08:48:37 -05:00
/**
* Prints most of step 1 for network settings .
*
* @ since 3.0 . 0
* @ param bool $rewrite_enabled Whether mod_rewrite is enabled . Default false .
*/
2010-01-18 19:18:52 -05:00
function printstep1form ( $rewrite_enabled = false ) {
2010-01-27 08:48:37 -05:00
$weblog_title = sprintf ( __ ( '%s Sites' ), ucfirst ( get_option ( 'blogname' ) ) );
2010-01-18 19:18:52 -05:00
$email = get_option ( 'admin_email' );
2010-01-21 12:20:23 -05:00
$hostname = get_clean_basedomain ();
2010-01-27 08:48:37 -05:00
if ( substr ( $hostname , 0 , 4 ) == 'www.' )
2010-01-21 12:20:23 -05:00
$nowww = substr ( $hostname , 4 );
2010-01-18 19:18:52 -05:00
wp_nonce_field ( 'install-network-1' );
?>
< input type = 'hidden' name = 'action' value = 'step2' />
2010-01-23 14:06:15 -05:00
< h2 >< ? php esc_html_e ( 'Site Addresses' ); ?> </h2>
< 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>
2010-01-27 08:48:37 -05:00
< ? php if ( ! $rewrite_enabled ) { ?>
< p >< ? php _e ( '<strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.' ); ?> </p>
2010-01-18 19:18:52 -05:00
< ? php } ?>
< p class = " blog-address " >
2010-01-27 08:48:37 -05:00
< 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 />
< 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>
2010-01-18 19:18:52 -05:00
</ p >
2010-01-23 14:06:15 -05:00
< h2 >< ? php esc_html_e ( 'Server Address' ); ?> </h2>
2010-01-21 12:20:23 -05:00
< ? php if ( isset ( $nowww ) ) { ?>
2010-01-23 14:06:15 -05:00
< h3 >< ? php printf ( __ ( 'We recommend you change your siteurl to <code>%1$s</code> before enabling the network feature. It will still be possible to visit your site using the "www" prefix with an address like <code>%2$s</code> but any links will not have the "www" prefix.' ), $nowww , $hostname ); ?> </h3>
2010-01-21 12:20:23 -05:00
< ? php } ?>
2010-01-26 17:49:05 -05:00
< table class = " form-table " >
< tr >
< th scope = 'row' >< ? php esc_html_e ( 'Server Address' ); ?> </th>
2010-01-18 19:18:52 -05:00
< td >
2010-01-23 14:06:15 -05:00
< p >< ? php printf ( __ ( 'This will be the Internet address of your site: <strong><em>%s</em></strong>.' ), $hostname ); ?> </p>
< input type = 'hidden' name = 'basedomain' value = '<?php echo esc_attr( $hostname ); ?>' />
< p >< ? php _e ( 'Do not use an IP address (like 127.0.0.1) or a single word hostname like <q>localhost</q> as your server address.' ); ?> </p>
2010-01-26 17:49:05 -05:00
</ td >
2010-01-18 19:18:52 -05:00
</ tr >
</ table >
2010-01-23 14:06:15 -05:00
< h2 >< ? php esc_html_e ( 'Site Details' ); ?> </h2>
2010-01-26 17:49:05 -05:00
< table class = " form-table " >
< tr >
< th scope = 'row' >< ? php esc_html_e ( 'Site Title' ); ?> </th>
2010-01-18 19:18:52 -05:00
< td >
2010-01-23 14:06:15 -05:00
< input name = 'weblog_title' type = 'text' size = '45' value = '<?php echo esc_attr( $weblog_title ); ?>' />
< br />< ? php _e ( 'What would you like to call your site?' ); ?>
2010-01-26 17:49:05 -05:00
</ td >
</ tr >
< tr >
< th scope = 'row' >< ? php esc_html_e ( 'Email' ); ?> </th>
2010-01-18 19:18:52 -05:00
< td >
2010-01-26 17:49:05 -05:00
< input name = 'email' type = 'text' size = '45' value = '<?php echo esc_attr( $email ); ?>' />
2010-01-23 14:06:15 -05:00
< br />< ? php _e ( 'Your email address.' ); ?>
2010-01-26 17:49:05 -05:00
</ td >
</ tr >
</ table >
2010-01-23 14:06:15 -05:00
< p class = 'submit' >< input class = " button " name = 'submit' type = 'submit' value = '<?php esc_attr_e( ' Proceed ' ); ?>' /></ p >
2010-01-18 19:18:52 -05:00
< ? php
}
2010-01-27 08:48:37 -05:00
/**
* Prints step 2 for network settings .
*
* @ since 3.0 . 0
*/
2010-01-18 19:18:52 -05:00
function step2 () {
?>
2010-01-23 14:06:15 -05:00
< h2 >< ? php esc_html_e ( 'Enabling WordPress Sites' ); ?> </h2>
< p >< ? php _e ( 'Complete the following steps to enable the features for creating a network of sites. <strong>Note:</strong> We recommend you make a backup copy of your existing <code>wp-config.php</code> and <code>.htaccess</code> files.' ); ?> </p>
2010-01-18 19:18:52 -05:00
< ol >
2010-01-23 14:06:15 -05:00
< li >< ? php _e ( 'Create a <code>blogs.dir</code> directory in your <code>wp-content</code> directory. This directory is used to stored uploaded media for your additional sites and must be writeable by the web server.' ); ?> </li>
2010-01-18 19:18:52 -05:00
< ? php step2_config (); ?>
< ? php step2_htaccess (); ?>
</ ol >
< ? php
}
2010-01-27 08:48:37 -05:00
/**
* Prints configuration file component of step 2 for network settings .
*
* @ since 3.0 . 0
*/
2010-01-18 19:18:52 -05:00
function step2_config () {
global $base , $wpdb , $vhost ;
2010-01-27 08:48:37 -05:00
$vhost = stripslashes ( $_POST [ 'vhost' ] );
2010-01-18 19:18:52 -05:00
$prefix = $wpdb -> base_prefix ;
$config_sample = ABSPATH . 'wp-admin/includes/wp-config.ms' ;
2010-01-27 08:48:37 -05:00
if ( ! file_exists ( $config_sample ) )
2010-01-23 14:06:15 -05:00
wp_die ( sprintf ( __ ( 'Sorry, I need a <code>%s</code> to work from. Please re-upload this file to your WordPress installation.' ), $config_sample ) );
2010-01-18 19:18:52 -05:00
$wp_config_file = file ( $config_sample );
?>
2010-01-23 14:06:15 -05:00
< li >< p >< ? php _e ( 'Replace the contents of your <code>wp-config.php</code> with the following:' ); ?> </p>
2010-01-18 19:18:52 -05:00
< textarea name = " wp-config " cols = " 120 " rows = " 20 " >
< ? php
2010-01-27 08:48:37 -05:00
foreach ( $wp_config_file as $line ) {
switch ( trim ( substr ( $line , 0 , 16 ) ) ) {
2010-01-18 19:18:52 -05:00
case " define('DB_NAME' " :
2010-01-27 08:48:37 -05:00
$output = str_replace ( " wordpress " , DB_NAME , $line );
2010-01-18 19:18:52 -05:00
break ;
case " define('DB_USER' " :
2010-01-27 08:48:37 -05:00
$output = str_replace ( " username " , DB_USER , $line );
2010-01-18 19:18:52 -05:00
break ;
case " define('DB_PASSW " :
2010-01-27 08:48:37 -05:00
$output = str_replace ( " password " , DB_PASSWORD , $line );
2010-01-18 19:18:52 -05:00
break ;
case " define('DB_HOST' " :
2010-01-27 08:48:37 -05:00
$output = str_replace ( " localhost " , DB_HOST , $line );
2010-01-18 19:18:52 -05:00
break ;
case " define('VHOST', " :
2010-01-27 08:48:37 -05:00
$output = str_replace ( " VHOSTSETTING " , $vhost , $line );
2010-01-18 19:18:52 -05:00
break ;
case '$table_prefix =' :
2010-01-27 08:48:37 -05:00
$output = str_replace ( 'wp_' , $prefix , $line );
2010-01-18 19:18:52 -05:00
break ;
case '$base = \'BASE\';' :
2010-01-27 08:48:37 -05:00
$output = str_replace ( 'BASE' , $base , $line );
2010-01-18 19:18:52 -05:00
break ;
case " define('DOMAIN_C " :
$domain = get_clean_basedomain ();
2010-01-27 08:48:37 -05:00
$output = str_replace ( " current_site_domain " , $domain , $line );
2010-01-18 19:18:52 -05:00
break ;
case " define('PATH_CUR " :
2010-01-27 08:48:37 -05:00
$output = str_replace ( " current_site_path " , $base , $line );
2010-01-18 19:18:52 -05:00
break ;
case " define('AUTH_KEY " :
case " define('AUTH_SAL " :
case " define('LOGGED_I " :
case " define('SECURE_A " :
case " define('NONCE_KE " :
$constant = substr ( $line , 8 , strpos ( $line , " ' " , 9 ) - 8 );
if ( defined ( $constant ) )
$hash = constant ( $constant );
else
$hash = md5 ( mt_rand () ) . md5 ( mt_rand () );
2010-01-27 08:48:37 -05:00
$output = str_replace ( 'put your unique phrase here' , $hash , $line );
2010-01-18 19:18:52 -05:00
break ;
default :
$output = $line ;
break ;
}
echo $output ;
}
?>
</ textarea >
</ li >
< ? php
}
2010-01-27 08:48:37 -05:00
/**
* Gets base domain of network .
*
* @ since 3.0 . 0
*/
2010-01-18 19:18:52 -05:00
function get_clean_basedomain () {
global $wpdb ;
2010-01-27 08:48:37 -05:00
$domain = preg_replace ( '|https?://|' , '' , get_option ( 'siteurl' ) );
if ( strpos ( $domain , '/' ) )
2010-01-18 19:18:52 -05:00
$domain = substr ( $domain , 0 , strpos ( $domain , '/' ) );
return $domain ;
}
2010-01-27 08:48:37 -05:00
$action = isset ( $_POST [ 'action' ] ) ? $_POST [ 'action' ] : null ;
switch ( $action ) {
case 'step2' :
2010-01-18 19:18:52 -05:00
check_admin_referer ( 'install-network-1' );
2010-01-26 17:49:05 -05:00
2010-01-18 19:18:52 -05:00
// Install!
2010-01-27 08:48:37 -05:00
$base = stripslashes ( dirname ( dirname ( $_SERVER [ 'SCRIPT_NAME' ] ) ) );
if ( $base != '/' )
$base .= '/' ;
2010-01-18 19:18:52 -05:00
require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
// create network tables
2010-01-20 15:42:20 -05:00
$domain = get_clean_basedomain ();
2010-01-18 19:18:52 -05:00
install_network ();
2010-01-27 08:48:37 -05:00
populate_network ( 1 , $domain , sanitize_email ( $_POST [ 'email' ] ), $_POST [ 'weblog_title' ], $base , $_POST [ 'vhost' ] );
2010-01-18 19:18:52 -05:00
// create wp-config.php / htaccess
step2 ();
break ;
default :
//@todo: give an informative screen instead
if ( is_multisite () ) {
2010-01-27 08:48:37 -05:00
_e ( 'Network already enabled.' );
2010-01-20 17:11:02 -05:00
} else {
$rewrite_enabled = step1 ();
2010-01-27 08:48:37 -05:00
printstep1form ( $rewrite_enabled );
2010-01-18 19:18:52 -05:00
}
break ;
}
?>
</ form >
</ div >
2010-01-27 08:48:37 -05:00
< ? php include ( './admin-footer.php' ); ?>