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