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