a826c3d69b85716689946314fb9f18eb01ac04d9
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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         die();
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                 debug_report_bug(__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 debug_report_bug(__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         // Trigger an error on failure
123         if ((ob_get_length() > 0) && (!ob_end_clean())) {
124                 // Failed!
125                 debug_report_bug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
126         } // END - if
127 }
128
129 // Encode strings
130 // @TODO Implement $compress
131 function encodeString ($str, $compress = true) {
132         $str = urlencode(base64_encode(compileUriCode($str)));
133         return $str;
134 }
135
136 // Decode strings encoded with encodeString()
137 // @TODO Implement $decompress
138 function decodeString ($str, $decompress = true) {
139         $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
140         return $str;
141 }
142
143 // Decode entities in a nicer way
144 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
145         // Decode the entities to UTF-8 now
146         $decodedString = html_entity_decode($str, $quote, 'UTF-8');
147
148         // Return decoded string
149         return $decodedString;
150 }
151
152 // Merges an array together but only if both are arrays
153 function merge_array ($array1, $array2) {
154         // Are both an array?
155         if ((!is_array($array1)) && (!is_array($array2))) {
156                 // Both are not arrays
157                 debug_report_bug(__FUNCTION__, __LINE__, 'No arrays provided!');
158         } elseif (!is_array($array1)) {
159                 // Left one is not an array
160                 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
161         } elseif (!is_array($array2)) {
162                 // Right one is not an array
163                 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
164         }
165
166         // Merge all together
167         return array_merge($array1, $array2);
168 }
169
170 // Check if given FQFN is a readable file
171 function isFileReadable ($FQFN) {
172         // Do we have cache?
173         if (!isset($GLOBALS['file_readable'][$FQFN])) {
174                 // Check all...
175                 $GLOBALS['file_readable'][$FQFN] = ((file_exists($FQFN)) && (is_file($FQFN)) && (is_readable($FQFN)));
176         } // END - if
177
178         // Return result
179         return $GLOBALS['file_readable'][$FQFN];
180 }
181
182 // Checks wether the given FQFN is a directory and not ., .. or .svn
183 function isDirectory ($FQFN) {
184         // Do we have cache?
185         if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
186                 // Generate baseName
187                 $baseName = basename($FQFN);
188
189                 // Check it
190                 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
191         } // END - if
192
193         // Return the result
194         return $GLOBALS[__FUNCTION__][$FQFN];
195 }
196
197 // "Getter" for the real remote IP number
198 function detectRealIpAddress () {
199         // Get remote ip from environment
200         $remoteAddr = determineRealRemoteAddress();
201
202         // Is removeip installed?
203         if (isExtensionActive('removeip')) {
204                 // Then anonymize it
205                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
206         } // END - if
207
208         // Return it
209         return $remoteAddr;
210 }
211
212 // "Getter" for remote IP number
213 function detectRemoteAddr () {
214         // Get remote ip from environment
215         $remoteAddr = determineRealRemoteAddress(true);
216
217         // Is removeip installed?
218         if (isExtensionActive('removeip')) {
219                 // Then anonymize it
220                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
221         } // END - if
222
223         // Return it
224         return $remoteAddr;
225 }
226
227 // "Getter" for remote hostname
228 function detectRemoteHostname () {
229         // Get remote ip from environment
230         $remoteHost = getenv('REMOTE_HOST');
231
232         // Is removeip installed?
233         if (isExtensionActive('removeip')) {
234                 // Then anonymize it
235                 $remoteHost = getAnonymousRemoteHost($remoteHost);
236         } // END - if
237
238         // Return it
239         return $remoteHost;
240 }
241
242 // "Getter" for user agent
243 function detectUserAgent ($alwaysReal = false) {
244         // Get remote ip from environment
245         $userAgent = getenv('HTTP_USER_AGENT');
246
247         // Is removeip installed?
248         if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
249                 // Then anonymize it
250                 $userAgent = getAnonymousUserAgent($userAgent);
251         } // END - if
252
253         // Return it
254         return $userAgent;
255 }
256
257 // "Getter" for referer
258 function detectReferer () {
259         // Get remote ip from environment
260         $referer = getenv('HTTP_REFERER');
261
262         // Is removeip installed?
263         if (isExtensionActive('removeip')) {
264                 // Then anonymize it
265                 $referer = getAnonymousReferer($referer);
266         } // END - if
267
268         // Return it
269         return $referer;
270 }
271
272 // "Getter" for request URI
273 function detectRequestUri () {
274         // Return it
275         return (getenv('REQUEST_URI'));
276 }
277
278 // "Getter" for query string
279 function detectQueryString () {
280         return str_replace('&', '&amp;', (getenv('QUERY_STRING')));
281 }
282
283 // "Getter" for SERVER_NAME
284 function detectServerName () {
285         // Return it
286         return (getenv('SERVER_NAME'));
287 }
288
289 // Removes any  existing www. from SERVER_NAME. This is very silly but enough
290 // for our purpose here.
291 function detectDomainName () {
292         // Do we have cache?
293         if (!isset($GLOBALS[__FUNCTION__])) {
294                 // Get server name
295                 $domainName = detectServerName();
296
297                 // Is there any www. ?
298                 if (substr($domainName, 0, 4) == 'www.') {
299                         // Remove it
300                         $domainName = substr($domainName, 4);
301                 } // END - if
302
303                 // Set cache
304                 $GLOBALS[__FUNCTION__] = $domainName;
305         } // END - if
306
307         // Return cache
308         return $GLOBALS[__FUNCTION__];
309 }
310
311 // Check wether we are installing
312 function isInstalling () {
313         // Determine wether we are installing
314         if (!isset($GLOBALS['mailer_installing'])) {
315                 // Check URL (css.php/js.php need this)
316                 $GLOBALS['mailer_installing'] = isGetRequestParameterSet('installing');
317         } // END - if
318
319         // Return result
320         return $GLOBALS['mailer_installing'];
321 }
322
323 // Check wether this script is installed
324 function isInstalled () {
325         // Do we have cache?
326         if (!isset($GLOBALS[__FUNCTION__])) {
327                 // Determine wether this script is installed
328                 $GLOBALS[__FUNCTION__] = (
329                 (
330                         // First is config
331                         (
332                                 (
333                                         isConfigEntrySet('MXCHANGE_INSTALLED')
334                                 ) && (
335                                         getConfig('MXCHANGE_INSTALLED') == 'Y'
336                                 )
337                         )
338                 ) || (
339                         // New config file found and loaded
340                         isIncludeReadable(getCachePath() . 'config-local.php')
341                 ) || (
342                         (
343                                 // New config file found, but not yet read
344                                 isIncludeReadable(getCachePath() . 'config-local.php')
345                         ) && (
346                                 (
347                                         // Only new config file is found
348                                         !isIncludeReadable('inc/config.php')
349                                 ) || (
350                                         // Is installation mode
351                                         !isInstalling()
352                                 )
353                         )
354                 ));
355         } // END - if
356
357         // Then use the cache
358         return $GLOBALS[__FUNCTION__];
359 }
360
361 // Check wether an admin is registered
362 function isAdminRegistered () {
363         // Is cache set?
364         if (!isset($GLOBALS[__FUNCTION__])) {
365                 // Simply check it
366                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
367         } // END - if
368
369         // Return it
370         return $GLOBALS[__FUNCTION__];
371 }
372
373 // Checks wether the hourly reset mode is active
374 function isHourlyResetEnabled () {
375         // Now simply check it
376         return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === true));
377 }
378
379 // Checks wether the reset mode is active
380 function isResetModeEnabled () {
381         // Now simply check it
382         return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
383 }
384
385 // Checks wether the debug mode is enabled
386 function isDebugModeEnabled () {
387         // Is cache set?
388         if (!isset($GLOBALS[__FUNCTION__])) {
389                 // Simply check it
390                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
391         } // END - if
392
393         // Return it
394         return $GLOBALS[__FUNCTION__];
395 }
396
397 // Checks wether the debug reset is enabled
398 function isDebugResetEnabled () {
399         // Is cache set?
400         if (!isset($GLOBALS[__FUNCTION__])) {
401                 // Simply check it
402                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
403         } // END - if
404
405         // Return it
406         return $GLOBALS[__FUNCTION__];
407 }
408
409 // Checks wether SQL debugging is enabled
410 function isSqlDebuggingEnabled () {
411         // Is cache set?
412         if (!isset($GLOBALS[__FUNCTION__])) {
413                 // Determine if SQL debugging is enabled
414                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
415         } // END - if
416
417         // Return it
418         return $GLOBALS[__FUNCTION__];
419 }
420
421 // Checks wether we shall debug regular expressions
422 function isDebugRegularExpressionEnabled () {
423         // Is cache set?
424         if (!isset($GLOBALS[__FUNCTION__])) {
425                 // Simply check it
426                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
427         } // END - if
428
429         // Return it
430         return $GLOBALS[__FUNCTION__];
431 }
432
433 // Checks wether the cache instance is valid
434 function isCacheInstanceValid () {
435         // Do we have cache?
436         if (!isset($GLOBALS[__FUNCTION__])) {
437                 // Determine it
438                 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
439         } // END - if
440
441         // Return cache
442         return $GLOBALS[__FUNCTION__];
443 }
444
445 // Copies a file from source to destination and verifies if that goes fine.
446 // This function should wrap the copy() command and make a nicer debug backtrace
447 // even if there is no xdebug extension installed.
448 function copyFileVerified ($source, $dest, $chmod = '') {
449         // Failed is the default
450         $status = false;
451
452         // Is the source file there?
453         if (!isFileReadable($source)) {
454                 // Then abort here
455                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
456         } // END - if
457
458         // Is the target directory there?
459         if (!isDirectory(dirname($dest))) {
460                 // Then abort here
461                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
462         } // END - if
463
464         // Now try to copy it
465         if (!copy($source, $dest)) {
466                 // Something went wrong
467                 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
468         } else {
469                 // Reset cache
470                 $GLOBALS['file_readable'][$dest] = true;
471         }
472
473         // If there are chmod rights set, apply them
474         if (!empty($chmod)) {
475                 // Try to apply them
476                 $status = changeMode($dest, $chmod);
477         } else {
478                 // All fine
479                 $status = true;
480         }
481
482         // All fine
483         return $status;
484 }
485
486 // Wrapper function for header()
487 // Send a header but checks before if we can do so
488 function sendHeader ($header) {
489         // Send the header
490         //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header);
491         $GLOBALS['header'][] = trim($header);
492 }
493
494 // Flushes all headers
495 function flushHeaders () {
496         // Is the header already sent?
497         if (headers_sent()) {
498                 // Then abort here
499                 debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!');
500         } // END - if
501
502         // Flush all headers if found
503         if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) {
504                 foreach ($GLOBALS['header'] as $header) {
505                         header($header);
506                 } // END - foreach
507         } // END - if
508
509         // Mark them as flushed
510         $GLOBALS['header'] = array();
511 }
512
513 // Wrapper function for chmod()
514 // @TODO Do some more sanity check here
515 function changeMode ($FQFN, $mode) {
516         // Is the file/directory there?
517         if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
518                 // Neither, so abort here
519                 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
520         } // END - if
521
522         // Try to set them
523         return chmod($FQFN, $mode);
524 }
525
526 // Wrapper for unlink()
527 function removeFile ($FQFN) {
528         // Is the file there?
529         if (isFileReadable($FQFN)) {
530                 // Reset cache first
531                 $GLOBALS['file_readable'][$FQFN] = false;
532
533                 // Yes, so remove it
534                 return unlink($FQFN);
535         } // END - if
536
537         // All fine if no file was removed. If we change this to 'false' or rewrite
538         // above if() block it would be to restrictive.
539         return true;
540 }
541
542 // Wrapper for $_POST['sel']
543 function countPostSelection ($element = 'sel') {
544         // Is it set?
545         if (isPostRequestParameterSet($element)) {
546                 // Return counted elements
547                 return countSelection(postRequestParameter($element));
548         } else {
549                 // Return zero if not found
550                 return 0;
551         }
552 }
553
554 // Checks wether the config-local.php is loaded
555 function isConfigLocalLoaded () {
556         return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
557 }
558
559 // Checks wether a nickname or userid was entered and caches the result
560 function isNicknameUsed ($userid) {
561         // Is the cache there
562         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
563                 // Determine it
564                 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . round($userid) . '') != $userid));
565         } // END - if
566
567         // Return the result
568         return $GLOBALS[__FUNCTION__][$userid];
569 }
570
571 // Getter for 'what' value
572 function getWhat () {
573         // Default is null
574         $what = null;
575
576         // Is the value set?
577         if (isWhatSet(true)) {
578                 // Then use it
579                 $what = $GLOBALS['what'];
580         } // END - if
581
582         // Return it
583         return $what;
584 }
585
586 // Setter for 'what' value
587 function setWhat ($newWhat) {
588         $GLOBALS['what'] = SQL_ESCAPE($newWhat);
589 }
590
591 // Setter for 'what' from configuration
592 function setWhatFromConfig ($configEntry) {
593         // Get 'what' from config
594         $what = getConfig($configEntry);
595
596         // Set it
597         setWhat($what);
598 }
599
600 // Checks wether what is set and optionally aborts on miss
601 function isWhatSet ($strict =  false) {
602         // Check for it
603         $isset = isset($GLOBALS['what']);
604
605         // Should we abort here?
606         if (($strict === true) && ($isset === false)) {
607                 // Output backtrace
608                 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
609         } // END - if
610
611         // Return it
612         return $isset;
613 }
614
615 // Getter for 'action' value
616 function getAction ($strict = true) {
617         // Default is null
618         $action = null;
619
620         // Is the value set?
621         if (isActionSet(($strict) && (isHtmlOutputMode()))) {
622                 // Then use it
623                 $action = $GLOBALS['action'];
624         } // END - if
625
626         // Return it
627         return $action;
628 }
629
630 // Setter for 'action' value
631 function setAction ($newAction) {
632         $GLOBALS['action'] = SQL_ESCAPE($newAction);
633 }
634
635 // Checks wether action is set and optionally aborts on miss
636 function isActionSet ($strict =  false) {
637         // Check for it
638         $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action'])));
639
640         // Should we abort here?
641         if (($strict === true) && ($isset === false)) {
642                 // Output backtrace
643                 debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.');
644         } // END - if
645
646         // Return it
647         return $isset;
648 }
649
650 // Getter for 'module' value
651 function getModule ($strict = true) {
652         // Default is null
653         $module = null;
654
655         // Is the value set?
656         if (isModuleSet($strict)) {
657                 // Then use it
658                 $module = $GLOBALS['module'];
659         } // END - if
660
661         // Return it
662         return $module;
663 }
664
665 // Setter for 'module' value
666 function setModule ($newModule) {
667         // Secure it and make all modules lower-case
668         $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
669 }
670
671 // Checks wether module is set and optionally aborts on miss
672 function isModuleSet ($strict =  false) {
673         // Check for it
674         $isset = (!empty($GLOBALS['module']));
675
676         // Should we abort here?
677         if (($strict === true) && ($isset === false)) {
678                 // Output backtrace
679                 debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.');
680         } // END - if
681
682         // Return it
683         return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
684 }
685
686 // Getter for 'output_mode' value
687 function getScriptOutputMode () {
688         // Do we have cache?
689         if (!isset($GLOBALS[__FUNCTION__])) {
690                 // Default is null
691                 $output_mode = null;
692
693                 // Is the value set?
694                 if (isOutputModeSet(true)) {
695                         // Then use it
696                         $output_mode = $GLOBALS['output_mode'];
697                 } // END - if
698
699                 // Store it in cache
700                 $GLOBALS[__FUNCTION__] = $output_mode;
701         } // END - if
702
703         // Return cache
704         return $GLOBALS[__FUNCTION__];
705 }
706
707 // Setter for 'output_mode' value
708 function setOutputMode ($newOutputMode) {
709         $GLOBALS['output_mode'] = (int) $newOutputMode;
710 }
711
712 // Checks wether output_mode is set and optionally aborts on miss
713 function isOutputModeSet ($strict =  false) {
714         // Check for it
715         $isset = (isset($GLOBALS['output_mode']));
716
717         // Should we abort here?
718         if (($strict === true) && ($isset === false)) {
719                 // Output backtrace
720                 debug_report_bug(__FUNCTION__, __LINE__, 'Output mode is not set.');
721         } // END - if
722
723         // Return it
724         return $isset;
725 }
726
727 // Enables block-mode
728 function enableBlockMode ($enabled = true) {
729         $GLOBALS['block_mode'] = $enabled;
730 }
731
732 // Checks wether block-mode is enabled
733 function isBlockModeEnabled () {
734         // Abort if not set
735         if (!isset($GLOBALS['block_mode'])) {
736                 // Needs to be fixed
737                 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
738         } // END - if
739
740         // Return it
741         return $GLOBALS['block_mode'];
742 }
743
744 /**
745  * Wrapper function for addPointsThroughReferalSystem(), you should generally
746  * avoid this function and use addPointsThroughReferalSystem() directly and add
747  * your special payment method entry to points_data instead.
748  *
749  * @param       $subject        A string-encoded subject for this add
750  * @param       $userid         The recipient (member) for given points
751  * @param       $points         Points to be added to member's account
752  * @return      $added          Wether the points has been added to the user's account
753  */
754 function addPointsDirectly ($subject, $userid, $points) {
755         // Reset level here
756         initReferalSystem();
757
758         // Call more complicated method (due to more parameters)
759         return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'DIRECT');
760 }
761
762 // Wrapper for redirectToUrl but URL comes from a configuration entry
763 function redirectToConfiguredUrl ($configEntry) {
764         // Load the URL
765         redirectToUrl(getConfig($configEntry));
766 }
767
768 // Wrapper function to redirect from member-only modules to index
769 function redirectToIndexMemberOnlyModule () {
770         // Do the redirect here
771         redirectToUrl('modules.php?module=index&amp;code=' . getCode('MODULE_MEMBER_ONLY') . '&amp;mod=' . getModule());
772 }
773
774 // Wrapper function to redirect to current URL
775 function redirectToRequestUri () {
776         redirectToUrl(basename(detectRequestUri()));
777 }
778
779 // Wrapper function to redirect to de-refered URL
780 function redirectToDereferedUrl ($url) {
781         // Redirect to to
782         redirectToUrl(generateDerefererUrl($url));
783 }
784
785 // Wrapper function for checking if extension is installed and newer or same version
786 function isExtensionInstalledAndNewer ($ext_name, $version) {
787         // Is an cache entry found?
788         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
789                 // Determine it
790                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
791         } else {
792                 // Cache hits should be incremented twice
793                 incrementStatsEntry('cache_hits', 2);
794         }
795
796         // Return it
797         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=&gt;' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
798         return $GLOBALS[__FUNCTION__][$ext_name][$version];
799 }
800
801 // Wrapper function for checking if extension is installed and older than given version
802 function isExtensionInstalledAndOlder ($ext_name, $version) {
803         // Is an cache entry found?
804         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
805                 // Determine it
806                 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
807         } else {
808                 // Cache hits should be incremented twice
809                 incrementStatsEntry('cache_hits', 2);
810         }
811
812         // Return it
813         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '&lt;' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
814         return $GLOBALS[__FUNCTION__][$ext_name][$version];
815 }
816
817 // Set username
818 function setUsername ($userName) {
819         $GLOBALS['username'] = (string) $userName;
820 }
821
822 // Get username
823 function getUsername () {
824         // User name set?
825         if (!isset($GLOBALS['username'])) {
826                 // No, so it has to be a guest
827                 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
828         } // END - if
829
830         // Return it
831         return $GLOBALS['username'];
832 }
833
834 // Wrapper function for installation phase
835 function isInstallationPhase () {
836         // Do we have cache?
837         if (!isset($GLOBALS[__FUNCTION__])) {
838                 // Determine it
839                 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
840         } // END - if
841
842         // Return result
843         return $GLOBALS[__FUNCTION__];
844 }
845
846 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
847 function isDemoModeActive () {
848         // Is cache set?
849         if (!isset($GLOBALS[__FUNCTION__])) {
850                 // Simply check it
851                 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
852         } // END - if
853
854         // Return it
855         return $GLOBALS[__FUNCTION__];
856 }
857
858 // Getter for PHP caching value
859 function getPhpCaching () {
860         return $GLOBALS['php_caching'];
861 }
862
863 // Checks wether the admin hash is set
864 function isAdminHashSet ($adminId) {
865         // Is the array there?
866         if (!isset($GLOBALS['cache_array']['admin'])) {
867                 // Missing array should be reported
868                 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
869         } // END - if
870
871         // Check for admin hash
872         return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
873 }
874
875 // Setter for admin hash
876 function setAdminHash ($adminId, $hash) {
877         $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
878 }
879
880 // Getter for current admin login
881 function getCurrentAdminLogin () {
882         // Log debug message
883         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
884
885         // Do we have cache?
886         if (!isset($GLOBALS[__FUNCTION__])) {
887                 // Determine it
888                 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
889         } // END - if
890
891         // Return it
892         return $GLOBALS[__FUNCTION__];
893 }
894
895 // Setter for admin id (and current)
896 function setAdminId ($adminId) {
897         // Log debug message
898         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
899
900         // Set session
901         $status = setSession('admin_id', bigintval($adminId));
902
903         // Set current id
904         setCurrentAdminId($adminId);
905
906         // Return status
907         return $status;
908 }
909
910 // Setter for admin_last
911 function setAdminLast ($adminLast) {
912         // Log debug message
913         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
914
915         // Set session
916         $status = setSession('admin_last', $adminLast);
917
918         // Return status
919         return $status;
920 }
921
922 // Setter for admin_md5
923 function setAdminMd5 ($adminMd5) {
924         // Log debug message
925         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
926
927         // Set session
928         $status = setSession('admin_md5', $adminMd5);
929
930         // Return status
931         return $status;
932 }
933
934 // Getter for admin_md5
935 function getAdminMd5 () {
936         // Log debug message
937         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
938
939         // Get session
940         return getSession('admin_md5');
941 }
942
943 // Init user data array
944 function initUserData () {
945         // User id should not be zero
946         if (!isValidUserId(getCurrentUserId())) {
947                 // Should be always valid
948                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
949         } // END - if
950
951         // Init the user
952         $GLOBALS['user_data'][getCurrentUserId()] = array();
953 }
954
955 // Getter for user data
956 function getUserData ($column) {
957         // User id should not be zero
958         if (!isValidUserId(getCurrentUserId())) {
959                 // Should be always valid
960                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
961         } // END - if
962
963         // Default is empty
964         $data = null;
965
966         if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
967                 // Return the value
968                 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
969         } // END - if
970
971         // Return it
972         return $data;
973 }
974
975 // Checks wether given user data is set to 'Y'
976 function isUserDataEnabled ($column) {
977         // Do we have cache?
978         if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
979                 // Determine it
980                 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
981         } // END - if
982
983         // Return cache
984         return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
985 }
986
987 // Geter for whole user data array
988 function getUserDataArray () {
989         // Get user id
990         $userid = getCurrentUserId();
991
992         // Is the current userid valid?
993         if (!isValidUserId($userid)) {
994                 // Should be always valid
995                 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
996         } // END - if
997
998         // Get the whole array if found
999         if (isset($GLOBALS['user_data'][$userid])) {
1000                 // Found, so return it
1001                 return $GLOBALS['user_data'][$userid];
1002         } else {
1003                 // Return empty array
1004                 return array();
1005         }
1006 }
1007
1008 // Checks if the user data is valid, this may indicate that the user has logged
1009 // in, but you should use isMember() if you want to find that out.
1010 function isUserDataValid () {
1011         // User id should not be zero so abort here
1012         if (!isCurrentUserIdSet()) return false;
1013
1014         // Is it cached?
1015         if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
1016                 // Determine it
1017                 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
1018         } // END - if
1019
1020         // Return the result
1021         return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1022 }
1023
1024 // Setter for current userid
1025 function setCurrentUserId ($userid) {
1026         // Set userid
1027         $GLOBALS['current_userid'] = bigintval($userid);
1028
1029         // Unset it to re-determine the actual state
1030         unset($GLOBALS['is_userdata_valid'][$userid]);
1031 }
1032
1033 // Getter for current userid
1034 function getCurrentUserId () {
1035         // Userid must be set before it can be used
1036         if (!isCurrentUserIdSet()) {
1037                 // Not set
1038                 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
1039         } // END - if
1040
1041         // Return the userid
1042         return $GLOBALS['current_userid'];
1043 }
1044
1045 // Checks if current userid is set
1046 function isCurrentUserIdSet () {
1047         return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1048 }
1049
1050 // Checks wether we are debugging template cache
1051 function isDebuggingTemplateCache () {
1052         // Do we have cache?
1053         if (!isset($GLOBALS[__FUNCTION__])) {
1054                 // Determine it
1055                 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1056         } // END - if
1057
1058         // Return cache
1059         return $GLOBALS[__FUNCTION__];
1060 }
1061
1062 // Wrapper for fetchUserData() and getUserData() calls
1063 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1064         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1065         // Is it cached?
1066         if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1067                 // Default is 'guest'
1068                 $data = '{--USERNAME_GUEST--}';
1069
1070                 // Can we fetch the user data?
1071                 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1072                         // Now get the data back
1073                         $data = getUserData($valueColumn);
1074                 } // END - if
1075
1076                 // Cache it
1077                 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1078         } // END - if
1079
1080         // Return it
1081         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1082         return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1083 }
1084
1085 // Wrapper for strpos() to ease porting from deprecated ereg() function
1086 function isInString ($needle, $haystack) {
1087         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1088         return (strpos($haystack, $needle) !== false);
1089 }
1090
1091 // Wrapper for strpos() to ease porting from deprecated eregi() function
1092 // This function is case-insensitive
1093 function isInStringIgnoreCase ($needle, $haystack) {
1094         return (isInString(strtolower($needle), strtolower($haystack)));
1095 }
1096
1097 // Wrapper to check for if fatal errors where detected
1098 function ifFatalErrorsDetected () {
1099         // Just call the inner function
1100         return (getTotalFatalErrors() > 0);
1101 }
1102
1103 // Setter for HTTP status
1104 function setHttpStatus ($status) {
1105         $GLOBALS['http_status'] = (string) $status;
1106 }
1107
1108 // Getter for HTTP status
1109 function getHttpStatus () {
1110         // Is the status set?
1111         if (!isset($GLOBALS['http_status'])) {
1112                 // Abort here
1113                 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1114         } // END - if
1115
1116         // Return it
1117         return $GLOBALS['http_status'];
1118 }
1119
1120 /**
1121  * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1122  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1123  *
1124  * ----------------------------------------------------------------------------
1125  * If you want to redirect, please use redirectToUrl(); instead
1126  * ----------------------------------------------------------------------------
1127  *
1128  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1129  *
1130  * @link    http://support.microsoft.com/kb/q176113/
1131  * @author  Andreas Gohr <andi@splitbrain.org>
1132  * @access  private
1133  */
1134 function sendRawRedirect ($url) {
1135         // Send helping header
1136         setHttpStatus('302 Found');
1137
1138         // always close the session
1139         session_write_close();
1140
1141         // Revert entity &amp;
1142         $url = str_replace('&amp;', '&', $url);
1143
1144         // check if running on IIS < 6 with CGI-PHP
1145         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1146                 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
1147                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1148                 ($matches[1] < 6)) {
1149                 // Send the IIS header
1150                 sendHeader('Refresh: 0;url=' . $url);
1151         } else {
1152                 // Send generic header
1153                 sendHeader('Location: ' . $url);
1154         }
1155
1156         // Shutdown here
1157         shutdown();
1158 }
1159
1160 // Determines the country of the given user id
1161 function determineCountry ($userid) {
1162         // Do we have cache?
1163         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1164                 // Default is 'invalid'
1165                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1166
1167                 // Is extension country active?
1168                 if (isExtensionActive('country')) {
1169                         // Determine the right country code through the country id
1170                         $id = getUserData('country_code');
1171
1172                         // Then handle it over
1173                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1174                 } else {
1175                         // Get raw code from user data
1176                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1177                 }
1178         } // END - if
1179
1180         // Return cache
1181         return $GLOBALS[__FUNCTION__][$userid];
1182 }
1183
1184 // "Getter" for total confirmed user accounts
1185 function getTotalConfirmedUser () {
1186         // Is it cached?
1187         if (!isset($GLOBALS[__FUNCTION__])) {
1188                 // Then do it
1189                 if (isExtensionActive('user')) {
1190                         $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1191                 } else {
1192                         $GLOBALS[__FUNCTION__] = 0;
1193                 }
1194         } // END - if
1195
1196         // Return cached value
1197         return $GLOBALS[__FUNCTION__];
1198 }
1199
1200 // "Getter" for total unconfirmed user accounts
1201 function getTotalUnconfirmedUser () {
1202         // Is it cached?
1203         if (!isset($GLOBALS[__FUNCTION__])) {
1204                 // Then do it
1205                 if (isExtensionActive('user')) {
1206                         $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1207                 } else {
1208                         $GLOBALS[__FUNCTION__] = 0;
1209                 }
1210         } // END - if
1211
1212         // Return cached value
1213         return $GLOBALS[__FUNCTION__];
1214 }
1215
1216 // "Getter" for total locked user accounts
1217 function getTotalLockedUser () {
1218         // Is it cached?
1219         if (!isset($GLOBALS[__FUNCTION__])) {
1220                 // Then do it
1221                 if (isExtensionActive('user')) {
1222                         $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1223                 } else {
1224                         $GLOBALS[__FUNCTION__] = 0;
1225                 }
1226         } // END - if
1227
1228         // Return cached value
1229         return $GLOBALS[__FUNCTION__];
1230 }
1231
1232 // "Getter" for total locked user accounts
1233 function getTotalRandomRefidUser () {
1234         // Is it cached?
1235         if (!isset($GLOBALS[__FUNCTION__])) {
1236                 // Then do it
1237                 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1238                         $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, '', '>=');
1239                 } else {
1240                         $GLOBALS[__FUNCTION__] = 0;
1241                 }
1242         } // END - if
1243
1244         // Return cached value
1245         return $GLOBALS[__FUNCTION__];
1246 }
1247
1248 // Is given userid valid?
1249 function isValidUserId ($userid) {
1250         // Do we have cache?
1251         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1252                 // Check it out
1253                 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1254         } // END - if
1255
1256         // Return cache
1257         return $GLOBALS[__FUNCTION__][$userid];
1258 }
1259
1260 // Encodes entities
1261 function encodeEntities ($str) {
1262         // Secure it first
1263         $str = secureString($str, true, true);
1264
1265         // Encode dollar sign as well
1266         $str = str_replace('$', '&#36;', $str);
1267
1268         // Return it
1269         return $str;
1270 }
1271
1272 // "Getter" for date from patch_ctime
1273 function getDateFromPatchTime () {
1274         // Is it cached?
1275         if (!isset($GLOBALS[__FUNCTION__])) {
1276                 // Then set it
1277                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1278         } // END - if
1279
1280         // Return cache
1281         return $GLOBALS[__FUNCTION__];
1282 }
1283
1284 // Getter for current year (default)
1285 function getYear ($timestamp = null) {
1286         // Is it cached?
1287         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1288                 // null is time()
1289                 if (is_null($timestamp)) {
1290                         $timestamp = time();
1291                 } // END - if
1292
1293                 // Then create it
1294                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1295         } // END - if
1296
1297         // Return cache
1298         return $GLOBALS[__FUNCTION__][$timestamp];
1299 }
1300
1301 // Getter for current month (default)
1302 function getMonth ($timestamp = null) {
1303         // Is it cached?
1304         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1305                 // If null is set, use time()
1306                 if (is_null($timestamp)) {
1307                         // Use time() which is current timestamp
1308                         $timestamp = time();
1309                 } // END - if
1310
1311                 // Then create it
1312                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1313         } // END - if
1314
1315         // Return cache
1316         return $GLOBALS[__FUNCTION__][$timestamp];
1317 }
1318
1319 // Getter for current hour (default)
1320 function getHour ($timestamp = null) {
1321         // Is it cached?
1322         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1323                 // null is time()
1324                 if (is_null($timestamp)) {
1325                         $timestamp = time();
1326                 } // END - if
1327
1328                 // Then create it
1329                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1330         } // END - if
1331
1332         // Return cache
1333         return $GLOBALS[__FUNCTION__][$timestamp];
1334 }
1335
1336 // Getter for current day (default)
1337 function getDay ($timestamp = null) {
1338         // Is it cached?
1339         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1340                 // null is time()
1341                 if (is_null($timestamp)) {
1342                         $timestamp = time();
1343                 } // END - if
1344
1345                 // Then create it
1346                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1347         } // END - if
1348
1349         // Return cache
1350         return $GLOBALS[__FUNCTION__][$timestamp];
1351 }
1352
1353 // Getter for current week (default)
1354 function getWeek ($timestamp = null) {
1355         // Is it cached?
1356         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1357                 // null is time()
1358                 if (is_null($timestamp)) $timestamp = time();
1359
1360                 // Then create it
1361                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1362         } // END - if
1363
1364         // Return cache
1365         return $GLOBALS[__FUNCTION__][$timestamp];
1366 }
1367
1368 // Getter for current short_hour (default)
1369 function getShortHour ($timestamp = null) {
1370         // Is it cached?
1371         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1372                 // null is time()
1373                 if (is_null($timestamp)) $timestamp = time();
1374
1375                 // Then create it
1376                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1377         } // END - if
1378
1379         // Return cache
1380         return $GLOBALS[__FUNCTION__][$timestamp];
1381 }
1382
1383 // Getter for current long_hour (default)
1384 function getLongHour ($timestamp = null) {
1385         // Is it cached?
1386         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1387                 // null is time()
1388                 if (is_null($timestamp)) $timestamp = time();
1389
1390                 // Then create it
1391                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1392         } // END - if
1393
1394         // Return cache
1395         return $GLOBALS[__FUNCTION__][$timestamp];
1396 }
1397
1398 // Getter for current second (default)
1399 function getSecond ($timestamp = null) {
1400         // Is it cached?
1401         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1402                 // null is time()
1403                 if (is_null($timestamp)) $timestamp = time();
1404
1405                 // Then create it
1406                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1407         } // END - if
1408
1409         // Return cache
1410         return $GLOBALS[__FUNCTION__][$timestamp];
1411 }
1412
1413 // Getter for current minute (default)
1414 function getMinute ($timestamp = null) {
1415         // Is it cached?
1416         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1417                 // null is time()
1418                 if (is_null($timestamp)) $timestamp = time();
1419
1420                 // Then create it
1421                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1422         } // END - if
1423
1424         // Return cache
1425         return $GLOBALS[__FUNCTION__][$timestamp];
1426 }
1427
1428 // Checks wether the title decoration is enabled
1429 function isTitleDecorationEnabled () {
1430         // Do we have cache?
1431         if (!isset($GLOBALS[__FUNCTION__])) {
1432                 // Just check it
1433                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1434         } // END - if
1435
1436         // Return cache
1437         return $GLOBALS[__FUNCTION__];
1438 }
1439
1440 // Checks wether filter usage updates are enabled (expensive queries!)
1441 function isFilterUsageUpdateEnabled () {
1442         // Do we have cache?
1443         if (!isset($GLOBALS[__FUNCTION__])) {
1444                 // Determine it
1445                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1446         } // END - if
1447
1448         // Return cache
1449         return $GLOBALS[__FUNCTION__];
1450 }
1451
1452 // Checks wether debugging of weekly resets is enabled
1453 function isWeeklyResetDebugEnabled () {
1454         // Do we have cache?
1455         if (!isset($GLOBALS[__FUNCTION__])) {
1456                 // Determine it
1457                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1458         } // END - if
1459
1460         // Return cache
1461         return $GLOBALS[__FUNCTION__];
1462 }
1463
1464 // Checks wether debugging of monthly resets is enabled
1465 function isMonthlyResetDebugEnabled () {
1466         // Do we have cache?
1467         if (!isset($GLOBALS[__FUNCTION__])) {
1468                 // Determine it
1469                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1470         } // END - if
1471
1472         // Return cache
1473         return $GLOBALS[__FUNCTION__];
1474 }
1475
1476 // Checks wether displaying of debug SQLs are enabled
1477 function isDisplayDebugSqlEnabled () {
1478         // Do we have cache?
1479         if (!isset($GLOBALS[__FUNCTION__])) {
1480                 // Determine it
1481                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1482         } // END - if
1483
1484         // Return cache
1485         return $GLOBALS[__FUNCTION__];
1486 }
1487
1488 // Checks wether module title is enabled
1489 function isModuleTitleEnabled () {
1490         // Do we have cache?
1491         if (!isset($GLOBALS[__FUNCTION__])) {
1492                 // Determine it
1493                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1494         } // END - if
1495
1496         // Return cache
1497         return $GLOBALS[__FUNCTION__];
1498 }
1499
1500 // Checks wether what title is enabled
1501 function isWhatTitleEnabled () {
1502         // Do we have cache?
1503         if (!isset($GLOBALS[__FUNCTION__])) {
1504                 // Determine it
1505                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1506         } // END - if
1507
1508         // Return cache
1509         return $GLOBALS[__FUNCTION__];
1510 }
1511
1512 // Checks wether stats are enabled
1513 function ifStatsAreEnabled () {
1514         // Do we have cache?
1515         if (!isset($GLOBALS[__FUNCTION__])) {
1516                 // Then determine it
1517                 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1518         } // END - if
1519
1520         // Return cached value
1521         return $GLOBALS[__FUNCTION__];
1522 }
1523
1524 // Checks wether admin-notification of certain user actions is enabled
1525 function isAdminNotificationEnabled () {
1526         // Do we have cache?
1527         if (!isset($GLOBALS[__FUNCTION__])) {
1528                 // Determine it
1529                 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1530         } // END - if
1531
1532         // Return cache
1533         return $GLOBALS[__FUNCTION__];
1534 }
1535
1536 // Checks wether random referal id selection is enabled
1537 function isRandomReferalIdEnabled () {
1538         // Do we have cache?
1539         if (!isset($GLOBALS[__FUNCTION__])) {
1540                 // Determine it
1541                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1542         } // END - if
1543
1544         // Return cache
1545         return $GLOBALS[__FUNCTION__];
1546 }
1547
1548 // "Getter" for default language
1549 function getDefaultLanguage () {
1550         // Do we have cache?
1551         if (!isset($GLOBALS[__FUNCTION__])) {
1552                 // Determine it
1553                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1554         } // END - if
1555
1556         // Return cache
1557         return $GLOBALS[__FUNCTION__];
1558 }
1559
1560 // "Getter" for default referal id
1561 function getDefRefid () {
1562         // Do we have cache?
1563         if (!isset($GLOBALS[__FUNCTION__])) {
1564                 // Determine it
1565                 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1566         } // END - if
1567
1568         // Return cache
1569         return $GLOBALS[__FUNCTION__];
1570 }
1571
1572 // "Getter" for path
1573 function getPath () {
1574         // Do we have cache?
1575         if (!isset($GLOBALS[__FUNCTION__])) {
1576                 // Determine it
1577                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1578         } // END - if
1579
1580         // Return cache
1581         return $GLOBALS[__FUNCTION__];
1582 }
1583
1584 // "Getter" for url
1585 function getUrl () {
1586         // Do we have cache?
1587         if (!isset($GLOBALS[__FUNCTION__])) {
1588                 // Determine it
1589                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1590         } // END - if
1591
1592         // Return cache
1593         return $GLOBALS[__FUNCTION__];
1594 }
1595
1596 // "Getter" for cache_path
1597 function getCachePath () {
1598         // Do we have cache?
1599         if (!isset($GLOBALS[__FUNCTION__])) {
1600                 // Determine it
1601                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1602         } // END - if
1603
1604         // Return cache
1605         return $GLOBALS[__FUNCTION__];
1606 }
1607
1608 // "Getter" for secret_key
1609 function getSecretKey () {
1610         // Do we have cache?
1611         if (!isset($GLOBALS[__FUNCTION__])) {
1612                 // Determine it
1613                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1614         } // END - if
1615
1616         // Return cache
1617         return $GLOBALS[__FUNCTION__];
1618 }
1619
1620 // "Getter" for SITE_KEY
1621 function getSiteKey () {
1622         // Do we have cache?
1623         if (!isset($GLOBALS[__FUNCTION__])) {
1624                 // Determine it
1625                 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1626         } // END - if
1627
1628         // Return cache
1629         return $GLOBALS[__FUNCTION__];
1630 }
1631
1632 // "Getter" for DATE_KEY
1633 function getDateKey () {
1634         // Do we have cache?
1635         if (!isset($GLOBALS[__FUNCTION__])) {
1636                 // Determine it
1637                 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1638         } // END - if
1639
1640         // Return cache
1641         return $GLOBALS[__FUNCTION__];
1642 }
1643
1644 // "Getter" for master_salt
1645 function getMasterSalt () {
1646         // Do we have cache?
1647         if (!isset($GLOBALS[__FUNCTION__])) {
1648                 // Determine it
1649                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1650         } // END - if
1651
1652         // Return cache
1653         return $GLOBALS[__FUNCTION__];
1654 }
1655
1656 // "Getter" for prime
1657 function getPrime () {
1658         // Do we have cache?
1659         if (!isset($GLOBALS[__FUNCTION__])) {
1660                 // Determine it
1661                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1662         } // END - if
1663
1664         // Return cache
1665         return $GLOBALS[__FUNCTION__];
1666 }
1667
1668 // "Getter" for encrypt_seperator
1669 function getEncryptSeperator () {
1670         // Do we have cache?
1671         if (!isset($GLOBALS[__FUNCTION__])) {
1672                 // Determine it
1673                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1674         } // END - if
1675
1676         // Return cache
1677         return $GLOBALS[__FUNCTION__];
1678 }
1679
1680 // "Getter" for mysql_prefix
1681 function getMysqlPrefix () {
1682         // Do we have cache?
1683         if (!isset($GLOBALS[__FUNCTION__])) {
1684                 // Determine it
1685                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1686         } // END - if
1687
1688         // Return cache
1689         return $GLOBALS[__FUNCTION__];
1690 }
1691
1692 // "Getter" for table_type
1693 function getTableType () {
1694         // Do we have cache?
1695         if (!isset($GLOBALS[__FUNCTION__])) {
1696                 // Determine it
1697                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1698         } // END - if
1699
1700         // Return cache
1701         return $GLOBALS[__FUNCTION__];
1702 }
1703
1704 // "Getter" for salt_length
1705 function getSaltLength () {
1706         // Do we have cache?
1707         if (!isset($GLOBALS[__FUNCTION__])) {
1708                 // Determine it
1709                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1710         } // END - if
1711
1712         // Return cache
1713         return $GLOBALS[__FUNCTION__];
1714 }
1715
1716 // "Getter" for output_mode
1717 function getOutputMode () {
1718         // Do we have cache?
1719         if (!isset($GLOBALS[__FUNCTION__])) {
1720                 // Determine it
1721                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1722         } // END - if
1723
1724         // Return cache
1725         return $GLOBALS[__FUNCTION__];
1726 }
1727
1728 // "Getter" for full_version
1729 function getFullVersion () {
1730         // Do we have cache?
1731         if (!isset($GLOBALS[__FUNCTION__])) {
1732                 // Determine it
1733                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1734         } // END - if
1735
1736         // Return cache
1737         return $GLOBALS[__FUNCTION__];
1738 }
1739
1740 // "Getter" for title
1741 function getTitle () {
1742         // Do we have cache?
1743         if (!isset($GLOBALS[__FUNCTION__])) {
1744                 // Determine it
1745                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1746         } // END - if
1747
1748         // Return cache
1749         return $GLOBALS[__FUNCTION__];
1750 }
1751
1752 // "Getter" for curr_svn_revision
1753 function getCurrentRepositoryRevision () {
1754         // Do we have cache?
1755         if (!isset($GLOBALS[__FUNCTION__])) {
1756                 // Determine it
1757                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1758         } // END - if
1759
1760         // Return cache
1761         return $GLOBALS[__FUNCTION__];
1762 }
1763
1764 // "Getter" for server_url
1765 function getServerUrl () {
1766         // Do we have cache?
1767         if (!isset($GLOBALS[__FUNCTION__])) {
1768                 // Determine it
1769                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1770         } // END - if
1771
1772         // Return cache
1773         return $GLOBALS[__FUNCTION__];
1774 }
1775
1776 // "Getter" for mt_word
1777 function getMtWord () {
1778         // Do we have cache?
1779         if (!isset($GLOBALS[__FUNCTION__])) {
1780                 // Determine it
1781                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1782         } // END - if
1783
1784         // Return cache
1785         return $GLOBALS[__FUNCTION__];
1786 }
1787
1788 // "Getter" for mt_word2
1789 function getMtWord2 () {
1790         // Do we have cache?
1791         if (!isset($GLOBALS[__FUNCTION__])) {
1792                 // Determine it
1793                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1794         } // END - if
1795
1796         // Return cache
1797         return $GLOBALS[__FUNCTION__];
1798 }
1799
1800 // "Getter" for main_title
1801 function getMainTitle () {
1802         // Do we have cache?
1803         if (!isset($GLOBALS[__FUNCTION__])) {
1804                 // Determine it
1805                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1806         } // END - if
1807
1808         // Return cache
1809         return $GLOBALS[__FUNCTION__];
1810 }
1811
1812 // "Getter" for file_hash
1813 function getFileHash () {
1814         // Do we have cache?
1815         if (!isset($GLOBALS[__FUNCTION__])) {
1816                 // Determine it
1817                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1818         } // END - if
1819
1820         // Return cache
1821         return $GLOBALS[__FUNCTION__];
1822 }
1823
1824 // "Getter" for pass_scramble
1825 function getPassScramble () {
1826         // Do we have cache?
1827         if (!isset($GLOBALS[__FUNCTION__])) {
1828                 // Determine it
1829                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1830         } // END - if
1831
1832         // Return cache
1833         return $GLOBALS[__FUNCTION__];
1834 }
1835
1836 // "Getter" for ap_inactive_since
1837 function getApInactiveSince () {
1838         // Do we have cache?
1839         if (!isset($GLOBALS[__FUNCTION__])) {
1840                 // Determine it
1841                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1842         } // END - if
1843
1844         // Return cache
1845         return $GLOBALS[__FUNCTION__];
1846 }
1847
1848 // "Getter" for user_min_confirmed
1849 function getUserMinConfirmed () {
1850         // Do we have cache?
1851         if (!isset($GLOBALS[__FUNCTION__])) {
1852                 // Determine it
1853                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1854         } // END - if
1855
1856         // Return cache
1857         return $GLOBALS[__FUNCTION__];
1858 }
1859
1860 // "Getter" for auto_purge
1861 function getAutoPurge () {
1862         // Do we have cache?
1863         if (!isset($GLOBALS[__FUNCTION__])) {
1864                 // Determine it
1865                 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1866         } // END - if
1867
1868         // Return cache
1869         return $GLOBALS[__FUNCTION__];
1870 }
1871
1872 // "Getter" for bonus_userid
1873 function getBonusUserid () {
1874         // Do we have cache?
1875         if (!isset($GLOBALS[__FUNCTION__])) {
1876                 // Determine it
1877                 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1878         } // END - if
1879
1880         // Return cache
1881         return $GLOBALS[__FUNCTION__];
1882 }
1883
1884 // "Getter" for ap_inactive_time
1885 function getApInactiveTime () {
1886         // Do we have cache?
1887         if (!isset($GLOBALS[__FUNCTION__])) {
1888                 // Determine it
1889                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1890         } // END - if
1891
1892         // Return cache
1893         return $GLOBALS[__FUNCTION__];
1894 }
1895
1896 // "Getter" for ap_dm_timeout
1897 function getApDmTimeout () {
1898         // Do we have cache?
1899         if (!isset($GLOBALS[__FUNCTION__])) {
1900                 // Determine it
1901                 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1902         } // END - if
1903
1904         // Return cache
1905         return $GLOBALS[__FUNCTION__];
1906 }
1907
1908 // "Getter" for ap_tasks_time
1909 function getApTasksTime () {
1910         // Do we have cache?
1911         if (!isset($GLOBALS[__FUNCTION__])) {
1912                 // Determine it
1913                 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1914         } // END - if
1915
1916         // Return cache
1917         return $GLOBALS[__FUNCTION__];
1918 }
1919
1920 // "Getter" for ap_unconfirmed_time
1921 function getApUnconfirmedTime () {
1922         // Do we have cache?
1923         if (!isset($GLOBALS[__FUNCTION__])) {
1924                 // Determine it
1925                 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1926         } // END - if
1927
1928         // Return cache
1929         return $GLOBALS[__FUNCTION__];
1930 }
1931
1932 // "Getter" for points
1933 function getPoints () {
1934         // Do we have cache?
1935         if (!isset($GLOBALS[__FUNCTION__])) {
1936                 // Determine it
1937                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1938         } // END - if
1939
1940         // Return cache
1941         return $GLOBALS[__FUNCTION__];
1942 }
1943
1944 // "Getter" for slogan
1945 function getSlogan () {
1946         // Do we have cache?
1947         if (!isset($GLOBALS[__FUNCTION__])) {
1948                 // Determine it
1949                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1950         } // END - if
1951
1952         // Return cache
1953         return $GLOBALS[__FUNCTION__];
1954 }
1955
1956 // "Getter" for copy
1957 function getCopy () {
1958         // Do we have cache?
1959         if (!isset($GLOBALS[__FUNCTION__])) {
1960                 // Determine it
1961                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1962         } // END - if
1963
1964         // Return cache
1965         return $GLOBALS[__FUNCTION__];
1966 }
1967
1968 // "Getter" for webmaster
1969 function getWebmaster () {
1970         // Do we have cache?
1971         if (!isset($GLOBALS[__FUNCTION__])) {
1972                 // Determine it
1973                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1974         } // END - if
1975
1976         // Return cache
1977         return $GLOBALS[__FUNCTION__];
1978 }
1979
1980 // "Getter" for sql_count
1981 function getSqlCount () {
1982         // Do we have cache?
1983         if (!isset($GLOBALS[__FUNCTION__])) {
1984                 // Determine it
1985                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1986         } // END - if
1987
1988         // Return cache
1989         return $GLOBALS[__FUNCTION__];
1990 }
1991
1992 // "Getter" for num_templates
1993 function getNumTemplates () {
1994         // Do we have cache?
1995         if (!isset($GLOBALS[__FUNCTION__])) {
1996                 // Determine it
1997                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1998         } // END - if
1999
2000         // Return cache
2001         return $GLOBALS[__FUNCTION__];
2002 }
2003
2004 // "Getter" for dns_cache_timeout
2005 function getDnsCacheTimeout () {
2006         // Do we have cache?
2007         if (!isset($GLOBALS[__FUNCTION__])) {
2008                 // Determine it
2009                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2010         } // END - if
2011
2012         // Return cache
2013         return $GLOBALS[__FUNCTION__];
2014 }
2015
2016 // "Getter" for menu_blur_spacer
2017 function getMenuBlurSpacer () {
2018         // Do we have cache?
2019         if (!isset($GLOBALS[__FUNCTION__])) {
2020                 // Determine it
2021                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2022         } // END - if
2023
2024         // Return cache
2025         return $GLOBALS[__FUNCTION__];
2026 }
2027
2028 // "Getter" for points_register
2029 function getPointsRegister () {
2030         // Do we have cache?
2031         if (!isset($GLOBALS[__FUNCTION__])) {
2032                 // Determine it
2033                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2034         } // END - if
2035
2036         // Return cache
2037         return $GLOBALS[__FUNCTION__];
2038 }
2039
2040 // "Getter" for points_ref
2041 function getPointsRef () {
2042         // Do we have cache?
2043         if (!isset($GLOBALS[__FUNCTION__])) {
2044                 // Determine it
2045                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2046         } // END - if
2047
2048         // Return cache
2049         return $GLOBALS[__FUNCTION__];
2050 }
2051
2052 // "Getter" for ref_payout
2053 function getRefPayout () {
2054         // Do we have cache?
2055         if (!isset($GLOBALS[__FUNCTION__])) {
2056                 // Determine it
2057                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2058         } // END - if
2059
2060         // Return cache
2061         return $GLOBALS[__FUNCTION__];
2062 }
2063
2064 // "Getter" for online_timeout
2065 function getOnlineTimeout () {
2066         // Do we have cache?
2067         if (!isset($GLOBALS[__FUNCTION__])) {
2068                 // Determine it
2069                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2070         } // END - if
2071
2072         // Return cache
2073         return $GLOBALS[__FUNCTION__];
2074 }
2075
2076 // "Getter" for index_home
2077 function getIndexHome () {
2078         // Do we have cache?
2079         if (!isset($GLOBALS[__FUNCTION__])) {
2080                 // Determine it
2081                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2082         } // END - if
2083
2084         // Return cache
2085         return $GLOBALS[__FUNCTION__];
2086 }
2087
2088 // "Getter" for one_day
2089 function getOneDay () {
2090         // Do we have cache?
2091         if (!isset($GLOBALS[__FUNCTION__])) {
2092                 // Determine it
2093                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2094         } // END - if
2095
2096         // Return cache
2097         return $GLOBALS[__FUNCTION__];
2098 }
2099
2100 // "Getter" for activate_xchange
2101 function getActivateXchange () {
2102         // Do we have cache?
2103         if (!isset($GLOBALS[__FUNCTION__])) {
2104                 // Determine it
2105                 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2106         } // END - if
2107
2108         // Return cache
2109         return $GLOBALS[__FUNCTION__];
2110 }
2111
2112 // "Getter" for img_type
2113 function getImgType () {
2114         // Do we have cache?
2115         if (!isset($GLOBALS[__FUNCTION__])) {
2116                 // Determine it
2117                 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2118         } // END - if
2119
2120         // Return cache
2121         return $GLOBALS[__FUNCTION__];
2122 }
2123
2124 // "Getter" for code_length
2125 function getCodeLength () {
2126         // Do we have cache?
2127         if (!isset($GLOBALS[__FUNCTION__])) {
2128                 // Determine it
2129                 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2130         } // END - if
2131
2132         // Return cache
2133         return $GLOBALS[__FUNCTION__];
2134 }
2135
2136 // "Getter" for least_cats
2137 function getLeastCats () {
2138         // Do we have cache?
2139         if (!isset($GLOBALS[__FUNCTION__])) {
2140                 // Determine it
2141                 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2142         } // END - if
2143
2144         // Return cache
2145         return $GLOBALS[__FUNCTION__];
2146 }
2147
2148 // "Getter" for pass_len
2149 function getPassLen () {
2150         // Do we have cache?
2151         if (!isset($GLOBALS[__FUNCTION__])) {
2152                 // Determine it
2153                 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2154         } // END - if
2155
2156         // Return cache
2157         return $GLOBALS[__FUNCTION__];
2158 }
2159
2160 // "Getter" for admin_menu
2161 function getAdminMenu () {
2162         // Do we have cache?
2163         if (!isset($GLOBALS[__FUNCTION__])) {
2164                 // Determine it
2165                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2166         } // END - if
2167
2168         // Return cache
2169         return $GLOBALS[__FUNCTION__];
2170 }
2171
2172 // "Getter" for last_month
2173 function getLastMonth () {
2174         // Do we have cache?
2175         if (!isset($GLOBALS[__FUNCTION__])) {
2176                 // Determine it
2177                 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2178         } // END - if
2179
2180         // Return cache
2181         return $GLOBALS[__FUNCTION__];
2182 }
2183
2184 // "Getter" for max_send
2185 function getMaxSend () {
2186         // Do we have cache?
2187         if (!isset($GLOBALS[__FUNCTION__])) {
2188                 // Determine it
2189                 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2190         } // END - if
2191
2192         // Return cache
2193         return $GLOBALS[__FUNCTION__];
2194 }
2195
2196 // "Getter" for mails_page
2197 function getMailsPage () {
2198         // Do we have cache?
2199         if (!isset($GLOBALS[__FUNCTION__])) {
2200                 // Determine it
2201                 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2202         } // END - if
2203
2204         // Return cache
2205         return $GLOBALS[__FUNCTION__];
2206 }
2207
2208 // "Getter" for rand_no
2209 function getRandNo () {
2210         // Do we have cache?
2211         if (!isset($GLOBALS[__FUNCTION__])) {
2212                 // Determine it
2213                 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2214         } // END - if
2215
2216         // Return cache
2217         return $GLOBALS[__FUNCTION__];
2218 }
2219
2220 // "Getter" for __DB_NAME
2221 function getDbName () {
2222         // Do we have cache?
2223         if (!isset($GLOBALS[__FUNCTION__])) {
2224                 // Determine it
2225                 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2226         } // END - if
2227
2228         // Return cache
2229         return $GLOBALS[__FUNCTION__];
2230 }
2231
2232 // "Getter" for DOMAIN
2233 function getDomain () {
2234         // Do we have cache?
2235         if (!isset($GLOBALS[__FUNCTION__])) {
2236                 // Determine it
2237                 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2238         } // END - if
2239
2240         // Return cache
2241         return $GLOBALS[__FUNCTION__];
2242 }
2243
2244 // "Getter" for proxy_username
2245 function getProxyUsername () {
2246         // Do we have cache?
2247         if (!isset($GLOBALS[__FUNCTION__])) {
2248                 // Determine it
2249                 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2250         } // END - if
2251
2252         // Return cache
2253         return $GLOBALS[__FUNCTION__];
2254 }
2255
2256 // "Getter" for proxy_password
2257 function getProxyPassword () {
2258         // Do we have cache?
2259         if (!isset($GLOBALS[__FUNCTION__])) {
2260                 // Determine it
2261                 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2262         } // END - if
2263
2264         // Return cache
2265         return $GLOBALS[__FUNCTION__];
2266 }
2267
2268 // "Getter" for proxy_host
2269 function getProxyHost () {
2270         // Do we have cache?
2271         if (!isset($GLOBALS[__FUNCTION__])) {
2272                 // Determine it
2273                 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2274         } // END - if
2275
2276         // Return cache
2277         return $GLOBALS[__FUNCTION__];
2278 }
2279
2280 // "Getter" for proxy_port
2281 function getProxyPort () {
2282         // Do we have cache?
2283         if (!isset($GLOBALS[__FUNCTION__])) {
2284                 // Determine it
2285                 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2286         } // END - if
2287
2288         // Return cache
2289         return $GLOBALS[__FUNCTION__];
2290 }
2291
2292 // "Getter" for SMTP_HOSTNAME
2293 function getSmtpHostname () {
2294         // Do we have cache?
2295         if (!isset($GLOBALS[__FUNCTION__])) {
2296                 // Determine it
2297                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2298         } // END - if
2299
2300         // Return cache
2301         return $GLOBALS[__FUNCTION__];
2302 }
2303
2304 // "Getter" for SMTP_USER
2305 function getSmtpUser () {
2306         // Do we have cache?
2307         if (!isset($GLOBALS[__FUNCTION__])) {
2308                 // Determine it
2309                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2310         } // END - if
2311
2312         // Return cache
2313         return $GLOBALS[__FUNCTION__];
2314 }
2315
2316 // "Getter" for SMTP_PASSWORD
2317 function getSmtpPassword () {
2318         // Do we have cache?
2319         if (!isset($GLOBALS[__FUNCTION__])) {
2320                 // Determine it
2321                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2322         } // END - if
2323
2324         // Return cache
2325         return $GLOBALS[__FUNCTION__];
2326 }
2327
2328 // "Getter" for points_word
2329 function getPointsWord () {
2330         // Do we have cache?
2331         if (!isset($GLOBALS[__FUNCTION__])) {
2332                 // Determine it
2333                 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2334         } // END - if
2335
2336         // Return cache
2337         return $GLOBALS[__FUNCTION__];
2338 }
2339
2340 // "Getter" for profile_lock
2341 function getProfileLock () {
2342         // Do we have cache?
2343         if (!isset($GLOBALS[__FUNCTION__])) {
2344                 // Determine it
2345                 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2346         } // END - if
2347
2348         // Return cache
2349         return $GLOBALS[__FUNCTION__];
2350 }
2351
2352 // "Getter" for url_tlock
2353 function getUrlTlock () {
2354         // Do we have cache?
2355         if (!isset($GLOBALS[__FUNCTION__])) {
2356                 // Determine it
2357                 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2358         } // END - if
2359
2360         // Return cache
2361         return $GLOBALS[__FUNCTION__];
2362 }
2363
2364 // Checks wether proxy configuration is used
2365 function isProxyUsed () {
2366         // Do we have cache?
2367         if (!isset($GLOBALS[__FUNCTION__])) {
2368                 // Determine it
2369                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2370         } // END - if
2371
2372         // Return cache
2373         return $GLOBALS[__FUNCTION__];
2374 }
2375
2376 // Checks wether POST data contains selections
2377 function ifPostContainsSelections ($element = 'sel') {
2378         // Do we have cache?
2379         if (!isset($GLOBALS[__FUNCTION__][$element])) {
2380                 // Determine it
2381                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
2382         } // END - if
2383
2384         // Return cache
2385         return $GLOBALS[__FUNCTION__][$element];
2386 }
2387
2388 // Checks wether verbose_sql is Y and returns true/false if so
2389 function isVerboseSqlEnabled () {
2390         // Do we have cache?
2391         if (!isset($GLOBALS[__FUNCTION__])) {
2392                 // Determine it
2393                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2394         } // END - if
2395
2396         // Return cache
2397         return $GLOBALS[__FUNCTION__];
2398 }
2399
2400 // "Getter" for total user points
2401 function getTotalPoints ($userid) {
2402         // Do we have cache?
2403         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2404                 // Init array for filter chain
2405                 $data = array(
2406                         'userid' => $userid,
2407                         'points' => 0
2408                 );
2409
2410                 // Run filter chain for getting more point values
2411                 $data = runFilterChain('get_total_points', $data);
2412
2413                 // Determine it
2414                 $GLOBALS[__FUNCTION__][$userid] = $data['points']  - countSumTotalData($userid, 'user_data', 'used_points');
2415         } // END - if
2416
2417         // Return cache
2418         return $GLOBALS[__FUNCTION__][$userid];
2419 }
2420
2421 // Wrapper to check if url_blacklist is enabled
2422 function isUrlBlacklistEnabled () {
2423         // Do we have cache?
2424         if (!isset($GLOBALS[__FUNCTION__])) {
2425                 // Determine it
2426                 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2427         } // END - if
2428
2429         // Return cache
2430         return $GLOBALS[__FUNCTION__];
2431 }
2432
2433 // Checks wether direct payment is allowed in configuration
2434 function isDirectPaymentEnabled () {
2435         // Do we have cache?
2436         if (!isset($GLOBALS[__FUNCTION__])) {
2437                 // Determine it
2438                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2439         } // END - if
2440
2441         // Return cache
2442         return $GLOBALS[__FUNCTION__];
2443 }
2444
2445 // Wrapper to check if current task is for extension (not update)
2446 function isExtensionTask ($content) {
2447         // Do we have cache?
2448         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2449                 // Determine it
2450                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2451         } // END - if
2452
2453         // Return cache
2454         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2455 }
2456
2457 // Wrapper to check if output mode is CSS
2458 function isCssOutputMode () {
2459         // Determine it
2460         return (getScriptOutputMode() == 1);
2461 }
2462
2463 // Wrapper to check if output mode is HTML
2464 function isHtmlOutputMode () {
2465         // Determine it
2466         return (getScriptOutputMode() == 0);
2467 }
2468
2469 // Wrapper to check if output mode is RAW
2470 function isRawOutputMode () {
2471         // Determine it
2472         return (getScriptOutputMode() == -1);
2473 }
2474
2475 // Wrapper to generate a user email link
2476 function generateWrappedUserEmailLink ($email) {
2477         // Just call the inner function
2478         return generateEmailLink($email, 'user_data');
2479 }
2480
2481 // Wrapper to check if user points are locked
2482 function ifUserPointsLocked ($userid) {
2483         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2484         // Do we have cache?
2485         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2486                 // Determine it
2487                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2488         } // END - if
2489
2490         // Return cache
2491         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2492         return $GLOBALS[__FUNCTION__][$userid];
2493 }
2494
2495 // Appends a line to an existing file or creates it instantly with given content.
2496 // This function does always add a new-line character to every line.
2497 function appendLineToFile ($file, $line) {
2498         $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2499         fwrite($fp, $line . "\n");
2500         fclose($fp);
2501 }
2502
2503 // Wrapper for changeDataInFile() but with full path added
2504 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2505         // Add full path
2506         $FQFN = getPath() . $FQFN;
2507
2508         // Call inner function
2509         return changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);
2510 }
2511
2512 // Wrapper for changing entries in config-local.php
2513 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $DATA, $seek = 0) {
2514         // Call the inner function
2515         return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $DATA, $seek);
2516 }
2517
2518 // Shortens ucfirst(strtolower()) calls
2519 function firstCharUpperCase ($str) {
2520         return ucfirst(strtolower($str));
2521 }
2522
2523 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2524 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2525         // Get the configuration entry
2526         $configValue = getConfig($configEntry);
2527
2528         // Call inner method
2529         return createTimeSelections($configValue, $configEntry, $stamps, $align);
2530 }
2531
2532 // Shortens converting of German comma to Computer's version in POST data
2533 function convertCommaToDotInPostData ($postEntry) {
2534         // Read and convert given entry
2535         $postValue = convertCommaToDot(postRequestParameter($postEntry));
2536
2537         // ... and set it again
2538         setPostRequestParameter($postEntry, $postValue);
2539 }
2540
2541 // Converts German commas to Computer's version in all entries
2542 function convertCommaToDotInPostDataArray ($postEntries) {
2543         // Replace german decimal comma with computer decimal dot
2544         foreach ($postEntries as $entry) {
2545                 // Is the entry there?
2546                 if (isPostRequestParameterSet($entry)) {
2547                         // Then convert it
2548                         convertCommaToDotInPostData($entry);
2549                 } // END - if
2550         } // END - foreach
2551 }
2552
2553 /**
2554  * Parses a string into a US formated float variable, taken from user comments
2555  * from PHP documentation website.
2556  *
2557  * @param       $floatString    A string holding a float expression
2558  * @return      $float                  Corresponding float variable
2559  * @author      chris<at>georgakopoulos<dot>com
2560  * @link        http://de.php.net/manual/en/function.floatval.php#92563
2561  */
2562 function parseFloat ($floatString){
2563     $LocaleInfo = localeconv();
2564     $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '', $floatString);
2565     $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2566     return floatval($floatString);
2567 }
2568
2569 // Generates a YES/NO option list from given default
2570 function generateYesNoOptionList ($default = '') {
2571         // Generate it
2572         return generateOptionList('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $default);
2573 }
2574
2575 // "Getter" for total available receivers
2576 function getTotalReceivers ($mode = 'normal') {
2577         // Get num rows
2578         $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode));
2579
2580         // Return value
2581         return $numRows;
2582 }
2583
2584 // Wrapper "getter" to get total unconfirmed mails for given userid
2585 function getTotalUnconfirmedMails ($userid) {
2586         // Do we have cache?
2587         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2588                 // Determine it
2589                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
2590         } // END - if
2591
2592         // Return cache
2593         return $GLOBALS[__FUNCTION__][$userid];
2594 }
2595
2596 //-----------------------------------------------------------------------------
2597 //                        Configuration wrapper
2598 //-----------------------------------------------------------------------------
2599
2600 // Getter for 'check_double_email'
2601 function getCheckDoubleEmail () {
2602         // Is the cache entry set?
2603         if (!isset($GLOBALS[__FUNCTION__])) {
2604                 // No, so determine it
2605                 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2606         } // END - if
2607
2608         // Return cached entry
2609         return $GLOBALS[__FUNCTION__];
2610 }
2611
2612 // Checks wether 'check_double_email' is 'Y'
2613 function isCheckDoubleEmailEnabled () {
2614         // Is the cache entry set?
2615         if (!isset($GLOBALS[__FUNCTION__])) {
2616                 // No, so determine it
2617                 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2618         } // END - if
2619
2620         // Return cached entry
2621         return $GLOBALS[__FUNCTION__];
2622 }
2623
2624 // [EOF]
2625 ?>