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