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