X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fwrapper-functions.php;h=ab921c4b4f0752a52a4cfc376ae54f528d27748e;hp=4bd75bad61b69e9995fd1858ff334ee9baf3e16a;hb=82c5c7d37ee00f628b4fdd445f7fc453523ed1dd;hpb=b4784eb7267921f162d2fa90d21fa20fad700962 diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 4bd75bad61..ab921c4b4f 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -10,13 +10,8 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : Wrapper-Funktionen * * -------------------------------------------------------------------- * - * $Revision:: $ * - * $Date:: $ * - * $Tag:: 0.2.1-FINAL $ * - * $Author:: $ * - * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2012 by Mailer Developer Team * + * Copyright (c) 2009 - 2015 by Mailer Developer Team * * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -66,7 +61,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 or cannot change CHMOD to 0644.", basename($FQFN))); + logDebugMessage(__FUNCTION__, __LINE__, sprintf('File %s not writeable or cannot change CHMOD to 0644.', basename($FQFN))); // Failed! :( return FALSE; @@ -88,8 +83,7 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) { } } else { // Write it with fopen - $fp = fopen($FQFN, 'w') - or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!'); + $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!'); // Aquire a lock? if ($aquireLock === TRUE) { @@ -158,10 +152,10 @@ function merge_array ($array1, $array2, $keepIndex = FALSE) { 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))); } // Maintain index of array2? @@ -200,7 +194,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 @@ -326,7 +320,7 @@ function isInstalling () { // Determine whether we are installing if (!isset($GLOBALS['__mailer_installing'])) { // Check URL (css.php/js.php need this) - $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing'); + $GLOBALS['__mailer_installing'] = (isGetRequestElementSet('installing') || ((isAjaxOutputMode()) && (isGetRequestElementSet('level')) && (getRequestElement('level') == 'install'))); } // END - if // Return result @@ -389,10 +383,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 @@ -407,12 +425,60 @@ function isDebugModeEnabled () { return $GLOBALS[__FUNCTION__]; } -// Checks whether the debug reset is enabled -function isDebugResetEnabled () { +// Checks whether the debug hourly is enabled +function isDebugHourlyEnabled () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Simply check it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_HOURLY')) && (getConfig('DEBUG_HOURLY') == 'Y')); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether the debug daily is enabled +function isDebugDailyEnabled () { // Is cache set? if (!isset($GLOBALS[__FUNCTION__])) { // Simply check it - $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y')); + $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 @@ -456,7 +522,7 @@ function isDebugBuildMailsEnabled () { } // Checks whether the cache instance is valid -function isCacheInstanceValid () { +function isValidCacheInstance () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it @@ -673,6 +739,27 @@ 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) { // Check for it @@ -737,7 +824,7 @@ function isBlockModeEnabled () { // Abort if not set if (!isset($GLOBALS['__block_mode'])) { // Needs to be fixed - reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.'); + reportBug(__FUNCTION__, __LINE__, '__block_mode is not set.'); } // END - if // Return it @@ -817,7 +904,7 @@ function getUsername () { } // Wrapper function for installation phase -function isInstallationPhase () { +function isInstaller () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it @@ -912,6 +999,9 @@ function setAdminMd5 ($adminMd5) { // Set session $status = setSession('admin_md5', $adminMd5); + // Remove cache to get correct results + unset($GLOBALS['isAdmin']); + // Return status return $status; } @@ -928,7 +1018,7 @@ function getAdminMd5 () { // Init user data array function initUserData () { // User id should not be zero - if (!isValidUserId(getCurrentUserId())) { + if (!isValidId(getCurrentUserId())) { // Should be always valid reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); } // END - if @@ -941,7 +1031,7 @@ function initUserData () { // Getter for user data function getUserData ($column) { // User id should not be zero - if (!isValidUserId(getCurrentUserId())) { + if (!isValidId(getCurrentUserId())) { // Should be always valid reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId()); } // END - if @@ -976,7 +1066,7 @@ function getUserDataArray () { $userid = getCurrentUserId(); // Is the current userid valid? - if (!isValidUserId($userid)) { + if (!isValidId($userid)) { // Should be always valid reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid); } // END - if @@ -993,7 +1083,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 @@ -1057,7 +1147,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 @@ -1069,7 +1159,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 @@ -1079,11 +1169,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 @@ -1099,7 +1189,7 @@ function getFetchedUserData ($keyColumn, $userid, $valueColumn) { $data = NULL; // Can we fetch the user data? - if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) { + if ((isValidId($userid)) && (fetchUserData($userid, $keyColumn))) { // Now get the data back $data = getUserData($valueColumn); } // END - if @@ -1169,6 +1259,8 @@ function getHttpStatus () { * @access private */ function sendRawRedirect ($url) { + //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url); + // Clear output buffer clearOutputBuffer(); @@ -1186,6 +1278,7 @@ function sendRawRedirect ($url) { // Revert entity & $url = str_replace('&', '&', $url); + //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url); // check if running on IIS < 6 with CGI-PHP if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) && @@ -1295,20 +1388,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 != 'NULL') && ($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 @@ -1323,30 +1422,6 @@ function encodeEntities ($str) { return $str; } -// "Getter" for date from patch_ctime -function getDateFromRepository () { - // Is it cached? - if (!isset($GLOBALS[__FUNCTION__])) { - // Then set it - $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for date/time from patch_ctime -function getDateTimeFromRepository () { - // Is it cached? - if (!isset($GLOBALS[__FUNCTION__])) { - // Then set it - $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - // Getter for current year (default) function getYear ($timestamp = NULL) { // Is it cached? @@ -1496,7 +1571,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 @@ -1539,12 +1614,24 @@ function isMonthlyResetDebugEnabled () { return $GLOBALS[__FUNCTION__]; } +// Checks whether debugging of yearly resets is enabled +function isYearlyResetDebugEnabled () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y')); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // Checks whether displaying of debug SQLs are enabled function isDisplayDebugSqlEnabled () { // 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 @@ -1556,7 +1643,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 @@ -1568,7 +1655,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 @@ -1579,8 +1678,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 @@ -1592,7 +1691,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 @@ -1604,7 +1703,7 @@ function isRandomReferralIdEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getSelectUserZeroRefid() == 'Y')); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isConfigEntrySet('select_user_zero_refid')) && (getSelectUserZeroRefid() == 'Y')); } // END - if // Return cache @@ -1671,6 +1770,18 @@ function getCachePath () { return $GLOBALS[__FUNCTION__]; } +// "Getter" for cache_extension +function getCacheExtension () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('CACHE_EXTENSION'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // "Getter" for WRITE_FOOTER function getWriteFooter () { // Is there cache? @@ -1779,6 +1890,18 @@ function getTableType () { return $GLOBALS[__FUNCTION__]; } +// "Getter" for db_type +function getDbType () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('_DB_TYPE'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // "Getter" for salt_length function getSaltLength () { // Is there cache? @@ -1827,18 +1950,6 @@ function getTitle () { return $GLOBALS[__FUNCTION__]; } -// "Getter" for curr_svn_revision -function getCurrentRepositoryRevision () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - // "Getter" for server_url function getServerUrl () { // Is there cache? @@ -2138,18 +2249,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? @@ -2174,24 +2273,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 @@ -2210,24 +2309,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_month'); + $GLOBALS[__FUNCTION__] = getConfig('last_daily'); } // END - if // Return cache return $GLOBALS[__FUNCTION__]; } -// "Getter" for max_send -function getMaxSend () { +// "Getter" for last_weekly +function getLastWeekly () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = getConfig('max_send'); + $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_monthly'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "Getter" for last_yearly +function getLastYearly () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('last_yearly'); } // END - if // Return cache @@ -2438,30 +2573,6 @@ function getTitleMiddle () { return $GLOBALS[__FUNCTION__]; } -// Getter for 'check_double_email' -function getCheckDoubleEmail () { - // Is the cache entry set? - if (!isset($GLOBALS[__FUNCTION__])) { - // No, so determine it - $GLOBALS[__FUNCTION__] = getConfig('check_double_email'); - } // END - if - - // Return cached entry - return $GLOBALS[__FUNCTION__]; -} - -// Checks whether 'check_double_email' is 'Y' -function isCheckDoubleEmailEnabled () { - // Is the cache entry set? - if (!isset($GLOBALS[__FUNCTION__])) { - // No, so determine it - $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y'); - } // END - if - - // Return cached entry - return $GLOBALS[__FUNCTION__]; -} - // Getter for 'display_home_in_index' function getDisplayHomeInIndex () { // Is the cache entry set? @@ -2479,7 +2590,7 @@ function isDisplayHomeInIndexEnabled () { // Is the cache entry set? if (!isset($GLOBALS[__FUNCTION__])) { // No, so determine it - $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isConfigEntrySet('display_home_in_index')) && (getDisplayHomeInIndex() == 'Y')); } // END - if // Return cached entry @@ -2503,7 +2614,7 @@ function isShowPointsUnconfirmedEnabled () { // Is the cache entry set? if (!isset($GLOBALS[__FUNCTION__])) { // No, so determine it - $GLOBALS[__FUNCTION__] = (getShowPointsUnconfirmed() == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.5.5')) && (isConfigEntrySet('show_points_unconfirmed')) && (getShowPointsUnconfirmed() == 'Y')); } // END - if // Return cached entry @@ -2527,7 +2638,7 @@ function isYoureHereEnabled () { // Is the cache entry set? if (!isset($GLOBALS[__FUNCTION__])) { // No, so determine it - $GLOBALS[__FUNCTION__] = (getYoureHere() == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (isConfigEntrySet('youre_here')) && (getYoureHere() == 'Y')); } // END - if // Return cached entry @@ -2551,7 +2662,7 @@ function isShowTimingsEnabled () { // Is the cache entry set? if (!isset($GLOBALS[__FUNCTION__])) { // No, so determine it - $GLOBALS[__FUNCTION__] = (getShowTimings() == 'Y'); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (isConfigEntrySet('show_timings')) && (getShowTimings() == 'Y')); } // END - if // Return cached entry @@ -2719,7 +2830,7 @@ 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 @@ -2783,24 +2894,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 @@ -2812,7 +2911,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 @@ -2937,9 +3036,9 @@ function appendLineToFile ($file, $line) { } // 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); @@ -3224,9 +3323,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() @@ -3280,34 +3379,34 @@ function getUsersTotalLockedReferrals ($userid, $level = NULL) { // Is the not level NULL? if (!is_null($level)) { // Then add referral level - $add = ' AND r.`level`=' . bigintval($level); + $add = ' AND `r`.`level`=' . bigintval($level); } // END - if // Check for all referrals - $result = SQL_QUERY_ESC("SELECT - COUNT(d.`userid`) AS `cnt` + $result = sqlQueryEscaped("SELECT + COUNT(`d`.`userid`) AS `cnt` FROM - `{?_MYSQL_PREFIX?}_user_data` AS d + `{?_MYSQL_PREFIX?}_user_data` AS `d` INNER JOIN - `{?_MYSQL_PREFIX?}_user_refs` AS r + `{?_MYSQL_PREFIX?}_user_refs` AS `r` ON - d.`userid`=r.`refid` + `d`.`userid`=`r`.`refid` WHERE - d.`status` != 'CONFIRMED' AND - r.`userid`=%s + `d`.`status` != 'CONFIRMED' AND + `r`.`userid`=%s " . $add . " ORDER BY - d.`userid` ASC + `d`.`userid` ASC LIMIT 1", array( $userid ), __FUNCTION__, __LINE__); // Load count - list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result); + list($GLOBALS[__FUNCTION__][$userid][$level]) = sqlFetchRow($result); // Free result - SQL_FREERESULT($result); + sqlFreeResult($result); } // END - if // Return it @@ -3328,7 +3427,7 @@ function convertDollarDataToGetElement ($data) { } // Wrapper function for SQL layer to speed-up things -function SQL_DEBUG_ENABLED () { +function isSqlDebugEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it @@ -3348,5 +3447,146 @@ function wrapWords ($text) { return $wrapped; } +// Encodes given data into a JSON object +function encodeJson ($data) { + // Encode it + return json_encode($data, JSON_FORCE_OBJECT); +} + +// Get all extension files +function loadAllExtensionsByTemplate () { + // Get all + $extensions = getArrayFromDirectory( + 'templates/' . getLanguage() . '/html/ext/', + 'ext_', + false, + false, + array(), + '.tpl', + '@(\.|\.\.)$@', + false + ); + + // Return them + return $extensions; +} + +// Wrapper function to allow full float values as supported by current database layout +function translateFullComma ($dotted) { + // Call inner function + return translateComma($dotted, TRUE, 5); +} + +// Wrapper to check if the first element to be shifted is set to given value +function shift_array (&$array, $value, $key = '0') { + // Is the element set and value matches? + assert(is_array($array)); + assert(isset($array[$key])); + assert($array[$key] === $value); + + // Shift it + array_shift($array); +} + +// Wrapper for str_pad() with left padding zeros +function padLeftZero ($str, $amount = 2) { + // Is str_pad() there? + if (!function_exists('str_pad')) { + // Use prependZeros() + return prependZeros($str, $amount); + } else { + // Pad it + return str_pad($str, $amount, '0', STR_PAD_LEFT); + } +} + +// Calculates percentage +function calculatePercentageRate ($current, $total) { + // Default is zero + $rate = '0.0'; + + // Is sent larger zero? (Prevents division-by-zero) + if ($total > 0) { + // Calculate it (it should be "translated" alter on) + $rate = ($current / $total * 100); + } // END - if + + // The should be a .0 at the end? + if (strpos($rate, '.') === FALSE) { + // No, then add it + $rate .= '.0'; + } // END - if + + // Return it + return $rate; +} + +// Checks whether an array is filled with entries +function isFilledArray ($array) { + // Determine it + return ((is_array($array)) && (count($array) > 0)); +} + +// Checks whether this script runs on a developer system (called with localhost/127.0.0.1 SERVER_NAME) +function isDeveloperSystem () { + // Determine it + return in_array(detectServerName(), array('localhost', '127.0.0.1')); +} + +// Checks whether given subject line has '_ref' suffix +function ifSubjectHasReferralSuffix ($subject) { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__][$subject])) { + // Determine it + $GLOBALS[__FUNCTION__][$subject] = (substr($subject, -4, 4) == '_ref'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__][$subject]; +} + +// Converts an API response to an associative array +function convertApiResponseToArray ($responseString, $keyDelimiter, $valueDelimiter) { + // Explode for key delimiter + $keys = explode($keyDelimiter, $responseString); + + // Init returned array and "walk" through all entries + $returned = array(); + foreach ($keys as $keyValue) { + // Explode it + $parts = explode($valueDelimiter, $keyValue); + + // Count must be 2 + assert(count($parts) == 2); + + // Then add both: 0=key, 1=value + $returned[sqlEscapeString($parts[0])] = sqlEscapeString($parts[1]); + } // END - if + + // Return finished array + return $returned; +} + +// Getter for full (generic) hash file name +function getGenericHashFileName () { + // Return result + return sprintf('%s%s.%s%s', getPath(), getCachePath(), getFileHash(), getCacheExtension()); +} + +// "Compiles" the given value and sets it in given key +function setSessionCompiled ($key, $value) { + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key[]=' . gettype($key) . ',value[]=' . gettype($value)); + + // Is the value not an array? + if (!is_array($value)) { + // "Compile" the value + $value = doFinalCompilation(compileRawCode($value)); + } // END - if + + // And set it + return setSession($key, $value); +} + // [EOF] ?>