From 97596be52eb3e437603508b3efa8695549ec1508 Mon Sep 17 00:00:00 2001 From: "Aldo \"xoen\" Giambelluca" Date: Sun, 11 Jul 2010 22:44:48 +0200 Subject: [PATCH] added `writeConfiguration()` method to OC_CONFIG This actually write all the key/value into the config.php. The code in `writeAdminLisener()` is cleaner. This is in prevision of new configuration options (e.g. plugin related) --- inc/lib_config.php | 79 ++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 28 deletions(-) mode change 100755 => 100644 inc/lib_config.php diff --git a/inc/lib_config.php b/inc/lib_config.php old mode 100755 new mode 100644 index 5058f387a13..af8f030786d --- a/inc/lib_config.php +++ b/inc/lib_config.php @@ -109,7 +109,32 @@ class OC_CONFIG{ return false; } } - + + /** + * Write the configuration to the `config.php` file + * + * $configuration contains key/value + * - the key is the option name without the 'CONFIG_' prefix + * - the value is a string or a boolean + * + * @param array $configuration is an associarive array + */ + protected static function saveConfiguration($configuration) { + global $SERVERROOT; + global $WEBROOT; + + $configContent = ' $value ) { + if ( is_string($value) ) { + $configContent .= "\n\$CONFIG_$key = '$value';"; + } else if ( is_bool($value) ) { + $value = $value ? 'true' : 'false'; + $configContent .= "\n\$CONFIG_$key = $value;"; + } + } + $filename = "$SERVERROOT/config/config.php"; + file_put_contents($filename, $configContent); + } /** * lisen for admin configuration changes and write it to the file @@ -234,42 +259,40 @@ class OC_CONFIG{ $error.='error while trying to add the admin user to the admin group
'; } } - //storedata - $config=' '; - $filename=$SERVERROOT.'/config/config.php'; - if(empty($error)){ - header("Location: ".$WEBROOT."/"); - try{ - file_put_contents($filename,$config); - }catch(Exception $e){ + if( empty($error) ) { + header("Location: $WEBROOT/"); + try { + // Write the configuration array to `/config/config.php` + OC_CONFIG::saveConfiguration($config); + } catch ( Exception $e ) { $error.='error while trying to save the configuration file
'; return $error; } - }else{ + } else { return $error; } - } return($error); - } } } -- 2.39.5