]> git.mxchange.org Git - mailer.git/blob - inc/wrapper-functions.php
Always reset cache and output-mode must be 'raw' to make redirects working
[mailer.git] / inc / wrapper-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/04/2009 *
4  * ===================                          Last change: 04/04/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : wrapper-functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Wrapper functions                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Wrapper-Funktionen                               *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Read a given file
44 function readFromFile ($FQFN) {
45         // Sanity-check if file is there (should be there, but just to make it sure)
46         if (!isFileReadable($FQFN)) {
47                 // This should not happen
48                 debug_report_bug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!');
49         } elseif (!isset($GLOBALS['file_content'][$FQFN])) {
50                 // Load the file
51                 if (function_exists('file_get_contents')) {
52                         // Use new function
53                         $GLOBALS['file_content'][$FQFN] = file_get_contents($FQFN);
54                 } else {
55                         // Fall-back to implode-file chain
56                         $GLOBALS['file_content'][$FQFN] = implode('', file($FQFN));
57                 }
58         } // END - if
59
60         // Return the content
61         return $GLOBALS['file_content'][$FQFN];
62 }
63
64 // Writes content to a file
65 function writeToFile ($FQFN, $content, $aquireLock = false) {
66         // Is the file writeable?
67         if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
68                 // Not writeable!
69                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN)));
70
71                 // Failed! :(
72                 return false;
73         } // END - if
74
75         // By default all is failed...
76         $GLOBALS['file_readable'][$FQFN] = false;
77         unset($GLOBALS['file_content'][$FQFN]);
78         $return = false;
79
80         // Is the function there?
81         if (function_exists('file_put_contents')) {
82                 // With lock?
83                 if ($aquireLock === true) {
84                         // Write it directly with lock
85                         $return = file_put_contents($FQFN, $content, LOCK_EX);
86                 } else {
87                         // Write it directly
88                         $return = file_put_contents($FQFN, $content);
89                 }
90         } else {
91                 // Write it with fopen
92                 $fp = fopen($FQFN, 'w') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
93
94                 // Do we need to aquire a lock?
95                 if ($aquireLock === true) {
96                         // Aquire lock
97                         flock($fp, LOCK_EX);
98                 } // END - if
99
100                 // Write content
101                 $return = fwrite($fp, $content);
102
103                 // Close stream
104                 fclose($fp);
105         }
106
107         // Was something written?
108         if ($return !== false) {
109                 // Mark it as readable
110                 $GLOBALS['file_readable'][$FQFN] = true;
111
112                 // Remember content in cache
113                 $GLOBALS['file_content'][$FQFN] = $content;
114         } // END - if
115
116         // Return status
117         return (($return !== false) && (changeMode($FQFN, 0644)));
118 }
119
120 // Clears the output buffer. This function does *NOT* backup sent content.
121 function clearOutputBuffer () {
122         // Trigger an error on failure
123         if ((ob_get_length() > 0) && (!ob_end_clean())) {
124                 // Failed!
125                 debug_report_bug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
126         } // END - if
127 }
128
129 // Encode strings
130 function encodeString ($str) {
131         $str = urlencode(base64_encode(compileUriCode($str)));
132         return $str;
133 }
134
135 // Decode strings encoded with encodeString()
136 function decodeString ($str) {
137         $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
138         return $str;
139 }
140
141 // Decode entities in a nicer way
142 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
143         // Decode the entities to UTF-8 now
144         $decodedString = html_entity_decode($str, $quote, 'UTF-8');
145
146         // Return decoded string
147         return $decodedString;
148 }
149
150 // Merges an array together but only if both are arrays
151 function merge_array ($array1, $array2) {
152         // Are both an array?
153         if ((!is_array($array1)) && (!is_array($array2))) {
154                 // Both are not arrays
155                 debug_report_bug(__FUNCTION__, __LINE__, 'No arrays provided!');
156         } elseif (!is_array($array1)) {
157                 // Left one is not an array
158                 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
159         } elseif (!is_array($array2)) {
160                 // Right one is not an array
161                 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
162         }
163
164         // Merge all together
165         return array_merge($array1, $array2);
166 }
167
168 // Check if given FQFN is a readable file
169 function isFileReadable ($FQFN) {
170         // Do we have cache?
171         if (!isset($GLOBALS['file_readable'][$FQFN])) {
172                 // Check all...
173                 $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN)));
174         } // END - if
175
176         // Return result
177         return $GLOBALS['file_readable'][$FQFN];
178 }
179
180 // Checks wether the given FQFN is a directory and not ., .. or .svn
181 function isDirectory ($FQFN) {
182         // Do we have cache?
183         if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
184                 // Generate baseName
185                 $baseName = basename($FQFN);
186
187                 // Check it
188                 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
189         } // END - if
190
191         // Return the result
192         return $GLOBALS[__FUNCTION__][$FQFN];
193 }
194
195 // "Getter" for the real remote IP number
196 function detectRealIpAddress () {
197         // Get remote ip from environment
198         $remoteAddr = determineRealRemoteAddress();
199
200         // Is removeip installed?
201         if (isExtensionActive('removeip')) {
202                 // Then anonymize it
203                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
204         } // END - if
205
206         // Return it
207         return $remoteAddr;
208 }
209
210 // "Getter" for remote IP number
211 function detectRemoteAddr () {
212         // Get remote ip from environment
213         $remoteAddr = determineRealRemoteAddress(true);
214
215         // Is removeip installed?
216         if (isExtensionActive('removeip')) {
217                 // Then anonymize it
218                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
219         } // END - if
220
221         // Return it
222         return $remoteAddr;
223 }
224
225 // "Getter" for remote hostname
226 function detectRemoteHostname () {
227         // Get remote ip from environment
228         $remoteHost = getenv('REMOTE_HOST');
229
230         // Is removeip installed?
231         if (isExtensionActive('removeip')) {
232                 // Then anonymize it
233                 $remoteHost = getAnonymousRemoteHost($remoteHost);
234         } // END - if
235
236         // Return it
237         return $remoteHost;
238 }
239
240 // "Getter" for user agent
241 function detectUserAgent ($alwaysReal = false) {
242         // Get remote ip from environment
243         $userAgent = getenv('HTTP_USER_AGENT');
244
245         // Is removeip installed?
246         if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
247                 // Then anonymize it
248                 $userAgent = getAnonymousUserAgent($userAgent);
249         } // END - if
250
251         // Return it
252         return $userAgent;
253 }
254
255 // "Getter" for referer
256 function detectReferer () {
257         // Get remote ip from environment
258         $referer = getenv('HTTP_REFERER');
259
260         // Is removeip installed?
261         if (isExtensionActive('removeip')) {
262                 // Then anonymize it
263                 $referer = getAnonymousReferer($referer);
264         } // END - if
265
266         // Return it
267         return $referer;
268 }
269
270 // "Getter" for request URI
271 function detectRequestUri () {
272         // Return it
273         return (getenv('REQUEST_URI'));
274 }
275
276 // "Getter" for query string
277 function detectQueryString () {
278         return str_replace('&', '&amp;', (getenv('QUERY_STRING')));
279 }
280
281 // "Getter" for SERVER_NAME
282 function detectServerName () {
283         // Return it
284         return (getenv('SERVER_NAME'));
285 }
286
287 // Removes any  existing www. from SERVER_NAME. This is very silly but enough
288 // for our purpose here.
289 function detectDomainName () {
290         // Do we have cache?
291         if (!isset($GLOBALS[__FUNCTION__])) {
292                 // Get server name
293                 $domainName = detectServerName();
294
295                 // Is there any www. ?
296                 if (substr($domainName, 0, 4) == 'www.') {
297                         // Remove it
298                         $domainName = substr($domainName, 4);
299                 } // END - if
300
301                 // Set cache
302                 $GLOBALS[__FUNCTION__] = $domainName;
303         } // END - if
304
305         // Return cache
306         return $GLOBALS[__FUNCTION__];
307 }
308
309 // Check wether we are installing
310 function isInstalling () {
311         // Determine wether we are installing
312         if (!isset($GLOBALS['mailer_installing'])) {
313                 // Check URL (css.php/js.php need this)
314                 $GLOBALS['mailer_installing'] = isGetRequestElementSet('installing');
315         } // END - if
316
317         // Return result
318         return $GLOBALS['mailer_installing'];
319 }
320
321 // Check wether this script is installed
322 function isInstalled () {
323         // Do we have cache?
324         if (!isset($GLOBALS[__FUNCTION__])) {
325                 // Determine wether this script is installed
326                 $GLOBALS[__FUNCTION__] = (
327                 (
328                         // First is config
329                         (
330                                 (
331                                         isConfigEntrySet('MXCHANGE_INSTALLED')
332                                 ) && (
333                                         getConfig('MXCHANGE_INSTALLED') == 'Y'
334                                 )
335                         )
336                 ) || (
337                         // New config file found and loaded
338                         isIncludeReadable(getCachePath() . 'config-local.php')
339                 ) || (
340                         (
341                                 // New config file found, but not yet read
342                                 isIncludeReadable(getCachePath() . 'config-local.php')
343                         ) && (
344                                 (
345                                         // Only new config file is found
346                                         !isIncludeReadable('inc/config.php')
347                                 ) || (
348                                         // Is installation mode
349                                         !isInstalling()
350                                 )
351                         )
352                 ));
353         } // END - if
354
355         // Then use the cache
356         return $GLOBALS[__FUNCTION__];
357 }
358
359 // Check wether an admin is registered
360 function isAdminRegistered () {
361         // Is cache set?
362         if (!isset($GLOBALS[__FUNCTION__])) {
363                 // Simply check it
364                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
365         } // END - if
366
367         // Return it
368         return $GLOBALS[__FUNCTION__];
369 }
370
371 // Checks wether the hourly reset mode is active
372 function isHourlyResetEnabled () {
373         // Now simply check it
374         return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === true));
375 }
376
377 // Checks wether the reset mode is active
378 function isResetModeEnabled () {
379         // Now simply check it
380         return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
381 }
382
383 // Checks wether the debug mode is enabled
384 function isDebugModeEnabled () {
385         // Is cache set?
386         if (!isset($GLOBALS[__FUNCTION__])) {
387                 // Simply check it
388                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
389         } // END - if
390
391         // Return it
392         return $GLOBALS[__FUNCTION__];
393 }
394
395 // Checks wether the debug reset is enabled
396 function isDebugResetEnabled () {
397         // Is cache set?
398         if (!isset($GLOBALS[__FUNCTION__])) {
399                 // Simply check it
400                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
401         } // END - if
402
403         // Return it
404         return $GLOBALS[__FUNCTION__];
405 }
406
407 // Checks wether SQL debugging is enabled
408 function isSqlDebuggingEnabled () {
409         // Is cache set?
410         if (!isset($GLOBALS[__FUNCTION__])) {
411                 // Determine if SQL debugging is enabled
412                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
413         } // END - if
414
415         // Return it
416         return $GLOBALS[__FUNCTION__];
417 }
418
419 // Checks wether we shall debug regular expressions
420 function isDebugRegularExpressionEnabled () {
421         // Is cache set?
422         if (!isset($GLOBALS[__FUNCTION__])) {
423                 // Simply check it
424                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
425         } // END - if
426
427         // Return it
428         return $GLOBALS[__FUNCTION__];
429 }
430
431 // Checks wether the cache instance is valid
432 function isCacheInstanceValid () {
433         // Do we have cache?
434         if (!isset($GLOBALS[__FUNCTION__])) {
435                 // Determine it
436                 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
437         } // END - if
438
439         // Return cache
440         return $GLOBALS[__FUNCTION__];
441 }
442
443 // Copies a file from source to destination and verifies if that goes fine.
444 // This function should wrap the copy() command and make a nicer debug backtrace
445 // even if there is no xdebug extension installed.
446 function copyFileVerified ($source, $dest, $chmod = '') {
447         // Failed is the default
448         $status = false;
449
450         // Is the source file there?
451         if (!isFileReadable($source)) {
452                 // Then abort here
453                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
454         } // END - if
455
456         // Is the target directory there?
457         if (!isDirectory(dirname($dest))) {
458                 // Then abort here
459                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
460         } // END - if
461
462         // Now try to copy it
463         if (!copy($source, $dest)) {
464                 // Something went wrong
465                 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
466         } else {
467                 // Reset cache
468                 $GLOBALS['file_readable'][$dest] = true;
469         }
470
471         // If there are chmod rights set, apply them
472         if (!empty($chmod)) {
473                 // Try to apply them
474                 $status = changeMode($dest, $chmod);
475         } else {
476                 // All fine
477                 $status = true;
478         }
479
480         // All fine
481         return $status;
482 }
483
484 // Wrapper function for chmod()
485 // @TODO Do some more sanity check here
486 function changeMode ($FQFN, $mode) {
487         // Is the file/directory there?
488         if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
489                 // Neither, so abort here
490                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
491         } // END - if
492
493         // Try to set them
494         return chmod($FQFN, $mode);
495 }
496
497 // Wrapper for unlink()
498 function removeFile ($FQFN) {
499         // Is the file there?
500         if (isFileReadable($FQFN)) {
501                 // Reset cache first
502                 $GLOBALS['file_readable'][$FQFN] = false;
503
504                 // Yes, so remove it
505                 return unlink($FQFN);
506         } // END - if
507
508         // All fine if no file was removed. If we change this to 'false' or rewrite
509         // above if() block it would be to restrictive.
510         return true;
511 }
512
513 // Wrapper for $_POST['sel']
514 function countPostSelection ($element = 'sel') {
515         // Is it set?
516         if (isPostRequestElementSet($element)) {
517                 // Return counted elements
518                 return countSelection(postRequestElement($element));
519         } else {
520                 // Return zero if not found
521                 return 0;
522         }
523 }
524
525 // Checks wether the config-local.php is loaded
526 function isConfigLocalLoaded () {
527         return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
528 }
529
530 // Checks wether a nickname or userid was entered and caches the result
531 function isNicknameUsed ($userid) {
532         // Is the cache there
533         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
534                 // Determine it
535                 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . round($userid) . '') != $userid) && ($userid != 'NULL'));
536         } // END - if
537
538         // Return the result
539         return $GLOBALS[__FUNCTION__][$userid];
540 }
541
542 // Getter for 'what' value
543 function getWhat () {
544         // Default is null
545         $what = NULL;
546
547         // Is the value set?
548         if (isWhatSet(true)) {
549                 // Then use it
550                 $what = $GLOBALS['__what'];
551         } // END - if
552
553         // Return it
554         return $what;
555 }
556
557 // Setter for 'what' value
558 function setWhat ($newWhat) {
559         $GLOBALS['__what'] = $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         // Send helping header
1112         setHttpStatus('302 Found');
1113
1114         // always close the session
1115         session_write_close();
1116
1117         // Revert entity &amp;
1118         $url = str_replace('&amp;', '&', $url);
1119
1120         // check if running on IIS < 6 with CGI-PHP
1121         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1122                 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1123                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1124                 ($matches[1] < 6)) {
1125                 // Send the IIS header
1126                 addHttpHeader('Refresh: 0;url=' . $url);
1127         } else {
1128                 // Send generic header
1129                 addHttpHeader('Location: ' . $url);
1130         }
1131
1132         // Shutdown here
1133         shutdown();
1134 }
1135
1136 // Determines the country of the given user id
1137 function determineCountry ($userid) {
1138         // Do we have cache?
1139         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1140                 // Default is 'invalid'
1141                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1142
1143                 // Is extension country active?
1144                 if (isExtensionActive('country')) {
1145                         // Determine the right country code through the country id
1146                         $id = getUserData('country_code');
1147
1148                         // Then handle it over
1149                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1150                 } else {
1151                         // Get raw code from user data
1152                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1153                 }
1154         } // END - if
1155
1156         // Return cache
1157         return $GLOBALS[__FUNCTION__][$userid];
1158 }
1159
1160 // "Getter" for total confirmed user accounts
1161 function getTotalConfirmedUser () {
1162         // Is it cached?
1163         if (!isset($GLOBALS[__FUNCTION__])) {
1164                 // Then do it
1165                 if (isExtensionActive('user')) {
1166                         $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1167                 } else {
1168                         $GLOBALS[__FUNCTION__] = 0;
1169                 }
1170         } // END - if
1171
1172         // Return cached value
1173         return $GLOBALS[__FUNCTION__];
1174 }
1175
1176 // "Getter" for total unconfirmed user accounts
1177 function getTotalUnconfirmedUser () {
1178         // Is it cached?
1179         if (!isset($GLOBALS[__FUNCTION__])) {
1180                 // Then do it
1181                 if (isExtensionActive('user')) {
1182                         $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1183                 } else {
1184                         $GLOBALS[__FUNCTION__] = 0;
1185                 }
1186         } // END - if
1187
1188         // Return cached value
1189         return $GLOBALS[__FUNCTION__];
1190 }
1191
1192 // "Getter" for total locked user accounts
1193 function getTotalLockedUser () {
1194         // Is it cached?
1195         if (!isset($GLOBALS[__FUNCTION__])) {
1196                 // Then do it
1197                 if (isExtensionActive('user')) {
1198                         $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1199                 } else {
1200                         $GLOBALS[__FUNCTION__] = 0;
1201                 }
1202         } // END - if
1203
1204         // Return cached value
1205         return $GLOBALS[__FUNCTION__];
1206 }
1207
1208 // "Getter" for total locked user accounts
1209 function getTotalRandomRefidUser () {
1210         // Is it cached?
1211         if (!isset($GLOBALS[__FUNCTION__])) {
1212                 // Then do it
1213                 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1214                         $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, '', '>=');
1215                 } else {
1216                         $GLOBALS[__FUNCTION__] = 0;
1217                 }
1218         } // END - if
1219
1220         // Return cached value
1221         return $GLOBALS[__FUNCTION__];
1222 }
1223
1224 // Is given userid valid?
1225 function isValidUserId ($userid) {
1226         // Do we have cache?
1227         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1228                 // Check it out
1229                 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1230         } // END - if
1231
1232         // Return cache
1233         return $GLOBALS[__FUNCTION__][$userid];
1234 }
1235
1236 // Encodes entities
1237 function encodeEntities ($str) {
1238         // Secure it first
1239         $str = secureString($str, true, true);
1240
1241         // Encode dollar sign as well
1242         $str = str_replace('$', '&#36;', $str);
1243
1244         // Return it
1245         return $str;
1246 }
1247
1248 // "Getter" for date from patch_ctime
1249 function getDateFromRepository () {
1250         // Is it cached?
1251         if (!isset($GLOBALS[__FUNCTION__])) {
1252                 // Then set it
1253                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1254         } // END - if
1255
1256         // Return cache
1257         return $GLOBALS[__FUNCTION__];
1258 }
1259
1260 // "Getter" for date/time from patch_ctime
1261 function getDateTimeFromRepository () {
1262         // Is it cached?
1263         if (!isset($GLOBALS[__FUNCTION__])) {
1264                 // Then set it
1265                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1266         } // END - if
1267
1268         // Return cache
1269         return $GLOBALS[__FUNCTION__];
1270 }
1271
1272 // Getter for current year (default)
1273 function getYear ($timestamp = NULL) {
1274         // Is it cached?
1275         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1276                 // null is time()
1277                 if (is_null($timestamp)) {
1278                         $timestamp = time();
1279                 } // END - if
1280
1281                 // Then create it
1282                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1283         } // END - if
1284
1285         // Return cache
1286         return $GLOBALS[__FUNCTION__][$timestamp];
1287 }
1288
1289 // Getter for current month (default)
1290 function getMonth ($timestamp = NULL) {
1291         // Is it cached?
1292         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1293                 // If null is set, use time()
1294                 if (is_null($timestamp)) {
1295                         // Use time() which is current timestamp
1296                         $timestamp = time();
1297                 } // END - if
1298
1299                 // Then create it
1300                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1301         } // END - if
1302
1303         // Return cache
1304         return $GLOBALS[__FUNCTION__][$timestamp];
1305 }
1306
1307 // Getter for current hour (default)
1308 function getHour ($timestamp = NULL) {
1309         // Is it cached?
1310         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1311                 // null is time()
1312                 if (is_null($timestamp)) {
1313                         $timestamp = time();
1314                 } // END - if
1315
1316                 // Then create it
1317                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1318         } // END - if
1319
1320         // Return cache
1321         return $GLOBALS[__FUNCTION__][$timestamp];
1322 }
1323
1324 // Getter for current day (default)
1325 function getDay ($timestamp = NULL) {
1326         // Is it cached?
1327         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1328                 // null is time()
1329                 if (is_null($timestamp)) {
1330                         $timestamp = time();
1331                 } // END - if
1332
1333                 // Then create it
1334                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1335         } // END - if
1336
1337         // Return cache
1338         return $GLOBALS[__FUNCTION__][$timestamp];
1339 }
1340
1341 // Getter for current week (default)
1342 function getWeek ($timestamp = NULL) {
1343         // Is it cached?
1344         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1345                 // null is time()
1346                 if (is_null($timestamp)) $timestamp = time();
1347
1348                 // Then create it
1349                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1350         } // END - if
1351
1352         // Return cache
1353         return $GLOBALS[__FUNCTION__][$timestamp];
1354 }
1355
1356 // Getter for current short_hour (default)
1357 function getShortHour ($timestamp = NULL) {
1358         // Is it cached?
1359         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1360                 // null is time()
1361                 if (is_null($timestamp)) $timestamp = time();
1362
1363                 // Then create it
1364                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1365         } // END - if
1366
1367         // Return cache
1368         return $GLOBALS[__FUNCTION__][$timestamp];
1369 }
1370
1371 // Getter for current long_hour (default)
1372 function getLongHour ($timestamp = NULL) {
1373         // Is it cached?
1374         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1375                 // null is time()
1376                 if (is_null($timestamp)) $timestamp = time();
1377
1378                 // Then create it
1379                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1380         } // END - if
1381
1382         // Return cache
1383         return $GLOBALS[__FUNCTION__][$timestamp];
1384 }
1385
1386 // Getter for current second (default)
1387 function getSecond ($timestamp = NULL) {
1388         // Is it cached?
1389         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1390                 // null is time()
1391                 if (is_null($timestamp)) $timestamp = time();
1392
1393                 // Then create it
1394                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1395         } // END - if
1396
1397         // Return cache
1398         return $GLOBALS[__FUNCTION__][$timestamp];
1399 }
1400
1401 // Getter for current minute (default)
1402 function getMinute ($timestamp = NULL) {
1403         // Is it cached?
1404         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1405                 // null is time()
1406                 if (is_null($timestamp)) $timestamp = time();
1407
1408                 // Then create it
1409                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1410         } // END - if
1411
1412         // Return cache
1413         return $GLOBALS[__FUNCTION__][$timestamp];
1414 }
1415
1416 // Checks wether the title decoration is enabled
1417 function isTitleDecorationEnabled () {
1418         // Do we have cache?
1419         if (!isset($GLOBALS[__FUNCTION__])) {
1420                 // Just check it
1421                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1422         } // END - if
1423
1424         // Return cache
1425         return $GLOBALS[__FUNCTION__];
1426 }
1427
1428 // Checks wether filter usage updates are enabled (expensive queries!)
1429 function isFilterUsageUpdateEnabled () {
1430         // Do we have cache?
1431         if (!isset($GLOBALS[__FUNCTION__])) {
1432                 // Determine it
1433                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1434         } // END - if
1435
1436         // Return cache
1437         return $GLOBALS[__FUNCTION__];
1438 }
1439
1440 // Checks wether debugging of weekly resets is enabled
1441 function isWeeklyResetDebugEnabled () {
1442         // Do we have cache?
1443         if (!isset($GLOBALS[__FUNCTION__])) {
1444                 // Determine it
1445                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1446         } // END - if
1447
1448         // Return cache
1449         return $GLOBALS[__FUNCTION__];
1450 }
1451
1452 // Checks wether debugging of monthly resets is enabled
1453 function isMonthlyResetDebugEnabled () {
1454         // Do we have cache?
1455         if (!isset($GLOBALS[__FUNCTION__])) {
1456                 // Determine it
1457                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1458         } // END - if
1459
1460         // Return cache
1461         return $GLOBALS[__FUNCTION__];
1462 }
1463
1464 // Checks wether displaying of debug SQLs are enabled
1465 function isDisplayDebugSqlEnabled () {
1466         // Do we have cache?
1467         if (!isset($GLOBALS[__FUNCTION__])) {
1468                 // Determine it
1469                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1470         } // END - if
1471
1472         // Return cache
1473         return $GLOBALS[__FUNCTION__];
1474 }
1475
1476 // Checks wether module title is enabled
1477 function isModuleTitleEnabled () {
1478         // Do we have cache?
1479         if (!isset($GLOBALS[__FUNCTION__])) {
1480                 // Determine it
1481                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1482         } // END - if
1483
1484         // Return cache
1485         return $GLOBALS[__FUNCTION__];
1486 }
1487
1488 // Checks wether what title is enabled
1489 function isWhatTitleEnabled () {
1490         // Do we have cache?
1491         if (!isset($GLOBALS[__FUNCTION__])) {
1492                 // Determine it
1493                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1494         } // END - if
1495
1496         // Return cache
1497         return $GLOBALS[__FUNCTION__];
1498 }
1499
1500 // Checks wether stats are enabled
1501 function ifInternalStatsEnabled () {
1502         // Do we have cache?
1503         if (!isset($GLOBALS[__FUNCTION__])) {
1504                 // Then determine it
1505                 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1506         } // END - if
1507
1508         // Return cached value
1509         return $GLOBALS[__FUNCTION__];
1510 }
1511
1512 // Checks wether admin-notification of certain user actions is enabled
1513 function isAdminNotificationEnabled () {
1514         // Do we have cache?
1515         if (!isset($GLOBALS[__FUNCTION__])) {
1516                 // Determine it
1517                 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1518         } // END - if
1519
1520         // Return cache
1521         return $GLOBALS[__FUNCTION__];
1522 }
1523
1524 // Checks wether random referral id selection is enabled
1525 function isRandomReferralIdEnabled () {
1526         // Do we have cache?
1527         if (!isset($GLOBALS[__FUNCTION__])) {
1528                 // Determine it
1529                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1530         } // END - if
1531
1532         // Return cache
1533         return $GLOBALS[__FUNCTION__];
1534 }
1535
1536 // "Getter" for default language
1537 function getDefaultLanguage () {
1538         // Do we have cache?
1539         if (!isset($GLOBALS[__FUNCTION__])) {
1540                 // Determine it
1541                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1542         } // END - if
1543
1544         // Return cache
1545         return $GLOBALS[__FUNCTION__];
1546 }
1547
1548 // "Getter" for default referral id
1549 function getDefRefid () {
1550         // Do we have cache?
1551         if (!isset($GLOBALS[__FUNCTION__])) {
1552                 // Determine it
1553                 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1554         } // END - if
1555
1556         // Return cache
1557         return $GLOBALS[__FUNCTION__];
1558 }
1559
1560 // "Getter" for path
1561 function getPath () {
1562         // Do we have cache?
1563         if (!isset($GLOBALS[__FUNCTION__])) {
1564                 // Determine it
1565                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1566         } // END - if
1567
1568         // Return cache
1569         return $GLOBALS[__FUNCTION__];
1570 }
1571
1572 // "Getter" for url
1573 function getUrl () {
1574         // Do we have cache?
1575         if (!isset($GLOBALS[__FUNCTION__])) {
1576                 // Determine it
1577                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1578         } // END - if
1579
1580         // Return cache
1581         return $GLOBALS[__FUNCTION__];
1582 }
1583
1584 // "Getter" for cache_path
1585 function getCachePath () {
1586         // Do we have cache?
1587         if (!isset($GLOBALS[__FUNCTION__])) {
1588                 // Determine it
1589                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1590         } // END - if
1591
1592         // Return cache
1593         return $GLOBALS[__FUNCTION__];
1594 }
1595
1596 // "Getter" for secret_key
1597 function getSecretKey () {
1598         // Do we have cache?
1599         if (!isset($GLOBALS[__FUNCTION__])) {
1600                 // Determine it
1601                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1602         } // END - if
1603
1604         // Return cache
1605         return $GLOBALS[__FUNCTION__];
1606 }
1607
1608 // "Getter" for SITE_KEY
1609 function getSiteKey () {
1610         // Do we have cache?
1611         if (!isset($GLOBALS[__FUNCTION__])) {
1612                 // Determine it
1613                 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1614         } // END - if
1615
1616         // Return cache
1617         return $GLOBALS[__FUNCTION__];
1618 }
1619
1620 // "Getter" for DATE_KEY
1621 function getDateKey () {
1622         // Do we have cache?
1623         if (!isset($GLOBALS[__FUNCTION__])) {
1624                 // Determine it
1625                 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1626         } // END - if
1627
1628         // Return cache
1629         return $GLOBALS[__FUNCTION__];
1630 }
1631
1632 // "Getter" for master_salt
1633 function getMasterSalt () {
1634         // Do we have cache?
1635         if (!isset($GLOBALS[__FUNCTION__])) {
1636                 // Determine it
1637                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1638         } // END - if
1639
1640         // Return cache
1641         return $GLOBALS[__FUNCTION__];
1642 }
1643
1644 // "Getter" for prime
1645 function getPrime () {
1646         // Do we have cache?
1647         if (!isset($GLOBALS[__FUNCTION__])) {
1648                 // Determine it
1649                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1650         } // END - if
1651
1652         // Return cache
1653         return $GLOBALS[__FUNCTION__];
1654 }
1655
1656 // "Getter" for encrypt_separator
1657 function getEncryptSeparator () {
1658         // Do we have cache?
1659         if (!isset($GLOBALS[__FUNCTION__])) {
1660                 // Determine it
1661                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1662         } // END - if
1663
1664         // Return cache
1665         return $GLOBALS[__FUNCTION__];
1666 }
1667
1668 // "Getter" for mysql_prefix
1669 function getMysqlPrefix () {
1670         // Do we have cache?
1671         if (!isset($GLOBALS[__FUNCTION__])) {
1672                 // Determine it
1673                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1674         } // END - if
1675
1676         // Return cache
1677         return $GLOBALS[__FUNCTION__];
1678 }
1679
1680 // "Getter" for table_type
1681 function getTableType () {
1682         // Do we have cache?
1683         if (!isset($GLOBALS[__FUNCTION__])) {
1684                 // Determine it
1685                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1686         } // END - if
1687
1688         // Return cache
1689         return $GLOBALS[__FUNCTION__];
1690 }
1691
1692 // "Getter" for salt_length
1693 function getSaltLength () {
1694         // Do we have cache?
1695         if (!isset($GLOBALS[__FUNCTION__])) {
1696                 // Determine it
1697                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1698         } // END - if
1699
1700         // Return cache
1701         return $GLOBALS[__FUNCTION__];
1702 }
1703
1704 // "Getter" for output_mode
1705 function getOutputMode () {
1706         // Do we have cache?
1707         if (!isset($GLOBALS[__FUNCTION__])) {
1708                 // Determine it
1709                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1710         } // END - if
1711
1712         // Return cache
1713         return $GLOBALS[__FUNCTION__];
1714 }
1715
1716 // "Getter" for full_version
1717 function getFullVersion () {
1718         // Do we have cache?
1719         if (!isset($GLOBALS[__FUNCTION__])) {
1720                 // Determine it
1721                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1722         } // END - if
1723
1724         // Return cache
1725         return $GLOBALS[__FUNCTION__];
1726 }
1727
1728 // "Getter" for title
1729 function getTitle () {
1730         // Do we have cache?
1731         if (!isset($GLOBALS[__FUNCTION__])) {
1732                 // Determine it
1733                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1734         } // END - if
1735
1736         // Return cache
1737         return $GLOBALS[__FUNCTION__];
1738 }
1739
1740 // "Getter" for curr_svn_revision
1741 function getCurrentRepositoryRevision () {
1742         // Do we have cache?
1743         if (!isset($GLOBALS[__FUNCTION__])) {
1744                 // Determine it
1745                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1746         } // END - if
1747
1748         // Return cache
1749         return $GLOBALS[__FUNCTION__];
1750 }
1751
1752 // "Getter" for server_url
1753 function getServerUrl () {
1754         // Do we have cache?
1755         if (!isset($GLOBALS[__FUNCTION__])) {
1756                 // Determine it
1757                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1758         } // END - if
1759
1760         // Return cache
1761         return $GLOBALS[__FUNCTION__];
1762 }
1763
1764 // "Getter" for mt_word
1765 function getMtWord () {
1766         // Do we have cache?
1767         if (!isset($GLOBALS[__FUNCTION__])) {
1768                 // Determine it
1769                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1770         } // END - if
1771
1772         // Return cache
1773         return $GLOBALS[__FUNCTION__];
1774 }
1775
1776 // "Getter" for mt_word2
1777 function getMtWord2 () {
1778         // Do we have cache?
1779         if (!isset($GLOBALS[__FUNCTION__])) {
1780                 // Determine it
1781                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1782         } // END - if
1783
1784         // Return cache
1785         return $GLOBALS[__FUNCTION__];
1786 }
1787
1788 // "Getter" for main_title
1789 function getMainTitle () {
1790         // Do we have cache?
1791         if (!isset($GLOBALS[__FUNCTION__])) {
1792                 // Determine it
1793                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1794         } // END - if
1795
1796         // Return cache
1797         return $GLOBALS[__FUNCTION__];
1798 }
1799
1800 // "Getter" for file_hash
1801 function getFileHash () {
1802         // Do we have cache?
1803         if (!isset($GLOBALS[__FUNCTION__])) {
1804                 // Determine it
1805                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1806         } // END - if
1807
1808         // Return cache
1809         return $GLOBALS[__FUNCTION__];
1810 }
1811
1812 // "Getter" for pass_scramble
1813 function getPassScramble () {
1814         // Do we have cache?
1815         if (!isset($GLOBALS[__FUNCTION__])) {
1816                 // Determine it
1817                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1818         } // END - if
1819
1820         // Return cache
1821         return $GLOBALS[__FUNCTION__];
1822 }
1823
1824 // "Getter" for ap_inactive_since
1825 function getApInactiveSince () {
1826         // Do we have cache?
1827         if (!isset($GLOBALS[__FUNCTION__])) {
1828                 // Determine it
1829                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1830         } // END - if
1831
1832         // Return cache
1833         return $GLOBALS[__FUNCTION__];
1834 }
1835
1836 // "Getter" for user_min_confirmed
1837 function getUserMinConfirmed () {
1838         // Do we have cache?
1839         if (!isset($GLOBALS[__FUNCTION__])) {
1840                 // Determine it
1841                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1842         } // END - if
1843
1844         // Return cache
1845         return $GLOBALS[__FUNCTION__];
1846 }
1847
1848 // "Getter" for auto_purge
1849 function getAutoPurge () {
1850         // Do we have cache?
1851         if (!isset($GLOBALS[__FUNCTION__])) {
1852                 // Determine it
1853                 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1854         } // END - if
1855
1856         // Return cache
1857         return $GLOBALS[__FUNCTION__];
1858 }
1859
1860 // "Getter" for bonus_userid
1861 function getBonusUserid () {
1862         // Do we have cache?
1863         if (!isset($GLOBALS[__FUNCTION__])) {
1864                 // Determine it
1865                 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1866         } // END - if
1867
1868         // Return cache
1869         return $GLOBALS[__FUNCTION__];
1870 }
1871
1872 // "Getter" for ap_inactive_time
1873 function getApInactiveTime () {
1874         // Do we have cache?
1875         if (!isset($GLOBALS[__FUNCTION__])) {
1876                 // Determine it
1877                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1878         } // END - if
1879
1880         // Return cache
1881         return $GLOBALS[__FUNCTION__];
1882 }
1883
1884 // "Getter" for ap_dm_timeout
1885 function getApDmTimeout () {
1886         // Do we have cache?
1887         if (!isset($GLOBALS[__FUNCTION__])) {
1888                 // Determine it
1889                 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1890         } // END - if
1891
1892         // Return cache
1893         return $GLOBALS[__FUNCTION__];
1894 }
1895
1896 // "Getter" for ap_tasks_time
1897 function getApTasksTime () {
1898         // Do we have cache?
1899         if (!isset($GLOBALS[__FUNCTION__])) {
1900                 // Determine it
1901                 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1902         } // END - if
1903
1904         // Return cache
1905         return $GLOBALS[__FUNCTION__];
1906 }
1907
1908 // "Getter" for ap_unconfirmed_time
1909 function getApUnconfirmedTime () {
1910         // Do we have cache?
1911         if (!isset($GLOBALS[__FUNCTION__])) {
1912                 // Determine it
1913                 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1914         } // END - if
1915
1916         // Return cache
1917         return $GLOBALS[__FUNCTION__];
1918 }
1919
1920 // "Getter" for points
1921 function getPoints () {
1922         // Do we have cache?
1923         if (!isset($GLOBALS[__FUNCTION__])) {
1924                 // Determine it
1925                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1926         } // END - if
1927
1928         // Return cache
1929         return $GLOBALS[__FUNCTION__];
1930 }
1931
1932 // "Getter" for slogan
1933 function getSlogan () {
1934         // Do we have cache?
1935         if (!isset($GLOBALS[__FUNCTION__])) {
1936                 // Determine it
1937                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1938         } // END - if
1939
1940         // Return cache
1941         return $GLOBALS[__FUNCTION__];
1942 }
1943
1944 // "Getter" for copy
1945 function getCopy () {
1946         // Do we have cache?
1947         if (!isset($GLOBALS[__FUNCTION__])) {
1948                 // Determine it
1949                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1950         } // END - if
1951
1952         // Return cache
1953         return $GLOBALS[__FUNCTION__];
1954 }
1955
1956 // "Getter" for webmaster
1957 function getWebmaster () {
1958         // Do we have cache?
1959         if (!isset($GLOBALS[__FUNCTION__])) {
1960                 // Determine it
1961                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1962         } // END - if
1963
1964         // Return cache
1965         return $GLOBALS[__FUNCTION__];
1966 }
1967
1968 // "Getter" for sql_count
1969 function getSqlCount () {
1970         // Do we have cache?
1971         if (!isset($GLOBALS[__FUNCTION__])) {
1972                 // Determine it
1973                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1974         } // END - if
1975
1976         // Return cache
1977         return $GLOBALS[__FUNCTION__];
1978 }
1979
1980 // "Getter" for num_templates
1981 function getNumTemplates () {
1982         // Do we have cache?
1983         if (!isset($GLOBALS[__FUNCTION__])) {
1984                 // Determine it
1985                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1986         } // END - if
1987
1988         // Return cache
1989         return $GLOBALS[__FUNCTION__];
1990 }
1991
1992 // "Getter" for dns_cache_timeout
1993 function getDnsCacheTimeout () {
1994         // Do we have cache?
1995         if (!isset($GLOBALS[__FUNCTION__])) {
1996                 // Determine it
1997                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1998         } // END - if
1999
2000         // Return cache
2001         return $GLOBALS[__FUNCTION__];
2002 }
2003
2004 // "Getter" for menu_blur_spacer
2005 function getMenuBlurSpacer () {
2006         // Do we have cache?
2007         if (!isset($GLOBALS[__FUNCTION__])) {
2008                 // Determine it
2009                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2010         } // END - if
2011
2012         // Return cache
2013         return $GLOBALS[__FUNCTION__];
2014 }
2015
2016 // "Getter" for points_register
2017 function getPointsRegister () {
2018         // Do we have cache?
2019         if (!isset($GLOBALS[__FUNCTION__])) {
2020                 // Determine it
2021                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2022         } // END - if
2023
2024         // Return cache
2025         return $GLOBALS[__FUNCTION__];
2026 }
2027
2028 // "Getter" for points_ref
2029 function getPointsRef () {
2030         // Do we have cache?
2031         if (!isset($GLOBALS[__FUNCTION__])) {
2032                 // Determine it
2033                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2034         } // END - if
2035
2036         // Return cache
2037         return $GLOBALS[__FUNCTION__];
2038 }
2039
2040 // "Getter" for ref_payout
2041 function getRefPayout () {
2042         // Do we have cache?
2043         if (!isset($GLOBALS[__FUNCTION__])) {
2044                 // Determine it
2045                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2046         } // END - if
2047
2048         // Return cache
2049         return $GLOBALS[__FUNCTION__];
2050 }
2051
2052 // "Getter" for online_timeout
2053 function getOnlineTimeout () {
2054         // Do we have cache?
2055         if (!isset($GLOBALS[__FUNCTION__])) {
2056                 // Determine it
2057                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2058         } // END - if
2059
2060         // Return cache
2061         return $GLOBALS[__FUNCTION__];
2062 }
2063
2064 // "Getter" for index_home
2065 function getIndexHome () {
2066         // Do we have cache?
2067         if (!isset($GLOBALS[__FUNCTION__])) {
2068                 // Determine it
2069                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2070         } // END - if
2071
2072         // Return cache
2073         return $GLOBALS[__FUNCTION__];
2074 }
2075
2076 // "Getter" for one_day
2077 function getOneDay () {
2078         // Do we have cache?
2079         if (!isset($GLOBALS[__FUNCTION__])) {
2080                 // Determine it
2081                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2082         } // END - if
2083
2084         // Return cache
2085         return $GLOBALS[__FUNCTION__];
2086 }
2087
2088 // "Getter" for activate_xchange
2089 function getActivateXchange () {
2090         // Do we have cache?
2091         if (!isset($GLOBALS[__FUNCTION__])) {
2092                 // Determine it
2093                 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2094         } // END - if
2095
2096         // Return cache
2097         return $GLOBALS[__FUNCTION__];
2098 }
2099
2100 // "Getter" for img_type
2101 function getImgType () {
2102         // Do we have cache?
2103         if (!isset($GLOBALS[__FUNCTION__])) {
2104                 // Determine it
2105                 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2106         } // END - if
2107
2108         // Return cache
2109         return $GLOBALS[__FUNCTION__];
2110 }
2111
2112 // "Getter" for code_length
2113 function getCodeLength () {
2114         // Do we have cache?
2115         if (!isset($GLOBALS[__FUNCTION__])) {
2116                 // Determine it
2117                 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2118         } // END - if
2119
2120         // Return cache
2121         return $GLOBALS[__FUNCTION__];
2122 }
2123
2124 // "Getter" for least_cats
2125 function getLeastCats () {
2126         // Do we have cache?
2127         if (!isset($GLOBALS[__FUNCTION__])) {
2128                 // Determine it
2129                 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2130         } // END - if
2131
2132         // Return cache
2133         return $GLOBALS[__FUNCTION__];
2134 }
2135
2136 // "Getter" for pass_len
2137 function getPassLen () {
2138         // Do we have cache?
2139         if (!isset($GLOBALS[__FUNCTION__])) {
2140                 // Determine it
2141                 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2142         } // END - if
2143
2144         // Return cache
2145         return $GLOBALS[__FUNCTION__];
2146 }
2147
2148 // "Getter" for admin_menu
2149 function getAdminMenu () {
2150         // Do we have cache?
2151         if (!isset($GLOBALS[__FUNCTION__])) {
2152                 // Determine it
2153                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2154         } // END - if
2155
2156         // Return cache
2157         return $GLOBALS[__FUNCTION__];
2158 }
2159
2160 // "Getter" for last_month
2161 function getLastMonth () {
2162         // Do we have cache?
2163         if (!isset($GLOBALS[__FUNCTION__])) {
2164                 // Determine it
2165                 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2166         } // END - if
2167
2168         // Return cache
2169         return $GLOBALS[__FUNCTION__];
2170 }
2171
2172 // "Getter" for max_send
2173 function getMaxSend () {
2174         // Do we have cache?
2175         if (!isset($GLOBALS[__FUNCTION__])) {
2176                 // Determine it
2177                 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2178         } // END - if
2179
2180         // Return cache
2181         return $GLOBALS[__FUNCTION__];
2182 }
2183
2184 // "Getter" for mails_page
2185 function getMailsPage () {
2186         // Do we have cache?
2187         if (!isset($GLOBALS[__FUNCTION__])) {
2188                 // Determine it
2189                 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2190         } // END - if
2191
2192         // Return cache
2193         return $GLOBALS[__FUNCTION__];
2194 }
2195
2196 // "Getter" for rand_no
2197 function getRandNo () {
2198         // Do we have cache?
2199         if (!isset($GLOBALS[__FUNCTION__])) {
2200                 // Determine it
2201                 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2202         } // END - if
2203
2204         // Return cache
2205         return $GLOBALS[__FUNCTION__];
2206 }
2207
2208 // "Getter" for __DB_NAME
2209 function getDbName () {
2210         // Do we have cache?
2211         if (!isset($GLOBALS[__FUNCTION__])) {
2212                 // Determine it
2213                 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2214         } // END - if
2215
2216         // Return cache
2217         return $GLOBALS[__FUNCTION__];
2218 }
2219
2220 // "Getter" for DOMAIN
2221 function getDomain () {
2222         // Do we have cache?
2223         if (!isset($GLOBALS[__FUNCTION__])) {
2224                 // Determine it
2225                 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2226         } // END - if
2227
2228         // Return cache
2229         return $GLOBALS[__FUNCTION__];
2230 }
2231
2232 // "Getter" for proxy_username
2233 function getProxyUsername () {
2234         // Do we have cache?
2235         if (!isset($GLOBALS[__FUNCTION__])) {
2236                 // Determine it
2237                 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2238         } // END - if
2239
2240         // Return cache
2241         return $GLOBALS[__FUNCTION__];
2242 }
2243
2244 // "Getter" for proxy_password
2245 function getProxyPassword () {
2246         // Do we have cache?
2247         if (!isset($GLOBALS[__FUNCTION__])) {
2248                 // Determine it
2249                 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2250         } // END - if
2251
2252         // Return cache
2253         return $GLOBALS[__FUNCTION__];
2254 }
2255
2256 // "Getter" for proxy_host
2257 function getProxyHost () {
2258         // Do we have cache?
2259         if (!isset($GLOBALS[__FUNCTION__])) {
2260                 // Determine it
2261                 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2262         } // END - if
2263
2264         // Return cache
2265         return $GLOBALS[__FUNCTION__];
2266 }
2267
2268 // "Getter" for proxy_port
2269 function getProxyPort () {
2270         // Do we have cache?
2271         if (!isset($GLOBALS[__FUNCTION__])) {
2272                 // Determine it
2273                 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2274         } // END - if
2275
2276         // Return cache
2277         return $GLOBALS[__FUNCTION__];
2278 }
2279
2280 // "Getter" for SMTP_HOSTNAME
2281 function getSmtpHostname () {
2282         // Do we have cache?
2283         if (!isset($GLOBALS[__FUNCTION__])) {
2284                 // Determine it
2285                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2286         } // END - if
2287
2288         // Return cache
2289         return $GLOBALS[__FUNCTION__];
2290 }
2291
2292 // "Getter" for SMTP_USER
2293 function getSmtpUser () {
2294         // Do we have cache?
2295         if (!isset($GLOBALS[__FUNCTION__])) {
2296                 // Determine it
2297                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2298         } // END - if
2299
2300         // Return cache
2301         return $GLOBALS[__FUNCTION__];
2302 }
2303
2304 // "Getter" for SMTP_PASSWORD
2305 function getSmtpPassword () {
2306         // Do we have cache?
2307         if (!isset($GLOBALS[__FUNCTION__])) {
2308                 // Determine it
2309                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2310         } // END - if
2311
2312         // Return cache
2313         return $GLOBALS[__FUNCTION__];
2314 }
2315
2316 // "Getter" for points_word
2317 function getPointsWord () {
2318         // Do we have cache?
2319         if (!isset($GLOBALS[__FUNCTION__])) {
2320                 // Determine it
2321                 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2322         } // END - if
2323
2324         // Return cache
2325         return $GLOBALS[__FUNCTION__];
2326 }
2327
2328 // "Getter" for profile_lock
2329 function getProfileLock () {
2330         // Do we have cache?
2331         if (!isset($GLOBALS[__FUNCTION__])) {
2332                 // Determine it
2333                 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2334         } // END - if
2335
2336         // Return cache
2337         return $GLOBALS[__FUNCTION__];
2338 }
2339
2340 // "Getter" for url_tlock
2341 function getUrlTlock () {
2342         // Do we have cache?
2343         if (!isset($GLOBALS[__FUNCTION__])) {
2344                 // Determine it
2345                 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2346         } // END - if
2347
2348         // Return cache
2349         return $GLOBALS[__FUNCTION__];
2350 }
2351
2352 // "Getter" for title_left
2353 function getTitleLeft () {
2354         // Do we have cache?
2355         if (!isset($GLOBALS[__FUNCTION__])) {
2356                 // Determine it
2357                 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2358         } // END - if
2359
2360         // Return cache
2361         return $GLOBALS[__FUNCTION__];
2362 }
2363
2364 // "Getter" for title_right
2365 function getTitleRight () {
2366         // Do we have cache?
2367         if (!isset($GLOBALS[__FUNCTION__])) {
2368                 // Determine it
2369                 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2370         } // END - if
2371
2372         // Return cache
2373         return $GLOBALS[__FUNCTION__];
2374 }
2375
2376 // "Getter" for title_middle
2377 function getTitleMiddle () {
2378         // Do we have cache?
2379         if (!isset($GLOBALS[__FUNCTION__])) {
2380                 // Determine it
2381                 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2382         } // END - if
2383
2384         // Return cache
2385         return $GLOBALS[__FUNCTION__];
2386 }
2387
2388 // Getter for 'check_double_email'
2389 function getCheckDoubleEmail () {
2390         // Is the cache entry set?
2391         if (!isset($GLOBALS[__FUNCTION__])) {
2392                 // No, so determine it
2393                 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2394         } // END - if
2395
2396         // Return cached entry
2397         return $GLOBALS[__FUNCTION__];
2398 }
2399
2400 // Checks wether 'check_double_email' is 'Y'
2401 function isCheckDoubleEmailEnabled () {
2402         // Is the cache entry set?
2403         if (!isset($GLOBALS[__FUNCTION__])) {
2404                 // No, so determine it
2405                 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2406         } // END - if
2407
2408         // Return cached entry
2409         return $GLOBALS[__FUNCTION__];
2410 }
2411
2412 // Getter for 'display_home_in_index'
2413 function getDisplayHomeInIndex () {
2414         // Is the cache entry set?
2415         if (!isset($GLOBALS[__FUNCTION__])) {
2416                 // No, so determine it
2417                 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2418         } // END - if
2419
2420         // Return cached entry
2421         return $GLOBALS[__FUNCTION__];
2422 }
2423
2424 // Checks wether 'display_home_in_index' is 'Y'
2425 function isDisplayHomeInIndexEnabled () {
2426         // Is the cache entry set?
2427         if (!isset($GLOBALS[__FUNCTION__])) {
2428                 // No, so determine it
2429                 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2430         } // END - if
2431
2432         // Return cached entry
2433         return $GLOBALS[__FUNCTION__];
2434 }
2435
2436 // Getter for 'admin_menu_javascript'
2437 function getAdminMenuJavascript () {
2438         // Is the cache entry set?
2439         if (!isset($GLOBALS[__FUNCTION__])) {
2440                 // No, so determine it
2441                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2442         } // END - if
2443
2444         // Return cached entry
2445         return $GLOBALS[__FUNCTION__];
2446 }
2447
2448 // Checks wether proxy configuration is used
2449 function isProxyUsed () {
2450         // Do we have cache?
2451         if (!isset($GLOBALS[__FUNCTION__])) {
2452                 // Determine it
2453                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2454         } // END - if
2455
2456         // Return cache
2457         return $GLOBALS[__FUNCTION__];
2458 }
2459
2460 // Checks wether POST data contains selections
2461 function ifPostContainsSelections ($element = 'sel') {
2462         // Do we have cache?
2463         if (!isset($GLOBALS[__FUNCTION__][$element])) {
2464                 // Determine it
2465                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (countPostSelection($element) > 0));
2466         } // END - if
2467
2468         // Return cache
2469         return $GLOBALS[__FUNCTION__][$element];
2470 }
2471
2472 // Checks wether verbose_sql is Y and returns true/false if so
2473 function isVerboseSqlEnabled () {
2474         // Do we have cache?
2475         if (!isset($GLOBALS[__FUNCTION__])) {
2476                 // Determine it
2477                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2478         } // END - if
2479
2480         // Return cache
2481         return $GLOBALS[__FUNCTION__];
2482 }
2483
2484 // "Getter" for total user points
2485 function getTotalPoints ($userid) {
2486         // Do we have cache?
2487         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2488                 // Init array for filter chain
2489                 $data = array(
2490                         'userid' => $userid,
2491                         'points' => 0
2492                 );
2493
2494                 // Run filter chain for getting more point values
2495                 $data = runFilterChain('get_total_points', $data);
2496
2497                 // Determine it
2498                 $GLOBALS[__FUNCTION__][$userid] = $data['points']  - countSumTotalData($userid, 'user_data', 'used_points');
2499         } // END - if
2500
2501         // Return cache
2502         return $GLOBALS[__FUNCTION__][$userid];
2503 }
2504
2505 // Wrapper to check if url_blacklist is enabled
2506 function isUrlBlacklistEnabled () {
2507         // Do we have cache?
2508         if (!isset($GLOBALS[__FUNCTION__])) {
2509                 // Determine it
2510                 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2511         } // END - if
2512
2513         // Return cache
2514         return $GLOBALS[__FUNCTION__];
2515 }
2516
2517 // Checks wether direct payment is allowed in configuration
2518 function isDirectPaymentEnabled () {
2519         // Do we have cache?
2520         if (!isset($GLOBALS[__FUNCTION__])) {
2521                 // Determine it
2522                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2523         } // END - if
2524
2525         // Return cache
2526         return $GLOBALS[__FUNCTION__];
2527 }
2528
2529 // Checks wether JavaScript-based admin menu is enabled
2530 function isAdminMenuJavascriptEnabled () {
2531         // Do we have cache?
2532         if (!isset($GLOBALS[__FUNCTION__])) {
2533                 // Determine it
2534                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getConfig('admin_menu_javascript') == 'Y'));
2535         } // END - if
2536
2537         // Return cache
2538         return $GLOBALS[__FUNCTION__];
2539 }
2540
2541 // Wrapper to check if current task is for extension (not update)
2542 function isExtensionTask ($content) {
2543         // Do we have cache?
2544         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2545                 // Determine it
2546                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2547         } // END - if
2548
2549         // Return cache
2550         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2551 }
2552
2553 // Wrapper to check if output mode is CSS
2554 function isCssOutputMode () {
2555         // Determine it
2556         return (getScriptOutputMode() == 1);
2557 }
2558
2559 // Wrapper to check if output mode is HTML
2560 function isHtmlOutputMode () {
2561         // Determine it
2562         return (getScriptOutputMode() == 0);
2563 }
2564
2565 // Wrapper to check if output mode is RAW
2566 function isRawOutputMode () {
2567         // Determine it
2568         return (getScriptOutputMode() == -1);
2569 }
2570
2571 // Wrapper to check if output mode is AJAX
2572 function isAjaxOutputMode () {
2573         // Determine it
2574         return (getScriptOutputMode() == -2);
2575 }
2576
2577 // Wrapper to check if output mode is image
2578 function isImageOutputMode () {
2579         // Determine it
2580         return (getScriptOutputMode() == -3);
2581 }
2582
2583 // Wrapper to generate a user email link
2584 function generateWrappedUserEmailLink ($email) {
2585         // Just call the inner function
2586         return generateEmailLink($email, 'user_data');
2587 }
2588
2589 // Wrapper to check if user points are locked
2590 function ifUserPointsLocked ($userid) {
2591         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2592         // Do we have cache?
2593         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2594                 // Determine it
2595                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2596         } // END - if
2597
2598         // Return cache
2599         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2600         return $GLOBALS[__FUNCTION__][$userid];
2601 }
2602
2603 // Appends a line to an existing file or creates it instantly with given content.
2604 // This function does always add a new-line character to every line.
2605 function appendLineToFile ($file, $line) {
2606         $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2607         fwrite($fp, $line . "\n");
2608         fclose($fp);
2609 }
2610
2611 // Wrapper for changeDataInFile() but with full path added
2612 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2613         // Add full path
2614         $FQFN = getPath() . $FQFN;
2615
2616         // Call inner function
2617         return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2618 }
2619
2620 // Wrapper for changing entries in config-local.php
2621 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2622         // Call the inner function
2623         return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2624 }
2625
2626 // Shortens ucfirst(strtolower()) calls
2627 function firstCharUpperCase ($str) {
2628         return ucfirst(strtolower($str));
2629 }
2630
2631 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2632 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2633         // Get the configuration entry
2634         $configValue = getConfig($configEntry);
2635
2636         // Call inner method
2637         return createTimeSelections($configValue, $configEntry, $stamps, $align);
2638 }
2639
2640 // Shortens converting of German comma to Computer's version in POST data
2641 function convertCommaToDotInPostData ($postEntry) {
2642         // Read and convert given entry
2643         $postValue = convertCommaToDot(postRequestElement($postEntry));
2644
2645         // ... and set it again
2646         setPostRequestElement($postEntry, $postValue);
2647 }
2648
2649 // Converts German commas to Computer's version in all entries
2650 function convertCommaToDotInPostDataArray ($postEntries) {
2651         // Replace german decimal comma with computer decimal dot
2652         foreach ($postEntries as $entry) {
2653                 // Is the entry there?
2654                 if (isPostRequestElementSet($entry)) {
2655                         // Then convert it
2656                         convertCommaToDotInPostData($entry);
2657                 } // END - if
2658         } // END - foreach
2659 }
2660
2661 /**
2662  * Parses a string into a US formated float variable, taken from user comments
2663  * from PHP documentation website.
2664  *
2665  * @param       $floatString    A string holding a float expression
2666  * @return      $float                  Corresponding float variable
2667  * @author      chris<at>georgakopoulos<dot>com
2668  * @link        http://de.php.net/manual/en/function.floatval.php#92563
2669  */
2670 function parseFloat ($floatString){
2671         // Load locale info
2672         $LocaleInfo = localeconv();
2673
2674         // Remove thousand separators
2675         $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
2676
2677         // Convert decimal point
2678         $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2679
2680         // Return float value of converted string
2681         return floatval($floatString);
2682 }
2683
2684 // Generates a YES/NO option list from given default
2685 function generateYesNoOptionList ($defaultValue = '') {
2686         // Generate it
2687         return generateOptionList('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2688 }
2689
2690 // "Getter" for total available receivers
2691 function getTotalReceivers ($mode = 'normal') {
2692         // Get num rows
2693         $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode));
2694
2695         // Return value
2696         return $numRows;
2697 }
2698
2699 // Wrapper "getter" to get total unconfirmed mails for given userid
2700 function getTotalUnconfirmedMails ($userid) {
2701         // Do we have cache?
2702         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2703                 // Determine it
2704                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
2705         } // END - if
2706
2707         // Return cache
2708         return $GLOBALS[__FUNCTION__][$userid];
2709 }
2710
2711 // Checks wether 'mailer_theme' was found in session
2712 function isMailerThemeSet () {
2713         // Check session
2714         return isSessionVariableSet('mailer_theme');
2715 }
2716
2717 /**
2718  * Setter for theme in session (This setter does return the success of
2719  * setSession() which is required e.g. for destroySponsorSession().
2720  */
2721 function setMailerTheme ($newTheme) {
2722         // Set it in session
2723         return setSession('mailer_theme', $newTheme);
2724 }
2725
2726 /**
2727  * Getter for theme from session (This getter does return 'mailer_theme' from
2728  * session data or throws an error if not possible
2729  */
2730 function getMailerTheme () {
2731         // Is 'mailer_theme' set?
2732         if (!isMailerThemeSet()) {
2733                 // No, then abort here
2734                 debug_report_bug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2735         } // END - if
2736
2737         // Return the theme from session
2738         return getSession('mailer_theme');
2739 }
2740
2741 // [EOF]
2742 ?>