Ticket #19796: 19796-hack-day.7.diff
File 19796-hack-day.7.diff, 10.4 KB (added by , 12 years ago) |
---|
-
wp-admin/network.php
51 51 * @return bool Whether subdomain install is allowed 52 52 */ 53 53 function allow_subdomain_install() { 54 $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( ' siteurl' ) );55 if( false !== strpos( $domain, '/' ) || 'localhost' == $domain || preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $domain ) )54 $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) ); 55 if( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) 56 56 return false; 57 57 58 58 return true; … … 144 144 function network_step1( $errors = false ) { 145 145 global $is_apache; 146 146 147 if ( get_option( 'siteurl' ) != get_option( 'home' ) ) {148 echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . sprintf( __( 'Your <strong>WordPress address</strong> must match your <strong>Site address</strong> before creating a Network. See <a href="%s">General Settings</a>.' ), esc_url( admin_url( 'options-general.php' ) ) ) . '</p></div>';149 echo '</div>';150 include ( ABSPATH . 'wp-admin/admin-footer.php' );151 die();152 }153 154 147 if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) { 155 148 echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>'; 156 149 echo '</div>'; … … 314 307 * @since 3.0.0 315 308 */ 316 309 function network_step2( $errors = false ) { 317 global $base, $wpdb; 318 $hostname = get_clean_basedomain(); 310 global $wpdb; 319 311 320 if ( ! isset( $base ) ) 321 $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) ); 312 $hostname = get_clean_basedomain(); 313 $slashed_home = trailingslashit( get_option( 'home' ) ); 314 $slashed_siteurl = trailingslashit( get_option( 'siteurl' ) ); 315 $wp_siteurl_subdir = '/' . str_replace( $slashed_home, '', $slashed_siteurl ); 316 $rewrite_base = ! empty( $wp_siteurl_subdir ) ? trailingslashit( $wp_siteurl_subdir ) : ''; 317 $base = parse_url( $slashed_home, PHP_URL_PATH ); 322 318 323 319 // Wildcard DNS message. 324 320 if ( is_wp_error( $errors ) ) 325 321 echo '<div class="error">' . $errors->get_error_message() . '</div>'; 326 322 327 if ( $_POST) {328 if ( allow_subdomain_install() ) 323 if ( ! empty( $_POST ) ) { 324 if ( allow_subdomain_install() ) { 329 325 $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true; 330 else326 } else { 331 327 $subdomain_install = false; 328 } 332 329 } else { 333 330 if ( is_multisite() ) { 334 331 $subdomain_install = is_subdomain_install(); … … 344 341 } 345 342 } 346 343 347 if ( $_POST|| ! is_multisite() ) {344 if ( ! empty( $_POST ) || ! is_multisite() ) { 348 345 ?> 349 346 <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3> 350 347 <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p> … … 369 366 <textarea class="code" readonly="readonly" cols="100" rows="7"> 370 367 define('MULTISITE', true); 371 368 define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>); 372 $base = '<?php echo $base; ?>';373 369 define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>'); 374 370 define('PATH_CURRENT_SITE', '<?php echo $base; ?>'); 375 371 define('SITE_ID_CURRENT_SITE', 1); 376 define('BLOG_ID_CURRENT_SITE', 1);</textarea> 372 define('BLOG_ID_CURRENT_SITE', 1); 373 define('WP_SITEURL_SUBDIR', '<?php echo $wp_siteurl_subdir; ?>');</textarea> 377 374 <?php 378 375 $keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' ); 379 376 foreach ( $keys_salts as $c => $v ) { 380 if ( defined( $c ) ) 377 if ( defined( $c ) ) { 381 378 unset( $keys_salts[ $c ] ); 379 } 382 380 } 381 383 382 if ( ! empty( $keys_salts ) ) { 384 383 $keys_salts_str = ''; 385 $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );384 $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); 386 385 if ( is_wp_error( $from_api ) ) { 387 386 foreach ( $keys_salts as $c => $v ) { 388 387 $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );"; … … 465 464 </rule> 466 465 <rule name="WordPress Rule 5" stopProcessing="true"> 467 466 <match url="^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*)" ignoreCase="false" /> 468 <action type="Rewrite" url=" {R:1}" />467 <action type="Rewrite" url="' . $rewrite_base . '{R:1}" /> 469 468 </rule> 470 469 <rule name="WordPress Rule 6" stopProcessing="true"> 471 470 <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" /> 472 <action type="Rewrite" url=" {R:2}" />471 <action type="Rewrite" url="' . $rewrite_base . '{R:2}" /> 473 472 </rule> 474 473 <rule name="WordPress Rule 7" stopProcessing="true"> 475 474 <match url="." ignoreCase="false" /> … … 504 503 RewriteRule ^ - [L]'; 505 504 506 505 // @todo custom content dir. 507 if ( ! $subdomain_install ) 508 $htaccess_file .= "\nRewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]\nRewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]"; 506 if ( ! $subdomain_install ) { 507 $htaccess_file .= "\nRewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $rewrite_base$1 [L]\nRewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $rewrite_base$1 [L]"; 508 } 509 509 510 510 $htaccess_file .= "\nRewriteRule . index.php [L]"; 511 511 512 512 ?> 513 <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH); ?></p>513 <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), trailingslashit( str_replace( trailingslashit( $wp_siteurl_subdir ), '', ABSPATH ) ) ); ?></p> 514 514 <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $subdomain_install ? 11 : 16; ?>"> 515 515 <?php echo esc_textarea( $htaccess_file ); ?></textarea></li> 516 516 </ol> … … 523 523 } 524 524 } 525 525 526 if ( $_POST) {526 if ( ! empty( $_POST ) ) { 527 527 528 $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );529 530 528 check_admin_referer( 'install-network-1' ); 531 529 532 530 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 531 533 532 // create network tables 534 533 install_network(); 535 $hostname = get_clean_basedomain(); 534 535 $base = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH ); 536 536 $subdomain_install = allow_subdomain_install() ? !empty( $_POST['subdomain_install'] ) : false; 537 537 538 if ( ! network_domain_check() ) { 538 539 $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), stripslashes( $_POST['sitename'] ), $base, $subdomain_install ); 539 540 if ( is_wp_error( $result ) ) { 540 if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() ) 541 if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() ) { 541 542 network_step2( $result ); 542 else543 } else { 543 544 network_step1( $result ); 545 } 544 546 } else { 545 547 network_step2(); 546 548 } -
wp-admin/network/site-new.php
62 62 63 63 if ( is_subdomain_install() ) { 64 64 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain ); 65 $path = $base;65 $path = $current_site->path; 66 66 } else { 67 67 $newdomain = $current_site->domain; 68 $path = $base. $domain . '/';68 $path = $current_site->path . $domain . '/'; 69 69 } 70 70 71 71 $password = 'N/A'; -
wp-includes/link-template.php
2129 2129 if ( 'relative' == $scheme ) 2130 2130 $url = $current_site->path; 2131 2131 else 2132 $url = $scheme . '://' . $current_site->domain . $current_site-> path;2132 $url = $scheme . '://' . $current_site->domain . $current_site->wp_siteurl_subdir; 2133 2133 2134 2134 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) 2135 2135 $url .= ltrim($path, '/'); -
wp-includes/ms-default-constants.php
47 47 * @since 1.5.0 48 48 */ 49 49 if ( !defined( 'SITECOOKIEPATH' ) ) 50 define( 'SITECOOKIEPATH', $current_site-> path);50 define( 'SITECOOKIEPATH', $current_site->wp_siteurl_subdir ); 51 51 52 52 /** 53 53 * @since 2.6.0 -
wp-includes/ms-functions.php
1142 1142 1143 1143 $wpdb->suppress_errors(false); 1144 1144 1145 $ url = get_blogaddress_by_id($blog_id);1145 $homeurl = $siteurl = untrailingslashit( get_blogaddress_by_id( $blog_id ) ); 1146 1146 1147 1147 // Set everything up 1148 1148 make_db_current_silent( 'blog' ); … … 1150 1150 populate_roles(); 1151 1151 $wp_roles->_init(); 1152 1152 1153 $url = untrailingslashit( $url ); 1154 // fix url. 1155 update_option('siteurl', $url); 1156 update_option('home', $url); 1153 // Maybe fix url 1154 if ( defined( 'WP_SITEURL_SUBDIR' ) && WP_SITEURL_SUBDIR ) 1155 $siteurl = trailingslashit( $siteurl ) . WP_SITEURL_SUBDIR; 1156 1157 update_option('siteurl', $siteurl); 1158 update_option('home', $homeurl); 1157 1159 update_option('fileupload_url', $url . "/files" ); 1158 1160 update_option('upload_path', UPLOADBLOGSDIR . "/$blog_id/files"); 1159 1161 update_option('blogname', stripslashes( $blog_title ) ); … … 1161 1163 $wpdb->update( $wpdb->options, array('option_value' => ''), array('option_name' => 'admin_email') ); 1162 1164 1163 1165 // remove all perms 1164 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'user_level' ) ); 1166 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix . 'user_level' ) ); 1167 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix . 'capabilities' ) ); 1165 1168 1166 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'capabilities' ) );1167 1168 1169 $wpdb->suppress_errors( false ); 1169 1170 } 1170 1171 -
wp-includes/ms-load.php
142 142 $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1; 143 143 $current_site->domain = DOMAIN_CURRENT_SITE; 144 144 $current_site->path = $path = PATH_CURRENT_SITE; 145 146 if( defined( 'WP_SITEURL_SUBDIR' ) ) 147 $current_site->wp_siteurl_subdir = WP_SITEURL_SUBDIR; 148 else 149 $current_site->wp_siteurl_subdir = $current_site->path; 150 145 151 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) 146 152 $current_site->blog_id = BLOG_ID_CURRENT_SITE; 147 153 elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.