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