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