Index: branches/5.3.x/core/install/install_toolkit.php =================================================================== diff -u -N -r15928 -r15962 --- branches/5.3.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 15928) +++ branches/5.3.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 15962) @@ -1,6 +1,6 @@ defaultWritablePath = DIRECTORY_SEPARATOR . 'system'; + $this->systemConfig = new kSystemConfig(true, false); if ( class_exists('kApplication') ) { // auto-setup in case of separate module install @@ -107,10 +85,6 @@ $this->Conn =& $this->Application->GetADODBConnection(); } - - $this->INIFile = FULL_PATH . $this->defaultWritablePath . DIRECTORY_SEPARATOR . 'config.php'; - - $this->systemConfig = $this->ParseConfig(true); } /** @@ -209,14 +183,14 @@ $file_data = array_map('trim', $file_data); if ($modules_helper->verifyLicense($file_data[0])) { - $this->setSystemConfig('Intechnic', 'License', $file_data[0]); + $this->systemConfig->set('License', 'Intechnic', $file_data[0]); if (array_key_exists(1, $file_data)) { - $this->setSystemConfig('Intechnic', 'LicenseCode', $file_data[1]); + $this->systemConfig->set('LicenseCode', 'Intechnic', $file_data[1]); } else { - $this->setSystemConfig('Intechnic', 'LicenseCode'); + $this->systemConfig->set('LicenseCode', 'Intechnic'); } - $this->SaveConfig(); + $this->systemConfig->save(); } else { // invalid license received from licensing server @@ -257,7 +231,7 @@ } // get table prefix from config, because application may not be available here - $table_prefix = $this->getSystemConfig('Database', 'TablePrefix'); + $table_prefix = $this->systemConfig->get('TablePrefix', 'Database'); if ($module_name == 'kernel') { $module_name = 'in-portal'; @@ -278,7 +252,7 @@ function SetModuleRootCategory($module_name, $category_id = 0) { // get table prefix from config, because application may not be available here - $table_prefix = $this->getSystemConfig('Database', 'TablePrefix'); + $table_prefix = $this->systemConfig->get('TablePrefix', 'Database'); if ($module_name == 'kernel') { $module_name = 'in-portal'; @@ -355,11 +329,12 @@ */ function RunSQLText(&$sqls, $replace_from = null, $replace_to = null, $start_from = 0) { - $table_prefix = $this->getSystemConfig('Database', 'TablePrefix'); + $table_prefix = $this->systemConfig->get('TablePrefix', 'Database'); // add prefix to all tables if (strlen($table_prefix) > 0) { $replacements = Array ('INSERT INTO ', 'UPDATE ', 'ALTER TABLE ', 'DELETE FROM ', 'REPLACE INTO '); + foreach ($replacements as $replacement) { $sqls = str_replace($replacement, $replacement . $table_prefix, $sqls); } @@ -394,7 +369,7 @@ } $sql_count = count($sqls); - $db_collation = $this->getSystemConfig('Database', 'DBCollation'); + $db_collation = $this->systemConfig->get('DBCollation', 'Database'); for ($i = $start_from; $i < $sql_count; $i++) { $sql = $sqls[$i]; @@ -502,147 +477,14 @@ return $this->Conn->GetCol($sql, $id_field); } - function ParseConfig($parse_section = false) - { - if (!file_exists($this->INIFile)) { - return Array (); - } - - if (file_exists($this->INIFile) && !is_readable($this->INIFile)) { - die('Could Not Open Ini File'); - } - - $contents = file($this->INIFile); - - if ($contents && $contents[0] == '<' . '?' . 'php die() ?' . ">\n") { - // format of "config.php" file before 5.1.0 version - array_shift($contents); - - return $this->parseIniString(implode('', $contents), $parse_section); - } - - $_CONFIG = Array (); - require($this->INIFile); - - 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))) { - $error_msg = 'Cannot write to "' . $this->INIFile . '" file'; - - if ($silent) { - trigger_error($error_msg, E_USER_WARNING); - } - else { - throw new Exception($error_msg); - } - - return ; - } - - $fp = fopen($this->INIFile, 'w'); - fwrite($fp, '<' . '?' . 'php' . "\n\n"); - - foreach ($this->systemConfig as $section_name => $section_data) { - foreach ($section_data as $key => $value) { - fwrite($fp, '$_CONFIG[\'' . $section_name . '\'][\'' . $key . '\'] = \'' . addslashes($value) . '\';' . "\n"); - } - - fwrite($fp, "\n"); - } - - fclose($fp); - - $this->systemConfigChanged = false; - } - - /** - * Sets value to system config (yet SaveConfig must be called to write it to file) - * - * @param string $section - * @param string $key - * @param string $value - */ - function setSystemConfig($section, $key, $value = null) - { - $this->systemConfigChanged = true; - - if (isset($value)) { - if (!array_key_exists($section, $this->systemConfig)) { - // create section, when missing - $this->systemConfig[$section] = Array (); - } - - // create key in section - $this->systemConfig[$section][$key] = $value; - return ; - } - - unset($this->systemConfig[$section][$key]); - } - - /** - * Returns information from system config - * - * @param string $section - * @param string $key - * @param mixed $default - * @return string|bool - */ - function getSystemConfig($section, $key, $default = false) - { - if ( !array_key_exists($section, $this->systemConfig) ) { - return $default; - } - - if ( !array_key_exists($key, $this->systemConfig[$section]) ) { - return $default; - } - - return isset($this->systemConfig[$section][$key]) ? $this->systemConfig[$section][$key] : $default; - } - - /** * Checks if system config is present and is not empty * * @return bool */ function systemConfigFound() { - return file_exists($this->INIFile) && $this->systemConfig; + return $this->systemConfig->exists(); } /** @@ -653,7 +495,7 @@ */ function sectionFound($section) { - return array_key_exists($section, $this->systemConfig); + return $this->systemConfig->sectionFound($section); } /** @@ -912,7 +754,7 @@ */ function deleteEditTables() { - $table_prefix = $this->getSystemConfig('Database', 'TablePrefix'); + $table_prefix = $this->systemConfig->get('TablePrefix', 'Database'); $tables = $this->Conn->GetCol('SHOW TABLES'); $mask_edit_table = '/' . $table_prefix . 'ses_(.*)_edit_(.*)/'; @@ -1124,7 +966,7 @@ public function getWorkingCacheHandlers($current = null) { if ( !isset($current) ) { - $current = $this->getSystemConfig('Misc', 'CacheHandler'); + $current = $this->systemConfig->get('CacheHandler', 'Misc'); } $cache_handler = $this->Application->makeClass('kCache'); @@ -1166,7 +1008,7 @@ public function getWorkingCompressionEngines($current = null) { if ( !isset($current) ) { - $current = $this->getSystemConfig('Misc', 'CompressionEngine'); + $current = $this->systemConfig->get('CompressionEngine', 'Misc'); } $output = shell_exec('java -version 2>&1');