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