~canonical-sysadmins/wordpress/4.6

« back to all changes in this revision

Viewing changes to wp-admin/network.php

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Network installation administration panel.
 
4
 *
 
5
 * A multi-step process allowing the user to enable a network of WordPress sites.
 
6
 *
 
7
 * @since 3.0.0
 
8
 *
 
9
 * @package WordPress
 
10
 * @subpackage Administration
 
11
 */
 
12
 
 
13
define( 'WP_INSTALLING_NETWORK', true );
 
14
 
 
15
/** WordPress Administration Bootstrap */
 
16
require_once( dirname( __FILE__ ) . '/admin.php' );
 
17
 
 
18
if ( ! is_super_admin() )
 
19
        wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
 
20
 
 
21
if ( is_multisite() ) {
 
22
        if ( ! is_network_admin() ) {
 
23
                wp_redirect( network_admin_url( 'setup.php' ) );
 
24
                exit;
 
25
        }
 
26
        if ( ! defined( 'MULTISITE' ) )
 
27
                wp_die( __( 'The Network creation panel is not for WordPress MU networks.' ) );
 
28
}
 
29
 
 
30
// We need to create references to ms global tables to enable Network.
 
31
foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table )
 
32
        $wpdb->$table = $prefixed_table;
 
33
 
 
34
/**
 
35
 * Check for an existing network.
 
36
 *
 
37
 * @since 3.0.0
 
38
 * @return Whether a network exists.
 
39
 */
 
40
function network_domain_check() {
 
41
        global $wpdb;
 
42
 
 
43
        $sql = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) );
 
44
        if ( $wpdb->get_var( $sql ) ) {
 
45
                return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
 
46
        }
 
47
        return false;
 
48
}
 
49
 
 
50
/**
 
51
 * Allow subdomain install
 
52
 *
 
53
 * @since 3.0.0
 
54
 * @return bool Whether subdomain install is allowed
 
55
 */
 
56
function allow_subdomain_install() {
 
57
        $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
 
58
        if( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) )
 
59
                return false;
 
60
 
 
61
        return true;
 
62
}
 
63
/**
 
64
 * Allow subdirectory install.
 
65
 *
 
66
 * @since 3.0.0
 
67
 * @return bool Whether subdirectory install is allowed
 
68
 */
 
69
function allow_subdirectory_install() {
 
70
        global $wpdb;
 
71
        /**
 
72
         * Filter whether to enable the subdirectory install feature in Multisite.
 
73
         *
 
74
         * @since 3.0.0
 
75
         *
 
76
         * @param bool true Whether to enable the subdirectory install feature in Multisite. Default is false.
 
77
         */
 
78
        if ( apply_filters( 'allow_subdirectory_install', false ) )
 
79
                return true;
 
80
 
 
81
        if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL )
 
82
                return true;
 
83
 
 
84
        $post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" );
 
85
        if ( empty( $post ) )
 
86
                return true;
 
87
 
 
88
        return false;
 
89
}
 
90
/**
 
91
 * Get base domain of network.
 
92
 *
 
93
 * @since 3.0.0
 
94
 * @return string Base domain.
 
95
 */
 
96
function get_clean_basedomain() {
 
97
        if ( $existing_domain = network_domain_check() )
 
98
                return $existing_domain;
 
99
        $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
 
100
        if ( $slash = strpos( $domain, '/' ) )
 
101
                $domain = substr( $domain, 0, $slash );
 
102
        return $domain;
 
103
}
 
104
 
 
105
if ( ! network_domain_check() && ( ! defined( 'WP_ALLOW_MULTISITE' ) || ! WP_ALLOW_MULTISITE ) )
 
106
        wp_die( __( 'You must define the <code>WP_ALLOW_MULTISITE</code> constant as true in your wp-config.php file to allow creation of a Network.' ) );
 
107
 
 
108
if ( is_network_admin() ) {
 
109
        $title = __( 'Network Setup' );
 
110
        $parent_file = 'settings.php';
 
111
} else {
 
112
        $title = __( 'Create a Network of WordPress Sites' );
 
113
        $parent_file = 'tools.php';
 
114
}
 
115
 
 
116
$network_help = '<p>' . __('This screen allows you to configure a network as having subdomains (<code>site1.example.com</code>) or subdirectories (<code>example.com/site1</code>). Subdomains require wildcard subdomains to be enabled in Apache and DNS records, if your host allows it.') . '</p>' .
 
117
        '<p>' . __('Choose subdomains or subdirectories; this can only be switched afterwards by reconfiguring your install. Fill out the network details, and click install. If this does not work, you may have to add a wildcard DNS record (for subdomains) or change to another setting in Permalinks (for subdirectories).') . '</p>' .
 
118
        '<p>' . __('The next screen for Network Setup will give you individually-generated lines of code to add to your wp-config.php and .htaccess files. Make sure the settings of your FTP client make files starting with a dot visible, so that you can find .htaccess; you may have to create this file if it really is not there. Make backup copies of those two files.') . '</p>' .
 
119
        '<p>' . __('Add the designated lines of code to wp-config.php (just before <code>/*...stop editing...*/</code>) and <code>.htaccess</code> (replacing the existing WordPress rules).') . '</p>' .
 
120
        '<p>' . __('Once you add this code and refresh your browser, multisite should be enabled. This screen, now in the Network Admin navigation menu, will keep an archive of the added code. You can toggle between Network Admin and Site Admin by clicking on the Network Admin or an individual site name under the My Sites dropdown in the Toolbar.') . '</p>' .
 
121
        '<p>' . __('The choice of subdirectory sites is disabled if this setup is more than a month old because of permalink problems with &#8220;/blog/&#8221; from the main site. This disabling will be addressed in a future version.') . '</p>' .
 
122
        '<p><strong>' . __('For more information:') . '</strong></p>' .
 
123
        '<p>' . __('<a href="http://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>') . '</p>' .
 
124
        '<p>' . __('<a href="http://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>') . '</p>';
 
125
 
 
126
get_current_screen()->add_help_tab( array(
 
127
        'id'      => 'network',
 
128
        'title'   => __('Network'),
 
129
        'content' => $network_help,
 
130
) );
 
131
 
 
132
get_current_screen()->set_help_sidebar(
 
133
        '<p><strong>' . __('For more information:') . '</strong></p>' .
 
134
        '<p>' . __('<a href="http://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>') . '</p>' .
 
135
        '<p>' . __('<a href="http://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>') . '</p>' .
 
136
        '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
 
137
);
 
138
 
 
139
include( ABSPATH . 'wp-admin/admin-header.php' );
 
140
?>
 
141
<div class="wrap">
 
142
<h2><?php echo esc_html( $title ); ?></h2>
 
143
 
 
144
<?php
 
145
/**
 
146
 * Prints step 1 for Network installation process.
 
147
 *
 
148
 * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network
 
149
 *      should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo.
 
150
 *
 
151
 * @since 3.0.0
 
152
 */
 
153
function network_step1( $errors = false ) {
 
154
        global $is_apache;
 
155
 
 
156
        if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
 
157
                echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>';
 
158
                echo '</div>';
 
159
                include( ABSPATH . 'wp-admin/admin-footer.php' );
 
160
                die();
 
161
        }
 
162
 
 
163
        $active_plugins = get_option( 'active_plugins' );
 
164
        if ( ! empty( $active_plugins ) ) {
 
165
                echo '<div class="updated"><p><strong>' . __('Warning:') . '</strong> ' . sprintf( __( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ), admin_url( 'plugins.php?plugin_status=active' ) ) . '</p></div><p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
 
166
                echo '</div>';
 
167
                include( ABSPATH . 'wp-admin/admin-footer.php' );
 
168
                die();
 
169
        }
 
170
 
 
171
        $hostname = get_clean_basedomain();
 
172
        $has_ports = strstr( $hostname, ':' );
 
173
        if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
 
174
                echo '<div class="error"><p><strong>' . __( 'ERROR:') . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
 
175
                echo '<p>' . sprintf( __( 'You cannot use port numbers such as <code>%s</code>.' ), $has_ports ) . '</p>';
 
176
                echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>';
 
177
                echo '</div>';
 
178
                include( ABSPATH . 'wp-admin/admin-footer.php' );
 
179
                die();
 
180
        }
 
181
 
 
182
        echo '<form method="post" action="">';
 
183
 
 
184
        wp_nonce_field( 'install-network-1' );
 
185
 
 
186
        $error_codes = array();
 
187
        if ( is_wp_error( $errors ) ) {
 
188
                echo '<div class="error"><p><strong>' . __( 'ERROR: The network could not be created.' ) . '</strong></p>';
 
189
                foreach ( $errors->get_error_messages() as $error )
 
190
                        echo "<p>$error</p>";
 
191
                echo '</div>';
 
192
                $error_codes = $errors->get_error_codes();
 
193
        }
 
194
 
 
195
        $site_name = ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) ? $_POST['sitename'] : sprintf( _x('%s Sites', 'Default network name' ), get_option( 'blogname' ) );
 
196
        $admin_email = ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) ? $_POST['email'] : get_option( 'admin_email' );
 
197
        ?>
 
198
        <p><?php _e( 'Welcome to the Network installation process!' ); ?></p>
 
199
        <p><?php _e( 'Fill in the information below and you&#8217;ll be on your way to creating a network of WordPress sites. We will create configuration files in the next step.' ); ?></p>
 
200
        <?php
 
201
 
 
202
        if ( isset( $_POST['subdomain_install'] ) ) {
 
203
                $subdomain_install = (bool) $_POST['subdomain_install'];
 
204
        } elseif ( apache_mod_loaded('mod_rewrite') ) { // assume nothing
 
205
                $subdomain_install = true;
 
206
        } elseif ( !allow_subdirectory_install() ) {
 
207
                $subdomain_install = true;
 
208
        } else {
 
209
                $subdomain_install = false;
 
210
                if ( $got_mod_rewrite = got_mod_rewrite() ) // dangerous assumptions
 
211
                        echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ' . __( 'Please make sure the Apache <code>mod_rewrite</code> module is installed as it will be used at the end of this installation.' ) . '</p>';
 
212
                elseif ( $is_apache )
 
213
                        echo '<div class="error inline"><p><strong>' . __( 'Warning!' ) . '</strong> ' . __( 'It looks like the Apache <code>mod_rewrite</code> module is not installed.' ) . '</p>';
 
214
                if ( $got_mod_rewrite || $is_apache ) // Protect against mod_rewrite mimicry (but ! Apache)
 
215
                        echo '<p>' . __( 'If <code>mod_rewrite</code> 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></div>';
 
216
        }
 
217
 
 
218
        if ( allow_subdomain_install() && allow_subdirectory_install() ) : ?>
 
219
                <h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
 
220
                <p><?php _e( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories. <strong>You cannot change this later.</strong>' ); ?></p>
 
221
                <p><?php _e( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?></p>
 
222
                <?php // @todo: Link to an MS readme? ?>
 
223
                <table class="form-table">
 
224
                        <tr>
 
225
                                <th><label><input type="radio" name="subdomain_install" value="1"<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
 
226
                                <td><?php printf( _x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ), $hostname ); ?></td>
 
227
                        </tr>
 
228
                        <tr>
 
229
                                <th><label><input type="radio" name="subdomain_install" value="0"<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
 
230
                                <td><?php printf( _x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ), $hostname ); ?></td>
 
231
                        </tr>
 
232
                </table>
 
233
 
 
234
<?php
 
235
        endif;
 
236
 
 
237
                if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) )
 
238
                        echo '<div class="error inline"><p><strong>' . __('Warning!') . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
 
239
 
 
240
                $is_www = ( 0 === strpos( $hostname, 'www.' ) );
 
241
                if ( $is_www ) :
 
242
                ?>
 
243
                <h3><?php esc_html_e( 'Server Address' ); ?></h3>
 
244
                <p><?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 <code>www</code> prefix with an address like <code>%2$s</code> but any links will not have the <code>www</code> prefix.' ), substr( $hostname, 4 ), $hostname ); ?></p>
 
245
                <table class="form-table">
 
246
                        <tr>
 
247
                                <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
 
248
                                <td>
 
249
                                        <?php printf( __( 'The internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
 
250
                                </td>
 
251
                        </tr>
 
252
                </table>
 
253
                <?php endif; ?>
 
254
 
 
255
                <h3><?php esc_html_e( 'Network Details' ); ?></h3>
 
256
                <table class="form-table">
 
257
                <?php if ( 'localhost' == $hostname ) : ?>
 
258
                        <tr>
 
259
                                <th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th>
 
260
                                <td><?php
 
261
                                        _e( 'Because you are using <code>localhost</code>, the sites in your WordPress network must use sub-directories. Consider using <code>localhost.localdomain</code> if you wish to use sub-domains.' );
 
262
                                        // Uh oh:
 
263
                                        if ( !allow_subdirectory_install() )
 
264
                                                echo ' <strong>' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
 
265
                                ?></td>
 
266
                        </tr>
 
267
                <?php elseif ( !allow_subdomain_install() ) : ?>
 
268
                        <tr>
 
269
                                <th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th>
 
270
                                <td><?php
 
271
                                        _e( 'Because your install is in a directory, the sites in your WordPress network must use sub-directories.' );
 
272
                                        // Uh oh:
 
273
                                        if ( !allow_subdirectory_install() )
 
274
                                                echo ' <strong>' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
 
275
                                ?></td>
 
276
                        </tr>
 
277
                <?php elseif ( !allow_subdirectory_install() ) : ?>
 
278
                        <tr>
 
279
                                <th scope="row"><?php esc_html_e( 'Sub-domain Install' ); ?></th>
 
280
                                <td><?php _e( 'Because your install is not new, the sites in your WordPress network must use sub-domains.' );
 
281
                                        echo ' <strong>' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
 
282
                                ?></td>
 
283
                        </tr>
 
284
                <?php endif; ?>
 
285
                <?php if ( ! $is_www ) : ?>
 
286
                        <tr>
 
287
                                <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
 
288
                                <td>
 
289
                                        <?php printf( __( 'The internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
 
290
                                </td>
 
291
                        </tr>
 
292
                <?php endif; ?>
 
293
                        <tr>
 
294
                                <th scope='row'><?php esc_html_e( 'Network Title' ); ?></th>
 
295
                                <td>
 
296
                                        <input name='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' />
 
297
                                        <p class="description">
 
298
                                                <?php _e( 'What would you like to call your network?' ); ?>
 
299
                                        </p>
 
300
                                </td>
 
301
                        </tr>
 
302
                        <tr>
 
303
                                <th scope='row'><?php esc_html_e( 'Network Admin Email' ); ?></th>
 
304
                                <td>
 
305
                                        <input name='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' />
 
306
                                        <p class="description">
 
307
                                                <?php _e( 'Your email address.' ); ?>
 
308
                                        </p>
 
309
                                </td>
 
310
                        </tr>
 
311
                </table>
 
312
                <?php submit_button( __( 'Install' ), 'primary', 'submit' ); ?>
 
313
        </form>
 
314
        <?php
 
315
}
 
316
 
 
317
/**
 
318
 * Prints step 2 for Network installation process.
 
319
 *
 
320
 * @since 3.0.0
 
321
 */
 
322
function network_step2( $errors = false ) {
 
323
        global $wpdb;
 
324
 
 
325
        $hostname          = get_clean_basedomain();
 
326
        $slashed_home      = trailingslashit( get_option( 'home' ) );
 
327
        $base              = parse_url( $slashed_home, PHP_URL_PATH );
 
328
        $document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
 
329
        $abspath_fix       = str_replace( '\\', '/', ABSPATH );
 
330
        $home_path         = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
 
331
        $wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
 
332
        $rewrite_base      = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
 
333
 
 
334
 
 
335
        $location_of_wp_config = $abspath_fix;
 
336
        if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) {
 
337
                $location_of_wp_config = dirname( $abspath_fix );
 
338
        }
 
339
        $location_of_wp_config = trailingslashit( $location_of_wp_config );
 
340
 
 
341
        // Wildcard DNS message.
 
342
        if ( is_wp_error( $errors ) )
 
343
                echo '<div class="error">' . $errors->get_error_message() . '</div>';
 
344
 
 
345
        if ( $_POST ) {
 
346
                if ( allow_subdomain_install() )
 
347
                        $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
 
348
                else
 
349
                        $subdomain_install = false;
 
350
        } else {
 
351
                if ( is_multisite() ) {
 
352
                        $subdomain_install = is_subdomain_install();
 
353
?>
 
354
        <p><?php _e( 'The original configuration steps are shown here for reference.' ); ?></p>
 
355
<?php
 
356
                } else {
 
357
                        $subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
 
358
?>
 
359
        <div class="error"><p><strong><?php _e('Warning:'); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
 
360
        <p><?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p>
 
361
<?php
 
362
                }
 
363
        }
 
364
 
 
365
        $subdir_match          = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
 
366
        $subdir_replacement_01 = $subdomain_install ? '' : '$1';
 
367
        $subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
 
368
 
 
369
        if ( $_POST || ! is_multisite() ) {
 
370
?>
 
371
                <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
 
372
                <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
 
373
                <div class="updated inline"><p><?php
 
374
                        if ( file_exists( $home_path . '.htaccess' ) )
 
375
                                printf( __( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), '.htaccess' );
 
376
                        elseif ( file_exists( $home_path . 'web.config' ) )
 
377
                                printf( __( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), 'web.config' );
 
378
                        else
 
379
                                _e( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> file.' );
 
380
                ?></p></div>
 
381
<?php
 
382
        }
 
383
?>
 
384
                <ol>
 
385
                        <li><p><?php printf( __( 'Add the following to your <code>wp-config.php</code> file in <code>%s</code> <strong>above</strong> the line reading <code>/* That&#8217;s all, stop editing! Happy blogging. */</code>:' ), $location_of_wp_config ); ?></p>
 
386
                                <textarea class="code" readonly="readonly" cols="100" rows="6">
 
387
define('MULTISITE', true);
 
388
define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
 
389
define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
 
390
define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
 
391
define('SITE_ID_CURRENT_SITE', 1);
 
392
define('BLOG_ID_CURRENT_SITE', 1);</textarea>
 
393
<?php
 
394
        $keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
 
395
        foreach ( $keys_salts as $c => $v ) {
 
396
                if ( defined( $c ) )
 
397
                        unset( $keys_salts[ $c ] );
 
398
        }
 
399
 
 
400
        if ( ! empty( $keys_salts ) ) {
 
401
                $keys_salts_str = '';
 
402
                $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
 
403
                if ( is_wp_error( $from_api ) ) {
 
404
                        foreach ( $keys_salts as $c => $v ) {
 
405
                                $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
 
406
                        }
 
407
                } else {
 
408
                        $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
 
409
                        foreach ( $keys_salts as $c => $v ) {
 
410
                                $keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
 
411
                        }
 
412
                }
 
413
                $num_keys_salts = count( $keys_salts );
 
414
?>
 
415
        <p><?php
 
416
                echo _n( 'This unique authentication key is also missing from your <code>wp-config.php</code> file.', 'These unique authentication keys are also missing from your <code>wp-config.php</code> file.', $num_keys_salts ); ?> <?php _e( 'To make your installation more secure, you should also add:' ) ?></p>
 
417
        <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
 
418
<?php
 
419
        }
 
420
?>
 
421
</li>
 
422
<?php
 
423
        if ( iis7_supports_permalinks() ) :
 
424
                // IIS doesn't support RewriteBase, all your RewriteBase are belong to us
 
425
                $iis_subdir_match = ltrim( $base, '/' ) . $subdir_match;
 
426
                $iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base;
 
427
                $iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
 
428
 
 
429
                $web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
 
430
<configuration>
 
431
    <system.webServer>
 
432
        <rewrite>
 
433
            <rules>
 
434
                <rule name="WordPress Rule 1" stopProcessing="true">
 
435
                    <match url="^index\.php$" ignoreCase="false" />
 
436
                    <action type="None" />
 
437
                </rule>';
 
438
                                if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
 
439
                                        $web_config_file .= '
 
440
                <rule name="WordPress Rule for Files" stopProcessing="true">
 
441
                    <match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" />
 
442
                    <action type="Rewrite" url="' . $iis_rewrite_base . WPINC . '/ms-files.php?file={R:1}" appendQueryString="false" />
 
443
                </rule>';
 
444
                }
 
445
                $web_config_file .= '
 
446
                <rule name="WordPress Rule 2" stopProcessing="true">
 
447
                    <match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" />
 
448
                    <action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" />
 
449
                </rule>
 
450
                <rule name="WordPress Rule 3" stopProcessing="true">
 
451
                    <match url="^" ignoreCase="false" />
 
452
                    <conditions logicalGrouping="MatchAny">
 
453
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
 
454
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
 
455
                    </conditions>
 
456
                    <action type="None" />
 
457
                </rule>
 
458
                <rule name="WordPress Rule 4" stopProcessing="true">
 
459
                    <match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" />
 
460
                    <action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" />
 
461
                </rule>
 
462
                <rule name="WordPress Rule 5" stopProcessing="true">
 
463
                    <match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
 
464
                    <action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" />
 
465
                </rule>
 
466
                <rule name="WordPress Rule 6" stopProcessing="true">
 
467
                    <match url="." ignoreCase="false" />
 
468
                    <action type="Rewrite" url="index.php" />
 
469
                </rule>
 
470
            </rules>
 
471
        </rewrite>
 
472
    </system.webServer>
 
473
</configuration>';
 
474
 
 
475
                echo '<li><p>';
 
476
                /* translators: 1: a filename like .htaccess. 2: a file path. */
 
477
                printf( __( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
 
478
                        '<code>web.config</code>', '<code>' . $home_path . '</code>' );
 
479
                echo '</p>';
 
480
                if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
 
481
                        echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
 
482
                ?>
 
483
                <textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?>
 
484
                </textarea></li>
 
485
                </ol>
 
486
 
 
487
        <?php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
 
488
 
 
489
                $ms_files_rewriting = '';
 
490
                if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
 
491
                        $ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
 
492
                        $ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
 
493
                }
 
494
 
 
495
                $htaccess_file = <<<EOF
 
496
RewriteEngine On
 
497
RewriteBase {$base}
 
498
RewriteRule ^index\.php$ - [L]
 
499
{$ms_files_rewriting}
 
500
# add a trailing slash to /wp-admin
 
501
RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L]
 
502
 
 
503
RewriteCond %{REQUEST_FILENAME} -f [OR]
 
504
RewriteCond %{REQUEST_FILENAME} -d
 
505
RewriteRule ^ - [L]
 
506
RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
 
507
RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L]
 
508
RewriteRule . index.php [L]
 
509
EOF;
 
510
 
 
511
                echo '<li><p>';
 
512
                /* translators: 1: a filename like .htaccess. 2: a file path. */
 
513
                printf( __( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
 
514
                        '<code>.htaccess</code>', '<code>' . $home_path . '</code>' );
 
515
                echo '</p>';
 
516
                if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
 
517
                        echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
 
518
                ?>
 
519
                <textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>">
 
520
<?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
 
521
                </ol>
 
522
 
 
523
        <?php endif; // end IIS/Apache code branches.
 
524
 
 
525
        if ( !is_multisite() ) { ?>
 
526
                <p><?php printf( __( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.') ); ?> <a href="<?php echo esc_url( site_url( 'wp-login.php' ) ); ?>"><?php _e( 'Log In' ); ?></a></p>
 
527
<?php
 
528
        }
 
529
}
 
530
 
 
531
if ( $_POST ) {
 
532
 
 
533
        check_admin_referer( 'install-network-1' );
 
534
 
 
535
        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
 
536
        // Create network tables.
 
537
        install_network();
 
538
        $base              = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
 
539
        $subdomain_install = allow_subdomain_install() ? !empty( $_POST['subdomain_install'] ) : false;
 
540
        if ( ! network_domain_check() ) {
 
541
                $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), wp_unslash( $_POST['sitename'] ), $base, $subdomain_install );
 
542
                if ( is_wp_error( $result ) ) {
 
543
                        if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() )
 
544
                                network_step2( $result );
 
545
                        else
 
546
                                network_step1( $result );
 
547
                } else {
 
548
                        network_step2();
 
549
                }
 
550
        } else {
 
551
                network_step2();
 
552
        }
 
553
} elseif ( is_multisite() || network_domain_check() ) {
 
554
        network_step2();
 
555
} else {
 
556
        network_step1();
 
557
}
 
558
?>
 
559
</div>
 
560
 
 
561
<?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>