X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fwrapper-functions.php;h=3dbbfa8dc3e3b8ae5c0f11f6777ce0e2ccf867b7;hb=ca11996eb52fa0a1ec45d6ab10f5331c4a54a116;hp=1d49f0ac9b04d044e79f9205bb9de654cd3a6815;hpb=2e33dfdf1973c145784a172982b2c15ffa923d2f;p=mailer.git diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 1d49f0ac9b..3dbbfa8dc3 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -14,12 +14,10 @@ * $Date:: $ * * $Tag:: 0.2.1-FINAL $ * * $Author:: $ * - * Needs to be in all Files and every File needs "svn propset * - * svn:keywords Date Revision" (autoprobset!) at least!!!!!! * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009, 2010 by Mailer Developer Team * - * For more information visit: http://www.mxchange.org * + * Copyright (c) 2009 - 2012 by Mailer Developer Team * + * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -39,7 +37,7 @@ // Some security stuff... if (!defined('__SECURITY')) { - die(); + exit(); } // END - if // Read a given file @@ -47,7 +45,7 @@ function readFromFile ($FQFN) { // Sanity-check if file is there (should be there, but just to make it sure) if (!isFileReadable($FQFN)) { // This should not happen - debug_report_bug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!'); + reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!'); } elseif (!isset($GLOBALS['file_content'][$FQFN])) { // Load the file if (function_exists('file_get_contents')) { @@ -91,7 +89,7 @@ function writeToFile ($FQFN, $content, $aquireLock = false) { } } else { // Write it with fopen - $fp = fopen($FQFN, 'w') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!'); + $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!'); // Do we need to aquire a lock? if ($aquireLock === true) { @@ -121,23 +119,30 @@ function writeToFile ($FQFN, $content, $aquireLock = false) { // Clears the output buffer. This function does *NOT* backup sent content. function clearOutputBuffer () { + // Make sure this function is not called twice (no double-cleaning!) + 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())) { // Failed! - debug_report_bug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.'); + reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.'); } // END - if + + // Mark this function as called + $GLOBALS[__FUNCTION__] = true; } // Encode strings -// @TODO Implement $compress -function encodeString ($str, $compress = true) { +function encodeString ($str) { $str = urlencode(base64_encode(compileUriCode($str))); return $str; } // Decode strings encoded with encodeString() -// @TODO Implement $decompress -function decodeString ($str, $decompress = true) { +function decodeString ($str) { $str = compileUriCode(base64_decode(urldecode(compileUriCode($str)))); return $str; } @@ -156,16 +161,16 @@ function merge_array ($array1, $array2) { // Are both an array? if ((!is_array($array1)) && (!is_array($array2))) { // Both are not arrays - debug_report_bug(__FUNCTION__, __LINE__, 'No arrays provided!'); + reportBug(__FUNCTION__, __LINE__, 'No arrays provided!'); } elseif (!is_array($array1)) { // Left one is not an array - debug_report_bug(__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 - debug_report_bug(__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 all together + // Merge both together return array_merge($array1, $array2); } @@ -174,14 +179,14 @@ function isFileReadable ($FQFN) { // Do we have cache? if (!isset($GLOBALS['file_readable'][$FQFN])) { // Check all... - $GLOBALS['file_readable'][$FQFN] = ((file_exists($FQFN)) && (is_file($FQFN)) && (is_readable($FQFN))); + $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN))); } // END - if // Return result return $GLOBALS['file_readable'][$FQFN]; } -// Checks wether the given FQFN is a directory and not ., .. or .svn +// Checks whether the given FQFN is a directory and not ., .. or .svn function isDirectory ($FQFN) { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__][$FQFN])) { @@ -196,10 +201,25 @@ function isDirectory ($FQFN) { return $GLOBALS[__FUNCTION__][$FQFN]; } +// "Getter" for the real remote IP number +function detectRealIpAddress () { + // Get remote ip from environment + $remoteAddr = determineRealRemoteAddress(); + + // Is removeip installed? + if (isExtensionActive('removeip')) { + // Then anonymize it + $remoteAddr = getAnonymousRemoteAddress($remoteAddr); + } // END - if + + // Return it + return $remoteAddr; +} + // "Getter" for remote IP number function detectRemoteAddr () { // Get remote ip from environment - $remoteAddr = determineRealRemoteAddress(); + $remoteAddr = determineRealRemoteAddress(true); // Is removeip installed? if (isExtensionActive('removeip')) { @@ -273,23 +293,45 @@ function detectServerName () { return (getenv('SERVER_NAME')); } -// Check wether we are installing -function isInstalling () { - // Determine wether we are installing +// Removes any existing www. from SERVER_NAME. This is very silly but enough +// for our purpose here. +function detectDomainName () { + // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { + // Get server name + $domainName = detectServerName(); + + // Is there any www. ? + if (substr($domainName, 0, 4) == 'www.') { + // Remove it + $domainName = substr($domainName, 4); + } // END - if + + // Set cache + $GLOBALS[__FUNCTION__] = $domainName; + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Check whether we are installing +function isInstalling () { + // Determine whether we are installing + if (!isset($GLOBALS['__mailer_installing'])) { // Check URL (css.php/js.php need this) - $GLOBALS[__FUNCTION__] = isGetRequestParameterSet('installing'); + $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing'); } // END - if // Return result - return $GLOBALS[__FUNCTION__]; + return $GLOBALS['__mailer_installing']; } -// Check wether this script is installed +// Check whether this script is installed function isInstalled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { - // Determine wether this script is installed + // Determine whether this script is installed $GLOBALS[__FUNCTION__] = ( ( // First is config @@ -323,7 +365,7 @@ function isInstalled () { return $GLOBALS[__FUNCTION__]; } -// Check wether an admin is registered +// Check whether an admin is registered function isAdminRegistered () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { @@ -335,13 +377,19 @@ function isAdminRegistered () { return $GLOBALS[__FUNCTION__]; } -// Checks wether the reset mode is active +// Checks whether the hourly reset mode is active +function isHourlyResetEnabled () { + // Now simply check it + 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)); } -// Checks wether the debug mode is enabled +// Checks whether the debug mode is enabled function isDebugModeEnabled () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { @@ -353,7 +401,19 @@ function isDebugModeEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether SQL debugging is enabled +// Checks whether the debug reset is enabled +function isDebugResetEnabled () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Simply check it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y')); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether SQL debugging is enabled function isSqlDebuggingEnabled () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { @@ -365,7 +425,7 @@ function isSqlDebuggingEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether we shall debug regular expressions +// Checks whether we shall debug regular expressions function isDebugRegularExpressionEnabled () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { @@ -377,9 +437,16 @@ function isDebugRegularExpressionEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether the cache instance is valid +// Checks whether the cache instance is valid function isCacheInstanceValid () { - return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance']))); + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance']))); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; } // Copies a file from source to destination and verifies if that goes fine. @@ -392,19 +459,19 @@ function copyFileVerified ($source, $dest, $chmod = '') { // Is the source file there? if (!isFileReadable($source)) { // Then abort here - debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.'); + reportBug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.'); } // END - if // Is the target directory there? if (!isDirectory(dirname($dest))) { // Then abort here - debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.'); + reportBug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.'); } // END - if // Now try to copy it if (!copy($source, $dest)) { // Something went wrong - debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.'); + reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.'); } else { // Reset cache $GLOBALS['file_readable'][$dest] = true; @@ -423,40 +490,13 @@ function copyFileVerified ($source, $dest, $chmod = '') { return $status; } -// Wrapper function for header() -// Send a header but checks before if we can do so -function sendHeader ($header) { - // Send the header - //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header); - $GLOBALS['header'][] = trim($header); -} - -// Flushes all headers -function flushHeaders () { - // Is the header already sent? - if (headers_sent()) { - // Then abort here - debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!'); - } // END - if - - // Flush all headers if found - if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) { - foreach ($GLOBALS['header'] as $header) { - header($header); - } // END - foreach - } // END - if - - // Mark them as flushed - $GLOBALS['header'] = array(); -} - // Wrapper function for chmod() // @TODO Do some more sanity check here function changeMode ($FQFN, $mode) { // Is the file/directory there? if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) { // Neither, so abort here - debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.'); + reportBug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.'); } // END - if // Try to set them @@ -482,26 +522,26 @@ function removeFile ($FQFN) { // Wrapper for $_POST['sel'] function countPostSelection ($element = 'sel') { // Is it set? - if (isPostRequestParameterSet($element)) { + if (isPostRequestElementSet($element)) { // Return counted elements - return countSelection(postRequestParameter($element)); + return countSelection(postRequestElement($element)); } else { // Return zero if not found - return 0; + return '0'; } } -// Checks wether the config-local.php is loaded +// Checks whether the config-local.php is loaded function isConfigLocalLoaded () { return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true)); } -// Checks wether a nickname or userid was entered and caches the result +// Checks whether a nickname or userid was entered and caches the result function isNicknameUsed ($userid) { // Is the cache there if (!isset($GLOBALS[__FUNCTION__][$userid])) { // Determine it - $GLOBALS[__FUNCTION__][$userid] = (('' . round($userid) . '') != $userid); + $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, true, false) . '') != $userid) && ($userid != 'NULL')); } // END - if // Return the result @@ -509,14 +549,14 @@ function isNicknameUsed ($userid) { } // Getter for 'what' value -function getWhat () { +function getWhat ($strict = true) { // Default is null - $what = null; + $what = NULL; // Is the value set? - if (isWhatSet(true)) { + if (isWhatSet($strict)) { // Then use it - $what = $GLOBALS['what']; + $what = $GLOBALS['__what']; } // END - if // Return it @@ -525,7 +565,8 @@ function getWhat () { // Setter for 'what' value function setWhat ($newWhat) { - $GLOBALS['what'] = SQL_ESCAPE($newWhat); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat); + $GLOBALS['__what'] = $newWhat; } // Setter for 'what' from configuration @@ -537,10 +578,10 @@ function setWhatFromConfig ($configEntry) { setWhat($what); } -// Checks wether what is set and optionally aborts on miss +// Checks whether what is set and optionally aborts on miss function isWhatSet ($strict = false) { // Check for it - $isset = isset($GLOBALS['what']); + $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what']))); // Should we abort here? if (($strict === true) && ($isset === false)) { @@ -555,12 +596,12 @@ function isWhatSet ($strict = false) { // Getter for 'action' value function getAction ($strict = true) { // Default is null - $action = null; + $action = NULL; // Is the value set? if (isActionSet(($strict) && (isHtmlOutputMode()))) { // Then use it - $action = $GLOBALS['action']; + $action = $GLOBALS['__action']; } // END - if // Return it @@ -569,18 +610,18 @@ function getAction ($strict = true) { // Setter for 'action' value function setAction ($newAction) { - $GLOBALS['action'] = SQL_ESCAPE($newAction); + $GLOBALS['__action'] = $newAction; } -// Checks wether action is set and optionally aborts on miss +// Checks whether action is set and optionally aborts on miss function isActionSet ($strict = false) { // Check for it - $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action']))); + $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action']))); // Should we abort here? if (($strict === true) && ($isset === false)) { // Output backtrace - debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.'); + reportBug(__FUNCTION__, __LINE__, 'action is empty.'); } // END - if // Return it @@ -590,12 +631,12 @@ function isActionSet ($strict = false) { // Getter for 'module' value function getModule ($strict = true) { // Default is null - $module = null; + $module = NULL; // Is the value set? if (isModuleSet($strict)) { // Then use it - $module = $GLOBALS['module']; + $module = $GLOBALS['__module']; } // END - if // Return it @@ -605,53 +646,57 @@ function getModule ($strict = true) { // Setter for 'module' value function setModule ($newModule) { // Secure it and make all modules lower-case - $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule)); + $GLOBALS['__module'] = strtolower($newModule); } -// Checks wether module is set and optionally aborts on miss +// Checks whether module is set and optionally aborts on miss function isModuleSet ($strict = false) { // Check for it - $isset = (!empty($GLOBALS['module'])); + $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module']))); // Should we abort here? if (($strict === true) && ($isset === false)) { // Output backtrace - debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.'); + 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 function getScriptOutputMode () { - // Default is null - $output_mode = null; + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Is the output mode set? + if (!isOutputModeSet()) { + // No, then abort here + reportBug(__FUNCTION__, __LINE__, 'Output mode not set.'); + } // END - if - // Is the value set? - if (isOutputModeSet(true)) { - // Then use it - $output_mode = $GLOBALS['output_mode']; + // Set it in cache + $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode']; } // END - if - // Return it - return $output_mode; + // Return cache + return $GLOBALS[__FUNCTION__]; } // Setter for 'output_mode' value function setOutputMode ($newOutputMode) { - $GLOBALS['output_mode'] = (int) $newOutputMode; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode); + $GLOBALS['__output_mode'] = (int) $newOutputMode; } -// Checks wether output_mode is set and optionally aborts on miss +// Checks whether output_mode is set and optionally aborts on miss function isOutputModeSet ($strict = false) { // Check for it - $isset = (isset($GLOBALS['output_mode'])); + $isset = (isset($GLOBALS['__output_mode'])); // Should we abort here? if (($strict === true) && ($isset === false)) { // Output backtrace - debug_report_bug(__FUNCTION__, __LINE__, 'Output_mode is empty.'); + reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.'); } // END - if // Return it @@ -660,28 +705,19 @@ function isOutputModeSet ($strict = false) { // Enables block-mode function enableBlockMode ($enabled = true) { - $GLOBALS['block_mode'] = $enabled; + $GLOBALS['__block_mode'] = $enabled; } -// Checks wether block-mode is enabled +// Checks whether block-mode is enabled function isBlockModeEnabled () { // Abort if not set - if (!isset($GLOBALS[__FUNCTION__])) { + if (!isset($GLOBALS['__block_mode'])) { // Needs to be fixed - debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.'); + reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.'); } // END - if // Return it - return $GLOBALS[__FUNCTION__]; -} - -// Wrapper function for addPointsThroughReferalSystem() -function addPointsDirectly ($subject, $userid, $points) { - // Reset level here - unset($GLOBALS['ref_level']); - - // Call more complicated method (due to more parameters) - return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'direct'); + return $GLOBALS['__block_mode']; } // Wrapper for redirectToUrl but URL comes from a configuration entry @@ -693,7 +729,7 @@ function redirectToConfiguredUrl ($configEntry) { // Wrapper function to redirect from member-only modules to index function redirectToIndexMemberOnlyModule () { // Do the redirect here - redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule()); + redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule()); } // Wrapper function to redirect to current URL @@ -702,9 +738,9 @@ function redirectToRequestUri () { } // Wrapper function to redirect to de-refered URL -function redirectToDereferedUrl ($URL) { +function redirectToDereferedUrl ($url) { // Redirect to to - redirectToUrl(generateDerefererUrl($URL)); + redirectToUrl(generateDerefererUrl($url)); } // Wrapper function for checking if extension is installed and newer or same version @@ -719,7 +755,7 @@ function isExtensionInstalledAndNewer ($ext_name, $version) { } // Return it - //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'=>'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version])); + //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version])); return $GLOBALS[__FUNCTION__][$ext_name][$version]; } @@ -735,7 +771,7 @@ function isExtensionInstalledAndOlder ($ext_name, $version) { } // Return it - //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'<'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version])); + //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version])); return $GLOBALS[__FUNCTION__][$ext_name][$version]; } @@ -768,12 +804,12 @@ function isInstallationPhase () { return $GLOBALS[__FUNCTION__]; } -// Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!) +// Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!) function isDemoModeActive () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { // Simply check it - $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getAdminLogin(getSession('admin_id')) == 'demo')); + $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo')); } // END - if // Return it @@ -785,12 +821,12 @@ function getPhpCaching () { return $GLOBALS['php_caching']; } -// Checks wether the admin hash is set +// Checks whether the admin hash is set function isAdminHashSet ($adminId) { // Is the array there? if (!isset($GLOBALS['cache_array']['admin'])) { // Missing array should be reported - debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.'); + reportBug(__FUNCTION__, __LINE__, 'Cache not set.'); } // END - if // Check for admin hash @@ -802,15 +838,79 @@ function setAdminHash ($adminId, $hash) { $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash; } +// Getter for current admin login +function getCurrentAdminLogin () { + // Log debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!'); + + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId()); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + +// Setter for admin id (and current) +function setAdminId ($adminId) { + // Log debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId); + + // Set session + $status = setSession('admin_id', bigintval($adminId)); + + // Set current id + setCurrentAdminId($adminId); + + // Return status + return $status; +} + +// Setter for admin_last +function setAdminLast ($adminLast) { + // Log debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast); + + // Set session + $status = setSession('admin_last', $adminLast); + + // Return status + return $status; +} + +// Setter for admin_md5 +function setAdminMd5 ($adminMd5) { + // Log debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5); + + // Set session + $status = setSession('admin_md5', $adminMd5); + + // Return status + return $status; +} + +// Getter for admin_md5 +function getAdminMd5 () { + // Log debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!'); + + // Get session + return getSession('admin_md5'); +} + // Init user data array function initUserData () { // User id should not be zero if (!isValidUserId(getCurrentUserId())) { // Should be always valid - debug_report_bug(__FUNCTION__, __LINE__, 'User id is zero.'); + reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); } // END - if // Init the user + unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]); $GLOBALS['user_data'][getCurrentUserId()] = array(); } @@ -819,11 +919,31 @@ function getUserData ($column) { // User id should not be zero if (!isValidUserId(getCurrentUserId())) { // Should be always valid - debug_report_bug(__FUNCTION__, __LINE__, 'User id is zero.'); + reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); + } // END - if + + // Default is empty + $data = NULL; + + if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) { + // Return the value + $data = $GLOBALS['user_data'][getCurrentUserId()][$column]; + } // END - if + + // Return it + return $data; +} + +// Checks whether given user data is set to 'Y' +function isUserDataEnabled ($column) { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) { + // Determine it + $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y'); } // END - if - // Return the value - return $GLOBALS['user_data'][getCurrentUserId()][$column]; + // Return cache + return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column]; } // Geter for whole user data array @@ -834,7 +954,7 @@ function getUserDataArray () { // Is the current userid valid? if (!isValidUserId($userid)) { // Should be always valid - debug_report_bug(__FUNCTION__, __LINE__, 'User id is invalid.'); + reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid); } // END - if // Get the whole array if found @@ -851,7 +971,9 @@ function getUserDataArray () { // in, but you should use isMember() if you want to find that out. function isUserDataValid () { // User id should not be zero so abort here - if (!isCurrentUserIdSet()) return false; + if (!isCurrentUserIdSet()) { + return false; + } // END - if // Is it cached? if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) { @@ -870,26 +992,46 @@ function setCurrentUserId ($userid) { // Unset it to re-determine the actual state unset($GLOBALS['is_userdata_valid'][$userid]); + + // Is the cache from below functions different? + if ((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) { + // Then unset both + unset($GLOBALS['getCurrentUserId']); + unset($GLOBALS['isCurrentUserIdSet']); + } // END - if } // Getter for current userid function getCurrentUserId () { - // Userid must be set before it can be used - if (!isCurrentUserIdSet()) { - // Not set - debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.'); + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Userid must be set before it can be used + if (!isCurrentUserIdSet()) { + // Not set + reportBug(__FUNCTION__, __LINE__, 'User id is not set.'); + } // END - if + + // Set userid in cache + $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid']; } // END - if - // Return the userid - return $GLOBALS['current_userid']; + // Return cache + return $GLOBALS[__FUNCTION__]; } // Checks if current userid is set function isCurrentUserIdSet () { - return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid']))); + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid']))); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; } -// Checks wether we are debugging template cache +// Checks whether we are debugging template cache function isDebuggingTemplateCache () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { @@ -903,10 +1045,11 @@ function isDebuggingTemplateCache () { // Wrapper for fetchUserData() and getUserData() calls function getFetchedUserData ($keyColumn, $userid, $valueColumn) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!'); // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) { - // Default is 'guest' - $data = '{--USERNAME_GUEST--}'; + // Default is NULL + $data = NULL; // Can we fetch the user data? if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) { @@ -919,6 +1062,7 @@ function getFetchedUserData ($keyColumn, $userid, $valueColumn) { } // END - if // Return it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!'); return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn]; } @@ -940,6 +1084,12 @@ function ifFatalErrorsDetected () { return (getTotalFatalErrors() > 0); } +// Checks whether a HTTP status has been set +function isHttpStatusSet () { + // Is it set and not empty? + return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status']))); +} + // Setter for HTTP status function setHttpStatus ($status) { $GLOBALS['http_status'] = (string) $status; @@ -947,6 +1097,13 @@ function setHttpStatus ($status) { // Getter for HTTP status function getHttpStatus () { + // Is the status set? + if (!isHttpStatusSet()) { + // Abort here + reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!'); + } // END - if + + // Return it return $GLOBALS['http_status']; } @@ -965,6 +1122,18 @@ function getHttpStatus () { * @access private */ function sendRawRedirect ($url) { + // Clear output buffer + clearOutputBuffer(); + + // Clear own output buffer + $GLOBALS['__output'] = ''; + + // To make redirects working (no content type), output mode must be raw + setOutputMode(-1); + + // Send helping header + setHttpStatus('302 Found'); + // always close the session session_write_close(); @@ -973,18 +1142,18 @@ function sendRawRedirect ($url) { // check if running on IIS < 6 with CGI-PHP if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) && - (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) && + (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) && (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) && ($matches[1] < 6)) { // Send the IIS header - sendHeader('Refresh: 0;url=' . $url); + addHttpHeader('Refresh: 0;url=' . $url); } else { // Send generic header - sendHeader('Location: ' . $url); + addHttpHeader('Location: ' . $url); } // Shutdown here - shutdown(); + doShutdown(); } // Determines the country of the given user id @@ -1016,7 +1185,11 @@ function getTotalConfirmedUser () { // Is it cached? if (!isset($GLOBALS[__FUNCTION__])) { // Then do it - $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true); + if (isExtensionActive('user')) { + $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' ')); + } else { + $GLOBALS[__FUNCTION__] = 0; + } } // END - if // Return cached value @@ -1028,7 +1201,11 @@ function getTotalUnconfirmedUser () { // Is it cached? if (!isset($GLOBALS[__FUNCTION__])) { // Then do it - $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true); + if (isExtensionActive('user')) { + $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' ')); + } else { + $GLOBALS[__FUNCTION__] = 0; + } } // END - if // Return cached value @@ -1040,7 +1217,27 @@ function getTotalLockedUser () { // Is it cached? if (!isset($GLOBALS[__FUNCTION__])) { // Then do it - $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true); + if (isExtensionActive('user')) { + $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' ')); + } else { + $GLOBALS[__FUNCTION__] = 0; + } + } // END - if + + // Return cached value + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for total locked user accounts +function getTotalRandomRefidUser () { + // Is it cached? + 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', ' '), '>='); + } else { + $GLOBALS[__FUNCTION__] = 0; + } } // END - if // Return cached value @@ -1049,6 +1246,15 @@ function getTotalLockedUser () { // Is given userid valid? function isValidUserId ($userid) { + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid); + + // Handle NULL + if (is_null($userid)) { + // Do not handle this as of below isset() will always return false + return false; + } // END - if + // Do we have cache? if (!isset($GLOBALS[__FUNCTION__][$userid])) { // Check it out @@ -1072,11 +1278,23 @@ function encodeEntities ($str) { } // "Getter" for date from patch_ctime -function getDateFromPatchTime () { +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('patch_ctime'), '5'); + $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2'); } // END - if // Return cache @@ -1084,11 +1302,13 @@ function getDateFromPatchTime () { } // Getter for current year (default) -function getYear ($timestamp = null) { +function getYear ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { // null is time() - if (is_null($timestamp)) $timestamp = time(); + if (is_null($timestamp)) { + $timestamp = time(); + } // END - if // Then create it $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp); @@ -1099,11 +1319,14 @@ function getYear ($timestamp = null) { } // Getter for current month (default) -function getMonth ($timestamp = null) { +function getMonth ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { - // null is time() - if (is_null($timestamp)) $timestamp = time(); + // If null is set, use time() + if (is_null($timestamp)) { + // Use time() which is current timestamp + $timestamp = time(); + } // END - if // Then create it $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp); @@ -1113,12 +1336,31 @@ function getMonth ($timestamp = null) { return $GLOBALS[__FUNCTION__][$timestamp]; } +// Getter for current hour (default) +function getHour ($timestamp = NULL) { + // Is it cached? + if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { + // null is time() + if (is_null($timestamp)) { + $timestamp = time(); + } // END - if + + // Then create it + $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__][$timestamp]; +} + // Getter for current day (default) -function getDay ($timestamp = null) { +function getDay ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { // null is time() - if (is_null($timestamp)) $timestamp = time(); + if (is_null($timestamp)) { + $timestamp = time(); + } // END - if // Then create it $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp); @@ -1129,7 +1371,7 @@ function getDay ($timestamp = null) { } // Getter for current week (default) -function getWeek ($timestamp = null) { +function getWeek ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { // null is time() @@ -1144,7 +1386,7 @@ function getWeek ($timestamp = null) { } // Getter for current short_hour (default) -function getShortHour ($timestamp = null) { +function getShortHour ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { // null is time() @@ -1159,7 +1401,7 @@ function getShortHour ($timestamp = null) { } // Getter for current long_hour (default) -function getLongHour ($timestamp = null) { +function getLongHour ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { // null is time() @@ -1174,7 +1416,7 @@ function getLongHour ($timestamp = null) { } // Getter for current second (default) -function getSecond ($timestamp = null) { +function getSecond ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { // null is time() @@ -1189,7 +1431,7 @@ function getSecond ($timestamp = null) { } // Getter for current minute (default) -function getMinute ($timestamp = null) { +function getMinute ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { // null is time() @@ -1203,7 +1445,7 @@ function getMinute ($timestamp = null) { return $GLOBALS[__FUNCTION__][$timestamp]; } -// Checks wether the title decoration is enabled +// Checks whether the title decoration is enabled function isTitleDecorationEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { @@ -1215,7 +1457,7 @@ function isTitleDecorationEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether filter usage updates are enabled (expensive queries!) +// Checks whether filter usage updates are enabled (expensive queries!) function isFilterUsageUpdateEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { @@ -1227,7 +1469,7 @@ function isFilterUsageUpdateEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether debugging of weekly resets is enabled +// Checks whether debugging of weekly resets is enabled function isWeeklyResetDebugEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { @@ -1239,7 +1481,7 @@ function isWeeklyResetDebugEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether debugging of monthly resets is enabled +// Checks whether debugging of monthly resets is enabled function isMonthlyResetDebugEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { @@ -1251,7 +1493,7 @@ function isMonthlyResetDebugEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether displaying of debug SQLs are enabled +// Checks whether displaying of debug SQLs are enabled function isDisplayDebugSqlEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { @@ -1263,7 +1505,7 @@ function isDisplayDebugSqlEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether module title is enabled +// Checks whether module title is enabled function isModuleTitleEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { @@ -1275,7 +1517,7 @@ function isModuleTitleEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether what title is enabled +// Checks whether what title is enabled function isWhatTitleEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { @@ -1287,19 +1529,19 @@ function isWhatTitleEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether stats are enabled -function ifStatsAreEnabled () { +// Checks whether stats are enabled +function ifInternalStatsEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { // Then determine it - $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y'); + $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y'); } // END - if // Return cached value return $GLOBALS[__FUNCTION__]; } -// Checks wether admin-notification of certain user actions is enabled +// Checks whether admin-notification of certain user actions is enabled function isAdminNotificationEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { @@ -1311,12 +1553,12 @@ function isAdminNotificationEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether random referal id selection is enabled -function isRandomReferalIdEnabled () { +// Checks whether random referral id selection is enabled +function isRandomReferralIdEnabled () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = (getConfig('select_user_zero_refid') == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y')); } // END - if // Return cache @@ -1335,6 +1577,18 @@ function getDefaultLanguage () { return $GLOBALS[__FUNCTION__]; } +// "Getter" for default referral id +function getDefRefid () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('def_refid'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // "Getter" for path function getPath () { // Do we have cache? @@ -1383,6 +1637,30 @@ function getSecretKey () { return $GLOBALS[__FUNCTION__]; } +// "Getter" for SITE_KEY +function getSiteKey () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for DATE_KEY +function getDateKey () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // "Getter" for master_salt function getMasterSalt () { // Do we have cache? @@ -1407,12 +1685,12 @@ function getPrime () { return $GLOBALS[__FUNCTION__]; } -// "Getter" for encrypt_seperator -function getEncryptSeperator () { +// "Getter" for encrypt_separator +function getEncryptSeparator () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR'); + $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR'); } // END - if // Return cache @@ -1492,11 +1770,11 @@ function getTitle () { } // "Getter" for curr_svn_revision -function getCurrSvnRevision () { +function getCurrentRepositoryRevision () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = getConfig('CURR_SVN_REVISION'); + $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION'); } // END - if // Return cache @@ -1839,106 +2117,966 @@ function getOneDay () { return $GLOBALS[__FUNCTION__]; } -// Checks wether proxy configuration is used -function isProxyUsed () { +// "Getter" for activate_xchange +function getActivateXchange () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0)); + $GLOBALS[__FUNCTION__] = getConfig('activate_xchange'); } // END - if // Return cache return $GLOBALS[__FUNCTION__]; } -// Checks wether POST data contains selections -function ifPostContainsSelections ($element = 'sel') { +// "Getter" for img_type +function getImgType () { // Do we have cache? - if (!isset($GLOBALS[__FUNCTION__][$element])) { + if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0)); + $GLOBALS[__FUNCTION__] = getConfig('img_type'); } // END - if // Return cache - return $GLOBALS[__FUNCTION__][$element]; + return $GLOBALS[__FUNCTION__]; } -// Checks wether verbose_sql is Y and returns true/false if so -function isVerboseSqlEnabled () { +// "Getter" for code_length +function getCodeLength () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')); + $GLOBALS[__FUNCTION__] = getConfig('code_length'); } // END - if // Return cache return $GLOBALS[__FUNCTION__]; } -// "Getter" for total user points -function getTotalPoints ($userid) { +// "Getter" for least_cats +function getLeastCats () { // Do we have cache? - if (!isset($GLOBALS[__FUNCTION__][$userid])) { + if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points'); + $GLOBALS[__FUNCTION__] = getConfig('least_cats'); } // END - if // Return cache - return $GLOBALS[__FUNCTION__][$userid]; + return $GLOBALS[__FUNCTION__]; } -// Wrapper to check if url_blacklist is enabled -function isUrlBlacklistEnabled () { +// "Getter" for pass_len +function getPassLen () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y'); + $GLOBALS[__FUNCTION__] = getConfig('pass_len'); } // END - if // Return cache return $GLOBALS[__FUNCTION__]; } -// Checks wether direct payment is allowed in configuration -function isDirectPaymentEnabled () { +// "Getter" for admin_menu +function getAdminMenu () { // Do we have cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y'); + $GLOBALS[__FUNCTION__] = getConfig('admin_menu'); } // END - if // Return cache return $GLOBALS[__FUNCTION__]; } -// Wrapper to check if current task is for extension (not update) -function isExtensionTask ($content) { +// "Getter" for last_month +function getLastMonth () { // Do we have cache? - if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) { + if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos']))); + $GLOBALS[__FUNCTION__] = getConfig('last_month'); } // END - if // Return cache - return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']]; + return $GLOBALS[__FUNCTION__]; } -// Wrapper to check if output mode is CSS -function isCssOutputMode () { - // Determine it - return (getScriptOutputMode() == 1); +// "Getter" for max_send +function getMaxSend () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('max_send'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for mails_page +function getMailsPage () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('mails_page'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for rand_no +function getRandNo () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('rand_no'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for __DB_NAME +function getDbName () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for DOMAIN +function getDomain () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('DOMAIN'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for proxy_username +function getProxyUsername () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('proxy_username'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for proxy_password +function getProxyPassword () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('proxy_password'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for proxy_host +function getProxyHost () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('proxy_host'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for proxy_port +function getProxyPort () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('proxy_port'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for SMTP_HOSTNAME +function getSmtpHostname () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for SMTP_USER +function getSmtpUser () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for SMTP_PASSWORD +function getSmtpPassword () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for points_word +function getPointsWord () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('points_word'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for profile_lock +function getProfileLock () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('profile_lock'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for url_tlock +function getUrlTlock () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('url_tlock'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for title_left +function getTitleLeft () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('title_left'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for title_right +function getTitleRight () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('title_right'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for title_middle +function getTitleMiddle () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('title_middle'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'check_double_email' +function getCheckDoubleEmail () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('check_double_email'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether 'check_double_email' is 'Y' +function isCheckDoubleEmailEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// 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__] = (getDisplayHomeInIndex() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'admin_menu_javascript' +function getAdminMenuJavascript () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'points_remove_account' +function getPointsRemoveAccount () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('points_remove_account'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether proxy configuration is used +function isProxyUsed () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0)); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether POST data contains selections +function ifPostContainsSelections ($element = 'sel') { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__][$element])) { + // Determine it + $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0)); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__][$element]; +} + +// Checks whether verbose_sql is Y and returns true/false if so +function isVerboseSqlEnabled () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for total user points +function getTotalPoints ($userid) { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__][$userid])) { + // Init array for filter chain + $data = array( + 'userid' => $userid, + 'points' => 0 + ); + + // Run filter chain for getting more point values + $data = runFilterChain('get_total_points', $data); + + // Determine it + $GLOBALS[__FUNCTION__][$userid] = $data['points'] - getUserUsedPoints($userid); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__][$userid]; +} + +// Wrapper to get used points for given userid +function getUserUsedPoints ($userid) { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__][$userid])) { + // Determine it + $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points'); + } // END - if + + // Return cache + 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? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether JavaScript-based admin menu is enabled +function isAdminMenuJavascriptEnabled () { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y')); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Wrapper to check if current task is for extension (not update) +function isExtensionTask ($content) { + // Do we have 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']))); + } // END - if + + // Return cache + 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? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y')); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Wrapper to check if output mode is CSS +function isCssOutputMode () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode()); + $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; } // Wrapper to check if output mode is HTML function isHtmlOutputMode () { - // Determine it - return (getScriptOutputMode() == 0); + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode()); + $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; } // Wrapper to check if output mode is RAW function isRawOutputMode () { - // Determine it - return (getScriptOutputMode() == -1); + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode()); + $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Wrapper to check if output mode is AJAX +function isAjaxOutputMode () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode()); + $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Wrapper to check if output mode is image +function isImageOutputMode () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode()); + $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Wrapper to generate a user email link +function generateWrappedUserEmailLink ($email) { + // Just call the inner function + return generateEmailLink($email, 'user_data'); +} + +// Wrapper to check if user points are locked +function ifUserPointsLocked ($userid) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!'); + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__][$userid])) { + // Determine it + $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled())); + } // END - if + + // Return cache + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!'); + return $GLOBALS[__FUNCTION__][$userid]; +} + +// Appends a line to an existing file or creates it instantly with given content. +// 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)); + fclose($fp); +} + +// Wrapper for changeDataInFile() but with full path added +function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) { + // Add full path + $FQFN = getPath() . $FQFN; + + // Call inner function + return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek); +} + +// Wrapper for changing entries in config-local.php +function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) { + // Call the inner function + return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek); +} + +// Shortens ucfirst(strtolower()) calls +function firstCharUpperCase ($str) { + return ucfirst(strtolower($str)); +} + +// Shortens calls with configuration entry as first argument (the second will become obsolete in the future) +function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') { + // Get the configuration entry + $configValue = getConfig($configEntry); + + // Call inner method + return createTimeSelections($configValue, $configEntry, $stamps, $align); +} + +// Shortens converting of German comma to Computer's version in POST data +function convertCommaToDotInPostData ($postEntry) { + // Read and convert given entry + $postValue = convertCommaToDot(postRequestElement($postEntry)); + + // ... and set it again + setPostRequestElement($postEntry, $postValue); +} + +// Converts German commas to Computer's version in all entries +function convertCommaToDotInPostDataArray ($postEntries) { + // Replace german decimal comma with computer decimal dot + foreach ($postEntries as $entry) { + // Is the entry there? + if (isPostRequestElementSet($entry)) { + // Then convert it + convertCommaToDotInPostData($entry); + } // END - if + } // END - foreach +} + +/** + * Parses a string into a US formated float variable, taken from user comments + * from PHP documentation website. + * + * @param $floatString A string holding a float expression + * @return $float Corresponding float variable + * @author chrisgeorgakopouloscom + * @link http://de.php.net/manual/en/function.floatval.php#92563 + */ +function parseFloat ($floatString){ + // Load locale info + $LocaleInfo = localeconv(); + + // Remove thousand separators + $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString); + + // Convert decimal point + $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString); + + // Return float value of converted string + return floatval($floatString); +} + +// Generates a YES/NO option list from given default +function generateYesNoOptions ($defaultValue = '') { + // Generate it + return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $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))); + + // Return value + return $numRows; +} + +// Wrapper "getter" to get total unconfirmed mails for given userid +function getTotalUnconfirmedMails ($userid) { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__][$userid])) { + // Determine it + $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__][$userid]; +} + +// Checks whether 'mailer_theme' was found in session +function isMailerThemeSet () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +/** + * Setter for theme in session (This setter does return the success of + * setSession() which is required e.g. for destroySponsorSession(). + */ +function setMailerTheme ($newTheme) { + // Set it in session + return setSession('mailer_theme', $newTheme); +} + +/** + * Getter for theme from session (This getter does return 'mailer_theme' from + * session data or throws an error if not possible + */ +function getMailerTheme () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Is 'mailer_theme' set? + if (!isMailerThemeSet()) { + // No, then abort here + reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.'); + } // END - if + + // Get it and store it in cache + $GLOBALS[__FUNCTION__] = getSession('mailer_theme'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for last_module/last_what depending on ext-user version +function getUserLastWhatName () { + // Default is old one: last_module + $columnName = 'last_module'; + + // Is ext-user up-to-date? + if (isExtensionInstalledAndNewer('user', '0.4.9')) { + // Yes, then use new one + $columnName = 'last_what'; + } // END - if + + // Return it + return $columnName; +} + +// "Getter" for all columns for given alias and separator +function getAllPointColumns ($alias = NULL, $separator = ',') { + // Prepare the filter array + $filterData = array( + 'columns' => '', + 'alias' => $alias, + 'separator' => $separator + ); + + // Run the filter + $filterData = runFilterChain('get_all_point_columns', $filterData); + + // Return the columns + return $filterData['columns']; +} + +// Checks whether the copyright footer (which breaks framesets) is enabled +function ifCopyrightFooterEnabled () { + // Is not unset and not 'N'? + return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y')); +} + +/** + * Wrapper to check whether we have a "full page". This means that the actual + * content is not delivered in any frame of a frameset. + */ +function isFullPage () { + /* + * The parameter 'frame' is generic and always indicates that this content + * will be output into a frame. Furthermore, if a frameset is reported or + * the copyright line is explicitly deactivated, this cannot be a "full + * page" again. + */ + // @TODO Find a way to not use direct module comparison + $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled())); + + // Return it + return $isFullPage; +} + +// Checks whether frameset_mode is set to true +function isFramesetModeEnabled () { + // Check it + return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === true)); +} + +// Function to determine correct 'what' value +function determineWhat ($module = NULL) { + // Init default 'what' + $what = 'welcome'; + + // Is module NULL? + if (is_null($module)) { + // Then use default + $module = getModule(); + } // END - if + + // Is what set? + if (isWhatSet()) { + // Then use it + $what = getWhat(); + } else { + // Else try to get it from current module + $what = getWhatFromModule($module); + } + //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*'); + + // Remove any spaces from variable + $what = trim($what); + + // Is it empty? + if (empty($what)) { + // Default action for non-admin menus + $what = 'welcome'; + } else { + // Secure it + $what = secureString($what); + } + + // Return what + return $what; +} + +// 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) { + // Return prepended string + return sprintf('%0' . (int) $length . 's', $mStretch); +} + +// Wraps convertSelectionsToEpocheTime() +function convertSelectionsToEpocheTimeInPostData ($id) { + // Init variables + $content = array(); + $skip = false; + + // Get all POST data + $postData = postRequestArray(); + + // Convert given selection id + convertSelectionsToEpocheTime($postData, $content, $id, $skip); + + // Set the POST array back + setPostRequestArray($postData); +} + +// Wraps checking if given points account type matches with given in POST data +function ifPointsAccountTypeMatchesPost ($type) { + // Check condition + exit(__FUNCTION__.':type='.$type.',post=
'.print_r(postRequestArray(), true).'
'); +} + +// Gets given user's total referral +function getUsersTotalReferrals ($userid, $level = NULL) { + // Do we have 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); + } else { + // Get it from user refs + $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true, ' AND `level`=' . bigintval($level)); + } + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__][$userid][$level]; +} + +// 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? + if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) { + // Default is all refs + $add = ''; + + // Is the not level NULL? + if (!is_null($level)) { + // Then add referral level + $add = ' AND r.`level`=' . bigintval($level); + } // END - if + + // Check for all referrals + $result = SQL_QUERY_ESC("SELECT + COUNT(d.`userid`) AS `cnt` +FROM + `{?_MYSQL_PREFIX?}_user_data` AS d +INNER JOIN + `{?_MYSQL_PREFIX?}_user_refs` AS r +ON + d.`userid`=r.`refid` +WHERE + d.`status` != 'CONFIRMED' AND + r.`userid`=%s + " . $add . " +ORDER BY + d.`userid` ASC +LIMIT 1", + array( + $userid + ), __FUNCTION__, __LINE__); + + // Load count + list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result); + + // Free result + SQL_FREERESULT($result); + } // END - if + + // Return it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!'); + return $GLOBALS[__FUNCTION__][$userid][$level]; +} + +// Converts, if found, dollar data to get element +function convertDollarDataToGetElement ($data) { + // Is first char a dollar? + if (substr($data, 0, 1) == chr(36)) { + // Use last part for getRequestElement() + $data = getRequestElement(substr($data, 1)); + } // END - if + + // Return it + return $data; +} + +// Wrapper function for SQL layer to speed-up things +function SQL_DEBUG_ENABLED () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled())); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; } // [EOF]