]> git.mxchange.org Git - mailer.git/commitdiff
Caching of expensive PHP functions:
authorquix0r <quix0r@mxchange.org>
Tue, 29 Jun 2010 04:48:58 +0000 (04:48 +0000)
committerquix0r <quix0r@mxchange.org>
Tue, 29 Jun 2010 04:48:58 +0000 (04:48 +0000)
- date() calls are now wrapped and cached
- translateYesNo() is now cached (will follow more)
- TODOs.txt updated

19 files changed:
DOCS/TODOs.txt
inc/config-local.php.dist
inc/extensions/ext-bonus.php
inc/filters.php
inc/functions.php
inc/mails/beg_mails.php
inc/mails/bonus_mails.php
inc/modules/admin/what-add_rallye.php
inc/modules/admin/what-config_mediadata.php
inc/modules/admin/what-list_beg.php
inc/modules/admin/what-list_bonus.php
inc/modules/admin/what-list_rallyes.php
inc/modules/member/what-holiday.php
inc/monthly/monthly_beg.php
inc/monthly/monthly_bonus.php
inc/reset/reset_birthday.php
inc/stats-functions.php
inc/template-functions.php
inc/wrapper-functions.php

index 3f3a06d8609b1d4e8df2db55804b80135573bc36..5953193f647ed7a7e47379756ef65339b43d44b7 100644 (file)
 ./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
 ./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
index 5b4f26f088fb5fcb598ffd773ab0c486543a5045..9b17267c11609d09730d1618d220716415cad4a1 100644 (file)
@@ -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');
index 928b9c29f43e2146f817674bc240b8641ea1fefb..f9d1b1241d2e7916807296c8f44c5a4acf513d10 100644 (file)
@@ -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`
index 9a3b441a7ab30fb8604ba51e1e411ebd6facda92..2a099fe8026f25f775003715dfd625cc9c175825 100644 (file)
@@ -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
index 90dbe1d5e69a801bdd4c84ff4d95f7f4b2ba407a..e1b5a9ca363ad074e1419e570afa344346c42bbf 100644 (file)
@@ -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
 }
index 29d9c589c598bee96fed3456fb9b5ce68bd889d4..148404fff0e5cd8be5618739d440663a18a9294b 100644 (file)
@@ -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?
index ce784a4652d944cd9bf347f478e76ea747ee8aa8..84f30688dcf8e13466ecf21cda5e23fe092d649a 100644 (file)
@@ -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?
index 9b57ec31f3e982baf3a97320f8029a0ce9138323..d276330b9e383cf26eb3cf8501e04cb8cafe3fdb 100644 (file)
@@ -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();
index dbacb56b841fe94cde72c7e0bdf8ad57eb3d69c2..7b87200ab3ff10f6865a60958167f13715bc68e3 100644 (file)
@@ -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)
                ;
        }
index 5504a22b3d0c0b48293eaf03eab37b723035ca0b..f098de3f1cad5cce32f5f4a225a5ad43e3d98e4d 100644 (file)
@@ -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 {
index 5b295dd7e5f2eccc921701dc3e65a265c5fa7d3b..83c96f2799290fd89d7028e5de2779dbec904cce 100644 (file)
@@ -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 {
index 76bdd3eb3342351ad24dc1b6f6c44eae181ce528..65cf9f270d6ecba6aacfa69343325ad6289ebf25 100644 (file)
@@ -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']);
index ef2b99b8f4ae0e82ef5020cd96ce2c5816ee889a..d22688bea8629675837ddec0bdc865c6771770a1 100644 (file)
@@ -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);
index a509f4d834f83ee8b7fab766e4a349b592c23185..63440b567a33a198e2963cc3f88b5777ded38934 100644 (file)
@@ -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)) {
index 500f9f23d471c6e37bc6eee3dc638bc97288bcb1..cb010de05e74c2545ff4d830b30cc96be63a2297 100644 (file)
@@ -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
index fb45557875151fd42256ddd2612d5f752ac79201..2ca54a1cbe9d94e9728a3f855a5699d3d05170d4 100644 (file)
@@ -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 = '';
index 79cc70549b335fac7581673e44d509583efabf57..338f3b833adab7d1920438ea6c89e070d8c4b6a3 100644 (file)
@@ -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) {
index cf0b136f4d0d2d75ee90ccd32fb72c70da1a8aca..c3ecb5783475fc6dfed2e6db3b071e9bc7685d59 100644 (file)
@@ -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');
index dee0ad81ac815be93cf0539b73315a133cb4e125..6fc935bd28a050adf6a4116e55d3ee69c8b4e1c1 100644 (file)
@@ -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]
 ?>