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