]> git.mxchange.org Git - mailer.git/blob - inc/wrapper-functions.php
Do not rebuild cache if it is already rebuild
[mailer.git] / inc / wrapper-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/04/2009 *
4  * ===================                          Last change: 04/04/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : wrapper-functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Wrapper functions                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Wrapper-Funktionen                               *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         exit();
41 } // END - if
42
43 // Read a given file
44 function readFromFile ($FQFN) {
45         // Sanity-check if file is there (should be there, but just to make it sure)
46         if (!isFileReadable($FQFN)) {
47                 // This should not happen
48                 reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!');
49         } elseif (!isset($GLOBALS['file_content'][$FQFN])) {
50                 // Load the file
51                 if (function_exists('file_get_contents')) {
52                         // Use new function
53                         $GLOBALS['file_content'][$FQFN] = file_get_contents($FQFN);
54                 } else {
55                         // Fall-back to implode-file chain
56                         $GLOBALS['file_content'][$FQFN] = implode('', file($FQFN));
57                 }
58         } // END - if
59
60         // Return the content
61         return $GLOBALS['file_content'][$FQFN];
62 }
63
64 // Writes content to a file
65 function writeToFile ($FQFN, $content, $aquireLock = false) {
66         // Is the file writeable?
67         if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
68                 // Not writeable!
69                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN)));
70
71                 // Failed! :(
72                 return false;
73         } // END - if
74
75         // By default all is failed...
76         $GLOBALS['file_readable'][$FQFN] = false;
77         unset($GLOBALS['file_content'][$FQFN]);
78         $return = false;
79
80         // Is the function there?
81         if (function_exists('file_put_contents')) {
82                 // With lock?
83                 if ($aquireLock === true) {
84                         // Write it directly with lock
85                         $return = file_put_contents($FQFN, $content, LOCK_EX);
86                 } else {
87                         // Write it directly
88                         $return = file_put_contents($FQFN, $content);
89                 }
90         } else {
91                 // Write it with fopen
92                 $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
93
94                 // Do we need to aquire a lock?
95                 if ($aquireLock === true) {
96                         // Aquire lock
97                         flock($fp, LOCK_EX);
98                 } // END - if
99
100                 // Write content
101                 $return = fwrite($fp, $content);
102
103                 // Close stream
104                 fclose($fp);
105         }
106
107         // Was something written?
108         if ($return !== false) {
109                 // Mark it as readable
110                 $GLOBALS['file_readable'][$FQFN] = true;
111
112                 // Remember content in cache
113                 $GLOBALS['file_content'][$FQFN] = $content;
114         } // END - if
115
116         // Return status
117         return (($return !== false) && (changeMode($FQFN, 0644)));
118 }
119
120 // Clears the output buffer. This function does *NOT* backup sent content.
121 function clearOutputBuffer () {
122         // Make sure this function is not called twice (no double-cleaning!)
123         if (isset($GLOBALS[__FUNCTION__])) {
124                 // This function is called twice
125                 reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.');
126         } // END - if
127
128         // Trigger an error on failure
129         if ((ob_get_length() > 0) && (!ob_end_clean())) {
130                 // Failed!
131                 reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
132         } // END - if
133
134         // Mark this function as called
135         $GLOBALS[__FUNCTION__] = true;
136 }
137
138 // Encode strings
139 function encodeString ($str) {
140         $str = urlencode(base64_encode(compileUriCode($str)));
141         return $str;
142 }
143
144 // Decode strings encoded with encodeString()
145 function decodeString ($str) {
146         $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
147         return $str;
148 }
149
150 // Decode entities in a nicer way
151 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
152         // Decode the entities to UTF-8 now
153         $decodedString = html_entity_decode($str, $quote, 'UTF-8');
154
155         // Return decoded string
156         return $decodedString;
157 }
158
159 // Merges an array together but only if both are arrays
160 function merge_array ($array1, $array2) {
161         // Are both an array?
162         if ((!is_array($array1)) && (!is_array($array2))) {
163                 // Both are not arrays
164                 reportBug(__FUNCTION__, __LINE__, 'No arrays provided!');
165         } elseif (!is_array($array1)) {
166                 // Left one is not an array
167                 reportBug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
168         } elseif (!is_array($array2)) {
169                 // Right one is not an array
170                 reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
171         }
172
173         // Merge both together
174         return array_merge($array1, $array2);
175 }
176
177 // Check if given FQFN is a readable file
178 function isFileReadable ($FQFN) {
179         // Do we have cache?
180         if (!isset($GLOBALS['file_readable'][$FQFN])) {
181                 // Check all...
182                 $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN)));
183         } // END - if
184
185         // Return result
186         return $GLOBALS['file_readable'][$FQFN];
187 }
188
189 // Checks whether the given FQFN is a directory and not ., .. or .svn
190 function isDirectory ($FQFN) {
191         // Do we have cache?
192         if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
193                 // Generate baseName
194                 $baseName = basename($FQFN);
195
196                 // Check it
197                 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
198         } // END - if
199
200         // Return the result
201         return $GLOBALS[__FUNCTION__][$FQFN];
202 }
203
204 // "Getter" for the real remote IP number
205 function detectRealIpAddress () {
206         // Get remote ip from environment
207         $remoteAddr = determineRealRemoteAddress();
208
209         // Is removeip installed?
210         if (isExtensionActive('removeip')) {
211                 // Then anonymize it
212                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
213         } // END - if
214
215         // Return it
216         return $remoteAddr;
217 }
218
219 // "Getter" for remote IP number
220 function detectRemoteAddr () {
221         // Get remote ip from environment
222         $remoteAddr = determineRealRemoteAddress(true);
223
224         // Is removeip installed?
225         if (isExtensionActive('removeip')) {
226                 // Then anonymize it
227                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
228         } // END - if
229
230         // Return it
231         return $remoteAddr;
232 }
233
234 // "Getter" for remote hostname
235 function detectRemoteHostname () {
236         // Get remote ip from environment
237         $remoteHost = getenv('REMOTE_HOST');
238
239         // Is removeip installed?
240         if (isExtensionActive('removeip')) {
241                 // Then anonymize it
242                 $remoteHost = getAnonymousRemoteHost($remoteHost);
243         } // END - if
244
245         // Return it
246         return $remoteHost;
247 }
248
249 // "Getter" for user agent
250 function detectUserAgent ($alwaysReal = false) {
251         // Get remote ip from environment
252         $userAgent = getenv('HTTP_USER_AGENT');
253
254         // Is removeip installed?
255         if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
256                 // Then anonymize it
257                 $userAgent = getAnonymousUserAgent($userAgent);
258         } // END - if
259
260         // Return it
261         return $userAgent;
262 }
263
264 // "Getter" for referer
265 function detectReferer () {
266         // Get remote ip from environment
267         $referer = getenv('HTTP_REFERER');
268
269         // Is removeip installed?
270         if (isExtensionActive('removeip')) {
271                 // Then anonymize it
272                 $referer = getAnonymousReferer($referer);
273         } // END - if
274
275         // Return it
276         return $referer;
277 }
278
279 // "Getter" for request URI
280 function detectRequestUri () {
281         // Return it
282         return (getenv('REQUEST_URI'));
283 }
284
285 // "Getter" for query string
286 function detectQueryString () {
287         return str_replace('&', '&amp;', (getenv('QUERY_STRING')));
288 }
289
290 // "Getter" for SERVER_NAME
291 function detectServerName () {
292         // Return it
293         return (getenv('SERVER_NAME'));
294 }
295
296 // Removes any  existing www. from SERVER_NAME. This is very silly but enough
297 // for our purpose here.
298 function detectDomainName () {
299         // Do we have cache?
300         if (!isset($GLOBALS[__FUNCTION__])) {
301                 // Get server name
302                 $domainName = detectServerName();
303
304                 // Is there any www. ?
305                 if (substr($domainName, 0, 4) == 'www.') {
306                         // Remove it
307                         $domainName = substr($domainName, 4);
308                 } // END - if
309
310                 // Set cache
311                 $GLOBALS[__FUNCTION__] = $domainName;
312         } // END - if
313
314         // Return cache
315         return $GLOBALS[__FUNCTION__];
316 }
317
318 // Check whether we are installing
319 function isInstalling () {
320         // Determine whether we are installing
321         if (!isset($GLOBALS['__mailer_installing'])) {
322                 // Check URL (css.php/js.php need this)
323                 $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing');
324         } // END - if
325
326         // Return result
327         return $GLOBALS['__mailer_installing'];
328 }
329
330 // Check whether this script is installed
331 function isInstalled () {
332         // Do we have cache?
333         if (!isset($GLOBALS[__FUNCTION__])) {
334                 // Determine whether this script is installed
335                 $GLOBALS[__FUNCTION__] = (
336                 (
337                         // First is config
338                         (
339                                 (
340                                         isConfigEntrySet('MXCHANGE_INSTALLED')
341                                 ) && (
342                                         getConfig('MXCHANGE_INSTALLED') == 'Y'
343                                 )
344                         )
345                 ) || (
346                         // New config file found and loaded
347                         isIncludeReadable(getCachePath() . 'config-local.php')
348                 ) || (
349                         (
350                                 // New config file found, but not yet read
351                                 isIncludeReadable(getCachePath() . 'config-local.php')
352                         ) && (
353                                 (
354                                         // Only new config file is found
355                                         !isIncludeReadable('inc/config.php')
356                                 ) || (
357                                         // Is installation mode
358                                         !isInstalling()
359                                 )
360                         )
361                 ));
362         } // END - if
363
364         // Then use the cache
365         return $GLOBALS[__FUNCTION__];
366 }
367
368 // Check whether an admin is registered
369 function isAdminRegistered () {
370         // Is cache set?
371         if (!isset($GLOBALS[__FUNCTION__])) {
372                 // Simply check it
373                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
374         } // END - if
375
376         // Return it
377         return $GLOBALS[__FUNCTION__];
378 }
379
380 // Checks whether the hourly reset mode is active
381 function isHourlyResetEnabled () {
382         // Now simply check it
383         return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === true));
384 }
385
386 // Checks whether the reset mode is active
387 function isResetModeEnabled () {
388         // Now simply check it
389         return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
390 }
391
392 // Checks whether the debug mode is enabled
393 function isDebugModeEnabled () {
394         // Is cache set?
395         if (!isset($GLOBALS[__FUNCTION__])) {
396                 // Simply check it
397                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
398         } // END - if
399
400         // Return it
401         return $GLOBALS[__FUNCTION__];
402 }
403
404 // Checks whether the debug reset is enabled
405 function isDebugResetEnabled () {
406         // Is cache set?
407         if (!isset($GLOBALS[__FUNCTION__])) {
408                 // Simply check it
409                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
410         } // END - if
411
412         // Return it
413         return $GLOBALS[__FUNCTION__];
414 }
415
416 // Checks whether SQL debugging is enabled
417 function isSqlDebuggingEnabled () {
418         // Is cache set?
419         if (!isset($GLOBALS[__FUNCTION__])) {
420                 // Determine if SQL debugging is enabled
421                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
422         } // END - if
423
424         // Return it
425         return $GLOBALS[__FUNCTION__];
426 }
427
428 // Checks whether we shall debug regular expressions
429 function isDebugRegularExpressionEnabled () {
430         // Is cache set?
431         if (!isset($GLOBALS[__FUNCTION__])) {
432                 // Simply check it
433                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
434         } // END - if
435
436         // Return it
437         return $GLOBALS[__FUNCTION__];
438 }
439
440 // Checks whether the cache instance is valid
441 function isCacheInstanceValid () {
442         // Do we have cache?
443         if (!isset($GLOBALS[__FUNCTION__])) {
444                 // Determine it
445                 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
446         } // END - if
447
448         // Return cache
449         return $GLOBALS[__FUNCTION__];
450 }
451
452 // Copies a file from source to destination and verifies if that goes fine.
453 // This function should wrap the copy() command and make a nicer debug backtrace
454 // even if there is no xdebug extension installed.
455 function copyFileVerified ($source, $dest, $chmod = '') {
456         // Failed is the default
457         $status = false;
458
459         // Is the source file there?
460         if (!isFileReadable($source)) {
461                 // Then abort here
462                 reportBug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
463         } // END - if
464
465         // Is the target directory there?
466         if (!isDirectory(dirname($dest))) {
467                 // Then abort here
468                 reportBug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
469         } // END - if
470
471         // Now try to copy it
472         if (!copy($source, $dest)) {
473                 // Something went wrong
474                 reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
475         } else {
476                 // Reset cache
477                 $GLOBALS['file_readable'][$dest] = true;
478         }
479
480         // If there are chmod rights set, apply them
481         if (!empty($chmod)) {
482                 // Try to apply them
483                 $status = changeMode($dest, $chmod);
484         } else {
485                 // All fine
486                 $status = true;
487         }
488
489         // All fine
490         return $status;
491 }
492
493 // Wrapper function for chmod()
494 // @TODO Do some more sanity check here
495 function changeMode ($FQFN, $mode) {
496         // Is the file/directory there?
497         if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
498                 // Neither, so abort here
499                 reportBug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
500         } // END - if
501
502         // Try to set them
503         return chmod($FQFN, $mode);
504 }
505
506 // Wrapper for unlink()
507 function removeFile ($FQFN) {
508         // Is the file there?
509         if (isFileReadable($FQFN)) {
510                 // Reset cache first
511                 $GLOBALS['file_readable'][$FQFN] = false;
512
513                 // Yes, so remove it
514                 return unlink($FQFN);
515         } // END - if
516
517         // All fine if no file was removed. If we change this to 'false' or rewrite
518         // above if() block it would be to restrictive.
519         return true;
520 }
521
522 // Wrapper for $_POST['sel']
523 function countPostSelection ($element = 'sel') {
524         // Is it set?
525         if (isPostRequestElementSet($element)) {
526                 // Return counted elements
527                 return countSelection(postRequestElement($element));
528         } else {
529                 // Return zero if not found
530                 return '0';
531         }
532 }
533
534 // Checks whether the config-local.php is loaded
535 function isConfigLocalLoaded () {
536         return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
537 }
538
539 // Checks whether a nickname or userid was entered and caches the result
540 function isNicknameUsed ($userid) {
541         // Is the cache there
542         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
543                 // Determine it
544                 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, true, false) . '') != $userid) && ($userid != 'NULL'));
545         } // END - if
546
547         // Return the result
548         return $GLOBALS[__FUNCTION__][$userid];
549 }
550
551 // Getter for 'what' value
552 function getWhat ($strict = true) {
553         // Default is null
554         $what = NULL;
555
556         // Is the value set?
557         if (isWhatSet($strict)) {
558                 // Then use it
559                 $what = $GLOBALS['__what'];
560         } // END - if
561
562         // Return it
563         return $what;
564 }
565
566 // Setter for 'what' value
567 function setWhat ($newWhat) {
568         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat);
569         $GLOBALS['__what'] = $newWhat;
570 }
571
572 // Setter for 'what' from configuration
573 function setWhatFromConfig ($configEntry) {
574         // Get 'what' from config
575         $what = getConfig($configEntry);
576
577         // Set it
578         setWhat($what);
579 }
580
581 // Checks whether what is set and optionally aborts on miss
582 function isWhatSet ($strict =  false) {
583         // Check for it
584         $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
585
586         // Should we abort here?
587         if (($strict === true) && ($isset === false)) {
588                 // Output backtrace
589                 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
590         } // END - if
591
592         // Return it
593         return $isset;
594 }
595
596 // Getter for 'action' value
597 function getAction ($strict = true) {
598         // Default is null
599         $action = NULL;
600
601         // Is the value set?
602         if (isActionSet(($strict) && (isHtmlOutputMode()))) {
603                 // Then use it
604                 $action = $GLOBALS['__action'];
605         } // END - if
606
607         // Return it
608         return $action;
609 }
610
611 // Setter for 'action' value
612 function setAction ($newAction) {
613         $GLOBALS['__action'] = $newAction;
614 }
615
616 // Checks whether action is set and optionally aborts on miss
617 function isActionSet ($strict =  false) {
618         // Check for it
619         $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
620
621         // Should we abort here?
622         if (($strict === true) && ($isset === false)) {
623                 // Output backtrace
624                 reportBug(__FUNCTION__, __LINE__, 'action is empty.');
625         } // END - if
626
627         // Return it
628         return $isset;
629 }
630
631 // Getter for 'module' value
632 function getModule ($strict = true) {
633         // Default is null
634         $module = NULL;
635
636         // Is the value set?
637         if (isModuleSet($strict)) {
638                 // Then use it
639                 $module = $GLOBALS['__module'];
640         } // END - if
641
642         // Return it
643         return $module;
644 }
645
646 // Setter for 'module' value
647 function setModule ($newModule) {
648         // Secure it and make all modules lower-case
649         $GLOBALS['__module'] = strtolower($newModule);
650 }
651
652 // Checks whether module is set and optionally aborts on miss
653 function isModuleSet ($strict =  false) {
654         // Check for it
655         $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
656
657         // Should we abort here?
658         if (($strict === true) && ($isset === false)) {
659                 // Output backtrace
660                 reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
661         } // END - if
662
663         // Return it
664         return (($isset === true) && ($GLOBALS['__module'] != 'unknown')) ;
665 }
666
667 // Getter for 'output_mode' value
668 function getScriptOutputMode () {
669         // Is cache set?
670         if (!isset($GLOBALS[__FUNCTION__])) {
671                 // Is the output mode set?
672                 if (!isOutputModeSet()) {
673                         // No, then abort here
674                         reportBug(__FUNCTION__, __LINE__, 'Output mode not set.');
675                 } // END - if
676
677                 // Set it in cache
678                 $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode'];
679         } // END - if
680
681         // Return cache
682         return $GLOBALS[__FUNCTION__];
683 }
684
685 // Setter for 'output_mode' value
686 function setOutputMode ($newOutputMode) {
687         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
688         $GLOBALS['__output_mode'] = (int) $newOutputMode;
689 }
690
691 // Checks whether output_mode is set and optionally aborts on miss
692 function isOutputModeSet ($strict =  false) {
693         // Check for it
694         $isset = (isset($GLOBALS['__output_mode']));
695
696         // Should we abort here?
697         if (($strict === true) && ($isset === false)) {
698                 // Output backtrace
699                 reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
700         } // END - if
701
702         // Return it
703         return $isset;
704 }
705
706 // Enables block-mode
707 function enableBlockMode ($enabled = true) {
708         $GLOBALS['__block_mode'] = $enabled;
709 }
710
711 // Checks whether block-mode is enabled
712 function isBlockModeEnabled () {
713         // Abort if not set
714         if (!isset($GLOBALS['__block_mode'])) {
715                 // Needs to be fixed
716                 reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
717         } // END - if
718
719         // Return it
720         return $GLOBALS['__block_mode'];
721 }
722
723 // Wrapper for redirectToUrl but URL comes from a configuration entry
724 function redirectToConfiguredUrl ($configEntry) {
725         // Load the URL
726         redirectToUrl(getConfig($configEntry));
727 }
728
729 // Wrapper function to redirect from member-only modules to index
730 function redirectToIndexMemberOnlyModule () {
731         // Do the redirect here
732         redirectToUrl('modules.php?module=index&amp;code=' . getCode('MODULE_MEMBER_ONLY') . '&amp;mod=' . getModule());
733 }
734
735 // Wrapper function to redirect to current URL
736 function redirectToRequestUri () {
737         redirectToUrl(basename(detectRequestUri()));
738 }
739
740 // Wrapper function to redirect to de-refered URL
741 function redirectToDereferedUrl ($url) {
742         // Redirect to to
743         redirectToUrl(generateDerefererUrl($url));
744 }
745
746 // Wrapper function for checking if extension is installed and newer or same version
747 function isExtensionInstalledAndNewer ($ext_name, $version) {
748         // Is an cache entry found?
749         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
750                 // Determine it
751                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
752         } else {
753                 // Cache hits should be incremented twice
754                 incrementStatsEntry('cache_hits', 2);
755         }
756
757         // Return it
758         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=&gt;' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
759         return $GLOBALS[__FUNCTION__][$ext_name][$version];
760 }
761
762 // Wrapper function for checking if extension is installed and older than given version
763 function isExtensionInstalledAndOlder ($ext_name, $version) {
764         // Is an cache entry found?
765         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
766                 // Determine it
767                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
768         } else {
769                 // Cache hits should be incremented twice
770                 incrementStatsEntry('cache_hits', 2);
771         }
772
773         // Return it
774         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '&lt;' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
775         return $GLOBALS[__FUNCTION__][$ext_name][$version];
776 }
777
778 // Set username
779 function setUsername ($userName) {
780         $GLOBALS['username'] = (string) $userName;
781 }
782
783 // Get username
784 function getUsername () {
785         // User name set?
786         if (!isset($GLOBALS['username'])) {
787                 // No, so it has to be a guest
788                 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
789         } // END - if
790
791         // Return it
792         return $GLOBALS['username'];
793 }
794
795 // Wrapper function for installation phase
796 function isInstallationPhase () {
797         // Do we have cache?
798         if (!isset($GLOBALS[__FUNCTION__])) {
799                 // Determine it
800                 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
801         } // END - if
802
803         // Return result
804         return $GLOBALS[__FUNCTION__];
805 }
806
807 // Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
808 function isDemoModeActive () {
809         // Is cache set?
810         if (!isset($GLOBALS[__FUNCTION__])) {
811                 // Simply check it
812                 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
813         } // END - if
814
815         // Return it
816         return $GLOBALS[__FUNCTION__];
817 }
818
819 // Getter for PHP caching value
820 function getPhpCaching () {
821         return $GLOBALS['php_caching'];
822 }
823
824 // Checks whether the admin hash is set
825 function isAdminHashSet ($adminId) {
826         // Is the array there?
827         if (!isset($GLOBALS['cache_array']['admin'])) {
828                 // Missing array should be reported
829                 reportBug(__FUNCTION__, __LINE__, 'Cache not set.');
830         } // END - if
831
832         // Check for admin hash
833         return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
834 }
835
836 // Setter for admin hash
837 function setAdminHash ($adminId, $hash) {
838         $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
839 }
840
841 // Getter for current admin login
842 function getCurrentAdminLogin () {
843         // Log debug message
844         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
845
846         // Do we have cache?
847         if (!isset($GLOBALS[__FUNCTION__])) {
848                 // Determine it
849                 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
850         } // END - if
851
852         // Return it
853         return $GLOBALS[__FUNCTION__];
854 }
855
856 // Setter for admin id (and current)
857 function setAdminId ($adminId) {
858         // Log debug message
859         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
860
861         // Set session
862         $status = setSession('admin_id', bigintval($adminId));
863
864         // Set current id
865         setCurrentAdminId($adminId);
866
867         // Return status
868         return $status;
869 }
870
871 // Setter for admin_last
872 function setAdminLast ($adminLast) {
873         // Log debug message
874         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
875
876         // Set session
877         $status = setSession('admin_last', $adminLast);
878
879         // Return status
880         return $status;
881 }
882
883 // Setter for admin_md5
884 function setAdminMd5 ($adminMd5) {
885         // Log debug message
886         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
887
888         // Set session
889         $status = setSession('admin_md5', $adminMd5);
890
891         // Return status
892         return $status;
893 }
894
895 // Getter for admin_md5
896 function getAdminMd5 () {
897         // Log debug message
898         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
899
900         // Get session
901         return getSession('admin_md5');
902 }
903
904 // Init user data array
905 function initUserData () {
906         // User id should not be zero
907         if (!isValidUserId(getCurrentUserId())) {
908                 // Should be always valid
909                 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
910         } // END - if
911
912         // Init the user
913         unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
914         $GLOBALS['user_data'][getCurrentUserId()] = array();
915 }
916
917 // Getter for user data
918 function getUserData ($column) {
919         // User id should not be zero
920         if (!isValidUserId(getCurrentUserId())) {
921                 // Should be always valid
922                 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
923         } // END - if
924
925         // Default is empty
926         $data = NULL;
927
928         if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
929                 // Return the value
930                 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
931         } // END - if
932
933         // Return it
934         return $data;
935 }
936
937 // Checks whether given user data is set to 'Y'
938 function isUserDataEnabled ($column) {
939         // Do we have cache?
940         if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
941                 // Determine it
942                 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
943         } // END - if
944
945         // Return cache
946         return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
947 }
948
949 // Geter for whole user data array
950 function getUserDataArray () {
951         // Get user id
952         $userid = getCurrentUserId();
953
954         // Is the current userid valid?
955         if (!isValidUserId($userid)) {
956                 // Should be always valid
957                 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
958         } // END - if
959
960         // Get the whole array if found
961         if (isset($GLOBALS['user_data'][$userid])) {
962                 // Found, so return it
963                 return $GLOBALS['user_data'][$userid];
964         } else {
965                 // Return empty array
966                 return array();
967         }
968 }
969
970 // Checks if the user data is valid, this may indicate that the user has logged
971 // in, but you should use isMember() if you want to find that out.
972 function isUserDataValid () {
973         // User id should not be zero so abort here
974         if (!isCurrentUserIdSet()) {
975                 return false;
976         } // END - if
977
978         // Is it cached?
979         if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
980                 // Determine it
981                 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
982         } // END - if
983
984         // Return the result
985         return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
986 }
987
988 // Setter for current userid
989 function setCurrentUserId ($userid) {
990         // Set userid
991         $GLOBALS['current_userid'] = bigintval($userid);
992
993         // Unset it to re-determine the actual state
994         unset($GLOBALS['is_userdata_valid'][$userid]);
995
996         // Is the cache from below functions different?
997         if ((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) {
998                 // Then unset both
999                 unset($GLOBALS['getCurrentUserId']);
1000                 unset($GLOBALS['isCurrentUserIdSet']);
1001         } // END - if
1002 }
1003
1004 // Getter for current userid
1005 function getCurrentUserId () {
1006         // Is cache set?
1007         if (!isset($GLOBALS[__FUNCTION__])) {
1008                 // Userid must be set before it can be used
1009                 if (!isCurrentUserIdSet()) {
1010                         // Not set
1011                         reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1012                 } // END - if
1013
1014                 // Set userid in cache
1015                 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1016         } // END - if
1017
1018         // Return cache
1019         return $GLOBALS[__FUNCTION__];
1020 }
1021
1022 // Checks if current userid is set
1023 function isCurrentUserIdSet () {
1024         // Do we have cache?
1025         if (!isset($GLOBALS[__FUNCTION__])) {
1026                 // Determine it
1027                 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1028         } // END - if
1029
1030         // Return cache
1031         return $GLOBALS[__FUNCTION__];
1032 }
1033
1034 // Checks whether we are debugging template cache
1035 function isDebuggingTemplateCache () {
1036         // Do we have cache?
1037         if (!isset($GLOBALS[__FUNCTION__])) {
1038                 // Determine it
1039                 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1040         } // END - if
1041
1042         // Return cache
1043         return $GLOBALS[__FUNCTION__];
1044 }
1045
1046 // Wrapper for fetchUserData() and getUserData() calls
1047 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1048         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1049         // Is it cached?
1050         if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1051                 // Default is NULL
1052                 $data = NULL;
1053
1054                 // Can we fetch the user data?
1055                 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1056                         // Now get the data back
1057                         $data = getUserData($valueColumn);
1058                 } // END - if
1059
1060                 // Cache it
1061                 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1062         } // END - if
1063
1064         // Return it
1065         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1066         return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1067 }
1068
1069 // Wrapper for strpos() to ease porting from deprecated ereg() function
1070 function isInString ($needle, $haystack) {
1071         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1072         return (strpos($haystack, $needle) !== false);
1073 }
1074
1075 // Wrapper for strpos() to ease porting from deprecated eregi() function
1076 // This function is case-insensitive
1077 function isInStringIgnoreCase ($needle, $haystack) {
1078         return (isInString(strtolower($needle), strtolower($haystack)));
1079 }
1080
1081 // Wrapper to check for if fatal errors where detected
1082 function ifFatalErrorsDetected () {
1083         // Just call the inner function
1084         return (getTotalFatalErrors() > 0);
1085 }
1086
1087 // Checks whether a HTTP status has been set
1088 function isHttpStatusSet () {
1089         // Is it set and not empty?
1090         return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1091 }
1092
1093 // Setter for HTTP status
1094 function setHttpStatus ($status) {
1095         $GLOBALS['http_status'] = (string) $status;
1096 }
1097
1098 // Getter for HTTP status
1099 function getHttpStatus () {
1100         // Is the status set?
1101         if (!isHttpStatusSet()) {
1102                 // Abort here
1103                 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1104         } // END - if
1105
1106         // Return it
1107         return $GLOBALS['http_status'];
1108 }
1109
1110 /**
1111  * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1112  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1113  *
1114  * ----------------------------------------------------------------------------
1115  * If you want to redirect, please use redirectToUrl(); instead
1116  * ----------------------------------------------------------------------------
1117  *
1118  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1119  *
1120  * @link    http://support.microsoft.com/kb/q176113/
1121  * @author  Andreas Gohr <andi@splitbrain.org>
1122  * @access  private
1123  */
1124 function sendRawRedirect ($url) {
1125         // Clear output buffer
1126         clearOutputBuffer();
1127
1128         // Clear own output buffer
1129         $GLOBALS['__output'] = '';
1130
1131         // To make redirects working (no content type), output mode must be raw
1132         setOutputMode(-1);
1133
1134         // Send helping header
1135         setHttpStatus('302 Found');
1136
1137         // always close the session
1138         session_write_close();
1139
1140         // Revert entity &amp;
1141         $url = str_replace('&amp;', '&', $url);
1142
1143         // check if running on IIS < 6 with CGI-PHP
1144         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1145                 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1146                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1147                 ($matches[1] < 6)) {
1148                 // Send the IIS header
1149                 addHttpHeader('Refresh: 0;url=' . $url);
1150         } else {
1151                 // Send generic header
1152                 addHttpHeader('Location: ' . $url);
1153         }
1154
1155         // Shutdown here
1156         doShutdown();
1157 }
1158
1159 // Determines the country of the given user id
1160 function determineCountry ($userid) {
1161         // Do we have cache?
1162         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1163                 // Default is 'invalid'
1164                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1165
1166                 // Is extension country active?
1167                 if (isExtensionActive('country')) {
1168                         // Determine the right country code through the country id
1169                         $id = getUserData('country_code');
1170
1171                         // Then handle it over
1172                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1173                 } else {
1174                         // Get raw code from user data
1175                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1176                 }
1177         } // END - if
1178
1179         // Return cache
1180         return $GLOBALS[__FUNCTION__][$userid];
1181 }
1182
1183 // "Getter" for total confirmed user accounts
1184 function getTotalConfirmedUser () {
1185         // Is it cached?
1186         if (!isset($GLOBALS[__FUNCTION__])) {
1187                 // Then do it
1188                 if (isExtensionActive('user')) {
1189                         $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1190                 } else {
1191                         $GLOBALS[__FUNCTION__] = 0;
1192                 }
1193         } // END - if
1194
1195         // Return cached value
1196         return $GLOBALS[__FUNCTION__];
1197 }
1198
1199 // "Getter" for total unconfirmed user accounts
1200 function getTotalUnconfirmedUser () {
1201         // Is it cached?
1202         if (!isset($GLOBALS[__FUNCTION__])) {
1203                 // Then do it
1204                 if (isExtensionActive('user')) {
1205                         $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1206                 } else {
1207                         $GLOBALS[__FUNCTION__] = 0;
1208                 }
1209         } // END - if
1210
1211         // Return cached value
1212         return $GLOBALS[__FUNCTION__];
1213 }
1214
1215 // "Getter" for total locked user accounts
1216 function getTotalLockedUser () {
1217         // Is it cached?
1218         if (!isset($GLOBALS[__FUNCTION__])) {
1219                 // Then do it
1220                 if (isExtensionActive('user')) {
1221                         $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1222                 } else {
1223                         $GLOBALS[__FUNCTION__] = 0;
1224                 }
1225         } // END - if
1226
1227         // Return cached value
1228         return $GLOBALS[__FUNCTION__];
1229 }
1230
1231 // "Getter" for total locked user accounts
1232 function getTotalRandomRefidUser () {
1233         // Is it cached?
1234         if (!isset($GLOBALS[__FUNCTION__])) {
1235                 // Then do it
1236                 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1237                         $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, runFilterChain('user_exclusion_sql', ' '), '>=');
1238                 } else {
1239                         $GLOBALS[__FUNCTION__] = 0;
1240                 }
1241         } // END - if
1242
1243         // Return cached value
1244         return $GLOBALS[__FUNCTION__];
1245 }
1246
1247 // Is given userid valid?
1248 function isValidUserId ($userid) {
1249         // Debug message
1250         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid);
1251
1252         // Handle NULL
1253         if (is_null($userid)) {
1254                 // Do not handle this as of below isset() will always return false
1255                 return false;
1256         } // END - if
1257
1258         // Do we have cache?
1259         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1260                 // Check it out
1261                 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1262         } // END - if
1263
1264         // Return cache
1265         return $GLOBALS[__FUNCTION__][$userid];
1266 }
1267
1268 // Encodes entities
1269 function encodeEntities ($str) {
1270         // Secure it first
1271         $str = secureString($str, true, true);
1272
1273         // Encode dollar sign as well
1274         $str = str_replace('$', '&#36;', $str);
1275
1276         // Return it
1277         return $str;
1278 }
1279
1280 // "Getter" for date from patch_ctime
1281 function getDateFromRepository () {
1282         // Is it cached?
1283         if (!isset($GLOBALS[__FUNCTION__])) {
1284                 // Then set it
1285                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1286         } // END - if
1287
1288         // Return cache
1289         return $GLOBALS[__FUNCTION__];
1290 }
1291
1292 // "Getter" for date/time from patch_ctime
1293 function getDateTimeFromRepository () {
1294         // Is it cached?
1295         if (!isset($GLOBALS[__FUNCTION__])) {
1296                 // Then set it
1297                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1298         } // END - if
1299
1300         // Return cache
1301         return $GLOBALS[__FUNCTION__];
1302 }
1303
1304 // Getter for current year (default)
1305 function getYear ($timestamp = NULL) {
1306         // Is it cached?
1307         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1308                 // null is time()
1309                 if (is_null($timestamp)) {
1310                         $timestamp = time();
1311                 } // END - if
1312
1313                 // Then create it
1314                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1315         } // END - if
1316
1317         // Return cache
1318         return $GLOBALS[__FUNCTION__][$timestamp];
1319 }
1320
1321 // Getter for current month (default)
1322 function getMonth ($timestamp = NULL) {
1323         // Is it cached?
1324         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1325                 // If null is set, use time()
1326                 if (is_null($timestamp)) {
1327                         // Use time() which is current timestamp
1328                         $timestamp = time();
1329                 } // END - if
1330
1331                 // Then create it
1332                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1333         } // END - if
1334
1335         // Return cache
1336         return $GLOBALS[__FUNCTION__][$timestamp];
1337 }
1338
1339 // Getter for current hour (default)
1340 function getHour ($timestamp = NULL) {
1341         // Is it cached?
1342         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1343                 // null is time()
1344                 if (is_null($timestamp)) {
1345                         $timestamp = time();
1346                 } // END - if
1347
1348                 // Then create it
1349                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1350         } // END - if
1351
1352         // Return cache
1353         return $GLOBALS[__FUNCTION__][$timestamp];
1354 }
1355
1356 // Getter for current day (default)
1357 function getDay ($timestamp = NULL) {
1358         // Is it cached?
1359         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1360                 // null is time()
1361                 if (is_null($timestamp)) {
1362                         $timestamp = time();
1363                 } // END - if
1364
1365                 // Then create it
1366                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1367         } // END - if
1368
1369         // Return cache
1370         return $GLOBALS[__FUNCTION__][$timestamp];
1371 }
1372
1373 // Getter for current week (default)
1374 function getWeek ($timestamp = NULL) {
1375         // Is it cached?
1376         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1377                 // null is time()
1378                 if (is_null($timestamp)) $timestamp = time();
1379
1380                 // Then create it
1381                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1382         } // END - if
1383
1384         // Return cache
1385         return $GLOBALS[__FUNCTION__][$timestamp];
1386 }
1387
1388 // Getter for current short_hour (default)
1389 function getShortHour ($timestamp = NULL) {
1390         // Is it cached?
1391         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1392                 // null is time()
1393                 if (is_null($timestamp)) $timestamp = time();
1394
1395                 // Then create it
1396                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1397         } // END - if
1398
1399         // Return cache
1400         return $GLOBALS[__FUNCTION__][$timestamp];
1401 }
1402
1403 // Getter for current long_hour (default)
1404 function getLongHour ($timestamp = NULL) {
1405         // Is it cached?
1406         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1407                 // null is time()
1408                 if (is_null($timestamp)) $timestamp = time();
1409
1410                 // Then create it
1411                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1412         } // END - if
1413
1414         // Return cache
1415         return $GLOBALS[__FUNCTION__][$timestamp];
1416 }
1417
1418 // Getter for current second (default)
1419 function getSecond ($timestamp = NULL) {
1420         // Is it cached?
1421         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1422                 // null is time()
1423                 if (is_null($timestamp)) $timestamp = time();
1424
1425                 // Then create it
1426                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1427         } // END - if
1428
1429         // Return cache
1430         return $GLOBALS[__FUNCTION__][$timestamp];
1431 }
1432
1433 // Getter for current minute (default)
1434 function getMinute ($timestamp = NULL) {
1435         // Is it cached?
1436         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1437                 // null is time()
1438                 if (is_null($timestamp)) $timestamp = time();
1439
1440                 // Then create it
1441                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1442         } // END - if
1443
1444         // Return cache
1445         return $GLOBALS[__FUNCTION__][$timestamp];
1446 }
1447
1448 // Checks whether the title decoration is enabled
1449 function isTitleDecorationEnabled () {
1450         // Do we have cache?
1451         if (!isset($GLOBALS[__FUNCTION__])) {
1452                 // Just check it
1453                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1454         } // END - if
1455
1456         // Return cache
1457         return $GLOBALS[__FUNCTION__];
1458 }
1459
1460 // Checks whether filter usage updates are enabled (expensive queries!)
1461 function isFilterUsageUpdateEnabled () {
1462         // Do we have cache?
1463         if (!isset($GLOBALS[__FUNCTION__])) {
1464                 // Determine it
1465                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1466         } // END - if
1467
1468         // Return cache
1469         return $GLOBALS[__FUNCTION__];
1470 }
1471
1472 // Checks whether debugging of weekly resets is enabled
1473 function isWeeklyResetDebugEnabled () {
1474         // Do we have cache?
1475         if (!isset($GLOBALS[__FUNCTION__])) {
1476                 // Determine it
1477                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1478         } // END - if
1479
1480         // Return cache
1481         return $GLOBALS[__FUNCTION__];
1482 }
1483
1484 // Checks whether debugging of monthly resets is enabled
1485 function isMonthlyResetDebugEnabled () {
1486         // Do we have cache?
1487         if (!isset($GLOBALS[__FUNCTION__])) {
1488                 // Determine it
1489                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1490         } // END - if
1491
1492         // Return cache
1493         return $GLOBALS[__FUNCTION__];
1494 }
1495
1496 // Checks whether displaying of debug SQLs are enabled
1497 function isDisplayDebugSqlEnabled () {
1498         // Do we have cache?
1499         if (!isset($GLOBALS[__FUNCTION__])) {
1500                 // Determine it
1501                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1502         } // END - if
1503
1504         // Return cache
1505         return $GLOBALS[__FUNCTION__];
1506 }
1507
1508 // Checks whether module title is enabled
1509 function isModuleTitleEnabled () {
1510         // Do we have cache?
1511         if (!isset($GLOBALS[__FUNCTION__])) {
1512                 // Determine it
1513                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1514         } // END - if
1515
1516         // Return cache
1517         return $GLOBALS[__FUNCTION__];
1518 }
1519
1520 // Checks whether what title is enabled
1521 function isWhatTitleEnabled () {
1522         // Do we have cache?
1523         if (!isset($GLOBALS[__FUNCTION__])) {
1524                 // Determine it
1525                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1526         } // END - if
1527
1528         // Return cache
1529         return $GLOBALS[__FUNCTION__];
1530 }
1531
1532 // Checks whether stats are enabled
1533 function ifInternalStatsEnabled () {
1534         // Do we have cache?
1535         if (!isset($GLOBALS[__FUNCTION__])) {
1536                 // Then determine it
1537                 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1538         } // END - if
1539
1540         // Return cached value
1541         return $GLOBALS[__FUNCTION__];
1542 }
1543
1544 // Checks whether admin-notification of certain user actions is enabled
1545 function isAdminNotificationEnabled () {
1546         // Do we have cache?
1547         if (!isset($GLOBALS[__FUNCTION__])) {
1548                 // Determine it
1549                 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1550         } // END - if
1551
1552         // Return cache
1553         return $GLOBALS[__FUNCTION__];
1554 }
1555
1556 // Checks whether random referral id selection is enabled
1557 function isRandomReferralIdEnabled () {
1558         // Do we have cache?
1559         if (!isset($GLOBALS[__FUNCTION__])) {
1560                 // Determine it
1561                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1562         } // END - if
1563
1564         // Return cache
1565         return $GLOBALS[__FUNCTION__];
1566 }
1567
1568 // "Getter" for default language
1569 function getDefaultLanguage () {
1570         // Do we have cache?
1571         if (!isset($GLOBALS[__FUNCTION__])) {
1572                 // Determine it
1573                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1574         } // END - if
1575
1576         // Return cache
1577         return $GLOBALS[__FUNCTION__];
1578 }
1579
1580 // "Getter" for default referral id
1581 function getDefRefid () {
1582         // Do we have cache?
1583         if (!isset($GLOBALS[__FUNCTION__])) {
1584                 // Determine it
1585                 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1586         } // END - if
1587
1588         // Return cache
1589         return $GLOBALS[__FUNCTION__];
1590 }
1591
1592 // "Getter" for path
1593 function getPath () {
1594         // Do we have cache?
1595         if (!isset($GLOBALS[__FUNCTION__])) {
1596                 // Determine it
1597                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1598         } // END - if
1599
1600         // Return cache
1601         return $GLOBALS[__FUNCTION__];
1602 }
1603
1604 // "Getter" for url
1605 function getUrl () {
1606         // Do we have cache?
1607         if (!isset($GLOBALS[__FUNCTION__])) {
1608                 // Determine it
1609                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1610         } // END - if
1611
1612         // Return cache
1613         return $GLOBALS[__FUNCTION__];
1614 }
1615
1616 // "Getter" for cache_path
1617 function getCachePath () {
1618         // Do we have cache?
1619         if (!isset($GLOBALS[__FUNCTION__])) {
1620                 // Determine it
1621                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1622         } // END - if
1623
1624         // Return cache
1625         return $GLOBALS[__FUNCTION__];
1626 }
1627
1628 // "Getter" for secret_key
1629 function getSecretKey () {
1630         // Do we have cache?
1631         if (!isset($GLOBALS[__FUNCTION__])) {
1632                 // Determine it
1633                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1634         } // END - if
1635
1636         // Return cache
1637         return $GLOBALS[__FUNCTION__];
1638 }
1639
1640 // "Getter" for SITE_KEY
1641 function getSiteKey () {
1642         // Do we have cache?
1643         if (!isset($GLOBALS[__FUNCTION__])) {
1644                 // Determine it
1645                 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1646         } // END - if
1647
1648         // Return cache
1649         return $GLOBALS[__FUNCTION__];
1650 }
1651
1652 // "Getter" for DATE_KEY
1653 function getDateKey () {
1654         // Do we have cache?
1655         if (!isset($GLOBALS[__FUNCTION__])) {
1656                 // Determine it
1657                 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1658         } // END - if
1659
1660         // Return cache
1661         return $GLOBALS[__FUNCTION__];
1662 }
1663
1664 // "Getter" for master_salt
1665 function getMasterSalt () {
1666         // Do we have cache?
1667         if (!isset($GLOBALS[__FUNCTION__])) {
1668                 // Determine it
1669                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1670         } // END - if
1671
1672         // Return cache
1673         return $GLOBALS[__FUNCTION__];
1674 }
1675
1676 // "Getter" for prime
1677 function getPrime () {
1678         // Do we have cache?
1679         if (!isset($GLOBALS[__FUNCTION__])) {
1680                 // Determine it
1681                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1682         } // END - if
1683
1684         // Return cache
1685         return $GLOBALS[__FUNCTION__];
1686 }
1687
1688 // "Getter" for encrypt_separator
1689 function getEncryptSeparator () {
1690         // Do we have cache?
1691         if (!isset($GLOBALS[__FUNCTION__])) {
1692                 // Determine it
1693                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1694         } // END - if
1695
1696         // Return cache
1697         return $GLOBALS[__FUNCTION__];
1698 }
1699
1700 // "Getter" for mysql_prefix
1701 function getMysqlPrefix () {
1702         // Do we have cache?
1703         if (!isset($GLOBALS[__FUNCTION__])) {
1704                 // Determine it
1705                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1706         } // END - if
1707
1708         // Return cache
1709         return $GLOBALS[__FUNCTION__];
1710 }
1711
1712 // "Getter" for table_type
1713 function getTableType () {
1714         // Do we have cache?
1715         if (!isset($GLOBALS[__FUNCTION__])) {
1716                 // Determine it
1717                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1718         } // END - if
1719
1720         // Return cache
1721         return $GLOBALS[__FUNCTION__];
1722 }
1723
1724 // "Getter" for salt_length
1725 function getSaltLength () {
1726         // Do we have cache?
1727         if (!isset($GLOBALS[__FUNCTION__])) {
1728                 // Determine it
1729                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1730         } // END - if
1731
1732         // Return cache
1733         return $GLOBALS[__FUNCTION__];
1734 }
1735
1736 // "Getter" for output_mode
1737 function getOutputMode () {
1738         // Do we have cache?
1739         if (!isset($GLOBALS[__FUNCTION__])) {
1740                 // Determine it
1741                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1742         } // END - if
1743
1744         // Return cache
1745         return $GLOBALS[__FUNCTION__];
1746 }
1747
1748 // "Getter" for full_version
1749 function getFullVersion () {
1750         // Do we have cache?
1751         if (!isset($GLOBALS[__FUNCTION__])) {
1752                 // Determine it
1753                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1754         } // END - if
1755
1756         // Return cache
1757         return $GLOBALS[__FUNCTION__];
1758 }
1759
1760 // "Getter" for title
1761 function getTitle () {
1762         // Do we have cache?
1763         if (!isset($GLOBALS[__FUNCTION__])) {
1764                 // Determine it
1765                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1766         } // END - if
1767
1768         // Return cache
1769         return $GLOBALS[__FUNCTION__];
1770 }
1771
1772 // "Getter" for curr_svn_revision
1773 function getCurrentRepositoryRevision () {
1774         // Do we have cache?
1775         if (!isset($GLOBALS[__FUNCTION__])) {
1776                 // Determine it
1777                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1778         } // END - if
1779
1780         // Return cache
1781         return $GLOBALS[__FUNCTION__];
1782 }
1783
1784 // "Getter" for server_url
1785 function getServerUrl () {
1786         // Do we have cache?
1787         if (!isset($GLOBALS[__FUNCTION__])) {
1788                 // Determine it
1789                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1790         } // END - if
1791
1792         // Return cache
1793         return $GLOBALS[__FUNCTION__];
1794 }
1795
1796 // "Getter" for mt_word
1797 function getMtWord () {
1798         // Do we have cache?
1799         if (!isset($GLOBALS[__FUNCTION__])) {
1800                 // Determine it
1801                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1802         } // END - if
1803
1804         // Return cache
1805         return $GLOBALS[__FUNCTION__];
1806 }
1807
1808 // "Getter" for mt_word2
1809 function getMtWord2 () {
1810         // Do we have cache?
1811         if (!isset($GLOBALS[__FUNCTION__])) {
1812                 // Determine it
1813                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1814         } // END - if
1815
1816         // Return cache
1817         return $GLOBALS[__FUNCTION__];
1818 }
1819
1820 // "Getter" for main_title
1821 function getMainTitle () {
1822         // Do we have cache?
1823         if (!isset($GLOBALS[__FUNCTION__])) {
1824                 // Determine it
1825                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1826         } // END - if
1827
1828         // Return cache
1829         return $GLOBALS[__FUNCTION__];
1830 }
1831
1832 // "Getter" for file_hash
1833 function getFileHash () {
1834         // Do we have cache?
1835         if (!isset($GLOBALS[__FUNCTION__])) {
1836                 // Determine it
1837                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1838         } // END - if
1839
1840         // Return cache
1841         return $GLOBALS[__FUNCTION__];
1842 }
1843
1844 // "Getter" for pass_scramble
1845 function getPassScramble () {
1846         // Do we have cache?
1847         if (!isset($GLOBALS[__FUNCTION__])) {
1848                 // Determine it
1849                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1850         } // END - if
1851
1852         // Return cache
1853         return $GLOBALS[__FUNCTION__];
1854 }
1855
1856 // "Getter" for ap_inactive_since
1857 function getApInactiveSince () {
1858         // Do we have cache?
1859         if (!isset($GLOBALS[__FUNCTION__])) {
1860                 // Determine it
1861                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1862         } // END - if
1863
1864         // Return cache
1865         return $GLOBALS[__FUNCTION__];
1866 }
1867
1868 // "Getter" for user_min_confirmed
1869 function getUserMinConfirmed () {
1870         // Do we have cache?
1871         if (!isset($GLOBALS[__FUNCTION__])) {
1872                 // Determine it
1873                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1874         } // END - if
1875
1876         // Return cache
1877         return $GLOBALS[__FUNCTION__];
1878 }
1879
1880 // "Getter" for auto_purge
1881 function getAutoPurge () {
1882         // Do we have cache?
1883         if (!isset($GLOBALS[__FUNCTION__])) {
1884                 // Determine it
1885                 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1886         } // END - if
1887
1888         // Return cache
1889         return $GLOBALS[__FUNCTION__];
1890 }
1891
1892 // "Getter" for bonus_userid
1893 function getBonusUserid () {
1894         // Do we have cache?
1895         if (!isset($GLOBALS[__FUNCTION__])) {
1896                 // Determine it
1897                 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1898         } // END - if
1899
1900         // Return cache
1901         return $GLOBALS[__FUNCTION__];
1902 }
1903
1904 // "Getter" for ap_inactive_time
1905 function getApInactiveTime () {
1906         // Do we have cache?
1907         if (!isset($GLOBALS[__FUNCTION__])) {
1908                 // Determine it
1909                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1910         } // END - if
1911
1912         // Return cache
1913         return $GLOBALS[__FUNCTION__];
1914 }
1915
1916 // "Getter" for ap_dm_timeout
1917 function getApDmTimeout () {
1918         // Do we have cache?
1919         if (!isset($GLOBALS[__FUNCTION__])) {
1920                 // Determine it
1921                 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1922         } // END - if
1923
1924         // Return cache
1925         return $GLOBALS[__FUNCTION__];
1926 }
1927
1928 // "Getter" for ap_tasks_time
1929 function getApTasksTime () {
1930         // Do we have cache?
1931         if (!isset($GLOBALS[__FUNCTION__])) {
1932                 // Determine it
1933                 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1934         } // END - if
1935
1936         // Return cache
1937         return $GLOBALS[__FUNCTION__];
1938 }
1939
1940 // "Getter" for ap_unconfirmed_time
1941 function getApUnconfirmedTime () {
1942         // Do we have cache?
1943         if (!isset($GLOBALS[__FUNCTION__])) {
1944                 // Determine it
1945                 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1946         } // END - if
1947
1948         // Return cache
1949         return $GLOBALS[__FUNCTION__];
1950 }
1951
1952 // "Getter" for points
1953 function getPoints () {
1954         // Do we have cache?
1955         if (!isset($GLOBALS[__FUNCTION__])) {
1956                 // Determine it
1957                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1958         } // END - if
1959
1960         // Return cache
1961         return $GLOBALS[__FUNCTION__];
1962 }
1963
1964 // "Getter" for slogan
1965 function getSlogan () {
1966         // Do we have cache?
1967         if (!isset($GLOBALS[__FUNCTION__])) {
1968                 // Determine it
1969                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1970         } // END - if
1971
1972         // Return cache
1973         return $GLOBALS[__FUNCTION__];
1974 }
1975
1976 // "Getter" for copy
1977 function getCopy () {
1978         // Do we have cache?
1979         if (!isset($GLOBALS[__FUNCTION__])) {
1980                 // Determine it
1981                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1982         } // END - if
1983
1984         // Return cache
1985         return $GLOBALS[__FUNCTION__];
1986 }
1987
1988 // "Getter" for webmaster
1989 function getWebmaster () {
1990         // Do we have cache?
1991         if (!isset($GLOBALS[__FUNCTION__])) {
1992                 // Determine it
1993                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1994         } // END - if
1995
1996         // Return cache
1997         return $GLOBALS[__FUNCTION__];
1998 }
1999
2000 // "Getter" for sql_count
2001 function getSqlCount () {
2002         // Do we have cache?
2003         if (!isset($GLOBALS[__FUNCTION__])) {
2004                 // Determine it
2005                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2006         } // END - if
2007
2008         // Return cache
2009         return $GLOBALS[__FUNCTION__];
2010 }
2011
2012 // "Getter" for num_templates
2013 function getNumTemplates () {
2014         // Do we have cache?
2015         if (!isset($GLOBALS[__FUNCTION__])) {
2016                 // Determine it
2017                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2018         } // END - if
2019
2020         // Return cache
2021         return $GLOBALS[__FUNCTION__];
2022 }
2023
2024 // "Getter" for dns_cache_timeout
2025 function getDnsCacheTimeout () {
2026         // Do we have cache?
2027         if (!isset($GLOBALS[__FUNCTION__])) {
2028                 // Determine it
2029                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2030         } // END - if
2031
2032         // Return cache
2033         return $GLOBALS[__FUNCTION__];
2034 }
2035
2036 // "Getter" for menu_blur_spacer
2037 function getMenuBlurSpacer () {
2038         // Do we have cache?
2039         if (!isset($GLOBALS[__FUNCTION__])) {
2040                 // Determine it
2041                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2042         } // END - if
2043
2044         // Return cache
2045         return $GLOBALS[__FUNCTION__];
2046 }
2047
2048 // "Getter" for points_register
2049 function getPointsRegister () {
2050         // Do we have cache?
2051         if (!isset($GLOBALS[__FUNCTION__])) {
2052                 // Determine it
2053                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2054         } // END - if
2055
2056         // Return cache
2057         return $GLOBALS[__FUNCTION__];
2058 }
2059
2060 // "Getter" for points_ref
2061 function getPointsRef () {
2062         // Do we have cache?
2063         if (!isset($GLOBALS[__FUNCTION__])) {
2064                 // Determine it
2065                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2066         } // END - if
2067
2068         // Return cache
2069         return $GLOBALS[__FUNCTION__];
2070 }
2071
2072 // "Getter" for ref_payout
2073 function getRefPayout () {
2074         // Do we have cache?
2075         if (!isset($GLOBALS[__FUNCTION__])) {
2076                 // Determine it
2077                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2078         } // END - if
2079
2080         // Return cache
2081         return $GLOBALS[__FUNCTION__];
2082 }
2083
2084 // "Getter" for online_timeout
2085 function getOnlineTimeout () {
2086         // Do we have cache?
2087         if (!isset($GLOBALS[__FUNCTION__])) {
2088                 // Determine it
2089                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2090         } // END - if
2091
2092         // Return cache
2093         return $GLOBALS[__FUNCTION__];
2094 }
2095
2096 // "Getter" for index_home
2097 function getIndexHome () {
2098         // Do we have cache?
2099         if (!isset($GLOBALS[__FUNCTION__])) {
2100                 // Determine it
2101                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2102         } // END - if
2103
2104         // Return cache
2105         return $GLOBALS[__FUNCTION__];
2106 }
2107
2108 // "Getter" for one_day
2109 function getOneDay () {
2110         // Do we have cache?
2111         if (!isset($GLOBALS[__FUNCTION__])) {
2112                 // Determine it
2113                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2114         } // END - if
2115
2116         // Return cache
2117         return $GLOBALS[__FUNCTION__];
2118 }
2119
2120 // "Getter" for activate_xchange
2121 function getActivateXchange () {
2122         // Do we have cache?
2123         if (!isset($GLOBALS[__FUNCTION__])) {
2124                 // Determine it
2125                 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2126         } // END - if
2127
2128         // Return cache
2129         return $GLOBALS[__FUNCTION__];
2130 }
2131
2132 // "Getter" for img_type
2133 function getImgType () {
2134         // Do we have cache?
2135         if (!isset($GLOBALS[__FUNCTION__])) {
2136                 // Determine it
2137                 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2138         } // END - if
2139
2140         // Return cache
2141         return $GLOBALS[__FUNCTION__];
2142 }
2143
2144 // "Getter" for code_length
2145 function getCodeLength () {
2146         // Do we have cache?
2147         if (!isset($GLOBALS[__FUNCTION__])) {
2148                 // Determine it
2149                 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2150         } // END - if
2151
2152         // Return cache
2153         return $GLOBALS[__FUNCTION__];
2154 }
2155
2156 // "Getter" for least_cats
2157 function getLeastCats () {
2158         // Do we have cache?
2159         if (!isset($GLOBALS[__FUNCTION__])) {
2160                 // Determine it
2161                 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2162         } // END - if
2163
2164         // Return cache
2165         return $GLOBALS[__FUNCTION__];
2166 }
2167
2168 // "Getter" for pass_len
2169 function getPassLen () {
2170         // Do we have cache?
2171         if (!isset($GLOBALS[__FUNCTION__])) {
2172                 // Determine it
2173                 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2174         } // END - if
2175
2176         // Return cache
2177         return $GLOBALS[__FUNCTION__];
2178 }
2179
2180 // "Getter" for admin_menu
2181 function getAdminMenu () {
2182         // Do we have cache?
2183         if (!isset($GLOBALS[__FUNCTION__])) {
2184                 // Determine it
2185                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2186         } // END - if
2187
2188         // Return cache
2189         return $GLOBALS[__FUNCTION__];
2190 }
2191
2192 // "Getter" for last_month
2193 function getLastMonth () {
2194         // Do we have cache?
2195         if (!isset($GLOBALS[__FUNCTION__])) {
2196                 // Determine it
2197                 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2198         } // END - if
2199
2200         // Return cache
2201         return $GLOBALS[__FUNCTION__];
2202 }
2203
2204 // "Getter" for max_send
2205 function getMaxSend () {
2206         // Do we have cache?
2207         if (!isset($GLOBALS[__FUNCTION__])) {
2208                 // Determine it
2209                 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2210         } // END - if
2211
2212         // Return cache
2213         return $GLOBALS[__FUNCTION__];
2214 }
2215
2216 // "Getter" for mails_page
2217 function getMailsPage () {
2218         // Do we have cache?
2219         if (!isset($GLOBALS[__FUNCTION__])) {
2220                 // Determine it
2221                 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2222         } // END - if
2223
2224         // Return cache
2225         return $GLOBALS[__FUNCTION__];
2226 }
2227
2228 // "Getter" for rand_no
2229 function getRandNo () {
2230         // Do we have cache?
2231         if (!isset($GLOBALS[__FUNCTION__])) {
2232                 // Determine it
2233                 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2234         } // END - if
2235
2236         // Return cache
2237         return $GLOBALS[__FUNCTION__];
2238 }
2239
2240 // "Getter" for __DB_NAME
2241 function getDbName () {
2242         // Do we have cache?
2243         if (!isset($GLOBALS[__FUNCTION__])) {
2244                 // Determine it
2245                 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2246         } // END - if
2247
2248         // Return cache
2249         return $GLOBALS[__FUNCTION__];
2250 }
2251
2252 // "Getter" for DOMAIN
2253 function getDomain () {
2254         // Do we have cache?
2255         if (!isset($GLOBALS[__FUNCTION__])) {
2256                 // Determine it
2257                 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2258         } // END - if
2259
2260         // Return cache
2261         return $GLOBALS[__FUNCTION__];
2262 }
2263
2264 // "Getter" for proxy_username
2265 function getProxyUsername () {
2266         // Do we have cache?
2267         if (!isset($GLOBALS[__FUNCTION__])) {
2268                 // Determine it
2269                 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2270         } // END - if
2271
2272         // Return cache
2273         return $GLOBALS[__FUNCTION__];
2274 }
2275
2276 // "Getter" for proxy_password
2277 function getProxyPassword () {
2278         // Do we have cache?
2279         if (!isset($GLOBALS[__FUNCTION__])) {
2280                 // Determine it
2281                 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2282         } // END - if
2283
2284         // Return cache
2285         return $GLOBALS[__FUNCTION__];
2286 }
2287
2288 // "Getter" for proxy_host
2289 function getProxyHost () {
2290         // Do we have cache?
2291         if (!isset($GLOBALS[__FUNCTION__])) {
2292                 // Determine it
2293                 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2294         } // END - if
2295
2296         // Return cache
2297         return $GLOBALS[__FUNCTION__];
2298 }
2299
2300 // "Getter" for proxy_port
2301 function getProxyPort () {
2302         // Do we have cache?
2303         if (!isset($GLOBALS[__FUNCTION__])) {
2304                 // Determine it
2305                 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2306         } // END - if
2307
2308         // Return cache
2309         return $GLOBALS[__FUNCTION__];
2310 }
2311
2312 // "Getter" for SMTP_HOSTNAME
2313 function getSmtpHostname () {
2314         // Do we have cache?
2315         if (!isset($GLOBALS[__FUNCTION__])) {
2316                 // Determine it
2317                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2318         } // END - if
2319
2320         // Return cache
2321         return $GLOBALS[__FUNCTION__];
2322 }
2323
2324 // "Getter" for SMTP_USER
2325 function getSmtpUser () {
2326         // Do we have cache?
2327         if (!isset($GLOBALS[__FUNCTION__])) {
2328                 // Determine it
2329                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2330         } // END - if
2331
2332         // Return cache
2333         return $GLOBALS[__FUNCTION__];
2334 }
2335
2336 // "Getter" for SMTP_PASSWORD
2337 function getSmtpPassword () {
2338         // Do we have cache?
2339         if (!isset($GLOBALS[__FUNCTION__])) {
2340                 // Determine it
2341                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2342         } // END - if
2343
2344         // Return cache
2345         return $GLOBALS[__FUNCTION__];
2346 }
2347
2348 // "Getter" for points_word
2349 function getPointsWord () {
2350         // Do we have cache?
2351         if (!isset($GLOBALS[__FUNCTION__])) {
2352                 // Determine it
2353                 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2354         } // END - if
2355
2356         // Return cache
2357         return $GLOBALS[__FUNCTION__];
2358 }
2359
2360 // "Getter" for profile_lock
2361 function getProfileLock () {
2362         // Do we have cache?
2363         if (!isset($GLOBALS[__FUNCTION__])) {
2364                 // Determine it
2365                 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2366         } // END - if
2367
2368         // Return cache
2369         return $GLOBALS[__FUNCTION__];
2370 }
2371
2372 // "Getter" for url_tlock
2373 function getUrlTlock () {
2374         // Do we have cache?
2375         if (!isset($GLOBALS[__FUNCTION__])) {
2376                 // Determine it
2377                 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2378         } // END - if
2379
2380         // Return cache
2381         return $GLOBALS[__FUNCTION__];
2382 }
2383
2384 // "Getter" for title_left
2385 function getTitleLeft () {
2386         // Do we have cache?
2387         if (!isset($GLOBALS[__FUNCTION__])) {
2388                 // Determine it
2389                 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2390         } // END - if
2391
2392         // Return cache
2393         return $GLOBALS[__FUNCTION__];
2394 }
2395
2396 // "Getter" for title_right
2397 function getTitleRight () {
2398         // Do we have cache?
2399         if (!isset($GLOBALS[__FUNCTION__])) {
2400                 // Determine it
2401                 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2402         } // END - if
2403
2404         // Return cache
2405         return $GLOBALS[__FUNCTION__];
2406 }
2407
2408 // "Getter" for title_middle
2409 function getTitleMiddle () {
2410         // Do we have cache?
2411         if (!isset($GLOBALS[__FUNCTION__])) {
2412                 // Determine it
2413                 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2414         } // END - if
2415
2416         // Return cache
2417         return $GLOBALS[__FUNCTION__];
2418 }
2419
2420 // Getter for 'check_double_email'
2421 function getCheckDoubleEmail () {
2422         // Is the cache entry set?
2423         if (!isset($GLOBALS[__FUNCTION__])) {
2424                 // No, so determine it
2425                 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2426         } // END - if
2427
2428         // Return cached entry
2429         return $GLOBALS[__FUNCTION__];
2430 }
2431
2432 // Checks whether 'check_double_email' is 'Y'
2433 function isCheckDoubleEmailEnabled () {
2434         // Is the cache entry set?
2435         if (!isset($GLOBALS[__FUNCTION__])) {
2436                 // No, so determine it
2437                 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2438         } // END - if
2439
2440         // Return cached entry
2441         return $GLOBALS[__FUNCTION__];
2442 }
2443
2444 // Getter for 'display_home_in_index'
2445 function getDisplayHomeInIndex () {
2446         // Is the cache entry set?
2447         if (!isset($GLOBALS[__FUNCTION__])) {
2448                 // No, so determine it
2449                 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2450         } // END - if
2451
2452         // Return cached entry
2453         return $GLOBALS[__FUNCTION__];
2454 }
2455
2456 // Checks whether 'display_home_in_index' is 'Y'
2457 function isDisplayHomeInIndexEnabled () {
2458         // Is the cache entry set?
2459         if (!isset($GLOBALS[__FUNCTION__])) {
2460                 // No, so determine it
2461                 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2462         } // END - if
2463
2464         // Return cached entry
2465         return $GLOBALS[__FUNCTION__];
2466 }
2467
2468 // Getter for 'admin_menu_javascript'
2469 function getAdminMenuJavascript () {
2470         // Is the cache entry set?
2471         if (!isset($GLOBALS[__FUNCTION__])) {
2472                 // No, so determine it
2473                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2474         } // END - if
2475
2476         // Return cached entry
2477         return $GLOBALS[__FUNCTION__];
2478 }
2479
2480 // Getter for 'points_remove_account'
2481 function getPointsRemoveAccount () {
2482         // Is the cache entry set?
2483         if (!isset($GLOBALS[__FUNCTION__])) {
2484                 // No, so determine it
2485                 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2486         } // END - if
2487
2488         // Return cached entry
2489         return $GLOBALS[__FUNCTION__];
2490 }
2491
2492 // Checks whether proxy configuration is used
2493 function isProxyUsed () {
2494         // Do we have cache?
2495         if (!isset($GLOBALS[__FUNCTION__])) {
2496                 // Determine it
2497                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2498         } // END - if
2499
2500         // Return cache
2501         return $GLOBALS[__FUNCTION__];
2502 }
2503
2504 // Checks whether POST data contains selections
2505 function ifPostContainsSelections ($element = 'sel') {
2506         // Do we have cache?
2507         if (!isset($GLOBALS[__FUNCTION__][$element])) {
2508                 // Determine it
2509                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2510         } // END - if
2511
2512         // Return cache
2513         return $GLOBALS[__FUNCTION__][$element];
2514 }
2515
2516 // Checks whether verbose_sql is Y and returns true/false if so
2517 function isVerboseSqlEnabled () {
2518         // Do we have cache?
2519         if (!isset($GLOBALS[__FUNCTION__])) {
2520                 // Determine it
2521                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2522         } // END - if
2523
2524         // Return cache
2525         return $GLOBALS[__FUNCTION__];
2526 }
2527
2528 // "Getter" for total user points
2529 function getTotalPoints ($userid) {
2530         // Do we have cache?
2531         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2532                 // Init array for filter chain
2533                 $data = array(
2534                         'userid' => $userid,
2535                         'points' => 0
2536                 );
2537
2538                 // Run filter chain for getting more point values
2539                 $data = runFilterChain('get_total_points', $data);
2540
2541                 // Determine it
2542                 $GLOBALS[__FUNCTION__][$userid] = $data['points']  - getUserUsedPoints($userid);
2543         } // END - if
2544
2545         // Return cache
2546         return $GLOBALS[__FUNCTION__][$userid];
2547 }
2548
2549 // Wrapper to get used points for given userid
2550 function getUserUsedPoints ($userid) {
2551         // Do we have cache?
2552         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2553                 // Determine it
2554                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2555         } // END - if
2556
2557         // Return cache
2558         return $GLOBALS[__FUNCTION__][$userid];
2559 }
2560
2561 // Wrapper to check if url_blacklist is enabled
2562 function isUrlBlacklistEnabled () {
2563         // Do we have cache?
2564         if (!isset($GLOBALS[__FUNCTION__])) {
2565                 // Determine it
2566                 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2567         } // END - if
2568
2569         // Return cache
2570         return $GLOBALS[__FUNCTION__];
2571 }
2572
2573 // Checks whether direct payment is allowed in configuration
2574 function isDirectPaymentEnabled () {
2575         // Do we have cache?
2576         if (!isset($GLOBALS[__FUNCTION__])) {
2577                 // Determine it
2578                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2579         } // END - if
2580
2581         // Return cache
2582         return $GLOBALS[__FUNCTION__];
2583 }
2584
2585 // Checks whether JavaScript-based admin menu is enabled
2586 function isAdminMenuJavascriptEnabled () {
2587         // Do we have cache?
2588         if (!isset($GLOBALS[__FUNCTION__])) {
2589                 // Determine it
2590                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
2591         } // END - if
2592
2593         // Return cache
2594         return $GLOBALS[__FUNCTION__];
2595 }
2596
2597 // Wrapper to check if current task is for extension (not update)
2598 function isExtensionTask ($content) {
2599         // Do we have cache?
2600         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2601                 // Determine it
2602                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2603         } // END - if
2604
2605         // Return cache
2606         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2607 }
2608
2609 // Getter for 'mt_start'
2610 function getMtStart () {
2611         // Is the cache entry set?
2612         if (!isset($GLOBALS[__FUNCTION__])) {
2613                 // No, so determine it
2614                 $GLOBALS[__FUNCTION__] = getConfig('mt_start');
2615         } // END - if
2616
2617         // Return cached entry
2618         return $GLOBALS[__FUNCTION__];
2619 }
2620
2621 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2622 function ifTesterAccountsAllowed () {
2623         // Is the cache entry set?
2624         if (!isset($GLOBALS[__FUNCTION__])) {
2625                 // No, so determine it
2626                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2627         } // END - if
2628
2629         // Return cached entry
2630         return $GLOBALS[__FUNCTION__];
2631 }
2632
2633 // Wrapper to check if output mode is CSS
2634 function isCssOutputMode () {
2635         // Is cache set?
2636         if (!isset($GLOBALS[__FUNCTION__])) {
2637                 // Determine it
2638                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2639                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2640         } // END - if
2641
2642         // Return cache
2643         return $GLOBALS[__FUNCTION__];
2644 }
2645
2646 // Wrapper to check if output mode is HTML
2647 function isHtmlOutputMode () {
2648         // Is cache set?
2649         if (!isset($GLOBALS[__FUNCTION__])) {
2650                 // Determine it
2651                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2652                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2653         } // END - if
2654
2655         // Return cache
2656         return $GLOBALS[__FUNCTION__];
2657 }
2658
2659 // Wrapper to check if output mode is RAW
2660 function isRawOutputMode () {
2661         // Is cache set?
2662         if (!isset($GLOBALS[__FUNCTION__])) {
2663                 // Determine it
2664                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2665                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2666         } // END - if
2667
2668         // Return cache
2669         return $GLOBALS[__FUNCTION__];
2670 }
2671
2672 // Wrapper to check if output mode is AJAX
2673 function isAjaxOutputMode () {
2674         // Is cache set?
2675         if (!isset($GLOBALS[__FUNCTION__])) {
2676                 // Determine it
2677                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2678                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2679         } // END - if
2680
2681         // Return cache
2682         return $GLOBALS[__FUNCTION__];
2683 }
2684
2685 // Wrapper to check if output mode is image
2686 function isImageOutputMode () {
2687         // Is cache set?
2688         if (!isset($GLOBALS[__FUNCTION__])) {
2689                 // Determine it
2690                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2691                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
2692         } // END - if
2693
2694         // Return cache
2695         return $GLOBALS[__FUNCTION__];
2696 }
2697
2698 // Wrapper to generate a user email link
2699 function generateWrappedUserEmailLink ($email) {
2700         // Just call the inner function
2701         return generateEmailLink($email, 'user_data');
2702 }
2703
2704 // Wrapper to check if user points are locked
2705 function ifUserPointsLocked ($userid) {
2706         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2707         // Do we have cache?
2708         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2709                 // Determine it
2710                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2711         } // END - if
2712
2713         // Return cache
2714         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2715         return $GLOBALS[__FUNCTION__][$userid];
2716 }
2717
2718 // Appends a line to an existing file or creates it instantly with given content.
2719 // This function does always add a new-line character to every line.
2720 function appendLineToFile ($file, $line) {
2721         $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2722         fwrite($fp, $line . chr(10));
2723         fclose($fp);
2724 }
2725
2726 // Wrapper for changeDataInFile() but with full path added
2727 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2728         // Add full path
2729         $FQFN = getPath() . $FQFN;
2730
2731         // Call inner function
2732         return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2733 }
2734
2735 // Wrapper for changing entries in config-local.php
2736 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2737         // Call the inner function
2738         return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2739 }
2740
2741 // Shortens ucfirst(strtolower()) calls
2742 function firstCharUpperCase ($str) {
2743         return ucfirst(strtolower($str));
2744 }
2745
2746 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2747 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2748         // Get the configuration entry
2749         $configValue = getConfig($configEntry);
2750
2751         // Call inner method
2752         return createTimeSelections($configValue, $configEntry, $stamps, $align);
2753 }
2754
2755 // Shortens converting of German comma to Computer's version in POST data
2756 function convertCommaToDotInPostData ($postEntry) {
2757         // Read and convert given entry
2758         $postValue = convertCommaToDot(postRequestElement($postEntry));
2759
2760         // ... and set it again
2761         setPostRequestElement($postEntry, $postValue);
2762 }
2763
2764 // Converts German commas to Computer's version in all entries
2765 function convertCommaToDotInPostDataArray ($postEntries) {
2766         // Replace german decimal comma with computer decimal dot
2767         foreach ($postEntries as $entry) {
2768                 // Is the entry there?
2769                 if (isPostRequestElementSet($entry)) {
2770                         // Then convert it
2771                         convertCommaToDotInPostData($entry);
2772                 } // END - if
2773         } // END - foreach
2774 }
2775
2776 /**
2777  * Parses a string into a US formated float variable, taken from user comments
2778  * from PHP documentation website.
2779  *
2780  * @param       $floatString    A string holding a float expression
2781  * @return      $float                  Corresponding float variable
2782  * @author      chris<at>georgakopoulos<dot>com
2783  * @link        http://de.php.net/manual/en/function.floatval.php#92563
2784  */
2785 function parseFloat ($floatString){
2786         // Load locale info
2787         $LocaleInfo = localeconv();
2788
2789         // Remove thousand separators
2790         $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
2791
2792         // Convert decimal point
2793         $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2794
2795         // Return float value of converted string
2796         return floatval($floatString);
2797 }
2798
2799 // Generates a YES/NO option list from given default
2800 function generateYesNoOptions ($defaultValue = '') {
2801         // Generate it
2802         return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2803 }
2804
2805 // "Getter" for total available receivers
2806 function getTotalReceivers ($mode = 'normal') {
2807         // Get num rows
2808         $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
2809
2810         // Return value
2811         return $numRows;
2812 }
2813
2814 // Wrapper "getter" to get total unconfirmed mails for given userid
2815 function getTotalUnconfirmedMails ($userid) {
2816         // Do we have cache?
2817         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2818                 // Determine it
2819                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
2820         } // END - if
2821
2822         // Return cache
2823         return $GLOBALS[__FUNCTION__][$userid];
2824 }
2825
2826 // Checks whether 'mailer_theme' was found in session
2827 function isMailerThemeSet () {
2828         // Is cache set?
2829         if (!isset($GLOBALS[__FUNCTION__])) {
2830                 // Determine it
2831                 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
2832         } // END - if
2833
2834         // Return cache
2835         return $GLOBALS[__FUNCTION__];
2836 }
2837
2838 /**
2839  * Setter for theme in session (This setter does return the success of
2840  * setSession() which is required e.g. for destroySponsorSession().
2841  */
2842 function setMailerTheme ($newTheme) {
2843         // Set it in session
2844         return setSession('mailer_theme', $newTheme);
2845 }
2846
2847 /**
2848  * Getter for theme from session (This getter does return 'mailer_theme' from
2849  * session data or throws an error if not possible
2850  */
2851 function getMailerTheme () {
2852         // Is cache set?
2853         if (!isset($GLOBALS[__FUNCTION__])) {
2854                 // Is 'mailer_theme' set?
2855                 if (!isMailerThemeSet()) {
2856                         // No, then abort here
2857                         reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2858                 } // END - if
2859
2860                 // Get it and store it in cache
2861                 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
2862         } // END - if
2863
2864         // Return cache
2865         return $GLOBALS[__FUNCTION__];
2866 }
2867
2868 // "Getter" for last_module/last_what depending on ext-user version
2869 function getUserLastWhatName () {
2870         // Default is old one: last_module
2871         $columnName = 'last_module';
2872
2873         // Is ext-user up-to-date?
2874         if (isExtensionInstalledAndNewer('user', '0.4.9')) {
2875                 // Yes, then use new one
2876                 $columnName = 'last_what';
2877         } // END - if
2878
2879         // Return it
2880         return $columnName;
2881 }
2882
2883 // "Getter" for all columns for given alias and separator
2884 function getAllPointColumns ($alias = NULL, $separator = ',') {
2885         // Prepare the filter array
2886         $filterData = array(
2887                 'columns'   => '',
2888                 'alias'     => $alias,
2889                 'separator' => $separator
2890         );
2891
2892         // Run the filter
2893         $filterData = runFilterChain('get_all_point_columns', $filterData);
2894
2895         // Return the columns
2896         return $filterData['columns'];
2897 }
2898
2899 // Checks whether the copyright footer (which breaks framesets) is enabled
2900 function ifCopyrightFooterEnabled () {
2901         // Is not unset and not 'N'?
2902         return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
2903 }
2904
2905 /**
2906  * Wrapper to check whether we have a "full page". This means that the actual
2907  * content is not delivered in any frame of a frameset.
2908  */
2909 function isFullPage () {
2910         /*
2911          * The parameter 'frame' is generic and always indicates that this content
2912          * will be output into a frame. Furthermore, if a frameset is reported or
2913          * the copyright line is explicitly deactivated, this cannot be a "full
2914          * page" again.
2915          */
2916         // @TODO Find a way to not use direct module comparison
2917         $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
2918
2919         // Return it
2920         return $isFullPage;
2921 }
2922
2923 // Checks whether frameset_mode is set to true
2924 function isFramesetModeEnabled () {
2925         // Check it
2926         return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === true));
2927 }
2928
2929 // Function to determine correct 'what' value
2930 function determineWhat ($module = NULL) {
2931         // Init default 'what'
2932         $what = 'welcome';
2933
2934         // Is module NULL?
2935         if (is_null($module)) {
2936                 // Then use default
2937                 $module = getModule();
2938         } // END - if
2939
2940         // Is what set?
2941         if (isWhatSet()) {
2942                 // Then use it
2943                 $what = getWhat();
2944         } else {
2945                 // Else try to get it from current module
2946                 $what = getWhatFromModule($module);
2947         }
2948         //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
2949
2950         // Remove any spaces from variable
2951         $what = trim($what);
2952
2953         // Is it empty?
2954         if (empty($what)) {
2955                 // Default action for non-admin menus
2956                 $what = 'welcome';
2957         } else {
2958                 // Secure it
2959                 $what = secureString($what);
2960         }
2961
2962         // Return what
2963         return $what;
2964 }
2965
2966 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
2967 function prependZeros ($mStretch, $length = 2) {
2968         // Return prepended string
2969         return sprintf('%0' . (int) $length . 's', $mStretch);
2970 }
2971
2972 // Wraps convertSelectionsToEpocheTime()
2973 function convertSelectionsToEpocheTimeInPostData ($id) {
2974         // Init variables
2975         $content = array();
2976         $skip = false;
2977
2978         // Get all POST data
2979         $postData = postRequestArray();
2980
2981         // Convert given selection id
2982         convertSelectionsToEpocheTime($postData, $content, $id, $skip);
2983
2984         // Set the POST array back
2985         setPostRequestArray($postData);
2986 }
2987
2988 // Wraps checking if given points account type matches with given in POST data
2989 function ifPointsAccountTypeMatchesPost ($type) {
2990         // Check condition
2991         exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), true).'</pre>');
2992 }
2993
2994 // Gets given user's total referral
2995 function getUsersTotalReferrals ($userid, $level = NULL) {
2996         // Do we have cache?
2997         if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
2998                 // Is the level NULL?
2999                 if (is_null($level)) {
3000                         // Get total amount (all levels)
3001                         $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true);
3002                 } else {
3003                         // Get it from user refs
3004                         $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true, ' AND `level`=' . bigintval($level));
3005                 }
3006         } // END - if
3007
3008         // Return it
3009         return $GLOBALS[__FUNCTION__][$userid][$level];
3010 }
3011
3012 // Gets given user's total referral
3013 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3014         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3015         // Do we have cache?
3016         if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3017                 // Default is all refs
3018                 $add = '';
3019
3020                 // Is the not level NULL?
3021                 if (!is_null($level)) {
3022                         // Then add referral level
3023                         $add = ' AND r.`level`=' . bigintval($level);
3024                 } // END - if
3025
3026                 // Check for all referrals
3027                 $result = SQL_QUERY_ESC("SELECT
3028         COUNT(d.`userid`) AS `cnt`
3029 FROM
3030         `{?_MYSQL_PREFIX?}_user_data` AS d
3031 INNER JOIN
3032         `{?_MYSQL_PREFIX?}_user_refs` AS r
3033 ON
3034         d.`userid`=r.`refid`
3035 WHERE
3036         d.`status` != 'CONFIRMED' AND
3037         r.`userid`=%s
3038         " . $add . "
3039 ORDER BY
3040         d.`userid` ASC
3041 LIMIT 1",
3042                         array(
3043                                 $userid
3044                         ), __FUNCTION__, __LINE__);
3045
3046                 // Load count
3047                 list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
3048
3049                 // Free result
3050                 SQL_FREERESULT($result);
3051         } // END - if
3052
3053         // Return it
3054         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3055         return $GLOBALS[__FUNCTION__][$userid][$level];
3056 }
3057
3058 // Converts, if found, dollar data to get element
3059 function convertDollarDataToGetElement ($data) {
3060         // Is first char a dollar?
3061         if (substr($data, 0, 1) == chr(36)) {
3062                 // Use last part for getRequestElement()
3063                 $data = getRequestElement(substr($data, 1));
3064         } // END - if
3065
3066         // Return it
3067         return $data;
3068 }
3069
3070 // Wrapper function for SQL layer to speed-up things
3071 function SQL_DEBUG_ENABLED () {
3072         // Is there cache?
3073         if (!isset($GLOBALS[__FUNCTION__])) {
3074                 // Determine it
3075                 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3076         } // END - if
3077
3078         // Return cache
3079         return $GLOBALS[__FUNCTION__];
3080 }
3081
3082 // [EOF]
3083 ?>