X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fwrapper-functions.php;h=ba56fb2c8e3e9d5bab2e12f2020d764694fc292a;hp=d7f6db028ed82ebbdcc7bac5aa3ac9a1ea4ae73a;hb=7052cc3bd3ca07281078acbbce6ce595d753def1;hpb=f99fabc783c022ddc5ca1f3e9c0d3ab89170dcf5 diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index d7f6db028e..ba56fb2c8e 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2011 by Mailer Developer Team * + * 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 * @@ -37,7 +37,7 @@ // Some security stuff... if (!defined('__SECURITY')) { - die(); + exit(); } // END - if // Read a given file @@ -45,42 +45,41 @@ 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!'); - } 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)); - } + reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!'); } // 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,11 +88,12 @@ 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) { - // Aquire lock + // Aquire a lock? + if ($aquireLock === TRUE) { + // Aquire a lock. flock($fp, LOCK_EX); } // END - if @@ -105,25 +105,28 @@ 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. function clearOutputBuffer () { - // Trigger an error on failure - if ((ob_get_length() > 0) && (!ob_end_clean())) { + // 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.'); + } elseif ((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 @@ -148,26 +151,38 @@ function decodeEntities ($str, $quote = ENT_NOQUOTES) { } // Merges an array together but only if both are arrays -function merge_array ($array1, $array2) { +function merge_array ($array1, $array2, $keepIndex = FALSE) { // Are both an array? if ((!is_array($array1)) && (!is_array($array2))) { // Both are not arrays - 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 - return array_merge($array1, $array2); + // Maintain index of array2? + if ($keepIndex === TRUE) { + // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :( + foreach ($array2 as $key => $value) { + // Add it + $array1[$key] = $value; + } // END - foreach + + // Return it + return $array1; + } else { + // Merge both together normally + return array_merge($array1, $array2); + } } // Check if given FQFN is a readable file function isFileReadable ($FQFN) { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS['file_readable'][$FQFN])) { // Check all... $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN))); @@ -177,9 +192,9 @@ function isFileReadable ($FQFN) { 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? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$FQFN])) { // Generate baseName $baseName = basename($FQFN); @@ -193,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 @@ -208,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 @@ -223,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 @@ -238,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 @@ -253,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 @@ -287,7 +302,7 @@ function detectServerName () { // Removes any existing www. from SERVER_NAME. This is very silly but enough // for our purpose here. function detectDomainName () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Get server name $domainName = detectServerName(); @@ -306,23 +321,23 @@ function detectDomainName () { return $GLOBALS[__FUNCTION__]; } -// Check wether we are installing +// Check whether we are installing function isInstalling () { - // Determine wether we are installing - if (!isset($GLOBALS['mailer_installing'])) { + // Determine whether we are installing + if (!isset($GLOBALS['__mailer_installing'])) { // Check URL (css.php/js.php need this) - $GLOBALS['mailer_installing'] = isGetRequestElementSet('installing'); + $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing'); } // END - if // Return result - return $GLOBALS['mailer_installing']; + return $GLOBALS['__mailer_installing']; } -// Check wether this script is installed +// Check whether this script is installed function isInstalled () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { - // Determine wether this script is installed + // Determine whether this script is installed $GLOBALS[__FUNCTION__] = ( ( // First is config @@ -356,7 +371,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__])) { @@ -368,19 +383,19 @@ function isAdminRegistered () { return $GLOBALS[__FUNCTION__]; } -// Checks wether the hourly 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)); + return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE)); } -// Checks wether the reset mode is active +// 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 wether the debug mode is enabled +// Checks whether the debug mode is enabled function isDebugModeEnabled () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { @@ -392,7 +407,7 @@ function isDebugModeEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether the debug reset is enabled +// Checks whether the debug reset is enabled function isDebugResetEnabled () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { @@ -404,7 +419,7 @@ function isDebugResetEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether SQL debugging is enabled +// Checks whether SQL debugging is enabled function isSqlDebuggingEnabled () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { @@ -416,7 +431,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__])) { @@ -428,9 +443,9 @@ function isDebugRegularExpressionEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether the cache instance is valid +// Checks whether the cache instance is valid function isCacheInstanceValid () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance']))); @@ -445,76 +460,49 @@ 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)) { // 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; + $GLOBALS['file_readable'][$dest] = TRUE; } + // All fine by default + $status = TRUE; + // If there are chmod rights set, apply them if (!empty($chmod)) { // Try to apply them $status = changeMode($dest, $chmod); - } else { - // All fine - $status = true; - } + } // END - if // All fine return $status; } -// 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 @@ -526,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); @@ -534,32 +522,38 @@ function removeFile ($FQFN) { // All fine if no file was removed. If we change this to 'false' or rewrite // above if() block it would be to restrictive. - return true; + return TRUE; } // Wrapper for $_POST['sel'] function countPostSelection ($element = 'sel') { - // Is it set? - if (isPostRequestElementSet($element)) { - // Return counted elements - return countSelection(postRequestElement($element)); - } else { - // Return zero if not found - return 0; - } + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__][$element])) { + // Default is zero + $GLOBALS[__FUNCTION__][$element] = '0'; + + // Is it set? + if (isPostRequestElementSet($element)) { + // Return counted elements + $GLOBALS[__FUNCTION__][$element] = countSelection(postRequestElement($element)); + } // END - if + } // END - if + + // Return cached value + return $GLOBALS[__FUNCTION__][$element]; } -// Checks 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)); + 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] = ((!empty($userid)) && (('' . round($userid) . '') != $userid) && ($userid != 'NULL')); + $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL')); } // END - if // Return the result @@ -567,14 +561,14 @@ function isNicknameUsed ($userid) { } // Getter for 'what' value -function getWhat () { +function getWhat ($strict = TRUE) { // Default is 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 @@ -583,7 +577,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 @@ -595,13 +590,13 @@ 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)) { + if (($strict === TRUE) && ($isset === FALSE)) { // Output backtrace debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.'); } // END - if @@ -611,14 +606,14 @@ function isWhatSet ($strict = false) { } // Getter for 'action' value -function getAction ($strict = true) { +function getAction ($strict = TRUE) { // Default is null $action = NULL; // Is the value set? if (isActionSet(($strict) && (isHtmlOutputMode()))) { // Then use it - $action = $GLOBALS['action']; + $action = $GLOBALS['__action']; } // END - if // Return it @@ -627,18 +622,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)) { + 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 @@ -646,14 +641,14 @@ function isActionSet ($strict = false) { } // Getter for 'module' value -function getModule ($strict = true) { +function getModule ($strict = TRUE) { // Default is null $module = NULL; // Is the value set? if (isModuleSet($strict)) { // Then use it - $module = $GLOBALS['module']; + $module = $GLOBALS['__module']; } // END - if // Return it @@ -663,39 +658,36 @@ 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)) { + 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 () { - // Do we have cache? + // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { - // Default is null - $output_mode = NULL; - - // Is the value set? - if (isOutputModeSet(true)) { - // Then use it - $output_mode = $GLOBALS['output_mode']; + // Is the output mode set? + if (!isOutputModeSet()) { + // No, then abort here + reportBug(__FUNCTION__, __LINE__, 'Output mode not set.'); } // END - if - // Store it in cache - $GLOBALS[__FUNCTION__] = $output_mode; + // Set it in cache + $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode']; } // END - if // Return cache @@ -704,18 +696,19 @@ function getScriptOutputMode () { // 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)) { + if (($strict === TRUE) && ($isset === FALSE)) { // Output backtrace - debug_report_bug(__FUNCTION__, __LINE__, 'Output mode is not set.'); + reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.'); } // END - if // Return it @@ -723,38 +716,20 @@ function isOutputModeSet ($strict = false) { } // Enables block-mode -function enableBlockMode ($enabled = true) { - $GLOBALS['block_mode'] = $enabled; +function enableBlockMode ($enabled = TRUE) { + $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['block_mode'])) { + 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['block_mode']; -} - -/** - * Wrapper function for addPointsThroughReferalSystem(), you should generally - * avoid this function and use addPointsThroughReferalSystem() directly and add - * your special payment method entry to points_data instead. - * - * @param $subject A string-encoded subject for this add - * @param $userid The recipient (member) for given points - * @param $points Points to be added to member's account - * @return $added Wether the points has been added to the user's account - */ -function addPointsDirectly ($subject, $userid, $points) { - // Reset level here - initReferalSystem(); - - // 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 @@ -777,39 +752,39 @@ function redirectToRequestUri () { // Wrapper function to redirect to de-refered URL function redirectToDereferedUrl ($url) { // Redirect to to - redirectToUrl(generateDerefererUrl($url)); + redirectToUrl(generateDereferrerUrl($url)); } // Wrapper function for checking if extension is installed and newer or same version -function isExtensionInstalledAndNewer ($ext_name, $version) { +function isExtensionInstalledAndNewer ($ext_name, $ext_ver) { // Is an cache entry found? - if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) { + if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) { // Determine it - $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version)); + $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE)); } else { // Cache hits should be incremented twice incrementStatsEntry('cache_hits', 2); } // Return it - //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version])); - return $GLOBALS[__FUNCTION__][$ext_name][$version]; + //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])); + return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver]; } // Wrapper function for checking if extension is installed and older than given version -function isExtensionInstalledAndOlder ($ext_name, $version) { +function isExtensionInstalledAndOlder ($ext_name, $ext_ver) { // Is an cache entry found? - if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) { + if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) { // Determine it - $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version))); + $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '<') === TRUE)); } else { // Cache hits should be incremented twice incrementStatsEntry('cache_hits', 2); } // Return it - //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $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 @@ -831,7 +806,7 @@ function getUsername () { // Wrapper function for installation phase function isInstallationPhase () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling())); @@ -841,7 +816,7 @@ 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__])) { @@ -858,12 +833,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 @@ -880,7 +855,7 @@ function getCurrentAdminLogin () { // Log debug message //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!'); - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId()); @@ -943,7 +918,7 @@ function initUserData () { // User id should not be zero if (!isValidUserId(getCurrentUserId())) { // Should be always valid - debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); + reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); } // END - if // Init the user @@ -956,7 +931,7 @@ function getUserData ($column) { // User id should not be zero if (!isValidUserId(getCurrentUserId())) { // Should be always valid - debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); + reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); } // END - if // Default is empty @@ -971,9 +946,9 @@ function getUserData ($column) { return $data; } -// Checks wether given user data is set to 'Y' +// Checks whether given user data is set to 'Y' function isUserDataEnabled ($column) { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) { // Determine it $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y'); @@ -991,7 +966,7 @@ function getUserDataArray () { // Is the current userid valid? if (!isValidUserId($userid)) { // Should be always valid - debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid); + reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid); } // END - if // Get the whole array if found @@ -1009,7 +984,11 @@ function getUserDataArray () { function isUserDataValid () { // User id should not be zero so abort here if (!isCurrentUserIdSet()) { - return false; + // Debug message, may be noisy + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!'); + + // Abort here + return FALSE; } // END - if // Is it cached? @@ -1024,33 +1003,72 @@ function isUserDataValid () { // Setter for current userid function setCurrentUserId ($userid) { + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - ENTERED!'); + + // Is the cache from below functions different? + if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) { + // Then unset both + unsetCurrentUserId(); + } // END - if + // Set userid $GLOBALS['current_userid'] = bigintval($userid); // Unset it to re-determine the actual state unset($GLOBALS['is_userdata_valid'][$userid]); + + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - EXIT!'); } // 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']))); + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid']))); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Unsets current userid +function unsetCurrentUserId () { + // Is it set? + if (isset($GLOBALS['current_userid'])) { + // Unset this, too + unset($GLOBALS['isValidUserId'][$GLOBALS['current_userid']]); + } // END - if + + // Unset all cache entries + unset($GLOBALS['current_userid']); + unset($GLOBALS['getCurrentUserId']); + unset($GLOBALS['isCurrentUserIdSet']); } -// Checks wether we are debugging template cache +// Checks whether we are debugging template cache function isDebuggingTemplateCache () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y'); @@ -1085,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 @@ -1101,6 +1119,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; @@ -1109,9 +1133,9 @@ function setHttpStatus ($status) { // Getter for HTTP status function getHttpStatus () { // Is the status set? - if (!isset($GLOBALS['http_status'])) { + if (!isHttpStatusSet()) { // Abort here - debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!'); + reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!'); } // END - if // Return it @@ -1133,6 +1157,15 @@ 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'); @@ -1148,19 +1181,19 @@ function sendRawRedirect ($url) { (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 function determineCountry ($userid) { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$userid])) { // Default is 'invalid' $GLOBALS[__FUNCTION__][$userid] = 'invalid'; @@ -1188,13 +1221,14 @@ function getTotalConfirmedUser () { if (!isset($GLOBALS[__FUNCTION__])) { // Then do it if (isExtensionActive('user')) { - $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true); + $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__]; } @@ -1204,13 +1238,14 @@ function getTotalUnconfirmedUser () { if (!isset($GLOBALS[__FUNCTION__])) { // Then do it if (isExtensionActive('user')) { - $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true); + $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__]; } @@ -1220,13 +1255,14 @@ function getTotalLockedUser () { if (!isset($GLOBALS[__FUNCTION__])) { // Then do it if (isExtensionActive('user')) { - $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true); + $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__]; } @@ -1236,32 +1272,37 @@ 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, '', '>='); + $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>='); } else { $GLOBALS[__FUNCTION__] = 0; } } // END - if // Return cached value + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]); return $GLOBALS[__FUNCTION__]; } // Is given userid valid? function isValidUserId ($userid) { - // Do we have cache? + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid); + + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$userid])) { // Check it out $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0)); } // END - if // Return cache + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',result=' . intval($GLOBALS[__FUNCTION__][$userid])); return $GLOBALS[__FUNCTION__][$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); @@ -1438,9 +1479,9 @@ 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? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Just check it $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y'); @@ -1450,9 +1491,9 @@ 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? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y')); @@ -1462,9 +1503,9 @@ 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? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y')); @@ -1474,9 +1515,9 @@ 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? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y')); @@ -1486,9 +1527,9 @@ 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? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y')); @@ -1498,9 +1539,9 @@ function isDisplayDebugSqlEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether module title is enabled +// Checks whether module title is enabled function isModuleTitleEnabled () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y'); @@ -1510,9 +1551,9 @@ function isModuleTitleEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether what title is enabled +// Checks whether what title is enabled function isWhatTitleEnabled () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y'); @@ -1522,21 +1563,21 @@ function isWhatTitleEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether stats are enabled -function ifStatsAreEnabled () { - // Do we have cache? +// Checks whether stats are enabled +function ifInternalStatsEnabled () { + // Is there 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? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y'); @@ -1546,9 +1587,9 @@ function isAdminNotificationEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether random referal id selection is enabled -function isRandomReferalIdEnabled () { - // Do we have cache? +// Checks whether random referral id selection is enabled +function isRandomReferralIdEnabled () { + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y')); @@ -1560,7 +1601,7 @@ function isRandomReferalIdEnabled () { // "Getter" for default language function getDefaultLanguage () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG'); @@ -1570,9 +1611,9 @@ function getDefaultLanguage () { return $GLOBALS[__FUNCTION__]; } -// "Getter" for default referal id +// "Getter" for default referral id function getDefRefid () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('def_refid'); @@ -1584,7 +1625,7 @@ function getDefRefid () { // "Getter" for path function getPath () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('PATH'); @@ -1596,7 +1637,7 @@ function getPath () { // "Getter" for url function getUrl () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('URL'); @@ -1608,7 +1649,7 @@ function getUrl () { // "Getter" for cache_path function getCachePath () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH'); @@ -1620,7 +1661,7 @@ function getCachePath () { // "Getter" for secret_key function getSecretKey () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('secret_key'); @@ -1632,7 +1673,7 @@ function getSecretKey () { // "Getter" for SITE_KEY function getSiteKey () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY'); @@ -1644,7 +1685,7 @@ function getSiteKey () { // "Getter" for DATE_KEY function getDateKey () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY'); @@ -1656,7 +1697,7 @@ function getDateKey () { // "Getter" for master_salt function getMasterSalt () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('master_salt'); @@ -1668,7 +1709,7 @@ function getMasterSalt () { // "Getter" for prime function getPrime () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('_PRIME'); @@ -1680,7 +1721,7 @@ function getPrime () { // "Getter" for encrypt_separator function getEncryptSeparator () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR'); @@ -1692,7 +1733,7 @@ function getEncryptSeparator () { // "Getter" for mysql_prefix function getMysqlPrefix () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX'); @@ -1704,7 +1745,7 @@ function getMysqlPrefix () { // "Getter" for table_type function getTableType () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE'); @@ -1716,7 +1757,7 @@ function getTableType () { // "Getter" for salt_length function getSaltLength () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('salt_length'); @@ -1728,7 +1769,7 @@ function getSaltLength () { // "Getter" for output_mode function getOutputMode () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE'); @@ -1740,7 +1781,7 @@ function getOutputMode () { // "Getter" for full_version function getFullVersion () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION'); @@ -1752,7 +1793,7 @@ function getFullVersion () { // "Getter" for title function getTitle () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('TITLE'); @@ -1764,7 +1805,7 @@ function getTitle () { // "Getter" for curr_svn_revision function getCurrentRepositoryRevision () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION'); @@ -1776,7 +1817,7 @@ function getCurrentRepositoryRevision () { // "Getter" for server_url function getServerUrl () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL'); @@ -1788,7 +1829,7 @@ function getServerUrl () { // "Getter" for mt_word function getMtWord () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('mt_word'); @@ -1800,7 +1841,7 @@ function getMtWord () { // "Getter" for mt_word2 function getMtWord2 () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('mt_word2'); @@ -1810,9 +1851,45 @@ function getMtWord2 () { return $GLOBALS[__FUNCTION__]; } +// "Getter" for mt_word3 +function getMtWord3 () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('mt_word3'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for START_TDAY +function getStartTday () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('START_TDAY'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for START_YDAY +function getStartYday () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('START_YDAY'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // "Getter" for main_title function getMainTitle () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE'); @@ -1824,7 +1901,7 @@ function getMainTitle () { // "Getter" for file_hash function getFileHash () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('file_hash'); @@ -1836,7 +1913,7 @@ function getFileHash () { // "Getter" for pass_scramble function getPassScramble () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('pass_scramble'); @@ -1848,7 +1925,7 @@ function getPassScramble () { // "Getter" for ap_inactive_since function getApInactiveSince () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since'); @@ -1860,7 +1937,7 @@ function getApInactiveSince () { // "Getter" for user_min_confirmed function getUserMinConfirmed () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed'); @@ -1872,7 +1949,7 @@ function getUserMinConfirmed () { // "Getter" for auto_purge function getAutoPurge () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('auto_purge'); @@ -1884,7 +1961,7 @@ function getAutoPurge () { // "Getter" for bonus_userid function getBonusUserid () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('bonus_userid'); @@ -1896,7 +1973,7 @@ function getBonusUserid () { // "Getter" for ap_inactive_time function getApInactiveTime () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time'); @@ -1908,7 +1985,7 @@ function getApInactiveTime () { // "Getter" for ap_dm_timeout function getApDmTimeout () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout'); @@ -1920,7 +1997,7 @@ function getApDmTimeout () { // "Getter" for ap_tasks_time function getApTasksTime () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time'); @@ -1932,7 +2009,7 @@ function getApTasksTime () { // "Getter" for ap_unconfirmed_time function getApUnconfirmedTime () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time'); @@ -1944,7 +2021,7 @@ function getApUnconfirmedTime () { // "Getter" for points function getPoints () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('POINTS'); @@ -1956,7 +2033,7 @@ function getPoints () { // "Getter" for slogan function getSlogan () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('SLOGAN'); @@ -1968,7 +2045,7 @@ function getSlogan () { // "Getter" for copy function getCopy () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('COPY'); @@ -1980,7 +2057,7 @@ function getCopy () { // "Getter" for webmaster function getWebmaster () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER'); @@ -1992,7 +2069,7 @@ function getWebmaster () { // "Getter" for sql_count function getSqlCount () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('sql_count'); @@ -2004,7 +2081,7 @@ function getSqlCount () { // "Getter" for num_templates function getNumTemplates () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('num_templates'); @@ -2016,7 +2093,7 @@ function getNumTemplates () { // "Getter" for dns_cache_timeout function getDnsCacheTimeout () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout'); @@ -2028,7 +2105,7 @@ function getDnsCacheTimeout () { // "Getter" for menu_blur_spacer function getMenuBlurSpacer () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer'); @@ -2040,7 +2117,7 @@ function getMenuBlurSpacer () { // "Getter" for points_register function getPointsRegister () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('points_register'); @@ -2052,7 +2129,7 @@ function getPointsRegister () { // "Getter" for points_ref function getPointsRef () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('points_ref'); @@ -2064,7 +2141,7 @@ function getPointsRef () { // "Getter" for ref_payout function getRefPayout () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('ref_payout'); @@ -2076,7 +2153,7 @@ function getRefPayout () { // "Getter" for online_timeout function getOnlineTimeout () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('online_timeout'); @@ -2088,7 +2165,7 @@ function getOnlineTimeout () { // "Getter" for index_home function getIndexHome () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('index_home'); @@ -2100,7 +2177,7 @@ function getIndexHome () { // "Getter" for one_day function getOneDay () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY'); @@ -2112,7 +2189,7 @@ function getOneDay () { // "Getter" for activate_xchange function getActivateXchange () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('activate_xchange'); @@ -2124,7 +2201,7 @@ function getActivateXchange () { // "Getter" for img_type function getImgType () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('img_type'); @@ -2136,7 +2213,7 @@ function getImgType () { // "Getter" for code_length function getCodeLength () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('code_length'); @@ -2148,7 +2225,7 @@ function getCodeLength () { // "Getter" for least_cats function getLeastCats () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('least_cats'); @@ -2160,7 +2237,7 @@ function getLeastCats () { // "Getter" for pass_len function getPassLen () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('pass_len'); @@ -2172,7 +2249,7 @@ function getPassLen () { // "Getter" for admin_menu function getAdminMenu () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('admin_menu'); @@ -2184,7 +2261,7 @@ function getAdminMenu () { // "Getter" for last_month function getLastMonth () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('last_month'); @@ -2196,7 +2273,7 @@ function getLastMonth () { // "Getter" for max_send function getMaxSend () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('max_send'); @@ -2208,7 +2285,7 @@ function getMaxSend () { // "Getter" for mails_page function getMailsPage () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('mails_page'); @@ -2220,7 +2297,7 @@ function getMailsPage () { // "Getter" for rand_no function getRandNo () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('rand_no'); @@ -2232,7 +2309,7 @@ function getRandNo () { // "Getter" for __DB_NAME function getDbName () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME'); @@ -2244,7 +2321,7 @@ function getDbName () { // "Getter" for DOMAIN function getDomain () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('DOMAIN'); @@ -2256,7 +2333,7 @@ function getDomain () { // "Getter" for proxy_username function getProxyUsername () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('proxy_username'); @@ -2268,7 +2345,7 @@ function getProxyUsername () { // "Getter" for proxy_password function getProxyPassword () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('proxy_password'); @@ -2280,7 +2357,7 @@ function getProxyPassword () { // "Getter" for proxy_host function getProxyHost () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('proxy_host'); @@ -2292,7 +2369,7 @@ function getProxyHost () { // "Getter" for proxy_port function getProxyPort () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('proxy_port'); @@ -2304,7 +2381,7 @@ function getProxyPort () { // "Getter" for SMTP_HOSTNAME function getSmtpHostname () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME'); @@ -2316,7 +2393,7 @@ function getSmtpHostname () { // "Getter" for SMTP_USER function getSmtpUser () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER'); @@ -2328,7 +2405,7 @@ function getSmtpUser () { // "Getter" for SMTP_PASSWORD function getSmtpPassword () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD'); @@ -2340,7 +2417,7 @@ function getSmtpPassword () { // "Getter" for points_word function getPointsWord () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('points_word'); @@ -2352,7 +2429,7 @@ function getPointsWord () { // "Getter" for profile_lock function getProfileLock () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('profile_lock'); @@ -2364,7 +2441,7 @@ function getProfileLock () { // "Getter" for url_tlock function getUrlTlock () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('url_tlock'); @@ -2376,7 +2453,7 @@ function getUrlTlock () { // "Getter" for title_left function getTitleLeft () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('title_left'); @@ -2388,7 +2465,7 @@ function getTitleLeft () { // "Getter" for title_right function getTitleRight () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('title_right'); @@ -2400,7 +2477,7 @@ function getTitleRight () { // "Getter" for title_middle function getTitleMiddle () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = getConfig('title_middle'); @@ -2422,7 +2499,7 @@ function getCheckDoubleEmail () { return $GLOBALS[__FUNCTION__]; } -// Checks wether 'check_double_email' is 'Y' +// Checks whether 'check_double_email' is 'Y' function isCheckDoubleEmailEnabled () { // Is the cache entry set? if (!isset($GLOBALS[__FUNCTION__])) { @@ -2446,7 +2523,7 @@ function getDisplayHomeInIndex () { return $GLOBALS[__FUNCTION__]; } -// Checks wether 'display_home_in_index' is 'Y' +// Checks whether 'display_home_in_index' is 'Y' function isDisplayHomeInIndexEnabled () { // Is the cache entry set? if (!isset($GLOBALS[__FUNCTION__])) { @@ -2458,9 +2535,33 @@ function isDisplayHomeInIndexEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether proxy configuration is used +// 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? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0)); @@ -2470,21 +2571,21 @@ function isProxyUsed () { return $GLOBALS[__FUNCTION__]; } -// Checks wether POST data contains selections +// Checks whether POST data contains selections function ifPostContainsSelections ($element = 'sel') { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$element])) { // Determine it - $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (countPostSelection($element) > 0)); + $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0)); } // END - if // Return cache return $GLOBALS[__FUNCTION__][$element]; } -// Checks wether verbose_sql is Y and returns true/false if so +// Checks whether verbose_sql is Y and returns true/false if so function isVerboseSqlEnabled () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')); @@ -2496,7 +2597,7 @@ function isVerboseSqlEnabled () { // "Getter" for total user points function getTotalPoints ($userid) { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$userid])) { // Init array for filter chain $data = array( @@ -2508,7 +2609,19 @@ function getTotalPoints ($userid) { $data = runFilterChain('get_total_points', $data); // Determine it - $GLOBALS[__FUNCTION__][$userid] = $data['points'] - countSumTotalData($userid, 'user_data', 'used_points'); + $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) { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__][$userid])) { + // Determine it + $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points'); } // END - if // Return cache @@ -2517,7 +2630,7 @@ function getTotalPoints ($userid) { // Wrapper to check if url_blacklist is enabled function isUrlBlacklistEnabled () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y'); @@ -2527,9 +2640,9 @@ function isUrlBlacklistEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks wether direct payment is allowed in configuration +// Checks whether direct payment is allowed in configuration function isDirectPaymentEnabled () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y'); @@ -2539,34 +2652,117 @@ function isDirectPaymentEnabled () { return $GLOBALS[__FUNCTION__]; } +// Checks whether JavaScript-based admin menu is enabled +function isAdminMenuJavascriptEnabled () { + // Is there 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? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) { // Determine it - $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos']))); + $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 () { - // 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 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 @@ -2578,7 +2774,7 @@ function generateWrappedUserEmailLink ($email) { // Wrapper to check if user points are locked function ifUserPointsLocked ($userid) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!'); - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$userid])) { // Determine it $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled())); @@ -2592,8 +2788,8 @@ function ifUserPointsLocked ($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 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!'); - fwrite($fp, $line . "\n"); + $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!'); + fwrite($fp, $line . PHP_EOL); fclose($fp); } @@ -2631,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); } @@ -2657,22 +2856,71 @@ function convertCommaToDotInPostDataArray ($postEntries) { * @link http://de.php.net/manual/en/function.floatval.php#92563 */ function parseFloat ($floatString){ - $LocaleInfo = localeconv(); - $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '', $floatString); - $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString); - return floatval($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); +} + +/** + * 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 $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 sunelbegmailcom + * @link http://de.php.net/manual/en/function.array-search.php#110120 + */ +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)) { + // Search for whole array + 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=
' . print_r($subResult, TRUE).'
'; + + // 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; } // Generates a YES/NO option list from given default -function generateYesNoOptionList ($configValue = '') { +function generateYesNoOptions ($defaultValue = '') { // Generate it - return generateOptionList('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $configValue); + 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, ' 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; @@ -2680,15 +2928,271 @@ function getTotalReceivers ($mode = 'normal') { // Wrapper "getter" to get total unconfirmed mails for given userid function getTotalUnconfirmedMails ($userid) { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$userid])) { // Determine it - $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true); + $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE); } // END - if // Return cache 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) { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) { + // Is the level NULL? + if (is_null($level)) { + // Get total amount (all levels) + $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE); + } 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!'); + // Is there 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] ?>