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