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