Added encryption stuff + rewrote sendWernisApiRequest() to handle the decryption.
[mailer.git] / inc / wrapper-functions.php
index 733d25ce18a201d0046bf6e7b18401f9fec0e134..ab921c4b4f0752a52a4cfc376ae54f528d27748e 100644 (file)
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Wrapper-Funktionen                               *
  * -------------------------------------------------------------------- *
- * $Revision::                                                        $ *
- * $Date::                                                            $ *
- * $Tag:: 0.2.1-FINAL                                                 $ *
- * $Author::                                                          $ *
- * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -46,41 +41,40 @@ function readFromFile ($FQFN) {
        if (!isFileReadable($FQFN)) {
                // This should not happen
                reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!');
-       } elseif (!isset($GLOBALS['file_content'][$FQFN])) {
-               // Load the file
-               if (function_exists('file_get_contents')) {
-                       // Use new function
-                       $GLOBALS['file_content'][$FQFN] = file_get_contents($FQFN);
-               } else {
-                       // Fall-back to implode-file chain
-                       $GLOBALS['file_content'][$FQFN] = implode('', file($FQFN));
-               }
        } // END - if
 
+       // Load the file
+       if (function_exists('file_get_contents')) {
+               // Use new function
+               $fileContent = file_get_contents($FQFN);
+       } else {
+               // Fall-back to implode-file chain
+               $fileContent = implode('', file($FQFN));
+       }
+
        // Return the content
-       return $GLOBALS['file_content'][$FQFN];
+       return $fileContent;
 }
 
 // Writes content to a file
-function writeToFile ($FQFN, $content, $aquireLock = false) {
+function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
        // Is the file writeable?
        if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
                // Not writeable!
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN)));
+               logDebugMessage(__FUNCTION__, __LINE__, sprintf('File %s not writeable or cannot change CHMOD to 0644.', basename($FQFN)));
 
                // Failed! :(
-               return false;
+               return FALSE;
        } // END - if
 
        // By default all is failed...
-       $GLOBALS['file_readable'][$FQFN] = false;
-       unset($GLOBALS['file_content'][$FQFN]);
-       $return = false;
+       $GLOBALS['file_readable'][$FQFN] = FALSE;
+       $return = FALSE;
 
        // Is the function there?
        if (function_exists('file_put_contents')) {
                // With lock?
-               if ($aquireLock === true) {
+               if ($aquireLock === TRUE) {
                        // Write it directly with lock
                        $return = file_put_contents($FQFN, $content, LOCK_EX);
                } else {
@@ -91,9 +85,9 @@ function writeToFile ($FQFN, $content, $aquireLock = false) {
                // Write it with fopen
                $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
 
-               // Do we need to aquire a lock?
-               if ($aquireLock === true) {
-                       // Aquire lock
+               // Aquire a lock?
+               if ($aquireLock === TRUE) {
+                       // Aquire a lock.
                        flock($fp, LOCK_EX);
                } // END - if
 
@@ -105,16 +99,13 @@ function writeToFile ($FQFN, $content, $aquireLock = false) {
        }
 
        // Was something written?
-       if ($return !== false) {
+       if ($return !== FALSE) {
                // Mark it as readable
-               $GLOBALS['file_readable'][$FQFN] = true;
-
-               // Remember content in cache
-               $GLOBALS['file_content'][$FQFN] = $content;
+               $GLOBALS['file_readable'][$FQFN] = TRUE;
        } // END - if
 
        // Return status
-       return (($return !== false) && (changeMode($FQFN, 0644)));
+       return (($return !== FALSE) && (changeMode($FQFN, 0644)));
 }
 
 // Clears the output buffer. This function does *NOT* backup sent content.
@@ -123,16 +114,13 @@ function clearOutputBuffer () {
        if (isset($GLOBALS[__FUNCTION__])) {
                // This function is called twice
                reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.');
-       } // END - if
-
-       // Trigger an error on failure
-       if ((ob_get_length() > 0) && (!ob_end_clean())) {
+       } elseif ((ob_get_length() > 0) && (!ob_end_clean())) {
                // Failed!
                reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
        } // END - if
 
        // Mark this function as called
-       $GLOBALS[__FUNCTION__] = true;
+       $GLOBALS[__FUNCTION__] = TRUE;
 }
 
 // Encode strings
@@ -157,26 +145,38 @@ function decodeEntities ($str, $quote = ENT_NOQUOTES) {
 }
 
 // Merges an array together but only if both are arrays
-function merge_array ($array1, $array2) {
+function merge_array ($array1, $array2, $keepIndex = FALSE) {
        // Are both an array?
        if ((!is_array($array1)) && (!is_array($array2))) {
                // Both are not arrays
                reportBug(__FUNCTION__, __LINE__, 'No arrays provided!');
        } elseif (!is_array($array1)) {
                // Left one is not an array
-               reportBug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
+               reportBug(__FUNCTION__, __LINE__, sprintf('array1 is not an array. array != %s', gettype($array1)));
        } elseif (!is_array($array2)) {
                // Right one is not an array
-               reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
+               reportBug(__FUNCTION__, __LINE__, sprintf('array2 is not an array. array != %s', gettype($array2)));
        }
 
-       // Merge both together
-       return array_merge($array1, $array2);
+       // Maintain index of array2?
+       if ($keepIndex === TRUE) {
+               // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :(
+               foreach ($array2 as $key => $value) {
+                       // Add it
+                       $array1[$key] = $value;
+               } // END - foreach
+
+               // Return it
+               return $array1;
+       } else {
+               // Merge both together normally
+               return array_merge($array1, $array2);
+       }
 }
 
 // Check if given FQFN is a readable file
 function isFileReadable ($FQFN) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS['file_readable'][$FQFN])) {
                // Check all...
                $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN)));
@@ -188,13 +188,13 @@ function isFileReadable ($FQFN) {
 
 // Checks whether the given FQFN is a directory and not ., .. or .svn
 function isDirectory ($FQFN) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
                // Generate baseName
                $baseName = basename($FQFN);
 
                // Check it
-               $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
+               $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && (!in_array($baseName, array('.', '..', '.svn'))));
        } // END - if
 
        // Return the result
@@ -202,12 +202,12 @@ function isDirectory ($FQFN) {
 }
 
 // "Getter" for the real remote IP number
-function detectRealIpAddress () {
+function detectRealIpAddress ($alwaysReal = FALSE) {
        // Get remote ip from environment
        $remoteAddr = determineRealRemoteAddress();
 
        // Is removeip installed?
-       if (isExtensionActive('removeip')) {
+       if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
                // Then anonymize it
                $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
        } // END - if
@@ -217,12 +217,12 @@ function detectRealIpAddress () {
 }
 
 // "Getter" for remote IP number
-function detectRemoteAddr () {
+function detectRemoteAddr ($alwaysReal = FALSE) {
        // Get remote ip from environment
-       $remoteAddr = determineRealRemoteAddress(true);
+       $remoteAddr = determineRealRemoteAddress(TRUE);
 
        // Is removeip installed?
-       if (isExtensionActive('removeip')) {
+       if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
                // Then anonymize it
                $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
        } // END - if
@@ -232,12 +232,12 @@ function detectRemoteAddr () {
 }
 
 // "Getter" for remote hostname
-function detectRemoteHostname () {
+function detectRemoteHostname ($alwaysReal = FALSE) {
        // Get remote ip from environment
        $remoteHost = getenv('REMOTE_HOST');
 
        // Is removeip installed?
-       if (isExtensionActive('removeip')) {
+       if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
                // Then anonymize it
                $remoteHost = getAnonymousRemoteHost($remoteHost);
        } // END - if
@@ -247,12 +247,12 @@ function detectRemoteHostname () {
 }
 
 // "Getter" for user agent
-function detectUserAgent ($alwaysReal = false) {
+function detectUserAgent ($alwaysReal = FALSE) {
        // Get remote ip from environment
        $userAgent = getenv('HTTP_USER_AGENT');
 
        // Is removeip installed?
-       if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
+       if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
                // Then anonymize it
                $userAgent = getAnonymousUserAgent($userAgent);
        } // END - if
@@ -262,12 +262,12 @@ function detectUserAgent ($alwaysReal = false) {
 }
 
 // "Getter" for referer
-function detectReferer () {
+function detectReferer ($alwaysReal = FALSE) {
        // Get remote ip from environment
        $referer = getenv('HTTP_REFERER');
 
        // Is removeip installed?
-       if (isExtensionActive('removeip')) {
+       if ((isExtensionActive('removeip')) && ($alwaysReal === TRUE)) {
                // Then anonymize it
                $referer = getAnonymousReferer($referer);
        } // END - if
@@ -296,7 +296,7 @@ function detectServerName () {
 // Removes any  existing www. from SERVER_NAME. This is very silly but enough
 // for our purpose here.
 function detectDomainName () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Get server name
                $domainName = detectServerName();
@@ -320,7 +320,7 @@ function isInstalling () {
        // Determine whether we are installing
        if (!isset($GLOBALS['__mailer_installing'])) {
                // Check URL (css.php/js.php need this)
-               $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing');
+               $GLOBALS['__mailer_installing'] = (isGetRequestElementSet('installing') || ((isAjaxOutputMode()) && (isGetRequestElementSet('level')) && (getRequestElement('level') == 'install')));
        } // END - if
 
        // Return result
@@ -329,7 +329,7 @@ function isInstalling () {
 
 // Check whether this script is installed
 function isInstalled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine whether this script is installed
                $GLOBALS[__FUNCTION__] = (
@@ -337,9 +337,9 @@ function isInstalled () {
                        // First is config
                        (
                                (
-                                       isConfigEntrySet('MXCHANGE_INSTALLED')
+                                       isConfigEntrySet('MAILER_INSTALLED')
                                ) && (
-                                       getConfig('MXCHANGE_INSTALLED') == 'Y'
+                                       getConfig('MAILER_INSTALLED') == 'Y'
                                )
                        )
                ) || (
@@ -380,13 +380,37 @@ function isAdminRegistered () {
 // Checks whether the hourly reset mode is active
 function isHourlyResetEnabled () {
        // Now simply check it
-       return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === true));
+       return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE));
+}
+
+// Checks whether the daily reset mode is active
+function isDailyResetEnabled () {
+       // Now simply check it
+       return ((isset($GLOBALS['daily_enabled'])) && ($GLOBALS['daily_enabled'] === TRUE));
+}
+
+// Checks whether the weekly reset mode is active
+function isWeeklyResetEnabled () {
+       // Now simply check it
+       return ((isset($GLOBALS['weekly_enabled'])) && ($GLOBALS['weekly_enabled'] === TRUE));
+}
+
+// Checks whether the monthly reset mode is active
+function isMonthlyResetEnabled () {
+       // Now simply check it
+       return ((isset($GLOBALS['monthly_enabled'])) && ($GLOBALS['monthly_enabled'] === TRUE));
+}
+
+// Checks whether the yearly reset mode is active
+function isYearlyResetEnabled () {
+       // Now simply check it
+       return ((isset($GLOBALS['yearly_enabled'])) && ($GLOBALS['yearly_enabled'] === TRUE));
 }
 
-// Checks whether the reset mode is active
+// Checks whether one of the reset modes is enabled
 function isResetModeEnabled () {
        // Now simply check it
-       return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
+       return ((isHourlyResetEnabled()) || (isDailyResetEnabled()) || (isWeeklyResetEnabled()) || (isMonthlyResetEnabled()) || (isYearlyResetEnabled()));
 }
 
 // Checks whether the debug mode is enabled
@@ -401,12 +425,60 @@ function isDebugModeEnabled () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// Checks whether the debug reset is enabled
-function isDebugResetEnabled () {
+// Checks whether the debug hourly is enabled
+function isDebugHourlyEnabled () {
+       // Is cache set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Simply check it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_HOURLY')) && (getConfig('DEBUG_HOURLY') == 'Y'));
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether the debug daily is enabled
+function isDebugDailyEnabled () {
+       // Is cache set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Simply check it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_DAILY')) && (getConfig('DEBUG_DAILY') == 'Y'));
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether the debug weekly is enabled
+function isDebugWeeklyEnabled () {
+       // Is cache set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Simply check it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether the debug monthly is enabled
+function isDebugMonthlyEnabled () {
+       // Is cache set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Simply check it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether the debug yearly is enabled
+function isDebugYearlyEnabled () {
        // Is cache set?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Simply check it
-               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y'));
        } // END - if
 
        // Return it
@@ -437,9 +509,21 @@ function isDebugRegularExpressionEnabled () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// Checks whether debugging of build mails is enabled
+function isDebugBuildMailsEnabled () {
+       // Is cache set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Simply check it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_BUILD_MAILS')) && (getConfig('DEBUG_BUILD_MAILS') == 'Y'));
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Checks whether the cache instance is valid
-function isCacheInstanceValid () {
-       // Do we have cache?
+function isValidCacheInstance () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
@@ -454,7 +538,7 @@ function isCacheInstanceValid () {
 // even if there is no xdebug extension installed.
 function copyFileVerified ($source, $dest, $chmod = '') {
        // Failed is the default
-       $status = false;
+       $status = FALSE;
 
        // Is the source file there?
        if (!isFileReadable($source)) {
@@ -474,17 +558,17 @@ function copyFileVerified ($source, $dest, $chmod = '') {
                reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
        } else {
                // Reset cache
-               $GLOBALS['file_readable'][$dest] = true;
+               $GLOBALS['file_readable'][$dest] = TRUE;
        }
 
+       // All fine by default
+       $status = TRUE;
+
        // If there are chmod rights set, apply them
        if (!empty($chmod)) {
                // Try to apply them
                $status = changeMode($dest, $chmod);
-       } else {
-               // All fine
-               $status = true;
-       }
+       } // END - if
 
        // All fine
        return $status;
@@ -508,7 +592,7 @@ function removeFile ($FQFN) {
        // Is the file there?
        if (isFileReadable($FQFN)) {
                // Reset cache first
-               $GLOBALS['file_readable'][$FQFN] = false;
+               $GLOBALS['file_readable'][$FQFN] = FALSE;
 
                // Yes, so remove it
                return unlink($FQFN);
@@ -516,24 +600,30 @@ function removeFile ($FQFN) {
 
        // All fine if no file was removed. If we change this to 'false' or rewrite
        // above if() block it would be to restrictive.
-       return true;
+       return TRUE;
 }
 
 // Wrapper for $_POST['sel']
 function countPostSelection ($element = 'sel') {
-       // Is it set?
-       if (isPostRequestElementSet($element)) {
-               // Return counted elements
-               return countSelection(postRequestElement($element));
-       } else {
-               // Return zero if not found
-               return '0';
-       }
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$element])) {
+               // Default is zero
+               $GLOBALS[__FUNCTION__][$element] = '0';
+
+               // Is it set?
+               if (isPostRequestElementSet($element)) {
+                       // Return counted elements
+                       $GLOBALS[__FUNCTION__][$element] = countSelection(postRequestElement($element));
+               } // END - if
+       } // END - if
+
+       // Return cached value
+       return $GLOBALS[__FUNCTION__][$element];
 }
 
 // Checks whether the config-local.php is loaded
 function isConfigLocalLoaded () {
-       return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
+       return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === TRUE));
 }
 
 // Checks whether a nickname or userid was entered and caches the result
@@ -541,7 +631,7 @@ function isNicknameUsed ($userid) {
        // Is the cache there
        if (!isset($GLOBALS[__FUNCTION__][$userid])) {
                // Determine it
-               $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, true, false) . '') != $userid) && ($userid != 'NULL'));
+               $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL'));
        } // END - if
 
        // Return the result
@@ -549,7 +639,7 @@ function isNicknameUsed ($userid) {
 }
 
 // Getter for 'what' value
-function getWhat ($strict = true) {
+function getWhat ($strict = TRUE) {
        // Default is null
        $what = NULL;
 
@@ -579,12 +669,12 @@ function setWhatFromConfig ($configEntry) {
 }
 
 // Checks whether what is set and optionally aborts on miss
-function isWhatSet ($strict =  false) {
+function isWhatSet ($strict = FALSE) {
        // Check for it
        $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
 
        // Should we abort here?
-       if (($strict === true) && ($isset === false)) {
+       if (($strict === TRUE) && ($isset === FALSE)) {
                // Output backtrace
                debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
        } // END - if
@@ -594,7 +684,7 @@ function isWhatSet ($strict =  false) {
 }
 
 // Getter for 'action' value
-function getAction ($strict = true) {
+function getAction ($strict = TRUE) {
        // Default is null
        $action = NULL;
 
@@ -614,12 +704,12 @@ function setAction ($newAction) {
 }
 
 // Checks whether action is set and optionally aborts on miss
-function isActionSet ($strict =  false) {
+function isActionSet ($strict = FALSE) {
        // Check for it
        $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
 
        // Should we abort here?
-       if (($strict === true) && ($isset === false)) {
+       if (($strict === TRUE) && ($isset === FALSE)) {
                // Output backtrace
                reportBug(__FUNCTION__, __LINE__, 'action is empty.');
        } // END - if
@@ -629,7 +719,7 @@ function isActionSet ($strict =  false) {
 }
 
 // Getter for 'module' value
-function getModule ($strict = true) {
+function getModule ($strict = TRUE) {
        // Default is null
        $module = NULL;
 
@@ -649,19 +739,40 @@ function setModule ($newModule) {
        $GLOBALS['__module'] = strtolower($newModule);
 }
 
+// Wrapper to get extra module names
+function getExtraModule () {
+       // Default is 'NULL'
+       $extra = 'NULL';
+
+       // Is 'tab/step' set?
+       if (isPostRequestElementSet('tab')) {
+               // Use this
+               $extra = 'tab=' . postRequestElement('tab');
+       } elseif (isPostRequestElementSet('step')) {
+               // Use this
+               $extra = 'step=' . postRequestElement('step');
+       } elseif ((isActionSet()) && (isWhatSet())) {
+               // Use 'action/what'
+               $extra = 'action=' . getAction() . ':what=' . getWhat();
+       }
+
+       // Return it
+       return $extra;
+}
+
 // Checks whether module is set and optionally aborts on miss
-function isModuleSet ($strict =  false) {
+function isModuleSet ($strict = FALSE) {
        // Check for it
        $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
 
        // Should we abort here?
-       if (($strict === true) && ($isset === false)) {
+       if (($strict === TRUE) && ($isset === FALSE)) {
                // Output backtrace
                reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
        } // END - if
 
        // Return it
-       return (($isset === true) && ($GLOBALS['__module'] != 'unknown')) ;
+       return (($isset === TRUE) && ($GLOBALS['__module'] != 'unknown')) ;
 }
 
 // Getter for 'output_mode' value
@@ -683,18 +794,18 @@ function getScriptOutputMode () {
 }
 
 // Setter for 'output_mode' value
-function setOutputMode ($newOutputMode) {
+function setScriptOutputMode ($newOutputMode) {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
        $GLOBALS['__output_mode'] = (int) $newOutputMode;
 }
 
 // Checks whether output_mode is set and optionally aborts on miss
-function isOutputModeSet ($strict =  false) {
+function isOutputModeSet ($strict = FALSE) {
        // Check for it
        $isset = (isset($GLOBALS['__output_mode']));
 
        // Should we abort here?
-       if (($strict === true) && ($isset === false)) {
+       if (($strict === TRUE) && ($isset === FALSE)) {
                // Output backtrace
                reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
        } // END - if
@@ -704,7 +815,7 @@ function isOutputModeSet ($strict =  false) {
 }
 
 // Enables block-mode
-function enableBlockMode ($enabled = true) {
+function enableBlockMode ($enabled = TRUE) {
        $GLOBALS['__block_mode'] = $enabled;
 }
 
@@ -713,7 +824,7 @@ function isBlockModeEnabled () {
        // Abort if not set
        if (!isset($GLOBALS['__block_mode'])) {
                // Needs to be fixed
-               reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
+               reportBug(__FUNCTION__, __LINE__, '__block_mode is not set.');
        } // END - if
 
        // Return it
@@ -740,39 +851,39 @@ function redirectToRequestUri () {
 // Wrapper function to redirect to de-refered URL
 function redirectToDereferedUrl ($url) {
        // Redirect to to
-       redirectToUrl(generateDerefererUrl($url));
+       redirectToUrl(generateDereferrerUrl($url));
 }
 
 // Wrapper function for checking if extension is installed and newer or same version
-function isExtensionInstalledAndNewer ($ext_name, $version) {
+function isExtensionInstalledAndNewer ($ext_name, $ext_ver) {
        // Is an cache entry found?
-       if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
+       if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
                // Determine it
-               $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
+               $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE));
        } else {
                // Cache hits should be incremented twice
                incrementStatsEntry('cache_hits', 2);
        }
 
        // Return it
-       //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
-       return $GLOBALS[__FUNCTION__][$ext_name][$version];
+       //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
+       return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
 }
 
 // Wrapper function for checking if extension is installed and older than given version
-function isExtensionInstalledAndOlder ($ext_name, $version) {
+function isExtensionInstalledAndOlder ($ext_name, $ext_ver) {
        // Is an cache entry found?
-       if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
+       if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
                // Determine it
-               $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
+               $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '<') === TRUE));
        } else {
                // Cache hits should be incremented twice
                incrementStatsEntry('cache_hits', 2);
        }
 
        // Return it
-       //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '&lt;' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
-       return $GLOBALS[__FUNCTION__][$ext_name][$version];
+       //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '&lt;' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
+       return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
 }
 
 // Set username
@@ -793,8 +904,8 @@ function getUsername () {
 }
 
 // Wrapper function for installation phase
-function isInstallationPhase () {
-       // Do we have cache?
+function isInstaller () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
@@ -843,7 +954,7 @@ function getCurrentAdminLogin () {
        // Log debug message
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
 
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
@@ -888,6 +999,9 @@ function setAdminMd5 ($adminMd5) {
        // Set session
        $status = setSession('admin_md5', $adminMd5);
 
+       // Remove cache to get correct results
+       unset($GLOBALS['isAdmin']);
+
        // Return status
        return $status;
 }
@@ -904,7 +1018,7 @@ function getAdminMd5 () {
 // Init user data array
 function initUserData () {
        // User id should not be zero
-       if (!isValidUserId(getCurrentUserId())) {
+       if (!isValidId(getCurrentUserId())) {
                // Should be always valid
                reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
        } // END - if
@@ -917,7 +1031,7 @@ function initUserData () {
 // Getter for user data
 function getUserData ($column) {
        // User id should not be zero
-       if (!isValidUserId(getCurrentUserId())) {
+       if (!isValidId(getCurrentUserId())) {
                // Should be always valid
                reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
        } // END - if
@@ -936,7 +1050,7 @@ function getUserData ($column) {
 
 // Checks whether given user data is set to 'Y'
 function isUserDataEnabled ($column) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
                // Determine it
                $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
@@ -952,7 +1066,7 @@ function getUserDataArray () {
        $userid = getCurrentUserId();
 
        // Is the current userid valid?
-       if (!isValidUserId($userid)) {
+       if (!isValidId($userid)) {
                // Should be always valid
                reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
        } // END - if
@@ -969,14 +1083,14 @@ function getUserDataArray () {
 
 // Checks if the user data is valid, this may indicate that the user has logged
 // in, but you should use isMember() if you want to find that out.
-function isUserDataValid () {
+function isValidUserData () {
        // User id should not be zero so abort here
        if (!isCurrentUserIdSet()) {
                // Debug message, may be noisy
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
 
                // Abort here
-               return false;
+               return FALSE;
        } // END - if
 
        // Is it cached?
@@ -1030,10 +1144,10 @@ function getCurrentUserId () {
 
 // Checks if current userid is set
 function isCurrentUserIdSet () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
+               $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidId($GLOBALS['current_userid'])));
        } // END - if
 
        // Return cache
@@ -1042,10 +1156,10 @@ function isCurrentUserIdSet () {
 
 // Unsets current userid
 function unsetCurrentUserId () {
-       // Do we have it set?
+       // Is it set?
        if (isset($GLOBALS['current_userid'])) {
                // Unset this, too
-               unset($GLOBALS['isValidUserId'][$GLOBALS['current_userid']]);
+               unset($GLOBALS['isValidId'][$GLOBALS['current_userid']]);
        } // END - if
 
        // Unset all cache entries
@@ -1055,11 +1169,11 @@ function unsetCurrentUserId () {
 }
 
 // Checks whether we are debugging template cache
-function isDebuggingTemplateCache () {
-       // Do we have cache?
+function isDebugTemplateCacheEnabled () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_TEMPLATE_CACHE')) && (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y'));
        } // END - if
 
        // Return cache
@@ -1075,7 +1189,7 @@ function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
                $data = NULL;
 
                // Can we fetch the user data?
-               if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
+               if ((isValidId($userid)) && (fetchUserData($userid, $keyColumn))) {
                        // Now get the data back
                        $data = getUserData($valueColumn);
                } // END - if
@@ -1091,8 +1205,8 @@ function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
 
 // Wrapper for strpos() to ease porting from deprecated ereg() function
 function isInString ($needle, $haystack) {
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
-       return (strpos($haystack, $needle) !== false);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== FALSE));
+       return (strpos($haystack, $needle) !== FALSE);
 }
 
 // Wrapper for strpos() to ease porting from deprecated eregi() function
@@ -1145,6 +1259,8 @@ function getHttpStatus () {
  * @access  private
  */
 function sendRawRedirect ($url) {
+       //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url);
+
        // Clear output buffer
        clearOutputBuffer();
 
@@ -1152,7 +1268,7 @@ function sendRawRedirect ($url) {
        $GLOBALS['__output'] = '';
 
        // To make redirects working (no content type), output mode must be raw
-       setOutputMode(-1);
+       setScriptOutputMode(-1);
 
        // Send helping header
        setHttpStatus('302 Found');
@@ -1162,6 +1278,7 @@ function sendRawRedirect ($url) {
 
        // Revert entity &amp;
        $url = str_replace('&amp;', '&', $url);
+       //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url);
 
        // check if running on IIS < 6 with CGI-PHP
        if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
@@ -1181,7 +1298,7 @@ function sendRawRedirect ($url) {
 
 // Determines the country of the given user id
 function determineCountry ($userid) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$userid])) {
                // Default is 'invalid'
                $GLOBALS[__FUNCTION__][$userid] = 'invalid';
@@ -1209,13 +1326,14 @@ function getTotalConfirmedUser () {
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Then do it
                if (isExtensionActive('user')) {
-                       $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
+                       $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
                } else {
                        $GLOBALS[__FUNCTION__] = 0;
                }
        } // END - if
 
        // Return cached value
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
        return $GLOBALS[__FUNCTION__];
 }
 
@@ -1225,13 +1343,14 @@ function getTotalUnconfirmedUser () {
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Then do it
                if (isExtensionActive('user')) {
-                       $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
+                       $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
                } else {
                        $GLOBALS[__FUNCTION__] = 0;
                }
        } // END - if
 
        // Return cached value
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
        return $GLOBALS[__FUNCTION__];
 }
 
@@ -1241,13 +1360,14 @@ function getTotalLockedUser () {
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Then do it
                if (isExtensionActive('user')) {
-                       $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
+                       $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
                } else {
                        $GLOBALS[__FUNCTION__] = 0;
                }
        } // END - if
 
        // Return cached value
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
        return $GLOBALS[__FUNCTION__];
 }
 
@@ -1257,36 +1377,43 @@ function getTotalRandomRefidUser () {
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Then do it
                if (isExtensionInstalledAndNewer('user', '0.3.4')) {
-                       $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, runFilterChain('user_exclusion_sql', ' '), '>=');
+                       $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
                } else {
                        $GLOBALS[__FUNCTION__] = 0;
                }
        } // END - if
 
        // Return cached value
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
        return $GLOBALS[__FUNCTION__];
 }
 
-// Is given userid valid?
-function isValidUserId ($userid) {
+// Is given id number valid?
+function isValidId ($id) {
        // Debug message
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id[' . gettype($id) . ']=' . $id);
 
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__][$userid])) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$id])) {
                // Check it out
-               $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
+               $GLOBALS[__FUNCTION__][$id] = ((isValidNumber($id)) && (!is_bool($id)) && ($id != '00000') && ($id > 0));
        } // END - if
 
        // Return cache
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',result=' . intval($GLOBALS[__FUNCTION__][$userid]));
-       return $GLOBALS[__FUNCTION__][$userid];
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',result=' . intval($GLOBALS[__FUNCTION__][$id]));
+       return $GLOBALS[__FUNCTION__][$id];
+}
+
+// Checks whether a valid number is given
+function isValidNumber ($num) {
+       // Determine it
+       return ((!is_null($num)) && (!empty($num)) && ('*' . bigintval($num, TRUE, FALSE) . '*' == '*' . $num . '*'));
 }
 
 // Encodes entities
 function encodeEntities ($str) {
        // Secure it first
-       $str = secureString($str, true, true);
+       $str = secureString($str, TRUE, TRUE);
 
        // Encode dollar sign as well
        $str = str_replace('$', '&#36;', $str);
@@ -1295,35 +1422,11 @@ function encodeEntities ($str) {
        return $str;
 }
 
-// "Getter" for date from patch_ctime
-function getDateFromRepository () {
-       // Is it cached?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Then set it
-               $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for date/time from patch_ctime
-function getDateTimeFromRepository () {
-       // Is it cached?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Then set it
-               $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
 // Getter for current year (default)
 function getYear ($timestamp = NULL) {
        // Is it cached?
        if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
-               // null is time()
+               // If NULL is set, use time()
                if (is_null($timestamp)) {
                        $timestamp = time();
                } // END - if
@@ -1340,7 +1443,7 @@ function getYear ($timestamp = NULL) {
 function getMonth ($timestamp = NULL) {
        // Is it cached?
        if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
-               // If null is set, use time()
+               // If NULL is set, use time()
                if (is_null($timestamp)) {
                        // Use time() which is current timestamp
                        $timestamp = time();
@@ -1465,10 +1568,10 @@ function getMinute ($timestamp = NULL) {
 
 // Checks whether the title decoration is enabled
 function isTitleDecorationEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Just check it
-               $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_title_deco')) && (getConfig('enable_title_deco') == 'Y'));
        } // END - if
 
        // Return cache
@@ -1477,7 +1580,7 @@ function isTitleDecorationEnabled () {
 
 // Checks whether filter usage updates are enabled (expensive queries!)
 function isFilterUsageUpdateEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
@@ -1489,7 +1592,7 @@ function isFilterUsageUpdateEnabled () {
 
 // Checks whether debugging of weekly resets is enabled
 function isWeeklyResetDebugEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
@@ -1501,7 +1604,7 @@ function isWeeklyResetDebugEnabled () {
 
 // Checks whether debugging of monthly resets is enabled
 function isMonthlyResetDebugEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
@@ -1511,12 +1614,24 @@ function isMonthlyResetDebugEnabled () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// Checks whether debugging of yearly resets is enabled
+function isYearlyResetDebugEnabled () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y'));
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Checks whether displaying of debug SQLs are enabled
 function isDisplayDebugSqlEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (isConfigEntrySet('display_debug_sql')) && (getDisplayDebugSqls() == 'Y'));
        } // END - if
 
        // Return cache
@@ -1525,10 +1640,10 @@ function isDisplayDebugSqlEnabled () {
 
 // Checks whether module title is enabled
 function isModuleTitleEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_mod_title')) && (getConfig('enable_mod_title') == 'Y'));
        } // END - if
 
        // Return cache
@@ -1537,10 +1652,22 @@ function isModuleTitleEnabled () {
 
 // Checks whether what title is enabled
 function isWhatTitleEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_what_title')) && (getConfig('enable_what_title') == 'Y'));
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for internal_stats
+function getInternalStats () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('internal_stats');
        } // END - if
 
        // Return cache
@@ -1549,10 +1676,10 @@ function isWhatTitleEnabled () {
 
 // Checks whether stats are enabled
 function ifInternalStatsEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
-               // Then determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
+               // Then determine it, do not add isExtensionInstalledAndNewer() here as it breaks very first SQL query
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('internal_stats')) && (getInternalStats() == 'Y'));
        } // END - if
 
        // Return cached value
@@ -1561,10 +1688,10 @@ function ifInternalStatsEnabled () {
 
 // Checks whether admin-notification of certain user actions is enabled
 function isAdminNotificationEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.3.0')) && (isConfigEntrySet('admin_notify')) && (getAdminNotify() == 'Y'));
        } // END - if
 
        // Return cache
@@ -1573,10 +1700,10 @@ function isAdminNotificationEnabled () {
 
 // Checks whether random referral id selection is enabled
 function isRandomReferralIdEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isConfigEntrySet('select_user_zero_refid')) && (getSelectUserZeroRefid() == 'Y'));
        } // END - if
 
        // Return cache
@@ -1585,7 +1712,7 @@ function isRandomReferralIdEnabled () {
 
 // "Getter" for default language
 function getDefaultLanguage () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
@@ -1597,7 +1724,7 @@ function getDefaultLanguage () {
 
 // "Getter" for default referral id
 function getDefRefid () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('def_refid');
@@ -1609,7 +1736,7 @@ function getDefRefid () {
 
 // "Getter" for path
 function getPath () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('PATH');
@@ -1621,7 +1748,7 @@ function getPath () {
 
 // "Getter" for url
 function getUrl () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('URL');
@@ -1633,7 +1760,7 @@ function getUrl () {
 
 // "Getter" for cache_path
 function getCachePath () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
@@ -1643,9 +1770,33 @@ function getCachePath () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// "Getter" for cache_extension
+function getCacheExtension () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('CACHE_EXTENSION');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for WRITE_FOOTER
+function getWriteFooter () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('WRITE_FOOTER');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // "Getter" for secret_key
 function getSecretKey () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('secret_key');
@@ -1657,7 +1808,7 @@ function getSecretKey () {
 
 // "Getter" for SITE_KEY
 function getSiteKey () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
@@ -1669,7 +1820,7 @@ function getSiteKey () {
 
 // "Getter" for DATE_KEY
 function getDateKey () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
@@ -1681,7 +1832,7 @@ function getDateKey () {
 
 // "Getter" for master_salt
 function getMasterSalt () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('master_salt');
@@ -1693,7 +1844,7 @@ function getMasterSalt () {
 
 // "Getter" for prime
 function getPrime () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
@@ -1705,7 +1856,7 @@ function getPrime () {
 
 // "Getter" for encrypt_separator
 function getEncryptSeparator () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
@@ -1717,7 +1868,7 @@ function getEncryptSeparator () {
 
 // "Getter" for mysql_prefix
 function getMysqlPrefix () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
@@ -1729,7 +1880,7 @@ function getMysqlPrefix () {
 
 // "Getter" for table_type
 function getTableType () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
@@ -1739,9 +1890,21 @@ function getTableType () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// "Getter" for db_type
+function getDbType () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('_DB_TYPE');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // "Getter" for salt_length
 function getSaltLength () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('salt_length');
@@ -1753,7 +1916,7 @@ function getSaltLength () {
 
 // "Getter" for output_mode
 function getOutputMode () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
@@ -1765,7 +1928,7 @@ function getOutputMode () {
 
 // "Getter" for full_version
 function getFullVersion () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
@@ -1777,7 +1940,7 @@ function getFullVersion () {
 
 // "Getter" for title
 function getTitle () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('TITLE');
@@ -1787,21 +1950,9 @@ function getTitle () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for curr_svn_revision
-function getCurrentRepositoryRevision () {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
 // "Getter" for server_url
 function getServerUrl () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
@@ -1813,7 +1964,7 @@ function getServerUrl () {
 
 // "Getter" for mt_word
 function getMtWord () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('mt_word');
@@ -1825,7 +1976,7 @@ function getMtWord () {
 
 // "Getter" for mt_word2
 function getMtWord2 () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
@@ -1837,7 +1988,7 @@ function getMtWord2 () {
 
 // "Getter" for mt_word3
 function getMtWord3 () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
@@ -1849,7 +2000,7 @@ function getMtWord3 () {
 
 // "Getter" for START_TDAY
 function getStartTday () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
@@ -1861,7 +2012,7 @@ function getStartTday () {
 
 // "Getter" for START_YDAY
 function getStartYday () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
@@ -1873,7 +2024,7 @@ function getStartYday () {
 
 // "Getter" for main_title
 function getMainTitle () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
@@ -1885,7 +2036,7 @@ function getMainTitle () {
 
 // "Getter" for file_hash
 function getFileHash () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('file_hash');
@@ -1897,7 +2048,7 @@ function getFileHash () {
 
 // "Getter" for pass_scramble
 function getPassScramble () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
@@ -1909,7 +2060,7 @@ function getPassScramble () {
 
 // "Getter" for ap_inactive_since
 function getApInactiveSince () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
@@ -1921,7 +2072,7 @@ function getApInactiveSince () {
 
 // "Getter" for user_min_confirmed
 function getUserMinConfirmed () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
@@ -1930,166 +2081,93 @@ function getUserMinConfirmed () {
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
-
-// "Getter" for auto_purge
-function getAutoPurge () {
-       // Do we have cache?
+// "Getter" for points
+function getPoints () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
+               $GLOBALS[__FUNCTION__] = getConfig('POINTS');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for bonus_userid
-function getBonusUserid () {
-       // Do we have cache?
+// "Getter" for slogan
+function getSlogan () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
+               $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for ap_inactive_time
-function getApInactiveTime () {
-       // Do we have cache?
+// "Getter" for copy
+function getCopy () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
+               $GLOBALS[__FUNCTION__] = getConfig('COPY');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for ap_dm_timeout
-function getApDmTimeout () {
-       // Do we have cache?
+// "Getter" for webmaster
+function getWebmaster () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
+               $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for ap_tasks_time
-function getApTasksTime () {
-       // Do we have cache?
+// "Getter" for sql_count
+function getSqlCount () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
+               $GLOBALS[__FUNCTION__] = getConfig('sql_count');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for ap_unconfirmed_time
-function getApUnconfirmedTime () {
-       // Do we have cache?
+// "Getter" for num_templates
+function getNumTemplates () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
+               $GLOBALS[__FUNCTION__] = getConfig('num_templates');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for points
-function getPoints () {
-       // Do we have cache?
+// "Getter" for dns_cache_timeout
+function getDnsCacheTimeout () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('POINTS');
+               $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for slogan
-function getSlogan () {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for copy
-function getCopy () {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('COPY');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for webmaster
-function getWebmaster () {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for sql_count
-function getSqlCount () {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('sql_count');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for num_templates
-function getNumTemplates () {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('num_templates');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for dns_cache_timeout
-function getDnsCacheTimeout () {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for menu_blur_spacer
-function getMenuBlurSpacer () {
-       // Do we have cache?
+// "Getter" for menu_blur_spacer
+function getMenuBlurSpacer () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
@@ -2101,7 +2179,7 @@ function getMenuBlurSpacer () {
 
 // "Getter" for points_register
 function getPointsRegister () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('points_register');
@@ -2113,7 +2191,7 @@ function getPointsRegister () {
 
 // "Getter" for points_ref
 function getPointsRef () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('points_ref');
@@ -2125,7 +2203,7 @@ function getPointsRef () {
 
 // "Getter" for ref_payout
 function getRefPayout () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
@@ -2137,7 +2215,7 @@ function getRefPayout () {
 
 // "Getter" for online_timeout
 function getOnlineTimeout () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
@@ -2149,7 +2227,7 @@ function getOnlineTimeout () {
 
 // "Getter" for index_home
 function getIndexHome () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('index_home');
@@ -2161,7 +2239,7 @@ function getIndexHome () {
 
 // "Getter" for one_day
 function getOneDay () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
@@ -2171,21 +2249,9 @@ function getOneDay () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for activate_xchange
-function getActivateXchange () {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
 // "Getter" for img_type
 function getImgType () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('img_type');
@@ -2197,7 +2263,7 @@ function getImgType () {
 
 // "Getter" for code_length
 function getCodeLength () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('code_length');
@@ -2207,24 +2273,24 @@ function getCodeLength () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for least_cats
-function getLeastCats () {
-       // Do we have cache?
+// "Getter" for min_password_length
+function getMinPasswordLength () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('least_cats');
+               $GLOBALS[__FUNCTION__] = getConfig('min_password_length');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for pass_len
-function getPassLen () {
-       // Do we have cache?
+// "Getter" for min_password_score
+function getMinPasswordScore () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('pass_len');
+               $GLOBALS[__FUNCTION__] = getConfig('min_password_score');
        } // END - if
 
        // Return cache
@@ -2233,7 +2299,7 @@ function getPassLen () {
 
 // "Getter" for admin_menu
 function getAdminMenu () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
@@ -2243,24 +2309,60 @@ function getAdminMenu () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for last_month
-function getLastMonth () {
-       // Do we have cache?
+// "Getter" for last_hourly
+function getLastHourly () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('last_hourly');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for last_daily
+function getLastDaily () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('last_daily');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for last_weekly
+function getLastWeekly () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('last_weekly');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for last_monthly
+function getLastMonthly () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('last_month');
+               $GLOBALS[__FUNCTION__] = getConfig('last_monthly');
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for max_send
-function getMaxSend () {
-       // Do we have cache?
+// "Getter" for last_yearly
+function getLastYearly () {
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('max_send');
+               $GLOBALS[__FUNCTION__] = getConfig('last_yearly');
        } // END - if
 
        // Return cache
@@ -2269,7 +2371,7 @@ function getMaxSend () {
 
 // "Getter" for mails_page
 function getMailsPage () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('mails_page');
@@ -2281,7 +2383,7 @@ function getMailsPage () {
 
 // "Getter" for rand_no
 function getRandNo () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('rand_no');
@@ -2293,7 +2395,7 @@ function getRandNo () {
 
 // "Getter" for __DB_NAME
 function getDbName () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
@@ -2305,7 +2407,7 @@ function getDbName () {
 
 // "Getter" for DOMAIN
 function getDomain () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
@@ -2317,7 +2419,7 @@ function getDomain () {
 
 // "Getter" for proxy_username
 function getProxyUsername () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
@@ -2329,7 +2431,7 @@ function getProxyUsername () {
 
 // "Getter" for proxy_password
 function getProxyPassword () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
@@ -2341,7 +2443,7 @@ function getProxyPassword () {
 
 // "Getter" for proxy_host
 function getProxyHost () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
@@ -2353,7 +2455,7 @@ function getProxyHost () {
 
 // "Getter" for proxy_port
 function getProxyPort () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
@@ -2365,7 +2467,7 @@ function getProxyPort () {
 
 // "Getter" for SMTP_HOSTNAME
 function getSmtpHostname () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
@@ -2377,7 +2479,7 @@ function getSmtpHostname () {
 
 // "Getter" for SMTP_USER
 function getSmtpUser () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
@@ -2389,7 +2491,7 @@ function getSmtpUser () {
 
 // "Getter" for SMTP_PASSWORD
 function getSmtpPassword () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
@@ -2401,7 +2503,7 @@ function getSmtpPassword () {
 
 // "Getter" for points_word
 function getPointsWord () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('points_word');
@@ -2413,7 +2515,7 @@ function getPointsWord () {
 
 // "Getter" for profile_lock
 function getProfileLock () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
@@ -2425,7 +2527,7 @@ function getProfileLock () {
 
 // "Getter" for url_tlock
 function getUrlTlock () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
@@ -2437,7 +2539,7 @@ function getUrlTlock () {
 
 // "Getter" for title_left
 function getTitleLeft () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('title_left');
@@ -2449,7 +2551,7 @@ function getTitleLeft () {
 
 // "Getter" for title_right
 function getTitleRight () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('title_right');
@@ -2461,7 +2563,7 @@ function getTitleRight () {
 
 // "Getter" for title_middle
 function getTitleMiddle () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = getConfig('title_middle');
@@ -2471,48 +2573,144 @@ function getTitleMiddle () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// Getter for 'check_double_email'
-function getCheckDoubleEmail () {
+// Getter for 'display_home_in_index'
+function getDisplayHomeInIndex () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether 'display_home_in_index' is 'Y'
+function isDisplayHomeInIndexEnabled () {
        // Is the cache entry set?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // No, so determine it
-               $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isConfigEntrySet('display_home_in_index')) && (getDisplayHomeInIndex() == 'Y'));
        } // END - if
 
        // Return cached entry
        return $GLOBALS[__FUNCTION__];
 }
 
-// Checks whether 'check_double_email' is 'Y'
-function isCheckDoubleEmailEnabled () {
+// Getter for 'show_points_unconfirmed'
+function getShowPointsUnconfirmed () {
        // Is the cache entry set?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // No, so determine it
-               $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
+               $GLOBALS[__FUNCTION__] = getConfig('show_points_unconfirmed');
        } // END - if
 
        // Return cached entry
        return $GLOBALS[__FUNCTION__];
 }
 
-// Getter for 'display_home_in_index'
-function getDisplayHomeInIndex () {
+// Checks whether 'show_points_unconfirmed' is 'Y'
+function isShowPointsUnconfirmedEnabled () {
        // Is the cache entry set?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // No, so determine it
-               $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.5.5')) && (isConfigEntrySet('show_points_unconfirmed')) && (getShowPointsUnconfirmed() == 'Y'));
        } // END - if
 
        // Return cached entry
        return $GLOBALS[__FUNCTION__];
 }
 
-// Checks whether 'display_home_in_index' is 'Y'
-function isDisplayHomeInIndexEnabled () {
+// Getter for 'youre_here'
+function getYoureHere () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('youre_here');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether 'show_timings' is 'Y'
+function isYoureHereEnabled () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (isConfigEntrySet('youre_here')) && (getYoureHere() == 'Y'));
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for 'show_timings'
+function getShowTimings () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('show_timings');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether 'show_timings' is 'Y'
+function isShowTimingsEnabled () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (isConfigEntrySet('show_timings')) && (getShowTimings() == 'Y'));
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for 'ap_server_name_since'
+function getApServerNameSince () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('ap_server_name_since');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for 'ap_server_name'
+function getApServerName () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('ap_server_name');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for 'index_delay'
+function getIndexDelay () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('index_delay');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether 'ap_server_name' is 'Y'
+function isApServerNameEnabled () {
        // Is the cache entry set?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // No, so determine it
-               $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
+               $GLOBALS[__FUNCTION__] = (getApServerName() == 'Y');
        } // END - if
 
        // Return cached entry
@@ -2543,12 +2741,96 @@ function getPointsRemoveAccount () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// Getter for 'css_php'
+function getCssPhp () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('css_php');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for 'guest_menu'
+function getGuestMenu () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('guest_menu');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks if guest menu is enabled
+function isGuestMenuEnabled () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = (getGuestMenu() == 'Y');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for 'member_menu'
+function getMemberMenu () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('member_menu');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks if member menu is enabled
+function isMemberMenuEnabled () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = (getMemberMenu() == 'Y');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for 'word_wrap'
+function getWordWrap () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Construct config entry name
+               $configEntry = getMenuModeFromModule() . '_word_wrap_' . getWhat();
+
+               // Is a special config entry found or ext-sql_patches updated?
+               if (isConfigEntrySet($configEntry)) {
+                       // A special config entry has been found, then use it
+                       $GLOBALS[__FUNCTION__] = getConfig($configEntry);
+               } elseif (isExtensionInstalledAndNewer('other', '0.2.9')) {
+                       // No special config entry found, then use it as "fall-back"
+                       $GLOBALS[__FUNCTION__] = getConfig('word_wrap');
+               } else {
+                       // No, use default (15 characters)
+                       $GLOBALS[__FUNCTION__] = 15;
+               }
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Checks whether proxy configuration is used
 function isProxyUsed () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (isValidNumber(getConfig('proxy_port'))));
        } // END - if
 
        // Return cache
@@ -2557,7 +2839,7 @@ function isProxyUsed () {
 
 // Checks whether POST data contains selections
 function ifPostContainsSelections ($element = 'sel') {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$element])) {
                // Determine it
                $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
@@ -2569,7 +2851,7 @@ function ifPostContainsSelections ($element = 'sel') {
 
 // Checks whether verbose_sql is Y and returns true/false if so
 function isVerboseSqlEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
                $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
@@ -2581,7 +2863,7 @@ function isVerboseSqlEnabled () {
 
 // "Getter" for total user points
 function getTotalPoints ($userid) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$userid])) {
                // Init array for filter chain
                $data = array(
@@ -2602,7 +2884,7 @@ function getTotalPoints ($userid) {
 
 // Wrapper to get used points for given userid
 function getUserUsedPoints ($userid) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$userid])) {
                // Determine it
                $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
@@ -2612,24 +2894,12 @@ function getUserUsedPoints ($userid) {
        return $GLOBALS[__FUNCTION__][$userid];
 }
 
-// Wrapper to check if url_blacklist is enabled
-function isUrlBlacklistEnabled () {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
 // Checks whether direct payment is allowed in configuration
 function isDirectPaymentEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('allow_direct_pay')) && (getConfig('allow_direct_pay') == 'Y'));
        } // END - if
 
        // Return cache
@@ -2638,10 +2908,10 @@ function isDirectPaymentEnabled () {
 
 // Checks whether JavaScript-based admin menu is enabled
 function isAdminMenuJavascriptEnabled () {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (isConfigEntrySet('admin_menu_javascript')) && (getAdminMenuJavaScript() == 'Y'));
        } // END - if
 
        // Return cache
@@ -2650,7 +2920,7 @@ function isAdminMenuJavascriptEnabled () {
 
 // Wrapper to check if current task is for extension (not update)
 function isExtensionTask ($content) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
                // Determine it
                $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
@@ -2660,18 +2930,6 @@ function isExtensionTask ($content) {
        return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
 }
 
-// Getter for 'mt_start'
-function getMtStart () {
-       // Is the cache entry set?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // No, so determine it
-               $GLOBALS[__FUNCTION__] = getConfig('mt_start');
-       } // END - if
-
-       // Return cached entry
-       return $GLOBALS[__FUNCTION__];
-}
-
 // Checks whether ALLOW_TESTER_ACCOUNTS is set
 function ifTesterAccountsAllowed () {
        // Is the cache entry set?
@@ -2758,7 +3016,7 @@ function generateWrappedUserEmailLink ($email) {
 // Wrapper to check if user points are locked
 function ifUserPointsLocked ($userid) {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$userid])) {
                // Determine it
                $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
@@ -2773,14 +3031,14 @@ function ifUserPointsLocked ($userid) {
 // This function does always add a new-line character to every line.
 function appendLineToFile ($file, $line) {
        $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
-       fwrite($fp, $line . chr(10));
+       fwrite($fp, $line . PHP_EOL);
        fclose($fp);
 }
 
 // Wrapper for changeDataInFile() but with full path added
-function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
+function changeDataInInclude ($inc, $comment, $prefix, $suffix, $inserted, $seek=0) {
        // Add full path
-       $FQFN = getPath() . $FQFN;
+       $FQFN = getPath() . $inc;
 
        // Call inner function
        return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
@@ -2811,6 +3069,9 @@ function convertCommaToDotInPostData ($postEntry) {
        // Read and convert given entry
        $postValue = convertCommaToDot(postRequestElement($postEntry));
 
+       // Log message
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
+
        // ... and set it again
        setPostRequestElement($postEntry, $postValue);
 }
@@ -2854,33 +3115,43 @@ function parseFloat ($floatString){
  * Searches a multi-dimensional array (as used in many places) for given
  * key/value pair as taken from user comments from PHP documentation website.
  *
- * @param      $array          An array with one or more dimensions
- * @param      $key            Key to look for
- * @param      $valur          Value to look for
- * @return     $results        Resulted array or empty array if $array is no array
+ * @param      $array                  An array with one or more dimensions
+ * @param      $key                    Key to look for
+ * @param      $value                  Value to look for
+ * @param      $parentIndex    Parent index (ONLY INTERNAL USE!)
+ * @return     $results                Resulted array or empty array if $array is no array
  * @author     sunelbe<at>gmail<dot>com
  * @link       http://de.php.net/manual/en/function.array-search.php#110120
  */
-function search_array ($array, $key, $value) {
+function search_array ($array, $key, $value, $parentIndex = NULL) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
        // Init array result
        $results = array();
 
        // Is $array really an array?
        if (is_array($array)) {
-               // Does key and value match?
-               if (isset($array[$key]) && $array[$key] == $value) {
-                       // Then add it as result
-                       $results[] = $array;
-               } // END - if
-
                // Search for whole array
-               foreach ($array as $subArray) {
-                       // Search recursive and merge again
-                       $results = merge_array($results, search_array($subArray, $key, $value));
+               foreach ($array as $idx => $dummy) {
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex);
+                       //* DEBUG: */ print 'idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',key=' . $key . ',value=' . $value . ',array=<pre>'.print_r($array, TRUE).'</pre>';
+                       // Is dummy an array?
+                       if ((is_array($dummy)) && ((is_null($parentIndex)) || ($parentIndex === $value))) {
+                               // Then search again
+                               $subResult = search_array($dummy, $key, $value, $idx);
+                               //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
+
+                               // And merge both
+                               $results = merge_array($results, $subResult, TRUE);
+                       } elseif (($key == $idx) && (isset($array[$key])) && ($array[$key] === $value)) {
+                               // Is found, so add it
+                               $results[$parentIndex] = $array;
+                               //* DEBUG: */ print 'ARRAY: key=' . $key . ',idx=' . $idx . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',array=<pre>' . print_r($array, TRUE).'</pre>';
+                       }
                } // END - foreach
        } // END - if
 
        // Return resulting array
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
        return $results;
 }
 
@@ -2893,7 +3164,7 @@ function generateYesNoOptions ($defaultValue = '') {
 // "Getter" for total available receivers
 function getTotalReceivers ($mode = 'normal') {
        // Get num rows
-       $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
+       $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
 
        // Return value
        return $numRows;
@@ -2901,10 +3172,10 @@ function getTotalReceivers ($mode = 'normal') {
 
 // Wrapper "getter" to get total unconfirmed mails for given userid
 function getTotalUnconfirmedMails ($userid) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$userid])) {
                // Determine it
-               $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
+               $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
        } // END - if
 
        // Return cache
@@ -3011,7 +3282,7 @@ function isFullPage () {
 // Checks whether frameset_mode is set to true
 function isFramesetModeEnabled () {
        // Check it
-       return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === true));
+       return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
 }
 
 // Function to determine correct 'what' value
@@ -3052,16 +3323,16 @@ function determineWhat ($module = NULL) {
 }
 
 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
-function prependZeros ($mStretch, $length = 2) {
+function prependZeros ($str, $length = 2) {
        // Return prepended string
-       return sprintf('%0' . (int) $length . 's', $mStretch);
+       return sprintf('%0' . (int) $length . 's', $str);
 }
 
 // Wraps convertSelectionsToEpocheTime()
 function convertSelectionsToEpocheTimeInPostData ($id) {
        // Init variables
        $content = array();
-       $skip = false;
+       $skip = FALSE;
 
        // Get all POST data
        $postData = postRequestArray();
@@ -3076,20 +3347,20 @@ function convertSelectionsToEpocheTimeInPostData ($id) {
 // Wraps checking if given points account type matches with given in POST data
 function ifPointsAccountTypeMatchesPost ($type) {
        // Check condition
-       exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), true).'</pre>');
+       exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
 }
 
 // Gets given user's total referral
 function getUsersTotalReferrals ($userid, $level = NULL) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
                // Is the level NULL?
                if (is_null($level)) {
                        // Get total amount (all levels)
-                       $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true);
+                       $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
                } else {
                        // Get it from user refs
-                       $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true, ' AND `level`=' . bigintval($level));
+                       $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
                }
        } // END - if
 
@@ -3100,7 +3371,7 @@ function getUsersTotalReferrals ($userid, $level = NULL) {
 // Gets given user's total referral
 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
                // Default is all refs
                $add = '';
@@ -3108,34 +3379,34 @@ function getUsersTotalLockedReferrals ($userid, $level = NULL) {
                // Is the not level NULL?
                if (!is_null($level)) {
                        // Then add referral level
-                       $add = ' AND r.`level`=' . bigintval($level);
+                       $add = ' AND `r`.`level`=' . bigintval($level);
                } // END - if
 
                // Check for all referrals
-               $result = SQL_QUERY_ESC("SELECT
-       COUNT(d.`userid`) AS `cnt`
+               $result = sqlQueryEscaped("SELECT
+       COUNT(`d`.`userid`) AS `cnt`
 FROM
-       `{?_MYSQL_PREFIX?}_user_data` AS d
+       `{?_MYSQL_PREFIX?}_user_data` AS `d`
 INNER JOIN
-       `{?_MYSQL_PREFIX?}_user_refs` AS r
+       `{?_MYSQL_PREFIX?}_user_refs` AS `r`
 ON
-       d.`userid`=r.`refid`
+       `d`.`userid`=`r`.`refid`
 WHERE
-       d.`status` != 'CONFIRMED' AND
-       r.`userid`=%s
+       `d`.`status` != 'CONFIRMED' AND
+       `r`.`userid`=%s
        " . $add . "
 ORDER BY
-       d.`userid` ASC
+       `d`.`userid` ASC
 LIMIT 1",
                        array(
                                $userid
                        ), __FUNCTION__, __LINE__);
 
                // Load count
-               list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
+               list($GLOBALS[__FUNCTION__][$userid][$level]) = sqlFetchRow($result);
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
        } // END - if
 
        // Return it
@@ -3156,7 +3427,7 @@ function convertDollarDataToGetElement ($data) {
 }
 
 // Wrapper function for SQL layer to speed-up things
-function SQL_DEBUG_ENABLED () {
+function isSqlDebugEnabled () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
@@ -3167,5 +3438,155 @@ function SQL_DEBUG_ENABLED () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// Wrapper function to wrap call of wordwrap()
+function wrapWords ($text) {
+       // Wrap words
+       $wrapped = wordwrap($test, getWordWrap());
+
+       // Return it
+       return $wrapped;
+}
+
+// Encodes given data into a JSON object
+function encodeJson ($data) {
+       // Encode it
+       return json_encode($data, JSON_FORCE_OBJECT);
+}
+
+// Get all extension files
+function loadAllExtensionsByTemplate () {
+       // Get all
+       $extensions = getArrayFromDirectory(
+               'templates/' . getLanguage() . '/html/ext/',
+               'ext_',
+               false,
+               false,
+               array(),
+               '.tpl',
+               '@(\.|\.\.)$@',
+               false
+       );
+
+       // Return them
+       return $extensions;
+}
+
+// Wrapper function to allow full float values as supported by current database layout
+function translateFullComma ($dotted) {
+       // Call inner function
+       return translateComma($dotted, TRUE, 5);
+}
+
+// Wrapper to check if the first element to be shifted is set to given value
+function shift_array (&$array, $value, $key = '0') {
+       // Is the element set and value matches?
+       assert(is_array($array));
+       assert(isset($array[$key]));
+       assert($array[$key] === $value);
+
+       // Shift it
+       array_shift($array);
+}
+
+// Wrapper for str_pad() with left padding zeros
+function padLeftZero ($str, $amount = 2) {
+       // Is str_pad() there?
+       if (!function_exists('str_pad')) {
+               // Use prependZeros()
+               return prependZeros($str, $amount);
+       } else {
+               // Pad it
+               return str_pad($str, $amount, '0', STR_PAD_LEFT);
+       }
+}
+
+// Calculates percentage
+function calculatePercentageRate ($current, $total) {
+       // Default is zero
+       $rate = '0.0';
+
+       // Is sent larger zero? (Prevents division-by-zero)
+       if ($total > 0) {
+               // Calculate it (it should be "translated" alter on)
+               $rate = ($current / $total * 100);
+       } // END - if
+
+       // The should be a .0 at the end?
+       if (strpos($rate, '.') === FALSE) {
+               // No, then add it
+               $rate .= '.0';
+       } // END - if
+
+       // Return it
+       return $rate;
+}
+
+// Checks whether an array is filled with entries
+function isFilledArray ($array) {
+       // Determine it
+       return ((is_array($array)) && (count($array) > 0));
+}
+
+// Checks whether this script runs on a developer system (called with localhost/127.0.0.1 SERVER_NAME)
+function isDeveloperSystem () {
+       // Determine it
+       return in_array(detectServerName(), array('localhost', '127.0.0.1'));
+}
+
+// Checks whether given subject line has '_ref' suffix
+function ifSubjectHasReferralSuffix ($subject) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$subject])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__][$subject] = (substr($subject, -4, 4) == '_ref');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$subject];
+}
+
+// Converts an API response to an associative array
+function convertApiResponseToArray ($responseString, $keyDelimiter, $valueDelimiter) {
+       // Explode for key delimiter
+       $keys = explode($keyDelimiter, $responseString);
+
+       // Init returned array and "walk" through all entries
+       $returned = array();
+       foreach ($keys as $keyValue) {
+               // Explode it
+               $parts = explode($valueDelimiter, $keyValue);
+
+               // Count must be 2
+               assert(count($parts) == 2);
+
+               // Then add both: 0=key, 1=value
+               $returned[sqlEscapeString($parts[0])] = sqlEscapeString($parts[1]);
+       } // END - if
+
+       // Return finished array
+       return $returned;
+}
+
+// Getter for full (generic) hash file name
+function getGenericHashFileName () {
+       // Return result
+       return sprintf('%s%s.%s%s', getPath(), getCachePath(), getFileHash(), getCacheExtension());
+}
+
+// "Compiles" the given value and sets it in given key
+function setSessionCompiled ($key, $value) {
+       // Debug message
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key[]=' . gettype($key) . ',value[]=' . gettype($value));
+
+       // Is the value not an array?
+       if (!is_array($value)) {
+               // "Compile" the value
+               $value = doFinalCompilation(compileRawCode($value));
+       } // END - if
+
+       // And set it
+       return setSession($key, $value);
+}
+
 // [EOF]
 ?>