One more found
[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 ($strict = true) {
544         // Default is null
545         $what = NULL;
546
547         // Is the value set?
548         if (isWhatSet($strict)) {
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'] = $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']) && (!empty($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'] = $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'] = 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 = ((isset($GLOBALS['__module'])) && (!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         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
681         $GLOBALS['output_mode']         = (int) $newOutputMode;
682         $GLOBALS['getScriptOutputMode'] = (int) $newOutputMode;
683 }
684
685 // Checks wether output_mode is set and optionally aborts on miss
686 function isOutputModeSet ($strict =  false) {
687         // Check for it
688         $isset = (isset($GLOBALS['output_mode']));
689
690         // Should we abort here?
691         if (($strict === true) && ($isset === false)) {
692                 // Output backtrace
693                 debug_report_bug(__FUNCTION__, __LINE__, 'Output mode is not set.');
694         } // END - if
695
696         // Return it
697         return $isset;
698 }
699
700 // Enables block-mode
701 function enableBlockMode ($enabled = true) {
702         $GLOBALS['block_mode'] = $enabled;
703 }
704
705 // Checks wether block-mode is enabled
706 function isBlockModeEnabled () {
707         // Abort if not set
708         if (!isset($GLOBALS['block_mode'])) {
709                 // Needs to be fixed
710                 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
711         } // END - if
712
713         // Return it
714         return $GLOBALS['block_mode'];
715 }
716
717 /**
718  * Wrapper function for addPointsThroughReferralSystem(), you should generally
719  * avoid this function and use addPointsThroughReferralSystem() directly and add
720  * your special payment method entry to points_data instead.
721  *
722  * @param       $subject        A string-encoded subject for this add
723  * @param       $userid         The recipient (member) for given points
724  * @param       $points         Points to be added to member's account
725  * @return      $added          Wether the points has been added to the user's account
726  */
727 function addPointsDirectly ($subject, $userid, $points) {
728         // Reset level here
729         initReferralSystem();
730
731         // Call more complicated method (due to more parameters)
732         return addPointsThroughReferralSystem($subject, $userid, $points, false, 0, 'DIRECT');
733 }
734
735 // Wrapper for redirectToUrl but URL comes from a configuration entry
736 function redirectToConfiguredUrl ($configEntry) {
737         // Load the URL
738         redirectToUrl(getConfig($configEntry));
739 }
740
741 // Wrapper function to redirect from member-only modules to index
742 function redirectToIndexMemberOnlyModule () {
743         // Do the redirect here
744         redirectToUrl('modules.php?module=index&amp;code=' . getCode('MODULE_MEMBER_ONLY') . '&amp;mod=' . getModule());
745 }
746
747 // Wrapper function to redirect to current URL
748 function redirectToRequestUri () {
749         redirectToUrl(basename(detectRequestUri()));
750 }
751
752 // Wrapper function to redirect to de-refered URL
753 function redirectToDereferedUrl ($url) {
754         // Redirect to to
755         redirectToUrl(generateDerefererUrl($url));
756 }
757
758 // Wrapper function for checking if extension is installed and newer or same version
759 function isExtensionInstalledAndNewer ($ext_name, $version) {
760         // Is an cache entry found?
761         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
762                 // Determine it
763                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
764         } else {
765                 // Cache hits should be incremented twice
766                 incrementStatsEntry('cache_hits', 2);
767         }
768
769         // Return it
770         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=&gt;' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
771         return $GLOBALS[__FUNCTION__][$ext_name][$version];
772 }
773
774 // Wrapper function for checking if extension is installed and older than given version
775 function isExtensionInstalledAndOlder ($ext_name, $version) {
776         // Is an cache entry found?
777         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
778                 // Determine it
779                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
780         } else {
781                 // Cache hits should be incremented twice
782                 incrementStatsEntry('cache_hits', 2);
783         }
784
785         // Return it
786         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '&lt;' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
787         return $GLOBALS[__FUNCTION__][$ext_name][$version];
788 }
789
790 // Set username
791 function setUsername ($userName) {
792         $GLOBALS['username'] = (string) $userName;
793 }
794
795 // Get username
796 function getUsername () {
797         // User name set?
798         if (!isset($GLOBALS['username'])) {
799                 // No, so it has to be a guest
800                 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
801         } // END - if
802
803         // Return it
804         return $GLOBALS['username'];
805 }
806
807 // Wrapper function for installation phase
808 function isInstallationPhase () {
809         // Do we have cache?
810         if (!isset($GLOBALS[__FUNCTION__])) {
811                 // Determine it
812                 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
813         } // END - if
814
815         // Return result
816         return $GLOBALS[__FUNCTION__];
817 }
818
819 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
820 function isDemoModeActive () {
821         // Is cache set?
822         if (!isset($GLOBALS[__FUNCTION__])) {
823                 // Simply check it
824                 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
825         } // END - if
826
827         // Return it
828         return $GLOBALS[__FUNCTION__];
829 }
830
831 // Getter for PHP caching value
832 function getPhpCaching () {
833         return $GLOBALS['php_caching'];
834 }
835
836 // Checks wether the admin hash is set
837 function isAdminHashSet ($adminId) {
838         // Is the array there?
839         if (!isset($GLOBALS['cache_array']['admin'])) {
840                 // Missing array should be reported
841                 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
842         } // END - if
843
844         // Check for admin hash
845         return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
846 }
847
848 // Setter for admin hash
849 function setAdminHash ($adminId, $hash) {
850         $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
851 }
852
853 // Getter for current admin login
854 function getCurrentAdminLogin () {
855         // Log debug message
856         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
857
858         // Do we have cache?
859         if (!isset($GLOBALS[__FUNCTION__])) {
860                 // Determine it
861                 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
862         } // END - if
863
864         // Return it
865         return $GLOBALS[__FUNCTION__];
866 }
867
868 // Setter for admin id (and current)
869 function setAdminId ($adminId) {
870         // Log debug message
871         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
872
873         // Set session
874         $status = setSession('admin_id', bigintval($adminId));
875
876         // Set current id
877         setCurrentAdminId($adminId);
878
879         // Return status
880         return $status;
881 }
882
883 // Setter for admin_last
884 function setAdminLast ($adminLast) {
885         // Log debug message
886         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
887
888         // Set session
889         $status = setSession('admin_last', $adminLast);
890
891         // Return status
892         return $status;
893 }
894
895 // Setter for admin_md5
896 function setAdminMd5 ($adminMd5) {
897         // Log debug message
898         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
899
900         // Set session
901         $status = setSession('admin_md5', $adminMd5);
902
903         // Return status
904         return $status;
905 }
906
907 // Getter for admin_md5
908 function getAdminMd5 () {
909         // Log debug message
910         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
911
912         // Get session
913         return getSession('admin_md5');
914 }
915
916 // Init user data array
917 function initUserData () {
918         // User id should not be zero
919         if (!isValidUserId(getCurrentUserId())) {
920                 // Should be always valid
921                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
922         } // END - if
923
924         // Init the user
925         unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
926         $GLOBALS['user_data'][getCurrentUserId()] = array();
927 }
928
929 // Getter for user data
930 function getUserData ($column) {
931         // User id should not be zero
932         if (!isValidUserId(getCurrentUserId())) {
933                 // Should be always valid
934                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
935         } // END - if
936
937         // Default is empty
938         $data = NULL;
939
940         if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
941                 // Return the value
942                 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
943         } // END - if
944
945         // Return it
946         return $data;
947 }
948
949 // Checks wether given user data is set to 'Y'
950 function isUserDataEnabled ($column) {
951         // Do we have cache?
952         if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
953                 // Determine it
954                 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
955         } // END - if
956
957         // Return cache
958         return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
959 }
960
961 // Geter for whole user data array
962 function getUserDataArray () {
963         // Get user id
964         $userid = getCurrentUserId();
965
966         // Is the current userid valid?
967         if (!isValidUserId($userid)) {
968                 // Should be always valid
969                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
970         } // END - if
971
972         // Get the whole array if found
973         if (isset($GLOBALS['user_data'][$userid])) {
974                 // Found, so return it
975                 return $GLOBALS['user_data'][$userid];
976         } else {
977                 // Return empty array
978                 return array();
979         }
980 }
981
982 // Checks if the user data is valid, this may indicate that the user has logged
983 // in, but you should use isMember() if you want to find that out.
984 function isUserDataValid () {
985         // User id should not be zero so abort here
986         if (!isCurrentUserIdSet()) {
987                 return false;
988         } // END - if
989
990         // Is it cached?
991         if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
992                 // Determine it
993                 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
994         } // END - if
995
996         // Return the result
997         return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
998 }
999
1000 // Setter for current userid
1001 function setCurrentUserId ($userid) {
1002         // Set userid
1003         $GLOBALS['current_userid'] = bigintval($userid);
1004
1005         // Unset it to re-determine the actual state
1006         unset($GLOBALS['is_userdata_valid'][$userid]);
1007 }
1008
1009 // Getter for current userid
1010 function getCurrentUserId () {
1011         // Userid must be set before it can be used
1012         if (!isCurrentUserIdSet()) {
1013                 // Not set
1014                 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
1015         } // END - if
1016
1017         // Return the userid
1018         return $GLOBALS['current_userid'];
1019 }
1020
1021 // Checks if current userid is set
1022 function isCurrentUserIdSet () {
1023         return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1024 }
1025
1026 // Checks wether we are debugging template cache
1027 function isDebuggingTemplateCache () {
1028         // Do we have cache?
1029         if (!isset($GLOBALS[__FUNCTION__])) {
1030                 // Determine it
1031                 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1032         } // END - if
1033
1034         // Return cache
1035         return $GLOBALS[__FUNCTION__];
1036 }
1037
1038 // Wrapper for fetchUserData() and getUserData() calls
1039 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1040         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1041         // Is it cached?
1042         if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1043                 // Default is NULL
1044                 $data = NULL;
1045
1046                 // Can we fetch the user data?
1047                 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1048                         // Now get the data back
1049                         $data = getUserData($valueColumn);
1050                 } // END - if
1051
1052                 // Cache it
1053                 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1054         } // END - if
1055
1056         // Return it
1057         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1058         return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1059 }
1060
1061 // Wrapper for strpos() to ease porting from deprecated ereg() function
1062 function isInString ($needle, $haystack) {
1063         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1064         return (strpos($haystack, $needle) !== false);
1065 }
1066
1067 // Wrapper for strpos() to ease porting from deprecated eregi() function
1068 // This function is case-insensitive
1069 function isInStringIgnoreCase ($needle, $haystack) {
1070         return (isInString(strtolower($needle), strtolower($haystack)));
1071 }
1072
1073 // Wrapper to check for if fatal errors where detected
1074 function ifFatalErrorsDetected () {
1075         // Just call the inner function
1076         return (getTotalFatalErrors() > 0);
1077 }
1078
1079 // Setter for HTTP status
1080 function setHttpStatus ($status) {
1081         $GLOBALS['http_status'] = (string) $status;
1082 }
1083
1084 // Getter for HTTP status
1085 function getHttpStatus () {
1086         // Is the status set?
1087         if (!isset($GLOBALS['http_status'])) {
1088                 // Abort here
1089                 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1090         } // END - if
1091
1092         // Return it
1093         return $GLOBALS['http_status'];
1094 }
1095
1096 /**
1097  * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1098  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1099  *
1100  * ----------------------------------------------------------------------------
1101  * If you want to redirect, please use redirectToUrl(); instead
1102  * ----------------------------------------------------------------------------
1103  *
1104  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1105  *
1106  * @link    http://support.microsoft.com/kb/q176113/
1107  * @author  Andreas Gohr <andi@splitbrain.org>
1108  * @access  private
1109  */
1110 function sendRawRedirect ($url) {
1111         // Clear output buffer
1112         clearOutputBuffer();
1113
1114         // Clear own output buffer
1115         $GLOBALS['output'] = '';
1116
1117         // To make redirects working (no content type), output mode must be raw
1118         setOutputMode(-1);
1119
1120         // Send helping header
1121         setHttpStatus('302 Found');
1122
1123         // always close the session
1124         session_write_close();
1125
1126         // Revert entity &amp;
1127         $url = str_replace('&amp;', '&', $url);
1128
1129         // check if running on IIS < 6 with CGI-PHP
1130         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1131                 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1132                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1133                 ($matches[1] < 6)) {
1134                 // Send the IIS header
1135                 addHttpHeader('Refresh: 0;url=' . $url);
1136         } else {
1137                 // Send generic header
1138                 addHttpHeader('Location: ' . $url);
1139         }
1140
1141         // Shutdown here
1142         shutdown();
1143 }
1144
1145 // Determines the country of the given user id
1146 function determineCountry ($userid) {
1147         // Do we have cache?
1148         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1149                 // Default is 'invalid'
1150                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1151
1152                 // Is extension country active?
1153                 if (isExtensionActive('country')) {
1154                         // Determine the right country code through the country id
1155                         $id = getUserData('country_code');
1156
1157                         // Then handle it over
1158                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1159                 } else {
1160                         // Get raw code from user data
1161                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1162                 }
1163         } // END - if
1164
1165         // Return cache
1166         return $GLOBALS[__FUNCTION__][$userid];
1167 }
1168
1169 // "Getter" for total confirmed user accounts
1170 function getTotalConfirmedUser () {
1171         // Is it cached?
1172         if (!isset($GLOBALS[__FUNCTION__])) {
1173                 // Then do it
1174                 if (isExtensionActive('user')) {
1175                         $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1176                 } else {
1177                         $GLOBALS[__FUNCTION__] = 0;
1178                 }
1179         } // END - if
1180
1181         // Return cached value
1182         return $GLOBALS[__FUNCTION__];
1183 }
1184
1185 // "Getter" for total unconfirmed user accounts
1186 function getTotalUnconfirmedUser () {
1187         // Is it cached?
1188         if (!isset($GLOBALS[__FUNCTION__])) {
1189                 // Then do it
1190                 if (isExtensionActive('user')) {
1191                         $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1192                 } else {
1193                         $GLOBALS[__FUNCTION__] = 0;
1194                 }
1195         } // END - if
1196
1197         // Return cached value
1198         return $GLOBALS[__FUNCTION__];
1199 }
1200
1201 // "Getter" for total locked user accounts
1202 function getTotalLockedUser () {
1203         // Is it cached?
1204         if (!isset($GLOBALS[__FUNCTION__])) {
1205                 // Then do it
1206                 if (isExtensionActive('user')) {
1207                         $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1208                 } else {
1209                         $GLOBALS[__FUNCTION__] = 0;
1210                 }
1211         } // END - if
1212
1213         // Return cached value
1214         return $GLOBALS[__FUNCTION__];
1215 }
1216
1217 // "Getter" for total locked user accounts
1218 function getTotalRandomRefidUser () {
1219         // Is it cached?
1220         if (!isset($GLOBALS[__FUNCTION__])) {
1221                 // Then do it
1222                 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1223                         $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, '', '>=');
1224                 } else {
1225                         $GLOBALS[__FUNCTION__] = 0;
1226                 }
1227         } // END - if
1228
1229         // Return cached value
1230         return $GLOBALS[__FUNCTION__];
1231 }
1232
1233 // Is given userid valid?
1234 function isValidUserId ($userid) {
1235         // Do we have cache?
1236         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1237                 // Check it out
1238                 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1239         } // END - if
1240
1241         // Return cache
1242         return $GLOBALS[__FUNCTION__][$userid];
1243 }
1244
1245 // Encodes entities
1246 function encodeEntities ($str) {
1247         // Secure it first
1248         $str = secureString($str, true, true);
1249
1250         // Encode dollar sign as well
1251         $str = str_replace('$', '&#36;', $str);
1252
1253         // Return it
1254         return $str;
1255 }
1256
1257 // "Getter" for date from patch_ctime
1258 function getDateFromRepository () {
1259         // Is it cached?
1260         if (!isset($GLOBALS[__FUNCTION__])) {
1261                 // Then set it
1262                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1263         } // END - if
1264
1265         // Return cache
1266         return $GLOBALS[__FUNCTION__];
1267 }
1268
1269 // "Getter" for date/time from patch_ctime
1270 function getDateTimeFromRepository () {
1271         // Is it cached?
1272         if (!isset($GLOBALS[__FUNCTION__])) {
1273                 // Then set it
1274                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1275         } // END - if
1276
1277         // Return cache
1278         return $GLOBALS[__FUNCTION__];
1279 }
1280
1281 // Getter for current year (default)
1282 function getYear ($timestamp = NULL) {
1283         // Is it cached?
1284         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1285                 // null is time()
1286                 if (is_null($timestamp)) {
1287                         $timestamp = time();
1288                 } // END - if
1289
1290                 // Then create it
1291                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1292         } // END - if
1293
1294         // Return cache
1295         return $GLOBALS[__FUNCTION__][$timestamp];
1296 }
1297
1298 // Getter for current month (default)
1299 function getMonth ($timestamp = NULL) {
1300         // Is it cached?
1301         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1302                 // If null is set, use time()
1303                 if (is_null($timestamp)) {
1304                         // Use time() which is current timestamp
1305                         $timestamp = time();
1306                 } // END - if
1307
1308                 // Then create it
1309                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1310         } // END - if
1311
1312         // Return cache
1313         return $GLOBALS[__FUNCTION__][$timestamp];
1314 }
1315
1316 // Getter for current hour (default)
1317 function getHour ($timestamp = NULL) {
1318         // Is it cached?
1319         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1320                 // null is time()
1321                 if (is_null($timestamp)) {
1322                         $timestamp = time();
1323                 } // END - if
1324
1325                 // Then create it
1326                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1327         } // END - if
1328
1329         // Return cache
1330         return $GLOBALS[__FUNCTION__][$timestamp];
1331 }
1332
1333 // Getter for current day (default)
1334 function getDay ($timestamp = NULL) {
1335         // Is it cached?
1336         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1337                 // null is time()
1338                 if (is_null($timestamp)) {
1339                         $timestamp = time();
1340                 } // END - if
1341
1342                 // Then create it
1343                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1344         } // END - if
1345
1346         // Return cache
1347         return $GLOBALS[__FUNCTION__][$timestamp];
1348 }
1349
1350 // Getter for current week (default)
1351 function getWeek ($timestamp = NULL) {
1352         // Is it cached?
1353         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1354                 // null is time()
1355                 if (is_null($timestamp)) $timestamp = time();
1356
1357                 // Then create it
1358                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1359         } // END - if
1360
1361         // Return cache
1362         return $GLOBALS[__FUNCTION__][$timestamp];
1363 }
1364
1365 // Getter for current short_hour (default)
1366 function getShortHour ($timestamp = NULL) {
1367         // Is it cached?
1368         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1369                 // null is time()
1370                 if (is_null($timestamp)) $timestamp = time();
1371
1372                 // Then create it
1373                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1374         } // END - if
1375
1376         // Return cache
1377         return $GLOBALS[__FUNCTION__][$timestamp];
1378 }
1379
1380 // Getter for current long_hour (default)
1381 function getLongHour ($timestamp = NULL) {
1382         // Is it cached?
1383         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1384                 // null is time()
1385                 if (is_null($timestamp)) $timestamp = time();
1386
1387                 // Then create it
1388                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1389         } // END - if
1390
1391         // Return cache
1392         return $GLOBALS[__FUNCTION__][$timestamp];
1393 }
1394
1395 // Getter for current second (default)
1396 function getSecond ($timestamp = NULL) {
1397         // Is it cached?
1398         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1399                 // null is time()
1400                 if (is_null($timestamp)) $timestamp = time();
1401
1402                 // Then create it
1403                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1404         } // END - if
1405
1406         // Return cache
1407         return $GLOBALS[__FUNCTION__][$timestamp];
1408 }
1409
1410 // Getter for current minute (default)
1411 function getMinute ($timestamp = NULL) {
1412         // Is it cached?
1413         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1414                 // null is time()
1415                 if (is_null($timestamp)) $timestamp = time();
1416
1417                 // Then create it
1418                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1419         } // END - if
1420
1421         // Return cache
1422         return $GLOBALS[__FUNCTION__][$timestamp];
1423 }
1424
1425 // Checks wether the title decoration is enabled
1426 function isTitleDecorationEnabled () {
1427         // Do we have cache?
1428         if (!isset($GLOBALS[__FUNCTION__])) {
1429                 // Just check it
1430                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1431         } // END - if
1432
1433         // Return cache
1434         return $GLOBALS[__FUNCTION__];
1435 }
1436
1437 // Checks wether filter usage updates are enabled (expensive queries!)
1438 function isFilterUsageUpdateEnabled () {
1439         // Do we have cache?
1440         if (!isset($GLOBALS[__FUNCTION__])) {
1441                 // Determine it
1442                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1443         } // END - if
1444
1445         // Return cache
1446         return $GLOBALS[__FUNCTION__];
1447 }
1448
1449 // Checks wether debugging of weekly resets is enabled
1450 function isWeeklyResetDebugEnabled () {
1451         // Do we have cache?
1452         if (!isset($GLOBALS[__FUNCTION__])) {
1453                 // Determine it
1454                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1455         } // END - if
1456
1457         // Return cache
1458         return $GLOBALS[__FUNCTION__];
1459 }
1460
1461 // Checks wether debugging of monthly resets is enabled
1462 function isMonthlyResetDebugEnabled () {
1463         // Do we have cache?
1464         if (!isset($GLOBALS[__FUNCTION__])) {
1465                 // Determine it
1466                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1467         } // END - if
1468
1469         // Return cache
1470         return $GLOBALS[__FUNCTION__];
1471 }
1472
1473 // Checks wether displaying of debug SQLs are enabled
1474 function isDisplayDebugSqlEnabled () {
1475         // Do we have cache?
1476         if (!isset($GLOBALS[__FUNCTION__])) {
1477                 // Determine it
1478                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1479         } // END - if
1480
1481         // Return cache
1482         return $GLOBALS[__FUNCTION__];
1483 }
1484
1485 // Checks wether module title is enabled
1486 function isModuleTitleEnabled () {
1487         // Do we have cache?
1488         if (!isset($GLOBALS[__FUNCTION__])) {
1489                 // Determine it
1490                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1491         } // END - if
1492
1493         // Return cache
1494         return $GLOBALS[__FUNCTION__];
1495 }
1496
1497 // Checks wether what title is enabled
1498 function isWhatTitleEnabled () {
1499         // Do we have cache?
1500         if (!isset($GLOBALS[__FUNCTION__])) {
1501                 // Determine it
1502                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1503         } // END - if
1504
1505         // Return cache
1506         return $GLOBALS[__FUNCTION__];
1507 }
1508
1509 // Checks wether stats are enabled
1510 function ifInternalStatsEnabled () {
1511         // Do we have cache?
1512         if (!isset($GLOBALS[__FUNCTION__])) {
1513                 // Then determine it
1514                 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1515         } // END - if
1516
1517         // Return cached value
1518         return $GLOBALS[__FUNCTION__];
1519 }
1520
1521 // Checks wether admin-notification of certain user actions is enabled
1522 function isAdminNotificationEnabled () {
1523         // Do we have cache?
1524         if (!isset($GLOBALS[__FUNCTION__])) {
1525                 // Determine it
1526                 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1527         } // END - if
1528
1529         // Return cache
1530         return $GLOBALS[__FUNCTION__];
1531 }
1532
1533 // Checks wether random referral id selection is enabled
1534 function isRandomReferralIdEnabled () {
1535         // Do we have cache?
1536         if (!isset($GLOBALS[__FUNCTION__])) {
1537                 // Determine it
1538                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1539         } // END - if
1540
1541         // Return cache
1542         return $GLOBALS[__FUNCTION__];
1543 }
1544
1545 // "Getter" for default language
1546 function getDefaultLanguage () {
1547         // Do we have cache?
1548         if (!isset($GLOBALS[__FUNCTION__])) {
1549                 // Determine it
1550                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1551         } // END - if
1552
1553         // Return cache
1554         return $GLOBALS[__FUNCTION__];
1555 }
1556
1557 // "Getter" for default referral id
1558 function getDefRefid () {
1559         // Do we have cache?
1560         if (!isset($GLOBALS[__FUNCTION__])) {
1561                 // Determine it
1562                 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1563         } // END - if
1564
1565         // Return cache
1566         return $GLOBALS[__FUNCTION__];
1567 }
1568
1569 // "Getter" for path
1570 function getPath () {
1571         // Do we have cache?
1572         if (!isset($GLOBALS[__FUNCTION__])) {
1573                 // Determine it
1574                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1575         } // END - if
1576
1577         // Return cache
1578         return $GLOBALS[__FUNCTION__];
1579 }
1580
1581 // "Getter" for url
1582 function getUrl () {
1583         // Do we have cache?
1584         if (!isset($GLOBALS[__FUNCTION__])) {
1585                 // Determine it
1586                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1587         } // END - if
1588
1589         // Return cache
1590         return $GLOBALS[__FUNCTION__];
1591 }
1592
1593 // "Getter" for cache_path
1594 function getCachePath () {
1595         // Do we have cache?
1596         if (!isset($GLOBALS[__FUNCTION__])) {
1597                 // Determine it
1598                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1599         } // END - if
1600
1601         // Return cache
1602         return $GLOBALS[__FUNCTION__];
1603 }
1604
1605 // "Getter" for secret_key
1606 function getSecretKey () {
1607         // Do we have cache?
1608         if (!isset($GLOBALS[__FUNCTION__])) {
1609                 // Determine it
1610                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1611         } // END - if
1612
1613         // Return cache
1614         return $GLOBALS[__FUNCTION__];
1615 }
1616
1617 // "Getter" for SITE_KEY
1618 function getSiteKey () {
1619         // Do we have cache?
1620         if (!isset($GLOBALS[__FUNCTION__])) {
1621                 // Determine it
1622                 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1623         } // END - if
1624
1625         // Return cache
1626         return $GLOBALS[__FUNCTION__];
1627 }
1628
1629 // "Getter" for DATE_KEY
1630 function getDateKey () {
1631         // Do we have cache?
1632         if (!isset($GLOBALS[__FUNCTION__])) {
1633                 // Determine it
1634                 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1635         } // END - if
1636
1637         // Return cache
1638         return $GLOBALS[__FUNCTION__];
1639 }
1640
1641 // "Getter" for master_salt
1642 function getMasterSalt () {
1643         // Do we have cache?
1644         if (!isset($GLOBALS[__FUNCTION__])) {
1645                 // Determine it
1646                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1647         } // END - if
1648
1649         // Return cache
1650         return $GLOBALS[__FUNCTION__];
1651 }
1652
1653 // "Getter" for prime
1654 function getPrime () {
1655         // Do we have cache?
1656         if (!isset($GLOBALS[__FUNCTION__])) {
1657                 // Determine it
1658                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1659         } // END - if
1660
1661         // Return cache
1662         return $GLOBALS[__FUNCTION__];
1663 }
1664
1665 // "Getter" for encrypt_separator
1666 function getEncryptSeparator () {
1667         // Do we have cache?
1668         if (!isset($GLOBALS[__FUNCTION__])) {
1669                 // Determine it
1670                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1671         } // END - if
1672
1673         // Return cache
1674         return $GLOBALS[__FUNCTION__];
1675 }
1676
1677 // "Getter" for mysql_prefix
1678 function getMysqlPrefix () {
1679         // Do we have cache?
1680         if (!isset($GLOBALS[__FUNCTION__])) {
1681                 // Determine it
1682                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1683         } // END - if
1684
1685         // Return cache
1686         return $GLOBALS[__FUNCTION__];
1687 }
1688
1689 // "Getter" for table_type
1690 function getTableType () {
1691         // Do we have cache?
1692         if (!isset($GLOBALS[__FUNCTION__])) {
1693                 // Determine it
1694                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1695         } // END - if
1696
1697         // Return cache
1698         return $GLOBALS[__FUNCTION__];
1699 }
1700
1701 // "Getter" for salt_length
1702 function getSaltLength () {
1703         // Do we have cache?
1704         if (!isset($GLOBALS[__FUNCTION__])) {
1705                 // Determine it
1706                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1707         } // END - if
1708
1709         // Return cache
1710         return $GLOBALS[__FUNCTION__];
1711 }
1712
1713 // "Getter" for output_mode
1714 function getOutputMode () {
1715         // Do we have cache?
1716         if (!isset($GLOBALS[__FUNCTION__])) {
1717                 // Determine it
1718                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1719         } // END - if
1720
1721         // Return cache
1722         return $GLOBALS[__FUNCTION__];
1723 }
1724
1725 // "Getter" for full_version
1726 function getFullVersion () {
1727         // Do we have cache?
1728         if (!isset($GLOBALS[__FUNCTION__])) {
1729                 // Determine it
1730                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1731         } // END - if
1732
1733         // Return cache
1734         return $GLOBALS[__FUNCTION__];
1735 }
1736
1737 // "Getter" for title
1738 function getTitle () {
1739         // Do we have cache?
1740         if (!isset($GLOBALS[__FUNCTION__])) {
1741                 // Determine it
1742                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1743         } // END - if
1744
1745         // Return cache
1746         return $GLOBALS[__FUNCTION__];
1747 }
1748
1749 // "Getter" for curr_svn_revision
1750 function getCurrentRepositoryRevision () {
1751         // Do we have cache?
1752         if (!isset($GLOBALS[__FUNCTION__])) {
1753                 // Determine it
1754                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1755         } // END - if
1756
1757         // Return cache
1758         return $GLOBALS[__FUNCTION__];
1759 }
1760
1761 // "Getter" for server_url
1762 function getServerUrl () {
1763         // Do we have cache?
1764         if (!isset($GLOBALS[__FUNCTION__])) {
1765                 // Determine it
1766                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1767         } // END - if
1768
1769         // Return cache
1770         return $GLOBALS[__FUNCTION__];
1771 }
1772
1773 // "Getter" for mt_word
1774 function getMtWord () {
1775         // Do we have cache?
1776         if (!isset($GLOBALS[__FUNCTION__])) {
1777                 // Determine it
1778                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1779         } // END - if
1780
1781         // Return cache
1782         return $GLOBALS[__FUNCTION__];
1783 }
1784
1785 // "Getter" for mt_word2
1786 function getMtWord2 () {
1787         // Do we have cache?
1788         if (!isset($GLOBALS[__FUNCTION__])) {
1789                 // Determine it
1790                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1791         } // END - if
1792
1793         // Return cache
1794         return $GLOBALS[__FUNCTION__];
1795 }
1796
1797 // "Getter" for main_title
1798 function getMainTitle () {
1799         // Do we have cache?
1800         if (!isset($GLOBALS[__FUNCTION__])) {
1801                 // Determine it
1802                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1803         } // END - if
1804
1805         // Return cache
1806         return $GLOBALS[__FUNCTION__];
1807 }
1808
1809 // "Getter" for file_hash
1810 function getFileHash () {
1811         // Do we have cache?
1812         if (!isset($GLOBALS[__FUNCTION__])) {
1813                 // Determine it
1814                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1815         } // END - if
1816
1817         // Return cache
1818         return $GLOBALS[__FUNCTION__];
1819 }
1820
1821 // "Getter" for pass_scramble
1822 function getPassScramble () {
1823         // Do we have cache?
1824         if (!isset($GLOBALS[__FUNCTION__])) {
1825                 // Determine it
1826                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1827         } // END - if
1828
1829         // Return cache
1830         return $GLOBALS[__FUNCTION__];
1831 }
1832
1833 // "Getter" for ap_inactive_since
1834 function getApInactiveSince () {
1835         // Do we have cache?
1836         if (!isset($GLOBALS[__FUNCTION__])) {
1837                 // Determine it
1838                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1839         } // END - if
1840
1841         // Return cache
1842         return $GLOBALS[__FUNCTION__];
1843 }
1844
1845 // "Getter" for user_min_confirmed
1846 function getUserMinConfirmed () {
1847         // Do we have cache?
1848         if (!isset($GLOBALS[__FUNCTION__])) {
1849                 // Determine it
1850                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1851         } // END - if
1852
1853         // Return cache
1854         return $GLOBALS[__FUNCTION__];
1855 }
1856
1857 // "Getter" for auto_purge
1858 function getAutoPurge () {
1859         // Do we have cache?
1860         if (!isset($GLOBALS[__FUNCTION__])) {
1861                 // Determine it
1862                 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1863         } // END - if
1864
1865         // Return cache
1866         return $GLOBALS[__FUNCTION__];
1867 }
1868
1869 // "Getter" for bonus_userid
1870 function getBonusUserid () {
1871         // Do we have cache?
1872         if (!isset($GLOBALS[__FUNCTION__])) {
1873                 // Determine it
1874                 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1875         } // END - if
1876
1877         // Return cache
1878         return $GLOBALS[__FUNCTION__];
1879 }
1880
1881 // "Getter" for ap_inactive_time
1882 function getApInactiveTime () {
1883         // Do we have cache?
1884         if (!isset($GLOBALS[__FUNCTION__])) {
1885                 // Determine it
1886                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1887         } // END - if
1888
1889         // Return cache
1890         return $GLOBALS[__FUNCTION__];
1891 }
1892
1893 // "Getter" for ap_dm_timeout
1894 function getApDmTimeout () {
1895         // Do we have cache?
1896         if (!isset($GLOBALS[__FUNCTION__])) {
1897                 // Determine it
1898                 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1899         } // END - if
1900
1901         // Return cache
1902         return $GLOBALS[__FUNCTION__];
1903 }
1904
1905 // "Getter" for ap_tasks_time
1906 function getApTasksTime () {
1907         // Do we have cache?
1908         if (!isset($GLOBALS[__FUNCTION__])) {
1909                 // Determine it
1910                 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1911         } // END - if
1912
1913         // Return cache
1914         return $GLOBALS[__FUNCTION__];
1915 }
1916
1917 // "Getter" for ap_unconfirmed_time
1918 function getApUnconfirmedTime () {
1919         // Do we have cache?
1920         if (!isset($GLOBALS[__FUNCTION__])) {
1921                 // Determine it
1922                 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1923         } // END - if
1924
1925         // Return cache
1926         return $GLOBALS[__FUNCTION__];
1927 }
1928
1929 // "Getter" for points
1930 function getPoints () {
1931         // Do we have cache?
1932         if (!isset($GLOBALS[__FUNCTION__])) {
1933                 // Determine it
1934                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1935         } // END - if
1936
1937         // Return cache
1938         return $GLOBALS[__FUNCTION__];
1939 }
1940
1941 // "Getter" for slogan
1942 function getSlogan () {
1943         // Do we have cache?
1944         if (!isset($GLOBALS[__FUNCTION__])) {
1945                 // Determine it
1946                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1947         } // END - if
1948
1949         // Return cache
1950         return $GLOBALS[__FUNCTION__];
1951 }
1952
1953 // "Getter" for copy
1954 function getCopy () {
1955         // Do we have cache?
1956         if (!isset($GLOBALS[__FUNCTION__])) {
1957                 // Determine it
1958                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1959         } // END - if
1960
1961         // Return cache
1962         return $GLOBALS[__FUNCTION__];
1963 }
1964
1965 // "Getter" for webmaster
1966 function getWebmaster () {
1967         // Do we have cache?
1968         if (!isset($GLOBALS[__FUNCTION__])) {
1969                 // Determine it
1970                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1971         } // END - if
1972
1973         // Return cache
1974         return $GLOBALS[__FUNCTION__];
1975 }
1976
1977 // "Getter" for sql_count
1978 function getSqlCount () {
1979         // Do we have cache?
1980         if (!isset($GLOBALS[__FUNCTION__])) {
1981                 // Determine it
1982                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1983         } // END - if
1984
1985         // Return cache
1986         return $GLOBALS[__FUNCTION__];
1987 }
1988
1989 // "Getter" for num_templates
1990 function getNumTemplates () {
1991         // Do we have cache?
1992         if (!isset($GLOBALS[__FUNCTION__])) {
1993                 // Determine it
1994                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1995         } // END - if
1996
1997         // Return cache
1998         return $GLOBALS[__FUNCTION__];
1999 }
2000
2001 // "Getter" for dns_cache_timeout
2002 function getDnsCacheTimeout () {
2003         // Do we have cache?
2004         if (!isset($GLOBALS[__FUNCTION__])) {
2005                 // Determine it
2006                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2007         } // END - if
2008
2009         // Return cache
2010         return $GLOBALS[__FUNCTION__];
2011 }
2012
2013 // "Getter" for menu_blur_spacer
2014 function getMenuBlurSpacer () {
2015         // Do we have cache?
2016         if (!isset($GLOBALS[__FUNCTION__])) {
2017                 // Determine it
2018                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2019         } // END - if
2020
2021         // Return cache
2022         return $GLOBALS[__FUNCTION__];
2023 }
2024
2025 // "Getter" for points_register
2026 function getPointsRegister () {
2027         // Do we have cache?
2028         if (!isset($GLOBALS[__FUNCTION__])) {
2029                 // Determine it
2030                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2031         } // END - if
2032
2033         // Return cache
2034         return $GLOBALS[__FUNCTION__];
2035 }
2036
2037 // "Getter" for points_ref
2038 function getPointsRef () {
2039         // Do we have cache?
2040         if (!isset($GLOBALS[__FUNCTION__])) {
2041                 // Determine it
2042                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2043         } // END - if
2044
2045         // Return cache
2046         return $GLOBALS[__FUNCTION__];
2047 }
2048
2049 // "Getter" for ref_payout
2050 function getRefPayout () {
2051         // Do we have cache?
2052         if (!isset($GLOBALS[__FUNCTION__])) {
2053                 // Determine it
2054                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2055         } // END - if
2056
2057         // Return cache
2058         return $GLOBALS[__FUNCTION__];
2059 }
2060
2061 // "Getter" for online_timeout
2062 function getOnlineTimeout () {
2063         // Do we have cache?
2064         if (!isset($GLOBALS[__FUNCTION__])) {
2065                 // Determine it
2066                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2067         } // END - if
2068
2069         // Return cache
2070         return $GLOBALS[__FUNCTION__];
2071 }
2072
2073 // "Getter" for index_home
2074 function getIndexHome () {
2075         // Do we have cache?
2076         if (!isset($GLOBALS[__FUNCTION__])) {
2077                 // Determine it
2078                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2079         } // END - if
2080
2081         // Return cache
2082         return $GLOBALS[__FUNCTION__];
2083 }
2084
2085 // "Getter" for one_day
2086 function getOneDay () {
2087         // Do we have cache?
2088         if (!isset($GLOBALS[__FUNCTION__])) {
2089                 // Determine it
2090                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2091         } // END - if
2092
2093         // Return cache
2094         return $GLOBALS[__FUNCTION__];
2095 }
2096
2097 // "Getter" for activate_xchange
2098 function getActivateXchange () {
2099         // Do we have cache?
2100         if (!isset($GLOBALS[__FUNCTION__])) {
2101                 // Determine it
2102                 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2103         } // END - if
2104
2105         // Return cache
2106         return $GLOBALS[__FUNCTION__];
2107 }
2108
2109 // "Getter" for img_type
2110 function getImgType () {
2111         // Do we have cache?
2112         if (!isset($GLOBALS[__FUNCTION__])) {
2113                 // Determine it
2114                 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2115         } // END - if
2116
2117         // Return cache
2118         return $GLOBALS[__FUNCTION__];
2119 }
2120
2121 // "Getter" for code_length
2122 function getCodeLength () {
2123         // Do we have cache?
2124         if (!isset($GLOBALS[__FUNCTION__])) {
2125                 // Determine it
2126                 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2127         } // END - if
2128
2129         // Return cache
2130         return $GLOBALS[__FUNCTION__];
2131 }
2132
2133 // "Getter" for least_cats
2134 function getLeastCats () {
2135         // Do we have cache?
2136         if (!isset($GLOBALS[__FUNCTION__])) {
2137                 // Determine it
2138                 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2139         } // END - if
2140
2141         // Return cache
2142         return $GLOBALS[__FUNCTION__];
2143 }
2144
2145 // "Getter" for pass_len
2146 function getPassLen () {
2147         // Do we have cache?
2148         if (!isset($GLOBALS[__FUNCTION__])) {
2149                 // Determine it
2150                 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2151         } // END - if
2152
2153         // Return cache
2154         return $GLOBALS[__FUNCTION__];
2155 }
2156
2157 // "Getter" for admin_menu
2158 function getAdminMenu () {
2159         // Do we have cache?
2160         if (!isset($GLOBALS[__FUNCTION__])) {
2161                 // Determine it
2162                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2163         } // END - if
2164
2165         // Return cache
2166         return $GLOBALS[__FUNCTION__];
2167 }
2168
2169 // "Getter" for last_month
2170 function getLastMonth () {
2171         // Do we have cache?
2172         if (!isset($GLOBALS[__FUNCTION__])) {
2173                 // Determine it
2174                 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2175         } // END - if
2176
2177         // Return cache
2178         return $GLOBALS[__FUNCTION__];
2179 }
2180
2181 // "Getter" for max_send
2182 function getMaxSend () {
2183         // Do we have cache?
2184         if (!isset($GLOBALS[__FUNCTION__])) {
2185                 // Determine it
2186                 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2187         } // END - if
2188
2189         // Return cache
2190         return $GLOBALS[__FUNCTION__];
2191 }
2192
2193 // "Getter" for mails_page
2194 function getMailsPage () {
2195         // Do we have cache?
2196         if (!isset($GLOBALS[__FUNCTION__])) {
2197                 // Determine it
2198                 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2199         } // END - if
2200
2201         // Return cache
2202         return $GLOBALS[__FUNCTION__];
2203 }
2204
2205 // "Getter" for rand_no
2206 function getRandNo () {
2207         // Do we have cache?
2208         if (!isset($GLOBALS[__FUNCTION__])) {
2209                 // Determine it
2210                 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2211         } // END - if
2212
2213         // Return cache
2214         return $GLOBALS[__FUNCTION__];
2215 }
2216
2217 // "Getter" for __DB_NAME
2218 function getDbName () {
2219         // Do we have cache?
2220         if (!isset($GLOBALS[__FUNCTION__])) {
2221                 // Determine it
2222                 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2223         } // END - if
2224
2225         // Return cache
2226         return $GLOBALS[__FUNCTION__];
2227 }
2228
2229 // "Getter" for DOMAIN
2230 function getDomain () {
2231         // Do we have cache?
2232         if (!isset($GLOBALS[__FUNCTION__])) {
2233                 // Determine it
2234                 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2235         } // END - if
2236
2237         // Return cache
2238         return $GLOBALS[__FUNCTION__];
2239 }
2240
2241 // "Getter" for proxy_username
2242 function getProxyUsername () {
2243         // Do we have cache?
2244         if (!isset($GLOBALS[__FUNCTION__])) {
2245                 // Determine it
2246                 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2247         } // END - if
2248
2249         // Return cache
2250         return $GLOBALS[__FUNCTION__];
2251 }
2252
2253 // "Getter" for proxy_password
2254 function getProxyPassword () {
2255         // Do we have cache?
2256         if (!isset($GLOBALS[__FUNCTION__])) {
2257                 // Determine it
2258                 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2259         } // END - if
2260
2261         // Return cache
2262         return $GLOBALS[__FUNCTION__];
2263 }
2264
2265 // "Getter" for proxy_host
2266 function getProxyHost () {
2267         // Do we have cache?
2268         if (!isset($GLOBALS[__FUNCTION__])) {
2269                 // Determine it
2270                 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2271         } // END - if
2272
2273         // Return cache
2274         return $GLOBALS[__FUNCTION__];
2275 }
2276
2277 // "Getter" for proxy_port
2278 function getProxyPort () {
2279         // Do we have cache?
2280         if (!isset($GLOBALS[__FUNCTION__])) {
2281                 // Determine it
2282                 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2283         } // END - if
2284
2285         // Return cache
2286         return $GLOBALS[__FUNCTION__];
2287 }
2288
2289 // "Getter" for SMTP_HOSTNAME
2290 function getSmtpHostname () {
2291         // Do we have cache?
2292         if (!isset($GLOBALS[__FUNCTION__])) {
2293                 // Determine it
2294                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2295         } // END - if
2296
2297         // Return cache
2298         return $GLOBALS[__FUNCTION__];
2299 }
2300
2301 // "Getter" for SMTP_USER
2302 function getSmtpUser () {
2303         // Do we have cache?
2304         if (!isset($GLOBALS[__FUNCTION__])) {
2305                 // Determine it
2306                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2307         } // END - if
2308
2309         // Return cache
2310         return $GLOBALS[__FUNCTION__];
2311 }
2312
2313 // "Getter" for SMTP_PASSWORD
2314 function getSmtpPassword () {
2315         // Do we have cache?
2316         if (!isset($GLOBALS[__FUNCTION__])) {
2317                 // Determine it
2318                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2319         } // END - if
2320
2321         // Return cache
2322         return $GLOBALS[__FUNCTION__];
2323 }
2324
2325 // "Getter" for points_word
2326 function getPointsWord () {
2327         // Do we have cache?
2328         if (!isset($GLOBALS[__FUNCTION__])) {
2329                 // Determine it
2330                 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2331         } // END - if
2332
2333         // Return cache
2334         return $GLOBALS[__FUNCTION__];
2335 }
2336
2337 // "Getter" for profile_lock
2338 function getProfileLock () {
2339         // Do we have cache?
2340         if (!isset($GLOBALS[__FUNCTION__])) {
2341                 // Determine it
2342                 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2343         } // END - if
2344
2345         // Return cache
2346         return $GLOBALS[__FUNCTION__];
2347 }
2348
2349 // "Getter" for url_tlock
2350 function getUrlTlock () {
2351         // Do we have cache?
2352         if (!isset($GLOBALS[__FUNCTION__])) {
2353                 // Determine it
2354                 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2355         } // END - if
2356
2357         // Return cache
2358         return $GLOBALS[__FUNCTION__];
2359 }
2360
2361 // "Getter" for title_left
2362 function getTitleLeft () {
2363         // Do we have cache?
2364         if (!isset($GLOBALS[__FUNCTION__])) {
2365                 // Determine it
2366                 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2367         } // END - if
2368
2369         // Return cache
2370         return $GLOBALS[__FUNCTION__];
2371 }
2372
2373 // "Getter" for title_right
2374 function getTitleRight () {
2375         // Do we have cache?
2376         if (!isset($GLOBALS[__FUNCTION__])) {
2377                 // Determine it
2378                 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2379         } // END - if
2380
2381         // Return cache
2382         return $GLOBALS[__FUNCTION__];
2383 }
2384
2385 // "Getter" for title_middle
2386 function getTitleMiddle () {
2387         // Do we have cache?
2388         if (!isset($GLOBALS[__FUNCTION__])) {
2389                 // Determine it
2390                 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2391         } // END - if
2392
2393         // Return cache
2394         return $GLOBALS[__FUNCTION__];
2395 }
2396
2397 // Getter for 'check_double_email'
2398 function getCheckDoubleEmail () {
2399         // Is the cache entry set?
2400         if (!isset($GLOBALS[__FUNCTION__])) {
2401                 // No, so determine it
2402                 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2403         } // END - if
2404
2405         // Return cached entry
2406         return $GLOBALS[__FUNCTION__];
2407 }
2408
2409 // Checks wether 'check_double_email' is 'Y'
2410 function isCheckDoubleEmailEnabled () {
2411         // Is the cache entry set?
2412         if (!isset($GLOBALS[__FUNCTION__])) {
2413                 // No, so determine it
2414                 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2415         } // END - if
2416
2417         // Return cached entry
2418         return $GLOBALS[__FUNCTION__];
2419 }
2420
2421 // Getter for 'display_home_in_index'
2422 function getDisplayHomeInIndex () {
2423         // Is the cache entry set?
2424         if (!isset($GLOBALS[__FUNCTION__])) {
2425                 // No, so determine it
2426                 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2427         } // END - if
2428
2429         // Return cached entry
2430         return $GLOBALS[__FUNCTION__];
2431 }
2432
2433 // Checks wether 'display_home_in_index' is 'Y'
2434 function isDisplayHomeInIndexEnabled () {
2435         // Is the cache entry set?
2436         if (!isset($GLOBALS[__FUNCTION__])) {
2437                 // No, so determine it
2438                 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2439         } // END - if
2440
2441         // Return cached entry
2442         return $GLOBALS[__FUNCTION__];
2443 }
2444
2445 // Getter for 'admin_menu_javascript'
2446 function getAdminMenuJavascript () {
2447         // Is the cache entry set?
2448         if (!isset($GLOBALS[__FUNCTION__])) {
2449                 // No, so determine it
2450                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2451         } // END - if
2452
2453         // Return cached entry
2454         return $GLOBALS[__FUNCTION__];
2455 }
2456
2457 // Checks wether proxy configuration is used
2458 function isProxyUsed () {
2459         // Do we have cache?
2460         if (!isset($GLOBALS[__FUNCTION__])) {
2461                 // Determine it
2462                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2463         } // END - if
2464
2465         // Return cache
2466         return $GLOBALS[__FUNCTION__];
2467 }
2468
2469 // Checks wether POST data contains selections
2470 function ifPostContainsSelections ($element = 'sel') {
2471         // Do we have cache?
2472         if (!isset($GLOBALS[__FUNCTION__][$element])) {
2473                 // Determine it
2474                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (countPostSelection($element) > 0));
2475         } // END - if
2476
2477         // Return cache
2478         return $GLOBALS[__FUNCTION__][$element];
2479 }
2480
2481 // Checks wether verbose_sql is Y and returns true/false if so
2482 function isVerboseSqlEnabled () {
2483         // Do we have cache?
2484         if (!isset($GLOBALS[__FUNCTION__])) {
2485                 // Determine it
2486                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2487         } // END - if
2488
2489         // Return cache
2490         return $GLOBALS[__FUNCTION__];
2491 }
2492
2493 // "Getter" for total user points
2494 function getTotalPoints ($userid) {
2495         // Do we have cache?
2496         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2497                 // Init array for filter chain
2498                 $data = array(
2499                         'userid' => $userid,
2500                         'points' => 0
2501                 );
2502
2503                 // Run filter chain for getting more point values
2504                 $data = runFilterChain('get_total_points', $data);
2505
2506                 // Determine it
2507                 $GLOBALS[__FUNCTION__][$userid] = $data['points']  - countSumTotalData($userid, 'user_data', 'used_points');
2508         } // END - if
2509
2510         // Return cache
2511         return $GLOBALS[__FUNCTION__][$userid];
2512 }
2513
2514 // Wrapper to check if url_blacklist is enabled
2515 function isUrlBlacklistEnabled () {
2516         // Do we have cache?
2517         if (!isset($GLOBALS[__FUNCTION__])) {
2518                 // Determine it
2519                 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2520         } // END - if
2521
2522         // Return cache
2523         return $GLOBALS[__FUNCTION__];
2524 }
2525
2526 // Checks wether direct payment is allowed in configuration
2527 function isDirectPaymentEnabled () {
2528         // Do we have cache?
2529         if (!isset($GLOBALS[__FUNCTION__])) {
2530                 // Determine it
2531                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2532         } // END - if
2533
2534         // Return cache
2535         return $GLOBALS[__FUNCTION__];
2536 }
2537
2538 // Checks wether JavaScript-based admin menu is enabled
2539 function isAdminMenuJavascriptEnabled () {
2540         // Do we have cache?
2541         if (!isset($GLOBALS[__FUNCTION__])) {
2542                 // Determine it
2543                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getConfig('admin_menu_javascript') == 'Y'));
2544         } // END - if
2545
2546         // Return cache
2547         return $GLOBALS[__FUNCTION__];
2548 }
2549
2550 // Wrapper to check if current task is for extension (not update)
2551 function isExtensionTask ($content) {
2552         // Do we have cache?
2553         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2554                 // Determine it
2555                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2556         } // END - if
2557
2558         // Return cache
2559         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2560 }
2561
2562 // Wrapper to check if output mode is CSS
2563 function isCssOutputMode () {
2564         // Determine it
2565         return (getScriptOutputMode() == 1);
2566 }
2567
2568 // Wrapper to check if output mode is HTML
2569 function isHtmlOutputMode () {
2570         // Determine it
2571         return (getScriptOutputMode() == 0);
2572 }
2573
2574 // Wrapper to check if output mode is RAW
2575 function isRawOutputMode () {
2576         // Determine it
2577         return (getScriptOutputMode() == -1);
2578 }
2579
2580 // Wrapper to check if output mode is AJAX
2581 function isAjaxOutputMode () {
2582         // Determine it
2583         return (getScriptOutputMode() == -2);
2584 }
2585
2586 // Wrapper to check if output mode is image
2587 function isImageOutputMode () {
2588         // Determine it
2589         return (getScriptOutputMode() == -3);
2590 }
2591
2592 // Wrapper to generate a user email link
2593 function generateWrappedUserEmailLink ($email) {
2594         // Just call the inner function
2595         return generateEmailLink($email, 'user_data');
2596 }
2597
2598 // Wrapper to check if user points are locked
2599 function ifUserPointsLocked ($userid) {
2600         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2601         // Do we have cache?
2602         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2603                 // Determine it
2604                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2605         } // END - if
2606
2607         // Return cache
2608         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2609         return $GLOBALS[__FUNCTION__][$userid];
2610 }
2611
2612 // Appends a line to an existing file or creates it instantly with given content.
2613 // This function does always add a new-line character to every line.
2614 function appendLineToFile ($file, $line) {
2615         $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2616         fwrite($fp, $line . "\n");
2617         fclose($fp);
2618 }
2619
2620 // Wrapper for changeDataInFile() but with full path added
2621 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2622         // Add full path
2623         $FQFN = getPath() . $FQFN;
2624
2625         // Call inner function
2626         return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2627 }
2628
2629 // Wrapper for changing entries in config-local.php
2630 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2631         // Call the inner function
2632         return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2633 }
2634
2635 // Shortens ucfirst(strtolower()) calls
2636 function firstCharUpperCase ($str) {
2637         return ucfirst(strtolower($str));
2638 }
2639
2640 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2641 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2642         // Get the configuration entry
2643         $configValue = getConfig($configEntry);
2644
2645         // Call inner method
2646         return createTimeSelections($configValue, $configEntry, $stamps, $align);
2647 }
2648
2649 // Shortens converting of German comma to Computer's version in POST data
2650 function convertCommaToDotInPostData ($postEntry) {
2651         // Read and convert given entry
2652         $postValue = convertCommaToDot(postRequestElement($postEntry));
2653
2654         // ... and set it again
2655         setPostRequestElement($postEntry, $postValue);
2656 }
2657
2658 // Converts German commas to Computer's version in all entries
2659 function convertCommaToDotInPostDataArray ($postEntries) {
2660         // Replace german decimal comma with computer decimal dot
2661         foreach ($postEntries as $entry) {
2662                 // Is the entry there?
2663                 if (isPostRequestElementSet($entry)) {
2664                         // Then convert it
2665                         convertCommaToDotInPostData($entry);
2666                 } // END - if
2667         } // END - foreach
2668 }
2669
2670 /**
2671  * Parses a string into a US formated float variable, taken from user comments
2672  * from PHP documentation website.
2673  *
2674  * @param       $floatString    A string holding a float expression
2675  * @return      $float                  Corresponding float variable
2676  * @author      chris<at>georgakopoulos<dot>com
2677  * @link        http://de.php.net/manual/en/function.floatval.php#92563
2678  */
2679 function parseFloat ($floatString){
2680         // Load locale info
2681         $LocaleInfo = localeconv();
2682
2683         // Remove thousand separators
2684         $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
2685
2686         // Convert decimal point
2687         $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2688
2689         // Return float value of converted string
2690         return floatval($floatString);
2691 }
2692
2693 // Generates a YES/NO option list from given default
2694 function generateYesNoOptionList ($defaultValue = '') {
2695         // Generate it
2696         return generateOptionList('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2697 }
2698
2699 // "Getter" for total available receivers
2700 function getTotalReceivers ($mode = 'normal') {
2701         // Get num rows
2702         $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode));
2703
2704         // Return value
2705         return $numRows;
2706 }
2707
2708 // Wrapper "getter" to get total unconfirmed mails for given userid
2709 function getTotalUnconfirmedMails ($userid) {
2710         // Do we have cache?
2711         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2712                 // Determine it
2713                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
2714         } // END - if
2715
2716         // Return cache
2717         return $GLOBALS[__FUNCTION__][$userid];
2718 }
2719
2720 // Checks wether 'mailer_theme' was found in session
2721 function isMailerThemeSet () {
2722         // Check session
2723         return isSessionVariableSet('mailer_theme');
2724 }
2725
2726 /**
2727  * Setter for theme in session (This setter does return the success of
2728  * setSession() which is required e.g. for destroySponsorSession().
2729  */
2730 function setMailerTheme ($newTheme) {
2731         // Set it in session
2732         return setSession('mailer_theme', $newTheme);
2733 }
2734
2735 /**
2736  * Getter for theme from session (This getter does return 'mailer_theme' from
2737  * session data or throws an error if not possible
2738  */
2739 function getMailerTheme () {
2740         // Is 'mailer_theme' set?
2741         if (!isMailerThemeSet()) {
2742                 // No, then abort here
2743                 debug_report_bug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2744         } // END - if
2745
2746         // Return the theme from session
2747         return getSession('mailer_theme');
2748 }
2749
2750 // [EOF]
2751 ?>