b42874ee8a035d540729ff09ce03c050585be84d
[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         return $GLOBALS['http_status'];
949 }
950
951 /**
952  * Send a HTTP redirect to the browser. This function was taken from DokuWiki
953  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
954  *
955  * ----------------------------------------------------------------------------
956  * If you want to redirect, please use redirectToUrl(); instead
957  * ----------------------------------------------------------------------------
958  *
959  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
960  *
961  * @link    http://support.microsoft.com/kb/q176113/
962  * @author  Andreas Gohr <andi@splitbrain.org>
963  * @access  private
964  */
965 function sendRawRedirect ($url) {
966         // Send helping header
967         setHttpStatus('302 Found');
968
969         // always close the session
970         session_write_close();
971
972         // Revert entity &amp;
973         $url = str_replace('&amp;', '&', $url);
974
975         // check if running on IIS < 6 with CGI-PHP
976         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
977                 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
978                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
979                 ($matches[1] < 6)) {
980                 // Send the IIS header
981                 sendHeader('Refresh: 0;url=' . $url);
982         } else {
983                 // Send generic header
984                 sendHeader('Location: ' . $url);
985         }
986
987         // Shutdown here
988         shutdown();
989 }
990
991 // Determines the country of the given user id
992 function determineCountry ($userid) {
993         // Do we have cache?
994         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
995                 // Default is 'invalid'
996                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
997
998                 // Is extension country active?
999                 if (isExtensionActive('country')) {
1000                         // Determine the right country code through the country id
1001                         $id = getUserData('country_code');
1002
1003                         // Then handle it over
1004                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1005                 } else {
1006                         // Get raw code from user data
1007                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1008                 }
1009         } // END - if
1010
1011         // Return cache
1012         return $GLOBALS[__FUNCTION__][$userid];
1013 }
1014
1015 // "Getter" for total confirmed user accounts
1016 function getTotalConfirmedUser () {
1017         // Is it cached?
1018         if (!isset($GLOBALS[__FUNCTION__])) {
1019                 // Then do it
1020                 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1021         } // END - if
1022
1023         // Return cached value
1024         return $GLOBALS[__FUNCTION__];
1025 }
1026
1027 // "Getter" for total unconfirmed user accounts
1028 function getTotalUnconfirmedUser () {
1029         // Is it cached?
1030         if (!isset($GLOBALS[__FUNCTION__])) {
1031                 // Then do it
1032                 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1033         } // END - if
1034
1035         // Return cached value
1036         return $GLOBALS[__FUNCTION__];
1037 }
1038
1039 // "Getter" for total locked user accounts
1040 function getTotalLockedUser () {
1041         // Is it cached?
1042         if (!isset($GLOBALS[__FUNCTION__])) {
1043                 // Then do it
1044                 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1045         } // END - if
1046
1047         // Return cached value
1048         return $GLOBALS[__FUNCTION__];
1049 }
1050
1051 // Is given userid valid?
1052 function isValidUserId ($userid) {
1053         // Do we have cache?
1054         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1055                 // Check it out
1056                 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1057         } // END - if
1058
1059         // Return cache
1060         return $GLOBALS[__FUNCTION__][$userid];
1061 }
1062
1063 // Encodes entities
1064 function encodeEntities ($str) {
1065         // Secure it first
1066         $str = secureString($str, true, true);
1067
1068         // Encode dollar sign as well
1069         $str = str_replace('$', '&#36;', $str);
1070
1071         // Return it
1072         return $str;
1073 }
1074
1075 // "Getter" for date from patch_ctime
1076 function getDateFromPatchTime () {
1077         // Is it cached?
1078         if (!isset($GLOBALS[__FUNCTION__])) {
1079                 // Then set it
1080                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1081         } // END - if
1082
1083         // Return cache
1084         return $GLOBALS[__FUNCTION__];
1085 }
1086
1087 // Getter for current year (default)
1088 function getYear ($timestamp = null) {
1089         // Is it cached?
1090         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1091                 // null is time()
1092                 if (is_null($timestamp)) $timestamp = time();
1093
1094                 // Then create it
1095                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1096         } // END - if
1097
1098         // Return cache
1099         return $GLOBALS[__FUNCTION__][$timestamp];
1100 }
1101
1102 // Getter for current month (default)
1103 function getMonth ($timestamp = null) {
1104         // Is it cached?
1105         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1106                 // null is time()
1107                 if (is_null($timestamp)) $timestamp = time();
1108
1109                 // Then create it
1110                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1111         } // END - if
1112
1113         // Return cache
1114         return $GLOBALS[__FUNCTION__][$timestamp];
1115 }
1116
1117 // Getter for current day (default)
1118 function getDay ($timestamp = null) {
1119         // Is it cached?
1120         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1121                 // null is time()
1122                 if (is_null($timestamp)) $timestamp = time();
1123
1124                 // Then create it
1125                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1126         } // END - if
1127
1128         // Return cache
1129         return $GLOBALS[__FUNCTION__][$timestamp];
1130 }
1131
1132 // Getter for current week (default)
1133 function getWeek ($timestamp = null) {
1134         // Is it cached?
1135         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1136                 // null is time()
1137                 if (is_null($timestamp)) $timestamp = time();
1138
1139                 // Then create it
1140                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1141         } // END - if
1142
1143         // Return cache
1144         return $GLOBALS[__FUNCTION__][$timestamp];
1145 }
1146
1147 // Getter for current short_hour (default)
1148 function getShortHour ($timestamp = null) {
1149         // Is it cached?
1150         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1151                 // null is time()
1152                 if (is_null($timestamp)) $timestamp = time();
1153
1154                 // Then create it
1155                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1156         } // END - if
1157
1158         // Return cache
1159         return $GLOBALS[__FUNCTION__][$timestamp];
1160 }
1161
1162 // Getter for current long_hour (default)
1163 function getLongHour ($timestamp = null) {
1164         // Is it cached?
1165         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1166                 // null is time()
1167                 if (is_null($timestamp)) $timestamp = time();
1168
1169                 // Then create it
1170                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1171         } // END - if
1172
1173         // Return cache
1174         return $GLOBALS[__FUNCTION__][$timestamp];
1175 }
1176
1177 // Getter for current second (default)
1178 function getSecond ($timestamp = null) {
1179         // Is it cached?
1180         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1181                 // null is time()
1182                 if (is_null($timestamp)) $timestamp = time();
1183
1184                 // Then create it
1185                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1186         } // END - if
1187
1188         // Return cache
1189         return $GLOBALS[__FUNCTION__][$timestamp];
1190 }
1191
1192 // Getter for current minute (default)
1193 function getMinute ($timestamp = null) {
1194         // Is it cached?
1195         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1196                 // null is time()
1197                 if (is_null($timestamp)) $timestamp = time();
1198
1199                 // Then create it
1200                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1201         } // END - if
1202
1203         // Return cache
1204         return $GLOBALS[__FUNCTION__][$timestamp];
1205 }
1206
1207 // Checks wether the title decoration is enabled
1208 function isTitleDecorationEnabled () {
1209         // Do we have cache?
1210         if (!isset($GLOBALS[__FUNCTION__])) {
1211                 // Just check it
1212                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1213         } // END - if
1214
1215         // Return cache
1216         return $GLOBALS[__FUNCTION__];
1217 }
1218
1219 // Checks wether filter usage updates are enabled (expensive queries!)
1220 function isFilterUsageUpdateEnabled () {
1221         // Do we have cache?
1222         if (!isset($GLOBALS[__FUNCTION__])) {
1223                 // Determine it
1224                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1225         } // END - if
1226
1227         // Return cache
1228         return $GLOBALS[__FUNCTION__];
1229 }
1230
1231 // Checks wether debugging of weekly resets is enabled
1232 function isWeeklyResetDebugEnabled () {
1233         // Do we have cache?
1234         if (!isset($GLOBALS[__FUNCTION__])) {
1235                 // Determine it
1236                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1237         } // END - if
1238
1239         // Return cache
1240         return $GLOBALS[__FUNCTION__];
1241 }
1242
1243 // Checks wether debugging of monthly resets is enabled
1244 function isMonthlyResetDebugEnabled () {
1245         // Do we have cache?
1246         if (!isset($GLOBALS[__FUNCTION__])) {
1247                 // Determine it
1248                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1249         } // END - if
1250
1251         // Return cache
1252         return $GLOBALS[__FUNCTION__];
1253 }
1254
1255 // Checks wether displaying of debug SQLs are enabled
1256 function isDisplayDebugSqlEnabled () {
1257         // Do we have cache?
1258         if (!isset($GLOBALS[__FUNCTION__])) {
1259                 // Determine it
1260                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1261         } // END - if
1262
1263         // Return cache
1264         return $GLOBALS[__FUNCTION__];
1265 }
1266
1267 // Checks wether module title is enabled
1268 function isModuleTitleEnabled () {
1269         // Do we have cache?
1270         if (!isset($GLOBALS[__FUNCTION__])) {
1271                 // Determine it
1272                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1273         } // END - if
1274
1275         // Return cache
1276         return $GLOBALS[__FUNCTION__];
1277 }
1278
1279 // Checks wether what title is enabled
1280 function isWhatTitleEnabled () {
1281         // Do we have cache?
1282         if (!isset($GLOBALS[__FUNCTION__])) {
1283                 // Determine it
1284                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1285         } // END - if
1286
1287         // Return cache
1288         return $GLOBALS[__FUNCTION__];
1289 }
1290
1291 // Checks wether stats are enabled
1292 function ifStatsAreEnabled () {
1293         // Do we have cache?
1294         if (!isset($GLOBALS[__FUNCTION__])) {
1295                 // Then determine it
1296                 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1297         } // END - if
1298
1299         // Return cached value
1300         return $GLOBALS[__FUNCTION__];
1301 }
1302
1303 // Checks wether admin-notification of certain user actions is enabled
1304 function isAdminNotificationEnabled () {
1305         // Do we have cache?
1306         if (!isset($GLOBALS[__FUNCTION__])) {
1307                 // Determine it
1308                 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1309         } // END - if
1310
1311         // Return cache
1312         return $GLOBALS[__FUNCTION__];
1313 }
1314
1315 // Checks wether random referal id selection is enabled
1316 function isRandomReferalIdEnabled () {
1317         // Do we have cache?
1318         if (!isset($GLOBALS[__FUNCTION__])) {
1319                 // Determine it
1320                 $GLOBALS[__FUNCTION__] = (getConfig('select_user_zero_refid') == 'Y');
1321         } // END - if
1322
1323         // Return cache
1324         return $GLOBALS[__FUNCTION__];
1325 }
1326
1327 // "Getter" for default language
1328 function getDefaultLanguage () {
1329         // Do we have cache?
1330         if (!isset($GLOBALS[__FUNCTION__])) {
1331                 // Determine it
1332                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1333         } // END - if
1334
1335         // Return cache
1336         return $GLOBALS[__FUNCTION__];
1337 }
1338
1339 // "Getter" for path
1340 function getPath () {
1341         // Do we have cache?
1342         if (!isset($GLOBALS[__FUNCTION__])) {
1343                 // Determine it
1344                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1345         } // END - if
1346
1347         // Return cache
1348         return $GLOBALS[__FUNCTION__];
1349 }
1350
1351 // "Getter" for url
1352 function getUrl () {
1353         // Do we have cache?
1354         if (!isset($GLOBALS[__FUNCTION__])) {
1355                 // Determine it
1356                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1357         } // END - if
1358
1359         // Return cache
1360         return $GLOBALS[__FUNCTION__];
1361 }
1362
1363 // "Getter" for cache_path
1364 function getCachePath () {
1365         // Do we have cache?
1366         if (!isset($GLOBALS[__FUNCTION__])) {
1367                 // Determine it
1368                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1369         } // END - if
1370
1371         // Return cache
1372         return $GLOBALS[__FUNCTION__];
1373 }
1374
1375 // "Getter" for secret_key
1376 function getSecretKey () {
1377         // Do we have cache?
1378         if (!isset($GLOBALS[__FUNCTION__])) {
1379                 // Determine it
1380                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1381         } // END - if
1382
1383         // Return cache
1384         return $GLOBALS[__FUNCTION__];
1385 }
1386
1387 // "Getter" for master_salt
1388 function getMasterSalt () {
1389         // Do we have cache?
1390         if (!isset($GLOBALS[__FUNCTION__])) {
1391                 // Determine it
1392                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1393         } // END - if
1394
1395         // Return cache
1396         return $GLOBALS[__FUNCTION__];
1397 }
1398
1399 // "Getter" for prime
1400 function getPrime () {
1401         // Do we have cache?
1402         if (!isset($GLOBALS[__FUNCTION__])) {
1403                 // Determine it
1404                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1405         } // END - if
1406
1407         // Return cache
1408         return $GLOBALS[__FUNCTION__];
1409 }
1410
1411 // "Getter" for encrypt_seperator
1412 function getEncryptSeperator () {
1413         // Do we have cache?
1414         if (!isset($GLOBALS[__FUNCTION__])) {
1415                 // Determine it
1416                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1417         } // END - if
1418
1419         // Return cache
1420         return $GLOBALS[__FUNCTION__];
1421 }
1422
1423 // "Getter" for mysql_prefix
1424 function getMysqlPrefix () {
1425         // Do we have cache?
1426         if (!isset($GLOBALS[__FUNCTION__])) {
1427                 // Determine it
1428                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1429         } // END - if
1430
1431         // Return cache
1432         return $GLOBALS[__FUNCTION__];
1433 }
1434
1435 // "Getter" for table_type
1436 function getTableType () {
1437         // Do we have cache?
1438         if (!isset($GLOBALS[__FUNCTION__])) {
1439                 // Determine it
1440                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1441         } // END - if
1442
1443         // Return cache
1444         return $GLOBALS[__FUNCTION__];
1445 }
1446
1447 // "Getter" for salt_length
1448 function getSaltLength () {
1449         // Do we have cache?
1450         if (!isset($GLOBALS[__FUNCTION__])) {
1451                 // Determine it
1452                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1453         } // END - if
1454
1455         // Return cache
1456         return $GLOBALS[__FUNCTION__];
1457 }
1458
1459 // "Getter" for output_mode
1460 function getOutputMode () {
1461         // Do we have cache?
1462         if (!isset($GLOBALS[__FUNCTION__])) {
1463                 // Determine it
1464                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1465         } // END - if
1466
1467         // Return cache
1468         return $GLOBALS[__FUNCTION__];
1469 }
1470
1471 // "Getter" for full_version
1472 function getFullVersion () {
1473         // Do we have cache?
1474         if (!isset($GLOBALS[__FUNCTION__])) {
1475                 // Determine it
1476                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1477         } // END - if
1478
1479         // Return cache
1480         return $GLOBALS[__FUNCTION__];
1481 }
1482
1483 // "Getter" for title
1484 function getTitle () {
1485         // Do we have cache?
1486         if (!isset($GLOBALS[__FUNCTION__])) {
1487                 // Determine it
1488                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1489         } // END - if
1490
1491         // Return cache
1492         return $GLOBALS[__FUNCTION__];
1493 }
1494
1495 // "Getter" for curr_svn_revision
1496 function getCurrentRepositoryRevision () {
1497         // Do we have cache?
1498         if (!isset($GLOBALS[__FUNCTION__])) {
1499                 // Determine it
1500                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1501         } // END - if
1502
1503         // Return cache
1504         return $GLOBALS[__FUNCTION__];
1505 }
1506
1507 // "Getter" for server_url
1508 function getServerUrl () {
1509         // Do we have cache?
1510         if (!isset($GLOBALS[__FUNCTION__])) {
1511                 // Determine it
1512                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1513         } // END - if
1514
1515         // Return cache
1516         return $GLOBALS[__FUNCTION__];
1517 }
1518
1519 // "Getter" for mt_word
1520 function getMtWord () {
1521         // Do we have cache?
1522         if (!isset($GLOBALS[__FUNCTION__])) {
1523                 // Determine it
1524                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1525         } // END - if
1526
1527         // Return cache
1528         return $GLOBALS[__FUNCTION__];
1529 }
1530
1531 // "Getter" for mt_word2
1532 function getMtWord2 () {
1533         // Do we have cache?
1534         if (!isset($GLOBALS[__FUNCTION__])) {
1535                 // Determine it
1536                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1537         } // END - if
1538
1539         // Return cache
1540         return $GLOBALS[__FUNCTION__];
1541 }
1542
1543 // "Getter" for main_title
1544 function getMainTitle () {
1545         // Do we have cache?
1546         if (!isset($GLOBALS[__FUNCTION__])) {
1547                 // Determine it
1548                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1549         } // END - if
1550
1551         // Return cache
1552         return $GLOBALS[__FUNCTION__];
1553 }
1554
1555 // "Getter" for file_hash
1556 function getFileHash () {
1557         // Do we have cache?
1558         if (!isset($GLOBALS[__FUNCTION__])) {
1559                 // Determine it
1560                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1561         } // END - if
1562
1563         // Return cache
1564         return $GLOBALS[__FUNCTION__];
1565 }
1566
1567 // "Getter" for pass_scramble
1568 function getPassScramble () {
1569         // Do we have cache?
1570         if (!isset($GLOBALS[__FUNCTION__])) {
1571                 // Determine it
1572                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1573         } // END - if
1574
1575         // Return cache
1576         return $GLOBALS[__FUNCTION__];
1577 }
1578
1579 // "Getter" for ap_inactive_since
1580 function getApInactiveSince () {
1581         // Do we have cache?
1582         if (!isset($GLOBALS[__FUNCTION__])) {
1583                 // Determine it
1584                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1585         } // END - if
1586
1587         // Return cache
1588         return $GLOBALS[__FUNCTION__];
1589 }
1590
1591 // "Getter" for user_min_confirmed
1592 function getUserMinConfirmed () {
1593         // Do we have cache?
1594         if (!isset($GLOBALS[__FUNCTION__])) {
1595                 // Determine it
1596                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1597         } // END - if
1598
1599         // Return cache
1600         return $GLOBALS[__FUNCTION__];
1601 }
1602
1603 // "Getter" for auto_purge
1604 function getAutoPurge () {
1605         // Do we have cache?
1606         if (!isset($GLOBALS[__FUNCTION__])) {
1607                 // Determine it
1608                 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1609         } // END - if
1610
1611         // Return cache
1612         return $GLOBALS[__FUNCTION__];
1613 }
1614
1615 // "Getter" for bonus_userid
1616 function getBonusUserid () {
1617         // Do we have cache?
1618         if (!isset($GLOBALS[__FUNCTION__])) {
1619                 // Determine it
1620                 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1621         } // END - if
1622
1623         // Return cache
1624         return $GLOBALS[__FUNCTION__];
1625 }
1626
1627 // "Getter" for ap_inactive_time
1628 function getApInactiveTime () {
1629         // Do we have cache?
1630         if (!isset($GLOBALS[__FUNCTION__])) {
1631                 // Determine it
1632                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1633         } // END - if
1634
1635         // Return cache
1636         return $GLOBALS[__FUNCTION__];
1637 }
1638
1639 // "Getter" for ap_dm_timeout
1640 function getApDmTimeout () {
1641         // Do we have cache?
1642         if (!isset($GLOBALS[__FUNCTION__])) {
1643                 // Determine it
1644                 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1645         } // END - if
1646
1647         // Return cache
1648         return $GLOBALS[__FUNCTION__];
1649 }
1650
1651 // "Getter" for ap_tasks_time
1652 function getApTasksTime () {
1653         // Do we have cache?
1654         if (!isset($GLOBALS[__FUNCTION__])) {
1655                 // Determine it
1656                 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1657         } // END - if
1658
1659         // Return cache
1660         return $GLOBALS[__FUNCTION__];
1661 }
1662
1663 // "Getter" for ap_unconfirmed_time
1664 function getApUnconfirmedTime () {
1665         // Do we have cache?
1666         if (!isset($GLOBALS[__FUNCTION__])) {
1667                 // Determine it
1668                 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1669         } // END - if
1670
1671         // Return cache
1672         return $GLOBALS[__FUNCTION__];
1673 }
1674
1675 // "Getter" for points
1676 function getPoints () {
1677         // Do we have cache?
1678         if (!isset($GLOBALS[__FUNCTION__])) {
1679                 // Determine it
1680                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1681         } // END - if
1682
1683         // Return cache
1684         return $GLOBALS[__FUNCTION__];
1685 }
1686
1687 // "Getter" for slogan
1688 function getSlogan () {
1689         // Do we have cache?
1690         if (!isset($GLOBALS[__FUNCTION__])) {
1691                 // Determine it
1692                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1693         } // END - if
1694
1695         // Return cache
1696         return $GLOBALS[__FUNCTION__];
1697 }
1698
1699 // "Getter" for copy
1700 function getCopy () {
1701         // Do we have cache?
1702         if (!isset($GLOBALS[__FUNCTION__])) {
1703                 // Determine it
1704                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1705         } // END - if
1706
1707         // Return cache
1708         return $GLOBALS[__FUNCTION__];
1709 }
1710
1711 // "Getter" for webmaster
1712 function getWebmaster () {
1713         // Do we have cache?
1714         if (!isset($GLOBALS[__FUNCTION__])) {
1715                 // Determine it
1716                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1717         } // END - if
1718
1719         // Return cache
1720         return $GLOBALS[__FUNCTION__];
1721 }
1722
1723 // "Getter" for sql_count
1724 function getSqlCount () {
1725         // Do we have cache?
1726         if (!isset($GLOBALS[__FUNCTION__])) {
1727                 // Determine it
1728                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1729         } // END - if
1730
1731         // Return cache
1732         return $GLOBALS[__FUNCTION__];
1733 }
1734
1735 // "Getter" for num_templates
1736 function getNumTemplates () {
1737         // Do we have cache?
1738         if (!isset($GLOBALS[__FUNCTION__])) {
1739                 // Determine it
1740                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1741         } // END - if
1742
1743         // Return cache
1744         return $GLOBALS[__FUNCTION__];
1745 }
1746
1747 // "Getter" for dns_cache_timeout
1748 function getDnsCacheTimeout () {
1749         // Do we have cache?
1750         if (!isset($GLOBALS[__FUNCTION__])) {
1751                 // Determine it
1752                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1753         } // END - if
1754
1755         // Return cache
1756         return $GLOBALS[__FUNCTION__];
1757 }
1758
1759 // "Getter" for menu_blur_spacer
1760 function getMenuBlurSpacer () {
1761         // Do we have cache?
1762         if (!isset($GLOBALS[__FUNCTION__])) {
1763                 // Determine it
1764                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
1765         } // END - if
1766
1767         // Return cache
1768         return $GLOBALS[__FUNCTION__];
1769 }
1770
1771 // "Getter" for points_register
1772 function getPointsRegister () {
1773         // Do we have cache?
1774         if (!isset($GLOBALS[__FUNCTION__])) {
1775                 // Determine it
1776                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
1777         } // END - if
1778
1779         // Return cache
1780         return $GLOBALS[__FUNCTION__];
1781 }
1782
1783 // "Getter" for points_ref
1784 function getPointsRef () {
1785         // Do we have cache?
1786         if (!isset($GLOBALS[__FUNCTION__])) {
1787                 // Determine it
1788                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
1789         } // END - if
1790
1791         // Return cache
1792         return $GLOBALS[__FUNCTION__];
1793 }
1794
1795 // "Getter" for ref_payout
1796 function getRefPayout () {
1797         // Do we have cache?
1798         if (!isset($GLOBALS[__FUNCTION__])) {
1799                 // Determine it
1800                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
1801         } // END - if
1802
1803         // Return cache
1804         return $GLOBALS[__FUNCTION__];
1805 }
1806
1807 // "Getter" for online_timeout
1808 function getOnlineTimeout () {
1809         // Do we have cache?
1810         if (!isset($GLOBALS[__FUNCTION__])) {
1811                 // Determine it
1812                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
1813         } // END - if
1814
1815         // Return cache
1816         return $GLOBALS[__FUNCTION__];
1817 }
1818
1819 // "Getter" for index_home
1820 function getIndexHome () {
1821         // Do we have cache?
1822         if (!isset($GLOBALS[__FUNCTION__])) {
1823                 // Determine it
1824                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
1825         } // END - if
1826
1827         // Return cache
1828         return $GLOBALS[__FUNCTION__];
1829 }
1830
1831 // "Getter" for one_day
1832 function getOneDay () {
1833         // Do we have cache?
1834         if (!isset($GLOBALS[__FUNCTION__])) {
1835                 // Determine it
1836                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
1837         } // END - if
1838
1839         // Return cache
1840         return $GLOBALS[__FUNCTION__];
1841 }
1842
1843 // Checks wether proxy configuration is used
1844 function isProxyUsed () {
1845         // Do we have cache?
1846         if (!isset($GLOBALS[__FUNCTION__])) {
1847                 // Determine it
1848                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
1849         } // END - if
1850
1851         // Return cache
1852         return $GLOBALS[__FUNCTION__];
1853 }
1854
1855 // Checks wether POST data contains selections
1856 function ifPostContainsSelections ($element = 'sel') {
1857         // Do we have cache?
1858         if (!isset($GLOBALS[__FUNCTION__][$element])) {
1859                 // Determine it
1860                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
1861         } // END - if
1862
1863         // Return cache
1864         return $GLOBALS[__FUNCTION__][$element];
1865 }
1866
1867 // Checks wether verbose_sql is Y and returns true/false if so
1868 function isVerboseSqlEnabled () {
1869         // Do we have cache?
1870         if (!isset($GLOBALS[__FUNCTION__])) {
1871                 // Determine it
1872                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
1873         } // END - if
1874
1875         // Return cache
1876         return $GLOBALS[__FUNCTION__];
1877 }
1878
1879 // "Getter" for total user points
1880 function getTotalPoints ($userid) {
1881         // Do we have cache?
1882         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1883                 // Determine it
1884                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points');
1885         } // END - if
1886
1887         // Return cache
1888         return $GLOBALS[__FUNCTION__][$userid];
1889 }
1890
1891 // Wrapper to check if url_blacklist is enabled
1892 function isUrlBlacklistEnabled () {
1893         // Do we have cache?
1894         if (!isset($GLOBALS[__FUNCTION__])) {
1895                 // Determine it
1896                 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
1897         } // END - if
1898
1899         // Return cache
1900         return $GLOBALS[__FUNCTION__];
1901 }
1902
1903 // Checks wether direct payment is allowed in configuration
1904 function isDirectPaymentEnabled () {
1905         // Do we have cache?
1906         if (!isset($GLOBALS[__FUNCTION__])) {
1907                 // Determine it
1908                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
1909         } // END - if
1910
1911         // Return cache
1912         return $GLOBALS[__FUNCTION__];
1913 }
1914
1915 // Wrapper to check if current task is for extension (not update)
1916 function isExtensionTask ($content) {
1917         // Do we have cache?
1918         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
1919                 // Determine it
1920                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
1921         } // END - if
1922
1923         // Return cache
1924         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
1925 }
1926
1927 // Wrapper to check if output mode is CSS
1928 function isCssOutputMode () {
1929         // Determine it
1930         return (getScriptOutputMode() == 1);
1931 }
1932
1933 // Wrapper to check if output mode is HTML
1934 function isHtmlOutputMode () {
1935         // Determine it
1936         return (getScriptOutputMode() == 0);
1937 }
1938
1939 // Wrapper to check if output mode is RAW
1940 function isRawOutputMode () {
1941         // Determine it
1942         return (getScriptOutputMode() == -1);
1943 }
1944
1945 // Wrapper to generate a user email link
1946 function generateWrappedUserEmailLink ($email) {
1947         // Just call the inner function
1948         return generateEmailLink($email, 'user_data');
1949 }
1950
1951 // Wrapper to check if user points are locked
1952 function ifUserPointsLocked ($userid) {
1953         // Do we have cache?
1954         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1955                 // Determine it
1956                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
1957         } // END - if
1958
1959         // Return cache
1960         return $GLOBALS[__FUNCTION__][$userid];
1961 }
1962
1963 // [EOF]
1964 ?>