network_step2()
最后更新于:2021-11-27 17:13:26
network_step2( false|GC_Error$errors=false)Prints step 2 for Network installation process.
参数
- $errors
-
(false|GC_Error) (Optional) Error object.
Default value: false
源文件
文件: gc-admin/includes/network.php
function network_step2( $errors = false ) {
global $gcdb, $is_nginx;
$hostname = get_clean_basedomain();
$slashed_home = trailingslashit( get_option( 'home' ) );
$base = parse_url( $slashed_home, PHP_URL_PATH );
$document_root_fix = str_replace( '\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
$abspath_fix = str_replace( '\', '/', ABSPATH );
$home_path = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
$gc_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
$rewrite_base = ! empty( $gc_siteurl_subdir ) ? ltrim( trailingslashit( $gc_siteurl_subdir ), '/' ) : '';
$location_of_gc_config = $abspath_fix;
if ( ! file_exists( ABSPATH . 'gc-config.php' ) && file_exists( dirname( ABSPATH ) . '/gc-config.php' ) ) {
$location_of_gc_config = dirname( $abspath_fix );
}
$location_of_gc_config = trailingslashit( $location_of_gc_config );
// Wildcard DNS message.
if ( is_gc_error( $errors ) ) {
echo '<div class="error">' . $errors->get_error_message() . '</div>';
}
if ( $_POST ) {
if ( allow_subdomain_install() ) {
$subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
} else {
$subdomain_install = false;
}
} else {
if ( is_multisite() ) {
$subdomain_install = is_subdomain_install();
?>
<p><?php _e( 'The original configuration steps are shown here for reference.' ); ?></p>
<?php
} else {
$subdomain_install = (bool) $gcdb->get_var( "SELECT meta_value FROM $gcdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
?>
<div class="error"><p><strong><?php _e( 'Warning:' ); ?></strong> <?php _e( 'An existing GeChiUI network was detected.' ); ?></p></div>
<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>
<?php
}
}
$subdir_match = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
$subdir_replacement_01 = $subdomain_install ? '' : '$1';
$subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
if ( $_POST || ! is_multisite() ) {
?>
<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
<p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
<div class="notice notice-warning inline"><p>
<?php
if ( file_exists( $home_path . '.htaccess' ) ) {
echo '<strong>' . __( 'Caution:' ) . '</strong> ';
printf(
/* translators: 1: gc-config.php, 2: .htaccess */
__( 'We recommend you back up your existing %1$s and %2$s files.' ),
'<code>gc-config.php</code>',
'<code>.htaccess</code>'
);
} elseif ( file_exists( $home_path . 'web.config' ) ) {
echo '<strong>' . __( 'Caution:' ) . '</strong> ';
printf(
/* translators: 1: gc-config.php, 2: web.config */
__( 'We recommend you back up your existing %1$s and %2$s files.' ),
'<code>gc-config.php</code>',
'<code>web.config</code>'
);
} else {
echo '<strong>' . __( 'Caution:' ) . '</strong> ';
printf(
/* translators: %s: gc-config.php */
__( 'We recommend you back up your existing %s file.' ),
'<code>gc-config.php</code>'
);
}
?>
</p></div>
<?php
}
?>
<ol>
<li><p>
<?php
printf(
/* translators: 1: gc-config.php, 2: Location of gc-config file, 3: Translated version of "That's all, stop editing! Happy publishing." */
__( 'Add the following to your %1$s file in %2$s <strong>above</strong> the line reading %3$s:' ),
'<code>gc-config.php</code>',
'<code>' . $location_of_gc_config . '</code>',
/*
* translators: This string should only be translated if gc-config-sample.php is localized.
* You can check the localized release package or
* https://i18n.svn.gechiui.org/<locale code>/branches/<gc version>/dist/gc-config-sample.php
*/
'<code>/* ' . __( 'That’s all, stop editing! Happy publishing.' ) . ' */</code>'
);
?>
</p>
<textarea class="code" readonly="readonly" cols="100" rows="7">
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> );
define( 'DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>' );
define( 'PATH_CURRENT_SITE', '<?php echo $base; ?>' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
</textarea>
<?php
$keys_salts = array(
'AUTH_KEY' => '',
'SECURE_AUTH_KEY' => '',
'LOGGED_IN_KEY' => '',
'NONCE_KEY' => '',
'AUTH_SALT' => '',
'SECURE_AUTH_SALT' => '',
'LOGGED_IN_SALT' => '',
'NONCE_SALT' => '',
);
foreach ( $keys_salts as $c => $v ) {
if ( defined( $c ) ) {
unset( $keys_salts[ $c ] );
}
}
if ( ! empty( $keys_salts ) ) {
$keys_salts_str = '';
$from_api = gc_remote_get( 'https://api.gechiui.org/secret-key/1.1/salt/' );
if ( is_gc_error( $from_api ) ) {
foreach ( $keys_salts as $c => $v ) {
$keys_salts_str .= "ndefine( '$c', '" . gc_generate_password( 64, true, true ) . "' );";
}
} else {
$from_api = explode( "n", gc_remote_retrieve_body( $from_api ) );
foreach ( $keys_salts as $c => $v ) {
$keys_salts_str .= "ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
}
}
$num_keys_salts = count( $keys_salts );
?>
<p>
<?php
if ( 1 === $num_keys_salts ) {
printf(
/* translators: %s: gc-config.php */
__( 'This unique authentication key is also missing from your %s file.' ),
'<code>gc-config.php</code>'
);
} else {
printf(
/* translators: %s: gc-config.php */
__( 'These unique authentication keys are also missing from your %s file.' ),
'<code>gc-config.php</code>'
);
}
?>
<?php _e( 'To make your installation more secure, you should also add:' ); ?>
</p>
<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
<?php
}
?>
</li>
<?php
if ( iis7_supports_permalinks() ) :
// IIS doesn't support RewriteBase, all your RewriteBase are belong to us.
$iis_subdir_match = ltrim( $base, '/' ) . $subdir_match;
$iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base;
$iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
$web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="GeChiUI Rule 1" stopProcessing="true">
<match url="^index.php$" ignoreCase="false" />
<action type="None" />
</rule>';
if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
$web_config_file .= '
<rule name="GeChiUI Rule for Files" stopProcessing="true">
<match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" />
<action type="Rewrite" url="' . $iis_rewrite_base . GCINC . '/ms-files.php?file={R:1}" appendQueryString="false" />
</rule>';
}
$web_config_file .= '
<rule name="GeChiUI Rule 2" stopProcessing="true">
<match url="^' . $iis_subdir_match . 'gc-admin$" ignoreCase="false" />
<action type="Redirect" url="' . $iis_subdir_replacement . 'gc-admin/" redirectType="Permanent" />
</rule>
<rule name="GeChiUI Rule 3" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="GeChiUI Rule 4" stopProcessing="true">
<match url="^' . $iis_subdir_match . '(gc-(content|admin|includes).*)" ignoreCase="false" />
<action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" />
</rule>
<rule name="GeChiUI Rule 5" stopProcessing="true">
<match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*.php)$" ignoreCase="false" />
<action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" />
</rule>
<rule name="GeChiUI Rule 6" stopProcessing="true">
<match url="." ignoreCase="false" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
';
echo '<li><p>';
printf(
/* translators: 1: File name (.htaccess or web.config), 2: File path. */
__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other GeChiUI rules:' ),
'<code>web.config</code>',
'<code>' . $home_path . '</code>'
);
echo '</p>';
if ( ! $subdomain_install && GC_CONTENT_DIR !== ABSPATH . 'gc-content' ) {
echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom gc-content directories.' ) . '</strong></p>';
}
?>
<textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?></textarea>
</li>
</ol>
<?php
elseif ( $is_nginx ) : // End iis7_supports_permalinks(). Link to Nginx documentation instead:
echo '<li><p>';
printf(
/* translators: %s: Documentation URL. */
__( 'It seems your network is running with Nginx web server. <a href="https://docs.gechiui.com/functions/network_step2/%s">Learn more about further configuration</a>.' ),
__( 'https://gechiui.org/support/article/nginx/' )
);
echo '</p></li>';
else : // End $is_nginx. Construct an .htaccess file instead:
$ms_files_rewriting = '';
if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
$ms_files_rewriting = "n# uploaded filesnRewriteRule ^";
$ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . GCINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "n";
}
$htaccess_file = <<<EOF
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase {$base}
RewriteRule ^index.php$ - [L]
{$ms_files_rewriting}
# add a trailing slash to /gc-admin
RewriteRule ^{$subdir_match}gc-admin$ {$subdir_replacement_01}gc-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^{$subdir_match}(gc-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
RewriteRule ^{$subdir_match}(.*.php)$ {$rewrite_base}$subdir_replacement_12 [L]
RewriteRule . index.php [L]
EOF;
echo '<li><p>';
printf(
/* translators: 1: File name (.htaccess or web.config), 2: File path. */
__( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other GeChiUI rules:' ),
'<code>.htaccess</code>',
'<code>' . $home_path . '</code>'
);
echo '</p>';
if ( ! $subdomain_install && GC_CONTENT_DIR !== ABSPATH . 'gc-content' ) {
echo '<p><strong>' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom gc-content directories.' ) . '</strong></p>';
}
?>
<textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "n" ) + 1; ?>"><?php echo esc_textarea( $htaccess_file ); ?></textarea>
</li>
</ol>
<?php
endif; // End IIS/Nginx/Apache code branches.
if ( ! is_multisite() ) {
?>
<p><?php _e( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.' ); ?> <a href="https://docs.gechiui.com/functions/network_step2/<?php echo esc_url( gc_login_url() ); ?>"><?php _e( 'Log In' ); ?></a></p>
<?php
}
}