A lot more wrapper functions introduced, TODOs.txt updated
[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, 2010 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 remote IP number
198 function detectRemoteAddr () {
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 hostname
213 function detectRemoteHostname () {
214         // Get remote ip from environment
215         $remoteHost = getenv('REMOTE_HOST');
216
217         // Is removeip installed?
218         if (isExtensionActive('removeip')) {
219                 // Then anonymize it
220                 $remoteHost = getAnonymousRemoteHost($remoteHost);
221         } // END - if
222
223         // Return it
224         return $remoteHost;
225 }
226
227 // "Getter" for user agent
228 function detectUserAgent ($alwaysReal = false) {
229         // Get remote ip from environment
230         $userAgent = getenv('HTTP_USER_AGENT');
231
232         // Is removeip installed?
233         if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
234                 // Then anonymize it
235                 $userAgent = getAnonymousUserAgent($userAgent);
236         } // END - if
237
238         // Return it
239         return $userAgent;
240 }
241
242 // "Getter" for referer
243 function detectReferer () {
244         // Get remote ip from environment
245         $referer = getenv('HTTP_REFERER');
246
247         // Is removeip installed?
248         if (isExtensionActive('removeip')) {
249                 // Then anonymize it
250                 $referer = getAnonymousReferer($referer);
251         } // END - if
252
253         // Return it
254         return $referer;
255 }
256
257 // "Getter" for request URI
258 function detectRequestUri () {
259         // Return it
260         return (getenv('REQUEST_URI'));
261 }
262
263 // "Getter" for query string
264 function detectQueryString () {
265         return str_replace('&', '&amp;', (getenv('QUERY_STRING')));
266 }
267
268 // "Getter" for SERVER_NAME
269 function detectServerName () {
270         // Return it
271         return (getenv('SERVER_NAME'));
272 }
273
274 // Check wether we are installing
275 function isInstalling () {
276         // Determine wether we are installing
277         if (!isset($GLOBALS['mailer_installing'])) {
278                 // Check URL (css.php/js.php need this)
279                 $GLOBALS['mailer_installing'] = isGetRequestParameterSet('installing');
280         } // END - if
281
282         // Return result
283         return $GLOBALS['mailer_installing'];
284 }
285
286 // Check wether this script is installed
287 function isInstalled () {
288         // Do we have cache?
289         if (!isset($GLOBALS[__FUNCTION__])) {
290                 // Determine wether this script is installed
291                 $GLOBALS[__FUNCTION__] = (
292                 (
293                         // First is config
294                         (
295                                 (
296                                         isConfigEntrySet('MXCHANGE_INSTALLED')
297                                 ) && (
298                                         getConfig('MXCHANGE_INSTALLED') == 'Y'
299                                 )
300                         )
301                 ) || (
302                         // New config file found and loaded
303                         isIncludeReadable(getCachePath() . 'config-local.php')
304                 ) || (
305                         (
306                                 // New config file found, but not yet read
307                                 isIncludeReadable(getCachePath() . 'config-local.php')
308                         ) && (
309                                 (
310                                         // Only new config file is found
311                                         !isIncludeReadable('inc/config.php')
312                                 ) || (
313                                         // Is installation mode
314                                         !isInstalling()
315                                 )
316                         )
317                 ));
318         } // END - if
319
320         // Then use the cache
321         return $GLOBALS[__FUNCTION__];
322 }
323
324 // Check wether an admin is registered
325 function isAdminRegistered () {
326         // Is cache set?
327         if (!isset($GLOBALS[__FUNCTION__])) {
328                 // Simply check it
329                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
330         } // END - if
331
332         // Return it
333         return $GLOBALS[__FUNCTION__];
334 }
335
336 // Checks wether the reset mode is active
337 function isResetModeEnabled () {
338         // Now simply check it
339         return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
340 }
341
342 // Checks wether the debug mode is enabled
343 function isDebugModeEnabled () {
344         // Is cache set?
345         if (!isset($GLOBALS[__FUNCTION__])) {
346                 // Simply check it
347                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
348         } // END - if
349
350         // Return it
351         return $GLOBALS[__FUNCTION__];
352 }
353
354 // Checks wether SQL debugging is enabled
355 function isSqlDebuggingEnabled () {
356         // Is cache set?
357         if (!isset($GLOBALS[__FUNCTION__])) {
358                 // Determine if SQL debugging is enabled
359                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
360         } // END - if
361
362         // Return it
363         return $GLOBALS[__FUNCTION__];
364 }
365
366 // Checks wether we shall debug regular expressions
367 function isDebugRegularExpressionEnabled () {
368         // Is cache set?
369         if (!isset($GLOBALS[__FUNCTION__])) {
370                 // Simply check it
371                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
372         } // END - if
373
374         // Return it
375         return $GLOBALS[__FUNCTION__];
376 }
377
378 // Checks wether the cache instance is valid
379 function isCacheInstanceValid () {
380         return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
381 }
382
383 // Copies a file from source to destination and verifies if that goes fine.
384 // This function should wrap the copy() command and make a nicer debug backtrace
385 // even if there is no xdebug extension installed.
386 function copyFileVerified ($source, $dest, $chmod = '') {
387         // Failed is the default
388         $status = false;
389
390         // Is the source file there?
391         if (!isFileReadable($source)) {
392                 // Then abort here
393                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
394         } // END - if
395
396         // Is the target directory there?
397         if (!isDirectory(dirname($dest))) {
398                 // Then abort here
399                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
400         } // END - if
401
402         // Now try to copy it
403         if (!copy($source, $dest)) {
404                 // Something went wrong
405                 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
406         } else {
407                 // Reset cache
408                 $GLOBALS['file_readable'][$dest] = true;
409         }
410
411         // If there are chmod rights set, apply them
412         if (!empty($chmod)) {
413                 // Try to apply them
414                 $status = changeMode($dest, $chmod);
415         } else {
416                 // All fine
417                 $status = true;
418         }
419
420         // All fine
421         return $status;
422 }
423
424 // Wrapper function for header()
425 // Send a header but checks before if we can do so
426 function sendHeader ($header) {
427         // Send the header
428         //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header);
429         $GLOBALS['header'][] = trim($header);
430 }
431
432 // Flushes all headers
433 function flushHeaders () {
434         // Is the header already sent?
435         if (headers_sent()) {
436                 // Then abort here
437                 debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!');
438         } // END - if
439
440         // Flush all headers if found
441         if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) {
442                 foreach ($GLOBALS['header'] as $header) {
443                         header($header);
444                 } // END - foreach
445         } // END - if
446
447         // Mark them as flushed
448         $GLOBALS['header'] = array();
449 }
450
451 // Wrapper function for chmod()
452 // @TODO Do some more sanity check here
453 function changeMode ($FQFN, $mode) {
454         // Is the file/directory there?
455         if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
456                 // Neither, so abort here
457                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
458         } // END - if
459
460         // Try to set them
461         return chmod($FQFN, $mode);
462 }
463
464 // Wrapper for unlink()
465 function removeFile ($FQFN) {
466         // Is the file there?
467         if (isFileReadable($FQFN)) {
468                 // Reset cache first
469                 $GLOBALS['file_readable'][$FQFN] = false;
470
471                 // Yes, so remove it
472                 return unlink($FQFN);
473         } // END - if
474
475         // All fine if no file was removed. If we change this to 'false' or rewrite
476         // above if() block it would be to restrictive.
477         return true;
478 }
479
480 // Wrapper for $_POST['sel']
481 function countPostSelection ($element = 'sel') {
482         // Is it set?
483         if (isPostRequestParameterSet($element)) {
484                 // Return counted elements
485                 return countSelection(postRequestParameter($element));
486         } else {
487                 // Return zero if not found
488                 return 0;
489         }
490 }
491
492 // Checks wether the config-local.php is loaded
493 function isConfigLocalLoaded () {
494         return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
495 }
496
497 // Checks wether a nickname or userid was entered and caches the result
498 function isNicknameUsed ($userid) {
499         // Is the cache there
500         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
501                 // Determine it
502                 $GLOBALS[__FUNCTION__][$userid] = (('' . round($userid) . '') != $userid);
503         } // END - if
504
505         // Return the result
506         return $GLOBALS[__FUNCTION__][$userid];
507 }
508
509 // Getter for 'what' value
510 function getWhat () {
511         // Default is null
512         $what = null;
513
514         // Is the value set?
515         if (isWhatSet(true)) {
516                 // Then use it
517                 $what = $GLOBALS['what'];
518         } // END - if
519
520         // Return it
521         return $what;
522 }
523
524 // Setter for 'what' value
525 function setWhat ($newWhat) {
526         $GLOBALS['what'] = SQL_ESCAPE($newWhat);
527 }
528
529 // Setter for 'what' from configuration
530 function setWhatFromConfig ($configEntry) {
531         // Get 'what' from config
532         $what = getConfig($configEntry);
533
534         // Set it
535         setWhat($what);
536 }
537
538 // Checks wether what is set and optionally aborts on miss
539 function isWhatSet ($strict =  false) {
540         // Check for it
541         $isset = isset($GLOBALS['what']);
542
543         // Should we abort here?
544         if (($strict === true) && ($isset === false)) {
545                 // Output backtrace
546                 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
547         } // END - if
548
549         // Return it
550         return $isset;
551 }
552
553 // Getter for 'action' value
554 function getAction ($strict = true) {
555         // Default is null
556         $action = null;
557
558         // Is the value set?
559         if (isActionSet(($strict) && (isHtmlOutputMode()))) {
560                 // Then use it
561                 $action = $GLOBALS['action'];
562         } // END - if
563
564         // Return it
565         return $action;
566 }
567
568 // Setter for 'action' value
569 function setAction ($newAction) {
570         $GLOBALS['action'] = SQL_ESCAPE($newAction);
571 }
572
573 // Checks wether action is set and optionally aborts on miss
574 function isActionSet ($strict =  false) {
575         // Check for it
576         $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action'])));
577
578         // Should we abort here?
579         if (($strict === true) && ($isset === false)) {
580                 // Output backtrace
581                 debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.');
582         } // END - if
583
584         // Return it
585         return $isset;
586 }
587
588 // Getter for 'module' value
589 function getModule ($strict = true) {
590         // Default is null
591         $module = null;
592
593         // Is the value set?
594         if (isModuleSet($strict)) {
595                 // Then use it
596                 $module = $GLOBALS['module'];
597         } // END - if
598
599         // Return it
600         return $module;
601 }
602
603 // Setter for 'module' value
604 function setModule ($newModule) {
605         // Secure it and make all modules lower-case
606         $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
607 }
608
609 // Checks wether module is set and optionally aborts on miss
610 function isModuleSet ($strict =  false) {
611         // Check for it
612         $isset = (!empty($GLOBALS['module']));
613
614         // Should we abort here?
615         if (($strict === true) && ($isset === false)) {
616                 // Output backtrace
617                 debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.');
618         } // END - if
619
620         // Return it
621         return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
622 }
623
624 // Getter for 'output_mode' value
625 function getScriptOutputMode () {
626         // Default is null
627         $output_mode = null;
628
629         // Is the value set?
630         if (isOutputModeSet(true)) {
631                 // Then use it
632                 $output_mode = $GLOBALS['output_mode'];
633         } // END - if
634
635         // Return it
636         return $output_mode;
637 }
638
639 // Setter for 'output_mode' value
640 function setOutputMode ($newOutputMode) {
641         $GLOBALS['output_mode'] = (int) $newOutputMode;
642 }
643
644 // Checks wether output_mode is set and optionally aborts on miss
645 function isOutputModeSet ($strict =  false) {
646         // Check for it
647         $isset = (isset($GLOBALS['output_mode']));
648
649         // Should we abort here?
650         if (($strict === true) && ($isset === false)) {
651                 // Output backtrace
652                 debug_report_bug(__FUNCTION__, __LINE__, 'Output_mode is empty.');
653         } // END - if
654
655         // Return it
656         return $isset;
657 }
658
659 // Enables block-mode
660 function enableBlockMode ($enabled = true) {
661         $GLOBALS['block_mode'] = $enabled;
662 }
663
664 // Checks wether block-mode is enabled
665 function isBlockModeEnabled () {
666         // Abort if not set
667         if (!isset($GLOBALS['block_mode'])) {
668                 // Needs to be fixed
669                 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
670         } // END - if
671
672         // Return it
673         return $GLOBALS['block_mode'];
674 }
675
676 // Wrapper function for addPointsThroughReferalSystem()
677 function addPointsDirectly ($subject, $userid, $points) {
678         // Reset level here
679         unset($GLOBALS['ref_level']);
680
681         // Call more complicated method (due to more parameters)
682         return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'direct');
683 }
684
685 // Wrapper for redirectToUrl but URL comes from a configuration entry
686 function redirectToConfiguredUrl ($configEntry) {
687         // Load the URL
688         redirectToUrl(getConfig($configEntry));
689 }
690
691 // Wrapper function to redirect from member-only modules to index
692 function redirectToIndexMemberOnlyModule () {
693         // Do the redirect here
694         redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
695 }
696
697 // Wrapper function to redirect to current URL
698 function redirectToRequestUri () {
699         redirectToUrl(basename(detectRequestUri()));
700 }
701
702 // Wrapper function to redirect to de-refered URL
703 function redirectToDereferedUrl ($URL) {
704         // Redirect to to
705         redirectToUrl(generateDerefererUrl($URL));
706 }
707
708 // Wrapper function for checking if extension is installed and newer or same version
709 function isExtensionInstalledAndNewer ($ext_name, $version) {
710         // Is an cache entry found?
711         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
712                 // Determine it
713                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
714         } else {
715                 // Cache hits should be incremented twice
716                 incrementStatsEntry('cache_hits', 2);
717         }
718
719         // Return it
720         //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'=&gt;'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
721         return $GLOBALS[__FUNCTION__][$ext_name][$version];
722 }
723
724 // Wrapper function for checking if extension is installed and older than given version
725 function isExtensionInstalledAndOlder ($ext_name, $version) {
726         // Is an cache entry found?
727         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
728                 // Determine it
729                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
730         } else {
731                 // Cache hits should be incremented twice
732                 incrementStatsEntry('cache_hits', 2);
733         }
734
735         // Return it
736         //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'&lt;'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
737         return $GLOBALS[__FUNCTION__][$ext_name][$version];
738 }
739
740 // Set username
741 function setUsername ($userName) {
742         $GLOBALS['username'] = (string) $userName;
743 }
744
745 // Get username
746 function getUsername () {
747         // User name set?
748         if (!isset($GLOBALS['username'])) {
749                 // No, so it has to be a guest
750                 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
751         } // END - if
752
753         // Return it
754         return $GLOBALS['username'];
755 }
756
757 // Wrapper function for installation phase
758 function isInstallationPhase () {
759         // Do we have cache?
760         if (!isset($GLOBALS[__FUNCTION__])) {
761                 // Determine it
762                 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
763         } // END - if
764
765         // Return result
766         return $GLOBALS[__FUNCTION__];
767 }
768
769 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
770 function isDemoModeActive () {
771         // Is cache set?
772         if (!isset($GLOBALS[__FUNCTION__])) {
773                 // Simply check it
774                 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getAdminLogin(getSession('admin_id')) == 'demo'));
775         } // END - if
776
777         // Return it
778         return $GLOBALS[__FUNCTION__];
779 }
780
781 // Getter for PHP caching value
782 function getPhpCaching () {
783         return $GLOBALS['php_caching'];
784 }
785
786 // Checks wether the admin hash is set
787 function isAdminHashSet ($adminId) {
788         // Is the array there?
789         if (!isset($GLOBALS['cache_array']['admin'])) {
790                 // Missing array should be reported
791                 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
792         } // END - if
793
794         // Check for admin hash
795         return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
796 }
797
798 // Setter for admin hash
799 function setAdminHash ($adminId, $hash) {
800         $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
801 }
802
803 // Init user data array
804 function initUserData () {
805         // User id should not be zero
806         if (!isValidUserId(getCurrentUserId())) {
807                 // Should be always valid
808                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
809         } // END - if
810
811         // Init the user
812         $GLOBALS['user_data'][getCurrentUserId()] = array();
813 }
814
815 // Getter for user data
816 function getUserData ($column) {
817         // User id should not be zero
818         if (!isValidUserId(getCurrentUserId())) {
819                 // Should be always valid
820                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
821         } // END - if
822
823         // Return the value
824         return $GLOBALS['user_data'][getCurrentUserId()][$column];
825 }
826
827 // Geter for whole user data array
828 function getUserDataArray () {
829         // Get user id
830         $userid = getCurrentUserId();
831
832         // Is the current userid valid?
833         if (!isValidUserId($userid)) {
834                 // Should be always valid
835                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
836         } // END - if
837
838         // Get the whole array if found
839         if (isset($GLOBALS['user_data'][$userid])) {
840                 // Found, so return it
841                 return $GLOBALS['user_data'][$userid];
842         } else {
843                 // Return empty array
844                 return array();
845         }
846 }
847
848 // Checks if the user data is valid, this may indicate that the user has logged
849 // in, but you should use isMember() if you want to find that out.
850 function isUserDataValid () {
851         // User id should not be zero so abort here
852         if (!isCurrentUserIdSet()) return false;
853
854         // Is it cached?
855         if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
856                 // Determine it
857                 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
858         } // END - if
859
860         // Return the result
861         return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
862 }
863
864 // Setter for current userid
865 function setCurrentUserId ($userid) {
866         // Set userid
867         $GLOBALS['current_userid'] = bigintval($userid);
868
869         // Unset it to re-determine the actual state
870         unset($GLOBALS['is_userdata_valid'][$userid]);
871 }
872
873 // Getter for current userid
874 function getCurrentUserId () {
875         // Userid must be set before it can be used
876         if (!isCurrentUserIdSet()) {
877                 // Not set
878                 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
879         } // END - if
880
881         // Return the userid
882         return $GLOBALS['current_userid'];
883 }
884
885 // Checks if current userid is set
886 function isCurrentUserIdSet () {
887         return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
888 }
889
890 // Checks wether we are debugging template cache
891 function isDebuggingTemplateCache () {
892         // Do we have cache?
893         if (!isset($GLOBALS[__FUNCTION__])) {
894                 // Determine it
895                 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
896         } // END - if
897
898         // Return cache
899         return $GLOBALS[__FUNCTION__];
900 }
901
902 // Wrapper for fetchUserData() and getUserData() calls
903 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
904         // Is it cached?
905         if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
906                 // Default is 'guest'
907                 $data = '{--USERNAME_GUEST--}';
908
909                 // Can we fetch the user data?
910                 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
911                         // Now get the data back
912                         $data = getUserData($valueColumn);
913                 } // END - if
914
915                 // Cache it
916                 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
917         } // END - if
918
919         // Return it
920         return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
921 }
922
923 // Wrapper for strpos() to ease porting from deprecated ereg() function
924 function isInString ($needle, $haystack) {
925         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
926         return (strpos($haystack, $needle) !== false);
927 }
928
929 // Wrapper for strpos() to ease porting from deprecated eregi() function
930 // This function is case-insensitive
931 function isInStringIgnoreCase ($needle, $haystack) {
932         return (isInString(strtolower($needle), strtolower($haystack)));
933 }
934
935 // Wrapper to check for if fatal errors where detected
936 function ifFatalErrorsDetected () {
937         // Just call the inner function
938         return (getTotalFatalErrors() > 0);
939 }
940
941 // Setter for HTTP status
942 function setHttpStatus ($status) {
943         $GLOBALS['http_status'] = (string) $status;
944 }
945
946 // Getter for HTTP status
947 function getHttpStatus () {
948         // Is the status set?
949         if (!isset($GLOBALS['http_status'])) {
950                 // Abort here
951                 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
952         } // END - if
953
954         // Return it
955         return $GLOBALS['http_status'];
956 }
957
958 /**
959  * Send a HTTP redirect to the browser. This function was taken from DokuWiki
960  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
961  *
962  * ----------------------------------------------------------------------------
963  * If you want to redirect, please use redirectToUrl(); instead
964  * ----------------------------------------------------------------------------
965  *
966  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
967  *
968  * @link    http://support.microsoft.com/kb/q176113/
969  * @author  Andreas Gohr <andi@splitbrain.org>
970  * @access  private
971  */
972 function sendRawRedirect ($url) {
973         // Send helping header
974         setHttpStatus('302 Found');
975
976         // always close the session
977         session_write_close();
978
979         // Revert entity &amp;
980         $url = str_replace('&amp;', '&', $url);
981
982         // check if running on IIS < 6 with CGI-PHP
983         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
984                 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
985                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
986                 ($matches[1] < 6)) {
987                 // Send the IIS header
988                 sendHeader('Refresh: 0;url=' . $url);
989         } else {
990                 // Send generic header
991                 sendHeader('Location: ' . $url);
992         }
993
994         // Shutdown here
995         shutdown();
996 }
997
998 // Determines the country of the given user id
999 function determineCountry ($userid) {
1000         // Do we have cache?
1001         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1002                 // Default is 'invalid'
1003                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1004
1005                 // Is extension country active?
1006                 if (isExtensionActive('country')) {
1007                         // Determine the right country code through the country id
1008                         $id = getUserData('country_code');
1009
1010                         // Then handle it over
1011                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1012                 } else {
1013                         // Get raw code from user data
1014                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1015                 }
1016         } // END - if
1017
1018         // Return cache
1019         return $GLOBALS[__FUNCTION__][$userid];
1020 }
1021
1022 // "Getter" for total confirmed user accounts
1023 function getTotalConfirmedUser () {
1024         // Is it cached?
1025         if (!isset($GLOBALS[__FUNCTION__])) {
1026                 // Then do it
1027                 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1028         } // END - if
1029
1030         // Return cached value
1031         return $GLOBALS[__FUNCTION__];
1032 }
1033
1034 // "Getter" for total unconfirmed user accounts
1035 function getTotalUnconfirmedUser () {
1036         // Is it cached?
1037         if (!isset($GLOBALS[__FUNCTION__])) {
1038                 // Then do it
1039                 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1040         } // END - if
1041
1042         // Return cached value
1043         return $GLOBALS[__FUNCTION__];
1044 }
1045
1046 // "Getter" for total locked user accounts
1047 function getTotalLockedUser () {
1048         // Is it cached?
1049         if (!isset($GLOBALS[__FUNCTION__])) {
1050                 // Then do it
1051                 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1052         } // END - if
1053
1054         // Return cached value
1055         return $GLOBALS[__FUNCTION__];
1056 }
1057
1058 // Is given userid valid?
1059 function isValidUserId ($userid) {
1060         // Do we have cache?
1061         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1062                 // Check it out
1063                 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1064         } // END - if
1065
1066         // Return cache
1067         return $GLOBALS[__FUNCTION__][$userid];
1068 }
1069
1070 // Encodes entities
1071 function encodeEntities ($str) {
1072         // Secure it first
1073         $str = secureString($str, true, true);
1074
1075         // Encode dollar sign as well
1076         $str = str_replace('$', '&#36;', $str);
1077
1078         // Return it
1079         return $str;
1080 }
1081
1082 // "Getter" for date from patch_ctime
1083 function getDateFromPatchTime () {
1084         // Is it cached?
1085         if (!isset($GLOBALS[__FUNCTION__])) {
1086                 // Then set it
1087                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1088         } // END - if
1089
1090         // Return cache
1091         return $GLOBALS[__FUNCTION__];
1092 }
1093
1094 // Getter for current year (default)
1095 function getYear ($timestamp = null) {
1096         // Is it cached?
1097         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1098                 // null is time()
1099                 if (is_null($timestamp)) $timestamp = time();
1100
1101                 // Then create it
1102                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1103         } // END - if
1104
1105         // Return cache
1106         return $GLOBALS[__FUNCTION__][$timestamp];
1107 }
1108
1109 // Getter for current month (default)
1110 function getMonth ($timestamp = null) {
1111         // Is it cached?
1112         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1113                 // If null is set, use time()
1114                 if (is_null($timestamp)) {
1115                         // Use time() which is current timestamp
1116                         $timestamp = time();
1117                 } // END - if
1118
1119                 // Then create it
1120                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1121         } // END - if
1122
1123         // Return cache
1124         return $GLOBALS[__FUNCTION__][$timestamp];
1125 }
1126
1127 // Getter for current day (default)
1128 function getDay ($timestamp = null) {
1129         // Is it cached?
1130         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1131                 // null is time()
1132                 if (is_null($timestamp)) $timestamp = time();
1133
1134                 // Then create it
1135                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1136         } // END - if
1137
1138         // Return cache
1139         return $GLOBALS[__FUNCTION__][$timestamp];
1140 }
1141
1142 // Getter for current week (default)
1143 function getWeek ($timestamp = null) {
1144         // Is it cached?
1145         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1146                 // null is time()
1147                 if (is_null($timestamp)) $timestamp = time();
1148
1149                 // Then create it
1150                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1151         } // END - if
1152
1153         // Return cache
1154         return $GLOBALS[__FUNCTION__][$timestamp];
1155 }
1156
1157 // Getter for current short_hour (default)
1158 function getShortHour ($timestamp = null) {
1159         // Is it cached?
1160         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1161                 // null is time()
1162                 if (is_null($timestamp)) $timestamp = time();
1163
1164                 // Then create it
1165                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1166         } // END - if
1167
1168         // Return cache
1169         return $GLOBALS[__FUNCTION__][$timestamp];
1170 }
1171
1172 // Getter for current long_hour (default)
1173 function getLongHour ($timestamp = null) {
1174         // Is it cached?
1175         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1176                 // null is time()
1177                 if (is_null($timestamp)) $timestamp = time();
1178
1179                 // Then create it
1180                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1181         } // END - if
1182
1183         // Return cache
1184         return $GLOBALS[__FUNCTION__][$timestamp];
1185 }
1186
1187 // Getter for current second (default)
1188 function getSecond ($timestamp = null) {
1189         // Is it cached?
1190         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1191                 // null is time()
1192                 if (is_null($timestamp)) $timestamp = time();
1193
1194                 // Then create it
1195                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1196         } // END - if
1197
1198         // Return cache
1199         return $GLOBALS[__FUNCTION__][$timestamp];
1200 }
1201
1202 // Getter for current minute (default)
1203 function getMinute ($timestamp = null) {
1204         // Is it cached?
1205         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1206                 // null is time()
1207                 if (is_null($timestamp)) $timestamp = time();
1208
1209                 // Then create it
1210                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1211         } // END - if
1212
1213         // Return cache
1214         return $GLOBALS[__FUNCTION__][$timestamp];
1215 }
1216
1217 // Checks wether the title decoration is enabled
1218 function isTitleDecorationEnabled () {
1219         // Do we have cache?
1220         if (!isset($GLOBALS[__FUNCTION__])) {
1221                 // Just check it
1222                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1223         } // END - if
1224
1225         // Return cache
1226         return $GLOBALS[__FUNCTION__];
1227 }
1228
1229 // Checks wether filter usage updates are enabled (expensive queries!)
1230 function isFilterUsageUpdateEnabled () {
1231         // Do we have cache?
1232         if (!isset($GLOBALS[__FUNCTION__])) {
1233                 // Determine it
1234                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1235         } // END - if
1236
1237         // Return cache
1238         return $GLOBALS[__FUNCTION__];
1239 }
1240
1241 // Checks wether debugging of weekly resets is enabled
1242 function isWeeklyResetDebugEnabled () {
1243         // Do we have cache?
1244         if (!isset($GLOBALS[__FUNCTION__])) {
1245                 // Determine it
1246                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1247         } // END - if
1248
1249         // Return cache
1250         return $GLOBALS[__FUNCTION__];
1251 }
1252
1253 // Checks wether debugging of monthly resets is enabled
1254 function isMonthlyResetDebugEnabled () {
1255         // Do we have cache?
1256         if (!isset($GLOBALS[__FUNCTION__])) {
1257                 // Determine it
1258                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1259         } // END - if
1260
1261         // Return cache
1262         return $GLOBALS[__FUNCTION__];
1263 }
1264
1265 // Checks wether displaying of debug SQLs are enabled
1266 function isDisplayDebugSqlEnabled () {
1267         // Do we have cache?
1268         if (!isset($GLOBALS[__FUNCTION__])) {
1269                 // Determine it
1270                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1271         } // END - if
1272
1273         // Return cache
1274         return $GLOBALS[__FUNCTION__];
1275 }
1276
1277 // Checks wether module title is enabled
1278 function isModuleTitleEnabled () {
1279         // Do we have cache?
1280         if (!isset($GLOBALS[__FUNCTION__])) {
1281                 // Determine it
1282                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1283         } // END - if
1284
1285         // Return cache
1286         return $GLOBALS[__FUNCTION__];
1287 }
1288
1289 // Checks wether what title is enabled
1290 function isWhatTitleEnabled () {
1291         // Do we have cache?
1292         if (!isset($GLOBALS[__FUNCTION__])) {
1293                 // Determine it
1294                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1295         } // END - if
1296
1297         // Return cache
1298         return $GLOBALS[__FUNCTION__];
1299 }
1300
1301 // Checks wether stats are enabled
1302 function ifStatsAreEnabled () {
1303         // Do we have cache?
1304         if (!isset($GLOBALS[__FUNCTION__])) {
1305                 // Then determine it
1306                 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1307         } // END - if
1308
1309         // Return cached value
1310         return $GLOBALS[__FUNCTION__];
1311 }
1312
1313 // Checks wether admin-notification of certain user actions is enabled
1314 function isAdminNotificationEnabled () {
1315         // Do we have cache?
1316         if (!isset($GLOBALS[__FUNCTION__])) {
1317                 // Determine it
1318                 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1319         } // END - if
1320
1321         // Return cache
1322         return $GLOBALS[__FUNCTION__];
1323 }
1324
1325 // Checks wether random referal id selection is enabled
1326 function isRandomReferalIdEnabled () {
1327         // Do we have cache?
1328         if (!isset($GLOBALS[__FUNCTION__])) {
1329                 // Determine it
1330                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1331         } // END - if
1332
1333         // Return cache
1334         return $GLOBALS[__FUNCTION__];
1335 }
1336
1337 // "Getter" for default language
1338 function getDefaultLanguage () {
1339         // Do we have cache?
1340         if (!isset($GLOBALS[__FUNCTION__])) {
1341                 // Determine it
1342                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1343         } // END - if
1344
1345         // Return cache
1346         return $GLOBALS[__FUNCTION__];
1347 }
1348
1349 // "Getter" for default referal id
1350 function getDefRefid () {
1351         // Do we have cache?
1352         if (!isset($GLOBALS[__FUNCTION__])) {
1353                 // Determine it
1354                 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1355         } // END - if
1356
1357         // Return cache
1358         return $GLOBALS[__FUNCTION__];
1359 }
1360
1361 // "Getter" for path
1362 function getPath () {
1363         // Do we have cache?
1364         if (!isset($GLOBALS[__FUNCTION__])) {
1365                 // Determine it
1366                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1367         } // END - if
1368
1369         // Return cache
1370         return $GLOBALS[__FUNCTION__];
1371 }
1372
1373 // "Getter" for url
1374 function getUrl () {
1375         // Do we have cache?
1376         if (!isset($GLOBALS[__FUNCTION__])) {
1377                 // Determine it
1378                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1379         } // END - if
1380
1381         // Return cache
1382         return $GLOBALS[__FUNCTION__];
1383 }
1384
1385 // "Getter" for cache_path
1386 function getCachePath () {
1387         // Do we have cache?
1388         if (!isset($GLOBALS[__FUNCTION__])) {
1389                 // Determine it
1390                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1391         } // END - if
1392
1393         // Return cache
1394         return $GLOBALS[__FUNCTION__];
1395 }
1396
1397 // "Getter" for secret_key
1398 function getSecretKey () {
1399         // Do we have cache?
1400         if (!isset($GLOBALS[__FUNCTION__])) {
1401                 // Determine it
1402                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1403         } // END - if
1404
1405         // Return cache
1406         return $GLOBALS[__FUNCTION__];
1407 }
1408
1409 // "Getter" for master_salt
1410 function getMasterSalt () {
1411         // Do we have cache?
1412         if (!isset($GLOBALS[__FUNCTION__])) {
1413                 // Determine it
1414                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1415         } // END - if
1416
1417         // Return cache
1418         return $GLOBALS[__FUNCTION__];
1419 }
1420
1421 // "Getter" for prime
1422 function getPrime () {
1423         // Do we have cache?
1424         if (!isset($GLOBALS[__FUNCTION__])) {
1425                 // Determine it
1426                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1427         } // END - if
1428
1429         // Return cache
1430         return $GLOBALS[__FUNCTION__];
1431 }
1432
1433 // "Getter" for encrypt_seperator
1434 function getEncryptSeperator () {
1435         // Do we have cache?
1436         if (!isset($GLOBALS[__FUNCTION__])) {
1437                 // Determine it
1438                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1439         } // END - if
1440
1441         // Return cache
1442         return $GLOBALS[__FUNCTION__];
1443 }
1444
1445 // "Getter" for mysql_prefix
1446 function getMysqlPrefix () {
1447         // Do we have cache?
1448         if (!isset($GLOBALS[__FUNCTION__])) {
1449                 // Determine it
1450                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1451         } // END - if
1452
1453         // Return cache
1454         return $GLOBALS[__FUNCTION__];
1455 }
1456
1457 // "Getter" for table_type
1458 function getTableType () {
1459         // Do we have cache?
1460         if (!isset($GLOBALS[__FUNCTION__])) {
1461                 // Determine it
1462                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1463         } // END - if
1464
1465         // Return cache
1466         return $GLOBALS[__FUNCTION__];
1467 }
1468
1469 // "Getter" for salt_length
1470 function getSaltLength () {
1471         // Do we have cache?
1472         if (!isset($GLOBALS[__FUNCTION__])) {
1473                 // Determine it
1474                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1475         } // END - if
1476
1477         // Return cache
1478         return $GLOBALS[__FUNCTION__];
1479 }
1480
1481 // "Getter" for output_mode
1482 function getOutputMode () {
1483         // Do we have cache?
1484         if (!isset($GLOBALS[__FUNCTION__])) {
1485                 // Determine it
1486                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1487         } // END - if
1488
1489         // Return cache
1490         return $GLOBALS[__FUNCTION__];
1491 }
1492
1493 // "Getter" for full_version
1494 function getFullVersion () {
1495         // Do we have cache?
1496         if (!isset($GLOBALS[__FUNCTION__])) {
1497                 // Determine it
1498                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1499         } // END - if
1500
1501         // Return cache
1502         return $GLOBALS[__FUNCTION__];
1503 }
1504
1505 // "Getter" for title
1506 function getTitle () {
1507         // Do we have cache?
1508         if (!isset($GLOBALS[__FUNCTION__])) {
1509                 // Determine it
1510                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1511         } // END - if
1512
1513         // Return cache
1514         return $GLOBALS[__FUNCTION__];
1515 }
1516
1517 // "Getter" for curr_svn_revision
1518 function getCurrentRepositoryRevision () {
1519         // Do we have cache?
1520         if (!isset($GLOBALS[__FUNCTION__])) {
1521                 // Determine it
1522                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1523         } // END - if
1524
1525         // Return cache
1526         return $GLOBALS[__FUNCTION__];
1527 }
1528
1529 // "Getter" for server_url
1530 function getServerUrl () {
1531         // Do we have cache?
1532         if (!isset($GLOBALS[__FUNCTION__])) {
1533                 // Determine it
1534                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1535         } // END - if
1536
1537         // Return cache
1538         return $GLOBALS[__FUNCTION__];
1539 }
1540
1541 // "Getter" for mt_word
1542 function getMtWord () {
1543         // Do we have cache?
1544         if (!isset($GLOBALS[__FUNCTION__])) {
1545                 // Determine it
1546                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1547         } // END - if
1548
1549         // Return cache
1550         return $GLOBALS[__FUNCTION__];
1551 }
1552
1553 // "Getter" for mt_word2
1554 function getMtWord2 () {
1555         // Do we have cache?
1556         if (!isset($GLOBALS[__FUNCTION__])) {
1557                 // Determine it
1558                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1559         } // END - if
1560
1561         // Return cache
1562         return $GLOBALS[__FUNCTION__];
1563 }
1564
1565 // "Getter" for main_title
1566 function getMainTitle () {
1567         // Do we have cache?
1568         if (!isset($GLOBALS[__FUNCTION__])) {
1569                 // Determine it
1570                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1571         } // END - if
1572
1573         // Return cache
1574         return $GLOBALS[__FUNCTION__];
1575 }
1576
1577 // "Getter" for file_hash
1578 function getFileHash () {
1579         // Do we have cache?
1580         if (!isset($GLOBALS[__FUNCTION__])) {
1581                 // Determine it
1582                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1583         } // END - if
1584
1585         // Return cache
1586         return $GLOBALS[__FUNCTION__];
1587 }
1588
1589 // "Getter" for pass_scramble
1590 function getPassScramble () {
1591         // Do we have cache?
1592         if (!isset($GLOBALS[__FUNCTION__])) {
1593                 // Determine it
1594                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1595         } // END - if
1596
1597         // Return cache
1598         return $GLOBALS[__FUNCTION__];
1599 }
1600
1601 // "Getter" for ap_inactive_since
1602 function getApInactiveSince () {
1603         // Do we have cache?
1604         if (!isset($GLOBALS[__FUNCTION__])) {
1605                 // Determine it
1606                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1607         } // END - if
1608
1609         // Return cache
1610         return $GLOBALS[__FUNCTION__];
1611 }
1612
1613 // "Getter" for user_min_confirmed
1614 function getUserMinConfirmed () {
1615         // Do we have cache?
1616         if (!isset($GLOBALS[__FUNCTION__])) {
1617                 // Determine it
1618                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1619         } // END - if
1620
1621         // Return cache
1622         return $GLOBALS[__FUNCTION__];
1623 }
1624
1625 // "Getter" for auto_purge
1626 function getAutoPurge () {
1627         // Do we have cache?
1628         if (!isset($GLOBALS[__FUNCTION__])) {
1629                 // Determine it
1630                 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1631         } // END - if
1632
1633         // Return cache
1634         return $GLOBALS[__FUNCTION__];
1635 }
1636
1637 // "Getter" for bonus_userid
1638 function getBonusUserid () {
1639         // Do we have cache?
1640         if (!isset($GLOBALS[__FUNCTION__])) {
1641                 // Determine it
1642                 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1643         } // END - if
1644
1645         // Return cache
1646         return $GLOBALS[__FUNCTION__];
1647 }
1648
1649 // "Getter" for ap_inactive_time
1650 function getApInactiveTime () {
1651         // Do we have cache?
1652         if (!isset($GLOBALS[__FUNCTION__])) {
1653                 // Determine it
1654                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1655         } // END - if
1656
1657         // Return cache
1658         return $GLOBALS[__FUNCTION__];
1659 }
1660
1661 // "Getter" for ap_dm_timeout
1662 function getApDmTimeout () {
1663         // Do we have cache?
1664         if (!isset($GLOBALS[__FUNCTION__])) {
1665                 // Determine it
1666                 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1667         } // END - if
1668
1669         // Return cache
1670         return $GLOBALS[__FUNCTION__];
1671 }
1672
1673 // "Getter" for ap_tasks_time
1674 function getApTasksTime () {
1675         // Do we have cache?
1676         if (!isset($GLOBALS[__FUNCTION__])) {
1677                 // Determine it
1678                 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1679         } // END - if
1680
1681         // Return cache
1682         return $GLOBALS[__FUNCTION__];
1683 }
1684
1685 // "Getter" for ap_unconfirmed_time
1686 function getApUnconfirmedTime () {
1687         // Do we have cache?
1688         if (!isset($GLOBALS[__FUNCTION__])) {
1689                 // Determine it
1690                 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1691         } // END - if
1692
1693         // Return cache
1694         return $GLOBALS[__FUNCTION__];
1695 }
1696
1697 // "Getter" for points
1698 function getPoints () {
1699         // Do we have cache?
1700         if (!isset($GLOBALS[__FUNCTION__])) {
1701                 // Determine it
1702                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1703         } // END - if
1704
1705         // Return cache
1706         return $GLOBALS[__FUNCTION__];
1707 }
1708
1709 // "Getter" for slogan
1710 function getSlogan () {
1711         // Do we have cache?
1712         if (!isset($GLOBALS[__FUNCTION__])) {
1713                 // Determine it
1714                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1715         } // END - if
1716
1717         // Return cache
1718         return $GLOBALS[__FUNCTION__];
1719 }
1720
1721 // "Getter" for copy
1722 function getCopy () {
1723         // Do we have cache?
1724         if (!isset($GLOBALS[__FUNCTION__])) {
1725                 // Determine it
1726                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1727         } // END - if
1728
1729         // Return cache
1730         return $GLOBALS[__FUNCTION__];
1731 }
1732
1733 // "Getter" for webmaster
1734 function getWebmaster () {
1735         // Do we have cache?
1736         if (!isset($GLOBALS[__FUNCTION__])) {
1737                 // Determine it
1738                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1739         } // END - if
1740
1741         // Return cache
1742         return $GLOBALS[__FUNCTION__];
1743 }
1744
1745 // "Getter" for sql_count
1746 function getSqlCount () {
1747         // Do we have cache?
1748         if (!isset($GLOBALS[__FUNCTION__])) {
1749                 // Determine it
1750                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1751         } // END - if
1752
1753         // Return cache
1754         return $GLOBALS[__FUNCTION__];
1755 }
1756
1757 // "Getter" for num_templates
1758 function getNumTemplates () {
1759         // Do we have cache?
1760         if (!isset($GLOBALS[__FUNCTION__])) {
1761                 // Determine it
1762                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1763         } // END - if
1764
1765         // Return cache
1766         return $GLOBALS[__FUNCTION__];
1767 }
1768
1769 // "Getter" for dns_cache_timeout
1770 function getDnsCacheTimeout () {
1771         // Do we have cache?
1772         if (!isset($GLOBALS[__FUNCTION__])) {
1773                 // Determine it
1774                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1775         } // END - if
1776
1777         // Return cache
1778         return $GLOBALS[__FUNCTION__];
1779 }
1780
1781 // "Getter" for menu_blur_spacer
1782 function getMenuBlurSpacer () {
1783         // Do we have cache?
1784         if (!isset($GLOBALS[__FUNCTION__])) {
1785                 // Determine it
1786                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
1787         } // END - if
1788
1789         // Return cache
1790         return $GLOBALS[__FUNCTION__];
1791 }
1792
1793 // "Getter" for points_register
1794 function getPointsRegister () {
1795         // Do we have cache?
1796         if (!isset($GLOBALS[__FUNCTION__])) {
1797                 // Determine it
1798                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
1799         } // END - if
1800
1801         // Return cache
1802         return $GLOBALS[__FUNCTION__];
1803 }
1804
1805 // "Getter" for points_ref
1806 function getPointsRef () {
1807         // Do we have cache?
1808         if (!isset($GLOBALS[__FUNCTION__])) {
1809                 // Determine it
1810                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
1811         } // END - if
1812
1813         // Return cache
1814         return $GLOBALS[__FUNCTION__];
1815 }
1816
1817 // "Getter" for ref_payout
1818 function getRefPayout () {
1819         // Do we have cache?
1820         if (!isset($GLOBALS[__FUNCTION__])) {
1821                 // Determine it
1822                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
1823         } // END - if
1824
1825         // Return cache
1826         return $GLOBALS[__FUNCTION__];
1827 }
1828
1829 // "Getter" for online_timeout
1830 function getOnlineTimeout () {
1831         // Do we have cache?
1832         if (!isset($GLOBALS[__FUNCTION__])) {
1833                 // Determine it
1834                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
1835         } // END - if
1836
1837         // Return cache
1838         return $GLOBALS[__FUNCTION__];
1839 }
1840
1841 // "Getter" for index_home
1842 function getIndexHome () {
1843         // Do we have cache?
1844         if (!isset($GLOBALS[__FUNCTION__])) {
1845                 // Determine it
1846                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
1847         } // END - if
1848
1849         // Return cache
1850         return $GLOBALS[__FUNCTION__];
1851 }
1852
1853 // "Getter" for one_day
1854 function getOneDay () {
1855         // Do we have cache?
1856         if (!isset($GLOBALS[__FUNCTION__])) {
1857                 // Determine it
1858                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
1859         } // END - if
1860
1861         // Return cache
1862         return $GLOBALS[__FUNCTION__];
1863 }
1864
1865 // "Getter" for activate_xchange
1866 function getActivateXchange () {
1867         // Do we have cache?
1868         if (!isset($GLOBALS[__FUNCTION__])) {
1869                 // Determine it
1870                 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
1871         } // END - if
1872
1873         // Return cache
1874         return $GLOBALS[__FUNCTION__];
1875 }
1876
1877 // "Getter" for img_type
1878 function getImgType () {
1879         // Do we have cache?
1880         if (!isset($GLOBALS[__FUNCTION__])) {
1881                 // Determine it
1882                 $GLOBALS[__FUNCTION__] = getConfig('img_type');
1883         } // END - if
1884
1885         // Return cache
1886         return $GLOBALS[__FUNCTION__];
1887 }
1888
1889 // "Getter" for code_length
1890 function getCodeLength () {
1891         // Do we have cache?
1892         if (!isset($GLOBALS[__FUNCTION__])) {
1893                 // Determine it
1894                 $GLOBALS[__FUNCTION__] = getConfig('code_length');
1895         } // END - if
1896
1897         // Return cache
1898         return $GLOBALS[__FUNCTION__];
1899 }
1900
1901 // "Getter" for least_cats
1902 function getLeastCats () {
1903         // Do we have cache?
1904         if (!isset($GLOBALS[__FUNCTION__])) {
1905                 // Determine it
1906                 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
1907         } // END - if
1908
1909         // Return cache
1910         return $GLOBALS[__FUNCTION__];
1911 }
1912
1913 // "Getter" for pass_len
1914 function getPassLen () {
1915         // Do we have cache?
1916         if (!isset($GLOBALS[__FUNCTION__])) {
1917                 // Determine it
1918                 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
1919         } // END - if
1920
1921         // Return cache
1922         return $GLOBALS[__FUNCTION__];
1923 }
1924
1925 // "Getter" for admin_menu
1926 function getAdminMenu () {
1927         // Do we have cache?
1928         if (!isset($GLOBALS[__FUNCTION__])) {
1929                 // Determine it
1930                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
1931         } // END - if
1932
1933         // Return cache
1934         return $GLOBALS[__FUNCTION__];
1935 }
1936
1937 // "Getter" for last_month
1938 function getLastMonth () {
1939         // Do we have cache?
1940         if (!isset($GLOBALS[__FUNCTION__])) {
1941                 // Determine it
1942                 $GLOBALS[__FUNCTION__] = getConfig('last_month');
1943         } // END - if
1944
1945         // Return cache
1946         return $GLOBALS[__FUNCTION__];
1947 }
1948
1949 // "Getter" for __DB_NAME
1950 function getDbName () {
1951         // Do we have cache?
1952         if (!isset($GLOBALS[__FUNCTION__])) {
1953                 // Determine it
1954                 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
1955         } // END - if
1956
1957         // Return cache
1958         return $GLOBALS[__FUNCTION__];
1959 }
1960
1961 // Checks wether proxy configuration is used
1962 function isProxyUsed () {
1963         // Do we have cache?
1964         if (!isset($GLOBALS[__FUNCTION__])) {
1965                 // Determine it
1966                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
1967         } // END - if
1968
1969         // Return cache
1970         return $GLOBALS[__FUNCTION__];
1971 }
1972
1973 // Checks wether POST data contains selections
1974 function ifPostContainsSelections ($element = 'sel') {
1975         // Do we have cache?
1976         if (!isset($GLOBALS[__FUNCTION__][$element])) {
1977                 // Determine it
1978                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
1979         } // END - if
1980
1981         // Return cache
1982         return $GLOBALS[__FUNCTION__][$element];
1983 }
1984
1985 // Checks wether verbose_sql is Y and returns true/false if so
1986 function isVerboseSqlEnabled () {
1987         // Do we have cache?
1988         if (!isset($GLOBALS[__FUNCTION__])) {
1989                 // Determine it
1990                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
1991         } // END - if
1992
1993         // Return cache
1994         return $GLOBALS[__FUNCTION__];
1995 }
1996
1997 // "Getter" for total user points
1998 function getTotalPoints ($userid) {
1999         // Do we have cache?
2000         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2001                 // Determine it
2002                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points');
2003         } // END - if
2004
2005         // Return cache
2006         return $GLOBALS[__FUNCTION__][$userid];
2007 }
2008
2009 // Wrapper to check if url_blacklist is enabled
2010 function isUrlBlacklistEnabled () {
2011         // Do we have cache?
2012         if (!isset($GLOBALS[__FUNCTION__])) {
2013                 // Determine it
2014                 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2015         } // END - if
2016
2017         // Return cache
2018         return $GLOBALS[__FUNCTION__];
2019 }
2020
2021 // Checks wether direct payment is allowed in configuration
2022 function isDirectPaymentEnabled () {
2023         // Do we have cache?
2024         if (!isset($GLOBALS[__FUNCTION__])) {
2025                 // Determine it
2026                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2027         } // END - if
2028
2029         // Return cache
2030         return $GLOBALS[__FUNCTION__];
2031 }
2032
2033 // Wrapper to check if current task is for extension (not update)
2034 function isExtensionTask ($content) {
2035         // Do we have cache?
2036         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2037                 // Determine it
2038                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2039         } // END - if
2040
2041         // Return cache
2042         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2043 }
2044
2045 // Wrapper to check if output mode is CSS
2046 function isCssOutputMode () {
2047         // Determine it
2048         return (getScriptOutputMode() == 1);
2049 }
2050
2051 // Wrapper to check if output mode is HTML
2052 function isHtmlOutputMode () {
2053         // Determine it
2054         return (getScriptOutputMode() == 0);
2055 }
2056
2057 // Wrapper to check if output mode is RAW
2058 function isRawOutputMode () {
2059         // Determine it
2060         return (getScriptOutputMode() == -1);
2061 }
2062
2063 // Wrapper to generate a user email link
2064 function generateWrappedUserEmailLink ($email) {
2065         // Just call the inner function
2066         return generateEmailLink($email, 'user_data');
2067 }
2068
2069 // Wrapper to check if user points are locked
2070 function ifUserPointsLocked ($userid) {
2071         // Do we have cache?
2072         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2073                 // Determine it
2074                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2075         } // END - if
2076
2077         // Return cache
2078         return $GLOBALS[__FUNCTION__][$userid];
2079 }
2080
2081 // Appends a line to an existing file or creates it instantly with given content.
2082 // This function does always add a new-line character to every line.
2083 function appendLineToFile ($file, $line) {
2084         $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2085         fwrite($fp, $line . "\n");
2086         fclose($fp);
2087 }
2088
2089 // [EOF]
2090 ?>