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