Ticket #18180: 18180.5.diff

File 18180.5.diff, 3.2 KB (added by nacin, 17 months ago)
  • wp-admin/setup-config.php

     
    5252if (!file_exists(ABSPATH . 'wp-config-sample.php')) 
    5353        wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.'); 
    5454 
    55 $configFile = file(ABSPATH . 'wp-config-sample.php'); 
     55$config_file = file(ABSPATH . 'wp-config-sample.php'); 
    5656 
    5757// Check if wp-config.php has been created 
    5858if (file_exists(ABSPATH . 'wp-config.php')) 
     
    210210                        $secret_keys[$k] = substr( $v, 28, 64 ); 
    211211                } 
    212212        } 
     213 
    213214        $key = 0; 
     215        foreach ( $config_file as &$line ) { 
     216                if ( '$table_prefix  =' == substr( $line, 0, 16 ) ) { 
     217                        $line = '$table_prefix  = \'' . $prefix . "';\r\n"; 
     218                        continue; 
     219                } 
    214220 
    215         foreach ($configFile as $line_num => $line) { 
    216                 switch (substr($line,0,16)) { 
    217                         case "define('DB_NAME'": 
    218                                 $configFile[$line_num] = str_replace("database_name_here", $dbname, $line); 
     221                if ( ! preg_match( '/^define\(\'([A-Z_]+)\',([ ]+)/', $line, $match ) ) 
     222                        continue; 
     223 
     224                $constant = $match[1]; 
     225                $padding  = $match[2]; 
     226 
     227                switch ( $constant ) { 
     228                        case 'DB_NAME'     : 
     229                        case 'DB_USER'     : 
     230                        case 'DB_PASSWORD' : 
     231                        case 'DB_HOST'     : 
     232                                $line = "define('" . $constant . "'," . $padding . "'" . constant( $constant ) . "');\r\n"; 
    219233                                break; 
    220                         case "define('DB_USER'": 
    221                                 $configFile[$line_num] = str_replace("'username_here'", "'$uname'", $line); 
     234                        case 'AUTH_KEY'         : 
     235                        case 'SECURE_AUTH_KEY'  : 
     236                        case 'LOGGED_IN_KEY'    : 
     237                        case 'NONCE_KEY'        : 
     238                        case 'AUTH_SALT'        : 
     239                        case 'SECURE_AUTH_SALT' : 
     240                        case 'LOGGED_IN_SALT'   : 
     241                        case 'NONCE_SALT'       : 
     242                                $line = "define('" . $constant . "'," . $padding . "'" . $secret_keys[$key++] . "');\r\n"; 
    222243                                break; 
    223                         case "define('DB_PASSW": 
    224                                 $configFile[$line_num] = str_replace("'password_here'", "'$passwrd'", $line); 
    225                                 break; 
    226                         case "define('DB_HOST'": 
    227                                 $configFile[$line_num] = str_replace("localhost", $dbhost, $line); 
    228                                 break; 
    229                         case '$table_prefix  =': 
    230                                 $configFile[$line_num] = str_replace('wp_', $prefix, $line); 
    231                                 break; 
    232                         case "define('AUTH_KEY": 
    233                         case "define('SECURE_A": 
    234                         case "define('LOGGED_I": 
    235                         case "define('NONCE_KE": 
    236                         case "define('AUTH_SAL": 
    237                         case "define('SECURE_A": 
    238                         case "define('LOGGED_I": 
    239                         case "define('NONCE_SA": 
    240                                 $configFile[$line_num] = str_replace('put your unique phrase here', $secret_keys[$key++], $line ); 
    241                                 break; 
    242244                } 
    243245        } 
     246        unset( $line ); 
     247 
    244248        if ( ! is_writable(ABSPATH) ) : 
    245249                display_header(); 
    246250?> 
    247251<p>Sorry, but I can't write the <code>wp-config.php</code> file.</p> 
    248252<p>You can create the <code>wp-config.php</code> manually and paste the following text into it.</p> 
    249253<textarea cols="98" rows="15" class="code"><?php 
    250                 foreach( $configFile as $line ) { 
     254                foreach( $config_file as $line ) { 
    251255                        echo htmlentities($line, ENT_COMPAT, 'UTF-8'); 
    252256                } 
    253257?></textarea> 
     
    256260<?php 
    257261        else : 
    258262                $handle = fopen(ABSPATH . 'wp-config.php', 'w'); 
    259                 foreach( $configFile as $line ) { 
     263                foreach( $config_file as $line ) { 
    260264                        fwrite($handle, $line); 
    261265                } 
    262266                fclose($handle);