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