X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fwrapper-functions.php;h=e20a4abd2139350827cf4f5e69ec2794cb233cc5;hp=c6bb6cb804ecd93cbb87af715678cf737b5791ff;hb=87229cb5d7b5396793e85fd0b4172d473195835c;hpb=b3055f6c5889383a78eace62230ca4be55acee43 diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index c6bb6cb804..e20a4abd21 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 - 2012 by Mailer Developer Team * + * Copyright (c) 2009 - 2013 by Mailer Developer Team * * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -46,19 +46,19 @@ function readFromFile ($FQFN) { if (!isFileReadable($FQFN)) { // This should not happen reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!'); - } elseif (!isset($GLOBALS['file_content'][$FQFN])) { - // Load the file - if (function_exists('file_get_contents')) { - // Use new function - $GLOBALS['file_content'][$FQFN] = file_get_contents($FQFN); - } else { - // Fall-back to implode-file chain - $GLOBALS['file_content'][$FQFN] = implode('', file($FQFN)); - } } // END - if + // Load the file + if (function_exists('file_get_contents')) { + // Use new function + $fileContent = file_get_contents($FQFN); + } else { + // Fall-back to implode-file chain + $fileContent = implode('', file($FQFN)); + } + // Return the content - return $GLOBALS['file_content'][$FQFN]; + return $fileContent; } // Writes content to a file @@ -66,7 +66,7 @@ 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; @@ -74,7 +74,6 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) { // By default all is failed... $GLOBALS['file_readable'][$FQFN] = FALSE; - unset($GLOBALS['file_content'][$FQFN]); $return = FALSE; // Is the function there? @@ -108,9 +107,6 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) { if ($return !== FALSE) { // Mark it as readable $GLOBALS['file_readable'][$FQFN] = TRUE; - - // Remember content in cache - $GLOBALS['file_content'][$FQFN] = $content; } // END - if // Return status @@ -123,10 +119,7 @@ function clearOutputBuffer () { if (isset($GLOBALS[__FUNCTION__])) { // This function is called twice reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.'); - } // END - if - - // Trigger an error on failure - if ((ob_get_length() > 0) && (!ob_end_clean())) { + } elseif ((ob_get_length() > 0) && (!ob_end_clean())) { // Failed! reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.'); } // END - if @@ -157,21 +150,33 @@ function decodeEntities ($str, $quote = ENT_NOQUOTES) { } // Merges an array together but only if both are arrays -function merge_array ($array1, $array2) { +function merge_array ($array1, $array2, $keepIndex = FALSE) { // Are both an array? if ((!is_array($array1)) && (!is_array($array2))) { // Both are not arrays reportBug(__FUNCTION__, __LINE__, 'No arrays provided!'); } elseif (!is_array($array1)) { // Left one is not an array - reportBug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1))); + reportBug(__FUNCTION__, __LINE__, sprintf('array1 is not an array. array != %s', gettype($array1))); } elseif (!is_array($array2)) { // Right one is not an array - reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2))); + reportBug(__FUNCTION__, __LINE__, sprintf('array2 is not an array. array != %s', gettype($array2))); } - // Merge both together - return array_merge($array1, $array2); + // Maintain index of array2? + if ($keepIndex === TRUE) { + // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :( + foreach ($array2 as $key => $value) { + // Add it + $array1[$key] = $value; + } // END - foreach + + // Return it + return $array1; + } else { + // Merge both together normally + return array_merge($array1, $array2); + } } // Check if given FQFN is a readable file @@ -194,7 +199,7 @@ function isDirectory ($FQFN) { $baseName = basename($FQFN); // Check it - $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn')); + $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && (!in_array($baseName, array('.', '..', '.svn')))); } // END - if // Return the result @@ -202,12 +207,12 @@ function isDirectory ($FQFN) { } // "Getter" for the real remote IP number -function detectRealIpAddress () { +function detectRealIpAddress ($alwaysReal = FALSE) { // Get remote ip from environment $remoteAddr = determineRealRemoteAddress(); // Is removeip installed? - if (isExtensionActive('removeip')) { + if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) { // Then anonymize it $remoteAddr = getAnonymousRemoteAddress($remoteAddr); } // END - if @@ -217,12 +222,12 @@ function detectRealIpAddress () { } // "Getter" for remote IP number -function detectRemoteAddr () { +function detectRemoteAddr ($alwaysReal = FALSE) { // Get remote ip from environment $remoteAddr = determineRealRemoteAddress(TRUE); // Is removeip installed? - if (isExtensionActive('removeip')) { + if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) { // Then anonymize it $remoteAddr = getAnonymousRemoteAddress($remoteAddr); } // END - if @@ -232,12 +237,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 @@ -262,12 +267,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 @@ -320,7 +325,7 @@ function isInstalling () { // Determine whether we are installing if (!isset($GLOBALS['__mailer_installing'])) { // Check URL (css.php/js.php need this) - $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing'); + $GLOBALS['__mailer_installing'] = (isGetRequestElementSet('installing') || ((isAjaxOutputMode()) && (isGetRequestElementSet('level')) && (getRequestElement('level') == 'install'))); } // END - if // Return result @@ -337,9 +342,9 @@ function isInstalled () { // First is config ( ( - isConfigEntrySet('MXCHANGE_INSTALLED') + isConfigEntrySet('MAILER_INSTALLED') ) && ( - getConfig('MXCHANGE_INSTALLED') == 'Y' + getConfig('MAILER_INSTALLED') == 'Y' ) ) ) || ( @@ -383,10 +388,34 @@ function isHourlyResetEnabled () { return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE)); } -// Checks whether the reset mode is active +// Checks whether the daily reset mode is active +function isDailyResetEnabled () { + // Now simply check it + return ((isset($GLOBALS['daily_enabled'])) && ($GLOBALS['daily_enabled'] === TRUE)); +} + +// Checks whether the weekly reset mode is active +function isWeeklyResetEnabled () { + // Now simply check it + return ((isset($GLOBALS['weekly_enabled'])) && ($GLOBALS['weekly_enabled'] === TRUE)); +} + +// Checks whether the monthly reset mode is active +function isMonthlyResetEnabled () { + // Now simply check it + return ((isset($GLOBALS['monthly_enabled'])) && ($GLOBALS['monthly_enabled'] === TRUE)); +} + +// Checks whether the yearly reset mode is active +function isYearlyResetEnabled () { + // Now simply check it + return ((isset($GLOBALS['yearly_enabled'])) && ($GLOBALS['yearly_enabled'] === TRUE)); +} + +// Checks whether one of the reset modes is enabled function isResetModeEnabled () { // Now simply check it - return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === TRUE)); + return ((isHourlyResetEnabled()) || (isDailyResetEnabled()) || (isWeeklyResetEnabled()) || (isMonthlyResetEnabled()) || (isYearlyResetEnabled())); } // Checks whether the debug mode is enabled @@ -401,12 +430,60 @@ function isDebugModeEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks whether the debug reset is enabled -function isDebugResetEnabled () { +// Checks whether the debug hourly is enabled +function isDebugHourlyEnabled () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { // Simply check it - $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y')); + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_HOURLY')) && (getConfig('DEBUG_HOURLY') == 'Y')); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether the debug daily is enabled +function isDebugDailyEnabled () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Simply check it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_DAILY')) && (getConfig('DEBUG_DAILY') == 'Y')); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether the debug weekly is enabled +function isDebugWeeklyEnabled () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Simply check it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y')); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether the debug monthly is enabled +function isDebugMonthlyEnabled () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Simply check it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y')); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether the debug yearly is enabled +function isDebugYearlyEnabled () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Simply check it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y')); } // END - if // Return it @@ -437,8 +514,20 @@ function isDebugRegularExpressionEnabled () { return $GLOBALS[__FUNCTION__]; } +// Checks whether debugging of build mails is enabled +function isDebugBuildMailsEnabled () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Simply check it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_BUILD_MAILS')) && (getConfig('DEBUG_BUILD_MAILS') == 'Y')); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + // Checks whether the cache instance is valid -function isCacheInstanceValid () { +function isValidCacheInstance () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it @@ -585,7 +674,7 @@ function setWhatFromConfig ($configEntry) { } // Checks whether what is set and optionally aborts on miss -function isWhatSet ($strict = false) { +function isWhatSet ($strict = FALSE) { // Check for it $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what']))); @@ -620,7 +709,7 @@ function setAction ($newAction) { } // Checks whether action is set and optionally aborts on miss -function isActionSet ($strict = false) { +function isActionSet ($strict = FALSE) { // Check for it $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action']))); @@ -655,8 +744,29 @@ function setModule ($newModule) { $GLOBALS['__module'] = strtolower($newModule); } +// Wrapper to get extra module names +function getExtraModule () { + // Default is 'NULL' + $extra = 'NULL'; + + // Is 'tab/step' set? + if (isPostRequestElementSet('tab')) { + // Use this + $extra = 'tab=' . postRequestElement('tab'); + } elseif (isPostRequestElementSet('step')) { + // Use this + $extra = 'step=' . postRequestElement('step'); + } elseif ((isActionSet()) && (isWhatSet())) { + // Use 'action/what' + $extra = 'action=' . getAction() . ':what=' . getWhat(); + } + + // Return it + return $extra; +} + // Checks whether module is set and optionally aborts on miss -function isModuleSet ($strict = false) { +function isModuleSet ($strict = FALSE) { // Check for it $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module']))); @@ -689,13 +799,13 @@ function getScriptOutputMode () { } // Setter for 'output_mode' value -function setOutputMode ($newOutputMode) { +function setScriptOutputMode ($newOutputMode) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode); $GLOBALS['__output_mode'] = (int) $newOutputMode; } // Checks whether output_mode is set and optionally aborts on miss -function isOutputModeSet ($strict = false) { +function isOutputModeSet ($strict = FALSE) { // Check for it $isset = (isset($GLOBALS['__output_mode'])); @@ -719,7 +829,7 @@ function isBlockModeEnabled () { // Abort if not set if (!isset($GLOBALS['__block_mode'])) { // Needs to be fixed - reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.'); + reportBug(__FUNCTION__, __LINE__, '__block_mode is not set.'); } // END - if // Return it @@ -750,35 +860,35 @@ function redirectToDereferedUrl ($url) { } // Wrapper function for checking if extension is installed and newer or same version -function isExtensionInstalledAndNewer ($ext_name, $version) { +function isExtensionInstalledAndNewer ($ext_name, $ext_ver) { // Is an cache entry found? - if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) { + if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) { // Determine it - $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version)); + $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE)); } else { // Cache hits should be incremented twice incrementStatsEntry('cache_hits', 2); } // Return it - //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version])); - return $GLOBALS[__FUNCTION__][$ext_name][$version]; + //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])); + return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver]; } // Wrapper function for checking if extension is installed and older than given version -function isExtensionInstalledAndOlder ($ext_name, $version) { +function isExtensionInstalledAndOlder ($ext_name, $ext_ver) { // Is an cache entry found? - if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) { + if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) { // Determine it - $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version))); + $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (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 @@ -799,7 +909,7 @@ function getUsername () { } // Wrapper function for installation phase -function isInstallationPhase () { +function isInstaller () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it @@ -910,7 +1020,7 @@ function getAdminMd5 () { // Init user data array function initUserData () { // User id should not be zero - if (!isValidUserId(getCurrentUserId())) { + if (!isValidId(getCurrentUserId())) { // Should be always valid reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); } // END - if @@ -923,7 +1033,7 @@ function initUserData () { // Getter for user data function getUserData ($column) { // User id should not be zero - if (!isValidUserId(getCurrentUserId())) { + if (!isValidId(getCurrentUserId())) { // Should be always valid reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); } // END - if @@ -958,7 +1068,7 @@ function getUserDataArray () { $userid = getCurrentUserId(); // Is the current userid valid? - if (!isValidUserId($userid)) { + if (!isValidId($userid)) { // Should be always valid reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid); } // END - if @@ -975,7 +1085,7 @@ function getUserDataArray () { // Checks if the user data is valid, this may indicate that the user has logged // in, but you should use isMember() if you want to find that out. -function isUserDataValid () { +function isValidUserData () { // User id should not be zero so abort here if (!isCurrentUserIdSet()) { // Debug message, may be noisy @@ -1039,7 +1149,7 @@ function isCurrentUserIdSet () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid']))); + $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidId($GLOBALS['current_userid']))); } // END - if // Return cache @@ -1051,7 +1161,7 @@ function unsetCurrentUserId () { // Is it set? if (isset($GLOBALS['current_userid'])) { // Unset this, too - unset($GLOBALS['isValidUserId'][$GLOBALS['current_userid']]); + unset($GLOBALS['isValidId'][$GLOBALS['current_userid']]); } // END - if // Unset all cache entries @@ -1061,11 +1171,11 @@ function unsetCurrentUserId () { } // Checks whether we are debugging template cache -function isDebuggingTemplateCache () { +function isDebugTemplateCacheEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y'); + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_TEMPLATE_CACHE')) && (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y')); } // END - if // Return cache @@ -1081,7 +1191,7 @@ function getFetchedUserData ($keyColumn, $userid, $valueColumn) { $data = NULL; // Can we fetch the user data? - if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) { + if ((isValidId($userid)) && (fetchUserData($userid, $keyColumn))) { // Now get the data back $data = getUserData($valueColumn); } // END - if @@ -1158,7 +1268,7 @@ function sendRawRedirect ($url) { $GLOBALS['__output'] = ''; // To make redirects working (no content type), output mode must be raw - setOutputMode(-1); + setScriptOutputMode(-1); // Send helping header setHttpStatus('302 Found'); @@ -1277,20 +1387,26 @@ function getTotalRandomRefidUser () { return $GLOBALS[__FUNCTION__]; } -// Is given userid valid? -function isValidUserId ($userid) { +// Is given id number valid? +function isValidId ($id) { // Debug message - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id[' . gettype($id) . ']=' . $id); // Is there cache? - if (!isset($GLOBALS[__FUNCTION__][$userid])) { + if (!isset($GLOBALS[__FUNCTION__][$id])) { // Check it out - $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0)); + $GLOBALS[__FUNCTION__][$id] = ((isValidNumber($id)) && (!is_bool($id)) && ($id != '00000') && ($id > 0)); } // END - if // Return cache - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',result=' . intval($GLOBALS[__FUNCTION__][$userid])); - return $GLOBALS[__FUNCTION__][$userid]; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',result=' . intval($GLOBALS[__FUNCTION__][$id])); + return $GLOBALS[__FUNCTION__][$id]; +} + +// Checks whether a valid number is given +function isValidNumber ($num) { + // Determine it + return ((!is_null($num)) && (!empty($num)) && ('*' . bigintval($num, TRUE, FALSE) . '*' == '*' . $num . '*')); } // Encodes entities @@ -1333,7 +1449,7 @@ function getDateTimeFromRepository () { function getYear ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { - // null is time() + // If NULL is set, use time() if (is_null($timestamp)) { $timestamp = time(); } // END - if @@ -1350,7 +1466,7 @@ function getYear ($timestamp = NULL) { function getMonth ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { - // If null is set, use time() + // If NULL is set, use time() if (is_null($timestamp)) { // Use time() which is current timestamp $timestamp = time(); @@ -1478,7 +1594,7 @@ function isTitleDecorationEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Just check it - $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_title_deco')) && (getConfig('enable_title_deco') == 'Y')); } // END - if // Return cache @@ -1521,12 +1637,24 @@ function isMonthlyResetDebugEnabled () { return $GLOBALS[__FUNCTION__]; } +// Checks whether debugging of yearly resets is enabled +function isYearlyResetDebugEnabled () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y')); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // Checks whether displaying of debug SQLs are enabled function isDisplayDebugSqlEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y')); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (isConfigEntrySet('display_debug_sql')) && (getDisplayDebugSqls() == 'Y')); } // END - if // Return cache @@ -1538,7 +1666,7 @@ function isModuleTitleEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_mod_title')) && (getConfig('enable_mod_title') == 'Y')); } // END - if // Return cache @@ -1550,7 +1678,19 @@ function isWhatTitleEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_what_title')) && (getConfig('enable_what_title') == 'Y')); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for internal_stats +function getInternalStats () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('internal_stats'); } // END - if // Return cache @@ -1561,8 +1701,8 @@ function isWhatTitleEnabled () { function ifInternalStatsEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { - // Then determine it - $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y'); + // Then determine it, do not add isExtensionInstalledAndNewer() here as it breaks very first SQL query + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('internal_stats')) && (getInternalStats() == 'Y')); } // END - if // Return cached value @@ -1574,7 +1714,7 @@ function isAdminNotificationEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.3.0')) && (isConfigEntrySet('admin_notify')) && (getAdminNotify() == 'Y')); } // END - if // Return cache @@ -1586,7 +1726,7 @@ function isRandomReferralIdEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y')); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isConfigEntrySet('select_user_zero_refid')) && (getSelectUserZeroRefid() == 'Y')); } // END - if // Return cache @@ -1653,6 +1793,18 @@ function getCachePath () { return $GLOBALS[__FUNCTION__]; } +// "Getter" for WRITE_FOOTER +function getWriteFooter () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('WRITE_FOOTER'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // "Getter" for secret_key function getSecretKey () { // Is there cache? @@ -1940,79 +2092,6 @@ function getUserMinConfirmed () { // Return cache return $GLOBALS[__FUNCTION__]; } - -// "Getter" for auto_purge -function getAutoPurge () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('auto_purge'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for bonus_userid -function getBonusUserid () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('bonus_userid'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for ap_inactive_time -function getApInactiveTime () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for ap_dm_timeout -function getApDmTimeout () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for ap_tasks_time -function getApTasksTime () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for ap_unconfirmed_time -function getApUnconfirmedTime () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - // "Getter" for points function getPoints () { // Is there cache? @@ -2181,18 +2260,6 @@ function getOneDay () { return $GLOBALS[__FUNCTION__]; } -// "Getter" for activate_xchange -function getActivateXchange () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('activate_xchange'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - // "Getter" for img_type function getImgType () { // Is there cache? @@ -2217,24 +2284,24 @@ function getCodeLength () { return $GLOBALS[__FUNCTION__]; } -// "Getter" for least_cats -function getLeastCats () { +// "Getter" for min_password_length +function getMinPasswordLength () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = getConfig('least_cats'); + $GLOBALS[__FUNCTION__] = getConfig('min_password_length'); } // END - if // Return cache return $GLOBALS[__FUNCTION__]; } -// "Getter" for pass_len -function getPassLen () { +// "Getter" for min_password_score +function getMinPasswordScore () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = getConfig('pass_len'); + $GLOBALS[__FUNCTION__] = getConfig('min_password_score'); } // END - if // Return cache @@ -2253,24 +2320,60 @@ function getAdminMenu () { return $GLOBALS[__FUNCTION__]; } -// "Getter" for last_month -function getLastMonth () { +// "Getter" for last_hourly +function getLastHourly () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('last_hourly'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for last_daily +function getLastDaily () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('last_daily'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for last_weekly +function getLastWeekly () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('last_weekly'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for last_monthly +function getLastMonthly () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = getConfig('last_month'); + $GLOBALS[__FUNCTION__] = getConfig('last_monthly'); } // END - if // Return cache return $GLOBALS[__FUNCTION__]; } -// "Getter" for max_send -function getMaxSend () { +// "Getter" for last_yearly +function getLastYearly () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = getConfig('max_send'); + $GLOBALS[__FUNCTION__] = getConfig('last_yearly'); } // END - if // Return cache @@ -2481,48 +2584,144 @@ function getTitleMiddle () { return $GLOBALS[__FUNCTION__]; } -// Getter for 'check_double_email' -function getCheckDoubleEmail () { +// Getter for 'display_home_in_index' +function getDisplayHomeInIndex () { // Is the cache entry set? if (!isset($GLOBALS[__FUNCTION__])) { // No, so determine it - $GLOBALS[__FUNCTION__] = getConfig('check_double_email'); + $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index'); } // END - if // Return cached entry return $GLOBALS[__FUNCTION__]; } -// Checks whether 'check_double_email' is 'Y' -function isCheckDoubleEmailEnabled () { +// 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__] = (getCheckDoubleEmail() == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isConfigEntrySet('display_home_in_index')) && (getDisplayHomeInIndex() == 'Y')); } // END - if // Return cached entry return $GLOBALS[__FUNCTION__]; } -// Getter for 'display_home_in_index' -function getDisplayHomeInIndex () { +// Getter for 'show_points_unconfirmed' +function getShowPointsUnconfirmed () { // Is the cache entry set? if (!isset($GLOBALS[__FUNCTION__])) { // No, so determine it - $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index'); + $GLOBALS[__FUNCTION__] = getConfig('show_points_unconfirmed'); } // END - if // Return cached entry return $GLOBALS[__FUNCTION__]; } -// Checks whether 'display_home_in_index' is 'Y' -function isDisplayHomeInIndexEnabled () { +// Checks whether 'show_points_unconfirmed' is 'Y' +function isShowPointsUnconfirmedEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.5.5')) && (isConfigEntrySet('show_points_unconfirmed')) && (getShowPointsUnconfirmed() == 'Y')); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'youre_here' +function getYoureHere () { // Is the cache entry set? if (!isset($GLOBALS[__FUNCTION__])) { // No, so determine it - $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y'); + $GLOBALS[__FUNCTION__] = getConfig('youre_here'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether 'show_timings' is 'Y' +function isYoureHereEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (isConfigEntrySet('youre_here')) && (getYoureHere() == 'Y')); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'show_timings' +function getShowTimings () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('show_timings'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether 'show_timings' is 'Y' +function isShowTimingsEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (isConfigEntrySet('show_timings')) && (getShowTimings() == 'Y')); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'ap_server_name_since' +function getApServerNameSince () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('ap_server_name_since'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'ap_server_name' +function getApServerName () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('ap_server_name'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'index_delay' +function getIndexDelay () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('index_delay'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether 'ap_server_name' is 'Y' +function isApServerNameEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getApServerName() == 'Y'); } // END - if // Return cached entry @@ -2553,12 +2752,96 @@ function getPointsRemoveAccount () { return $GLOBALS[__FUNCTION__]; } +// Getter for 'css_php' +function getCssPhp () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('css_php'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'guest_menu' +function getGuestMenu () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('guest_menu'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks if guest menu is enabled +function isGuestMenuEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getGuestMenu() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'member_menu' +function getMemberMenu () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('member_menu'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks if member menu is enabled +function isMemberMenuEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getMemberMenu() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'word_wrap' +function getWordWrap () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Construct config entry name + $configEntry = getMenuModeFromModule() . '_word_wrap_' . getWhat(); + + // Is a special config entry found or ext-sql_patches updated? + if (isConfigEntrySet($configEntry)) { + // A special config entry has been found, then use it + $GLOBALS[__FUNCTION__] = getConfig($configEntry); + } elseif (isExtensionInstalledAndNewer('other', '0.2.9')) { + // No special config entry found, then use it as "fall-back" + $GLOBALS[__FUNCTION__] = getConfig('word_wrap'); + } else { + // No, use default (15 characters) + $GLOBALS[__FUNCTION__] = 15; + } + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + // Checks whether proxy configuration is used function isProxyUsed () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0)); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (isValidNumber(getConfig('proxy_port')))); } // END - if // Return cache @@ -2622,24 +2905,12 @@ function getUserUsedPoints ($userid) { return $GLOBALS[__FUNCTION__][$userid]; } -// Wrapper to check if url_blacklist is enabled -function isUrlBlacklistEnabled () { - // Is there 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 () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y'); + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('allow_direct_pay')) && (getConfig('allow_direct_pay') == 'Y')); } // END - if // Return cache @@ -2651,7 +2922,7 @@ function isAdminMenuJavascriptEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y')); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (isConfigEntrySet('admin_menu_javascript')) && (getAdminMenuJavaScript() == 'Y')); } // END - if // Return cache @@ -2670,18 +2941,6 @@ function isExtensionTask ($content) { return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']]; } -// Getter for 'mt_start' -function getMtStart () { - // Is the cache entry set? - if (!isset($GLOBALS[__FUNCTION__])) { - // No, so determine it - $GLOBALS[__FUNCTION__] = getConfig('mt_start'); - } // END - if - - // Return cached entry - return $GLOBALS[__FUNCTION__]; -} - // Checks whether ALLOW_TESTER_ACCOUNTS is set function ifTesterAccountsAllowed () { // Is the cache entry set? @@ -2783,14 +3042,14 @@ function ifUserPointsLocked ($userid) { // This function does always add a new-line character to every line. function appendLineToFile ($file, $line) { $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!'); - fwrite($fp, $line . chr(10)); + fwrite($fp, $line . PHP_EOL); fclose($fp); } // Wrapper for changeDataInFile() but with full path added -function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) { +function changeDataInInclude ($inc, $comment, $prefix, $suffix, $inserted, $seek=0) { // Add full path - $FQFN = getPath() . $FQFN; + $FQFN = getPath() . $inc; // Call inner function return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek); @@ -2821,6 +3080,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); } @@ -2864,33 +3126,43 @@ function parseFloat ($floatString){ * Searches a multi-dimensional array (as used in many places) for given * key/value pair as taken from user comments from PHP documentation website. * - * @param $array An array with one or more dimensions - * @param $key Key to look for - * @param $valur Value to look for - * @return $results Resulted array or empty array if $array is no array + * @param $array An array with one or more dimensions + * @param $key Key to look for + * @param $value Value to look for + * @param $parentIndex Parent index (ONLY INTERNAL USE!) + * @return $results Resulted array or empty array if $array is no array * @author sunelbegmailcom * @link http://de.php.net/manual/en/function.array-search.php#110120 */ -function search_array ($array, $key, $value) { +function search_array ($array, $key, $value, $parentIndex = NULL) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!'); // Init array result $results = array(); // Is $array really an array? if (is_array($array)) { - // Does key and value match? - if (isset($array[$key]) && $array[$key] == $value) { - // Then add it as result - $results[] = $array; - } // END - if - // Search for whole array - foreach ($array as $subArray) { - // Search recursive and merge again - $results = merge_array($results, search_array($subArray, $key, $value)); + foreach ($array as $idx => $dummy) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex); + //* DEBUG: */ print 'idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',key=' . $key . ',value=' . $value . ',array=
'.print_r($array, TRUE).'
'; + // Is dummy an array? + if ((is_array($dummy)) && ((is_null($parentIndex)) || ($parentIndex === $value))) { + // Then search again + $subResult = search_array($dummy, $key, $value, $idx); + //* DEBUG: */ print 'subResult=
' . print_r($subResult, TRUE).'
'; + + // And merge both + $results = merge_array($results, $subResult, TRUE); + } elseif (($key == $idx) && (isset($array[$key])) && ($array[$key] === $value)) { + // Is found, so add it + $results[$parentIndex] = $array; + //* DEBUG: */ print 'ARRAY: key=' . $key . ',idx=' . $idx . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',array=
' . print_r($array, TRUE).'
'; + } } // END - foreach } // END - if // Return resulting array + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!'); return $results; } @@ -3062,9 +3334,9 @@ function determineWhat ($module = NULL) { } // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad -function prependZeros ($mStretch, $length = 2) { +function prependZeros ($str, $length = 2) { // Return prepended string - return sprintf('%0' . (int) $length . 's', $mStretch); + return sprintf('%0' . (int) $length . 's', $str); } // Wraps convertSelectionsToEpocheTime() @@ -3118,34 +3390,34 @@ function getUsersTotalLockedReferrals ($userid, $level = NULL) { // Is the not level NULL? if (!is_null($level)) { // Then add referral level - $add = ' AND r.`level`=' . bigintval($level); + $add = ' AND `r`.`level`=' . bigintval($level); } // END - if // Check for all referrals - $result = SQL_QUERY_ESC("SELECT - COUNT(d.`userid`) AS `cnt` + $result = sqlQueryEscaped("SELECT + COUNT(`d`.`userid`) AS `cnt` FROM - `{?_MYSQL_PREFIX?}_user_data` AS d + `{?_MYSQL_PREFIX?}_user_data` AS `d` INNER JOIN - `{?_MYSQL_PREFIX?}_user_refs` AS r + `{?_MYSQL_PREFIX?}_user_refs` AS `r` ON - d.`userid`=r.`refid` + `d`.`userid`=`r`.`refid` WHERE - d.`status` != 'CONFIRMED' AND - r.`userid`=%s + `d`.`status` != 'CONFIRMED' AND + `r`.`userid`=%s " . $add . " ORDER BY - d.`userid` ASC + `d`.`userid` ASC LIMIT 1", array( $userid ), __FUNCTION__, __LINE__); // Load count - list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result); + list($GLOBALS[__FUNCTION__][$userid][$level]) = sqlFetchRow($result); // Free result - SQL_FREERESULT($result); + sqlFreeResult($result); } // END - if // Return it @@ -3166,7 +3438,7 @@ function convertDollarDataToGetElement ($data) { } // Wrapper function for SQL layer to speed-up things -function SQL_DEBUG_ENABLED () { +function isSqlDebugEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it @@ -3177,5 +3449,134 @@ function SQL_DEBUG_ENABLED () { return $GLOBALS[__FUNCTION__]; } +// Wrapper function to wrap call of wordwrap() +function wrapWords ($text) { + // Wrap words + $wrapped = wordwrap($test, getWordWrap()); + + // Return it + return $wrapped; +} + +// Encodes given data into a JSON object +function encodeJson ($data) { + // Encode it + return json_encode($data, JSON_FORCE_OBJECT); +} + +// Get all extension files +function loadAllExtensionsByTemplate () { + // Get all + $extensions = getArrayFromDirectory( + 'templates/' . getLanguage() . '/html/ext/', + 'ext_', + false, + false, + array(), + '.tpl', + '@(\.|\.\.)$@', + false + ); + + // Return them + return $extensions; +} + +// Wrapper function to allow full float values as supported by current database layout +function translateFullComma ($dotted) { + // Call inner function + return translateComma($dotted, TRUE, 5); +} + +// Wrapper to check if the first element to be shifted is set to given value +function shift_array (&$array, $value, $key = '0') { + // Is the element set and value matches? + assert(is_array($array)); + assert(isset($array[$key])); + assert($array[$key] === $value); + + // Shift it + array_shift($array); +} + +// Wrapper for str_pad() with left padding zeros +function padLeftZero ($str, $amount = 2) { + // Is str_pad() there? + if (!function_exists('str_pad')) { + // Use prependZeros() + return prependZeros($str, $amount); + } else { + // Pad it + return str_pad($str, $amount, '0', STR_PAD_LEFT); + } +} + +// Calculates percentage +function calculatePercentageRate ($current, $total) { + // Default is zero + $rate = '0.0'; + + // Is sent larger zero? (Prevents division-by-zero) + if ($total > 0) { + // Calculate it (it should be "translated" alter on) + $rate = ($current / $total * 100); + } // END - if + + // The should be a .0 at the end? + if (strpos($rate, '.') === FALSE) { + // No, then add it + $rate .= '.0'; + } // END - if + + // Return it + return $rate; +} + +// Checks whether an array is filled with entries +function isFilledArray ($array) { + // Determine it + return ((is_array($array)) && (count($array) > 0)); +} + +// Checks whether this script runs on a developer system (called with localhost/127.0.0.1 SERVER_NAME) +function isDeveloperSystem () { + // Determine it + return in_array(detectServerName(), array('localhost', '127.0.0.1')); +} + +// Checks whether given subject line has '_ref' suffix +function ifSubjectHasReferralSuffix ($subject) { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__][$subject])) { + // Determine it + $GLOBALS[__FUNCTION__][$subject] = (substr($subject, -4, 4) == '_ref'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__][$subject]; +} + +// Converts an API response to an associative array +function convertApiResponseToArray ($responseString, $keyDelimiter, $valueDelimiter) { + // Explode for key delimiter + $keys = explode($keyDelimiter, $responseString); + + // Init returned array and "walk" through all entries + $returned = array(); + foreach ($keys as $keyValue) { + // Explode it + $parts = explode($valueDelimiter, $keyValue); + + // Count must be 2 + assert(count($parts) == 2); + + // Then add both: 0=key, 1=value + $returned[sqlEscapeString($parts[0])] = sqlEscapeString($parts[1]); + } // END - if + + // Return finished array + return $returned; +} + // [EOF] ?>