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