Added "default" option for getConfig() and made setConfig() only set if the new value is different
authorDan
Wed, 09 Jul 2008 21:04:51 -0400
changeset 620 58852672ff12
parent 619 80fa6fa6bf3a
child 621 68f8a9cc0a18
Added "default" option for getConfig() and made setConfig() only set if the new value is different
includes/functions.php
--- a/includes/functions.php	Wed Jul 09 21:04:10 2008 -0400
+++ b/includes/functions.php	Wed Jul 09 21:04:51 2008 -0400
@@ -15,10 +15,11 @@
 /**
  * Fetch a value from the site configuration.
  * @param string The identifier of the value ("site_name" etc.)
+ * @param string If specified, this is the "default" value for the configuration entry. Defaults to false.
  * @return string Configuration value, or bool(false) if the value is not set
  */
 
-function getConfig($n)
+function getConfig($n, $default = false)
 {
   global $enano_config;
   if ( isset( $enano_config[ $n ] ) )
@@ -27,7 +28,7 @@
   }
   else
   {
-    return false;
+    return $default;
   }
 }
 
@@ -40,8 +41,17 @@
 
 function setConfig($n, $v)
 {
-
   global $enano_config, $db;
+  
+  if ( isset($enano_config[$n]) )
+  {
+    if ( $enano_config[$n] === $v )
+    {
+      // configuration already matches this value
+      return true;
+    }
+  }
+  
   $enano_config[$n] = $v;
   $v = $db->escape($v);