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