]> git.mxchange.org Git - mailer.git/blobdiff - inc/config-functions.php
Migration of stelzi's commit 1022 with some changes so we have a nicer code. See...
[mailer.git] / inc / config-functions.php
index 186ede833979629932d5b0994eec5780746665a1..506db1b908613789c62beb9e43428beecaa9d3b2 100644 (file)
@@ -49,16 +49,16 @@ function mergeConfig ($newConfig) {
 }
 
 // Getter for $_CONFIG entries
-function getConfig ($entry) {
+function getConfig ($configEntry) {
        global $_CONFIG;
 
        // Default value
        $value = null;
 
        // Is the entry there?
-       if (isConfigEntrySet($entry)) {
+       if (isConfigEntrySet($configEntry)) {
                // Then use it
-               $value = $_CONFIG[$entry];
+               $value = $_CONFIG[$configEntry];
        } // END - if
 
        // Return it
@@ -66,20 +66,26 @@ function getConfig ($entry) {
 }
 
 // Setter for $_CONFIG entries
-function setConfigEntry ($entry, $value) {
+function setConfigEntry ($configEntry, $value) {
        global $_CONFIG;
 
        // Secure the entry name
-       $entry = SQL_ESCAPE($entry);
+       if (function_exists('SQL_ESCAPE')) {
+               // Use our secure function
+               $configEntry = SQL_ESCAPE($configEntry);
+       } else {
+               // Use maybe insecure function
+               $configEntry = smartAddSlashes($configEntry);
+       }
 
        // And set it
-       $_CONFIG[$entry] = $value;
+       $_CONFIG[$configEntry] = $value;
 }
 
 // Checks wether the given config entry is set
-function isConfigEntrySet ($entry) {
+function isConfigEntrySet ($configEntry) {
        global $_CONFIG;
-       return (isset($_CONFIG[$entry]));
+       return (isset($_CONFIG[$configEntry]));
 }
 
 // Increment or init with given value or 1 as default the given config entry
@@ -105,6 +111,7 @@ function isConfigLoaded () {
 // Init the config array
 function initConfig () {
        global $_CONFIG;
+       debug_report_bug('Reached!');
 
        // Set a minimum dummy configuration
        $_CONFIG = array(
@@ -116,19 +123,17 @@ function initConfig () {
 
 // Load configuration and return it as an arry
 function loadConfiguration ($no = '0') {
-       global $_CONFIG;
-
        // Check for cache extension, cache-array and if the requested configuration is in cache
-       if ((is_array($GLOBALS['cache_array'])) && (isset($GLOBALS['cache_array']['config'][$no])) && (is_array($GLOBALS['cache_array']['config'][$no]))) {
+       if ((isset($GLOBALS['cache_array'])) && (is_array($GLOBALS['cache_array'])) && (isset($GLOBALS['cache_array']['config'][$no])) && (is_array($GLOBALS['cache_array']['config'][$no]))) {
                // Load config from cache
                //* DEBUG: */ echo gettype($GLOBALS['cache_array']['config'][$no])."<br />\n";
                foreach ($GLOBALS['cache_array']['config'][$no] as $key => $value) {
-                       $_CONFIG[$key] = $value;
+                       setConfigEntry($key, $value);
                } // END - foreach
 
                // Count cache hits if exists
-               if ((isset($_CONFIG['cache_hits'])) && (EXT_IS_ACTIVE('cache'))) {
-                       $_CONFIG['cache_hits']++;
+               if ((isConfigEntrySet('cache_hits')) && (EXT_IS_ACTIVE('cache'))) {
+                       incrementConfigEntry('cache_hits');
                } // END - if
        } elseif ((!EXT_IS_ACTIVE('cache')) || (!isset($GLOBALS['cache_array']['config'][$no]))) {
                // Load config from DB
@@ -138,14 +143,14 @@ function loadConfiguration ($no = '0') {
                // Is the config there?
                if (SQL_NUMROWS($result_config) == 1) {
                        // Get config from database
-                       $_CONFIG = SQL_FETCHARRAY($result_config);
+                       mergeConfig(SQL_FETCHARRAY($result_config));
                } // END - if
 
                // Free result
                SQL_FREERESULT($result_config);
 
                // Remember this config in the array
-               $GLOBALS['cache_array']['config'][$no] = $_CONFIG;
+               $GLOBALS['cache_array']['config'][$no] = getConfigArray();
        }
 }
 
@@ -153,8 +158,17 @@ function loadConfiguration ($no = '0') {
 function getConfigArray () {
        global $_CONFIG;
 
-       // Return it
-       return $_CONFIG;
+       // Default is null
+       $return = null;
+
+       // Is the config set?
+       if (isConfigLoaded()) {
+               // Then use it
+               $return = $_CONFIG;
+       } // END - if
+
+       // Return result
+       return $return;
 }
 
 // [EOF]