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