isExtensionOlder() is no longer required
[mailer.git] / inc / wrapper-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/04/2009 *
4  * ===================                          Last change: 04/04/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : wrapper-functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Wrapper functions                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Wrapper-Funktionen                               *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         exit();
41 } // END - if
42
43 // Read a given file
44 function readFromFile ($FQFN) {
45         // Sanity-check if file is there (should be there, but just to make it sure)
46         if (!isFileReadable($FQFN)) {
47                 // This should not happen
48                 reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!');
49         } // END - if
50
51         // Load the file
52         if (function_exists('file_get_contents')) {
53                 // Use new function
54                 $fileContent = file_get_contents($FQFN);
55         } else {
56                 // Fall-back to implode-file chain
57                 $fileContent = implode('', file($FQFN));
58         }
59
60         // Return the content
61         return $fileContent;
62 }
63
64 // Writes content to a file
65 function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
66         // Is the file writeable?
67         if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
68                 // Not writeable!
69                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable or cannot change CHMOD to 0644.", basename($FQFN)));
70
71                 // Failed! :(
72                 return FALSE;
73         } // END - if
74
75         // By default all is failed...
76         $GLOBALS['file_readable'][$FQFN] = FALSE;
77         $return = FALSE;
78
79         // Is the function there?
80         if (function_exists('file_put_contents')) {
81                 // With lock?
82                 if ($aquireLock === TRUE) {
83                         // Write it directly with lock
84                         $return = file_put_contents($FQFN, $content, LOCK_EX);
85                 } else {
86                         // Write it directly
87                         $return = file_put_contents($FQFN, $content);
88                 }
89         } else {
90                 // Write it with fopen
91                 $fp = fopen($FQFN, 'w')
92                         or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
93
94                 // Aquire a lock?
95                 if ($aquireLock === TRUE) {
96                         // Aquire a lock.
97                         flock($fp, LOCK_EX);
98                 } // END - if
99
100                 // Write content
101                 $return = fwrite($fp, $content);
102
103                 // Close stream
104                 fclose($fp);
105         }
106
107         // Was something written?
108         if ($return !== FALSE) {
109                 // Mark it as readable
110                 $GLOBALS['file_readable'][$FQFN] = TRUE;
111         } // END - if
112
113         // Return status
114         return (($return !== FALSE) && (changeMode($FQFN, 0644)));
115 }
116
117 // Clears the output buffer. This function does *NOT* backup sent content.
118 function clearOutputBuffer () {
119         // Make sure this function is not called twice (no double-cleaning!)
120         if (isset($GLOBALS[__FUNCTION__])) {
121                 // This function is called twice
122                 reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.');
123         } elseif ((ob_get_length() > 0) && (!ob_end_clean())) {
124                 // Failed!
125                 reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
126         } // END - if
127
128         // Mark this function as called
129         $GLOBALS[__FUNCTION__] = TRUE;
130 }
131
132 // Encode strings
133 function encodeString ($str) {
134         $str = urlencode(base64_encode(compileUriCode($str)));
135         return $str;
136 }
137
138 // Decode strings encoded with encodeString()
139 function decodeString ($str) {
140         $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
141         return $str;
142 }
143
144 // Decode entities in a nicer way
145 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
146         // Decode the entities to UTF-8 now
147         $decodedString = html_entity_decode($str, $quote, 'UTF-8');
148
149         // Return decoded string
150         return $decodedString;
151 }
152
153 // Merges an array together but only if both are arrays
154 function merge_array ($array1, $array2, $keepIndex = FALSE) {
155         // Are both an array?
156         if ((!is_array($array1)) && (!is_array($array2))) {
157                 // Both are not arrays
158                 reportBug(__FUNCTION__, __LINE__, 'No arrays provided!');
159         } elseif (!is_array($array1)) {
160                 // Left one is not an array
161                 reportBug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
162         } elseif (!is_array($array2)) {
163                 // Right one is not an array
164                 reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
165         }
166
167         // Maintain index of array2?
168         if ($keepIndex === TRUE) {
169                 // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :(
170                 foreach ($array2 as $key => $value) {
171                         // Add it
172                         $array1[$key] = $value;
173                 } // END - foreach
174
175                 // Return it
176                 return $array1;
177         } else {
178                 // Merge both together normally
179                 return array_merge($array1, $array2);
180         }
181 }
182
183 // Check if given FQFN is a readable file
184 function isFileReadable ($FQFN) {
185         // Is there cache?
186         if (!isset($GLOBALS['file_readable'][$FQFN])) {
187                 // Check all...
188                 $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN)));
189         } // END - if
190
191         // Return result
192         return $GLOBALS['file_readable'][$FQFN];
193 }
194
195 // Checks whether the given FQFN is a directory and not ., .. or .svn
196 function isDirectory ($FQFN) {
197         // Is there cache?
198         if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
199                 // Generate baseName
200                 $baseName = basename($FQFN);
201
202                 // Check it
203                 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
204         } // END - if
205
206         // Return the result
207         return $GLOBALS[__FUNCTION__][$FQFN];
208 }
209
210 // "Getter" for the real remote IP number
211 function detectRealIpAddress ($alwaysReal = FALSE) {
212         // Get remote ip from environment
213         $remoteAddr = determineRealRemoteAddress();
214
215         // Is removeip installed?
216         if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
217                 // Then anonymize it
218                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
219         } // END - if
220
221         // Return it
222         return $remoteAddr;
223 }
224
225 // "Getter" for remote IP number
226 function detectRemoteAddr ($alwaysReal = FALSE) {
227         // Get remote ip from environment
228         $remoteAddr = determineRealRemoteAddress(TRUE);
229
230         // Is removeip installed?
231         if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
232                 // Then anonymize it
233                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
234         } // END - if
235
236         // Return it
237         return $remoteAddr;
238 }
239
240 // "Getter" for remote hostname
241 function detectRemoteHostname ($alwaysReal = FALSE) {
242         // Get remote ip from environment
243         $remoteHost = getenv('REMOTE_HOST');
244
245         // Is removeip installed?
246         if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
247                 // Then anonymize it
248                 $remoteHost = getAnonymousRemoteHost($remoteHost);
249         } // END - if
250
251         // Return it
252         return $remoteHost;
253 }
254
255 // "Getter" for user agent
256 function detectUserAgent ($alwaysReal = FALSE) {
257         // Get remote ip from environment
258         $userAgent = getenv('HTTP_USER_AGENT');
259
260         // Is removeip installed?
261         if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
262                 // Then anonymize it
263                 $userAgent = getAnonymousUserAgent($userAgent);
264         } // END - if
265
266         // Return it
267         return $userAgent;
268 }
269
270 // "Getter" for referer
271 function detectReferer ($alwaysReal = FALSE) {
272         // Get remote ip from environment
273         $referer = getenv('HTTP_REFERER');
274
275         // Is removeip installed?
276         if ((isExtensionActive('removeip')) && ($alwaysReal === TRUE)) {
277                 // Then anonymize it
278                 $referer = getAnonymousReferer($referer);
279         } // END - if
280
281         // Return it
282         return $referer;
283 }
284
285 // "Getter" for request URI
286 function detectRequestUri () {
287         // Return it
288         return (getenv('REQUEST_URI'));
289 }
290
291 // "Getter" for query string
292 function detectQueryString () {
293         return str_replace('&', '&amp;', (getenv('QUERY_STRING')));
294 }
295
296 // "Getter" for SERVER_NAME
297 function detectServerName () {
298         // Return it
299         return (getenv('SERVER_NAME'));
300 }
301
302 // Removes any  existing www. from SERVER_NAME. This is very silly but enough
303 // for our purpose here.
304 function detectDomainName () {
305         // Is there cache?
306         if (!isset($GLOBALS[__FUNCTION__])) {
307                 // Get server name
308                 $domainName = detectServerName();
309
310                 // Is there any www. ?
311                 if (substr($domainName, 0, 4) == 'www.') {
312                         // Remove it
313                         $domainName = substr($domainName, 4);
314                 } // END - if
315
316                 // Set cache
317                 $GLOBALS[__FUNCTION__] = $domainName;
318         } // END - if
319
320         // Return cache
321         return $GLOBALS[__FUNCTION__];
322 }
323
324 // Check whether we are installing
325 function isInstalling () {
326         // Determine whether we are installing
327         if (!isset($GLOBALS['__mailer_installing'])) {
328                 // Check URL (css.php/js.php need this)
329                 $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing');
330         } // END - if
331
332         // Return result
333         return $GLOBALS['__mailer_installing'];
334 }
335
336 // Check whether this script is installed
337 function isInstalled () {
338         // Is there cache?
339         if (!isset($GLOBALS[__FUNCTION__])) {
340                 // Determine whether this script is installed
341                 $GLOBALS[__FUNCTION__] = (
342                 (
343                         // First is config
344                         (
345                                 (
346                                         isConfigEntrySet('MXCHANGE_INSTALLED')
347                                 ) && (
348                                         getConfig('MXCHANGE_INSTALLED') == 'Y'
349                                 )
350                         )
351                 ) || (
352                         // New config file found and loaded
353                         isIncludeReadable(getCachePath() . 'config-local.php')
354                 ) || (
355                         (
356                                 // New config file found, but not yet read
357                                 isIncludeReadable(getCachePath() . 'config-local.php')
358                         ) && (
359                                 (
360                                         // Only new config file is found
361                                         !isIncludeReadable('inc/config.php')
362                                 ) || (
363                                         // Is installation mode
364                                         !isInstalling()
365                                 )
366                         )
367                 ));
368         } // END - if
369
370         // Then use the cache
371         return $GLOBALS[__FUNCTION__];
372 }
373
374 // Check whether an admin is registered
375 function isAdminRegistered () {
376         // Is cache set?
377         if (!isset($GLOBALS[__FUNCTION__])) {
378                 // Simply check it
379                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
380         } // END - if
381
382         // Return it
383         return $GLOBALS[__FUNCTION__];
384 }
385
386 // Checks whether the hourly reset mode is active
387 function isHourlyResetEnabled () {
388         // Now simply check it
389         return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE));
390 }
391
392 // Checks whether the reset mode is active
393 function isResetModeEnabled () {
394         // Now simply check it
395         return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === TRUE));
396 }
397
398 // Checks whether the debug mode is enabled
399 function isDebugModeEnabled () {
400         // Is cache set?
401         if (!isset($GLOBALS[__FUNCTION__])) {
402                 // Simply check it
403                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
404         } // END - if
405
406         // Return it
407         return $GLOBALS[__FUNCTION__];
408 }
409
410 // Checks whether the debug reset is enabled
411 function isDebugResetEnabled () {
412         // Is cache set?
413         if (!isset($GLOBALS[__FUNCTION__])) {
414                 // Simply check it
415                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
416         } // END - if
417
418         // Return it
419         return $GLOBALS[__FUNCTION__];
420 }
421
422 // Checks whether SQL debugging is enabled
423 function isSqlDebuggingEnabled () {
424         // Is cache set?
425         if (!isset($GLOBALS[__FUNCTION__])) {
426                 // Determine if SQL debugging is enabled
427                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
428         } // END - if
429
430         // Return it
431         return $GLOBALS[__FUNCTION__];
432 }
433
434 // Checks whether we shall debug regular expressions
435 function isDebugRegularExpressionEnabled () {
436         // Is cache set?
437         if (!isset($GLOBALS[__FUNCTION__])) {
438                 // Simply check it
439                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
440         } // END - if
441
442         // Return it
443         return $GLOBALS[__FUNCTION__];
444 }
445
446 // Checks whether the cache instance is valid
447 function isCacheInstanceValid () {
448         // Is there cache?
449         if (!isset($GLOBALS[__FUNCTION__])) {
450                 // Determine it
451                 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
452         } // END - if
453
454         // Return cache
455         return $GLOBALS[__FUNCTION__];
456 }
457
458 // Copies a file from source to destination and verifies if that goes fine.
459 // This function should wrap the copy() command and make a nicer debug backtrace
460 // even if there is no xdebug extension installed.
461 function copyFileVerified ($source, $dest, $chmod = '') {
462         // Failed is the default
463         $status = FALSE;
464
465         // Is the source file there?
466         if (!isFileReadable($source)) {
467                 // Then abort here
468                 reportBug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
469         } // END - if
470
471         // Is the target directory there?
472         if (!isDirectory(dirname($dest))) {
473                 // Then abort here
474                 reportBug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
475         } // END - if
476
477         // Now try to copy it
478         if (!copy($source, $dest)) {
479                 // Something went wrong
480                 reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
481         } else {
482                 // Reset cache
483                 $GLOBALS['file_readable'][$dest] = TRUE;
484         }
485
486         // All fine by default
487         $status = TRUE;
488
489         // If there are chmod rights set, apply them
490         if (!empty($chmod)) {
491                 // Try to apply them
492                 $status = changeMode($dest, $chmod);
493         } // END - if
494
495         // All fine
496         return $status;
497 }
498
499 // Wrapper function for chmod()
500 // @TODO Do some more sanity check here
501 function changeMode ($FQFN, $mode) {
502         // Is the file/directory there?
503         if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
504                 // Neither, so abort here
505                 reportBug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
506         } // END - if
507
508         // Try to set them
509         return chmod($FQFN, $mode);
510 }
511
512 // Wrapper for unlink()
513 function removeFile ($FQFN) {
514         // Is the file there?
515         if (isFileReadable($FQFN)) {
516                 // Reset cache first
517                 $GLOBALS['file_readable'][$FQFN] = FALSE;
518
519                 // Yes, so remove it
520                 return unlink($FQFN);
521         } // END - if
522
523         // All fine if no file was removed. If we change this to 'false' or rewrite
524         // above if() block it would be to restrictive.
525         return TRUE;
526 }
527
528 // Wrapper for $_POST['sel']
529 function countPostSelection ($element = 'sel') {
530         // Is there cache?
531         if (!isset($GLOBALS[__FUNCTION__][$element])) {
532                 // Default is zero
533                 $GLOBALS[__FUNCTION__][$element] = '0';
534
535                 // Is it set?
536                 if (isPostRequestElementSet($element)) {
537                         // Return counted elements
538                         $GLOBALS[__FUNCTION__][$element] = countSelection(postRequestElement($element));
539                 } // END - if
540         } // END - if
541
542         // Return cached value
543         return $GLOBALS[__FUNCTION__][$element];
544 }
545
546 // Checks whether the config-local.php is loaded
547 function isConfigLocalLoaded () {
548         return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === TRUE));
549 }
550
551 // Checks whether a nickname or userid was entered and caches the result
552 function isNicknameUsed ($userid) {
553         // Is the cache there
554         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
555                 // Determine it
556                 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL'));
557         } // END - if
558
559         // Return the result
560         return $GLOBALS[__FUNCTION__][$userid];
561 }
562
563 // Getter for 'what' value
564 function getWhat ($strict = TRUE) {
565         // Default is null
566         $what = NULL;
567
568         // Is the value set?
569         if (isWhatSet($strict)) {
570                 // Then use it
571                 $what = $GLOBALS['__what'];
572         } // END - if
573
574         // Return it
575         return $what;
576 }
577
578 // Setter for 'what' value
579 function setWhat ($newWhat) {
580         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat);
581         $GLOBALS['__what'] = $newWhat;
582 }
583
584 // Setter for 'what' from configuration
585 function setWhatFromConfig ($configEntry) {
586         // Get 'what' from config
587         $what = getConfig($configEntry);
588
589         // Set it
590         setWhat($what);
591 }
592
593 // Checks whether what is set and optionally aborts on miss
594 function isWhatSet ($strict =  false) {
595         // Check for it
596         $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
597
598         // Should we abort here?
599         if (($strict === TRUE) && ($isset === FALSE)) {
600                 // Output backtrace
601                 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
602         } // END - if
603
604         // Return it
605         return $isset;
606 }
607
608 // Getter for 'action' value
609 function getAction ($strict = TRUE) {
610         // Default is null
611         $action = NULL;
612
613         // Is the value set?
614         if (isActionSet(($strict) && (isHtmlOutputMode()))) {
615                 // Then use it
616                 $action = $GLOBALS['__action'];
617         } // END - if
618
619         // Return it
620         return $action;
621 }
622
623 // Setter for 'action' value
624 function setAction ($newAction) {
625         $GLOBALS['__action'] = $newAction;
626 }
627
628 // Checks whether action is set and optionally aborts on miss
629 function isActionSet ($strict =  false) {
630         // Check for it
631         $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
632
633         // Should we abort here?
634         if (($strict === TRUE) && ($isset === FALSE)) {
635                 // Output backtrace
636                 reportBug(__FUNCTION__, __LINE__, 'action is empty.');
637         } // END - if
638
639         // Return it
640         return $isset;
641 }
642
643 // Getter for 'module' value
644 function getModule ($strict = TRUE) {
645         // Default is null
646         $module = NULL;
647
648         // Is the value set?
649         if (isModuleSet($strict)) {
650                 // Then use it
651                 $module = $GLOBALS['__module'];
652         } // END - if
653
654         // Return it
655         return $module;
656 }
657
658 // Setter for 'module' value
659 function setModule ($newModule) {
660         // Secure it and make all modules lower-case
661         $GLOBALS['__module'] = strtolower($newModule);
662 }
663
664 // Checks whether module is set and optionally aborts on miss
665 function isModuleSet ($strict =  false) {
666         // Check for it
667         $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
668
669         // Should we abort here?
670         if (($strict === TRUE) && ($isset === FALSE)) {
671                 // Output backtrace
672                 reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
673         } // END - if
674
675         // Return it
676         return (($isset === TRUE) && ($GLOBALS['__module'] != 'unknown')) ;
677 }
678
679 // Getter for 'output_mode' value
680 function getScriptOutputMode () {
681         // Is cache set?
682         if (!isset($GLOBALS[__FUNCTION__])) {
683                 // Is the output mode set?
684                 if (!isOutputModeSet()) {
685                         // No, then abort here
686                         reportBug(__FUNCTION__, __LINE__, 'Output mode not set.');
687                 } // END - if
688
689                 // Set it in cache
690                 $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode'];
691         } // END - if
692
693         // Return cache
694         return $GLOBALS[__FUNCTION__];
695 }
696
697 // Setter for 'output_mode' value
698 function setOutputMode ($newOutputMode) {
699         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
700         $GLOBALS['__output_mode'] = (int) $newOutputMode;
701 }
702
703 // Checks whether output_mode is set and optionally aborts on miss
704 function isOutputModeSet ($strict =  false) {
705         // Check for it
706         $isset = (isset($GLOBALS['__output_mode']));
707
708         // Should we abort here?
709         if (($strict === TRUE) && ($isset === FALSE)) {
710                 // Output backtrace
711                 reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
712         } // END - if
713
714         // Return it
715         return $isset;
716 }
717
718 // Enables block-mode
719 function enableBlockMode ($enabled = TRUE) {
720         $GLOBALS['__block_mode'] = $enabled;
721 }
722
723 // Checks whether block-mode is enabled
724 function isBlockModeEnabled () {
725         // Abort if not set
726         if (!isset($GLOBALS['__block_mode'])) {
727                 // Needs to be fixed
728                 reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
729         } // END - if
730
731         // Return it
732         return $GLOBALS['__block_mode'];
733 }
734
735 // Wrapper for redirectToUrl but URL comes from a configuration entry
736 function redirectToConfiguredUrl ($configEntry) {
737         // Load the URL
738         redirectToUrl(getConfig($configEntry));
739 }
740
741 // Wrapper function to redirect from member-only modules to index
742 function redirectToIndexMemberOnlyModule () {
743         // Do the redirect here
744         redirectToUrl('modules.php?module=index&amp;code=' . getCode('MODULE_MEMBER_ONLY') . '&amp;mod=' . getModule());
745 }
746
747 // Wrapper function to redirect to current URL
748 function redirectToRequestUri () {
749         redirectToUrl(basename(detectRequestUri()));
750 }
751
752 // Wrapper function to redirect to de-refered URL
753 function redirectToDereferedUrl ($url) {
754         // Redirect to to
755         redirectToUrl(generateDereferrerUrl($url));
756 }
757
758 // Wrapper function for checking if extension is installed and newer or same version
759 function isExtensionInstalledAndNewer ($ext_name, $ext_ver) {
760         // Is an cache entry found?
761         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
762                 // Determine it
763                 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE));
764         } else {
765                 // Cache hits should be incremented twice
766                 incrementStatsEntry('cache_hits', 2);
767         }
768
769         // Return it
770         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=&gt;' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
771         return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
772 }
773
774 // Wrapper function for checking if extension is installed and older than given version
775 function isExtensionInstalledAndOlder ($ext_name, $ext_ver) {
776         // Is an cache entry found?
777         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
778                 // Determine it
779                 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '<') === TRUE));
780         } else {
781                 // Cache hits should be incremented twice
782                 incrementStatsEntry('cache_hits', 2);
783         }
784
785         // Return it
786         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '&lt;' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
787         return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
788 }
789
790 // Set username
791 function setUsername ($userName) {
792         $GLOBALS['username'] = (string) $userName;
793 }
794
795 // Get username
796 function getUsername () {
797         // User name set?
798         if (!isset($GLOBALS['username'])) {
799                 // No, so it has to be a guest
800                 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
801         } // END - if
802
803         // Return it
804         return $GLOBALS['username'];
805 }
806
807 // Wrapper function for installation phase
808 function isInstallationPhase () {
809         // Is there cache?
810         if (!isset($GLOBALS[__FUNCTION__])) {
811                 // Determine it
812                 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
813         } // END - if
814
815         // Return result
816         return $GLOBALS[__FUNCTION__];
817 }
818
819 // Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
820 function isDemoModeActive () {
821         // Is cache set?
822         if (!isset($GLOBALS[__FUNCTION__])) {
823                 // Simply check it
824                 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
825         } // END - if
826
827         // Return it
828         return $GLOBALS[__FUNCTION__];
829 }
830
831 // Getter for PHP caching value
832 function getPhpCaching () {
833         return $GLOBALS['php_caching'];
834 }
835
836 // Checks whether the admin hash is set
837 function isAdminHashSet ($adminId) {
838         // Is the array there?
839         if (!isset($GLOBALS['cache_array']['admin'])) {
840                 // Missing array should be reported
841                 reportBug(__FUNCTION__, __LINE__, 'Cache not set.');
842         } // END - if
843
844         // Check for admin hash
845         return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
846 }
847
848 // Setter for admin hash
849 function setAdminHash ($adminId, $hash) {
850         $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
851 }
852
853 // Getter for current admin login
854 function getCurrentAdminLogin () {
855         // Log debug message
856         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
857
858         // Is there cache?
859         if (!isset($GLOBALS[__FUNCTION__])) {
860                 // Determine it
861                 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
862         } // END - if
863
864         // Return it
865         return $GLOBALS[__FUNCTION__];
866 }
867
868 // Setter for admin id (and current)
869 function setAdminId ($adminId) {
870         // Log debug message
871         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
872
873         // Set session
874         $status = setSession('admin_id', bigintval($adminId));
875
876         // Set current id
877         setCurrentAdminId($adminId);
878
879         // Return status
880         return $status;
881 }
882
883 // Setter for admin_last
884 function setAdminLast ($adminLast) {
885         // Log debug message
886         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
887
888         // Set session
889         $status = setSession('admin_last', $adminLast);
890
891         // Return status
892         return $status;
893 }
894
895 // Setter for admin_md5
896 function setAdminMd5 ($adminMd5) {
897         // Log debug message
898         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
899
900         // Set session
901         $status = setSession('admin_md5', $adminMd5);
902
903         // Return status
904         return $status;
905 }
906
907 // Getter for admin_md5
908 function getAdminMd5 () {
909         // Log debug message
910         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
911
912         // Get session
913         return getSession('admin_md5');
914 }
915
916 // Init user data array
917 function initUserData () {
918         // User id should not be zero
919         if (!isValidUserId(getCurrentUserId())) {
920                 // Should be always valid
921                 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
922         } // END - if
923
924         // Init the user
925         unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
926         $GLOBALS['user_data'][getCurrentUserId()] = array();
927 }
928
929 // Getter for user data
930 function getUserData ($column) {
931         // User id should not be zero
932         if (!isValidUserId(getCurrentUserId())) {
933                 // Should be always valid
934                 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
935         } // END - if
936
937         // Default is empty
938         $data = NULL;
939
940         if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
941                 // Return the value
942                 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
943         } // END - if
944
945         // Return it
946         return $data;
947 }
948
949 // Checks whether given user data is set to 'Y'
950 function isUserDataEnabled ($column) {
951         // Is there cache?
952         if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
953                 // Determine it
954                 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
955         } // END - if
956
957         // Return cache
958         return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
959 }
960
961 // Geter for whole user data array
962 function getUserDataArray () {
963         // Get user id
964         $userid = getCurrentUserId();
965
966         // Is the current userid valid?
967         if (!isValidUserId($userid)) {
968                 // Should be always valid
969                 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
970         } // END - if
971
972         // Get the whole array if found
973         if (isset($GLOBALS['user_data'][$userid])) {
974                 // Found, so return it
975                 return $GLOBALS['user_data'][$userid];
976         } else {
977                 // Return empty array
978                 return array();
979         }
980 }
981
982 // Checks if the user data is valid, this may indicate that the user has logged
983 // in, but you should use isMember() if you want to find that out.
984 function isUserDataValid () {
985         // User id should not be zero so abort here
986         if (!isCurrentUserIdSet()) {
987                 // Debug message, may be noisy
988                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
989
990                 // Abort here
991                 return FALSE;
992         } // END - if
993
994         // Is it cached?
995         if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
996                 // Determine it
997                 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
998         } // END - if
999
1000         // Return the result
1001         return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1002 }
1003
1004 // Setter for current userid
1005 function setCurrentUserId ($userid) {
1006         // Debug message
1007         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - ENTERED!');
1008
1009         // Is the cache from below functions different?
1010         if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) {
1011                 // Then unset both
1012                 unsetCurrentUserId();
1013         } // END - if
1014
1015         // Set userid
1016         $GLOBALS['current_userid'] = bigintval($userid);
1017
1018         // Unset it to re-determine the actual state
1019         unset($GLOBALS['is_userdata_valid'][$userid]);
1020
1021         // Debug message
1022         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - EXIT!');
1023 }
1024
1025 // Getter for current userid
1026 function getCurrentUserId () {
1027         // Is cache set?
1028         if (!isset($GLOBALS[__FUNCTION__])) {
1029                 // Userid must be set before it can be used
1030                 if (!isCurrentUserIdSet()) {
1031                         // Not set
1032                         reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1033                 } // END - if
1034
1035                 // Set userid in cache
1036                 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1037         } // END - if
1038
1039         // Return cache
1040         return $GLOBALS[__FUNCTION__];
1041 }
1042
1043 // Checks if current userid is set
1044 function isCurrentUserIdSet () {
1045         // Is there cache?
1046         if (!isset($GLOBALS[__FUNCTION__])) {
1047                 // Determine it
1048                 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1049         } // END - if
1050
1051         // Return cache
1052         return $GLOBALS[__FUNCTION__];
1053 }
1054
1055 // Unsets current userid
1056 function unsetCurrentUserId () {
1057         // Is it set?
1058         if (isset($GLOBALS['current_userid'])) {
1059                 // Unset this, too
1060                 unset($GLOBALS['isValidUserId'][$GLOBALS['current_userid']]);
1061         } // END - if
1062
1063         // Unset all cache entries
1064         unset($GLOBALS['current_userid']);
1065         unset($GLOBALS['getCurrentUserId']);
1066         unset($GLOBALS['isCurrentUserIdSet']);
1067 }
1068
1069 // Checks whether we are debugging template cache
1070 function isDebuggingTemplateCache () {
1071         // Is there cache?
1072         if (!isset($GLOBALS[__FUNCTION__])) {
1073                 // Determine it
1074                 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1075         } // END - if
1076
1077         // Return cache
1078         return $GLOBALS[__FUNCTION__];
1079 }
1080
1081 // Wrapper for fetchUserData() and getUserData() calls
1082 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1083         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1084         // Is it cached?
1085         if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1086                 // Default is NULL
1087                 $data = NULL;
1088
1089                 // Can we fetch the user data?
1090                 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1091                         // Now get the data back
1092                         $data = getUserData($valueColumn);
1093                 } // END - if
1094
1095                 // Cache it
1096                 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1097         } // END - if
1098
1099         // Return it
1100         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1101         return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1102 }
1103
1104 // Wrapper for strpos() to ease porting from deprecated ereg() function
1105 function isInString ($needle, $haystack) {
1106         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== FALSE));
1107         return (strpos($haystack, $needle) !== FALSE);
1108 }
1109
1110 // Wrapper for strpos() to ease porting from deprecated eregi() function
1111 // This function is case-insensitive
1112 function isInStringIgnoreCase ($needle, $haystack) {
1113         return (isInString(strtolower($needle), strtolower($haystack)));
1114 }
1115
1116 // Wrapper to check for if fatal errors where detected
1117 function ifFatalErrorsDetected () {
1118         // Just call the inner function
1119         return (getTotalFatalErrors() > 0);
1120 }
1121
1122 // Checks whether a HTTP status has been set
1123 function isHttpStatusSet () {
1124         // Is it set and not empty?
1125         return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1126 }
1127
1128 // Setter for HTTP status
1129 function setHttpStatus ($status) {
1130         $GLOBALS['http_status'] = (string) $status;
1131 }
1132
1133 // Getter for HTTP status
1134 function getHttpStatus () {
1135         // Is the status set?
1136         if (!isHttpStatusSet()) {
1137                 // Abort here
1138                 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1139         } // END - if
1140
1141         // Return it
1142         return $GLOBALS['http_status'];
1143 }
1144
1145 /**
1146  * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1147  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1148  *
1149  * ----------------------------------------------------------------------------
1150  * If you want to redirect, please use redirectToUrl(); instead
1151  * ----------------------------------------------------------------------------
1152  *
1153  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1154  *
1155  * @link    http://support.microsoft.com/kb/q176113/
1156  * @author  Andreas Gohr <andi@splitbrain.org>
1157  * @access  private
1158  */
1159 function sendRawRedirect ($url) {
1160         // Clear output buffer
1161         clearOutputBuffer();
1162
1163         // Clear own output buffer
1164         $GLOBALS['__output'] = '';
1165
1166         // To make redirects working (no content type), output mode must be raw
1167         setOutputMode(-1);
1168
1169         // Send helping header
1170         setHttpStatus('302 Found');
1171
1172         // always close the session
1173         session_write_close();
1174
1175         // Revert entity &amp;
1176         $url = str_replace('&amp;', '&', $url);
1177
1178         // check if running on IIS < 6 with CGI-PHP
1179         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1180                 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1181                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1182                 ($matches[1] < 6)) {
1183                 // Send the IIS header
1184                 addHttpHeader('Refresh: 0;url=' . $url);
1185         } else {
1186                 // Send generic header
1187                 addHttpHeader('Location: ' . $url);
1188         }
1189
1190         // Shutdown here
1191         doShutdown();
1192 }
1193
1194 // Determines the country of the given user id
1195 function determineCountry ($userid) {
1196         // Is there cache?
1197         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1198                 // Default is 'invalid'
1199                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1200
1201                 // Is extension country active?
1202                 if (isExtensionActive('country')) {
1203                         // Determine the right country code through the country id
1204                         $id = getUserData('country_code');
1205
1206                         // Then handle it over
1207                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1208                 } else {
1209                         // Get raw code from user data
1210                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1211                 }
1212         } // END - if
1213
1214         // Return cache
1215         return $GLOBALS[__FUNCTION__][$userid];
1216 }
1217
1218 // "Getter" for total confirmed user accounts
1219 function getTotalConfirmedUser () {
1220         // Is it cached?
1221         if (!isset($GLOBALS[__FUNCTION__])) {
1222                 // Then do it
1223                 if (isExtensionActive('user')) {
1224                         $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1225                 } else {
1226                         $GLOBALS[__FUNCTION__] = 0;
1227                 }
1228         } // END - if
1229
1230         // Return cached value
1231         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1232         return $GLOBALS[__FUNCTION__];
1233 }
1234
1235 // "Getter" for total unconfirmed user accounts
1236 function getTotalUnconfirmedUser () {
1237         // Is it cached?
1238         if (!isset($GLOBALS[__FUNCTION__])) {
1239                 // Then do it
1240                 if (isExtensionActive('user')) {
1241                         $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1242                 } else {
1243                         $GLOBALS[__FUNCTION__] = 0;
1244                 }
1245         } // END - if
1246
1247         // Return cached value
1248         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1249         return $GLOBALS[__FUNCTION__];
1250 }
1251
1252 // "Getter" for total locked user accounts
1253 function getTotalLockedUser () {
1254         // Is it cached?
1255         if (!isset($GLOBALS[__FUNCTION__])) {
1256                 // Then do it
1257                 if (isExtensionActive('user')) {
1258                         $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1259                 } else {
1260                         $GLOBALS[__FUNCTION__] = 0;
1261                 }
1262         } // END - if
1263
1264         // Return cached value
1265         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1266         return $GLOBALS[__FUNCTION__];
1267 }
1268
1269 // "Getter" for total locked user accounts
1270 function getTotalRandomRefidUser () {
1271         // Is it cached?
1272         if (!isset($GLOBALS[__FUNCTION__])) {
1273                 // Then do it
1274                 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1275                         $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
1276                 } else {
1277                         $GLOBALS[__FUNCTION__] = 0;
1278                 }
1279         } // END - if
1280
1281         // Return cached value
1282         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1283         return $GLOBALS[__FUNCTION__];
1284 }
1285
1286 // Is given userid valid?
1287 function isValidUserId ($userid) {
1288         // Debug message
1289         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid);
1290
1291         // Is there cache?
1292         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1293                 // Check it out
1294                 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1295         } // END - if
1296
1297         // Return cache
1298         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',result=' . intval($GLOBALS[__FUNCTION__][$userid]));
1299         return $GLOBALS[__FUNCTION__][$userid];
1300 }
1301
1302 // Encodes entities
1303 function encodeEntities ($str) {
1304         // Secure it first
1305         $str = secureString($str, TRUE, TRUE);
1306
1307         // Encode dollar sign as well
1308         $str = str_replace('$', '&#36;', $str);
1309
1310         // Return it
1311         return $str;
1312 }
1313
1314 // "Getter" for date from patch_ctime
1315 function getDateFromRepository () {
1316         // Is it cached?
1317         if (!isset($GLOBALS[__FUNCTION__])) {
1318                 // Then set it
1319                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1320         } // END - if
1321
1322         // Return cache
1323         return $GLOBALS[__FUNCTION__];
1324 }
1325
1326 // "Getter" for date/time from patch_ctime
1327 function getDateTimeFromRepository () {
1328         // Is it cached?
1329         if (!isset($GLOBALS[__FUNCTION__])) {
1330                 // Then set it
1331                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1332         } // END - if
1333
1334         // Return cache
1335         return $GLOBALS[__FUNCTION__];
1336 }
1337
1338 // Getter for current year (default)
1339 function getYear ($timestamp = NULL) {
1340         // Is it cached?
1341         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1342                 // null is time()
1343                 if (is_null($timestamp)) {
1344                         $timestamp = time();
1345                 } // END - if
1346
1347                 // Then create it
1348                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1349         } // END - if
1350
1351         // Return cache
1352         return $GLOBALS[__FUNCTION__][$timestamp];
1353 }
1354
1355 // Getter for current month (default)
1356 function getMonth ($timestamp = NULL) {
1357         // Is it cached?
1358         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1359                 // If null is set, use time()
1360                 if (is_null($timestamp)) {
1361                         // Use time() which is current timestamp
1362                         $timestamp = time();
1363                 } // END - if
1364
1365                 // Then create it
1366                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1367         } // END - if
1368
1369         // Return cache
1370         return $GLOBALS[__FUNCTION__][$timestamp];
1371 }
1372
1373 // Getter for current hour (default)
1374 function getHour ($timestamp = NULL) {
1375         // Is it cached?
1376         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1377                 // null is time()
1378                 if (is_null($timestamp)) {
1379                         $timestamp = time();
1380                 } // END - if
1381
1382                 // Then create it
1383                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1384         } // END - if
1385
1386         // Return cache
1387         return $GLOBALS[__FUNCTION__][$timestamp];
1388 }
1389
1390 // Getter for current day (default)
1391 function getDay ($timestamp = NULL) {
1392         // Is it cached?
1393         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1394                 // null is time()
1395                 if (is_null($timestamp)) {
1396                         $timestamp = time();
1397                 } // END - if
1398
1399                 // Then create it
1400                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1401         } // END - if
1402
1403         // Return cache
1404         return $GLOBALS[__FUNCTION__][$timestamp];
1405 }
1406
1407 // Getter for current week (default)
1408 function getWeek ($timestamp = NULL) {
1409         // Is it cached?
1410         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1411                 // null is time()
1412                 if (is_null($timestamp)) $timestamp = time();
1413
1414                 // Then create it
1415                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1416         } // END - if
1417
1418         // Return cache
1419         return $GLOBALS[__FUNCTION__][$timestamp];
1420 }
1421
1422 // Getter for current short_hour (default)
1423 function getShortHour ($timestamp = NULL) {
1424         // Is it cached?
1425         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1426                 // null is time()
1427                 if (is_null($timestamp)) $timestamp = time();
1428
1429                 // Then create it
1430                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1431         } // END - if
1432
1433         // Return cache
1434         return $GLOBALS[__FUNCTION__][$timestamp];
1435 }
1436
1437 // Getter for current long_hour (default)
1438 function getLongHour ($timestamp = NULL) {
1439         // Is it cached?
1440         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1441                 // null is time()
1442                 if (is_null($timestamp)) $timestamp = time();
1443
1444                 // Then create it
1445                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1446         } // END - if
1447
1448         // Return cache
1449         return $GLOBALS[__FUNCTION__][$timestamp];
1450 }
1451
1452 // Getter for current second (default)
1453 function getSecond ($timestamp = NULL) {
1454         // Is it cached?
1455         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1456                 // null is time()
1457                 if (is_null($timestamp)) $timestamp = time();
1458
1459                 // Then create it
1460                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1461         } // END - if
1462
1463         // Return cache
1464         return $GLOBALS[__FUNCTION__][$timestamp];
1465 }
1466
1467 // Getter for current minute (default)
1468 function getMinute ($timestamp = NULL) {
1469         // Is it cached?
1470         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1471                 // null is time()
1472                 if (is_null($timestamp)) $timestamp = time();
1473
1474                 // Then create it
1475                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1476         } // END - if
1477
1478         // Return cache
1479         return $GLOBALS[__FUNCTION__][$timestamp];
1480 }
1481
1482 // Checks whether the title decoration is enabled
1483 function isTitleDecorationEnabled () {
1484         // Is there cache?
1485         if (!isset($GLOBALS[__FUNCTION__])) {
1486                 // Just check it
1487                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1488         } // END - if
1489
1490         // Return cache
1491         return $GLOBALS[__FUNCTION__];
1492 }
1493
1494 // Checks whether filter usage updates are enabled (expensive queries!)
1495 function isFilterUsageUpdateEnabled () {
1496         // Is there cache?
1497         if (!isset($GLOBALS[__FUNCTION__])) {
1498                 // Determine it
1499                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1500         } // END - if
1501
1502         // Return cache
1503         return $GLOBALS[__FUNCTION__];
1504 }
1505
1506 // Checks whether debugging of weekly resets is enabled
1507 function isWeeklyResetDebugEnabled () {
1508         // Is there cache?
1509         if (!isset($GLOBALS[__FUNCTION__])) {
1510                 // Determine it
1511                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1512         } // END - if
1513
1514         // Return cache
1515         return $GLOBALS[__FUNCTION__];
1516 }
1517
1518 // Checks whether debugging of monthly resets is enabled
1519 function isMonthlyResetDebugEnabled () {
1520         // Is there cache?
1521         if (!isset($GLOBALS[__FUNCTION__])) {
1522                 // Determine it
1523                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1524         } // END - if
1525
1526         // Return cache
1527         return $GLOBALS[__FUNCTION__];
1528 }
1529
1530 // Checks whether displaying of debug SQLs are enabled
1531 function isDisplayDebugSqlEnabled () {
1532         // Is there cache?
1533         if (!isset($GLOBALS[__FUNCTION__])) {
1534                 // Determine it
1535                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1536         } // END - if
1537
1538         // Return cache
1539         return $GLOBALS[__FUNCTION__];
1540 }
1541
1542 // Checks whether module title is enabled
1543 function isModuleTitleEnabled () {
1544         // Is there cache?
1545         if (!isset($GLOBALS[__FUNCTION__])) {
1546                 // Determine it
1547                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1548         } // END - if
1549
1550         // Return cache
1551         return $GLOBALS[__FUNCTION__];
1552 }
1553
1554 // Checks whether what title is enabled
1555 function isWhatTitleEnabled () {
1556         // Is there cache?
1557         if (!isset($GLOBALS[__FUNCTION__])) {
1558                 // Determine it
1559                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1560         } // END - if
1561
1562         // Return cache
1563         return $GLOBALS[__FUNCTION__];
1564 }
1565
1566 // Checks whether stats are enabled
1567 function ifInternalStatsEnabled () {
1568         // Is there cache?
1569         if (!isset($GLOBALS[__FUNCTION__])) {
1570                 // Then determine it
1571                 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1572         } // END - if
1573
1574         // Return cached value
1575         return $GLOBALS[__FUNCTION__];
1576 }
1577
1578 // Checks whether admin-notification of certain user actions is enabled
1579 function isAdminNotificationEnabled () {
1580         // Is there cache?
1581         if (!isset($GLOBALS[__FUNCTION__])) {
1582                 // Determine it
1583                 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1584         } // END - if
1585
1586         // Return cache
1587         return $GLOBALS[__FUNCTION__];
1588 }
1589
1590 // Checks whether random referral id selection is enabled
1591 function isRandomReferralIdEnabled () {
1592         // Is there cache?
1593         if (!isset($GLOBALS[__FUNCTION__])) {
1594                 // Determine it
1595                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1596         } // END - if
1597
1598         // Return cache
1599         return $GLOBALS[__FUNCTION__];
1600 }
1601
1602 // "Getter" for default language
1603 function getDefaultLanguage () {
1604         // Is there cache?
1605         if (!isset($GLOBALS[__FUNCTION__])) {
1606                 // Determine it
1607                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1608         } // END - if
1609
1610         // Return cache
1611         return $GLOBALS[__FUNCTION__];
1612 }
1613
1614 // "Getter" for default referral id
1615 function getDefRefid () {
1616         // Is there cache?
1617         if (!isset($GLOBALS[__FUNCTION__])) {
1618                 // Determine it
1619                 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1620         } // END - if
1621
1622         // Return cache
1623         return $GLOBALS[__FUNCTION__];
1624 }
1625
1626 // "Getter" for path
1627 function getPath () {
1628         // Is there cache?
1629         if (!isset($GLOBALS[__FUNCTION__])) {
1630                 // Determine it
1631                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1632         } // END - if
1633
1634         // Return cache
1635         return $GLOBALS[__FUNCTION__];
1636 }
1637
1638 // "Getter" for url
1639 function getUrl () {
1640         // Is there cache?
1641         if (!isset($GLOBALS[__FUNCTION__])) {
1642                 // Determine it
1643                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1644         } // END - if
1645
1646         // Return cache
1647         return $GLOBALS[__FUNCTION__];
1648 }
1649
1650 // "Getter" for cache_path
1651 function getCachePath () {
1652         // Is there cache?
1653         if (!isset($GLOBALS[__FUNCTION__])) {
1654                 // Determine it
1655                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1656         } // END - if
1657
1658         // Return cache
1659         return $GLOBALS[__FUNCTION__];
1660 }
1661
1662 // "Getter" for secret_key
1663 function getSecretKey () {
1664         // Is there cache?
1665         if (!isset($GLOBALS[__FUNCTION__])) {
1666                 // Determine it
1667                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1668         } // END - if
1669
1670         // Return cache
1671         return $GLOBALS[__FUNCTION__];
1672 }
1673
1674 // "Getter" for SITE_KEY
1675 function getSiteKey () {
1676         // Is there cache?
1677         if (!isset($GLOBALS[__FUNCTION__])) {
1678                 // Determine it
1679                 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1680         } // END - if
1681
1682         // Return cache
1683         return $GLOBALS[__FUNCTION__];
1684 }
1685
1686 // "Getter" for DATE_KEY
1687 function getDateKey () {
1688         // Is there cache?
1689         if (!isset($GLOBALS[__FUNCTION__])) {
1690                 // Determine it
1691                 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1692         } // END - if
1693
1694         // Return cache
1695         return $GLOBALS[__FUNCTION__];
1696 }
1697
1698 // "Getter" for master_salt
1699 function getMasterSalt () {
1700         // Is there cache?
1701         if (!isset($GLOBALS[__FUNCTION__])) {
1702                 // Determine it
1703                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1704         } // END - if
1705
1706         // Return cache
1707         return $GLOBALS[__FUNCTION__];
1708 }
1709
1710 // "Getter" for prime
1711 function getPrime () {
1712         // Is there cache?
1713         if (!isset($GLOBALS[__FUNCTION__])) {
1714                 // Determine it
1715                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1716         } // END - if
1717
1718         // Return cache
1719         return $GLOBALS[__FUNCTION__];
1720 }
1721
1722 // "Getter" for encrypt_separator
1723 function getEncryptSeparator () {
1724         // Is there cache?
1725         if (!isset($GLOBALS[__FUNCTION__])) {
1726                 // Determine it
1727                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1728         } // END - if
1729
1730         // Return cache
1731         return $GLOBALS[__FUNCTION__];
1732 }
1733
1734 // "Getter" for mysql_prefix
1735 function getMysqlPrefix () {
1736         // Is there cache?
1737         if (!isset($GLOBALS[__FUNCTION__])) {
1738                 // Determine it
1739                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1740         } // END - if
1741
1742         // Return cache
1743         return $GLOBALS[__FUNCTION__];
1744 }
1745
1746 // "Getter" for table_type
1747 function getTableType () {
1748         // Is there cache?
1749         if (!isset($GLOBALS[__FUNCTION__])) {
1750                 // Determine it
1751                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1752         } // END - if
1753
1754         // Return cache
1755         return $GLOBALS[__FUNCTION__];
1756 }
1757
1758 // "Getter" for salt_length
1759 function getSaltLength () {
1760         // Is there cache?
1761         if (!isset($GLOBALS[__FUNCTION__])) {
1762                 // Determine it
1763                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1764         } // END - if
1765
1766         // Return cache
1767         return $GLOBALS[__FUNCTION__];
1768 }
1769
1770 // "Getter" for output_mode
1771 function getOutputMode () {
1772         // Is there cache?
1773         if (!isset($GLOBALS[__FUNCTION__])) {
1774                 // Determine it
1775                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1776         } // END - if
1777
1778         // Return cache
1779         return $GLOBALS[__FUNCTION__];
1780 }
1781
1782 // "Getter" for full_version
1783 function getFullVersion () {
1784         // Is there cache?
1785         if (!isset($GLOBALS[__FUNCTION__])) {
1786                 // Determine it
1787                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1788         } // END - if
1789
1790         // Return cache
1791         return $GLOBALS[__FUNCTION__];
1792 }
1793
1794 // "Getter" for title
1795 function getTitle () {
1796         // Is there cache?
1797         if (!isset($GLOBALS[__FUNCTION__])) {
1798                 // Determine it
1799                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1800         } // END - if
1801
1802         // Return cache
1803         return $GLOBALS[__FUNCTION__];
1804 }
1805
1806 // "Getter" for curr_svn_revision
1807 function getCurrentRepositoryRevision () {
1808         // Is there cache?
1809         if (!isset($GLOBALS[__FUNCTION__])) {
1810                 // Determine it
1811                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1812         } // END - if
1813
1814         // Return cache
1815         return $GLOBALS[__FUNCTION__];
1816 }
1817
1818 // "Getter" for server_url
1819 function getServerUrl () {
1820         // Is there cache?
1821         if (!isset($GLOBALS[__FUNCTION__])) {
1822                 // Determine it
1823                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1824         } // END - if
1825
1826         // Return cache
1827         return $GLOBALS[__FUNCTION__];
1828 }
1829
1830 // "Getter" for mt_word
1831 function getMtWord () {
1832         // Is there cache?
1833         if (!isset($GLOBALS[__FUNCTION__])) {
1834                 // Determine it
1835                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1836         } // END - if
1837
1838         // Return cache
1839         return $GLOBALS[__FUNCTION__];
1840 }
1841
1842 // "Getter" for mt_word2
1843 function getMtWord2 () {
1844         // Is there cache?
1845         if (!isset($GLOBALS[__FUNCTION__])) {
1846                 // Determine it
1847                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1848         } // END - if
1849
1850         // Return cache
1851         return $GLOBALS[__FUNCTION__];
1852 }
1853
1854 // "Getter" for mt_word3
1855 function getMtWord3 () {
1856         // Is there cache?
1857         if (!isset($GLOBALS[__FUNCTION__])) {
1858                 // Determine it
1859                 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
1860         } // END - if
1861
1862         // Return cache
1863         return $GLOBALS[__FUNCTION__];
1864 }
1865
1866 // "Getter" for START_TDAY
1867 function getStartTday () {
1868         // Is there cache?
1869         if (!isset($GLOBALS[__FUNCTION__])) {
1870                 // Determine it
1871                 $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
1872         } // END - if
1873
1874         // Return cache
1875         return $GLOBALS[__FUNCTION__];
1876 }
1877
1878 // "Getter" for START_YDAY
1879 function getStartYday () {
1880         // Is there cache?
1881         if (!isset($GLOBALS[__FUNCTION__])) {
1882                 // Determine it
1883                 $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
1884         } // END - if
1885
1886         // Return cache
1887         return $GLOBALS[__FUNCTION__];
1888 }
1889
1890 // "Getter" for main_title
1891 function getMainTitle () {
1892         // Is there cache?
1893         if (!isset($GLOBALS[__FUNCTION__])) {
1894                 // Determine it
1895                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1896         } // END - if
1897
1898         // Return cache
1899         return $GLOBALS[__FUNCTION__];
1900 }
1901
1902 // "Getter" for file_hash
1903 function getFileHash () {
1904         // Is there cache?
1905         if (!isset($GLOBALS[__FUNCTION__])) {
1906                 // Determine it
1907                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1908         } // END - if
1909
1910         // Return cache
1911         return $GLOBALS[__FUNCTION__];
1912 }
1913
1914 // "Getter" for pass_scramble
1915 function getPassScramble () {
1916         // Is there cache?
1917         if (!isset($GLOBALS[__FUNCTION__])) {
1918                 // Determine it
1919                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1920         } // END - if
1921
1922         // Return cache
1923         return $GLOBALS[__FUNCTION__];
1924 }
1925
1926 // "Getter" for ap_inactive_since
1927 function getApInactiveSince () {
1928         // Is there cache?
1929         if (!isset($GLOBALS[__FUNCTION__])) {
1930                 // Determine it
1931                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1932         } // END - if
1933
1934         // Return cache
1935         return $GLOBALS[__FUNCTION__];
1936 }
1937
1938 // "Getter" for user_min_confirmed
1939 function getUserMinConfirmed () {
1940         // Is there cache?
1941         if (!isset($GLOBALS[__FUNCTION__])) {
1942                 // Determine it
1943                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1944         } // END - if
1945
1946         // Return cache
1947         return $GLOBALS[__FUNCTION__];
1948 }
1949
1950 // "Getter" for auto_purge
1951 function getAutoPurge () {
1952         // Is there cache?
1953         if (!isset($GLOBALS[__FUNCTION__])) {
1954                 // Determine it
1955                 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1956         } // END - if
1957
1958         // Return cache
1959         return $GLOBALS[__FUNCTION__];
1960 }
1961
1962 // "Getter" for bonus_userid
1963 function getBonusUserid () {
1964         // Is there cache?
1965         if (!isset($GLOBALS[__FUNCTION__])) {
1966                 // Determine it
1967                 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1968         } // END - if
1969
1970         // Return cache
1971         return $GLOBALS[__FUNCTION__];
1972 }
1973
1974 // "Getter" for ap_inactive_time
1975 function getApInactiveTime () {
1976         // Is there cache?
1977         if (!isset($GLOBALS[__FUNCTION__])) {
1978                 // Determine it
1979                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1980         } // END - if
1981
1982         // Return cache
1983         return $GLOBALS[__FUNCTION__];
1984 }
1985
1986 // "Getter" for ap_dm_timeout
1987 function getApDmTimeout () {
1988         // Is there cache?
1989         if (!isset($GLOBALS[__FUNCTION__])) {
1990                 // Determine it
1991                 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1992         } // END - if
1993
1994         // Return cache
1995         return $GLOBALS[__FUNCTION__];
1996 }
1997
1998 // "Getter" for ap_tasks_time
1999 function getApTasksTime () {
2000         // Is there cache?
2001         if (!isset($GLOBALS[__FUNCTION__])) {
2002                 // Determine it
2003                 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
2004         } // END - if
2005
2006         // Return cache
2007         return $GLOBALS[__FUNCTION__];
2008 }
2009
2010 // "Getter" for ap_unconfirmed_time
2011 function getApUnconfirmedTime () {
2012         // Is there cache?
2013         if (!isset($GLOBALS[__FUNCTION__])) {
2014                 // Determine it
2015                 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
2016         } // END - if
2017
2018         // Return cache
2019         return $GLOBALS[__FUNCTION__];
2020 }
2021
2022 // "Getter" for points
2023 function getPoints () {
2024         // Is there cache?
2025         if (!isset($GLOBALS[__FUNCTION__])) {
2026                 // Determine it
2027                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
2028         } // END - if
2029
2030         // Return cache
2031         return $GLOBALS[__FUNCTION__];
2032 }
2033
2034 // "Getter" for slogan
2035 function getSlogan () {
2036         // Is there cache?
2037         if (!isset($GLOBALS[__FUNCTION__])) {
2038                 // Determine it
2039                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
2040         } // END - if
2041
2042         // Return cache
2043         return $GLOBALS[__FUNCTION__];
2044 }
2045
2046 // "Getter" for copy
2047 function getCopy () {
2048         // Is there cache?
2049         if (!isset($GLOBALS[__FUNCTION__])) {
2050                 // Determine it
2051                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
2052         } // END - if
2053
2054         // Return cache
2055         return $GLOBALS[__FUNCTION__];
2056 }
2057
2058 // "Getter" for webmaster
2059 function getWebmaster () {
2060         // Is there cache?
2061         if (!isset($GLOBALS[__FUNCTION__])) {
2062                 // Determine it
2063                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
2064         } // END - if
2065
2066         // Return cache
2067         return $GLOBALS[__FUNCTION__];
2068 }
2069
2070 // "Getter" for sql_count
2071 function getSqlCount () {
2072         // Is there cache?
2073         if (!isset($GLOBALS[__FUNCTION__])) {
2074                 // Determine it
2075                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2076         } // END - if
2077
2078         // Return cache
2079         return $GLOBALS[__FUNCTION__];
2080 }
2081
2082 // "Getter" for num_templates
2083 function getNumTemplates () {
2084         // Is there cache?
2085         if (!isset($GLOBALS[__FUNCTION__])) {
2086                 // Determine it
2087                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2088         } // END - if
2089
2090         // Return cache
2091         return $GLOBALS[__FUNCTION__];
2092 }
2093
2094 // "Getter" for dns_cache_timeout
2095 function getDnsCacheTimeout () {
2096         // Is there cache?
2097         if (!isset($GLOBALS[__FUNCTION__])) {
2098                 // Determine it
2099                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2100         } // END - if
2101
2102         // Return cache
2103         return $GLOBALS[__FUNCTION__];
2104 }
2105
2106 // "Getter" for menu_blur_spacer
2107 function getMenuBlurSpacer () {
2108         // Is there cache?
2109         if (!isset($GLOBALS[__FUNCTION__])) {
2110                 // Determine it
2111                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2112         } // END - if
2113
2114         // Return cache
2115         return $GLOBALS[__FUNCTION__];
2116 }
2117
2118 // "Getter" for points_register
2119 function getPointsRegister () {
2120         // Is there cache?
2121         if (!isset($GLOBALS[__FUNCTION__])) {
2122                 // Determine it
2123                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2124         } // END - if
2125
2126         // Return cache
2127         return $GLOBALS[__FUNCTION__];
2128 }
2129
2130 // "Getter" for points_ref
2131 function getPointsRef () {
2132         // Is there cache?
2133         if (!isset($GLOBALS[__FUNCTION__])) {
2134                 // Determine it
2135                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2136         } // END - if
2137
2138         // Return cache
2139         return $GLOBALS[__FUNCTION__];
2140 }
2141
2142 // "Getter" for ref_payout
2143 function getRefPayout () {
2144         // Is there cache?
2145         if (!isset($GLOBALS[__FUNCTION__])) {
2146                 // Determine it
2147                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2148         } // END - if
2149
2150         // Return cache
2151         return $GLOBALS[__FUNCTION__];
2152 }
2153
2154 // "Getter" for online_timeout
2155 function getOnlineTimeout () {
2156         // Is there cache?
2157         if (!isset($GLOBALS[__FUNCTION__])) {
2158                 // Determine it
2159                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2160         } // END - if
2161
2162         // Return cache
2163         return $GLOBALS[__FUNCTION__];
2164 }
2165
2166 // "Getter" for index_home
2167 function getIndexHome () {
2168         // Is there cache?
2169         if (!isset($GLOBALS[__FUNCTION__])) {
2170                 // Determine it
2171                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2172         } // END - if
2173
2174         // Return cache
2175         return $GLOBALS[__FUNCTION__];
2176 }
2177
2178 // "Getter" for one_day
2179 function getOneDay () {
2180         // Is there cache?
2181         if (!isset($GLOBALS[__FUNCTION__])) {
2182                 // Determine it
2183                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2184         } // END - if
2185
2186         // Return cache
2187         return $GLOBALS[__FUNCTION__];
2188 }
2189
2190 // "Getter" for activate_xchange
2191 function getActivateXchange () {
2192         // Is there cache?
2193         if (!isset($GLOBALS[__FUNCTION__])) {
2194                 // Determine it
2195                 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2196         } // END - if
2197
2198         // Return cache
2199         return $GLOBALS[__FUNCTION__];
2200 }
2201
2202 // "Getter" for img_type
2203 function getImgType () {
2204         // Is there cache?
2205         if (!isset($GLOBALS[__FUNCTION__])) {
2206                 // Determine it
2207                 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2208         } // END - if
2209
2210         // Return cache
2211         return $GLOBALS[__FUNCTION__];
2212 }
2213
2214 // "Getter" for code_length
2215 function getCodeLength () {
2216         // Is there cache?
2217         if (!isset($GLOBALS[__FUNCTION__])) {
2218                 // Determine it
2219                 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2220         } // END - if
2221
2222         // Return cache
2223         return $GLOBALS[__FUNCTION__];
2224 }
2225
2226 // "Getter" for least_cats
2227 function getLeastCats () {
2228         // Is there cache?
2229         if (!isset($GLOBALS[__FUNCTION__])) {
2230                 // Determine it
2231                 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2232         } // END - if
2233
2234         // Return cache
2235         return $GLOBALS[__FUNCTION__];
2236 }
2237
2238 // "Getter" for pass_len
2239 function getPassLen () {
2240         // Is there cache?
2241         if (!isset($GLOBALS[__FUNCTION__])) {
2242                 // Determine it
2243                 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2244         } // END - if
2245
2246         // Return cache
2247         return $GLOBALS[__FUNCTION__];
2248 }
2249
2250 // "Getter" for admin_menu
2251 function getAdminMenu () {
2252         // Is there cache?
2253         if (!isset($GLOBALS[__FUNCTION__])) {
2254                 // Determine it
2255                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2256         } // END - if
2257
2258         // Return cache
2259         return $GLOBALS[__FUNCTION__];
2260 }
2261
2262 // "Getter" for last_month
2263 function getLastMonth () {
2264         // Is there cache?
2265         if (!isset($GLOBALS[__FUNCTION__])) {
2266                 // Determine it
2267                 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2268         } // END - if
2269
2270         // Return cache
2271         return $GLOBALS[__FUNCTION__];
2272 }
2273
2274 // "Getter" for max_send
2275 function getMaxSend () {
2276         // Is there cache?
2277         if (!isset($GLOBALS[__FUNCTION__])) {
2278                 // Determine it
2279                 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2280         } // END - if
2281
2282         // Return cache
2283         return $GLOBALS[__FUNCTION__];
2284 }
2285
2286 // "Getter" for mails_page
2287 function getMailsPage () {
2288         // Is there cache?
2289         if (!isset($GLOBALS[__FUNCTION__])) {
2290                 // Determine it
2291                 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2292         } // END - if
2293
2294         // Return cache
2295         return $GLOBALS[__FUNCTION__];
2296 }
2297
2298 // "Getter" for rand_no
2299 function getRandNo () {
2300         // Is there cache?
2301         if (!isset($GLOBALS[__FUNCTION__])) {
2302                 // Determine it
2303                 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2304         } // END - if
2305
2306         // Return cache
2307         return $GLOBALS[__FUNCTION__];
2308 }
2309
2310 // "Getter" for __DB_NAME
2311 function getDbName () {
2312         // Is there cache?
2313         if (!isset($GLOBALS[__FUNCTION__])) {
2314                 // Determine it
2315                 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2316         } // END - if
2317
2318         // Return cache
2319         return $GLOBALS[__FUNCTION__];
2320 }
2321
2322 // "Getter" for DOMAIN
2323 function getDomain () {
2324         // Is there cache?
2325         if (!isset($GLOBALS[__FUNCTION__])) {
2326                 // Determine it
2327                 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2328         } // END - if
2329
2330         // Return cache
2331         return $GLOBALS[__FUNCTION__];
2332 }
2333
2334 // "Getter" for proxy_username
2335 function getProxyUsername () {
2336         // Is there cache?
2337         if (!isset($GLOBALS[__FUNCTION__])) {
2338                 // Determine it
2339                 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2340         } // END - if
2341
2342         // Return cache
2343         return $GLOBALS[__FUNCTION__];
2344 }
2345
2346 // "Getter" for proxy_password
2347 function getProxyPassword () {
2348         // Is there cache?
2349         if (!isset($GLOBALS[__FUNCTION__])) {
2350                 // Determine it
2351                 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2352         } // END - if
2353
2354         // Return cache
2355         return $GLOBALS[__FUNCTION__];
2356 }
2357
2358 // "Getter" for proxy_host
2359 function getProxyHost () {
2360         // Is there cache?
2361         if (!isset($GLOBALS[__FUNCTION__])) {
2362                 // Determine it
2363                 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2364         } // END - if
2365
2366         // Return cache
2367         return $GLOBALS[__FUNCTION__];
2368 }
2369
2370 // "Getter" for proxy_port
2371 function getProxyPort () {
2372         // Is there cache?
2373         if (!isset($GLOBALS[__FUNCTION__])) {
2374                 // Determine it
2375                 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2376         } // END - if
2377
2378         // Return cache
2379         return $GLOBALS[__FUNCTION__];
2380 }
2381
2382 // "Getter" for SMTP_HOSTNAME
2383 function getSmtpHostname () {
2384         // Is there cache?
2385         if (!isset($GLOBALS[__FUNCTION__])) {
2386                 // Determine it
2387                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2388         } // END - if
2389
2390         // Return cache
2391         return $GLOBALS[__FUNCTION__];
2392 }
2393
2394 // "Getter" for SMTP_USER
2395 function getSmtpUser () {
2396         // Is there cache?
2397         if (!isset($GLOBALS[__FUNCTION__])) {
2398                 // Determine it
2399                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2400         } // END - if
2401
2402         // Return cache
2403         return $GLOBALS[__FUNCTION__];
2404 }
2405
2406 // "Getter" for SMTP_PASSWORD
2407 function getSmtpPassword () {
2408         // Is there cache?
2409         if (!isset($GLOBALS[__FUNCTION__])) {
2410                 // Determine it
2411                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2412         } // END - if
2413
2414         // Return cache
2415         return $GLOBALS[__FUNCTION__];
2416 }
2417
2418 // "Getter" for points_word
2419 function getPointsWord () {
2420         // Is there cache?
2421         if (!isset($GLOBALS[__FUNCTION__])) {
2422                 // Determine it
2423                 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2424         } // END - if
2425
2426         // Return cache
2427         return $GLOBALS[__FUNCTION__];
2428 }
2429
2430 // "Getter" for profile_lock
2431 function getProfileLock () {
2432         // Is there cache?
2433         if (!isset($GLOBALS[__FUNCTION__])) {
2434                 // Determine it
2435                 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2436         } // END - if
2437
2438         // Return cache
2439         return $GLOBALS[__FUNCTION__];
2440 }
2441
2442 // "Getter" for url_tlock
2443 function getUrlTlock () {
2444         // Is there cache?
2445         if (!isset($GLOBALS[__FUNCTION__])) {
2446                 // Determine it
2447                 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2448         } // END - if
2449
2450         // Return cache
2451         return $GLOBALS[__FUNCTION__];
2452 }
2453
2454 // "Getter" for title_left
2455 function getTitleLeft () {
2456         // Is there cache?
2457         if (!isset($GLOBALS[__FUNCTION__])) {
2458                 // Determine it
2459                 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2460         } // END - if
2461
2462         // Return cache
2463         return $GLOBALS[__FUNCTION__];
2464 }
2465
2466 // "Getter" for title_right
2467 function getTitleRight () {
2468         // Is there cache?
2469         if (!isset($GLOBALS[__FUNCTION__])) {
2470                 // Determine it
2471                 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2472         } // END - if
2473
2474         // Return cache
2475         return $GLOBALS[__FUNCTION__];
2476 }
2477
2478 // "Getter" for title_middle
2479 function getTitleMiddle () {
2480         // Is there cache?
2481         if (!isset($GLOBALS[__FUNCTION__])) {
2482                 // Determine it
2483                 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2484         } // END - if
2485
2486         // Return cache
2487         return $GLOBALS[__FUNCTION__];
2488 }
2489
2490 // Getter for 'check_double_email'
2491 function getCheckDoubleEmail () {
2492         // Is the cache entry set?
2493         if (!isset($GLOBALS[__FUNCTION__])) {
2494                 // No, so determine it
2495                 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2496         } // END - if
2497
2498         // Return cached entry
2499         return $GLOBALS[__FUNCTION__];
2500 }
2501
2502 // Checks whether 'check_double_email' is 'Y'
2503 function isCheckDoubleEmailEnabled () {
2504         // Is the cache entry set?
2505         if (!isset($GLOBALS[__FUNCTION__])) {
2506                 // No, so determine it
2507                 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2508         } // END - if
2509
2510         // Return cached entry
2511         return $GLOBALS[__FUNCTION__];
2512 }
2513
2514 // Getter for 'display_home_in_index'
2515 function getDisplayHomeInIndex () {
2516         // Is the cache entry set?
2517         if (!isset($GLOBALS[__FUNCTION__])) {
2518                 // No, so determine it
2519                 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2520         } // END - if
2521
2522         // Return cached entry
2523         return $GLOBALS[__FUNCTION__];
2524 }
2525
2526 // Checks whether 'display_home_in_index' is 'Y'
2527 function isDisplayHomeInIndexEnabled () {
2528         // Is the cache entry set?
2529         if (!isset($GLOBALS[__FUNCTION__])) {
2530                 // No, so determine it
2531                 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2532         } // END - if
2533
2534         // Return cached entry
2535         return $GLOBALS[__FUNCTION__];
2536 }
2537
2538 // Getter for 'admin_menu_javascript'
2539 function getAdminMenuJavascript () {
2540         // Is the cache entry set?
2541         if (!isset($GLOBALS[__FUNCTION__])) {
2542                 // No, so determine it
2543                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2544         } // END - if
2545
2546         // Return cached entry
2547         return $GLOBALS[__FUNCTION__];
2548 }
2549
2550 // Getter for 'points_remove_account'
2551 function getPointsRemoveAccount () {
2552         // Is the cache entry set?
2553         if (!isset($GLOBALS[__FUNCTION__])) {
2554                 // No, so determine it
2555                 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2556         } // END - if
2557
2558         // Return cached entry
2559         return $GLOBALS[__FUNCTION__];
2560 }
2561
2562 // Checks whether proxy configuration is used
2563 function isProxyUsed () {
2564         // Is there cache?
2565         if (!isset($GLOBALS[__FUNCTION__])) {
2566                 // Determine it
2567                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2568         } // END - if
2569
2570         // Return cache
2571         return $GLOBALS[__FUNCTION__];
2572 }
2573
2574 // Checks whether POST data contains selections
2575 function ifPostContainsSelections ($element = 'sel') {
2576         // Is there cache?
2577         if (!isset($GLOBALS[__FUNCTION__][$element])) {
2578                 // Determine it
2579                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2580         } // END - if
2581
2582         // Return cache
2583         return $GLOBALS[__FUNCTION__][$element];
2584 }
2585
2586 // Checks whether verbose_sql is Y and returns true/false if so
2587 function isVerboseSqlEnabled () {
2588         // Is there cache?
2589         if (!isset($GLOBALS[__FUNCTION__])) {
2590                 // Determine it
2591                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2592         } // END - if
2593
2594         // Return cache
2595         return $GLOBALS[__FUNCTION__];
2596 }
2597
2598 // "Getter" for total user points
2599 function getTotalPoints ($userid) {
2600         // Is there cache?
2601         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2602                 // Init array for filter chain
2603                 $data = array(
2604                         'userid' => $userid,
2605                         'points' => 0
2606                 );
2607
2608                 // Run filter chain for getting more point values
2609                 $data = runFilterChain('get_total_points', $data);
2610
2611                 // Determine it
2612                 $GLOBALS[__FUNCTION__][$userid] = $data['points']  - getUserUsedPoints($userid);
2613         } // END - if
2614
2615         // Return cache
2616         return $GLOBALS[__FUNCTION__][$userid];
2617 }
2618
2619 // Wrapper to get used points for given userid
2620 function getUserUsedPoints ($userid) {
2621         // Is there cache?
2622         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2623                 // Determine it
2624                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2625         } // END - if
2626
2627         // Return cache
2628         return $GLOBALS[__FUNCTION__][$userid];
2629 }
2630
2631 // Wrapper to check if url_blacklist is enabled
2632 function isUrlBlacklistEnabled () {
2633         // Is there cache?
2634         if (!isset($GLOBALS[__FUNCTION__])) {
2635                 // Determine it
2636                 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2637         } // END - if
2638
2639         // Return cache
2640         return $GLOBALS[__FUNCTION__];
2641 }
2642
2643 // Checks whether direct payment is allowed in configuration
2644 function isDirectPaymentEnabled () {
2645         // Is there cache?
2646         if (!isset($GLOBALS[__FUNCTION__])) {
2647                 // Determine it
2648                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2649         } // END - if
2650
2651         // Return cache
2652         return $GLOBALS[__FUNCTION__];
2653 }
2654
2655 // Checks whether JavaScript-based admin menu is enabled
2656 function isAdminMenuJavascriptEnabled () {
2657         // Is there cache?
2658         if (!isset($GLOBALS[__FUNCTION__])) {
2659                 // Determine it
2660                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
2661         } // END - if
2662
2663         // Return cache
2664         return $GLOBALS[__FUNCTION__];
2665 }
2666
2667 // Wrapper to check if current task is for extension (not update)
2668 function isExtensionTask ($content) {
2669         // Is there cache?
2670         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2671                 // Determine it
2672                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2673         } // END - if
2674
2675         // Return cache
2676         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2677 }
2678
2679 // Getter for 'mt_start'
2680 function getMtStart () {
2681         // Is the cache entry set?
2682         if (!isset($GLOBALS[__FUNCTION__])) {
2683                 // No, so determine it
2684                 $GLOBALS[__FUNCTION__] = getConfig('mt_start');
2685         } // END - if
2686
2687         // Return cached entry
2688         return $GLOBALS[__FUNCTION__];
2689 }
2690
2691 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2692 function ifTesterAccountsAllowed () {
2693         // Is the cache entry set?
2694         if (!isset($GLOBALS[__FUNCTION__])) {
2695                 // No, so determine it
2696                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2697         } // END - if
2698
2699         // Return cached entry
2700         return $GLOBALS[__FUNCTION__];
2701 }
2702
2703 // Wrapper to check if output mode is CSS
2704 function isCssOutputMode () {
2705         // Is cache set?
2706         if (!isset($GLOBALS[__FUNCTION__])) {
2707                 // Determine it
2708                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2709                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2710         } // END - if
2711
2712         // Return cache
2713         return $GLOBALS[__FUNCTION__];
2714 }
2715
2716 // Wrapper to check if output mode is HTML
2717 function isHtmlOutputMode () {
2718         // Is cache set?
2719         if (!isset($GLOBALS[__FUNCTION__])) {
2720                 // Determine it
2721                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2722                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2723         } // END - if
2724
2725         // Return cache
2726         return $GLOBALS[__FUNCTION__];
2727 }
2728
2729 // Wrapper to check if output mode is RAW
2730 function isRawOutputMode () {
2731         // Is cache set?
2732         if (!isset($GLOBALS[__FUNCTION__])) {
2733                 // Determine it
2734                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2735                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2736         } // END - if
2737
2738         // Return cache
2739         return $GLOBALS[__FUNCTION__];
2740 }
2741
2742 // Wrapper to check if output mode is AJAX
2743 function isAjaxOutputMode () {
2744         // Is cache set?
2745         if (!isset($GLOBALS[__FUNCTION__])) {
2746                 // Determine it
2747                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2748                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2749         } // END - if
2750
2751         // Return cache
2752         return $GLOBALS[__FUNCTION__];
2753 }
2754
2755 // Wrapper to check if output mode is image
2756 function isImageOutputMode () {
2757         // Is cache set?
2758         if (!isset($GLOBALS[__FUNCTION__])) {
2759                 // Determine it
2760                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2761                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
2762         } // END - if
2763
2764         // Return cache
2765         return $GLOBALS[__FUNCTION__];
2766 }
2767
2768 // Wrapper to generate a user email link
2769 function generateWrappedUserEmailLink ($email) {
2770         // Just call the inner function
2771         return generateEmailLink($email, 'user_data');
2772 }
2773
2774 // Wrapper to check if user points are locked
2775 function ifUserPointsLocked ($userid) {
2776         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2777         // Is there cache?
2778         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2779                 // Determine it
2780                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2781         } // END - if
2782
2783         // Return cache
2784         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2785         return $GLOBALS[__FUNCTION__][$userid];
2786 }
2787
2788 // Appends a line to an existing file or creates it instantly with given content.
2789 // This function does always add a new-line character to every line.
2790 function appendLineToFile ($file, $line) {
2791         $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2792         fwrite($fp, $line . chr(10));
2793         fclose($fp);
2794 }
2795
2796 // Wrapper for changeDataInFile() but with full path added
2797 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2798         // Add full path
2799         $FQFN = getPath() . $FQFN;
2800
2801         // Call inner function
2802         return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2803 }
2804
2805 // Wrapper for changing entries in config-local.php
2806 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2807         // Call the inner function
2808         return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2809 }
2810
2811 // Shortens ucfirst(strtolower()) calls
2812 function firstCharUpperCase ($str) {
2813         return ucfirst(strtolower($str));
2814 }
2815
2816 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2817 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2818         // Get the configuration entry
2819         $configValue = getConfig($configEntry);
2820
2821         // Call inner method
2822         return createTimeSelections($configValue, $configEntry, $stamps, $align);
2823 }
2824
2825 // Shortens converting of German comma to Computer's version in POST data
2826 function convertCommaToDotInPostData ($postEntry) {
2827         // Read and convert given entry
2828         $postValue = convertCommaToDot(postRequestElement($postEntry));
2829
2830         // Log message
2831         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
2832
2833         // ... and set it again
2834         setPostRequestElement($postEntry, $postValue);
2835 }
2836
2837 // Converts German commas to Computer's version in all entries
2838 function convertCommaToDotInPostDataArray ($postEntries) {
2839         // Replace german decimal comma with computer decimal dot
2840         foreach ($postEntries as $entry) {
2841                 // Is the entry there?
2842                 if (isPostRequestElementSet($entry)) {
2843                         // Then convert it
2844                         convertCommaToDotInPostData($entry);
2845                 } // END - if
2846         } // END - foreach
2847 }
2848
2849 /**
2850  * Parses a string into a US formated float variable, taken from user comments
2851  * from PHP documentation website.
2852  *
2853  * @param       $floatString    A string holding a float expression
2854  * @return      $float                  Corresponding float variable
2855  * @author      chris<at>georgakopoulos<dot>com
2856  * @link        http://de.php.net/manual/en/function.floatval.php#92563
2857  */
2858 function parseFloat ($floatString){
2859         // Load locale info
2860         $LocaleInfo = localeconv();
2861
2862         // Remove thousand separators
2863         $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
2864
2865         // Convert decimal point
2866         $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2867
2868         // Return float value of converted string
2869         return floatval($floatString);
2870 }
2871
2872 /**
2873  * Searches a multi-dimensional array (as used in many places) for given
2874  * key/value pair as taken from user comments from PHP documentation website.
2875  *
2876  * @param       $array                  An array with one or more dimensions
2877  * @param       $key                    Key to look for
2878  * @param       $value                  Value to look for
2879  * @param       $parentIndex    Parent index (ONLY INTERNAL USE!)
2880  * @return      $results                Resulted array or empty array if $array is no array
2881  * @author      sunelbe<at>gmail<dot>com
2882  * @link        http://de.php.net/manual/en/function.array-search.php#110120
2883  */
2884 function search_array ($array, $key, $value, $parentIndex = NULL) {
2885         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
2886         // Init array result
2887         $results = array();
2888
2889         // Is $array really an array?
2890         if (is_array($array)) {
2891                 // Search for whole array
2892                 foreach ($array as $idx => $dummy) {
2893                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx);
2894                         // Is dummy an array?
2895                         if (is_array($dummy)) {
2896                                 // Then search again
2897                                 $subResult = search_array($dummy, $key, $value, $idx);
2898                                 //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
2899
2900                                 // And merge both
2901                                 $results = merge_array($results, $subResult, TRUE);
2902                         } elseif ((isset($array[$key])) && ($array[$key] == $value)) {
2903                                 // Is found, so add it
2904                                 $results[$parentIndex] = $array;
2905                         }
2906                 } // END - foreach
2907         } // END - if
2908
2909         // Return resulting array
2910         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
2911         return $results;
2912 }
2913
2914 // Generates a YES/NO option list from given default
2915 function generateYesNoOptions ($defaultValue = '') {
2916         // Generate it
2917         return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2918 }
2919
2920 // "Getter" for total available receivers
2921 function getTotalReceivers ($mode = 'normal') {
2922         // Get num rows
2923         $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
2924
2925         // Return value
2926         return $numRows;
2927 }
2928
2929 // Wrapper "getter" to get total unconfirmed mails for given userid
2930 function getTotalUnconfirmedMails ($userid) {
2931         // Is there cache?
2932         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2933                 // Determine it
2934                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
2935         } // END - if
2936
2937         // Return cache
2938         return $GLOBALS[__FUNCTION__][$userid];
2939 }
2940
2941 // Checks whether 'mailer_theme' was found in session
2942 function isMailerThemeSet () {
2943         // Is cache set?
2944         if (!isset($GLOBALS[__FUNCTION__])) {
2945                 // Determine it
2946                 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
2947         } // END - if
2948
2949         // Return cache
2950         return $GLOBALS[__FUNCTION__];
2951 }
2952
2953 /**
2954  * Setter for theme in session (This setter does return the success of
2955  * setSession() which is required e.g. for destroySponsorSession().
2956  */
2957 function setMailerTheme ($newTheme) {
2958         // Set it in session
2959         return setSession('mailer_theme', $newTheme);
2960 }
2961
2962 /**
2963  * Getter for theme from session (This getter does return 'mailer_theme' from
2964  * session data or throws an error if not possible
2965  */
2966 function getMailerTheme () {
2967         // Is cache set?
2968         if (!isset($GLOBALS[__FUNCTION__])) {
2969                 // Is 'mailer_theme' set?
2970                 if (!isMailerThemeSet()) {
2971                         // No, then abort here
2972                         reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2973                 } // END - if
2974
2975                 // Get it and store it in cache
2976                 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
2977         } // END - if
2978
2979         // Return cache
2980         return $GLOBALS[__FUNCTION__];
2981 }
2982
2983 // "Getter" for last_module/last_what depending on ext-user version
2984 function getUserLastWhatName () {
2985         // Default is old one: last_module
2986         $columnName = 'last_module';
2987
2988         // Is ext-user up-to-date?
2989         if (isExtensionInstalledAndNewer('user', '0.4.9')) {
2990                 // Yes, then use new one
2991                 $columnName = 'last_what';
2992         } // END - if
2993
2994         // Return it
2995         return $columnName;
2996 }
2997
2998 // "Getter" for all columns for given alias and separator
2999 function getAllPointColumns ($alias = NULL, $separator = ',') {
3000         // Prepare the filter array
3001         $filterData = array(
3002                 'columns'   => '',
3003                 'alias'     => $alias,
3004                 'separator' => $separator
3005         );
3006
3007         // Run the filter
3008         $filterData = runFilterChain('get_all_point_columns', $filterData);
3009
3010         // Return the columns
3011         return $filterData['columns'];
3012 }
3013
3014 // Checks whether the copyright footer (which breaks framesets) is enabled
3015 function ifCopyrightFooterEnabled () {
3016         // Is not unset and not 'N'?
3017         return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
3018 }
3019
3020 /**
3021  * Wrapper to check whether we have a "full page". This means that the actual
3022  * content is not delivered in any frame of a frameset.
3023  */
3024 function isFullPage () {
3025         /*
3026          * The parameter 'frame' is generic and always indicates that this content
3027          * will be output into a frame. Furthermore, if a frameset is reported or
3028          * the copyright line is explicitly deactivated, this cannot be a "full
3029          * page" again.
3030          */
3031         // @TODO Find a way to not use direct module comparison
3032         $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
3033
3034         // Return it
3035         return $isFullPage;
3036 }
3037
3038 // Checks whether frameset_mode is set to true
3039 function isFramesetModeEnabled () {
3040         // Check it
3041         return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
3042 }
3043
3044 // Function to determine correct 'what' value
3045 function determineWhat ($module = NULL) {
3046         // Init default 'what'
3047         $what = 'welcome';
3048
3049         // Is module NULL?
3050         if (is_null($module)) {
3051                 // Then use default
3052                 $module = getModule();
3053         } // END - if
3054
3055         // Is what set?
3056         if (isWhatSet()) {
3057                 // Then use it
3058                 $what = getWhat();
3059         } else {
3060                 // Else try to get it from current module
3061                 $what = getWhatFromModule($module);
3062         }
3063         //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
3064
3065         // Remove any spaces from variable
3066         $what = trim($what);
3067
3068         // Is it empty?
3069         if (empty($what)) {
3070                 // Default action for non-admin menus
3071                 $what = 'welcome';
3072         } else {
3073                 // Secure it
3074                 $what = secureString($what);
3075         }
3076
3077         // Return what
3078         return $what;
3079 }
3080
3081 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3082 function prependZeros ($mStretch, $length = 2) {
3083         // Return prepended string
3084         return sprintf('%0' . (int) $length . 's', $mStretch);
3085 }
3086
3087 // Wraps convertSelectionsToEpocheTime()
3088 function convertSelectionsToEpocheTimeInPostData ($id) {
3089         // Init variables
3090         $content = array();
3091         $skip = FALSE;
3092
3093         // Get all POST data
3094         $postData = postRequestArray();
3095
3096         // Convert given selection id
3097         convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3098
3099         // Set the POST array back
3100         setPostRequestArray($postData);
3101 }
3102
3103 // Wraps checking if given points account type matches with given in POST data
3104 function ifPointsAccountTypeMatchesPost ($type) {
3105         // Check condition
3106         exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
3107 }
3108
3109 // Gets given user's total referral
3110 function getUsersTotalReferrals ($userid, $level = NULL) {
3111         // Is there cache?
3112         if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3113                 // Is the level NULL?
3114                 if (is_null($level)) {
3115                         // Get total amount (all levels)
3116                         $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
3117                 } else {
3118                         // Get it from user refs
3119                         $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
3120                 }
3121         } // END - if
3122
3123         // Return it
3124         return $GLOBALS[__FUNCTION__][$userid][$level];
3125 }
3126
3127 // Gets given user's total referral
3128 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3129         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3130         // Is there cache?
3131         if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3132                 // Default is all refs
3133                 $add = '';
3134
3135                 // Is the not level NULL?
3136                 if (!is_null($level)) {
3137                         // Then add referral level
3138                         $add = ' AND r.`level`=' . bigintval($level);
3139                 } // END - if
3140
3141                 // Check for all referrals
3142                 $result = SQL_QUERY_ESC("SELECT
3143         COUNT(d.`userid`) AS `cnt`
3144 FROM
3145         `{?_MYSQL_PREFIX?}_user_data` AS d
3146 INNER JOIN
3147         `{?_MYSQL_PREFIX?}_user_refs` AS r
3148 ON
3149         d.`userid`=r.`refid`
3150 WHERE
3151         d.`status` != 'CONFIRMED' AND
3152         r.`userid`=%s
3153         " . $add . "
3154 ORDER BY
3155         d.`userid` ASC
3156 LIMIT 1",
3157                         array(
3158                                 $userid
3159                         ), __FUNCTION__, __LINE__);
3160
3161                 // Load count
3162                 list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
3163
3164                 // Free result
3165                 SQL_FREERESULT($result);
3166         } // END - if
3167
3168         // Return it
3169         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3170         return $GLOBALS[__FUNCTION__][$userid][$level];
3171 }
3172
3173 // Converts, if found, dollar data to get element
3174 function convertDollarDataToGetElement ($data) {
3175         // Is first char a dollar?
3176         if (substr($data, 0, 1) == chr(36)) {
3177                 // Use last part for getRequestElement()
3178                 $data = getRequestElement(substr($data, 1));
3179         } // END - if
3180
3181         // Return it
3182         return $data;
3183 }
3184
3185 // Wrapper function for SQL layer to speed-up things
3186 function SQL_DEBUG_ENABLED () {
3187         // Is there cache?
3188         if (!isset($GLOBALS[__FUNCTION__])) {
3189                 // Determine it
3190                 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3191         } // END - if
3192
3193         // Return cache
3194         return $GLOBALS[__FUNCTION__];
3195 }
3196
3197 // [EOF]
3198 ?>