Commented out noisy debug lines
[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                 // Debug message, may be noisy
976                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
977
978                 // Abort here
979                 return false;
980         } // END - if
981
982         // Is it cached?
983         if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
984                 // Determine it
985                 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
986         } // END - if
987
988         // Return the result
989         return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
990 }
991
992 // Setter for current userid
993 function setCurrentUserId ($userid) {
994         // Debug message
995         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - ENTERED!');
996
997         // Is the cache from below functions different?
998         if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) {
999                 // Then unset both
1000                 unsetCurrentUserId();
1001         } // END - if
1002
1003         // Set userid
1004         $GLOBALS['current_userid'] = bigintval($userid);
1005
1006         // Unset it to re-determine the actual state
1007         unset($GLOBALS['is_userdata_valid'][$userid]);
1008
1009         // Debug message
1010         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - EXIT!');
1011 }
1012
1013 // Getter for current userid
1014 function getCurrentUserId () {
1015         // Is cache set?
1016         if (!isset($GLOBALS[__FUNCTION__])) {
1017                 // Userid must be set before it can be used
1018                 if (!isCurrentUserIdSet()) {
1019                         // Not set
1020                         reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1021                 } // END - if
1022
1023                 // Set userid in cache
1024                 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1025         } // END - if
1026
1027         // Return cache
1028         return $GLOBALS[__FUNCTION__];
1029 }
1030
1031 // Checks if current userid is set
1032 function isCurrentUserIdSet () {
1033         // Do we have cache?
1034         if (!isset($GLOBALS[__FUNCTION__])) {
1035                 // Determine it
1036                 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1037         } // END - if
1038
1039         // Return cache
1040         return $GLOBALS[__FUNCTION__];
1041 }
1042
1043 // Unsets current userid
1044 function unsetCurrentUserId () {
1045         // Do we have it set?
1046         if (isset($GLOBALS['current_userid'])) {
1047                 // Unset this, too
1048                 unset($GLOBALS['isValidUserId'][$GLOBALS['current_userid']]);
1049         } // END - if
1050
1051         // Unset all cache entries
1052         unset($GLOBALS['current_userid']);
1053         unset($GLOBALS['getCurrentUserId']);
1054         unset($GLOBALS['isCurrentUserIdSet']);
1055 }
1056
1057 // Checks whether we are debugging template cache
1058 function isDebuggingTemplateCache () {
1059         // Do we have cache?
1060         if (!isset($GLOBALS[__FUNCTION__])) {
1061                 // Determine it
1062                 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1063         } // END - if
1064
1065         // Return cache
1066         return $GLOBALS[__FUNCTION__];
1067 }
1068
1069 // Wrapper for fetchUserData() and getUserData() calls
1070 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1071         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1072         // Is it cached?
1073         if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1074                 // Default is NULL
1075                 $data = NULL;
1076
1077                 // Can we fetch the user data?
1078                 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1079                         // Now get the data back
1080                         $data = getUserData($valueColumn);
1081                 } // END - if
1082
1083                 // Cache it
1084                 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1085         } // END - if
1086
1087         // Return it
1088         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1089         return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1090 }
1091
1092 // Wrapper for strpos() to ease porting from deprecated ereg() function
1093 function isInString ($needle, $haystack) {
1094         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1095         return (strpos($haystack, $needle) !== false);
1096 }
1097
1098 // Wrapper for strpos() to ease porting from deprecated eregi() function
1099 // This function is case-insensitive
1100 function isInStringIgnoreCase ($needle, $haystack) {
1101         return (isInString(strtolower($needle), strtolower($haystack)));
1102 }
1103
1104 // Wrapper to check for if fatal errors where detected
1105 function ifFatalErrorsDetected () {
1106         // Just call the inner function
1107         return (getTotalFatalErrors() > 0);
1108 }
1109
1110 // Checks whether a HTTP status has been set
1111 function isHttpStatusSet () {
1112         // Is it set and not empty?
1113         return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1114 }
1115
1116 // Setter for HTTP status
1117 function setHttpStatus ($status) {
1118         $GLOBALS['http_status'] = (string) $status;
1119 }
1120
1121 // Getter for HTTP status
1122 function getHttpStatus () {
1123         // Is the status set?
1124         if (!isHttpStatusSet()) {
1125                 // Abort here
1126                 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1127         } // END - if
1128
1129         // Return it
1130         return $GLOBALS['http_status'];
1131 }
1132
1133 /**
1134  * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1135  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1136  *
1137  * ----------------------------------------------------------------------------
1138  * If you want to redirect, please use redirectToUrl(); instead
1139  * ----------------------------------------------------------------------------
1140  *
1141  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1142  *
1143  * @link    http://support.microsoft.com/kb/q176113/
1144  * @author  Andreas Gohr <andi@splitbrain.org>
1145  * @access  private
1146  */
1147 function sendRawRedirect ($url) {
1148         // Clear output buffer
1149         clearOutputBuffer();
1150
1151         // Clear own output buffer
1152         $GLOBALS['__output'] = '';
1153
1154         // To make redirects working (no content type), output mode must be raw
1155         setOutputMode(-1);
1156
1157         // Send helping header
1158         setHttpStatus('302 Found');
1159
1160         // always close the session
1161         session_write_close();
1162
1163         // Revert entity &amp;
1164         $url = str_replace('&amp;', '&', $url);
1165
1166         // check if running on IIS < 6 with CGI-PHP
1167         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1168                 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1169                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1170                 ($matches[1] < 6)) {
1171                 // Send the IIS header
1172                 addHttpHeader('Refresh: 0;url=' . $url);
1173         } else {
1174                 // Send generic header
1175                 addHttpHeader('Location: ' . $url);
1176         }
1177
1178         // Shutdown here
1179         doShutdown();
1180 }
1181
1182 // Determines the country of the given user id
1183 function determineCountry ($userid) {
1184         // Do we have cache?
1185         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1186                 // Default is 'invalid'
1187                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1188
1189                 // Is extension country active?
1190                 if (isExtensionActive('country')) {
1191                         // Determine the right country code through the country id
1192                         $id = getUserData('country_code');
1193
1194                         // Then handle it over
1195                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1196                 } else {
1197                         // Get raw code from user data
1198                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1199                 }
1200         } // END - if
1201
1202         // Return cache
1203         return $GLOBALS[__FUNCTION__][$userid];
1204 }
1205
1206 // "Getter" for total confirmed user accounts
1207 function getTotalConfirmedUser () {
1208         // Is it cached?
1209         if (!isset($GLOBALS[__FUNCTION__])) {
1210                 // Then do it
1211                 if (isExtensionActive('user')) {
1212                         $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1213                 } else {
1214                         $GLOBALS[__FUNCTION__] = 0;
1215                 }
1216         } // END - if
1217
1218         // Return cached value
1219         return $GLOBALS[__FUNCTION__];
1220 }
1221
1222 // "Getter" for total unconfirmed user accounts
1223 function getTotalUnconfirmedUser () {
1224         // Is it cached?
1225         if (!isset($GLOBALS[__FUNCTION__])) {
1226                 // Then do it
1227                 if (isExtensionActive('user')) {
1228                         $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1229                 } else {
1230                         $GLOBALS[__FUNCTION__] = 0;
1231                 }
1232         } // END - if
1233
1234         // Return cached value
1235         return $GLOBALS[__FUNCTION__];
1236 }
1237
1238 // "Getter" for total locked user accounts
1239 function getTotalLockedUser () {
1240         // Is it cached?
1241         if (!isset($GLOBALS[__FUNCTION__])) {
1242                 // Then do it
1243                 if (isExtensionActive('user')) {
1244                         $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1245                 } else {
1246                         $GLOBALS[__FUNCTION__] = 0;
1247                 }
1248         } // END - if
1249
1250         // Return cached value
1251         return $GLOBALS[__FUNCTION__];
1252 }
1253
1254 // "Getter" for total locked user accounts
1255 function getTotalRandomRefidUser () {
1256         // Is it cached?
1257         if (!isset($GLOBALS[__FUNCTION__])) {
1258                 // Then do it
1259                 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1260                         $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, runFilterChain('user_exclusion_sql', ' '), '>=');
1261                 } else {
1262                         $GLOBALS[__FUNCTION__] = 0;
1263                 }
1264         } // END - if
1265
1266         // Return cached value
1267         return $GLOBALS[__FUNCTION__];
1268 }
1269
1270 // Is given userid valid?
1271 function isValidUserId ($userid) {
1272         // Debug message
1273         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid);
1274
1275         // Do we have cache?
1276         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1277                 // Check it out
1278                 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1279         } // END - if
1280
1281         // Return cache
1282         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',result=' . intval($GLOBALS[__FUNCTION__][$userid]));
1283         return $GLOBALS[__FUNCTION__][$userid];
1284 }
1285
1286 // Encodes entities
1287 function encodeEntities ($str) {
1288         // Secure it first
1289         $str = secureString($str, true, true);
1290
1291         // Encode dollar sign as well
1292         $str = str_replace('$', '&#36;', $str);
1293
1294         // Return it
1295         return $str;
1296 }
1297
1298 // "Getter" for date from patch_ctime
1299 function getDateFromRepository () {
1300         // Is it cached?
1301         if (!isset($GLOBALS[__FUNCTION__])) {
1302                 // Then set it
1303                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1304         } // END - if
1305
1306         // Return cache
1307         return $GLOBALS[__FUNCTION__];
1308 }
1309
1310 // "Getter" for date/time from patch_ctime
1311 function getDateTimeFromRepository () {
1312         // Is it cached?
1313         if (!isset($GLOBALS[__FUNCTION__])) {
1314                 // Then set it
1315                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1316         } // END - if
1317
1318         // Return cache
1319         return $GLOBALS[__FUNCTION__];
1320 }
1321
1322 // Getter for current year (default)
1323 function getYear ($timestamp = NULL) {
1324         // Is it cached?
1325         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1326                 // null is time()
1327                 if (is_null($timestamp)) {
1328                         $timestamp = time();
1329                 } // END - if
1330
1331                 // Then create it
1332                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1333         } // END - if
1334
1335         // Return cache
1336         return $GLOBALS[__FUNCTION__][$timestamp];
1337 }
1338
1339 // Getter for current month (default)
1340 function getMonth ($timestamp = NULL) {
1341         // Is it cached?
1342         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1343                 // If null is set, use time()
1344                 if (is_null($timestamp)) {
1345                         // Use time() which is current timestamp
1346                         $timestamp = time();
1347                 } // END - if
1348
1349                 // Then create it
1350                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1351         } // END - if
1352
1353         // Return cache
1354         return $GLOBALS[__FUNCTION__][$timestamp];
1355 }
1356
1357 // Getter for current hour (default)
1358 function getHour ($timestamp = NULL) {
1359         // Is it cached?
1360         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1361                 // null is time()
1362                 if (is_null($timestamp)) {
1363                         $timestamp = time();
1364                 } // END - if
1365
1366                 // Then create it
1367                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1368         } // END - if
1369
1370         // Return cache
1371         return $GLOBALS[__FUNCTION__][$timestamp];
1372 }
1373
1374 // Getter for current day (default)
1375 function getDay ($timestamp = NULL) {
1376         // Is it cached?
1377         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1378                 // null is time()
1379                 if (is_null($timestamp)) {
1380                         $timestamp = time();
1381                 } // END - if
1382
1383                 // Then create it
1384                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1385         } // END - if
1386
1387         // Return cache
1388         return $GLOBALS[__FUNCTION__][$timestamp];
1389 }
1390
1391 // Getter for current week (default)
1392 function getWeek ($timestamp = NULL) {
1393         // Is it cached?
1394         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1395                 // null is time()
1396                 if (is_null($timestamp)) $timestamp = time();
1397
1398                 // Then create it
1399                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1400         } // END - if
1401
1402         // Return cache
1403         return $GLOBALS[__FUNCTION__][$timestamp];
1404 }
1405
1406 // Getter for current short_hour (default)
1407 function getShortHour ($timestamp = NULL) {
1408         // Is it cached?
1409         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1410                 // null is time()
1411                 if (is_null($timestamp)) $timestamp = time();
1412
1413                 // Then create it
1414                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1415         } // END - if
1416
1417         // Return cache
1418         return $GLOBALS[__FUNCTION__][$timestamp];
1419 }
1420
1421 // Getter for current long_hour (default)
1422 function getLongHour ($timestamp = NULL) {
1423         // Is it cached?
1424         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1425                 // null is time()
1426                 if (is_null($timestamp)) $timestamp = time();
1427
1428                 // Then create it
1429                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1430         } // END - if
1431
1432         // Return cache
1433         return $GLOBALS[__FUNCTION__][$timestamp];
1434 }
1435
1436 // Getter for current second (default)
1437 function getSecond ($timestamp = NULL) {
1438         // Is it cached?
1439         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1440                 // null is time()
1441                 if (is_null($timestamp)) $timestamp = time();
1442
1443                 // Then create it
1444                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1445         } // END - if
1446
1447         // Return cache
1448         return $GLOBALS[__FUNCTION__][$timestamp];
1449 }
1450
1451 // Getter for current minute (default)
1452 function getMinute ($timestamp = NULL) {
1453         // Is it cached?
1454         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1455                 // null is time()
1456                 if (is_null($timestamp)) $timestamp = time();
1457
1458                 // Then create it
1459                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1460         } // END - if
1461
1462         // Return cache
1463         return $GLOBALS[__FUNCTION__][$timestamp];
1464 }
1465
1466 // Checks whether the title decoration is enabled
1467 function isTitleDecorationEnabled () {
1468         // Do we have cache?
1469         if (!isset($GLOBALS[__FUNCTION__])) {
1470                 // Just check it
1471                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1472         } // END - if
1473
1474         // Return cache
1475         return $GLOBALS[__FUNCTION__];
1476 }
1477
1478 // Checks whether filter usage updates are enabled (expensive queries!)
1479 function isFilterUsageUpdateEnabled () {
1480         // Do we have cache?
1481         if (!isset($GLOBALS[__FUNCTION__])) {
1482                 // Determine it
1483                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1484         } // END - if
1485
1486         // Return cache
1487         return $GLOBALS[__FUNCTION__];
1488 }
1489
1490 // Checks whether debugging of weekly resets is enabled
1491 function isWeeklyResetDebugEnabled () {
1492         // Do we have cache?
1493         if (!isset($GLOBALS[__FUNCTION__])) {
1494                 // Determine it
1495                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1496         } // END - if
1497
1498         // Return cache
1499         return $GLOBALS[__FUNCTION__];
1500 }
1501
1502 // Checks whether debugging of monthly resets is enabled
1503 function isMonthlyResetDebugEnabled () {
1504         // Do we have cache?
1505         if (!isset($GLOBALS[__FUNCTION__])) {
1506                 // Determine it
1507                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1508         } // END - if
1509
1510         // Return cache
1511         return $GLOBALS[__FUNCTION__];
1512 }
1513
1514 // Checks whether displaying of debug SQLs are enabled
1515 function isDisplayDebugSqlEnabled () {
1516         // Do we have cache?
1517         if (!isset($GLOBALS[__FUNCTION__])) {
1518                 // Determine it
1519                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1520         } // END - if
1521
1522         // Return cache
1523         return $GLOBALS[__FUNCTION__];
1524 }
1525
1526 // Checks whether module title is enabled
1527 function isModuleTitleEnabled () {
1528         // Do we have cache?
1529         if (!isset($GLOBALS[__FUNCTION__])) {
1530                 // Determine it
1531                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1532         } // END - if
1533
1534         // Return cache
1535         return $GLOBALS[__FUNCTION__];
1536 }
1537
1538 // Checks whether what title is enabled
1539 function isWhatTitleEnabled () {
1540         // Do we have cache?
1541         if (!isset($GLOBALS[__FUNCTION__])) {
1542                 // Determine it
1543                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1544         } // END - if
1545
1546         // Return cache
1547         return $GLOBALS[__FUNCTION__];
1548 }
1549
1550 // Checks whether stats are enabled
1551 function ifInternalStatsEnabled () {
1552         // Do we have cache?
1553         if (!isset($GLOBALS[__FUNCTION__])) {
1554                 // Then determine it
1555                 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1556         } // END - if
1557
1558         // Return cached value
1559         return $GLOBALS[__FUNCTION__];
1560 }
1561
1562 // Checks whether admin-notification of certain user actions is enabled
1563 function isAdminNotificationEnabled () {
1564         // Do we have cache?
1565         if (!isset($GLOBALS[__FUNCTION__])) {
1566                 // Determine it
1567                 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1568         } // END - if
1569
1570         // Return cache
1571         return $GLOBALS[__FUNCTION__];
1572 }
1573
1574 // Checks whether random referral id selection is enabled
1575 function isRandomReferralIdEnabled () {
1576         // Do we have cache?
1577         if (!isset($GLOBALS[__FUNCTION__])) {
1578                 // Determine it
1579                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1580         } // END - if
1581
1582         // Return cache
1583         return $GLOBALS[__FUNCTION__];
1584 }
1585
1586 // "Getter" for default language
1587 function getDefaultLanguage () {
1588         // Do we have cache?
1589         if (!isset($GLOBALS[__FUNCTION__])) {
1590                 // Determine it
1591                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1592         } // END - if
1593
1594         // Return cache
1595         return $GLOBALS[__FUNCTION__];
1596 }
1597
1598 // "Getter" for default referral id
1599 function getDefRefid () {
1600         // Do we have cache?
1601         if (!isset($GLOBALS[__FUNCTION__])) {
1602                 // Determine it
1603                 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1604         } // END - if
1605
1606         // Return cache
1607         return $GLOBALS[__FUNCTION__];
1608 }
1609
1610 // "Getter" for path
1611 function getPath () {
1612         // Do we have cache?
1613         if (!isset($GLOBALS[__FUNCTION__])) {
1614                 // Determine it
1615                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1616         } // END - if
1617
1618         // Return cache
1619         return $GLOBALS[__FUNCTION__];
1620 }
1621
1622 // "Getter" for url
1623 function getUrl () {
1624         // Do we have cache?
1625         if (!isset($GLOBALS[__FUNCTION__])) {
1626                 // Determine it
1627                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1628         } // END - if
1629
1630         // Return cache
1631         return $GLOBALS[__FUNCTION__];
1632 }
1633
1634 // "Getter" for cache_path
1635 function getCachePath () {
1636         // Do we have cache?
1637         if (!isset($GLOBALS[__FUNCTION__])) {
1638                 // Determine it
1639                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1640         } // END - if
1641
1642         // Return cache
1643         return $GLOBALS[__FUNCTION__];
1644 }
1645
1646 // "Getter" for secret_key
1647 function getSecretKey () {
1648         // Do we have cache?
1649         if (!isset($GLOBALS[__FUNCTION__])) {
1650                 // Determine it
1651                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1652         } // END - if
1653
1654         // Return cache
1655         return $GLOBALS[__FUNCTION__];
1656 }
1657
1658 // "Getter" for SITE_KEY
1659 function getSiteKey () {
1660         // Do we have cache?
1661         if (!isset($GLOBALS[__FUNCTION__])) {
1662                 // Determine it
1663                 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1664         } // END - if
1665
1666         // Return cache
1667         return $GLOBALS[__FUNCTION__];
1668 }
1669
1670 // "Getter" for DATE_KEY
1671 function getDateKey () {
1672         // Do we have cache?
1673         if (!isset($GLOBALS[__FUNCTION__])) {
1674                 // Determine it
1675                 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1676         } // END - if
1677
1678         // Return cache
1679         return $GLOBALS[__FUNCTION__];
1680 }
1681
1682 // "Getter" for master_salt
1683 function getMasterSalt () {
1684         // Do we have cache?
1685         if (!isset($GLOBALS[__FUNCTION__])) {
1686                 // Determine it
1687                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1688         } // END - if
1689
1690         // Return cache
1691         return $GLOBALS[__FUNCTION__];
1692 }
1693
1694 // "Getter" for prime
1695 function getPrime () {
1696         // Do we have cache?
1697         if (!isset($GLOBALS[__FUNCTION__])) {
1698                 // Determine it
1699                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1700         } // END - if
1701
1702         // Return cache
1703         return $GLOBALS[__FUNCTION__];
1704 }
1705
1706 // "Getter" for encrypt_separator
1707 function getEncryptSeparator () {
1708         // Do we have cache?
1709         if (!isset($GLOBALS[__FUNCTION__])) {
1710                 // Determine it
1711                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1712         } // END - if
1713
1714         // Return cache
1715         return $GLOBALS[__FUNCTION__];
1716 }
1717
1718 // "Getter" for mysql_prefix
1719 function getMysqlPrefix () {
1720         // Do we have cache?
1721         if (!isset($GLOBALS[__FUNCTION__])) {
1722                 // Determine it
1723                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1724         } // END - if
1725
1726         // Return cache
1727         return $GLOBALS[__FUNCTION__];
1728 }
1729
1730 // "Getter" for table_type
1731 function getTableType () {
1732         // Do we have cache?
1733         if (!isset($GLOBALS[__FUNCTION__])) {
1734                 // Determine it
1735                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1736         } // END - if
1737
1738         // Return cache
1739         return $GLOBALS[__FUNCTION__];
1740 }
1741
1742 // "Getter" for salt_length
1743 function getSaltLength () {
1744         // Do we have cache?
1745         if (!isset($GLOBALS[__FUNCTION__])) {
1746                 // Determine it
1747                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1748         } // END - if
1749
1750         // Return cache
1751         return $GLOBALS[__FUNCTION__];
1752 }
1753
1754 // "Getter" for output_mode
1755 function getOutputMode () {
1756         // Do we have cache?
1757         if (!isset($GLOBALS[__FUNCTION__])) {
1758                 // Determine it
1759                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1760         } // END - if
1761
1762         // Return cache
1763         return $GLOBALS[__FUNCTION__];
1764 }
1765
1766 // "Getter" for full_version
1767 function getFullVersion () {
1768         // Do we have cache?
1769         if (!isset($GLOBALS[__FUNCTION__])) {
1770                 // Determine it
1771                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1772         } // END - if
1773
1774         // Return cache
1775         return $GLOBALS[__FUNCTION__];
1776 }
1777
1778 // "Getter" for title
1779 function getTitle () {
1780         // Do we have cache?
1781         if (!isset($GLOBALS[__FUNCTION__])) {
1782                 // Determine it
1783                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1784         } // END - if
1785
1786         // Return cache
1787         return $GLOBALS[__FUNCTION__];
1788 }
1789
1790 // "Getter" for curr_svn_revision
1791 function getCurrentRepositoryRevision () {
1792         // Do we have cache?
1793         if (!isset($GLOBALS[__FUNCTION__])) {
1794                 // Determine it
1795                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1796         } // END - if
1797
1798         // Return cache
1799         return $GLOBALS[__FUNCTION__];
1800 }
1801
1802 // "Getter" for server_url
1803 function getServerUrl () {
1804         // Do we have cache?
1805         if (!isset($GLOBALS[__FUNCTION__])) {
1806                 // Determine it
1807                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1808         } // END - if
1809
1810         // Return cache
1811         return $GLOBALS[__FUNCTION__];
1812 }
1813
1814 // "Getter" for mt_word
1815 function getMtWord () {
1816         // Do we have cache?
1817         if (!isset($GLOBALS[__FUNCTION__])) {
1818                 // Determine it
1819                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1820         } // END - if
1821
1822         // Return cache
1823         return $GLOBALS[__FUNCTION__];
1824 }
1825
1826 // "Getter" for mt_word2
1827 function getMtWord2 () {
1828         // Do we have cache?
1829         if (!isset($GLOBALS[__FUNCTION__])) {
1830                 // Determine it
1831                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1832         } // END - if
1833
1834         // Return cache
1835         return $GLOBALS[__FUNCTION__];
1836 }
1837
1838 // "Getter" for mt_word2
1839 function getMtWord3 () {
1840         // Do we have cache?
1841         if (!isset($GLOBALS[__FUNCTION__])) {
1842                 // Determine it
1843                 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
1844         } // END - if
1845
1846         // Return cache
1847         return $GLOBALS[__FUNCTION__];
1848 }
1849
1850 // "Getter" for main_title
1851 function getMainTitle () {
1852         // Do we have cache?
1853         if (!isset($GLOBALS[__FUNCTION__])) {
1854                 // Determine it
1855                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1856         } // END - if
1857
1858         // Return cache
1859         return $GLOBALS[__FUNCTION__];
1860 }
1861
1862 // "Getter" for file_hash
1863 function getFileHash () {
1864         // Do we have cache?
1865         if (!isset($GLOBALS[__FUNCTION__])) {
1866                 // Determine it
1867                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1868         } // END - if
1869
1870         // Return cache
1871         return $GLOBALS[__FUNCTION__];
1872 }
1873
1874 // "Getter" for pass_scramble
1875 function getPassScramble () {
1876         // Do we have cache?
1877         if (!isset($GLOBALS[__FUNCTION__])) {
1878                 // Determine it
1879                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1880         } // END - if
1881
1882         // Return cache
1883         return $GLOBALS[__FUNCTION__];
1884 }
1885
1886 // "Getter" for ap_inactive_since
1887 function getApInactiveSince () {
1888         // Do we have cache?
1889         if (!isset($GLOBALS[__FUNCTION__])) {
1890                 // Determine it
1891                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1892         } // END - if
1893
1894         // Return cache
1895         return $GLOBALS[__FUNCTION__];
1896 }
1897
1898 // "Getter" for user_min_confirmed
1899 function getUserMinConfirmed () {
1900         // Do we have cache?
1901         if (!isset($GLOBALS[__FUNCTION__])) {
1902                 // Determine it
1903                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1904         } // END - if
1905
1906         // Return cache
1907         return $GLOBALS[__FUNCTION__];
1908 }
1909
1910 // "Getter" for auto_purge
1911 function getAutoPurge () {
1912         // Do we have cache?
1913         if (!isset($GLOBALS[__FUNCTION__])) {
1914                 // Determine it
1915                 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1916         } // END - if
1917
1918         // Return cache
1919         return $GLOBALS[__FUNCTION__];
1920 }
1921
1922 // "Getter" for bonus_userid
1923 function getBonusUserid () {
1924         // Do we have cache?
1925         if (!isset($GLOBALS[__FUNCTION__])) {
1926                 // Determine it
1927                 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1928         } // END - if
1929
1930         // Return cache
1931         return $GLOBALS[__FUNCTION__];
1932 }
1933
1934 // "Getter" for ap_inactive_time
1935 function getApInactiveTime () {
1936         // Do we have cache?
1937         if (!isset($GLOBALS[__FUNCTION__])) {
1938                 // Determine it
1939                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1940         } // END - if
1941
1942         // Return cache
1943         return $GLOBALS[__FUNCTION__];
1944 }
1945
1946 // "Getter" for ap_dm_timeout
1947 function getApDmTimeout () {
1948         // Do we have cache?
1949         if (!isset($GLOBALS[__FUNCTION__])) {
1950                 // Determine it
1951                 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1952         } // END - if
1953
1954         // Return cache
1955         return $GLOBALS[__FUNCTION__];
1956 }
1957
1958 // "Getter" for ap_tasks_time
1959 function getApTasksTime () {
1960         // Do we have cache?
1961         if (!isset($GLOBALS[__FUNCTION__])) {
1962                 // Determine it
1963                 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1964         } // END - if
1965
1966         // Return cache
1967         return $GLOBALS[__FUNCTION__];
1968 }
1969
1970 // "Getter" for ap_unconfirmed_time
1971 function getApUnconfirmedTime () {
1972         // Do we have cache?
1973         if (!isset($GLOBALS[__FUNCTION__])) {
1974                 // Determine it
1975                 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1976         } // END - if
1977
1978         // Return cache
1979         return $GLOBALS[__FUNCTION__];
1980 }
1981
1982 // "Getter" for points
1983 function getPoints () {
1984         // Do we have cache?
1985         if (!isset($GLOBALS[__FUNCTION__])) {
1986                 // Determine it
1987                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1988         } // END - if
1989
1990         // Return cache
1991         return $GLOBALS[__FUNCTION__];
1992 }
1993
1994 // "Getter" for slogan
1995 function getSlogan () {
1996         // Do we have cache?
1997         if (!isset($GLOBALS[__FUNCTION__])) {
1998                 // Determine it
1999                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
2000         } // END - if
2001
2002         // Return cache
2003         return $GLOBALS[__FUNCTION__];
2004 }
2005
2006 // "Getter" for copy
2007 function getCopy () {
2008         // Do we have cache?
2009         if (!isset($GLOBALS[__FUNCTION__])) {
2010                 // Determine it
2011                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
2012         } // END - if
2013
2014         // Return cache
2015         return $GLOBALS[__FUNCTION__];
2016 }
2017
2018 // "Getter" for webmaster
2019 function getWebmaster () {
2020         // Do we have cache?
2021         if (!isset($GLOBALS[__FUNCTION__])) {
2022                 // Determine it
2023                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
2024         } // END - if
2025
2026         // Return cache
2027         return $GLOBALS[__FUNCTION__];
2028 }
2029
2030 // "Getter" for sql_count
2031 function getSqlCount () {
2032         // Do we have cache?
2033         if (!isset($GLOBALS[__FUNCTION__])) {
2034                 // Determine it
2035                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2036         } // END - if
2037
2038         // Return cache
2039         return $GLOBALS[__FUNCTION__];
2040 }
2041
2042 // "Getter" for num_templates
2043 function getNumTemplates () {
2044         // Do we have cache?
2045         if (!isset($GLOBALS[__FUNCTION__])) {
2046                 // Determine it
2047                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2048         } // END - if
2049
2050         // Return cache
2051         return $GLOBALS[__FUNCTION__];
2052 }
2053
2054 // "Getter" for dns_cache_timeout
2055 function getDnsCacheTimeout () {
2056         // Do we have cache?
2057         if (!isset($GLOBALS[__FUNCTION__])) {
2058                 // Determine it
2059                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2060         } // END - if
2061
2062         // Return cache
2063         return $GLOBALS[__FUNCTION__];
2064 }
2065
2066 // "Getter" for menu_blur_spacer
2067 function getMenuBlurSpacer () {
2068         // Do we have cache?
2069         if (!isset($GLOBALS[__FUNCTION__])) {
2070                 // Determine it
2071                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2072         } // END - if
2073
2074         // Return cache
2075         return $GLOBALS[__FUNCTION__];
2076 }
2077
2078 // "Getter" for points_register
2079 function getPointsRegister () {
2080         // Do we have cache?
2081         if (!isset($GLOBALS[__FUNCTION__])) {
2082                 // Determine it
2083                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2084         } // END - if
2085
2086         // Return cache
2087         return $GLOBALS[__FUNCTION__];
2088 }
2089
2090 // "Getter" for points_ref
2091 function getPointsRef () {
2092         // Do we have cache?
2093         if (!isset($GLOBALS[__FUNCTION__])) {
2094                 // Determine it
2095                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2096         } // END - if
2097
2098         // Return cache
2099         return $GLOBALS[__FUNCTION__];
2100 }
2101
2102 // "Getter" for ref_payout
2103 function getRefPayout () {
2104         // Do we have cache?
2105         if (!isset($GLOBALS[__FUNCTION__])) {
2106                 // Determine it
2107                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2108         } // END - if
2109
2110         // Return cache
2111         return $GLOBALS[__FUNCTION__];
2112 }
2113
2114 // "Getter" for online_timeout
2115 function getOnlineTimeout () {
2116         // Do we have cache?
2117         if (!isset($GLOBALS[__FUNCTION__])) {
2118                 // Determine it
2119                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2120         } // END - if
2121
2122         // Return cache
2123         return $GLOBALS[__FUNCTION__];
2124 }
2125
2126 // "Getter" for index_home
2127 function getIndexHome () {
2128         // Do we have cache?
2129         if (!isset($GLOBALS[__FUNCTION__])) {
2130                 // Determine it
2131                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2132         } // END - if
2133
2134         // Return cache
2135         return $GLOBALS[__FUNCTION__];
2136 }
2137
2138 // "Getter" for one_day
2139 function getOneDay () {
2140         // Do we have cache?
2141         if (!isset($GLOBALS[__FUNCTION__])) {
2142                 // Determine it
2143                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2144         } // END - if
2145
2146         // Return cache
2147         return $GLOBALS[__FUNCTION__];
2148 }
2149
2150 // "Getter" for activate_xchange
2151 function getActivateXchange () {
2152         // Do we have cache?
2153         if (!isset($GLOBALS[__FUNCTION__])) {
2154                 // Determine it
2155                 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2156         } // END - if
2157
2158         // Return cache
2159         return $GLOBALS[__FUNCTION__];
2160 }
2161
2162 // "Getter" for img_type
2163 function getImgType () {
2164         // Do we have cache?
2165         if (!isset($GLOBALS[__FUNCTION__])) {
2166                 // Determine it
2167                 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2168         } // END - if
2169
2170         // Return cache
2171         return $GLOBALS[__FUNCTION__];
2172 }
2173
2174 // "Getter" for code_length
2175 function getCodeLength () {
2176         // Do we have cache?
2177         if (!isset($GLOBALS[__FUNCTION__])) {
2178                 // Determine it
2179                 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2180         } // END - if
2181
2182         // Return cache
2183         return $GLOBALS[__FUNCTION__];
2184 }
2185
2186 // "Getter" for least_cats
2187 function getLeastCats () {
2188         // Do we have cache?
2189         if (!isset($GLOBALS[__FUNCTION__])) {
2190                 // Determine it
2191                 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2192         } // END - if
2193
2194         // Return cache
2195         return $GLOBALS[__FUNCTION__];
2196 }
2197
2198 // "Getter" for pass_len
2199 function getPassLen () {
2200         // Do we have cache?
2201         if (!isset($GLOBALS[__FUNCTION__])) {
2202                 // Determine it
2203                 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2204         } // END - if
2205
2206         // Return cache
2207         return $GLOBALS[__FUNCTION__];
2208 }
2209
2210 // "Getter" for admin_menu
2211 function getAdminMenu () {
2212         // Do we have cache?
2213         if (!isset($GLOBALS[__FUNCTION__])) {
2214                 // Determine it
2215                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2216         } // END - if
2217
2218         // Return cache
2219         return $GLOBALS[__FUNCTION__];
2220 }
2221
2222 // "Getter" for last_month
2223 function getLastMonth () {
2224         // Do we have cache?
2225         if (!isset($GLOBALS[__FUNCTION__])) {
2226                 // Determine it
2227                 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2228         } // END - if
2229
2230         // Return cache
2231         return $GLOBALS[__FUNCTION__];
2232 }
2233
2234 // "Getter" for max_send
2235 function getMaxSend () {
2236         // Do we have cache?
2237         if (!isset($GLOBALS[__FUNCTION__])) {
2238                 // Determine it
2239                 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2240         } // END - if
2241
2242         // Return cache
2243         return $GLOBALS[__FUNCTION__];
2244 }
2245
2246 // "Getter" for mails_page
2247 function getMailsPage () {
2248         // Do we have cache?
2249         if (!isset($GLOBALS[__FUNCTION__])) {
2250                 // Determine it
2251                 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2252         } // END - if
2253
2254         // Return cache
2255         return $GLOBALS[__FUNCTION__];
2256 }
2257
2258 // "Getter" for rand_no
2259 function getRandNo () {
2260         // Do we have cache?
2261         if (!isset($GLOBALS[__FUNCTION__])) {
2262                 // Determine it
2263                 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2264         } // END - if
2265
2266         // Return cache
2267         return $GLOBALS[__FUNCTION__];
2268 }
2269
2270 // "Getter" for __DB_NAME
2271 function getDbName () {
2272         // Do we have cache?
2273         if (!isset($GLOBALS[__FUNCTION__])) {
2274                 // Determine it
2275                 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2276         } // END - if
2277
2278         // Return cache
2279         return $GLOBALS[__FUNCTION__];
2280 }
2281
2282 // "Getter" for DOMAIN
2283 function getDomain () {
2284         // Do we have cache?
2285         if (!isset($GLOBALS[__FUNCTION__])) {
2286                 // Determine it
2287                 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2288         } // END - if
2289
2290         // Return cache
2291         return $GLOBALS[__FUNCTION__];
2292 }
2293
2294 // "Getter" for proxy_username
2295 function getProxyUsername () {
2296         // Do we have cache?
2297         if (!isset($GLOBALS[__FUNCTION__])) {
2298                 // Determine it
2299                 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2300         } // END - if
2301
2302         // Return cache
2303         return $GLOBALS[__FUNCTION__];
2304 }
2305
2306 // "Getter" for proxy_password
2307 function getProxyPassword () {
2308         // Do we have cache?
2309         if (!isset($GLOBALS[__FUNCTION__])) {
2310                 // Determine it
2311                 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2312         } // END - if
2313
2314         // Return cache
2315         return $GLOBALS[__FUNCTION__];
2316 }
2317
2318 // "Getter" for proxy_host
2319 function getProxyHost () {
2320         // Do we have cache?
2321         if (!isset($GLOBALS[__FUNCTION__])) {
2322                 // Determine it
2323                 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2324         } // END - if
2325
2326         // Return cache
2327         return $GLOBALS[__FUNCTION__];
2328 }
2329
2330 // "Getter" for proxy_port
2331 function getProxyPort () {
2332         // Do we have cache?
2333         if (!isset($GLOBALS[__FUNCTION__])) {
2334                 // Determine it
2335                 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2336         } // END - if
2337
2338         // Return cache
2339         return $GLOBALS[__FUNCTION__];
2340 }
2341
2342 // "Getter" for SMTP_HOSTNAME
2343 function getSmtpHostname () {
2344         // Do we have cache?
2345         if (!isset($GLOBALS[__FUNCTION__])) {
2346                 // Determine it
2347                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2348         } // END - if
2349
2350         // Return cache
2351         return $GLOBALS[__FUNCTION__];
2352 }
2353
2354 // "Getter" for SMTP_USER
2355 function getSmtpUser () {
2356         // Do we have cache?
2357         if (!isset($GLOBALS[__FUNCTION__])) {
2358                 // Determine it
2359                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2360         } // END - if
2361
2362         // Return cache
2363         return $GLOBALS[__FUNCTION__];
2364 }
2365
2366 // "Getter" for SMTP_PASSWORD
2367 function getSmtpPassword () {
2368         // Do we have cache?
2369         if (!isset($GLOBALS[__FUNCTION__])) {
2370                 // Determine it
2371                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2372         } // END - if
2373
2374         // Return cache
2375         return $GLOBALS[__FUNCTION__];
2376 }
2377
2378 // "Getter" for points_word
2379 function getPointsWord () {
2380         // Do we have cache?
2381         if (!isset($GLOBALS[__FUNCTION__])) {
2382                 // Determine it
2383                 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2384         } // END - if
2385
2386         // Return cache
2387         return $GLOBALS[__FUNCTION__];
2388 }
2389
2390 // "Getter" for profile_lock
2391 function getProfileLock () {
2392         // Do we have cache?
2393         if (!isset($GLOBALS[__FUNCTION__])) {
2394                 // Determine it
2395                 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2396         } // END - if
2397
2398         // Return cache
2399         return $GLOBALS[__FUNCTION__];
2400 }
2401
2402 // "Getter" for url_tlock
2403 function getUrlTlock () {
2404         // Do we have cache?
2405         if (!isset($GLOBALS[__FUNCTION__])) {
2406                 // Determine it
2407                 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2408         } // END - if
2409
2410         // Return cache
2411         return $GLOBALS[__FUNCTION__];
2412 }
2413
2414 // "Getter" for title_left
2415 function getTitleLeft () {
2416         // Do we have cache?
2417         if (!isset($GLOBALS[__FUNCTION__])) {
2418                 // Determine it
2419                 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2420         } // END - if
2421
2422         // Return cache
2423         return $GLOBALS[__FUNCTION__];
2424 }
2425
2426 // "Getter" for title_right
2427 function getTitleRight () {
2428         // Do we have cache?
2429         if (!isset($GLOBALS[__FUNCTION__])) {
2430                 // Determine it
2431                 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2432         } // END - if
2433
2434         // Return cache
2435         return $GLOBALS[__FUNCTION__];
2436 }
2437
2438 // "Getter" for title_middle
2439 function getTitleMiddle () {
2440         // Do we have cache?
2441         if (!isset($GLOBALS[__FUNCTION__])) {
2442                 // Determine it
2443                 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2444         } // END - if
2445
2446         // Return cache
2447         return $GLOBALS[__FUNCTION__];
2448 }
2449
2450 // Getter for 'check_double_email'
2451 function getCheckDoubleEmail () {
2452         // Is the cache entry set?
2453         if (!isset($GLOBALS[__FUNCTION__])) {
2454                 // No, so determine it
2455                 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2456         } // END - if
2457
2458         // Return cached entry
2459         return $GLOBALS[__FUNCTION__];
2460 }
2461
2462 // Checks whether 'check_double_email' is 'Y'
2463 function isCheckDoubleEmailEnabled () {
2464         // Is the cache entry set?
2465         if (!isset($GLOBALS[__FUNCTION__])) {
2466                 // No, so determine it
2467                 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2468         } // END - if
2469
2470         // Return cached entry
2471         return $GLOBALS[__FUNCTION__];
2472 }
2473
2474 // Getter for 'display_home_in_index'
2475 function getDisplayHomeInIndex () {
2476         // Is the cache entry set?
2477         if (!isset($GLOBALS[__FUNCTION__])) {
2478                 // No, so determine it
2479                 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2480         } // END - if
2481
2482         // Return cached entry
2483         return $GLOBALS[__FUNCTION__];
2484 }
2485
2486 // Checks whether 'display_home_in_index' is 'Y'
2487 function isDisplayHomeInIndexEnabled () {
2488         // Is the cache entry set?
2489         if (!isset($GLOBALS[__FUNCTION__])) {
2490                 // No, so determine it
2491                 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2492         } // END - if
2493
2494         // Return cached entry
2495         return $GLOBALS[__FUNCTION__];
2496 }
2497
2498 // Getter for 'admin_menu_javascript'
2499 function getAdminMenuJavascript () {
2500         // Is the cache entry set?
2501         if (!isset($GLOBALS[__FUNCTION__])) {
2502                 // No, so determine it
2503                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2504         } // END - if
2505
2506         // Return cached entry
2507         return $GLOBALS[__FUNCTION__];
2508 }
2509
2510 // Getter for 'points_remove_account'
2511 function getPointsRemoveAccount () {
2512         // Is the cache entry set?
2513         if (!isset($GLOBALS[__FUNCTION__])) {
2514                 // No, so determine it
2515                 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2516         } // END - if
2517
2518         // Return cached entry
2519         return $GLOBALS[__FUNCTION__];
2520 }
2521
2522 // Checks whether proxy configuration is used
2523 function isProxyUsed () {
2524         // Do we have cache?
2525         if (!isset($GLOBALS[__FUNCTION__])) {
2526                 // Determine it
2527                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2528         } // END - if
2529
2530         // Return cache
2531         return $GLOBALS[__FUNCTION__];
2532 }
2533
2534 // Checks whether POST data contains selections
2535 function ifPostContainsSelections ($element = 'sel') {
2536         // Do we have cache?
2537         if (!isset($GLOBALS[__FUNCTION__][$element])) {
2538                 // Determine it
2539                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2540         } // END - if
2541
2542         // Return cache
2543         return $GLOBALS[__FUNCTION__][$element];
2544 }
2545
2546 // Checks whether verbose_sql is Y and returns true/false if so
2547 function isVerboseSqlEnabled () {
2548         // Do we have cache?
2549         if (!isset($GLOBALS[__FUNCTION__])) {
2550                 // Determine it
2551                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2552         } // END - if
2553
2554         // Return cache
2555         return $GLOBALS[__FUNCTION__];
2556 }
2557
2558 // "Getter" for total user points
2559 function getTotalPoints ($userid) {
2560         // Do we have cache?
2561         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2562                 // Init array for filter chain
2563                 $data = array(
2564                         'userid' => $userid,
2565                         'points' => 0
2566                 );
2567
2568                 // Run filter chain for getting more point values
2569                 $data = runFilterChain('get_total_points', $data);
2570
2571                 // Determine it
2572                 $GLOBALS[__FUNCTION__][$userid] = $data['points']  - getUserUsedPoints($userid);
2573         } // END - if
2574
2575         // Return cache
2576         return $GLOBALS[__FUNCTION__][$userid];
2577 }
2578
2579 // Wrapper to get used points for given userid
2580 function getUserUsedPoints ($userid) {
2581         // Do we have cache?
2582         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2583                 // Determine it
2584                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2585         } // END - if
2586
2587         // Return cache
2588         return $GLOBALS[__FUNCTION__][$userid];
2589 }
2590
2591 // Wrapper to check if url_blacklist is enabled
2592 function isUrlBlacklistEnabled () {
2593         // Do we have cache?
2594         if (!isset($GLOBALS[__FUNCTION__])) {
2595                 // Determine it
2596                 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2597         } // END - if
2598
2599         // Return cache
2600         return $GLOBALS[__FUNCTION__];
2601 }
2602
2603 // Checks whether direct payment is allowed in configuration
2604 function isDirectPaymentEnabled () {
2605         // Do we have cache?
2606         if (!isset($GLOBALS[__FUNCTION__])) {
2607                 // Determine it
2608                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2609         } // END - if
2610
2611         // Return cache
2612         return $GLOBALS[__FUNCTION__];
2613 }
2614
2615 // Checks whether JavaScript-based admin menu is enabled
2616 function isAdminMenuJavascriptEnabled () {
2617         // Do we have cache?
2618         if (!isset($GLOBALS[__FUNCTION__])) {
2619                 // Determine it
2620                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
2621         } // END - if
2622
2623         // Return cache
2624         return $GLOBALS[__FUNCTION__];
2625 }
2626
2627 // Wrapper to check if current task is for extension (not update)
2628 function isExtensionTask ($content) {
2629         // Do we have cache?
2630         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2631                 // Determine it
2632                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2633         } // END - if
2634
2635         // Return cache
2636         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2637 }
2638
2639 // Getter for 'mt_start'
2640 function getMtStart () {
2641         // Is the cache entry set?
2642         if (!isset($GLOBALS[__FUNCTION__])) {
2643                 // No, so determine it
2644                 $GLOBALS[__FUNCTION__] = getConfig('mt_start');
2645         } // END - if
2646
2647         // Return cached entry
2648         return $GLOBALS[__FUNCTION__];
2649 }
2650
2651 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2652 function ifTesterAccountsAllowed () {
2653         // Is the cache entry set?
2654         if (!isset($GLOBALS[__FUNCTION__])) {
2655                 // No, so determine it
2656                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2657         } // END - if
2658
2659         // Return cached entry
2660         return $GLOBALS[__FUNCTION__];
2661 }
2662
2663 // Wrapper to check if output mode is CSS
2664 function isCssOutputMode () {
2665         // Is cache set?
2666         if (!isset($GLOBALS[__FUNCTION__])) {
2667                 // Determine it
2668                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2669                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2670         } // END - if
2671
2672         // Return cache
2673         return $GLOBALS[__FUNCTION__];
2674 }
2675
2676 // Wrapper to check if output mode is HTML
2677 function isHtmlOutputMode () {
2678         // Is cache set?
2679         if (!isset($GLOBALS[__FUNCTION__])) {
2680                 // Determine it
2681                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2682                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2683         } // END - if
2684
2685         // Return cache
2686         return $GLOBALS[__FUNCTION__];
2687 }
2688
2689 // Wrapper to check if output mode is RAW
2690 function isRawOutputMode () {
2691         // Is cache set?
2692         if (!isset($GLOBALS[__FUNCTION__])) {
2693                 // Determine it
2694                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2695                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2696         } // END - if
2697
2698         // Return cache
2699         return $GLOBALS[__FUNCTION__];
2700 }
2701
2702 // Wrapper to check if output mode is AJAX
2703 function isAjaxOutputMode () {
2704         // Is cache set?
2705         if (!isset($GLOBALS[__FUNCTION__])) {
2706                 // Determine it
2707                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2708                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2709         } // END - if
2710
2711         // Return cache
2712         return $GLOBALS[__FUNCTION__];
2713 }
2714
2715 // Wrapper to check if output mode is image
2716 function isImageOutputMode () {
2717         // Is cache set?
2718         if (!isset($GLOBALS[__FUNCTION__])) {
2719                 // Determine it
2720                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2721                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
2722         } // END - if
2723
2724         // Return cache
2725         return $GLOBALS[__FUNCTION__];
2726 }
2727
2728 // Wrapper to generate a user email link
2729 function generateWrappedUserEmailLink ($email) {
2730         // Just call the inner function
2731         return generateEmailLink($email, 'user_data');
2732 }
2733
2734 // Wrapper to check if user points are locked
2735 function ifUserPointsLocked ($userid) {
2736         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2737         // Do we have cache?
2738         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2739                 // Determine it
2740                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2741         } // END - if
2742
2743         // Return cache
2744         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2745         return $GLOBALS[__FUNCTION__][$userid];
2746 }
2747
2748 // Appends a line to an existing file or creates it instantly with given content.
2749 // This function does always add a new-line character to every line.
2750 function appendLineToFile ($file, $line) {
2751         $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2752         fwrite($fp, $line . chr(10));
2753         fclose($fp);
2754 }
2755
2756 // Wrapper for changeDataInFile() but with full path added
2757 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2758         // Add full path
2759         $FQFN = getPath() . $FQFN;
2760
2761         // Call inner function
2762         return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2763 }
2764
2765 // Wrapper for changing entries in config-local.php
2766 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2767         // Call the inner function
2768         return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2769 }
2770
2771 // Shortens ucfirst(strtolower()) calls
2772 function firstCharUpperCase ($str) {
2773         return ucfirst(strtolower($str));
2774 }
2775
2776 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2777 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2778         // Get the configuration entry
2779         $configValue = getConfig($configEntry);
2780
2781         // Call inner method
2782         return createTimeSelections($configValue, $configEntry, $stamps, $align);
2783 }
2784
2785 // Shortens converting of German comma to Computer's version in POST data
2786 function convertCommaToDotInPostData ($postEntry) {
2787         // Read and convert given entry
2788         $postValue = convertCommaToDot(postRequestElement($postEntry));
2789
2790         // ... and set it again
2791         setPostRequestElement($postEntry, $postValue);
2792 }
2793
2794 // Converts German commas to Computer's version in all entries
2795 function convertCommaToDotInPostDataArray ($postEntries) {
2796         // Replace german decimal comma with computer decimal dot
2797         foreach ($postEntries as $entry) {
2798                 // Is the entry there?
2799                 if (isPostRequestElementSet($entry)) {
2800                         // Then convert it
2801                         convertCommaToDotInPostData($entry);
2802                 } // END - if
2803         } // END - foreach
2804 }
2805
2806 /**
2807  * Parses a string into a US formated float variable, taken from user comments
2808  * from PHP documentation website.
2809  *
2810  * @param       $floatString    A string holding a float expression
2811  * @return      $float                  Corresponding float variable
2812  * @author      chris<at>georgakopoulos<dot>com
2813  * @link        http://de.php.net/manual/en/function.floatval.php#92563
2814  */
2815 function parseFloat ($floatString){
2816         // Load locale info
2817         $LocaleInfo = localeconv();
2818
2819         // Remove thousand separators
2820         $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
2821
2822         // Convert decimal point
2823         $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2824
2825         // Return float value of converted string
2826         return floatval($floatString);
2827 }
2828
2829 /**
2830  * Searches a multi-dimensional array (as used in many places) for given
2831  * key/value pair as taken from user comments from PHP documentation website.
2832  *
2833  * @param       $array          An array with one or more dimensions
2834  * @param       $key            Key to look for
2835  * @param       $valur          Value to look for
2836  * @return      $results        Resulted array or empty array if $array is no array
2837  * @author      sunelbe<at>gmail<dot>com
2838  * @link        http://de.php.net/manual/en/function.array-search.php#110120
2839  */
2840 function search_array ($array, $key, $value) {
2841         // Init array result
2842         $results = array();
2843
2844         // Is $array really an array?
2845         if (is_array($array)) {
2846                 // Does key and value match?
2847                 if (isset($array[$key]) && $array[$key] == $value) {
2848                         // Then add it as result
2849                         $results[] = $array;
2850                 } // END - if
2851
2852                 // Search for whole array
2853                 foreach ($array as $subArray) {
2854                         // Search recursive and merge again
2855                         $results = merge_array($results, search_array($subArray, $key, $value));
2856                 } // END - foreach
2857         } // END - if
2858
2859         // Return resulting array
2860         return $results;
2861 }
2862
2863 // Generates a YES/NO option list from given default
2864 function generateYesNoOptions ($defaultValue = '') {
2865         // Generate it
2866         return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2867 }
2868
2869 // "Getter" for total available receivers
2870 function getTotalReceivers ($mode = 'normal') {
2871         // Get num rows
2872         $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
2873
2874         // Return value
2875         return $numRows;
2876 }
2877
2878 // Wrapper "getter" to get total unconfirmed mails for given userid
2879 function getTotalUnconfirmedMails ($userid) {
2880         // Do we have cache?
2881         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2882                 // Determine it
2883                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
2884         } // END - if
2885
2886         // Return cache
2887         return $GLOBALS[__FUNCTION__][$userid];
2888 }
2889
2890 // Checks whether 'mailer_theme' was found in session
2891 function isMailerThemeSet () {
2892         // Is cache set?
2893         if (!isset($GLOBALS[__FUNCTION__])) {
2894                 // Determine it
2895                 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
2896         } // END - if
2897
2898         // Return cache
2899         return $GLOBALS[__FUNCTION__];
2900 }
2901
2902 /**
2903  * Setter for theme in session (This setter does return the success of
2904  * setSession() which is required e.g. for destroySponsorSession().
2905  */
2906 function setMailerTheme ($newTheme) {
2907         // Set it in session
2908         return setSession('mailer_theme', $newTheme);
2909 }
2910
2911 /**
2912  * Getter for theme from session (This getter does return 'mailer_theme' from
2913  * session data or throws an error if not possible
2914  */
2915 function getMailerTheme () {
2916         // Is cache set?
2917         if (!isset($GLOBALS[__FUNCTION__])) {
2918                 // Is 'mailer_theme' set?
2919                 if (!isMailerThemeSet()) {
2920                         // No, then abort here
2921                         reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2922                 } // END - if
2923
2924                 // Get it and store it in cache
2925                 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
2926         } // END - if
2927
2928         // Return cache
2929         return $GLOBALS[__FUNCTION__];
2930 }
2931
2932 // "Getter" for last_module/last_what depending on ext-user version
2933 function getUserLastWhatName () {
2934         // Default is old one: last_module
2935         $columnName = 'last_module';
2936
2937         // Is ext-user up-to-date?
2938         if (isExtensionInstalledAndNewer('user', '0.4.9')) {
2939                 // Yes, then use new one
2940                 $columnName = 'last_what';
2941         } // END - if
2942
2943         // Return it
2944         return $columnName;
2945 }
2946
2947 // "Getter" for all columns for given alias and separator
2948 function getAllPointColumns ($alias = NULL, $separator = ',') {
2949         // Prepare the filter array
2950         $filterData = array(
2951                 'columns'   => '',
2952                 'alias'     => $alias,
2953                 'separator' => $separator
2954         );
2955
2956         // Run the filter
2957         $filterData = runFilterChain('get_all_point_columns', $filterData);
2958
2959         // Return the columns
2960         return $filterData['columns'];
2961 }
2962
2963 // Checks whether the copyright footer (which breaks framesets) is enabled
2964 function ifCopyrightFooterEnabled () {
2965         // Is not unset and not 'N'?
2966         return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
2967 }
2968
2969 /**
2970  * Wrapper to check whether we have a "full page". This means that the actual
2971  * content is not delivered in any frame of a frameset.
2972  */
2973 function isFullPage () {
2974         /*
2975          * The parameter 'frame' is generic and always indicates that this content
2976          * will be output into a frame. Furthermore, if a frameset is reported or
2977          * the copyright line is explicitly deactivated, this cannot be a "full
2978          * page" again.
2979          */
2980         // @TODO Find a way to not use direct module comparison
2981         $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
2982
2983         // Return it
2984         return $isFullPage;
2985 }
2986
2987 // Checks whether frameset_mode is set to true
2988 function isFramesetModeEnabled () {
2989         // Check it
2990         return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === true));
2991 }
2992
2993 // Function to determine correct 'what' value
2994 function determineWhat ($module = NULL) {
2995         // Init default 'what'
2996         $what = 'welcome';
2997
2998         // Is module NULL?
2999         if (is_null($module)) {
3000                 // Then use default
3001                 $module = getModule();
3002         } // END - if
3003
3004         // Is what set?
3005         if (isWhatSet()) {
3006                 // Then use it
3007                 $what = getWhat();
3008         } else {
3009                 // Else try to get it from current module
3010                 $what = getWhatFromModule($module);
3011         }
3012         //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
3013
3014         // Remove any spaces from variable
3015         $what = trim($what);
3016
3017         // Is it empty?
3018         if (empty($what)) {
3019                 // Default action for non-admin menus
3020                 $what = 'welcome';
3021         } else {
3022                 // Secure it
3023                 $what = secureString($what);
3024         }
3025
3026         // Return what
3027         return $what;
3028 }
3029
3030 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3031 function prependZeros ($mStretch, $length = 2) {
3032         // Return prepended string
3033         return sprintf('%0' . (int) $length . 's', $mStretch);
3034 }
3035
3036 // Wraps convertSelectionsToEpocheTime()
3037 function convertSelectionsToEpocheTimeInPostData ($id) {
3038         // Init variables
3039         $content = array();
3040         $skip = false;
3041
3042         // Get all POST data
3043         $postData = postRequestArray();
3044
3045         // Convert given selection id
3046         convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3047
3048         // Set the POST array back
3049         setPostRequestArray($postData);
3050 }
3051
3052 // Wraps checking if given points account type matches with given in POST data
3053 function ifPointsAccountTypeMatchesPost ($type) {
3054         // Check condition
3055         exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), true).'</pre>');
3056 }
3057
3058 // Gets given user's total referral
3059 function getUsersTotalReferrals ($userid, $level = NULL) {
3060         // Do we have cache?
3061         if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3062                 // Is the level NULL?
3063                 if (is_null($level)) {
3064                         // Get total amount (all levels)
3065                         $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true);
3066                 } else {
3067                         // Get it from user refs
3068                         $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true, ' AND `level`=' . bigintval($level));
3069                 }
3070         } // END - if
3071
3072         // Return it
3073         return $GLOBALS[__FUNCTION__][$userid][$level];
3074 }
3075
3076 // Gets given user's total referral
3077 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3078         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3079         // Do we have cache?
3080         if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3081                 // Default is all refs
3082                 $add = '';
3083
3084                 // Is the not level NULL?
3085                 if (!is_null($level)) {
3086                         // Then add referral level
3087                         $add = ' AND r.`level`=' . bigintval($level);
3088                 } // END - if
3089
3090                 // Check for all referrals
3091                 $result = SQL_QUERY_ESC("SELECT
3092         COUNT(d.`userid`) AS `cnt`
3093 FROM
3094         `{?_MYSQL_PREFIX?}_user_data` AS d
3095 INNER JOIN
3096         `{?_MYSQL_PREFIX?}_user_refs` AS r
3097 ON
3098         d.`userid`=r.`refid`
3099 WHERE
3100         d.`status` != 'CONFIRMED' AND
3101         r.`userid`=%s
3102         " . $add . "
3103 ORDER BY
3104         d.`userid` ASC
3105 LIMIT 1",
3106                         array(
3107                                 $userid
3108                         ), __FUNCTION__, __LINE__);
3109
3110                 // Load count
3111                 list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
3112
3113                 // Free result
3114                 SQL_FREERESULT($result);
3115         } // END - if
3116
3117         // Return it
3118         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3119         return $GLOBALS[__FUNCTION__][$userid][$level];
3120 }
3121
3122 // Converts, if found, dollar data to get element
3123 function convertDollarDataToGetElement ($data) {
3124         // Is first char a dollar?
3125         if (substr($data, 0, 1) == chr(36)) {
3126                 // Use last part for getRequestElement()
3127                 $data = getRequestElement(substr($data, 1));
3128         } // END - if
3129
3130         // Return it
3131         return $data;
3132 }
3133
3134 // Wrapper function for SQL layer to speed-up things
3135 function SQL_DEBUG_ENABLED () {
3136         // Is there cache?
3137         if (!isset($GLOBALS[__FUNCTION__])) {
3138                 // Determine it
3139                 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3140         } // END - if
3141
3142         // Return cache
3143         return $GLOBALS[__FUNCTION__];
3144 }
3145
3146 // [EOF]
3147 ?>