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