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