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