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