From: Roland Häder Date: Tue, 29 Jun 2010 04:48:58 +0000 (+0000) Subject: Caching of expensive PHP functions: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8d4176053d397a86baca20b4d7ab7ed526355be8;p=mailer.git Caching of expensive PHP functions: - date() calls are now wrapped and cached - translateYesNo() is now cached (will follow more) - TODOs.txt updated --- diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index 3f3a06d860..5953193f64 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -42,12 +42,12 @@ ./inc/extensions-functions.php:428:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) ) ./inc/extensions-functions.php:544: // @TODO Extension is loaded, what next? ./inc/functions.php:115: // @TODO Extension 'msg' does not exist -./inc/functions.php:1460: // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ? -./inc/functions.php:1483: // @TODO Rewrite this old lost code to a template -./inc/functions.php:1551: // @TODO Are these convertions still required? -./inc/functions.php:1569:// @TODO Rewrite this function to use readFromFile() and writeToFile() +./inc/functions.php:1482: // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ? +./inc/functions.php:1505: // @TODO Rewrite this old lost code to a template +./inc/functions.php:1573: // @TODO Are these convertions still required? +./inc/functions.php:1591:// @TODO Rewrite this function to use readFromFile() and writeToFile() ./inc/functions.php:178:// @TODO Rewrite this to an extension 'smtp' -./inc/functions.php:2222: // @TODO This is still very static, rewrite it somehow +./inc/functions.php:2244: // @TODO This is still very static, rewrite it somehow ./inc/install-functions.php:63: // @TODO DEACTIVATED: changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0); ./inc/language/de.php:1141:// @TODO Rewrite these two constants ./inc/language/de.php:1156:// @TODO Rewrite these three constants @@ -174,10 +174,10 @@ ./inc/modules/member/what-unconfirmed.php:143: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() ./inc/modules/order.php:76: // @TODO Unused: 2,4 ./inc/monthly/monthly_bonus.php:69: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1630: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() -./inc/mysql-manager.php:1730: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:2110: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:2154:// @TODO Fix inconsistency between last_module and getWhat() +./inc/mysql-manager.php:1629: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() +./inc/mysql-manager.php:1729: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:2109: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:2153:// @TODO Fix inconsistency between last_module and getWhat() ./inc/mysql-manager.php:229: // @TODO Nothing helped??? ./inc/mysql-manager.php:264: // @TODO Rewrite this to a filter ./inc/mysql-manager.php:589: // @TODO Try to rewrite this to one or more functions diff --git a/inc/config-local.php.dist b/inc/config-local.php.dist index 5b4f26f088..9b17267c11 100644 --- a/inc/config-local.php.dist +++ b/inc/config-local.php.dist @@ -50,7 +50,7 @@ if (!defined('__SECURITY')) { setConfigEntry('SITE_KEY', ''); // CFG: DATE-KEY -setConfigEntry('DATE_KEY', date('d-m-Y (l-F-T)', time())); +setConfigEntry('DATE_KEY', generateDateTime(time(), '5')); // CFG: DEFAULT-LANGUAGE setConfigEntry('DEFAULT_LANG', 'de'); diff --git a/inc/extensions/ext-bonus.php b/inc/extensions/ext-bonus.php index 928b9c29f4..f9d1b1241d 100644 --- a/inc/extensions/ext-bonus.php +++ b/inc/extensions/ext-bonus.php @@ -354,12 +354,12 @@ INDEX `userid` (`userid`) case '0.5.6': // SQL queries for v0.5.6 // Get current month - $curr = date('m', time()); + $curr = getMonth(); if (strlen($curr) == 1) $curr = '0' . $curr; - if ($curr == "00") $curr = "12"; + if ($curr == '00') $curr = '12'; // Generate timemark... - $mark = mktime(0, 0, 0, $curr, 1, date('Y', time())); + $mark = mktime(0, 0, 0, $curr, 1, getYear()); // Update accounts which are not active last months addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_user_data` diff --git a/inc/filters.php b/inc/filters.php index 9a3b441a7a..2a099fe802 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -548,7 +548,7 @@ function FILTER_RUN_RESET_INCLUDES () { // Is the config entry set? if (isExtensionInstalledAndNewer('sql_patches', '0.4.2')) { // Create current week mark - $currWeek = date('W', time()); + $currWeek = getWeek(); // Has it changed? if ((getConfig('last_week') != $currWeek) || ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'))) { @@ -560,7 +560,7 @@ function FILTER_RUN_RESET_INCLUDES () { } // END - if // Create current month mark - $currMonth = date('m', time()); + $currMonth = getMonth(); // Has it changed? if ((getConfig('last_month') != $currMonth) || ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'))) { @@ -708,7 +708,7 @@ function FILTER_RUN_DAILY_RESET () { if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalled('sql_patches'))) return; // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D - if (((date('d', getConfig('last_update')) != date('d', time())) || ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'))) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestParameterSet('register')) && (getOutputMode() != 1)) { + if (((getDay(getConfig('last_update')) != getDay()) || ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'))) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestParameterSet('register')) && (getOutputMode() != 1)) { // Tell every module we are in reset-mode! doReset(); } // END - if diff --git a/inc/functions.php b/inc/functions.php index 90dbe1d5e6..e1b5a9ca36 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -275,15 +275,22 @@ function generatePassword ($length = '0') { // Generates a human-readable timestamp from the Uni* stamp function generateDateTime ($time, $mode = '0') { - // Filter out numbers - $time = bigintval($time); - // If the stamp is zero it mostly didn't "happen" if ($time == '0') { // Never happend return '{--NEVER_HAPPENED--}'; } // END - if + // Filter out numbers + $time = bigintval($time); + + // Is it cached? + if (isset($GLOBALS[__FUNCTION__][$time][$mode])) { + // Then use it + return $GLOBALS[__FUNCTION__][$time][$mode]; + } // END - if + + // Detect language switch (getLanguage()) { case 'de': // German date / time format switch ($mode) { @@ -291,6 +298,9 @@ function generateDateTime ($time, $mode = '0') { case '1': $ret = strtolower(date('d.m.Y - H:i', $time)); break; case '2': $ret = date('d.m.Y|H:i', $time); break; case '3': $ret = date('d.m.Y', $time); break; + case '4': $ret = date('d.m.Y|H:i:s', $time); break; + case '5': $ret = date('d-m-Y (l-F-T)', $time); break; + case '6': $ret = date('Ymd', $time); break; default: logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode)); break; @@ -300,34 +310,43 @@ function generateDateTime ($time, $mode = '0') { default: // Default is the US date / time format! switch ($mode) { case '0': $ret = date('r', $time); break; - case '1': $ret = date('Y-m-d - g:i A', $time); break; + case '1': $ret = strtolower(date('Y-m-d - g:i A', $time)); break; case '2': $ret = date('y-m-d|H:i', $time); break; case '3': $ret = date('y-m-d', $time); break; + case '4': $ret = date('d.m.Y|H:i:s', $time); break; + case '5': $ret = date('d-m-Y (l-F-T)', $time); break; + case '6': $ret = date('Ymd', $time); break; default: logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode)); break; } // END - switch } // END - switch + // Store it in cache + $GLOBALS[__FUNCTION__][$time][$mode] = $ret; + // Return result return $ret; } // Translates Y/N to yes/no function translateYesNo ($yn) { - // Default - $translated = '??? (' . $yn . ')'; - switch ($yn) { - case 'Y': $translated = '{--YES--}'; break; - case 'N': $translated = '{--NO--}'; break; - default: - // Log unknown value - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected Y/N!", $yn)); - break; - } // END - switch + // Is it cached? + if (!isset($GLOBALS[__FUNCTION__][$yn])) { + // Default + $GLOBALS[__FUNCTION__][$yn] = '??? (' . $yn . ')'; + switch ($yn) { + case 'Y': $GLOBALS[__FUNCTION__][$yn] = '{--YES--}'; break; + case 'N': $GLOBALS[__FUNCTION__][$yn] = '{--NO--}'; break; + default: + // Log unknown value + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected Y/N!", $yn)); + break; + } // END - switch + } // END - if // Return it - return $translated; + return $GLOBALS[__FUNCTION__][$yn]; } // Translates the "pool type" into human-readable @@ -498,9 +517,9 @@ function countSelection ($array) { // Generates a timestamp (some wrapper for mktime()) function makeTime ($hours, $minutes, $seconds, $stamp) { // Extract day, month and year from given timestamp - $days = date('d', $stamp); - $months = date('m', $stamp); - $years = date('Y', $stamp); + $days = getDay($stamp); + $months = getMonth($stamp); + $years = getYear($stamp); // Create timestamp for wished time which depends on extracted date return mktime( @@ -632,7 +651,7 @@ function generateRandomCode ($length, $code, $userid, $DATA = '') { $keys = getConfig('SITE_KEY') . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY'); if (isConfigEntrySet('secret_key')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('secret_key'); if (isConfigEntrySet('file_hash')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('file_hash'); - $keys .= getConfig('ENCRYPT_SEPERATOR') . date('d-m-Y (l-F-T)', getConfig('patch_ctime')); + $keys .= getConfig('ENCRYPT_SEPERATOR') . getDateFromPatchTime(); if (isConfigEntrySet('master_salt')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('master_salt'); // Build string from misc data @@ -701,8 +720,8 @@ function createTimestampFromSelections ($prefix, $postData) { // Do we have a leap year? $SWITCH = '0'; - $TEST = date('Y', time()) / 4; - $M1 = date('m', time()); + $TEST = getYear() / 4; + $M1 = getMonth(); // If so and if current time is before 02/29 and estimated time is after 02/29 then add 86400 seconds (one day) if ((floor($TEST) == $TEST) && ($M1 == '02') && ($postData[$prefix . '_mo'] > '02')) $SWITCH = getConfig('ONE_DAY'); @@ -1132,7 +1151,7 @@ function generateHash ($plainText, $salt = '', $hash = true) { $server = $_SERVER['PHP_SELF'] . getConfig('ENCRYPT_SEPERATOR') . detectUserAgent() . getConfig('ENCRYPT_SEPERATOR') . getenv('SERVER_SOFTWARE') . getConfig('ENCRYPT_SEPERATOR') . detectRemoteAddr(); // Build key string - $keys = getConfig('SITE_KEY') . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY') . getConfig('ENCRYPT_SEPERATOR') . getConfig('secret_key') . getConfig('ENCRYPT_SEPERATOR') . getConfig('file_hash') . getConfig('ENCRYPT_SEPERATOR') . date('d-m-Y (l-F-T)', getConfig('patch_ctime')) . getConfig('ENCRYPT_SEPERATOR') . getConfig('master_salt'); + $keys = getConfig('SITE_KEY') . getConfig('ENCRYPT_SEPERATOR') . getConfig('DATE_KEY') . getConfig('ENCRYPT_SEPERATOR') . getConfig('secret_key') . getConfig('ENCRYPT_SEPERATOR') . getConfig('file_hash') . getConfig('ENCRYPT_SEPERATOR') . getDateFromPatchTime() . getConfig('ENCRYPT_SEPERATOR') . getConfig('master_salt'); // Additional data $data = $plainText . getConfig('ENCRYPT_SEPERATOR') . uniqid(mt_rand(), true) . getConfig('ENCRYPT_SEPERATOR') . time(); @@ -1664,7 +1683,7 @@ function logDebugMessage ($funcFile, $line, $message, $force=true) { // Log this message away $fp = fopen(getConfig('CACHE_PATH') . 'debug.log', 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write logfile debug.log!'); - fwrite($fp, date('d.m.Y|H:i:s', time()) . '|' . getModule(false) . '|' . basename($funcFile) . '|' . $line . '|' . $message . "\n"); + fwrite($fp, generateDateTime(time(), '4') . '|' . getModule(false) . '|' . basename($funcFile) . '|' . $line . '|' . $message . "\n"); fclose($fp); } // END - if } diff --git a/inc/mails/beg_mails.php b/inc/mails/beg_mails.php index 29d9c589c5..148404fff0 100644 --- a/inc/mails/beg_mails.php +++ b/inc/mails/beg_mails.php @@ -48,7 +48,7 @@ if (!defined('__SECURITY')) { if (getOutputMode() != 0) return; // Create timemark from saved month -$mark = mktime(0, 0, 0, getConfig('last_month'), date('d', time()), date('Y', time())); +$mark = mktime(0, 0, 0, getConfig('last_month'), getDay(), getYear()); $sql = ''; $mode = ''; // Shall I sent activation or deactivation mail? diff --git a/inc/mails/bonus_mails.php b/inc/mails/bonus_mails.php index ce784a4652..84f30688dc 100644 --- a/inc/mails/bonus_mails.php +++ b/inc/mails/bonus_mails.php @@ -48,7 +48,7 @@ if (!defined('__SECURITY')) { if (getOutputMode() != 0) return; // Create timemark from saved month -$mark = mktime(0, 0, 0, getConfig('last_month'), date('d', time()), date('Y', time())); +$mark = mktime(0, 0, 0, getConfig('last_month'), getDay(), getYear()); $sql = ''; $mode = ''; // Shall I sent activation or deactivation mail? diff --git a/inc/modules/admin/what-add_rallye.php b/inc/modules/admin/what-add_rallye.php index 9b57ec31f3..d276330b9e 100644 --- a/inc/modules/admin/what-add_rallye.php +++ b/inc/modules/admin/what-add_rallye.php @@ -98,25 +98,23 @@ $content['active_options'] = generateOptionList('/ARRAY/', array('N','Y'), arr $content['notify_options'] = generateOptionList('/ARRAY/', array('Y','N'), array('{--YES--}', '{--NO--}' )); // Starting day -$content['start_sec'] = addSelectionBox('sec' , 0 , 'start'); -$content['start_min'] = addSelectionBox('min' , 0 , 'start'); -$content['start_hour'] = addSelectionBox('hour' , date('G', time()), 'start'); -$content['start_day'] = addSelectionBox('day' , date('d', time()), 'start'); -$content['start_month'] = addSelectionBox('month', date('m', time()), 'start'); -$content['start_year'] = addSelectionBox('year' , date('Y', time()), 'start'); +$content['start_sec'] = addSelectionBox('sec' , 0 , 'start'); +$content['start_min'] = addSelectionBox('min' , 0 , 'start'); +$content['start_hour'] = addSelectionBox('hour' , getShortHour() , 'start'); +$content['start_day'] = addSelectionBox('day' , getDay() , 'start'); +$content['start_month'] = addSelectionBox('month', getMonth() , 'start'); +$content['start_year'] = addSelectionBox('year' , getYear() , 'start'); -// Calcualte ending date -$D = date('d', time() + (getConfig('ONE_DAY') * 7)); -$M = date('m', time() + (getConfig('ONE_DAY') * 7)); -$Y = date('Y', time() + (getConfig('ONE_DAY') * 7)); +// Ending timestamp +$endingStamp = time() + (getConfig('ONE_DAY') * 7); // Ending day -$content['end_sec'] = addSelectionBox('sec' , 0 , 'end'); -$content['end_min'] = addSelectionBox('min' , 0 , 'end'); -$content['end_hour'] = addSelectionBox('hour' , date('G', time()), 'end'); -$content['end_day'] = addSelectionBox('day' , $D , 'end'); -$content['end_month'] = addSelectionBox('month', $M , 'end'); -$content['end_year'] = addSelectionBox('year' , $Y , 'end'); +$content['end_sec'] = addSelectionBox('sec' , 0 , 'end'); +$content['end_min'] = addSelectionBox('min' , 0 , 'end'); +$content['end_hour'] = addSelectionBox('hour' , getShortHour() , 'end'); +$content['end_day'] = addSelectionBox('day' , getDay($endingStamp) , 'end'); +$content['end_month'] = addSelectionBox('month', getMonth($endingStamp), 'end'); +$content['end_year'] = addSelectionBox('year' , getYear($endingStamp) , 'end'); // Transfer (maybe found) templates into constant for the template $content['templates_selection'] = addReferalRallyeTemplateSelection(); diff --git a/inc/modules/admin/what-config_mediadata.php b/inc/modules/admin/what-config_mediadata.php index dbacb56b84..7b87200ab3 100644 --- a/inc/modules/admin/what-config_mediadata.php +++ b/inc/modules/admin/what-config_mediadata.php @@ -80,8 +80,8 @@ if (isFormSent()) { } else { // Make start editable $content['mt_start'] = - addSelectionBox('day' , date('d', time())). - addSelectionBox('month', date('m', time())). + addSelectionBox('day' , getDay()). + addSelectionBox('month', getMonth()). addSelectionBox('year', -1) ; } diff --git a/inc/modules/admin/what-list_beg.php b/inc/modules/admin/what-list_beg.php index 5504a22b3d..f098de3f1c 100644 --- a/inc/modules/admin/what-list_beg.php +++ b/inc/modules/admin/what-list_beg.php @@ -49,7 +49,7 @@ if (getConfig('beg_rallye') == 'Y') { // Shall I withdraw now? if (isPostRequestParameterSet('withdraw')) { // Okay, let's prepare... - $curr = date('m', time()) - 1; + $curr = getMonth() - 1; if (strlen($curr) == 1) $curr = '0' . $curr; updateConfiguration('last_month', $curr); loadTemplate('admin_settings_saved', false, '{--ADMIN_BEG_WITHDRAW_PREPARED--}'); @@ -108,7 +108,7 @@ ORDER BY $content['total'] = translateComma($total); // Check if we need to display form or not with manuel withdraw - if (getConfig('last_month') == date('m', time())) { + if (getConfig('last_month') == getMonth()) { // Load form $content['withdraw_form'] = loadTemplate('admin_list_beg_form', true); } else { diff --git a/inc/modules/admin/what-list_bonus.php b/inc/modules/admin/what-list_bonus.php index 5b295dd7e5..83c96f2799 100644 --- a/inc/modules/admin/what-list_bonus.php +++ b/inc/modules/admin/what-list_bonus.php @@ -49,7 +49,7 @@ if (getConfig('bonus_active') == 'Y') { // Shall I withdraw now? if (isPostRequestParameterSet('withdraw')) { // Okay, let's prepare... - $curr = date('m', time()) - 1; + $curr = getMonth() - 1; if (strlen($curr) == 1) $curr = '0' . $curr; updateConfiguration('last_month', $curr); loadTemplate('admin_settings_saved', false, '{--ADMIN_BONUS_WITHDRAW_PREPARED--}'); @@ -122,7 +122,7 @@ ORDER BY $content['total'] = translateComma($total); // Check if we need to display form or not with manuel withdraw - if (getConfig('last_month') == date('m', time())) { + if (getConfig('last_month') == getMonth()) { // Load form $content['withdraw_form'] = loadTemplate('admin_list_bonus_form', true); } else { diff --git a/inc/modules/admin/what-list_rallyes.php b/inc/modules/admin/what-list_rallyes.php index 76bdd3eb33..65cf9f270d 100644 --- a/inc/modules/admin/what-list_rallyes.php +++ b/inc/modules/admin/what-list_rallyes.php @@ -199,20 +199,20 @@ LIMIT 1", SQL_FREERESULT($result); // Starting day - $content['s_sec'] = addSelectionBox('sec' , date('s', $content['start_time']), 'start', $id); - $content['s_min'] = addSelectionBox('min' , date('i', $content['start_time']), 'start', $id); - $content['s_hour'] = addSelectionBox('hour' , date('G', $content['start_time']), 'start', $id); - $content['s_day'] = addSelectionBox('day' , date('d', $content['start_time']), 'start', $id); - $content['s_month'] = addSelectionBox('month', date('m', $content['start_time']), 'start', $id); - $content['s_year'] = addSelectionBox('year' , date('Y', $content['start_time']), 'start', $id); + $content['s_sec'] = addSelectionBox('sec' , getSecond($content['start_time']) , 'start', $id); + $content['s_min'] = addSelectionBox('min' , getMinute($content['start_time']) , 'start', $id); + $content['s_hour'] = addSelectionBox('hour' , getShortHour($content['start_time']), 'start', $id); + $content['s_day'] = addSelectionBox('day' , getDay($content['start_time']) , 'start', $id); + $content['s_month'] = addSelectionBox('month', getMonth($content['start_time']) , 'start', $id); + $content['s_year'] = addSelectionBox('year' , getYear($content['start_time']) , 'start', $id); // Ending day - $content['e_sec'] = addSelectionBox('sec' , date('s', $content['end_time']) , 'end' , $id); - $content['e_min'] = addSelectionBox('min' , date('i', $content['end_time']) , 'end' , $id); - $content['e_hour'] = addSelectionBox('hour' , date('G', $content['end_time']) , 'end' , $id); - $content['e_day'] = addSelectionBox('day' , date('d', $content['end_time']) , 'end' , $id); - $content['e_month'] = addSelectionBox('month', date('m', $content['end_time']) , 'end' , $id); - $content['e_year'] = addSelectionBox('year' , date('Y', $content['end_time']) , 'end' , $id); + $content['e_sec'] = addSelectionBox('sec' , getSecond($content['end_time']) , 'end' , $id); + $content['e_min'] = addSelectionBox('min' , getMinute($content['end_time']) , 'end' , $id); + $content['e_hour'] = addSelectionBox('hour' , getShortHour($content['end_time']) , 'end' , $id); + $content['e_day'] = addSelectionBox('day' , getDay($content['end_time']) , 'end' , $id); + $content['e_month'] = addSelectionBox('month', getMonth($content['end_time']) , 'end' , $id); + $content['e_year'] = addSelectionBox('year' , getYear($content['end_time']) , 'end' , $id); // Remember other values $content['templ'] = addReferalRallyeTemplateSelection('templ['.$id.']', $content['template']); diff --git a/inc/modules/member/what-holiday.php b/inc/modules/member/what-holiday.php index ef2b99b8f4..d22688bea8 100644 --- a/inc/modules/member/what-holiday.php +++ b/inc/modules/member/what-holiday.php @@ -293,20 +293,19 @@ LIMIT 1", array(getMemberId()), __FILE__, __LINE__); break; case 'N': // Display activation form - // Starting day - $content['start_day'] = addSelectionBox('day' , date('d', (time() + getConfig('ONE_DAY'))), 'start'); - $content['start_month'] = addSelectionBox('month', date('m', (time() + getConfig('ONE_DAY'))), 'start'); - $content['start_year'] = addSelectionBox('year' , date('Y', (time() + getConfig('ONE_DAY'))), 'start'); + // Cache timestamps + $startingStamp = time() + getConfig('ONE_DAY'); + $endingStamp = $startingStamp + (getConfig('ONE_DAY') * getConfig('holiday_max'); - // Calcualte ending date - $D = date('d', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max'))); - $M = date('m', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max'))); - $Y = date('Y', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max'))); + // Starting day + $content['start_day'] = addSelectionBox('day' , getDay($startingStamp) , 'start'); + $content['start_month'] = addSelectionBox('month', getMonth($startingStamp), 'start'); + $content['start_year'] = addSelectionBox('year' , getYear($startingStamp) , 'start'); // Ending day - $content['end_day'] = addSelectionBox('day' , $D, 'end'); - $content['end_month'] = addSelectionBox('month', $M, 'end'); - $content['end_year'] = addSelectionBox('year' , $Y, 'end'); + $content['end_day'] = addSelectionBox('day' , getDay($endingStamp) , 'end'); + $content['end_month'] = addSelectionBox('month', getMonth($endingStamp), 'end'); + $content['end_year'] = addSelectionBox('year' , getYear($endingStamp) , 'end'); // Output form loadTemplate('member_holiday_form', false, $content); diff --git a/inc/monthly/monthly_beg.php b/inc/monthly/monthly_beg.php index a509f4d834..63440b567a 100644 --- a/inc/monthly/monthly_beg.php +++ b/inc/monthly/monthly_beg.php @@ -49,7 +49,7 @@ if (!defined('__SECURITY')) { } // Get current month (2 digits) -$curr = date('m', time()); +$curr = getMonth(); // Check if month is done if (($curr != getConfig('last_month')) && (getConfig('last_month') > 0) && (getConfig('beg_ranks') > 0) && (getOutputMode() != 1)) { diff --git a/inc/monthly/monthly_bonus.php b/inc/monthly/monthly_bonus.php index 500f9f23d4..cb010de05e 100644 --- a/inc/monthly/monthly_bonus.php +++ b/inc/monthly/monthly_bonus.php @@ -49,7 +49,7 @@ if (!defined('__SECURITY')) { } // Get current month (2 digits) -$curr = date('m', time()); +$curr = getMonth(); if (($curr != getConfig('last_month')) && (getConfig('bonus_ranks') > 0) && (getOutputMode() != 1)) { // Extension 'autopurge' is inactive or purging of inactive accounts is deactivated diff --git a/inc/reset/reset_birthday.php b/inc/reset/reset_birthday.php index fb45557875..2ca54a1cbe 100644 --- a/inc/reset/reset_birthday.php +++ b/inc/reset/reset_birthday.php @@ -49,9 +49,9 @@ if (!defined('__SECURITY')) { } // Get current day (01 to 31), month (01 to 12) and year (4-digits year) -$day = date('d', time()); -$month = date('m', time()); -$year = date('Y', time()); +$day = getDay(); +$month = getMonth(); +$year = getYear(); // Shall I include only active members? $add = '%s'; $value = ''; diff --git a/inc/stats-functions.php b/inc/stats-functions.php index 79cc70549b..338f3b833a 100644 --- a/inc/stats-functions.php +++ b/inc/stats-functions.php @@ -111,7 +111,7 @@ function loadStatsTable () { // Load it from database $result = SQL_QUERY_ESC("SELECT `stats_entry`,`stats_value` FROM `{?_MYSQL_PREFIX?}_stats_%s` ORDER BY `stats_entry` ASC", - array(date('Ymd', time())), __FUNCTION__, __LINE__); + array(generateDateTime(time(), '6')), __FUNCTION__, __LINE__); // Read all rows while ($row = SQL_FETCHARRAY($result)) { @@ -129,7 +129,7 @@ function isStatsTableCreated () { // Ask for it $result = SQL_QUERY_ESC("SHOW TABLES LIKE '{?_MYSQL_PREFIX?}_stats_%s'", - array(date('Ymd', time())), __FUNCTION__, __LINE__); + array(generateDateTime(time(), '6')), __FUNCTION__, __LINE__); // Do we have a row? return SQL_NUMROWS($result); @@ -146,7 +146,7 @@ function createStatsTable () { `stats_value` BIGINT(20) NOT NULL DEFAULT 0, PRIMARY KEY (`stats_entry`) ) TYPE=HEAP COMMENT='Temporary statistics table'", - array(date('Ymd', time())), __FUNCTION__, __LINE__); + array(generateDateTime(time(), '6')), __FUNCTION__, __LINE__); } // Write all entries to the table @@ -156,11 +156,11 @@ function writeStatsTable () { // Empty the table first SQL_QUERY_ESC("TRUNCATE `{?_MYSQL_PREFIX?}_stats_%s`", - array(date('Ymd', time())), __FUNCTION__, __LINE__); + array(generateDateTime(time(), '6')), __FUNCTION__, __LINE__); // Begin the SQL command $sql = sprintf("REPLACE INTO `{?_MYSQL_PREFIX?}_stats_%s` (`stats_entry`,`stats_value`) VALUES ", - date('Ymd', time())); + generateDateTime(time(), '6')); // Add all entries to the final query foreach ($GLOBALS['stats'] as $entry => $value) { diff --git a/inc/template-functions.php b/inc/template-functions.php index cf0b136f4d..c3ecb57834 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -704,7 +704,7 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're case 'year': // Year // Get current year - $year = date('Y', time()); + $year = getYear(); // Use configured min age or fixed? if (isExtensionInstalledAndNewer('order', '0.2.1')) { @@ -736,10 +736,10 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're // Calculate earliest year depending on extension version if (isExtensionInstalledAndNewer('order', '0.2.1')) { // Use configured minimum age - $year = date('Y', time()) - getConfig('min_age'); + $year = getYear() - getConfig('min_age'); } else { // Use fixed 16 years age - $year = date('Y', time()) - 16; + $year = getYear() - 16; } // Construct year selection list @@ -856,9 +856,9 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = // Do we have a leap year? $SWITCH = '0'; - $TEST = date('Y', time()) / 4; - $M1 = date('m', time()); - $M2 = date('m', (time() + $timestamp)); + $TEST = getYear() / 4; + $M1 = getMonth(); + $M2 = getMonth(time() + $timestamp); // If so and if current time is before 02/29 and estimated time is after 02/29 then add 86400 seconds (one day) if ((floor($TEST) == $TEST) && ($M1 == '02') && ($M2 > '02')) $SWITCH = getConfig('ONE_DAY'); diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index dee0ad81ac..6fc935bd28 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -1036,5 +1036,137 @@ function encodeEntities ($str) { return $str; } +// "Getter" for date from patch_ctime +function getDateFromPatchTime () { + // Is it cached? + if (!isset($GLOBALS[__FUNCTION__])) { + // Then set it + $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + +// Getter for current year (default) +function getYear ($timestamp = null) { + // Is it cached? + if (!isset($GLOBALS['year'][$timestamp])) { + // null is time() + if (is_null($timestamp)) $timestamp = time(); + + // Then create it + $GLOBALS['year'][$timestamp] = date('Y', $timestamp); + } // END - if + + // Return cache + return $GLOBALS['year'][$timestamp]; +} + +// Getter for current month (default) +function getMonth ($timestamp = null) { + // Is it cached? + if (!isset($GLOBALS['month'][$timestamp])) { + // null is time() + if (is_null($timestamp)) $timestamp = time(); + + // Then create it + $GLOBALS['month'][$timestamp] = date('m', $timestamp); + } // END - if + + // Return cache + return $GLOBALS['month'][$timestamp]; +} + +// Getter for current day (default) +function getDay ($timestamp = null) { + // Is it cached? + if (!isset($GLOBALS['day'][$timestamp])) { + // null is time() + if (is_null($timestamp)) $timestamp = time(); + + // Then create it + $GLOBALS['day'][$timestamp] = date('d', $timestamp); + } // END - if + + // Return cache + return $GLOBALS['day'][$timestamp]; +} + +// Getter for current week (default) +function getWeek ($timestamp = null) { + // Is it cached? + if (!isset($GLOBALS['week'][$timestamp])) { + // null is time() + if (is_null($timestamp)) $timestamp = time(); + + // Then create it + $GLOBALS['week'][$timestamp] = date('W', $timestamp); + } // END - if + + // Return cache + return $GLOBALS['week'][$timestamp]; +} + +// Getter for current short_hour (default) +function getShortHour ($timestamp = null) { + // Is it cached? + if (!isset($GLOBALS['short_hour'][$timestamp])) { + // null is time() + if (is_null($timestamp)) $timestamp = time(); + + // Then create it + $GLOBALS['short_hour'][$timestamp] = date('G', $timestamp); + } // END - if + + // Return cache + return $GLOBALS['short_hour'][$timestamp]; +} + +// Getter for current long_hour (default) +function getLongHour ($timestamp = null) { + // Is it cached? + if (!isset($GLOBALS['long_hour'][$timestamp])) { + // null is time() + if (is_null($timestamp)) $timestamp = time(); + + // Then create it + $GLOBALS['long_hour'][$timestamp] = date('H', $timestamp); + } // END - if + + // Return cache + return $GLOBALS['long_hour'][$timestamp]; +} + +// Getter for current second (default) +function getSecond ($timestamp = null) { + // Is it cached? + if (!isset($GLOBALS['second'][$timestamp])) { + // null is time() + if (is_null($timestamp)) $timestamp = time(); + + // Then create it + $GLOBALS['second'][$timestamp] = date('s', $timestamp); + } // END - if + + // Return cache + return $GLOBALS['second'][$timestamp]; +} + +// Getter for current minute (default) +function getMinute ($timestamp = null) { + // Is it cached? + if (!isset($GLOBALS['minute'][$timestamp])) { + // null is time() + if (is_null($timestamp)) $timestamp = time(); + + // Then create it + $GLOBALS['minute'][$timestamp] = date('i', $timestamp); + } // END - if + + // Return cache + return $GLOBALS['minute'][$timestamp]; +} + // [EOF] ?>