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