Speed improvement, TODOs.txt updated:
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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         die();
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                 debug_report_bug(__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 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
93
94                 // Do we need to aquire a lock?
95                 if ($aquireLock === true) {
96                         // Aquire 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         // Trigger an error on failure
123         if ((ob_get_length() > 0) && (!ob_end_clean())) {
124                 // Failed!
125                 debug_report_bug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
126         } // END - if
127 }
128
129 // Encode strings
130 // @TODO Implement $compress
131 function encodeString ($str, $compress = true) {
132         $str = urlencode(base64_encode(compileUriCode($str)));
133         return $str;
134 }
135
136 // Decode strings encoded with encodeString()
137 // @TODO Implement $decompress
138 function decodeString ($str, $decompress = true) {
139         $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
140         return $str;
141 }
142
143 // Decode entities in a nicer way
144 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
145         // Decode the entities to UTF-8 now
146         $decodedString = html_entity_decode($str, $quote, 'UTF-8');
147
148         // Return decoded string
149         return $decodedString;
150 }
151
152 // Merges an array together but only if both are arrays
153 function merge_array ($array1, $array2) {
154         // Are both an array?
155         if ((!is_array($array1)) && (!is_array($array2))) {
156                 // Both are not arrays
157                 debug_report_bug(__FUNCTION__, __LINE__, 'No arrays provided!');
158         } elseif (!is_array($array1)) {
159                 // Left one is not an array
160                 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
161         } elseif (!is_array($array2)) {
162                 // Right one is not an array
163                 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
164         }
165
166         // Merge all together
167         return array_merge($array1, $array2);
168 }
169
170 // Check if given FQFN is a readable file
171 function isFileReadable ($FQFN) {
172         // Do we have cache?
173         if (!isset($GLOBALS['file_readable'][$FQFN])) {
174                 // Check all...
175                 $GLOBALS['file_readable'][$FQFN] = ((file_exists($FQFN)) && (is_file($FQFN)) && (is_readable($FQFN)));
176         } // END - if
177
178         // Return result
179         return $GLOBALS['file_readable'][$FQFN];
180 }
181
182 // Checks wether the given FQFN is a directory and not ., .. or .svn
183 function isDirectory ($FQFN) {
184         // Do we have cache?
185         if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
186                 // Generate baseName
187                 $baseName = basename($FQFN);
188
189                 // Check it
190                 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
191         } // END - if
192
193         // Return the result
194         return $GLOBALS[__FUNCTION__][$FQFN];
195 }
196
197 // "Getter" for the real remote IP number
198 function detectRealIpAddress () {
199         // Get remote ip from environment
200         $remoteAddr = determineRealRemoteAddress();
201
202         // Is removeip installed?
203         if (isExtensionActive('removeip')) {
204                 // Then anonymize it
205                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
206         } // END - if
207
208         // Return it
209         return $remoteAddr;
210 }
211
212 // "Getter" for remote IP number
213 function detectRemoteAddr () {
214         // Get remote ip from environment
215         $remoteAddr = determineRealRemoteAddress(true);
216
217         // Is removeip installed?
218         if (isExtensionActive('removeip')) {
219                 // Then anonymize it
220                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
221         } // END - if
222
223         // Return it
224         return $remoteAddr;
225 }
226
227 // "Getter" for remote hostname
228 function detectRemoteHostname () {
229         // Get remote ip from environment
230         $remoteHost = getenv('REMOTE_HOST');
231
232         // Is removeip installed?
233         if (isExtensionActive('removeip')) {
234                 // Then anonymize it
235                 $remoteHost = getAnonymousRemoteHost($remoteHost);
236         } // END - if
237
238         // Return it
239         return $remoteHost;
240 }
241
242 // "Getter" for user agent
243 function detectUserAgent ($alwaysReal = false) {
244         // Get remote ip from environment
245         $userAgent = getenv('HTTP_USER_AGENT');
246
247         // Is removeip installed?
248         if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
249                 // Then anonymize it
250                 $userAgent = getAnonymousUserAgent($userAgent);
251         } // END - if
252
253         // Return it
254         return $userAgent;
255 }
256
257 // "Getter" for referer
258 function detectReferer () {
259         // Get remote ip from environment
260         $referer = getenv('HTTP_REFERER');
261
262         // Is removeip installed?
263         if (isExtensionActive('removeip')) {
264                 // Then anonymize it
265                 $referer = getAnonymousReferer($referer);
266         } // END - if
267
268         // Return it
269         return $referer;
270 }
271
272 // "Getter" for request URI
273 function detectRequestUri () {
274         // Return it
275         return (getenv('REQUEST_URI'));
276 }
277
278 // "Getter" for query string
279 function detectQueryString () {
280         return str_replace('&', '&amp;', (getenv('QUERY_STRING')));
281 }
282
283 // "Getter" for SERVER_NAME
284 function detectServerName () {
285         // Return it
286         return (getenv('SERVER_NAME'));
287 }
288
289 // Removes any  existing www. from SERVER_NAME. This is very silly but enough
290 // for our purpose here.
291 function detectDomainName () {
292         // Do we have cache?
293         if (!isset($GLOBALS[__FUNCTION__])) {
294                 // Get server name
295                 $domainName = detectServerName();
296
297                 // Is there any www. ?
298                 if (substr($domainName, 0, 4) == 'www.') {
299                         // Remove it
300                         $domainName = substr($domainName, 4);
301                 } // END - if
302
303                 // Set cache
304                 $GLOBALS[__FUNCTION__] = $domainName;
305         } // END - if
306
307         // Return cache
308         return $GLOBALS[__FUNCTION__];
309 }
310
311 // Check wether we are installing
312 function isInstalling () {
313         // Determine wether we are installing
314         if (!isset($GLOBALS['mailer_installing'])) {
315                 // Check URL (css.php/js.php need this)
316                 $GLOBALS['mailer_installing'] = isGetRequestParameterSet('installing');
317         } // END - if
318
319         // Return result
320         return $GLOBALS['mailer_installing'];
321 }
322
323 // Check wether this script is installed
324 function isInstalled () {
325         // Do we have cache?
326         if (!isset($GLOBALS[__FUNCTION__])) {
327                 // Determine wether this script is installed
328                 $GLOBALS[__FUNCTION__] = (
329                 (
330                         // First is config
331                         (
332                                 (
333                                         isConfigEntrySet('MXCHANGE_INSTALLED')
334                                 ) && (
335                                         getConfig('MXCHANGE_INSTALLED') == 'Y'
336                                 )
337                         )
338                 ) || (
339                         // New config file found and loaded
340                         isIncludeReadable(getCachePath() . 'config-local.php')
341                 ) || (
342                         (
343                                 // New config file found, but not yet read
344                                 isIncludeReadable(getCachePath() . 'config-local.php')
345                         ) && (
346                                 (
347                                         // Only new config file is found
348                                         !isIncludeReadable('inc/config.php')
349                                 ) || (
350                                         // Is installation mode
351                                         !isInstalling()
352                                 )
353                         )
354                 ));
355         } // END - if
356
357         // Then use the cache
358         return $GLOBALS[__FUNCTION__];
359 }
360
361 // Check wether an admin is registered
362 function isAdminRegistered () {
363         // Is cache set?
364         if (!isset($GLOBALS[__FUNCTION__])) {
365                 // Simply check it
366                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
367         } // END - if
368
369         // Return it
370         return $GLOBALS[__FUNCTION__];
371 }
372
373 // Checks wether the reset mode is active
374 function isResetModeEnabled () {
375         // Now simply check it
376         return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
377 }
378
379 // Checks wether the debug mode is enabled
380 function isDebugModeEnabled () {
381         // Is cache set?
382         if (!isset($GLOBALS[__FUNCTION__])) {
383                 // Simply check it
384                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
385         } // END - if
386
387         // Return it
388         return $GLOBALS[__FUNCTION__];
389 }
390
391 // Checks wether SQL debugging is enabled
392 function isSqlDebuggingEnabled () {
393         // Is cache set?
394         if (!isset($GLOBALS[__FUNCTION__])) {
395                 // Determine if SQL debugging is enabled
396                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
397         } // END - if
398
399         // Return it
400         return $GLOBALS[__FUNCTION__];
401 }
402
403 // Checks wether we shall debug regular expressions
404 function isDebugRegularExpressionEnabled () {
405         // Is cache set?
406         if (!isset($GLOBALS[__FUNCTION__])) {
407                 // Simply check it
408                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
409         } // END - if
410
411         // Return it
412         return $GLOBALS[__FUNCTION__];
413 }
414
415 // Checks wether the cache instance is valid
416 function isCacheInstanceValid () {
417         return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
418 }
419
420 // Copies a file from source to destination and verifies if that goes fine.
421 // This function should wrap the copy() command and make a nicer debug backtrace
422 // even if there is no xdebug extension installed.
423 function copyFileVerified ($source, $dest, $chmod = '') {
424         // Failed is the default
425         $status = false;
426
427         // Is the source file there?
428         if (!isFileReadable($source)) {
429                 // Then abort here
430                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
431         } // END - if
432
433         // Is the target directory there?
434         if (!isDirectory(dirname($dest))) {
435                 // Then abort here
436                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
437         } // END - if
438
439         // Now try to copy it
440         if (!copy($source, $dest)) {
441                 // Something went wrong
442                 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
443         } else {
444                 // Reset cache
445                 $GLOBALS['file_readable'][$dest] = true;
446         }
447
448         // If there are chmod rights set, apply them
449         if (!empty($chmod)) {
450                 // Try to apply them
451                 $status = changeMode($dest, $chmod);
452         } else {
453                 // All fine
454                 $status = true;
455         }
456
457         // All fine
458         return $status;
459 }
460
461 // Wrapper function for header()
462 // Send a header but checks before if we can do so
463 function sendHeader ($header) {
464         // Send the header
465         //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header);
466         $GLOBALS['header'][] = trim($header);
467 }
468
469 // Flushes all headers
470 function flushHeaders () {
471         // Is the header already sent?
472         if (headers_sent()) {
473                 // Then abort here
474                 debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!');
475         } // END - if
476
477         // Flush all headers if found
478         if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) {
479                 foreach ($GLOBALS['header'] as $header) {
480                         header($header);
481                 } // END - foreach
482         } // END - if
483
484         // Mark them as flushed
485         $GLOBALS['header'] = array();
486 }
487
488 // Wrapper function for chmod()
489 // @TODO Do some more sanity check here
490 function changeMode ($FQFN, $mode) {
491         // Is the file/directory there?
492         if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
493                 // Neither, so abort here
494                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
495         } // END - if
496
497         // Try to set them
498         return chmod($FQFN, $mode);
499 }
500
501 // Wrapper for unlink()
502 function removeFile ($FQFN) {
503         // Is the file there?
504         if (isFileReadable($FQFN)) {
505                 // Reset cache first
506                 $GLOBALS['file_readable'][$FQFN] = false;
507
508                 // Yes, so remove it
509                 return unlink($FQFN);
510         } // END - if
511
512         // All fine if no file was removed. If we change this to 'false' or rewrite
513         // above if() block it would be to restrictive.
514         return true;
515 }
516
517 // Wrapper for $_POST['sel']
518 function countPostSelection ($element = 'sel') {
519         // Is it set?
520         if (isPostRequestParameterSet($element)) {
521                 // Return counted elements
522                 return countSelection(postRequestParameter($element));
523         } else {
524                 // Return zero if not found
525                 return 0;
526         }
527 }
528
529 // Checks wether the config-local.php is loaded
530 function isConfigLocalLoaded () {
531         return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
532 }
533
534 // Checks wether a nickname or userid was entered and caches the result
535 function isNicknameUsed ($userid) {
536         // Is the cache there
537         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
538                 // Determine it
539                 $GLOBALS[__FUNCTION__][$userid] = (('' . round($userid) . '') != $userid);
540         } // END - if
541
542         // Return the result
543         return $GLOBALS[__FUNCTION__][$userid];
544 }
545
546 // Getter for 'what' value
547 function getWhat () {
548         // Default is null
549         $what = null;
550
551         // Is the value set?
552         if (isWhatSet(true)) {
553                 // Then use it
554                 $what = $GLOBALS['what'];
555         } // END - if
556
557         // Return it
558         return $what;
559 }
560
561 // Setter for 'what' value
562 function setWhat ($newWhat) {
563         $GLOBALS['what'] = SQL_ESCAPE($newWhat);
564 }
565
566 // Setter for 'what' from configuration
567 function setWhatFromConfig ($configEntry) {
568         // Get 'what' from config
569         $what = getConfig($configEntry);
570
571         // Set it
572         setWhat($what);
573 }
574
575 // Checks wether what is set and optionally aborts on miss
576 function isWhatSet ($strict =  false) {
577         // Check for it
578         $isset = isset($GLOBALS['what']);
579
580         // Should we abort here?
581         if (($strict === true) && ($isset === false)) {
582                 // Output backtrace
583                 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
584         } // END - if
585
586         // Return it
587         return $isset;
588 }
589
590 // Getter for 'action' value
591 function getAction ($strict = true) {
592         // Default is null
593         $action = null;
594
595         // Is the value set?
596         if (isActionSet(($strict) && (isHtmlOutputMode()))) {
597                 // Then use it
598                 $action = $GLOBALS['action'];
599         } // END - if
600
601         // Return it
602         return $action;
603 }
604
605 // Setter for 'action' value
606 function setAction ($newAction) {
607         $GLOBALS['action'] = SQL_ESCAPE($newAction);
608 }
609
610 // Checks wether action is set and optionally aborts on miss
611 function isActionSet ($strict =  false) {
612         // Check for it
613         $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action'])));
614
615         // Should we abort here?
616         if (($strict === true) && ($isset === false)) {
617                 // Output backtrace
618                 debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.');
619         } // END - if
620
621         // Return it
622         return $isset;
623 }
624
625 // Getter for 'module' value
626 function getModule ($strict = true) {
627         // Default is null
628         $module = null;
629
630         // Is the value set?
631         if (isModuleSet($strict)) {
632                 // Then use it
633                 $module = $GLOBALS['module'];
634         } // END - if
635
636         // Return it
637         return $module;
638 }
639
640 // Setter for 'module' value
641 function setModule ($newModule) {
642         // Secure it and make all modules lower-case
643         $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
644 }
645
646 // Checks wether module is set and optionally aborts on miss
647 function isModuleSet ($strict =  false) {
648         // Check for it
649         $isset = (!empty($GLOBALS['module']));
650
651         // Should we abort here?
652         if (($strict === true) && ($isset === false)) {
653                 // Output backtrace
654                 debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.');
655         } // END - if
656
657         // Return it
658         return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
659 }
660
661 // Getter for 'output_mode' value
662 function getScriptOutputMode () {
663         // Do we have cache?
664         if (!isset($GLOBALS[__FUNCTION__])) {
665                 // Default is null
666                 $output_mode = null;
667
668                 // Is the value set?
669                 if (isOutputModeSet(true)) {
670                         // Then use it
671                         $output_mode = $GLOBALS['output_mode'];
672                 } // END - if
673
674                 // Store it in cache
675                 $GLOBALS[__FUNCTION__] = $output_mode;
676         } // END - if
677
678         // Return cache
679         return $GLOBALS[__FUNCTION__];
680 }
681
682 // Setter for 'output_mode' value
683 function setOutputMode ($newOutputMode) {
684         $GLOBALS['output_mode'] = (int) $newOutputMode;
685 }
686
687 // Checks wether output_mode is set and optionally aborts on miss
688 function isOutputModeSet ($strict =  false) {
689         // Check for it
690         $isset = (isset($GLOBALS['output_mode']));
691
692         // Should we abort here?
693         if (($strict === true) && ($isset === false)) {
694                 // Output backtrace
695                 debug_report_bug(__FUNCTION__, __LINE__, 'Output mode is not set.');
696         } // END - if
697
698         // Return it
699         return $isset;
700 }
701
702 // Enables block-mode
703 function enableBlockMode ($enabled = true) {
704         $GLOBALS['block_mode'] = $enabled;
705 }
706
707 // Checks wether block-mode is enabled
708 function isBlockModeEnabled () {
709         // Abort if not set
710         if (!isset($GLOBALS['block_mode'])) {
711                 // Needs to be fixed
712                 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
713         } // END - if
714
715         // Return it
716         return $GLOBALS['block_mode'];
717 }
718
719 // Wrapper function for addPointsThroughReferalSystem()
720 function addPointsDirectly ($subject, $userid, $points) {
721         // Reset level here
722         unset($GLOBALS['ref_level']);
723
724         // Call more complicated method (due to more parameters)
725         return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'direct');
726 }
727
728 // Wrapper for redirectToUrl but URL comes from a configuration entry
729 function redirectToConfiguredUrl ($configEntry) {
730         // Load the URL
731         redirectToUrl(getConfig($configEntry));
732 }
733
734 // Wrapper function to redirect from member-only modules to index
735 function redirectToIndexMemberOnlyModule () {
736         // Do the redirect here
737         redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
738 }
739
740 // Wrapper function to redirect to current URL
741 function redirectToRequestUri () {
742         redirectToUrl(basename(detectRequestUri()));
743 }
744
745 // Wrapper function to redirect to de-refered URL
746 function redirectToDereferedUrl ($URL) {
747         // Redirect to to
748         redirectToUrl(generateDerefererUrl($URL));
749 }
750
751 // Wrapper function for checking if extension is installed and newer or same version
752 function isExtensionInstalledAndNewer ($ext_name, $version) {
753         // Is an cache entry found?
754         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
755                 // Determine it
756                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
757         } else {
758                 // Cache hits should be incremented twice
759                 incrementStatsEntry('cache_hits', 2);
760         }
761
762         // Return it
763         //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'=&gt;'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
764         return $GLOBALS[__FUNCTION__][$ext_name][$version];
765 }
766
767 // Wrapper function for checking if extension is installed and older than given version
768 function isExtensionInstalledAndOlder ($ext_name, $version) {
769         // Is an cache entry found?
770         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
771                 // Determine it
772                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
773         } else {
774                 // Cache hits should be incremented twice
775                 incrementStatsEntry('cache_hits', 2);
776         }
777
778         // Return it
779         //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'&lt;'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
780         return $GLOBALS[__FUNCTION__][$ext_name][$version];
781 }
782
783 // Set username
784 function setUsername ($userName) {
785         $GLOBALS['username'] = (string) $userName;
786 }
787
788 // Get username
789 function getUsername () {
790         // User name set?
791         if (!isset($GLOBALS['username'])) {
792                 // No, so it has to be a guest
793                 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
794         } // END - if
795
796         // Return it
797         return $GLOBALS['username'];
798 }
799
800 // Wrapper function for installation phase
801 function isInstallationPhase () {
802         // Do we have cache?
803         if (!isset($GLOBALS[__FUNCTION__])) {
804                 // Determine it
805                 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
806         } // END - if
807
808         // Return result
809         return $GLOBALS[__FUNCTION__];
810 }
811
812 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
813 function isDemoModeActive () {
814         // Is cache set?
815         if (!isset($GLOBALS[__FUNCTION__])) {
816                 // Simply check it
817                 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
818         } // END - if
819
820         // Return it
821         return $GLOBALS[__FUNCTION__];
822 }
823
824 // Getter for PHP caching value
825 function getPhpCaching () {
826         return $GLOBALS['php_caching'];
827 }
828
829 // Checks wether the admin hash is set
830 function isAdminHashSet ($adminId) {
831         // Is the array there?
832         if (!isset($GLOBALS['cache_array']['admin'])) {
833                 // Missing array should be reported
834                 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
835         } // END - if
836
837         // Check for admin hash
838         return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
839 }
840
841 // Setter for admin hash
842 function setAdminHash ($adminId, $hash) {
843         $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
844 }
845
846 // Getter for current admin login
847 function getCurrentAdminLogin () {
848         // Log debug message
849         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
850
851         // Do we have cache?
852         if (!isset($GLOBALS[__FUNCTION__])) {
853                 // Determine it
854                 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
855         } // END - if
856
857         // Return it
858         return $GLOBALS[__FUNCTION__];
859 }
860
861 // Setter for admin id (and current)
862 function setAdminId ($adminId) {
863         // Log debug message
864         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
865
866         // Set session
867         $status = setSession('admin_id', bigintval($adminId));
868
869         // Set current id
870         setCurrentAdminId($adminId);
871
872         // Return status
873         return $status;
874 }
875
876 // Setter for admin_last
877 function setAdminLast ($adminLast) {
878         // Log debug message
879         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
880
881         // Set session
882         $status = setSession('admin_last', $adminLast);
883
884         // Return status
885         return $status;
886 }
887
888 // Setter for admin_md5
889 function setAdminMd5 ($adminMd5) {
890         // Log debug message
891         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
892
893         // Set session
894         $status = setSession('admin_md5', $adminMd5);
895
896         // Return status
897         return $status;
898 }
899
900 // Getter for admin_md5
901 function getAdminMd5 () {
902         // Log debug message
903         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
904
905         // Get session
906         return getSession('admin_md5');
907 }
908
909 // Init user data array
910 function initUserData () {
911         // User id should not be zero
912         if (!isValidUserId(getCurrentUserId())) {
913                 // Should be always valid
914                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
915         } // END - if
916
917         // Init the user
918         $GLOBALS['user_data'][getCurrentUserId()] = array();
919 }
920
921 // Getter for user data
922 function getUserData ($column) {
923         // User id should not be zero
924         if (!isValidUserId(getCurrentUserId())) {
925                 // Should be always valid
926                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
927         } // END - if
928
929         // Return the value
930         return $GLOBALS['user_data'][getCurrentUserId()][$column];
931 }
932
933 // Geter for whole user data array
934 function getUserDataArray () {
935         // Get user id
936         $userid = getCurrentUserId();
937
938         // Is the current userid valid?
939         if (!isValidUserId($userid)) {
940                 // Should be always valid
941                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
942         } // END - if
943
944         // Get the whole array if found
945         if (isset($GLOBALS['user_data'][$userid])) {
946                 // Found, so return it
947                 return $GLOBALS['user_data'][$userid];
948         } else {
949                 // Return empty array
950                 return array();
951         }
952 }
953
954 // Checks if the user data is valid, this may indicate that the user has logged
955 // in, but you should use isMember() if you want to find that out.
956 function isUserDataValid () {
957         // User id should not be zero so abort here
958         if (!isCurrentUserIdSet()) return false;
959
960         // Is it cached?
961         if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
962                 // Determine it
963                 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
964         } // END - if
965
966         // Return the result
967         return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
968 }
969
970 // Setter for current userid
971 function setCurrentUserId ($userid) {
972         // Set userid
973         $GLOBALS['current_userid'] = bigintval($userid);
974
975         // Unset it to re-determine the actual state
976         unset($GLOBALS['is_userdata_valid'][$userid]);
977 }
978
979 // Getter for current userid
980 function getCurrentUserId () {
981         // Userid must be set before it can be used
982         if (!isCurrentUserIdSet()) {
983                 // Not set
984                 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
985         } // END - if
986
987         // Return the userid
988         return $GLOBALS['current_userid'];
989 }
990
991 // Checks if current userid is set
992 function isCurrentUserIdSet () {
993         return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
994 }
995
996 // Checks wether we are debugging template cache
997 function isDebuggingTemplateCache () {
998         // Do we have cache?
999         if (!isset($GLOBALS[__FUNCTION__])) {
1000                 // Determine it
1001                 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1002         } // END - if
1003
1004         // Return cache
1005         return $GLOBALS[__FUNCTION__];
1006 }
1007
1008 // Wrapper for fetchUserData() and getUserData() calls
1009 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1010         // Is it cached?
1011         if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1012                 // Default is 'guest'
1013                 $data = '{--USERNAME_GUEST--}';
1014
1015                 // Can we fetch the user data?
1016                 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1017                         // Now get the data back
1018                         $data = getUserData($valueColumn);
1019                 } // END - if
1020
1021                 // Cache it
1022                 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1023         } // END - if
1024
1025         // Return it
1026         return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1027 }
1028
1029 // Wrapper for strpos() to ease porting from deprecated ereg() function
1030 function isInString ($needle, $haystack) {
1031         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1032         return (strpos($haystack, $needle) !== false);
1033 }
1034
1035 // Wrapper for strpos() to ease porting from deprecated eregi() function
1036 // This function is case-insensitive
1037 function isInStringIgnoreCase ($needle, $haystack) {
1038         return (isInString(strtolower($needle), strtolower($haystack)));
1039 }
1040
1041 // Wrapper to check for if fatal errors where detected
1042 function ifFatalErrorsDetected () {
1043         // Just call the inner function
1044         return (getTotalFatalErrors() > 0);
1045 }
1046
1047 // Setter for HTTP status
1048 function setHttpStatus ($status) {
1049         $GLOBALS['http_status'] = (string) $status;
1050 }
1051
1052 // Getter for HTTP status
1053 function getHttpStatus () {
1054         // Is the status set?
1055         if (!isset($GLOBALS['http_status'])) {
1056                 // Abort here
1057                 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1058         } // END - if
1059
1060         // Return it
1061         return $GLOBALS['http_status'];
1062 }
1063
1064 /**
1065  * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1066  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1067  *
1068  * ----------------------------------------------------------------------------
1069  * If you want to redirect, please use redirectToUrl(); instead
1070  * ----------------------------------------------------------------------------
1071  *
1072  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1073  *
1074  * @link    http://support.microsoft.com/kb/q176113/
1075  * @author  Andreas Gohr <andi@splitbrain.org>
1076  * @access  private
1077  */
1078 function sendRawRedirect ($url) {
1079         // Send helping header
1080         setHttpStatus('302 Found');
1081
1082         // always close the session
1083         session_write_close();
1084
1085         // Revert entity &amp;
1086         $url = str_replace('&amp;', '&', $url);
1087
1088         // check if running on IIS < 6 with CGI-PHP
1089         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1090                 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
1091                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1092                 ($matches[1] < 6)) {
1093                 // Send the IIS header
1094                 sendHeader('Refresh: 0;url=' . $url);
1095         } else {
1096                 // Send generic header
1097                 sendHeader('Location: ' . $url);
1098         }
1099
1100         // Shutdown here
1101         shutdown();
1102 }
1103
1104 // Determines the country of the given user id
1105 function determineCountry ($userid) {
1106         // Do we have cache?
1107         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1108                 // Default is 'invalid'
1109                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1110
1111                 // Is extension country active?
1112                 if (isExtensionActive('country')) {
1113                         // Determine the right country code through the country id
1114                         $id = getUserData('country_code');
1115
1116                         // Then handle it over
1117                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1118                 } else {
1119                         // Get raw code from user data
1120                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1121                 }
1122         } // END - if
1123
1124         // Return cache
1125         return $GLOBALS[__FUNCTION__][$userid];
1126 }
1127
1128 // "Getter" for total confirmed user accounts
1129 function getTotalConfirmedUser () {
1130         // Is it cached?
1131         if (!isset($GLOBALS[__FUNCTION__])) {
1132                 // Then do it
1133                 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1134         } // END - if
1135
1136         // Return cached value
1137         return $GLOBALS[__FUNCTION__];
1138 }
1139
1140 // "Getter" for total unconfirmed user accounts
1141 function getTotalUnconfirmedUser () {
1142         // Is it cached?
1143         if (!isset($GLOBALS[__FUNCTION__])) {
1144                 // Then do it
1145                 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1146         } // END - if
1147
1148         // Return cached value
1149         return $GLOBALS[__FUNCTION__];
1150 }
1151
1152 // "Getter" for total locked user accounts
1153 function getTotalLockedUser () {
1154         // Is it cached?
1155         if (!isset($GLOBALS[__FUNCTION__])) {
1156                 // Then do it
1157                 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1158         } // END - if
1159
1160         // Return cached value
1161         return $GLOBALS[__FUNCTION__];
1162 }
1163
1164 // Is given userid valid?
1165 function isValidUserId ($userid) {
1166         // Do we have cache?
1167         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1168                 // Check it out
1169                 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1170         } // END - if
1171
1172         // Return cache
1173         return $GLOBALS[__FUNCTION__][$userid];
1174 }
1175
1176 // Encodes entities
1177 function encodeEntities ($str) {
1178         // Secure it first
1179         $str = secureString($str, true, true);
1180
1181         // Encode dollar sign as well
1182         $str = str_replace('$', '&#36;', $str);
1183
1184         // Return it
1185         return $str;
1186 }
1187
1188 // "Getter" for date from patch_ctime
1189 function getDateFromPatchTime () {
1190         // Is it cached?
1191         if (!isset($GLOBALS[__FUNCTION__])) {
1192                 // Then set it
1193                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1194         } // END - if
1195
1196         // Return cache
1197         return $GLOBALS[__FUNCTION__];
1198 }
1199
1200 // Getter for current year (default)
1201 function getYear ($timestamp = null) {
1202         // Is it cached?
1203         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1204                 // null is time()
1205                 if (is_null($timestamp)) $timestamp = time();
1206
1207                 // Then create it
1208                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1209         } // END - if
1210
1211         // Return cache
1212         return $GLOBALS[__FUNCTION__][$timestamp];
1213 }
1214
1215 // Getter for current month (default)
1216 function getMonth ($timestamp = null) {
1217         // Is it cached?
1218         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1219                 // If null is set, use time()
1220                 if (is_null($timestamp)) {
1221                         // Use time() which is current timestamp
1222                         $timestamp = time();
1223                 } // END - if
1224
1225                 // Then create it
1226                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1227         } // END - if
1228
1229         // Return cache
1230         return $GLOBALS[__FUNCTION__][$timestamp];
1231 }
1232
1233 // Getter for current day (default)
1234 function getDay ($timestamp = null) {
1235         // Is it cached?
1236         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1237                 // null is time()
1238                 if (is_null($timestamp)) $timestamp = time();
1239
1240                 // Then create it
1241                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1242         } // END - if
1243
1244         // Return cache
1245         return $GLOBALS[__FUNCTION__][$timestamp];
1246 }
1247
1248 // Getter for current week (default)
1249 function getWeek ($timestamp = null) {
1250         // Is it cached?
1251         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1252                 // null is time()
1253                 if (is_null($timestamp)) $timestamp = time();
1254
1255                 // Then create it
1256                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1257         } // END - if
1258
1259         // Return cache
1260         return $GLOBALS[__FUNCTION__][$timestamp];
1261 }
1262
1263 // Getter for current short_hour (default)
1264 function getShortHour ($timestamp = null) {
1265         // Is it cached?
1266         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1267                 // null is time()
1268                 if (is_null($timestamp)) $timestamp = time();
1269
1270                 // Then create it
1271                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1272         } // END - if
1273
1274         // Return cache
1275         return $GLOBALS[__FUNCTION__][$timestamp];
1276 }
1277
1278 // Getter for current long_hour (default)
1279 function getLongHour ($timestamp = null) {
1280         // Is it cached?
1281         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1282                 // null is time()
1283                 if (is_null($timestamp)) $timestamp = time();
1284
1285                 // Then create it
1286                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1287         } // END - if
1288
1289         // Return cache
1290         return $GLOBALS[__FUNCTION__][$timestamp];
1291 }
1292
1293 // Getter for current second (default)
1294 function getSecond ($timestamp = null) {
1295         // Is it cached?
1296         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1297                 // null is time()
1298                 if (is_null($timestamp)) $timestamp = time();
1299
1300                 // Then create it
1301                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1302         } // END - if
1303
1304         // Return cache
1305         return $GLOBALS[__FUNCTION__][$timestamp];
1306 }
1307
1308 // Getter for current minute (default)
1309 function getMinute ($timestamp = null) {
1310         // Is it cached?
1311         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1312                 // null is time()
1313                 if (is_null($timestamp)) $timestamp = time();
1314
1315                 // Then create it
1316                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1317         } // END - if
1318
1319         // Return cache
1320         return $GLOBALS[__FUNCTION__][$timestamp];
1321 }
1322
1323 // Checks wether the title decoration is enabled
1324 function isTitleDecorationEnabled () {
1325         // Do we have cache?
1326         if (!isset($GLOBALS[__FUNCTION__])) {
1327                 // Just check it
1328                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1329         } // END - if
1330
1331         // Return cache
1332         return $GLOBALS[__FUNCTION__];
1333 }
1334
1335 // Checks wether filter usage updates are enabled (expensive queries!)
1336 function isFilterUsageUpdateEnabled () {
1337         // Do we have cache?
1338         if (!isset($GLOBALS[__FUNCTION__])) {
1339                 // Determine it
1340                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1341         } // END - if
1342
1343         // Return cache
1344         return $GLOBALS[__FUNCTION__];
1345 }
1346
1347 // Checks wether debugging of weekly resets is enabled
1348 function isWeeklyResetDebugEnabled () {
1349         // Do we have cache?
1350         if (!isset($GLOBALS[__FUNCTION__])) {
1351                 // Determine it
1352                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1353         } // END - if
1354
1355         // Return cache
1356         return $GLOBALS[__FUNCTION__];
1357 }
1358
1359 // Checks wether debugging of monthly resets is enabled
1360 function isMonthlyResetDebugEnabled () {
1361         // Do we have cache?
1362         if (!isset($GLOBALS[__FUNCTION__])) {
1363                 // Determine it
1364                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1365         } // END - if
1366
1367         // Return cache
1368         return $GLOBALS[__FUNCTION__];
1369 }
1370
1371 // Checks wether displaying of debug SQLs are enabled
1372 function isDisplayDebugSqlEnabled () {
1373         // Do we have cache?
1374         if (!isset($GLOBALS[__FUNCTION__])) {
1375                 // Determine it
1376                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1377         } // END - if
1378
1379         // Return cache
1380         return $GLOBALS[__FUNCTION__];
1381 }
1382
1383 // Checks wether module title is enabled
1384 function isModuleTitleEnabled () {
1385         // Do we have cache?
1386         if (!isset($GLOBALS[__FUNCTION__])) {
1387                 // Determine it
1388                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1389         } // END - if
1390
1391         // Return cache
1392         return $GLOBALS[__FUNCTION__];
1393 }
1394
1395 // Checks wether what title is enabled
1396 function isWhatTitleEnabled () {
1397         // Do we have cache?
1398         if (!isset($GLOBALS[__FUNCTION__])) {
1399                 // Determine it
1400                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1401         } // END - if
1402
1403         // Return cache
1404         return $GLOBALS[__FUNCTION__];
1405 }
1406
1407 // Checks wether stats are enabled
1408 function ifStatsAreEnabled () {
1409         // Do we have cache?
1410         if (!isset($GLOBALS[__FUNCTION__])) {
1411                 // Then determine it
1412                 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1413         } // END - if
1414
1415         // Return cached value
1416         return $GLOBALS[__FUNCTION__];
1417 }
1418
1419 // Checks wether admin-notification of certain user actions is enabled
1420 function isAdminNotificationEnabled () {
1421         // Do we have cache?
1422         if (!isset($GLOBALS[__FUNCTION__])) {
1423                 // Determine it
1424                 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1425         } // END - if
1426
1427         // Return cache
1428         return $GLOBALS[__FUNCTION__];
1429 }
1430
1431 // Checks wether random referal id selection is enabled
1432 function isRandomReferalIdEnabled () {
1433         // Do we have cache?
1434         if (!isset($GLOBALS[__FUNCTION__])) {
1435                 // Determine it
1436                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1437         } // END - if
1438
1439         // Return cache
1440         return $GLOBALS[__FUNCTION__];
1441 }
1442
1443 // "Getter" for default language
1444 function getDefaultLanguage () {
1445         // Do we have cache?
1446         if (!isset($GLOBALS[__FUNCTION__])) {
1447                 // Determine it
1448                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1449         } // END - if
1450
1451         // Return cache
1452         return $GLOBALS[__FUNCTION__];
1453 }
1454
1455 // "Getter" for default referal id
1456 function getDefRefid () {
1457         // Do we have cache?
1458         if (!isset($GLOBALS[__FUNCTION__])) {
1459                 // Determine it
1460                 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1461         } // END - if
1462
1463         // Return cache
1464         return $GLOBALS[__FUNCTION__];
1465 }
1466
1467 // "Getter" for path
1468 function getPath () {
1469         // Do we have cache?
1470         if (!isset($GLOBALS[__FUNCTION__])) {
1471                 // Determine it
1472                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1473         } // END - if
1474
1475         // Return cache
1476         return $GLOBALS[__FUNCTION__];
1477 }
1478
1479 // "Getter" for url
1480 function getUrl () {
1481         // Do we have cache?
1482         if (!isset($GLOBALS[__FUNCTION__])) {
1483                 // Determine it
1484                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1485         } // END - if
1486
1487         // Return cache
1488         return $GLOBALS[__FUNCTION__];
1489 }
1490
1491 // "Getter" for cache_path
1492 function getCachePath () {
1493         // Do we have cache?
1494         if (!isset($GLOBALS[__FUNCTION__])) {
1495                 // Determine it
1496                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1497         } // END - if
1498
1499         // Return cache
1500         return $GLOBALS[__FUNCTION__];
1501 }
1502
1503 // "Getter" for secret_key
1504 function getSecretKey () {
1505         // Do we have cache?
1506         if (!isset($GLOBALS[__FUNCTION__])) {
1507                 // Determine it
1508                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1509         } // END - if
1510
1511         // Return cache
1512         return $GLOBALS[__FUNCTION__];
1513 }
1514
1515 // "Getter" for master_salt
1516 function getMasterSalt () {
1517         // Do we have cache?
1518         if (!isset($GLOBALS[__FUNCTION__])) {
1519                 // Determine it
1520                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1521         } // END - if
1522
1523         // Return cache
1524         return $GLOBALS[__FUNCTION__];
1525 }
1526
1527 // "Getter" for prime
1528 function getPrime () {
1529         // Do we have cache?
1530         if (!isset($GLOBALS[__FUNCTION__])) {
1531                 // Determine it
1532                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1533         } // END - if
1534
1535         // Return cache
1536         return $GLOBALS[__FUNCTION__];
1537 }
1538
1539 // "Getter" for encrypt_seperator
1540 function getEncryptSeperator () {
1541         // Do we have cache?
1542         if (!isset($GLOBALS[__FUNCTION__])) {
1543                 // Determine it
1544                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1545         } // END - if
1546
1547         // Return cache
1548         return $GLOBALS[__FUNCTION__];
1549 }
1550
1551 // "Getter" for mysql_prefix
1552 function getMysqlPrefix () {
1553         // Do we have cache?
1554         if (!isset($GLOBALS[__FUNCTION__])) {
1555                 // Determine it
1556                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1557         } // END - if
1558
1559         // Return cache
1560         return $GLOBALS[__FUNCTION__];
1561 }
1562
1563 // "Getter" for table_type
1564 function getTableType () {
1565         // Do we have cache?
1566         if (!isset($GLOBALS[__FUNCTION__])) {
1567                 // Determine it
1568                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1569         } // END - if
1570
1571         // Return cache
1572         return $GLOBALS[__FUNCTION__];
1573 }
1574
1575 // "Getter" for salt_length
1576 function getSaltLength () {
1577         // Do we have cache?
1578         if (!isset($GLOBALS[__FUNCTION__])) {
1579                 // Determine it
1580                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1581         } // END - if
1582
1583         // Return cache
1584         return $GLOBALS[__FUNCTION__];
1585 }
1586
1587 // "Getter" for output_mode
1588 function getOutputMode () {
1589         // Do we have cache?
1590         if (!isset($GLOBALS[__FUNCTION__])) {
1591                 // Determine it
1592                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1593         } // END - if
1594
1595         // Return cache
1596         return $GLOBALS[__FUNCTION__];
1597 }
1598
1599 // "Getter" for full_version
1600 function getFullVersion () {
1601         // Do we have cache?
1602         if (!isset($GLOBALS[__FUNCTION__])) {
1603                 // Determine it
1604                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1605         } // END - if
1606
1607         // Return cache
1608         return $GLOBALS[__FUNCTION__];
1609 }
1610
1611 // "Getter" for title
1612 function getTitle () {
1613         // Do we have cache?
1614         if (!isset($GLOBALS[__FUNCTION__])) {
1615                 // Determine it
1616                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1617         } // END - if
1618
1619         // Return cache
1620         return $GLOBALS[__FUNCTION__];
1621 }
1622
1623 // "Getter" for curr_svn_revision
1624 function getCurrentRepositoryRevision () {
1625         // Do we have cache?
1626         if (!isset($GLOBALS[__FUNCTION__])) {
1627                 // Determine it
1628                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1629         } // END - if
1630
1631         // Return cache
1632         return $GLOBALS[__FUNCTION__];
1633 }
1634
1635 // "Getter" for server_url
1636 function getServerUrl () {
1637         // Do we have cache?
1638         if (!isset($GLOBALS[__FUNCTION__])) {
1639                 // Determine it
1640                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1641         } // END - if
1642
1643         // Return cache
1644         return $GLOBALS[__FUNCTION__];
1645 }
1646
1647 // "Getter" for mt_word
1648 function getMtWord () {
1649         // Do we have cache?
1650         if (!isset($GLOBALS[__FUNCTION__])) {
1651                 // Determine it
1652                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1653         } // END - if
1654
1655         // Return cache
1656         return $GLOBALS[__FUNCTION__];
1657 }
1658
1659 // "Getter" for mt_word2
1660 function getMtWord2 () {
1661         // Do we have cache?
1662         if (!isset($GLOBALS[__FUNCTION__])) {
1663                 // Determine it
1664                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1665         } // END - if
1666
1667         // Return cache
1668         return $GLOBALS[__FUNCTION__];
1669 }
1670
1671 // "Getter" for main_title
1672 function getMainTitle () {
1673         // Do we have cache?
1674         if (!isset($GLOBALS[__FUNCTION__])) {
1675                 // Determine it
1676                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1677         } // END - if
1678
1679         // Return cache
1680         return $GLOBALS[__FUNCTION__];
1681 }
1682
1683 // "Getter" for file_hash
1684 function getFileHash () {
1685         // Do we have cache?
1686         if (!isset($GLOBALS[__FUNCTION__])) {
1687                 // Determine it
1688                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1689         } // END - if
1690
1691         // Return cache
1692         return $GLOBALS[__FUNCTION__];
1693 }
1694
1695 // "Getter" for pass_scramble
1696 function getPassScramble () {
1697         // Do we have cache?
1698         if (!isset($GLOBALS[__FUNCTION__])) {
1699                 // Determine it
1700                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1701         } // END - if
1702
1703         // Return cache
1704         return $GLOBALS[__FUNCTION__];
1705 }
1706
1707 // "Getter" for ap_inactive_since
1708 function getApInactiveSince () {
1709         // Do we have cache?
1710         if (!isset($GLOBALS[__FUNCTION__])) {
1711                 // Determine it
1712                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1713         } // END - if
1714
1715         // Return cache
1716         return $GLOBALS[__FUNCTION__];
1717 }
1718
1719 // "Getter" for user_min_confirmed
1720 function getUserMinConfirmed () {
1721         // Do we have cache?
1722         if (!isset($GLOBALS[__FUNCTION__])) {
1723                 // Determine it
1724                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1725         } // END - if
1726
1727         // Return cache
1728         return $GLOBALS[__FUNCTION__];
1729 }
1730
1731 // "Getter" for auto_purge
1732 function getAutoPurge () {
1733         // Do we have cache?
1734         if (!isset($GLOBALS[__FUNCTION__])) {
1735                 // Determine it
1736                 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1737         } // END - if
1738
1739         // Return cache
1740         return $GLOBALS[__FUNCTION__];
1741 }
1742
1743 // "Getter" for bonus_userid
1744 function getBonusUserid () {
1745         // Do we have cache?
1746         if (!isset($GLOBALS[__FUNCTION__])) {
1747                 // Determine it
1748                 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1749         } // END - if
1750
1751         // Return cache
1752         return $GLOBALS[__FUNCTION__];
1753 }
1754
1755 // "Getter" for ap_inactive_time
1756 function getApInactiveTime () {
1757         // Do we have cache?
1758         if (!isset($GLOBALS[__FUNCTION__])) {
1759                 // Determine it
1760                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1761         } // END - if
1762
1763         // Return cache
1764         return $GLOBALS[__FUNCTION__];
1765 }
1766
1767 // "Getter" for ap_dm_timeout
1768 function getApDmTimeout () {
1769         // Do we have cache?
1770         if (!isset($GLOBALS[__FUNCTION__])) {
1771                 // Determine it
1772                 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1773         } // END - if
1774
1775         // Return cache
1776         return $GLOBALS[__FUNCTION__];
1777 }
1778
1779 // "Getter" for ap_tasks_time
1780 function getApTasksTime () {
1781         // Do we have cache?
1782         if (!isset($GLOBALS[__FUNCTION__])) {
1783                 // Determine it
1784                 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1785         } // END - if
1786
1787         // Return cache
1788         return $GLOBALS[__FUNCTION__];
1789 }
1790
1791 // "Getter" for ap_unconfirmed_time
1792 function getApUnconfirmedTime () {
1793         // Do we have cache?
1794         if (!isset($GLOBALS[__FUNCTION__])) {
1795                 // Determine it
1796                 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1797         } // END - if
1798
1799         // Return cache
1800         return $GLOBALS[__FUNCTION__];
1801 }
1802
1803 // "Getter" for points
1804 function getPoints () {
1805         // Do we have cache?
1806         if (!isset($GLOBALS[__FUNCTION__])) {
1807                 // Determine it
1808                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1809         } // END - if
1810
1811         // Return cache
1812         return $GLOBALS[__FUNCTION__];
1813 }
1814
1815 // "Getter" for slogan
1816 function getSlogan () {
1817         // Do we have cache?
1818         if (!isset($GLOBALS[__FUNCTION__])) {
1819                 // Determine it
1820                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1821         } // END - if
1822
1823         // Return cache
1824         return $GLOBALS[__FUNCTION__];
1825 }
1826
1827 // "Getter" for copy
1828 function getCopy () {
1829         // Do we have cache?
1830         if (!isset($GLOBALS[__FUNCTION__])) {
1831                 // Determine it
1832                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1833         } // END - if
1834
1835         // Return cache
1836         return $GLOBALS[__FUNCTION__];
1837 }
1838
1839 // "Getter" for webmaster
1840 function getWebmaster () {
1841         // Do we have cache?
1842         if (!isset($GLOBALS[__FUNCTION__])) {
1843                 // Determine it
1844                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1845         } // END - if
1846
1847         // Return cache
1848         return $GLOBALS[__FUNCTION__];
1849 }
1850
1851 // "Getter" for sql_count
1852 function getSqlCount () {
1853         // Do we have cache?
1854         if (!isset($GLOBALS[__FUNCTION__])) {
1855                 // Determine it
1856                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1857         } // END - if
1858
1859         // Return cache
1860         return $GLOBALS[__FUNCTION__];
1861 }
1862
1863 // "Getter" for num_templates
1864 function getNumTemplates () {
1865         // Do we have cache?
1866         if (!isset($GLOBALS[__FUNCTION__])) {
1867                 // Determine it
1868                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1869         } // END - if
1870
1871         // Return cache
1872         return $GLOBALS[__FUNCTION__];
1873 }
1874
1875 // "Getter" for dns_cache_timeout
1876 function getDnsCacheTimeout () {
1877         // Do we have cache?
1878         if (!isset($GLOBALS[__FUNCTION__])) {
1879                 // Determine it
1880                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1881         } // END - if
1882
1883         // Return cache
1884         return $GLOBALS[__FUNCTION__];
1885 }
1886
1887 // "Getter" for menu_blur_spacer
1888 function getMenuBlurSpacer () {
1889         // Do we have cache?
1890         if (!isset($GLOBALS[__FUNCTION__])) {
1891                 // Determine it
1892                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
1893         } // END - if
1894
1895         // Return cache
1896         return $GLOBALS[__FUNCTION__];
1897 }
1898
1899 // "Getter" for points_register
1900 function getPointsRegister () {
1901         // Do we have cache?
1902         if (!isset($GLOBALS[__FUNCTION__])) {
1903                 // Determine it
1904                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
1905         } // END - if
1906
1907         // Return cache
1908         return $GLOBALS[__FUNCTION__];
1909 }
1910
1911 // "Getter" for points_ref
1912 function getPointsRef () {
1913         // Do we have cache?
1914         if (!isset($GLOBALS[__FUNCTION__])) {
1915                 // Determine it
1916                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
1917         } // END - if
1918
1919         // Return cache
1920         return $GLOBALS[__FUNCTION__];
1921 }
1922
1923 // "Getter" for ref_payout
1924 function getRefPayout () {
1925         // Do we have cache?
1926         if (!isset($GLOBALS[__FUNCTION__])) {
1927                 // Determine it
1928                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
1929         } // END - if
1930
1931         // Return cache
1932         return $GLOBALS[__FUNCTION__];
1933 }
1934
1935 // "Getter" for online_timeout
1936 function getOnlineTimeout () {
1937         // Do we have cache?
1938         if (!isset($GLOBALS[__FUNCTION__])) {
1939                 // Determine it
1940                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
1941         } // END - if
1942
1943         // Return cache
1944         return $GLOBALS[__FUNCTION__];
1945 }
1946
1947 // "Getter" for index_home
1948 function getIndexHome () {
1949         // Do we have cache?
1950         if (!isset($GLOBALS[__FUNCTION__])) {
1951                 // Determine it
1952                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
1953         } // END - if
1954
1955         // Return cache
1956         return $GLOBALS[__FUNCTION__];
1957 }
1958
1959 // "Getter" for one_day
1960 function getOneDay () {
1961         // Do we have cache?
1962         if (!isset($GLOBALS[__FUNCTION__])) {
1963                 // Determine it
1964                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
1965         } // END - if
1966
1967         // Return cache
1968         return $GLOBALS[__FUNCTION__];
1969 }
1970
1971 // "Getter" for activate_xchange
1972 function getActivateXchange () {
1973         // Do we have cache?
1974         if (!isset($GLOBALS[__FUNCTION__])) {
1975                 // Determine it
1976                 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
1977         } // END - if
1978
1979         // Return cache
1980         return $GLOBALS[__FUNCTION__];
1981 }
1982
1983 // "Getter" for img_type
1984 function getImgType () {
1985         // Do we have cache?
1986         if (!isset($GLOBALS[__FUNCTION__])) {
1987                 // Determine it
1988                 $GLOBALS[__FUNCTION__] = getConfig('img_type');
1989         } // END - if
1990
1991         // Return cache
1992         return $GLOBALS[__FUNCTION__];
1993 }
1994
1995 // "Getter" for code_length
1996 function getCodeLength () {
1997         // Do we have cache?
1998         if (!isset($GLOBALS[__FUNCTION__])) {
1999                 // Determine it
2000                 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2001         } // END - if
2002
2003         // Return cache
2004         return $GLOBALS[__FUNCTION__];
2005 }
2006
2007 // "Getter" for least_cats
2008 function getLeastCats () {
2009         // Do we have cache?
2010         if (!isset($GLOBALS[__FUNCTION__])) {
2011                 // Determine it
2012                 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2013         } // END - if
2014
2015         // Return cache
2016         return $GLOBALS[__FUNCTION__];
2017 }
2018
2019 // "Getter" for pass_len
2020 function getPassLen () {
2021         // Do we have cache?
2022         if (!isset($GLOBALS[__FUNCTION__])) {
2023                 // Determine it
2024                 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2025         } // END - if
2026
2027         // Return cache
2028         return $GLOBALS[__FUNCTION__];
2029 }
2030
2031 // "Getter" for admin_menu
2032 function getAdminMenu () {
2033         // Do we have cache?
2034         if (!isset($GLOBALS[__FUNCTION__])) {
2035                 // Determine it
2036                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2037         } // END - if
2038
2039         // Return cache
2040         return $GLOBALS[__FUNCTION__];
2041 }
2042
2043 // "Getter" for last_month
2044 function getLastMonth () {
2045         // Do we have cache?
2046         if (!isset($GLOBALS[__FUNCTION__])) {
2047                 // Determine it
2048                 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2049         } // END - if
2050
2051         // Return cache
2052         return $GLOBALS[__FUNCTION__];
2053 }
2054
2055 // "Getter" for max_send
2056 function getMaxSend () {
2057         // Do we have cache?
2058         if (!isset($GLOBALS[__FUNCTION__])) {
2059                 // Determine it
2060                 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2061         } // END - if
2062
2063         // Return cache
2064         return $GLOBALS[__FUNCTION__];
2065 }
2066
2067 // "Getter" for mails_page
2068 function getMailsPage () {
2069         // Do we have cache?
2070         if (!isset($GLOBALS[__FUNCTION__])) {
2071                 // Determine it
2072                 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2073         } // END - if
2074
2075         // Return cache
2076         return $GLOBALS[__FUNCTION__];
2077 }
2078
2079 // "Getter" for __DB_NAME
2080 function getDbName () {
2081         // Do we have cache?
2082         if (!isset($GLOBALS[__FUNCTION__])) {
2083                 // Determine it
2084                 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2085         } // END - if
2086
2087         // Return cache
2088         return $GLOBALS[__FUNCTION__];
2089 }
2090
2091 // Checks wether proxy configuration is used
2092 function isProxyUsed () {
2093         // Do we have cache?
2094         if (!isset($GLOBALS[__FUNCTION__])) {
2095                 // Determine it
2096                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2097         } // END - if
2098
2099         // Return cache
2100         return $GLOBALS[__FUNCTION__];
2101 }
2102
2103 // Checks wether POST data contains selections
2104 function ifPostContainsSelections ($element = 'sel') {
2105         // Do we have cache?
2106         if (!isset($GLOBALS[__FUNCTION__][$element])) {
2107                 // Determine it
2108                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
2109         } // END - if
2110
2111         // Return cache
2112         return $GLOBALS[__FUNCTION__][$element];
2113 }
2114
2115 // Checks wether verbose_sql is Y and returns true/false if so
2116 function isVerboseSqlEnabled () {
2117         // Do we have cache?
2118         if (!isset($GLOBALS[__FUNCTION__])) {
2119                 // Determine it
2120                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2121         } // END - if
2122
2123         // Return cache
2124         return $GLOBALS[__FUNCTION__];
2125 }
2126
2127 // "Getter" for total user points
2128 function getTotalPoints ($userid) {
2129         // Do we have cache?
2130         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2131                 // Determine it
2132                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points');
2133         } // END - if
2134
2135         // Return cache
2136         return $GLOBALS[__FUNCTION__][$userid];
2137 }
2138
2139 // Wrapper to check if url_blacklist is enabled
2140 function isUrlBlacklistEnabled () {
2141         // Do we have cache?
2142         if (!isset($GLOBALS[__FUNCTION__])) {
2143                 // Determine it
2144                 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2145         } // END - if
2146
2147         // Return cache
2148         return $GLOBALS[__FUNCTION__];
2149 }
2150
2151 // Checks wether direct payment is allowed in configuration
2152 function isDirectPaymentEnabled () {
2153         // Do we have cache?
2154         if (!isset($GLOBALS[__FUNCTION__])) {
2155                 // Determine it
2156                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2157         } // END - if
2158
2159         // Return cache
2160         return $GLOBALS[__FUNCTION__];
2161 }
2162
2163 // Wrapper to check if current task is for extension (not update)
2164 function isExtensionTask ($content) {
2165         // Do we have cache?
2166         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2167                 // Determine it
2168                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2169         } // END - if
2170
2171         // Return cache
2172         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2173 }
2174
2175 // Wrapper to check if output mode is CSS
2176 function isCssOutputMode () {
2177         // Determine it
2178         return (getScriptOutputMode() == 1);
2179 }
2180
2181 // Wrapper to check if output mode is HTML
2182 function isHtmlOutputMode () {
2183         // Determine it
2184         return (getScriptOutputMode() == 0);
2185 }
2186
2187 // Wrapper to check if output mode is RAW
2188 function isRawOutputMode () {
2189         // Determine it
2190         return (getScriptOutputMode() == -1);
2191 }
2192
2193 // Wrapper to generate a user email link
2194 function generateWrappedUserEmailLink ($email) {
2195         // Just call the inner function
2196         return generateEmailLink($email, 'user_data');
2197 }
2198
2199 // Wrapper to check if user points are locked
2200 function ifUserPointsLocked ($userid) {
2201         // Do we have cache?
2202         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2203                 // Determine it
2204                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2205         } // END - if
2206
2207         // Return cache
2208         return $GLOBALS[__FUNCTION__][$userid];
2209 }
2210
2211 // Appends a line to an existing file or creates it instantly with given content.
2212 // This function does always add a new-line character to every line.
2213 function appendLineToFile ($file, $line) {
2214         $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2215         fwrite($fp, $line . "\n");
2216         fclose($fp);
2217 }
2218
2219 // Wrapper for changeDataInFile() but with full path added
2220 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2221         // Add full path
2222         $FQFN = getPath() . $FQFN;
2223
2224         // Call inner function
2225         changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);
2226 }
2227
2228 // Shortens ucfirst(strtolower()) calls
2229 function firstCharUpperCase ($str) {
2230         return ucfirst(strtolower($str));
2231 }
2232
2233 // [EOF]
2234 ?>