diff options
author | Paul Arthur <paul.arthur@flowerysong.com> | 2013-02-03 11:15:03 -0500 |
---|---|---|
committer | Paul Arthur <paul.arthur@flowerysong.com> | 2013-02-03 11:16:46 -0500 |
commit | dd70337451390b260e95f998c8b79b9fefbf3b3a (patch) | |
tree | 4bfd3c3728841843badfadaca0920d4622c9f891 /lib/general.lib.php | |
parent | c8cd1da88fbf0df1a99463032d97ac42d221a774 (diff) | |
download | ampache-dd70337451390b260e95f998c8b79b9fefbf3b3a.tar.gz ampache-dd70337451390b260e95f998c8b79b9fefbf3b3a.tar.bz2 ampache-dd70337451390b260e95f998c8b79b9fefbf3b3a.zip |
Clean up PHP tests and reuse them in init.php
Also move the config-related functions out of debug.lib.php (why they
were there in the first place is anyone's guess.)
Diffstat (limited to 'lib/general.lib.php')
-rw-r--r-- | lib/general.lib.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/general.lib.php b/lib/general.lib.php index 0e0f10c8..f42c3f87 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -261,4 +261,53 @@ function translate_pattern_code($code) { } // translate_pattern_code +/** + * generate_config + * + * This takes an array of results and re-generates the config file + * this is used by the installer and by the admin/system page + */ +function generate_config($current) { + // Start building the new config file + $distfile = Config::get('prefix') . '/config/ampache.cfg.php.dist'; + $handle = fopen($distfile,'r'); + $dist = fread($handle,filesize($distfile)); + fclose($handle); + + $data = explode("\n",$dist); + + foreach ($data as $line) { + if (preg_match("/^;?([\w\d]+)\s+=\s+[\"]{1}(.*?)[\"]{1}$/",$line,$matches) + || preg_match("/^;?([\w\d]+)\s+=\s+[\']{1}(.*?)[\']{1}$/", $line, $matches) + || preg_match("/^;?([\w\d]+)\s+=\s+[\'\"]{0}(.*)[\'\"]{0}$/",$line,$matches)) { + + $key = $matches[1]; + $value = $matches[2]; + + // Put in the current value + if ($key == 'config_version') { + $line = $key . ' = ' . escape_ini($value); + } + elseif (isset($current[$key])) { + $line = $key . ' = "' . escape_ini($current[$key]) . '"'; + unset($current[$key]); + } + } + + $final .= $line . "\n"; + } + + return $final; +} + +/** + * escape_ini + * + * Escape a value used for inserting into an ini file. + * Won't quote ', like addslashes does. + */ +function escape_ini($str) { + return str_replace('"', '\"', $str); +} + ?> |