X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fwrapper-functions.php;h=89b6ed3c7688cc10fbbeb078a49ad81d26d7a6e3;hp=1a9c6847a5f36054484ab583221b6739cdb151f4;hb=e5527fd38a6585c8466dc28d013f12d21eb7c07a;hpb=24462b1347471350179b20a64f91a864deeb1df0 diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 1a9c6847a5..89b6ed3c76 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 * @@ -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 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 +88,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 +157,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 +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 @@ -326,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') || ((isGetRequestElementSet('level')) && (getRequestElement('level') == 'install'))); + $GLOBALS['__mailer_installing'] = (isGetRequestElementSet('installing') || ((isAjaxOutputMode()) && (isGetRequestElementSet('level')) && (getRequestElement('level') == 'install'))); } // END - if // Return result @@ -407,10 +406,16 @@ function isMonthlyResetEnabled () { 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 ((isHourlyResetEnabled()) || (isDailyResetEnabled()) || (isWeeklyResetEnabled()) || (isMonthlyResetEnabled())); + return ((isHourlyResetEnabled()) || (isDailyResetEnabled()) || (isWeeklyResetEnabled()) || (isMonthlyResetEnabled()) || (isYearlyResetEnabled())); } // Checks whether the debug mode is enabled @@ -473,6 +478,18 @@ function isDebugMonthlyEnabled () { 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 + return $GLOBALS[__FUNCTION__]; +} + // Checks whether SQL debugging is enabled function isSqlDebuggingEnabled () { // Is cache set? @@ -510,7 +527,7 @@ function isDebugBuildMailsEnabled () { } // Checks whether the cache instance is valid -function isCacheInstanceValid () { +function isValidCacheInstance () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it @@ -812,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 @@ -892,7 +909,7 @@ function getUsername () { } // Wrapper function for installation phase -function isInstallationPhase () { +function isInstaller () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it @@ -1068,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 @@ -1158,7 +1175,7 @@ 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 @@ -1378,7 +1395,7 @@ function isValidId ($id) { // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$id])) { // Check it out - $GLOBALS[__FUNCTION__][$id] = ((!is_null($id)) && (!is_bool($id)) && (!empty($id)) && ($id != 'NULL') && ($id > 0)); + $GLOBALS[__FUNCTION__][$id] = ((isValidNumber($id)) && (!is_bool($id)) && ($id != '00000') && ($id > 0)); } // END - if // Return cache @@ -1386,6 +1403,12 @@ function isValidId ($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 function encodeEntities ($str) { // Secure it first @@ -1571,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 @@ -1614,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')) && (getDisplayDebugSqls() == 'Y')); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (isConfigEntrySet('display_debug_sql')) && (getDisplayDebugSqls() == 'Y')); } // END - if // Return cache @@ -1631,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 @@ -1643,7 +1678,7 @@ 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 @@ -1679,7 +1714,7 @@ function isAdminNotificationEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.3.0')) && (getAdminNotify() == 'Y')); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.3.0')) && (isConfigEntrySet('admin_notify')) && (getAdminNotify() == 'Y')); } // END - if // Return cache @@ -1691,7 +1726,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 @@ -2249,12 +2284,24 @@ function getCodeLength () { return $GLOBALS[__FUNCTION__]; } -// "Getter" for pass_len -function getPassLen () { +// "Getter" for min_password_length +function getMinPasswordLength () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('min_password_length'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// "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 @@ -2321,6 +2368,18 @@ function getLastMonthly () { 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 + return $GLOBALS[__FUNCTION__]; +} + // "Getter" for mails_page function getMailsPage () { // Is there cache? @@ -2542,7 +2601,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 @@ -2566,7 +2625,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 @@ -2590,7 +2649,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 @@ -2614,7 +2673,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 @@ -2782,7 +2841,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 @@ -2851,7 +2910,7 @@ 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 @@ -2863,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 @@ -2988,9 +3047,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); @@ -3335,7 +3394,7 @@ function getUsersTotalLockedReferrals ($userid, $level = NULL) { } // END - if // Check for all referrals - $result = SQL_QUERY_ESC("SELECT + $result = sqlQueryEscaped("SELECT COUNT(`d`.`userid`) AS `cnt` FROM `{?_MYSQL_PREFIX?}_user_data` AS `d` @@ -3355,10 +3414,10 @@ LIMIT 1", ), __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 @@ -3379,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 @@ -3452,5 +3511,50 @@ function padLeftZero ($str, $amount = 2) { } } +// 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]; +} + // [EOF] ?>