Index: install/install_toolkit.php =================================================================== --- install/install_toolkit.php (revision 13377) +++ install/install_toolkit.php (working copy) @@ -442,62 +442,59 @@ function ParseConfig($parse_section = false) { if (!file_exists($this->INIFile)) { - return Array(); + return Array (); } - if( file_exists($this->INIFile) && !is_readable($this->INIFile) ) { + if (file_exists($this->INIFile) && !is_readable($this->INIFile)) { die('Could Not Open Ini File'); } $contents = file($this->INIFile); - $retval = Array(); - $section = ''; - $ln = 1; - $resave = false; - foreach ($contents as $line) { - if ($ln == 1 && $line != '<'.'?'.'php die() ?'.">\n") { - $resave = true; - } + if ($contents && $contents[0] == '<' . '?' . 'php die() ?' . ">\n") { + // format of "config.php" file before 5.1.0 version + array_shift($contents); - $ln++; - $line = trim($line); - $line = preg_replace('/;[.]*/', '', $line); - if (strlen($line) > 0) { - //echo $line . " - "; - if (preg_match('/^\[[a-z]+\]$/i', str_replace(' ', '', $line))) { - //echo 'section'; - $section = mb_substr($line, 1, (mb_strlen($line) - 2)); - if ($parse_section) { - $retval[$section] = array(); - } - continue; - } elseif (strpos($line, '=') !== false) { - //echo 'main element'; - list ($key, $val) = explode(' = ', $line); - if (!$parse_section) { - $retval[trim($key)] = str_replace('"', '', $val); - } - else { - $retval[$section][trim($key)] = str_replace('"', '', $val); - } - } - } + return $this->parseIniString(implode('', $contents), $parse_section); } - if ($resave) { - $fp = fopen($this->INIFile, 'w'); - reset($contents); - fwrite($fp,'<'.'?'.'php die() ?'.">\n\n"); - foreach ($contents as $line) { - fwrite($fp,"$line"); - } - fclose($fp); - } + $_CONFIG = Array (); + require($this->INIFile); - return $retval; + if ($parse_section) { + return $_CONFIG; + } + + $ret = Array (); + + foreach ($_CONFIG as $section => $section_variables) { + $ret = array_merge($ret, $section_variables); + } + + return $ret; } + /** + * Equivalent for "parse_ini_string" function available since PHP 5.3.0 + * + * @param string $ini + * @param bool $process_sections + * @param int $scanner_mode + * @return Array + */ + function parseIniString($ini, $process_sections = false, $scanner_mode = null) + { + # Generate a temporary file. + $tempname = tempnam('/tmp', 'ini'); + $fp = fopen($tempname, 'w'); + fwrite($fp, $ini); + $ini = parse_ini_file($tempname, !empty($process_sections)); + fclose($fp); + @unlink($tempname); + + return $ini; + } + function SaveConfig($silent = false) { if (!is_writable($this->INIFile) && !is_writable(dirname($this->INIFile))) { @@ -506,15 +503,16 @@ } $fp = fopen($this->INIFile, 'w'); - fwrite($fp,'<'.'?'.'php die() ?'.">\n\n"); + fwrite($fp, '<' . '?' . 'php' . "\n\n"); foreach ($this->systemConfig as $section_name => $section_data) { - fwrite($fp, '['.$section_name."]\n"); foreach ($section_data as $key => $value) { - fwrite($fp, $key.' = "'.$value.'"'."\n"); + fwrite($fp, '$_CONFIG[\'' . $section_name . '\'][\'' . $key . '\'] = \'' . addslashes($value) . '\';' . "\n"); } + fwrite($fp, "\n"); } + fclose($fp); } Index: install/upgrades.php =================================================================== --- install/upgrades.php (revision 13377) +++ install/upgrades.php (working copy) @@ -1427,6 +1427,9 @@ $this->Conn->Query('DROP TABLE IF EXISTS ' . TABLE_PREFIX . 'Phrase'); $this->Conn->Query('RENAME TABLE ' . $temp_table . ' TO ' . TABLE_PREFIX . 'Phrase'); + + // save "config.php" in php format, not ini format as before + $this->_toolkit->SaveConfig(); } } } \ No newline at end of file Index: kernel/globals.php =================================================================== --- kernel/globals.php (revision 13377) +++ kernel/globals.php (working copy) @@ -135,59 +135,63 @@ { function parse_portal_ini($file, $parse_section = false) { - if (!file_exists($file)) return false; + if (!file_exists($file)) { + return Array (); + } - if( file_exists($file) && !is_readable($file) ) die('Could Not Open Ini File'); + if (file_exists($file) && !is_readable($file)) { + die('Could Not Open Ini File'); + } $contents = file($file); - $retval = Array(); - $section = ''; - $ln = 1; - $resave = false; - foreach($contents as $line) { - if ($ln == 1 && $line != '<'.'?'.'php die() ?'.">\n") { - $resave = true; - } - $ln++; - $line = trim($line); - $line = preg_replace('/;[.]*/', '', $line); - if(strlen($line) > 0) { - //echo $line . " - "; - if (preg_match('/^\[[a-z]+\]$/i', str_replace(' ', '', $line))) { - //echo 'section'; - $section = mb_substr($line,1,(mb_strlen($line)-2)); - if ($parse_section) { - $retval[$section] = array(); - } - continue; - } elseif(strpos($line, '=') !== false) { - //echo 'main element'; - list($key,$val) = explode(' = ',$line); - if (!$parse_section) { - $retval[trim($key)] = str_replace('"', '', $val); - } - else { - $retval[$section][trim($key)] = str_replace('"', '', $val); - } - } //end if - //echo '
'; - } //end if - } //end foreach - if($resave) - { - $fp = fopen($file, 'w'); - reset($contents); - fwrite($fp,'<'.'?'.'php die() ?'.">\n\n"); - foreach($contents as $line) fwrite($fp,"$line"); - fclose($fp); + if ($contents && $contents[0] == '<' . '?' . 'php die() ?' . ">\n") { + // format of "config.php" file before 5.1.0 version + array_shift($contents); + + return parse_ini_string(implode('', $contents), $parse_section); + } + + $_CONFIG = Array (); + require($file); + + if ($parse_section) { + return $_CONFIG; } - return $retval; + $ret = Array (); + + foreach ($_CONFIG as $section => $section_variables) { + $ret = array_merge($ret, $section_variables); + } + + return $ret; } } +if ( !function_exists('parse_ini_string') ) { + /** + * Equivalent for "parse_ini_string" function available since PHP 5.3.0 + * + * @param string $ini + * @param bool $process_sections + * @param int $scanner_mode + * @return Array + */ + function parse_ini_string($ini, $process_sections = false, $scanner_mode = null) + { + # Generate a temporary file. + $tempname = tempnam('/tmp', 'ini'); + $fp = fopen($tempname, 'w'); + fwrite($fp, $ini); + $ini = parse_ini_file($tempname, !empty($process_sections)); + fclose($fp); + @unlink($tempname); + return $ini; + } +} + if( !function_exists('getmicrotime') ) { function getmicrotime()