diff options
author | Thomas Bruederli <thomas@roundcube.net> | 2013-06-28 22:54:29 +0200 |
---|---|---|
committer | Thomas Bruederli <thomas@roundcube.net> | 2013-06-28 22:54:29 +0200 |
commit | 47278835f5173a65b797643e2a90edfcb55a1c5f (patch) | |
tree | 39753c5e46924b1f0cb2ebf90f23a8a3b0cbb038 /installer | |
parent | 9bacb2cd3f7e8f96a29f651460954965c400aac6 (diff) |
Preserve comments and order from existing or default config files
Diffstat (limited to 'installer')
-rw-r--r-- | installer/rcube_install.php | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/installer/rcube_install.php b/installer/rcube_install.php index 06622de4d..da636555b 100644 --- a/installer/rcube_install.php +++ b/installer/rcube_install.php @@ -118,6 +118,28 @@ class rcube_install if (is_readable($file)) { include $file; + // read comments from config file + if (function_exists('token_get_all')) { + $tokens = token_get_all(file_get_contents($file)); + $in_config = false; + $buffer = ''; + for ($i=0; $i < count($tokens); $i++) { + $token = $tokens[$i]; + if ($token[0] == T_VARIABLE && $token[1] == '$config' || $token[1] == '$rcmail_config') { + $in_config = true; + if ($buffer && $tokens[$i+1] == '[' && $tokens[$i+2][0] == T_CONSTANT_ENCAPSED_STRING) { + $propname = trim($tokens[$i+2][1], "'\""); + $this->comments[$propname] = $buffer; + $buffer = ''; + $i += 3; + } + } + else if ($in_config && $token[0] == T_COMMENT) { + $buffer .= strtr($token[1], array('\n' => "\n")); + } + } + } + // deprecated name of config variable if (is_array($rcmail_config)) { return $rcmail_config; @@ -225,15 +247,13 @@ class rcube_install $config[$prop] = $value; } - // sort by option name - ksort($config); - $out = "<?php\n\n"; + $out .= "/* Local configuration for Roundcube Webmail */\n\n"; foreach ($config as $prop => $value) { - // @TODO: copy option descriptions from defaults.inc.php file? - $out .= "\$config['$prop'] = " . rcube_install::_dump_var($value, $prop) . ";\n"; + // copy option descriptions from existing config or defaults.inc.php + $out .= $this->comments[$prop]; + $out .= "\$config['$prop'] = " . rcube_install::_dump_var($value, $prop) . ";\n\n"; } - $out .= "\n?>"; return $out; } |