Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Sack <kde@jakobsack.de>2011-04-08 18:54:12 +0400
committerJakob Sack <kde@jakobsack.de>2011-04-08 18:54:12 +0400
commitf66d3ab208e056bac699fef17c6e9ad6257f368b (patch)
tree1bbbcc7b61ce93030742c6a0858d977bec37fd48 /lib/config.php
parent908e377246cd770b7a3f9f2f4d929e29ffb22f25 (diff)
Implementation of OC_APPCONFIG, OC_CONFIG and OC_PREFERENCES
Diffstat (limited to 'lib/config.php')
-rw-r--r--lib/config.php95
1 files changed, 90 insertions, 5 deletions
diff --git a/lib/config.php b/lib/config.php
index 3e660a5fb55..1b7783403ca 100644
--- a/lib/config.php
+++ b/lib/config.php
@@ -53,8 +53,9 @@ class OC_CONFIG{
* does not return the values.
*/
public static function getKeys(){
- // TODO: write function
- return array();
+ self::readData();
+
+ return array_keys( self::$cache );
}
/**
@@ -67,7 +68,12 @@ class OC_CONFIG{
* $default will be returned.
*/
public static function getValue( $key, $default = null ){
- // TODO: write function
+ self::readData();
+
+ if( array_key_exists( $key, self::$cache )){
+ return self::$cache[$key];
+ }
+
return $default;
}
@@ -81,7 +87,14 @@ class OC_CONFIG{
* not be written, false will be returned.
*/
public static function setValue( $key, $value ){
- // TODO: write function
+ self::readData();
+
+ // Add change
+ self::$cache[$key] = $value;
+
+ // Write changes
+ self::writeData();
+
return true;
}
@@ -94,7 +107,79 @@ class OC_CONFIG{
* write access to config.php, the function will return false.
*/
public static function deleteKey( $key ){
- // TODO: write function
+ self::readData();
+
+ if( array_key_exists( $key, self::$cache )){
+ // Delete key from cache
+ unset( self::$cache[$key] );
+
+ // Write changes
+ self::writeData();
+ }
+
+ return true;
+ }
+
+ /**
+ * @brief Loads the config file
+ * @returns true/false
+ *
+ * Reads the config file and saves it to the cache
+ */
+ private static function readData( $key ){
+ if( !self::$init ){
+ return true;
+ }
+
+ global $SERVERROOT;
+
+ if( !file_exists( "$SERVERROOT/config/config.php" )){
+ return false;
+ }
+
+ // Include the file, save the data from $CONFIG
+ include( "$SERVERROOT/config/config.php" );
+ self::$cache = $CONFIG;
+
+ // We cached everything
+ self::$init = true;
+
+ return true;
+ }
+
+ /**
+ * @brief Writes the config file
+ * @returns true/false
+ *
+ * Saves the config to the config file.
+ *
+ * Known flaws: Strings are not escaped properly
+ */
+ public static function writeData( $key ){
+ // We need the serverroot path
+ global $SERVERROOT;
+
+ // Create a php file ...
+ $content = "<?php\n\$CONFIG = array(\n";
+
+ foreach( self::$cache as $key => $value ){
+ if( is_bool( $value )){
+ $value = $value ? 'true' : 'false';
+ $content .= "\"$key\" => $value,\n";
+ }
+ elseif( is_numeric( $value )){
+ $content .= "\"$key\" => $value,\n";
+ }
+ else{
+ $value = str_replace( "'", "\\'", $value );
+ $configContent .= "\"$key\" => '$value',\n";
+ }
+ }
+ $content .= ");\n?>\n";
+
+ // Write the file
+ file_put_contents( "$SERVERROOT/config/config.php", $content );
+
return true;
}
}