includes/functions.php
changeset 620 58852672ff12
parent 613 c08670a77871
child 621 68f8a9cc0a18
equal deleted inserted replaced
619:80fa6fa6bf3a 620:58852672ff12
    13  */
    13  */
    14 
    14 
    15 /**
    15 /**
    16  * Fetch a value from the site configuration.
    16  * Fetch a value from the site configuration.
    17  * @param string The identifier of the value ("site_name" etc.)
    17  * @param string The identifier of the value ("site_name" etc.)
       
    18  * @param string If specified, this is the "default" value for the configuration entry. Defaults to false.
    18  * @return string Configuration value, or bool(false) if the value is not set
    19  * @return string Configuration value, or bool(false) if the value is not set
    19  */
    20  */
    20 
    21 
    21 function getConfig($n)
    22 function getConfig($n, $default = false)
    22 {
    23 {
    23   global $enano_config;
    24   global $enano_config;
    24   if ( isset( $enano_config[ $n ] ) )
    25   if ( isset( $enano_config[ $n ] ) )
    25   {
    26   {
    26     return $enano_config[$n];
    27     return $enano_config[$n];
    27   }
    28   }
    28   else
    29   else
    29   {
    30   {
    30     return false;
    31     return $default;
    31   }
    32   }
    32 }
    33 }
    33 
    34 
    34 /**
    35 /**
    35  * Update or change a configuration value.
    36  * Update or change a configuration value.
    38  * @return null
    39  * @return null
    39  */
    40  */
    40 
    41 
    41 function setConfig($n, $v)
    42 function setConfig($n, $v)
    42 {
    43 {
    43 
       
    44   global $enano_config, $db;
    44   global $enano_config, $db;
       
    45   
       
    46   if ( isset($enano_config[$n]) )
       
    47   {
       
    48     if ( $enano_config[$n] === $v )
       
    49     {
       
    50       // configuration already matches this value
       
    51       return true;
       
    52     }
       
    53   }
       
    54   
    45   $enano_config[$n] = $v;
    55   $enano_config[$n] = $v;
    46   $v = $db->escape($v);
    56   $v = $db->escape($v);
    47 
    57 
    48   $e = $db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';');
    58   $e = $db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';');
    49   if ( !$e )
    59   if ( !$e )