]> git.mxchange.org Git - mailer.git/blobdiff - inc/wrapper-functions.php
Use version_compare(), unregister only registered filters:
[mailer.git] / inc / wrapper-functions.php
index fdae0479db245003a983c67b64ba19d45e376302..3cb81135295da53ba448a3553550f630b3826509 100644 (file)
@@ -46,41 +46,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 {
@@ -89,10 +88,11 @@ function writeToFile ($FQFN, $content, $aquireLock = false) {
                }
        } else {
                // Write it with fopen
-               $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
+               $fp = fopen($FQFN, 'w')
+                       or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
 
                // Aquire a lock?
-               if ($aquireLock === true) {
+               if ($aquireLock === TRUE) {
                        // Aquire a lock.
                        flock($fp, LOCK_EX);
                } // END - if
@@ -105,16 +105,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 +120,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,7 +151,7 @@ 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
@@ -170,8 +164,20 @@ function merge_array ($array1, $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
@@ -202,12 +208,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 +223,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 +238,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 +253,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 +268,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
@@ -380,13 +386,13 @@ 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 reset mode is active
 function isResetModeEnabled () {
        // Now simply check it
-       return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
+       return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === TRUE));
 }
 
 // Checks whether the debug mode is enabled
@@ -454,7 +460,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,11 +480,11 @@ 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;
+       $status = TRUE;
 
        // If there are chmod rights set, apply them
        if (!empty($chmod)) {
@@ -508,7 +514,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,7 +522,7 @@ 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']
@@ -539,7 +545,7 @@ function countPostSelection ($element = 'sel') {
 
 // 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
@@ -547,7 +553,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
@@ -555,7 +561,7 @@ function isNicknameUsed ($userid) {
 }
 
 // Getter for 'what' value
-function getWhat ($strict = true) {
+function getWhat ($strict = TRUE) {
        // Default is null
        $what = NULL;
 
@@ -590,7 +596,7 @@ function isWhatSet ($strict =  false) {
        $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
@@ -600,7 +606,7 @@ function isWhatSet ($strict =  false) {
 }
 
 // Getter for 'action' value
-function getAction ($strict = true) {
+function getAction ($strict = TRUE) {
        // Default is null
        $action = NULL;
 
@@ -625,7 +631,7 @@ function isActionSet ($strict =  false) {
        $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
@@ -635,7 +641,7 @@ function isActionSet ($strict =  false) {
 }
 
 // Getter for 'module' value
-function getModule ($strict = true) {
+function getModule ($strict = TRUE) {
        // Default is null
        $module = NULL;
 
@@ -661,13 +667,13 @@ function isModuleSet ($strict =  false) {
        $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
@@ -700,7 +706,7 @@ function isOutputModeSet ($strict =  false) {
        $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
@@ -710,7 +716,7 @@ function isOutputModeSet ($strict =  false) {
 }
 
 // Enables block-mode
-function enableBlockMode ($enabled = true) {
+function enableBlockMode ($enabled = TRUE) {
        $GLOBALS['__block_mode'] = $enabled;
 }
 
@@ -750,35 +756,35 @@ function redirectToDereferedUrl ($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)) && (isExtensionOlder($ext_name, $ext_ver)));
        } 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];
 }
 
 // Set username
@@ -982,7 +988,7 @@ function isUserDataValid () {
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
 
                // Abort here
-               return false;
+               return FALSE;
        } // END - if
 
        // Is it cached?
@@ -1097,8 +1103,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
@@ -1215,13 +1221,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__];
 }
 
@@ -1231,13 +1238,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__];
 }
 
@@ -1247,13 +1255,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__];
 }
 
@@ -1263,13 +1272,14 @@ 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__];
 }
 
@@ -1292,7 +1302,7 @@ function isValidUserId ($userid) {
 // 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('$', '$', $str);
@@ -2817,6 +2827,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);
 }
@@ -2860,33 +2873,41 @@ 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);
+                       // Is dummy an array?
+                       if (is_array($dummy)) {
+                               // 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 ((isset($array[$key])) && ($array[$key] == $value)) {
+                               // Is found, so add it
+                               $results[$parentIndex] = $array;
+                       }
                } // END - foreach
        } // END - if
 
        // Return resulting array
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
        return $results;
 }
 
@@ -2899,7 +2920,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;
@@ -2910,7 +2931,7 @@ function getTotalUnconfirmedMails ($userid) {
        // 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
@@ -3017,7 +3038,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
@@ -3067,7 +3088,7 @@ function prependZeros ($mStretch, $length = 2) {
 function convertSelectionsToEpocheTimeInPostData ($id) {
        // Init variables
        $content = array();
-       $skip = false;
+       $skip = FALSE;
 
        // Get all POST data
        $postData = postRequestArray();
@@ -3082,7 +3103,7 @@ 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
@@ -3092,10 +3113,10 @@ function getUsersTotalReferrals ($userid, $level = NULL) {
                // 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