2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 04/04/2009 *
4 * =================== Last change: 04/04/2009 *
6 * -------------------------------------------------------------------- *
7 * File : wrapper-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Wrapper functions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Wrapper-Funktionen *
12 * -------------------------------------------------------------------- *
13 * Copyright (c) 2003 - 2009 by Roland Haeder *
14 * Copyright (c) 2009 - 2015 by Mailer Developer Team *
15 * For more information visit: http://mxchange.org *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
22 * This program is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25 * GNU General Public License for more details. *
27 * You should have received a copy of the GNU General Public License *
28 * along with this program; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
31 ************************************************************************/
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
39 function readFromFile ($FQFN) {
40 // Sanity-check if file is there (should be there, but just to make it sure)
41 if (!isFileReadable($FQFN)) {
42 // This should not happen
43 reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!');
47 if (function_exists('file_get_contents')) {
49 $fileContent = file_get_contents($FQFN);
51 // Fall-back to implode-file chain
52 $fileContent = implode('', file($FQFN));
59 // Writes content to a file
60 function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
61 // Is the file writeable?
62 if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
64 logDebugMessage(__FUNCTION__, __LINE__, sprintf('File %s not writeable or cannot change CHMOD to 0644.', basename($FQFN)));
70 // By default all is failed...
71 $GLOBALS['file_readable'][$FQFN] = FALSE;
74 // Is the function there?
75 if (function_exists('file_put_contents')) {
77 if ($aquireLock === TRUE) {
78 // Write it directly with lock
79 $return = file_put_contents($FQFN, $content, LOCK_EX);
82 $return = file_put_contents($FQFN, $content);
85 // Write it with fopen
86 $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
89 if ($aquireLock === TRUE) {
95 $return = fwrite($fp, $content);
101 // Was something written?
102 if ($return !== FALSE) {
103 // Mark it as readable
104 $GLOBALS['file_readable'][$FQFN] = TRUE;
108 return (($return !== FALSE) && (changeMode($FQFN, 0644)));
111 // Clears the output buffer. This function does *NOT* backup sent content.
112 function clearOutputBuffer () {
113 // Make sure this function is not called twice (no double-cleaning!)
114 if (isset($GLOBALS[__FUNCTION__])) {
115 // This function is called twice
116 reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.');
117 } elseif ((ob_get_length() > 0) && (!ob_end_clean())) {
119 reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
122 // Mark this function as called
123 $GLOBALS[__FUNCTION__] = TRUE;
127 function encodeString ($str) {
128 $str = urlencode(base64_encode(compileUriCode($str)));
132 // Decode strings encoded with encodeString()
133 function decodeString ($str) {
134 $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
138 // Decode entities in a nicer way
139 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
140 // Decode the entities to UTF-8 now
141 $decodedString = html_entity_decode($str, $quote, 'UTF-8');
143 // Return decoded string
144 return $decodedString;
147 // Merges an array together but only if both are arrays
148 function merge_array ($array1, $array2, $keepIndex = FALSE) {
149 // Are both an array?
150 if ((!is_array($array1)) && (!is_array($array2))) {
151 // Both are not arrays
152 reportBug(__FUNCTION__, __LINE__, 'No arrays provided!');
153 } elseif (!is_array($array1)) {
154 // Left one is not an array
155 reportBug(__FUNCTION__, __LINE__, sprintf('array1 is not an array. array != %s', gettype($array1)));
156 } elseif (!is_array($array2)) {
157 // Right one is not an array
158 reportBug(__FUNCTION__, __LINE__, sprintf('array2 is not an array. array != %s', gettype($array2)));
161 // Maintain index of array2?
162 if ($keepIndex === TRUE) {
163 // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :(
164 foreach ($array2 as $key => $value) {
166 $array1[$key] = $value;
172 // Merge both together normally
173 return array_merge($array1, $array2);
177 // Check if given FQFN is a readable file
178 function isFileReadable ($FQFN) {
180 if (!isset($GLOBALS['file_readable'][$FQFN])) {
182 $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN)));
186 return $GLOBALS['file_readable'][$FQFN];
189 // Checks whether the given FQFN is a directory and not ., .. or .svn
190 function isDirectory ($FQFN) {
192 if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
194 $baseName = basename($FQFN);
197 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && (!in_array($baseName, array('.', '..', '.svn'))));
201 return $GLOBALS[__FUNCTION__][$FQFN];
204 // "Getter" for the real remote IP number
205 function detectRealIpAddress ($alwaysReal = FALSE) {
206 // Get remote ip from environment
207 $remoteAddr = determineRealRemoteAddress();
209 // Is removeip installed?
210 if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
212 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
219 // "Getter" for remote IP number
220 function detectRemoteAddr ($alwaysReal = FALSE) {
221 // Get remote ip from environment
222 $remoteAddr = determineRealRemoteAddress(TRUE);
224 // Is removeip installed?
225 if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
227 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
234 // "Getter" for remote hostname
235 function detectRemoteHostname ($alwaysReal = FALSE) {
236 // Get remote ip from environment
237 $remoteHost = getenv('REMOTE_HOST');
239 // Is removeip installed?
240 if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
242 $remoteHost = getAnonymousRemoteHost($remoteHost);
249 // "Getter" for user agent
250 function detectUserAgent ($alwaysReal = FALSE) {
251 // Get remote ip from environment
252 $userAgent = getenv('HTTP_USER_AGENT');
254 // Is removeip installed?
255 if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
257 $userAgent = getAnonymousUserAgent($userAgent);
264 // "Getter" for referer
265 function detectReferer ($alwaysReal = FALSE) {
266 // Get remote ip from environment
267 $referer = getenv('HTTP_REFERER');
269 // Is removeip installed?
270 if ((isExtensionActive('removeip')) && ($alwaysReal === TRUE)) {
272 $referer = getAnonymousReferer($referer);
279 // "Getter" for request URI
280 function detectRequestUri () {
282 return (getenv('REQUEST_URI'));
285 // "Getter" for query string
286 function detectQueryString () {
287 return str_replace('&', '&', (getenv('QUERY_STRING')));
290 // "Getter" for SERVER_NAME
291 function detectServerName () {
293 return (getenv('SERVER_NAME'));
296 // Removes any existing www. from SERVER_NAME. This is very silly but enough
297 // for our purpose here.
298 function detectDomainName () {
300 if (!isset($GLOBALS[__FUNCTION__])) {
302 $domainName = detectServerName();
304 // Is there any www. ?
305 if (substr($domainName, 0, 4) == 'www.') {
307 $domainName = substr($domainName, 4);
311 $GLOBALS[__FUNCTION__] = $domainName;
315 return $GLOBALS[__FUNCTION__];
318 // Check whether we are installing
319 function isInstalling () {
320 // Determine whether we are installing
321 if (!isset($GLOBALS['__mailer_installing'])) {
322 // Check URL (css.php/js.php need this)
323 $GLOBALS['__mailer_installing'] = (isGetRequestElementSet('installing') || ((isAjaxOutputMode()) && (isGetRequestElementSet('level')) && (getRequestElement('level') == 'install')));
327 return $GLOBALS['__mailer_installing'];
330 // Check whether this script is installed
331 function isInstalled () {
333 if (!isset($GLOBALS[__FUNCTION__])) {
334 // Determine whether this script is installed
335 $GLOBALS[__FUNCTION__] = (
340 isConfigEntrySet('MAILER_INSTALLED')
342 getConfig('MAILER_INSTALLED') == 'Y'
346 // New config file found and loaded
347 isIncludeReadable(getCachePath() . 'config-local.php')
350 // New config file found, but not yet read
351 isIncludeReadable(getCachePath() . 'config-local.php')
354 // Only new config file is found
355 !isIncludeReadable('inc/config.php')
357 // Is installation mode
364 // Then use the cache
365 return $GLOBALS[__FUNCTION__];
368 // Check whether an admin is registered
369 function isAdminRegistered () {
371 if (!isset($GLOBALS[__FUNCTION__])) {
373 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
377 return $GLOBALS[__FUNCTION__];
380 // Checks whether the hourly reset mode is active
381 function isHourlyResetEnabled () {
382 // Now simply check it
383 return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE));
386 // Checks whether the daily reset mode is active
387 function isDailyResetEnabled () {
388 // Now simply check it
389 return ((isset($GLOBALS['daily_enabled'])) && ($GLOBALS['daily_enabled'] === TRUE));
392 // Checks whether the weekly reset mode is active
393 function isWeeklyResetEnabled () {
394 // Now simply check it
395 return ((isset($GLOBALS['weekly_enabled'])) && ($GLOBALS['weekly_enabled'] === TRUE));
398 // Checks whether the monthly reset mode is active
399 function isMonthlyResetEnabled () {
400 // Now simply check it
401 return ((isset($GLOBALS['monthly_enabled'])) && ($GLOBALS['monthly_enabled'] === TRUE));
404 // Checks whether the yearly reset mode is active
405 function isYearlyResetEnabled () {
406 // Now simply check it
407 return ((isset($GLOBALS['yearly_enabled'])) && ($GLOBALS['yearly_enabled'] === TRUE));
410 // Checks whether one of the reset modes is enabled
411 function isResetModeEnabled () {
412 // Now simply check it
413 return ((isHourlyResetEnabled()) || (isDailyResetEnabled()) || (isWeeklyResetEnabled()) || (isMonthlyResetEnabled()) || (isYearlyResetEnabled()));
416 // Checks whether the debug mode is enabled
417 function isDebugModeEnabled () {
419 if (!isset($GLOBALS[__FUNCTION__])) {
421 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
425 return $GLOBALS[__FUNCTION__];
428 // Checks whether the debug hourly is enabled
429 function isDebugHourlyEnabled () {
431 if (!isset($GLOBALS[__FUNCTION__])) {
433 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_HOURLY')) && (getConfig('DEBUG_HOURLY') == 'Y'));
437 return $GLOBALS[__FUNCTION__];
440 // Checks whether the debug daily is enabled
441 function isDebugDailyEnabled () {
443 if (!isset($GLOBALS[__FUNCTION__])) {
445 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_DAILY')) && (getConfig('DEBUG_DAILY') == 'Y'));
449 return $GLOBALS[__FUNCTION__];
452 // Checks whether the debug weekly is enabled
453 function isDebugWeeklyEnabled () {
455 if (!isset($GLOBALS[__FUNCTION__])) {
457 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
461 return $GLOBALS[__FUNCTION__];
464 // Checks whether the debug monthly is enabled
465 function isDebugMonthlyEnabled () {
467 if (!isset($GLOBALS[__FUNCTION__])) {
469 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
473 return $GLOBALS[__FUNCTION__];
476 // Checks whether the debug yearly is enabled
477 function isDebugYearlyEnabled () {
479 if (!isset($GLOBALS[__FUNCTION__])) {
481 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y'));
485 return $GLOBALS[__FUNCTION__];
488 // Checks whether SQL debugging is enabled
489 function isSqlDebuggingEnabled () {
491 if (!isset($GLOBALS[__FUNCTION__])) {
492 // Determine if SQL debugging is enabled
493 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
497 return $GLOBALS[__FUNCTION__];
500 // Checks whether we shall debug regular expressions
501 function isDebugRegularExpressionEnabled () {
503 if (!isset($GLOBALS[__FUNCTION__])) {
505 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
509 return $GLOBALS[__FUNCTION__];
512 // Checks whether debugging of build mails is enabled
513 function isDebugBuildMailsEnabled () {
515 if (!isset($GLOBALS[__FUNCTION__])) {
517 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_BUILD_MAILS')) && (getConfig('DEBUG_BUILD_MAILS') == 'Y'));
521 return $GLOBALS[__FUNCTION__];
524 // Checks whether the cache instance is valid
525 function isValidCacheInstance () {
527 if (!isset($GLOBALS[__FUNCTION__])) {
529 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
533 return $GLOBALS[__FUNCTION__];
536 // Copies a file from source to destination and verifies if that goes fine.
537 // This function should wrap the copy() command and make a nicer debug backtrace
538 // even if there is no xdebug extension installed.
539 function copyFileVerified ($source, $dest, $chmod = '') {
540 // Failed is the default
543 // Is the source file there?
544 if (!isFileReadable($source)) {
546 reportBug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
549 // Is the target directory there?
550 if (!isDirectory(dirname($dest))) {
552 reportBug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
555 // Now try to copy it
556 if (!copy($source, $dest)) {
557 // Something went wrong
558 reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
561 $GLOBALS['file_readable'][$dest] = TRUE;
564 // All fine by default
567 // If there are chmod rights set, apply them
568 if (!empty($chmod)) {
570 $status = changeMode($dest, $chmod);
577 // Wrapper function for chmod()
578 // @TODO Do some more sanity check here
579 function changeMode ($FQFN, $mode) {
580 // Is the file/directory there?
581 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
582 // Neither, so abort here
583 reportBug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
587 return chmod($FQFN, $mode);
590 // Wrapper for unlink()
591 function removeFile ($FQFN) {
592 // Is the file there?
593 if (isFileReadable($FQFN)) {
595 $GLOBALS['file_readable'][$FQFN] = FALSE;
598 return unlink($FQFN);
601 // All fine if no file was removed. If we change this to 'false' or rewrite
602 // above if() block it would be to restrictive.
606 // Wrapper for $_POST['sel']
607 function countPostSelection ($element = 'sel') {
609 if (!isset($GLOBALS[__FUNCTION__][$element])) {
611 $GLOBALS[__FUNCTION__][$element] = '0';
614 if (isPostRequestElementSet($element)) {
615 // Return counted elements
616 $GLOBALS[__FUNCTION__][$element] = countSelection(postRequestElement($element));
620 // Return cached value
621 return $GLOBALS[__FUNCTION__][$element];
624 // Checks whether the config-local.php is loaded
625 function isConfigLocalLoaded () {
626 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === TRUE));
629 // Checks whether a nickname or userid was entered and caches the result
630 function isNicknameUsed ($userid) {
631 // Is the cache there
632 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
634 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL'));
638 return $GLOBALS[__FUNCTION__][$userid];
641 // Getter for 'what' value
642 function getWhat ($strict = TRUE) {
647 if (isWhatSet($strict)) {
649 $what = $GLOBALS['__what'];
656 // Setter for 'what' value
657 function setWhat ($newWhat) {
658 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat);
659 $GLOBALS['__what'] = $newWhat;
662 // Setter for 'what' from configuration
663 function setWhatFromConfig ($configEntry) {
664 // Get 'what' from config
665 $what = getConfig($configEntry);
671 // Checks whether what is set and optionally aborts on miss
672 function isWhatSet ($strict = FALSE) {
674 $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
676 // Should we abort here?
677 if (($strict === TRUE) && ($isset === FALSE)) {
679 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
686 // Getter for 'action' value
687 function getAction ($strict = TRUE) {
692 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
694 $action = $GLOBALS['__action'];
701 // Setter for 'action' value
702 function setAction ($newAction) {
703 $GLOBALS['__action'] = $newAction;
706 // Checks whether action is set and optionally aborts on miss
707 function isActionSet ($strict = FALSE) {
709 $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
711 // Should we abort here?
712 if (($strict === TRUE) && ($isset === FALSE)) {
714 reportBug(__FUNCTION__, __LINE__, 'action is empty.');
721 // Getter for 'module' value
722 function getModule ($strict = TRUE) {
727 if (isModuleSet($strict)) {
729 $module = $GLOBALS['__module'];
736 // Setter for 'module' value
737 function setModule ($newModule) {
738 // Secure it and make all modules lower-case
739 $GLOBALS['__module'] = strtolower($newModule);
742 // Wrapper to get extra module names
743 function getExtraModule () {
747 // Is 'tab/step' set?
748 if (isPostRequestElementSet('tab')) {
750 $extra = 'tab=' . postRequestElement('tab');
751 } elseif (isPostRequestElementSet('step')) {
753 $extra = 'step=' . postRequestElement('step');
754 } elseif ((isActionSet()) && (isWhatSet())) {
756 $extra = 'action=' . getAction() . ':what=' . getWhat();
763 // Checks whether module is set and optionally aborts on miss
764 function isModuleSet ($strict = FALSE) {
766 $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
768 // Should we abort here?
769 if (($strict === TRUE) && ($isset === FALSE)) {
771 reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
775 return (($isset === TRUE) && ($GLOBALS['__module'] != 'unknown')) ;
778 // Getter for 'output_mode' value
779 function getScriptOutputMode () {
781 if (!isset($GLOBALS[__FUNCTION__])) {
782 // Is the output mode set?
783 if (!isOutputModeSet()) {
784 // No, then abort here
785 reportBug(__FUNCTION__, __LINE__, 'Output mode not set.');
789 $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode'];
793 return $GLOBALS[__FUNCTION__];
796 // Setter for 'output_mode' value
797 function setScriptOutputMode ($newOutputMode) {
798 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
799 $GLOBALS['__output_mode'] = (int) $newOutputMode;
802 // Checks whether output_mode is set and optionally aborts on miss
803 function isOutputModeSet ($strict = FALSE) {
805 $isset = (isset($GLOBALS['__output_mode']));
807 // Should we abort here?
808 if (($strict === TRUE) && ($isset === FALSE)) {
810 reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
817 // Enables block-mode
818 function enableBlockMode ($enabled = TRUE) {
819 $GLOBALS['__block_mode'] = $enabled;
822 // Checks whether block-mode is enabled
823 function isBlockModeEnabled () {
825 if (!isset($GLOBALS['__block_mode'])) {
827 reportBug(__FUNCTION__, __LINE__, '__block_mode is not set.');
831 return $GLOBALS['__block_mode'];
834 // Wrapper for redirectToUrl but URL comes from a configuration entry
835 function redirectToConfiguredUrl ($configEntry) {
837 redirectToUrl(getConfig($configEntry));
840 // Wrapper function to redirect from member-only modules to index
841 function redirectToIndexMemberOnlyModule () {
842 // Do the redirect here
843 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
846 // Wrapper function to redirect to current URL
847 function redirectToRequestUri () {
848 redirectToUrl(basename(detectRequestUri()));
851 // Wrapper function to redirect to de-refered URL
852 function redirectToDereferedUrl ($url) {
854 redirectToUrl(generateDereferrerUrl($url));
857 // Wrapper function for checking if extension is installed and newer or same version
858 function isExtensionInstalledAndNewer ($ext_name, $ext_ver) {
859 // Is an cache entry found?
860 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
862 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE));
864 // Cache hits should be incremented twice
865 incrementStatsEntry('cache_hits', 2);
869 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
870 return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
873 // Wrapper function for checking if extension is installed and older than given version
874 function isExtensionInstalledAndOlder ($ext_name, $ext_ver) {
875 // Is an cache entry found?
876 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
878 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '<') === TRUE));
880 // Cache hits should be incremented twice
881 incrementStatsEntry('cache_hits', 2);
885 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
886 return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
890 function setUsername ($userName) {
891 $GLOBALS['username'] = (string) $userName;
895 function getUsername () {
897 if (!isset($GLOBALS['username'])) {
898 // No, so it has to be a guest
899 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
903 return $GLOBALS['username'];
906 // Wrapper function for installation phase
907 function isInstaller () {
909 if (!isset($GLOBALS[__FUNCTION__])) {
911 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
915 return $GLOBALS[__FUNCTION__];
918 // Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
919 function isDemoModeActive () {
921 if (!isset($GLOBALS[__FUNCTION__])) {
923 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
927 return $GLOBALS[__FUNCTION__];
930 // Getter for PHP caching value
931 function getPhpCaching () {
932 return $GLOBALS['php_caching'];
935 // Checks whether the admin hash is set
936 function isAdminHashSet ($adminId) {
937 // Is the array there?
938 if (!isset($GLOBALS['cache_array']['admin'])) {
939 // Missing array should be reported
940 reportBug(__FUNCTION__, __LINE__, 'Cache not set.');
943 // Check for admin hash
944 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
947 // Setter for admin hash
948 function setAdminHash ($adminId, $hash) {
949 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
952 // Getter for current admin login
953 function getCurrentAdminLogin () {
955 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
958 if (!isset($GLOBALS[__FUNCTION__])) {
960 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
964 return $GLOBALS[__FUNCTION__];
967 // Setter for admin id (and current)
968 function setAdminId ($adminId) {
970 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
973 $status = setSession('admin_id', bigintval($adminId));
976 setCurrentAdminId($adminId);
982 // Setter for admin_last
983 function setAdminLast ($adminLast) {
985 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
988 $status = setSession('admin_last', $adminLast);
994 // Setter for admin_md5
995 function setAdminMd5 ($adminMd5) {
997 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
1000 $status = setSession('admin_md5', $adminMd5);
1002 // Remove cache to get correct results
1003 unset($GLOBALS['isAdmin']);
1009 // Getter for admin_md5
1010 function getAdminMd5 () {
1011 // Log debug message
1012 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
1015 return getSession('admin_md5');
1018 // Init user data array
1019 function initUserData () {
1020 // User id should not be zero
1021 if (!isValidId(getCurrentUserId())) {
1022 // Should be always valid
1023 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
1027 unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
1028 $GLOBALS['user_data'][getCurrentUserId()] = array();
1031 // Getter for user data
1032 function getUserData ($column) {
1033 // User id should not be zero
1034 if (!isValidId(getCurrentUserId())) {
1035 // Should be always valid
1036 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
1042 if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
1044 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
1051 // Checks whether given user data is set to 'Y'
1052 function isUserDataEnabled ($column) {
1054 if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
1056 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
1060 return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
1063 // Geter for whole user data array
1064 function getUserDataArray () {
1066 $userid = getCurrentUserId();
1068 // Is the current userid valid?
1069 if (!isValidId($userid)) {
1070 // Should be always valid
1071 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
1074 // Get the whole array if found
1075 if (isset($GLOBALS['user_data'][$userid])) {
1076 // Found, so return it
1077 return $GLOBALS['user_data'][$userid];
1079 // Return empty array
1084 // Checks if the user data is valid, this may indicate that the user has logged
1085 // in, but you should use isMember() if you want to find that out.
1086 function isValidUserData () {
1087 // User id should not be zero so abort here
1088 if (!isCurrentUserIdSet()) {
1089 // Debug message, may be noisy
1090 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
1097 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
1099 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
1102 // Return the result
1103 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1106 // Setter for current userid
1107 function setCurrentUserId ($userid) {
1109 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - ENTERED!');
1111 // Is the cache from below functions different?
1112 if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) {
1114 unsetCurrentUserId();
1118 $GLOBALS['current_userid'] = bigintval($userid);
1120 // Unset it to re-determine the actual state
1121 unset($GLOBALS['is_userdata_valid'][$userid]);
1124 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - EXIT!');
1127 // Getter for current userid
1128 function getCurrentUserId () {
1130 if (!isset($GLOBALS[__FUNCTION__])) {
1131 // Userid must be set before it can be used
1132 if (!isCurrentUserIdSet()) {
1134 reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1137 // Set userid in cache
1138 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1142 return $GLOBALS[__FUNCTION__];
1145 // Checks if current userid is set
1146 function isCurrentUserIdSet () {
1148 if (!isset($GLOBALS[__FUNCTION__])) {
1150 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidId($GLOBALS['current_userid'])));
1154 return $GLOBALS[__FUNCTION__];
1157 // Unsets current userid
1158 function unsetCurrentUserId () {
1160 if (isset($GLOBALS['current_userid'])) {
1162 unset($GLOBALS['isValidId'][$GLOBALS['current_userid']]);
1165 // Unset all cache entries
1166 unset($GLOBALS['current_userid']);
1167 unset($GLOBALS['getCurrentUserId']);
1168 unset($GLOBALS['isCurrentUserIdSet']);
1171 // Checks whether we are debugging template cache
1172 function isDebugTemplateCacheEnabled () {
1174 if (!isset($GLOBALS[__FUNCTION__])) {
1176 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_TEMPLATE_CACHE')) && (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y'));
1180 return $GLOBALS[__FUNCTION__];
1183 // Wrapper for fetchUserData() and getUserData() calls
1184 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1185 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1187 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1191 // Can we fetch the user data?
1192 if ((isValidId($userid)) && (fetchUserData($userid, $keyColumn))) {
1193 // Now get the data back
1194 $data = getUserData($valueColumn);
1198 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1202 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1203 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1206 // Wrapper for strpos() to ease porting from deprecated ereg() function
1207 function isInString ($needle, $haystack) {
1208 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== FALSE));
1209 return (strpos($haystack, $needle) !== FALSE);
1212 // Wrapper for strpos() to ease porting from deprecated eregi() function
1213 // This function is case-insensitive
1214 function isInStringIgnoreCase ($needle, $haystack) {
1215 return (isInString(strtolower($needle), strtolower($haystack)));
1218 // Wrapper to check for if fatal errors where detected
1219 function ifFatalErrorsDetected () {
1220 // Just call the inner function
1221 return (getTotalFatalErrors() > 0);
1224 // Checks whether a HTTP status has been set
1225 function isHttpStatusSet () {
1226 // Is it set and not empty?
1227 return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1230 // Setter for HTTP status
1231 function setHttpStatus ($status) {
1232 $GLOBALS['http_status'] = (string) $status;
1235 // Getter for HTTP status
1236 function getHttpStatus () {
1237 // Is the status set?
1238 if (!isHttpStatusSet()) {
1240 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1244 return $GLOBALS['http_status'];
1248 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1249 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1251 * ----------------------------------------------------------------------------
1252 * If you want to redirect, please use redirectToUrl(); instead
1253 * ----------------------------------------------------------------------------
1255 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1257 * @link http://support.microsoft.com/kb/q176113/
1258 * @author Andreas Gohr <andi@splitbrain.org>
1261 function sendRawRedirect ($url) {
1262 //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url);
1264 // Clear output buffer
1265 clearOutputBuffer();
1267 // Clear own output buffer
1268 $GLOBALS['__output'] = '';
1270 // To make redirects working (no content type), output mode must be raw
1271 setScriptOutputMode(-1);
1273 // Send helping header
1274 setHttpStatus('302 Found');
1276 // always close the session
1277 session_write_close();
1279 // Revert entity &
1280 $url = str_replace('&', '&', $url);
1281 //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url);
1283 // check if running on IIS < 6 with CGI-PHP
1284 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1285 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1286 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1287 ($matches[1] < 6)) {
1288 // Send the IIS header
1289 addHttpHeader('Refresh: 0;url=' . $url);
1291 // Send generic header
1292 addHttpHeader('Location: ' . $url);
1299 // Determines the country of the given user id
1300 function determineCountry ($userid) {
1302 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1303 // Default is 'invalid'
1304 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1306 // Is extension country active?
1307 if (isExtensionActive('country')) {
1308 // Determine the right country code through the country id
1309 $id = getUserData('country_code');
1311 // Then handle it over
1312 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1314 // Get raw code from user data
1315 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1320 return $GLOBALS[__FUNCTION__][$userid];
1323 // "Getter" for total confirmed user accounts
1324 function getTotalConfirmedUser () {
1326 if (!isset($GLOBALS[__FUNCTION__])) {
1328 if (isExtensionActive('user')) {
1329 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1331 $GLOBALS[__FUNCTION__] = 0;
1335 // Return cached value
1336 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1337 return $GLOBALS[__FUNCTION__];
1340 // "Getter" for total unconfirmed user accounts
1341 function getTotalUnconfirmedUser () {
1343 if (!isset($GLOBALS[__FUNCTION__])) {
1345 if (isExtensionActive('user')) {
1346 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1348 $GLOBALS[__FUNCTION__] = 0;
1352 // Return cached value
1353 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1354 return $GLOBALS[__FUNCTION__];
1357 // "Getter" for total locked user accounts
1358 function getTotalLockedUser () {
1360 if (!isset($GLOBALS[__FUNCTION__])) {
1362 if (isExtensionActive('user')) {
1363 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1365 $GLOBALS[__FUNCTION__] = 0;
1369 // Return cached value
1370 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1371 return $GLOBALS[__FUNCTION__];
1374 // "Getter" for total locked user accounts
1375 function getTotalRandomRefidUser () {
1377 if (!isset($GLOBALS[__FUNCTION__])) {
1379 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1380 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
1382 $GLOBALS[__FUNCTION__] = 0;
1386 // Return cached value
1387 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1388 return $GLOBALS[__FUNCTION__];
1391 // Is given id number valid?
1392 function isValidId ($id) {
1394 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id[' . gettype($id) . ']=' . $id);
1397 if (!isset($GLOBALS[__FUNCTION__][$id])) {
1399 $GLOBALS[__FUNCTION__][$id] = ((isValidNumber($id)) && (!is_bool($id)) && ($id != '00000') && ($id > 0));
1403 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',result=' . intval($GLOBALS[__FUNCTION__][$id]));
1404 return $GLOBALS[__FUNCTION__][$id];
1407 // Checks whether a valid number is given
1408 function isValidNumber ($num) {
1410 return ((!is_null($num)) && (!empty($num)) && ('*' . bigintval($num, TRUE, FALSE) . '*' == '*' . $num . '*'));
1414 function encodeEntities ($str) {
1416 $str = secureString($str, TRUE, TRUE);
1418 // Encode dollar sign as well
1419 $str = str_replace('$', '$', $str);
1425 // Getter for current year (default)
1426 function getYear ($timestamp = NULL) {
1428 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1429 // If NULL is set, use time()
1430 if (is_null($timestamp)) {
1431 $timestamp = time();
1435 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1439 return $GLOBALS[__FUNCTION__][$timestamp];
1442 // Getter for current month (default)
1443 function getMonth ($timestamp = NULL) {
1445 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1446 // If NULL is set, use time()
1447 if (is_null($timestamp)) {
1448 // Use time() which is current timestamp
1449 $timestamp = time();
1453 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1457 return $GLOBALS[__FUNCTION__][$timestamp];
1460 // Getter for current hour (default)
1461 function getHour ($timestamp = NULL) {
1463 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1465 if (is_null($timestamp)) {
1466 $timestamp = time();
1470 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1474 return $GLOBALS[__FUNCTION__][$timestamp];
1477 // Getter for current day (default)
1478 function getDay ($timestamp = NULL) {
1480 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1482 if (is_null($timestamp)) {
1483 $timestamp = time();
1487 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1491 return $GLOBALS[__FUNCTION__][$timestamp];
1494 // Getter for current week (default)
1495 function getWeek ($timestamp = NULL) {
1497 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1499 if (is_null($timestamp)) $timestamp = time();
1502 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1506 return $GLOBALS[__FUNCTION__][$timestamp];
1509 // Getter for current short_hour (default)
1510 function getShortHour ($timestamp = NULL) {
1512 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1514 if (is_null($timestamp)) $timestamp = time();
1517 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1521 return $GLOBALS[__FUNCTION__][$timestamp];
1524 // Getter for current long_hour (default)
1525 function getLongHour ($timestamp = NULL) {
1527 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1529 if (is_null($timestamp)) $timestamp = time();
1532 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1536 return $GLOBALS[__FUNCTION__][$timestamp];
1539 // Getter for current second (default)
1540 function getSecond ($timestamp = NULL) {
1542 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1544 if (is_null($timestamp)) $timestamp = time();
1547 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1551 return $GLOBALS[__FUNCTION__][$timestamp];
1554 // Getter for current minute (default)
1555 function getMinute ($timestamp = NULL) {
1557 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1559 if (is_null($timestamp)) $timestamp = time();
1562 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1566 return $GLOBALS[__FUNCTION__][$timestamp];
1569 // Checks whether the title decoration is enabled
1570 function isTitleDecorationEnabled () {
1572 if (!isset($GLOBALS[__FUNCTION__])) {
1574 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_title_deco')) && (getConfig('enable_title_deco') == 'Y'));
1578 return $GLOBALS[__FUNCTION__];
1581 // Checks whether filter usage updates are enabled (expensive queries!)
1582 function isFilterUsageUpdateEnabled () {
1584 if (!isset($GLOBALS[__FUNCTION__])) {
1586 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1590 return $GLOBALS[__FUNCTION__];
1593 // Checks whether debugging of weekly resets is enabled
1594 function isWeeklyResetDebugEnabled () {
1596 if (!isset($GLOBALS[__FUNCTION__])) {
1598 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1602 return $GLOBALS[__FUNCTION__];
1605 // Checks whether debugging of monthly resets is enabled
1606 function isMonthlyResetDebugEnabled () {
1608 if (!isset($GLOBALS[__FUNCTION__])) {
1610 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1614 return $GLOBALS[__FUNCTION__];
1617 // Checks whether debugging of yearly resets is enabled
1618 function isYearlyResetDebugEnabled () {
1620 if (!isset($GLOBALS[__FUNCTION__])) {
1622 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y'));
1626 return $GLOBALS[__FUNCTION__];
1629 // Checks whether displaying of debug SQLs are enabled
1630 function isDisplayDebugSqlEnabled () {
1632 if (!isset($GLOBALS[__FUNCTION__])) {
1634 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (isConfigEntrySet('display_debug_sql')) && (getDisplayDebugSqls() == 'Y'));
1638 return $GLOBALS[__FUNCTION__];
1641 // Checks whether module title is enabled
1642 function isModuleTitleEnabled () {
1644 if (!isset($GLOBALS[__FUNCTION__])) {
1646 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_mod_title')) && (getConfig('enable_mod_title') == 'Y'));
1650 return $GLOBALS[__FUNCTION__];
1653 // Checks whether what title is enabled
1654 function isWhatTitleEnabled () {
1656 if (!isset($GLOBALS[__FUNCTION__])) {
1658 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_what_title')) && (getConfig('enable_what_title') == 'Y'));
1662 return $GLOBALS[__FUNCTION__];
1665 // "Getter" for internal_stats
1666 function getInternalStats () {
1668 if (!isset($GLOBALS[__FUNCTION__])) {
1670 $GLOBALS[__FUNCTION__] = getConfig('internal_stats');
1674 return $GLOBALS[__FUNCTION__];
1677 // Checks whether stats are enabled
1678 function ifInternalStatsEnabled () {
1680 if (!isset($GLOBALS[__FUNCTION__])) {
1681 // Then determine it, do not add isExtensionInstalledAndNewer() here as it breaks very first SQL query
1682 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('internal_stats')) && (getInternalStats() == 'Y'));
1685 // Return cached value
1686 return $GLOBALS[__FUNCTION__];
1689 // Checks whether admin-notification of certain user actions is enabled
1690 function isAdminNotificationEnabled () {
1692 if (!isset($GLOBALS[__FUNCTION__])) {
1694 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.3.0')) && (isConfigEntrySet('admin_notify')) && (getAdminNotify() == 'Y'));
1698 return $GLOBALS[__FUNCTION__];
1701 // Checks whether random referral id selection is enabled
1702 function isRandomReferralIdEnabled () {
1704 if (!isset($GLOBALS[__FUNCTION__])) {
1706 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isConfigEntrySet('select_user_zero_refid')) && (getSelectUserZeroRefid() == 'Y'));
1710 return $GLOBALS[__FUNCTION__];
1713 // "Getter" for default language
1714 function getDefaultLanguage () {
1716 if (!isset($GLOBALS[__FUNCTION__])) {
1718 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1722 return $GLOBALS[__FUNCTION__];
1725 // "Getter" for default referral id
1726 function getDefRefid () {
1728 if (!isset($GLOBALS[__FUNCTION__])) {
1730 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1734 return $GLOBALS[__FUNCTION__];
1737 // "Getter" for path
1738 function getPath () {
1740 if (!isset($GLOBALS[__FUNCTION__])) {
1742 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1746 return $GLOBALS[__FUNCTION__];
1750 function getUrl () {
1752 if (!isset($GLOBALS[__FUNCTION__])) {
1754 $GLOBALS[__FUNCTION__] = getConfig('URL');
1758 return $GLOBALS[__FUNCTION__];
1761 // "Getter" for cache_path
1762 function getCachePath () {
1764 if (!isset($GLOBALS[__FUNCTION__])) {
1766 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1770 return $GLOBALS[__FUNCTION__];
1773 // "Getter" for cache_extension
1774 function getCacheExtension () {
1776 if (!isset($GLOBALS[__FUNCTION__])) {
1778 $GLOBALS[__FUNCTION__] = getConfig('CACHE_EXTENSION');
1782 return $GLOBALS[__FUNCTION__];
1785 // "Getter" for WRITE_FOOTER
1786 function getWriteFooter () {
1788 if (!isset($GLOBALS[__FUNCTION__])) {
1790 $GLOBALS[__FUNCTION__] = getConfig('WRITE_FOOTER');
1794 return $GLOBALS[__FUNCTION__];
1797 // "Getter" for secret_key
1798 function getSecretKey () {
1800 if (!isset($GLOBALS[__FUNCTION__])) {
1802 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1806 return $GLOBALS[__FUNCTION__];
1809 // "Getter" for SITE_KEY
1810 function getSiteKey () {
1812 if (!isset($GLOBALS[__FUNCTION__])) {
1814 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1818 return $GLOBALS[__FUNCTION__];
1821 // "Getter" for DATE_KEY
1822 function getDateKey () {
1824 if (!isset($GLOBALS[__FUNCTION__])) {
1826 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1830 return $GLOBALS[__FUNCTION__];
1833 // "Getter" for master_salt
1834 function getMasterSalt () {
1836 if (!isset($GLOBALS[__FUNCTION__])) {
1838 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1842 return $GLOBALS[__FUNCTION__];
1845 // "Getter" for prime
1846 function getPrime () {
1848 if (!isset($GLOBALS[__FUNCTION__])) {
1850 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1854 return $GLOBALS[__FUNCTION__];
1857 // "Getter" for encrypt_separator
1858 function getEncryptSeparator () {
1860 if (!isset($GLOBALS[__FUNCTION__])) {
1862 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1866 return $GLOBALS[__FUNCTION__];
1869 // "Getter" for mysql_prefix
1870 function getMysqlPrefix () {
1872 if (!isset($GLOBALS[__FUNCTION__])) {
1874 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1878 return $GLOBALS[__FUNCTION__];
1881 // "Getter" for table_type
1882 function getTableType () {
1884 if (!isset($GLOBALS[__FUNCTION__])) {
1886 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1890 return $GLOBALS[__FUNCTION__];
1893 // "Getter" for db_type
1894 function getDbType () {
1896 if (!isset($GLOBALS[__FUNCTION__])) {
1898 $GLOBALS[__FUNCTION__] = getConfig('_DB_TYPE');
1902 return $GLOBALS[__FUNCTION__];
1905 // "Getter" for salt_length
1906 function getSaltLength () {
1908 if (!isset($GLOBALS[__FUNCTION__])) {
1910 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1914 return $GLOBALS[__FUNCTION__];
1917 // "Getter" for output_mode
1918 function getOutputMode () {
1920 if (!isset($GLOBALS[__FUNCTION__])) {
1922 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1926 return $GLOBALS[__FUNCTION__];
1929 // "Getter" for full_version
1930 function getFullVersion () {
1932 if (!isset($GLOBALS[__FUNCTION__])) {
1934 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1938 return $GLOBALS[__FUNCTION__];
1941 // "Getter" for title
1942 function getTitle () {
1944 if (!isset($GLOBALS[__FUNCTION__])) {
1946 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1950 return $GLOBALS[__FUNCTION__];
1953 // "Getter" for server_url
1954 function getServerUrl () {
1956 if (!isset($GLOBALS[__FUNCTION__])) {
1958 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1962 return $GLOBALS[__FUNCTION__];
1965 // "Getter" for mt_word
1966 function getMtWord () {
1968 if (!isset($GLOBALS[__FUNCTION__])) {
1970 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1974 return $GLOBALS[__FUNCTION__];
1977 // "Getter" for mt_word2
1978 function getMtWord2 () {
1980 if (!isset($GLOBALS[__FUNCTION__])) {
1982 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1986 return $GLOBALS[__FUNCTION__];
1989 // "Getter" for mt_word3
1990 function getMtWord3 () {
1992 if (!isset($GLOBALS[__FUNCTION__])) {
1994 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
1998 return $GLOBALS[__FUNCTION__];
2001 // "Getter" for START_TDAY
2002 function getStartTday () {
2004 if (!isset($GLOBALS[__FUNCTION__])) {
2006 $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
2010 return $GLOBALS[__FUNCTION__];
2013 // "Getter" for START_YDAY
2014 function getStartYday () {
2016 if (!isset($GLOBALS[__FUNCTION__])) {
2018 $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
2022 return $GLOBALS[__FUNCTION__];
2025 // "Getter" for main_title
2026 function getMainTitle () {
2028 if (!isset($GLOBALS[__FUNCTION__])) {
2030 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
2034 return $GLOBALS[__FUNCTION__];
2037 // "Getter" for file_hash
2038 function getFileHash () {
2040 if (!isset($GLOBALS[__FUNCTION__])) {
2042 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
2046 return $GLOBALS[__FUNCTION__];
2049 // "Getter" for pass_scramble
2050 function getPassScramble () {
2052 if (!isset($GLOBALS[__FUNCTION__])) {
2054 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
2058 return $GLOBALS[__FUNCTION__];
2061 // "Getter" for ap_inactive_since
2062 function getApInactiveSince () {
2064 if (!isset($GLOBALS[__FUNCTION__])) {
2066 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
2070 return $GLOBALS[__FUNCTION__];
2073 // "Getter" for user_min_confirmed
2074 function getUserMinConfirmed () {
2076 if (!isset($GLOBALS[__FUNCTION__])) {
2078 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
2082 return $GLOBALS[__FUNCTION__];
2084 // "Getter" for points
2085 function getPoints () {
2087 if (!isset($GLOBALS[__FUNCTION__])) {
2089 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
2093 return $GLOBALS[__FUNCTION__];
2096 // "Getter" for slogan
2097 function getSlogan () {
2099 if (!isset($GLOBALS[__FUNCTION__])) {
2101 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
2105 return $GLOBALS[__FUNCTION__];
2108 // "Getter" for copy
2109 function getCopy () {
2111 if (!isset($GLOBALS[__FUNCTION__])) {
2113 $GLOBALS[__FUNCTION__] = getConfig('COPY');
2117 return $GLOBALS[__FUNCTION__];
2120 // "Getter" for webmaster
2121 function getWebmaster () {
2123 if (!isset($GLOBALS[__FUNCTION__])) {
2125 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
2129 return $GLOBALS[__FUNCTION__];
2132 // "Getter" for sql_count
2133 function getSqlCount () {
2135 if (!isset($GLOBALS[__FUNCTION__])) {
2137 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2141 return $GLOBALS[__FUNCTION__];
2144 // "Getter" for num_templates
2145 function getNumTemplates () {
2147 if (!isset($GLOBALS[__FUNCTION__])) {
2149 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2153 return $GLOBALS[__FUNCTION__];
2156 // "Getter" for dns_cache_timeout
2157 function getDnsCacheTimeout () {
2159 if (!isset($GLOBALS[__FUNCTION__])) {
2161 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2165 return $GLOBALS[__FUNCTION__];
2168 // "Getter" for menu_blur_spacer
2169 function getMenuBlurSpacer () {
2171 if (!isset($GLOBALS[__FUNCTION__])) {
2173 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2177 return $GLOBALS[__FUNCTION__];
2180 // "Getter" for points_register
2181 function getPointsRegister () {
2183 if (!isset($GLOBALS[__FUNCTION__])) {
2185 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2189 return $GLOBALS[__FUNCTION__];
2192 // "Getter" for points_ref
2193 function getPointsRef () {
2195 if (!isset($GLOBALS[__FUNCTION__])) {
2197 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2201 return $GLOBALS[__FUNCTION__];
2204 // "Getter" for ref_payout
2205 function getRefPayout () {
2207 if (!isset($GLOBALS[__FUNCTION__])) {
2209 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2213 return $GLOBALS[__FUNCTION__];
2216 // "Getter" for online_timeout
2217 function getOnlineTimeout () {
2219 if (!isset($GLOBALS[__FUNCTION__])) {
2221 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2225 return $GLOBALS[__FUNCTION__];
2228 // "Getter" for index_home
2229 function getIndexHome () {
2231 if (!isset($GLOBALS[__FUNCTION__])) {
2233 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2237 return $GLOBALS[__FUNCTION__];
2240 // "Getter" for one_day
2241 function getOneDay () {
2243 if (!isset($GLOBALS[__FUNCTION__])) {
2245 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2249 return $GLOBALS[__FUNCTION__];
2252 // "Getter" for img_type
2253 function getImgType () {
2255 if (!isset($GLOBALS[__FUNCTION__])) {
2257 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2261 return $GLOBALS[__FUNCTION__];
2264 // "Getter" for code_length
2265 function getCodeLength () {
2267 if (!isset($GLOBALS[__FUNCTION__])) {
2269 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2273 return $GLOBALS[__FUNCTION__];
2276 // "Getter" for min_password_length
2277 function getMinPasswordLength () {
2279 if (!isset($GLOBALS[__FUNCTION__])) {
2281 $GLOBALS[__FUNCTION__] = getConfig('min_password_length');
2285 return $GLOBALS[__FUNCTION__];
2288 // "Getter" for min_password_score
2289 function getMinPasswordScore () {
2291 if (!isset($GLOBALS[__FUNCTION__])) {
2293 $GLOBALS[__FUNCTION__] = getConfig('min_password_score');
2297 return $GLOBALS[__FUNCTION__];
2300 // "Getter" for admin_menu
2301 function getAdminMenu () {
2303 if (!isset($GLOBALS[__FUNCTION__])) {
2305 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2309 return $GLOBALS[__FUNCTION__];
2312 // "Getter" for last_hourly
2313 function getLastHourly () {
2315 if (!isset($GLOBALS[__FUNCTION__])) {
2317 $GLOBALS[__FUNCTION__] = getConfig('last_hourly');
2321 return $GLOBALS[__FUNCTION__];
2324 // "Getter" for last_daily
2325 function getLastDaily () {
2327 if (!isset($GLOBALS[__FUNCTION__])) {
2329 $GLOBALS[__FUNCTION__] = getConfig('last_daily');
2333 return $GLOBALS[__FUNCTION__];
2336 // "Getter" for last_weekly
2337 function getLastWeekly () {
2339 if (!isset($GLOBALS[__FUNCTION__])) {
2341 $GLOBALS[__FUNCTION__] = getConfig('last_weekly');
2345 return $GLOBALS[__FUNCTION__];
2348 // "Getter" for last_monthly
2349 function getLastMonthly () {
2351 if (!isset($GLOBALS[__FUNCTION__])) {
2353 $GLOBALS[__FUNCTION__] = getConfig('last_monthly');
2357 return $GLOBALS[__FUNCTION__];
2360 // "Getter" for last_yearly
2361 function getLastYearly () {
2363 if (!isset($GLOBALS[__FUNCTION__])) {
2365 $GLOBALS[__FUNCTION__] = getConfig('last_yearly');
2369 return $GLOBALS[__FUNCTION__];
2372 // "Getter" for mails_page
2373 function getMailsPage () {
2375 if (!isset($GLOBALS[__FUNCTION__])) {
2377 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2381 return $GLOBALS[__FUNCTION__];
2384 // "Getter" for rand_no
2385 function getRandNo () {
2387 if (!isset($GLOBALS[__FUNCTION__])) {
2389 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2393 return $GLOBALS[__FUNCTION__];
2396 // "Getter" for __DB_NAME
2397 function getDbName () {
2399 if (!isset($GLOBALS[__FUNCTION__])) {
2401 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2405 return $GLOBALS[__FUNCTION__];
2408 // "Getter" for DOMAIN
2409 function getDomain () {
2411 if (!isset($GLOBALS[__FUNCTION__])) {
2413 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2417 return $GLOBALS[__FUNCTION__];
2420 // "Getter" for proxy_username
2421 function getProxyUsername () {
2423 if (!isset($GLOBALS[__FUNCTION__])) {
2425 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2429 return $GLOBALS[__FUNCTION__];
2432 // "Getter" for proxy_password
2433 function getProxyPassword () {
2435 if (!isset($GLOBALS[__FUNCTION__])) {
2437 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2441 return $GLOBALS[__FUNCTION__];
2444 // "Getter" for proxy_host
2445 function getProxyHost () {
2447 if (!isset($GLOBALS[__FUNCTION__])) {
2449 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2453 return $GLOBALS[__FUNCTION__];
2456 // "Getter" for proxy_port
2457 function getProxyPort () {
2459 if (!isset($GLOBALS[__FUNCTION__])) {
2461 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2465 return $GLOBALS[__FUNCTION__];
2468 // "Getter" for SMTP_HOSTNAME
2469 function getSmtpHostname () {
2471 if (!isset($GLOBALS[__FUNCTION__])) {
2473 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2477 return $GLOBALS[__FUNCTION__];
2480 // "Getter" for SMTP_USER
2481 function getSmtpUser () {
2483 if (!isset($GLOBALS[__FUNCTION__])) {
2485 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2489 return $GLOBALS[__FUNCTION__];
2492 // "Getter" for SMTP_PASSWORD
2493 function getSmtpPassword () {
2495 if (!isset($GLOBALS[__FUNCTION__])) {
2497 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2501 return $GLOBALS[__FUNCTION__];
2504 // "Getter" for points_word
2505 function getPointsWord () {
2507 if (!isset($GLOBALS[__FUNCTION__])) {
2509 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2513 return $GLOBALS[__FUNCTION__];
2516 // "Getter" for profile_lock
2517 function getProfileLock () {
2519 if (!isset($GLOBALS[__FUNCTION__])) {
2521 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2525 return $GLOBALS[__FUNCTION__];
2528 // "Getter" for url_tlock
2529 function getUrlTlock () {
2531 if (!isset($GLOBALS[__FUNCTION__])) {
2533 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2537 return $GLOBALS[__FUNCTION__];
2540 // "Getter" for title_left
2541 function getTitleLeft () {
2543 if (!isset($GLOBALS[__FUNCTION__])) {
2545 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2549 return $GLOBALS[__FUNCTION__];
2552 // "Getter" for title_right
2553 function getTitleRight () {
2555 if (!isset($GLOBALS[__FUNCTION__])) {
2557 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2561 return $GLOBALS[__FUNCTION__];
2564 // "Getter" for title_middle
2565 function getTitleMiddle () {
2567 if (!isset($GLOBALS[__FUNCTION__])) {
2569 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2573 return $GLOBALS[__FUNCTION__];
2576 // Getter for 'display_home_in_index'
2577 function getDisplayHomeInIndex () {
2578 // Is the cache entry set?
2579 if (!isset($GLOBALS[__FUNCTION__])) {
2580 // No, so determine it
2581 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2584 // Return cached entry
2585 return $GLOBALS[__FUNCTION__];
2588 // Checks whether 'display_home_in_index' is 'Y'
2589 function isDisplayHomeInIndexEnabled () {
2590 // Is the cache entry set?
2591 if (!isset($GLOBALS[__FUNCTION__])) {
2592 // No, so determine it
2593 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isConfigEntrySet('display_home_in_index')) && (getDisplayHomeInIndex() == 'Y'));
2596 // Return cached entry
2597 return $GLOBALS[__FUNCTION__];
2600 // Getter for 'show_points_unconfirmed'
2601 function getShowPointsUnconfirmed () {
2602 // Is the cache entry set?
2603 if (!isset($GLOBALS[__FUNCTION__])) {
2604 // No, so determine it
2605 $GLOBALS[__FUNCTION__] = getConfig('show_points_unconfirmed');
2608 // Return cached entry
2609 return $GLOBALS[__FUNCTION__];
2612 // Checks whether 'show_points_unconfirmed' is 'Y'
2613 function isShowPointsUnconfirmedEnabled () {
2614 // Is the cache entry set?
2615 if (!isset($GLOBALS[__FUNCTION__])) {
2616 // No, so determine it
2617 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.5.5')) && (isConfigEntrySet('show_points_unconfirmed')) && (getShowPointsUnconfirmed() == 'Y'));
2620 // Return cached entry
2621 return $GLOBALS[__FUNCTION__];
2624 // Getter for 'youre_here'
2625 function getYoureHere () {
2626 // Is the cache entry set?
2627 if (!isset($GLOBALS[__FUNCTION__])) {
2628 // No, so determine it
2629 $GLOBALS[__FUNCTION__] = getConfig('youre_here');
2632 // Return cached entry
2633 return $GLOBALS[__FUNCTION__];
2636 // Checks whether 'show_timings' is 'Y'
2637 function isYoureHereEnabled () {
2638 // Is the cache entry set?
2639 if (!isset($GLOBALS[__FUNCTION__])) {
2640 // No, so determine it
2641 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (isConfigEntrySet('youre_here')) && (getYoureHere() == 'Y'));
2644 // Return cached entry
2645 return $GLOBALS[__FUNCTION__];
2648 // Getter for 'show_timings'
2649 function getShowTimings () {
2650 // Is the cache entry set?
2651 if (!isset($GLOBALS[__FUNCTION__])) {
2652 // No, so determine it
2653 $GLOBALS[__FUNCTION__] = getConfig('show_timings');
2656 // Return cached entry
2657 return $GLOBALS[__FUNCTION__];
2660 // Checks whether 'show_timings' is 'Y'
2661 function isShowTimingsEnabled () {
2662 // Is the cache entry set?
2663 if (!isset($GLOBALS[__FUNCTION__])) {
2664 // No, so determine it
2665 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (isConfigEntrySet('show_timings')) && (getShowTimings() == 'Y'));
2668 // Return cached entry
2669 return $GLOBALS[__FUNCTION__];
2672 // Getter for 'ap_server_name_since'
2673 function getApServerNameSince () {
2674 // Is the cache entry set?
2675 if (!isset($GLOBALS[__FUNCTION__])) {
2676 // No, so determine it
2677 $GLOBALS[__FUNCTION__] = getConfig('ap_server_name_since');
2680 // Return cached entry
2681 return $GLOBALS[__FUNCTION__];
2684 // Getter for 'ap_server_name'
2685 function getApServerName () {
2686 // Is the cache entry set?
2687 if (!isset($GLOBALS[__FUNCTION__])) {
2688 // No, so determine it
2689 $GLOBALS[__FUNCTION__] = getConfig('ap_server_name');
2692 // Return cached entry
2693 return $GLOBALS[__FUNCTION__];
2696 // Getter for 'index_delay'
2697 function getIndexDelay () {
2698 // Is the cache entry set?
2699 if (!isset($GLOBALS[__FUNCTION__])) {
2700 // No, so determine it
2701 $GLOBALS[__FUNCTION__] = getConfig('index_delay');
2704 // Return cached entry
2705 return $GLOBALS[__FUNCTION__];
2708 // Checks whether 'ap_server_name' is 'Y'
2709 function isApServerNameEnabled () {
2710 // Is the cache entry set?
2711 if (!isset($GLOBALS[__FUNCTION__])) {
2712 // No, so determine it
2713 $GLOBALS[__FUNCTION__] = (getApServerName() == 'Y');
2716 // Return cached entry
2717 return $GLOBALS[__FUNCTION__];
2720 // Getter for 'admin_menu_javascript'
2721 function getAdminMenuJavascript () {
2722 // Is the cache entry set?
2723 if (!isset($GLOBALS[__FUNCTION__])) {
2724 // No, so determine it
2725 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2728 // Return cached entry
2729 return $GLOBALS[__FUNCTION__];
2732 // Getter for 'points_remove_account'
2733 function getPointsRemoveAccount () {
2734 // Is the cache entry set?
2735 if (!isset($GLOBALS[__FUNCTION__])) {
2736 // No, so determine it
2737 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2740 // Return cached entry
2741 return $GLOBALS[__FUNCTION__];
2744 // Getter for 'css_php'
2745 function getCssPhp () {
2746 // Is the cache entry set?
2747 if (!isset($GLOBALS[__FUNCTION__])) {
2748 // No, so determine it
2749 $GLOBALS[__FUNCTION__] = getConfig('css_php');
2752 // Return cached entry
2753 return $GLOBALS[__FUNCTION__];
2756 // Getter for 'guest_menu'
2757 function getGuestMenu () {
2758 // Is the cache entry set?
2759 if (!isset($GLOBALS[__FUNCTION__])) {
2760 // No, so determine it
2761 $GLOBALS[__FUNCTION__] = getConfig('guest_menu');
2764 // Return cached entry
2765 return $GLOBALS[__FUNCTION__];
2768 // Checks if guest menu is enabled
2769 function isGuestMenuEnabled () {
2770 // Is the cache entry set?
2771 if (!isset($GLOBALS[__FUNCTION__])) {
2772 // No, so determine it
2773 $GLOBALS[__FUNCTION__] = (getGuestMenu() == 'Y');
2776 // Return cached entry
2777 return $GLOBALS[__FUNCTION__];
2780 // Getter for 'member_menu'
2781 function getMemberMenu () {
2782 // Is the cache entry set?
2783 if (!isset($GLOBALS[__FUNCTION__])) {
2784 // No, so determine it
2785 $GLOBALS[__FUNCTION__] = getConfig('member_menu');
2788 // Return cached entry
2789 return $GLOBALS[__FUNCTION__];
2792 // Checks if member menu is enabled
2793 function isMemberMenuEnabled () {
2794 // Is the cache entry set?
2795 if (!isset($GLOBALS[__FUNCTION__])) {
2796 // No, so determine it
2797 $GLOBALS[__FUNCTION__] = (getMemberMenu() == 'Y');
2800 // Return cached entry
2801 return $GLOBALS[__FUNCTION__];
2804 // Getter for 'word_wrap'
2805 function getWordWrap () {
2806 // Is the cache entry set?
2807 if (!isset($GLOBALS[__FUNCTION__])) {
2808 // Construct config entry name
2809 $configEntry = getMenuModeFromModule() . '_word_wrap_' . getWhat();
2811 // Is a special config entry found or ext-sql_patches updated?
2812 if (isConfigEntrySet($configEntry)) {
2813 // A special config entry has been found, then use it
2814 $GLOBALS[__FUNCTION__] = getConfig($configEntry);
2815 } elseif (isExtensionInstalledAndNewer('other', '0.2.9')) {
2816 // No special config entry found, then use it as "fall-back"
2817 $GLOBALS[__FUNCTION__] = getConfig('word_wrap');
2819 // No, use default (15 characters)
2820 $GLOBALS[__FUNCTION__] = 15;
2824 // Return cached entry
2825 return $GLOBALS[__FUNCTION__];
2828 // Checks whether proxy configuration is used
2829 function isProxyUsed () {
2831 if (!isset($GLOBALS[__FUNCTION__])) {
2833 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (isValidNumber(getConfig('proxy_port'))));
2837 return $GLOBALS[__FUNCTION__];
2840 // Checks whether POST data contains selections
2841 function ifPostContainsSelections ($element = 'sel') {
2843 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2845 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2849 return $GLOBALS[__FUNCTION__][$element];
2852 // Checks whether verbose_sql is Y and returns true/false if so
2853 function isVerboseSqlEnabled () {
2855 if (!isset($GLOBALS[__FUNCTION__])) {
2857 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2861 return $GLOBALS[__FUNCTION__];
2864 // "Getter" for total user points
2865 function getTotalPoints ($userid) {
2867 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2868 // Init array for filter chain
2870 'userid' => $userid,
2874 // Run filter chain for getting more point values
2875 $data = runFilterChain('get_total_points', $data);
2878 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - getUserUsedPoints($userid);
2882 return $GLOBALS[__FUNCTION__][$userid];
2885 // Wrapper to get used points for given userid
2886 function getUserUsedPoints ($userid) {
2888 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2890 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2894 return $GLOBALS[__FUNCTION__][$userid];
2897 // Checks whether direct payment is allowed in configuration
2898 function isDirectPaymentEnabled () {
2900 if (!isset($GLOBALS[__FUNCTION__])) {
2902 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('allow_direct_pay')) && (getConfig('allow_direct_pay') == 'Y'));
2906 return $GLOBALS[__FUNCTION__];
2909 // Checks whether JavaScript-based admin menu is enabled
2910 function isAdminMenuJavascriptEnabled () {
2912 if (!isset($GLOBALS[__FUNCTION__])) {
2914 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (isConfigEntrySet('admin_menu_javascript')) && (getAdminMenuJavaScript() == 'Y'));
2918 return $GLOBALS[__FUNCTION__];
2921 // Wrapper to check if current task is for extension (not update)
2922 function isExtensionTask ($content) {
2924 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2926 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2930 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2933 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2934 function ifTesterAccountsAllowed () {
2935 // Is the cache entry set?
2936 if (!isset($GLOBALS[__FUNCTION__])) {
2937 // No, so determine it
2938 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2941 // Return cached entry
2942 return $GLOBALS[__FUNCTION__];
2945 // Wrapper to check if output mode is CSS
2946 function isCssOutputMode () {
2948 if (!isset($GLOBALS[__FUNCTION__])) {
2950 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2951 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2955 return $GLOBALS[__FUNCTION__];
2958 // Wrapper to check if output mode is HTML
2959 function isHtmlOutputMode () {
2961 if (!isset($GLOBALS[__FUNCTION__])) {
2963 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2964 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2968 return $GLOBALS[__FUNCTION__];
2971 // Wrapper to check if output mode is RAW
2972 function isRawOutputMode () {
2974 if (!isset($GLOBALS[__FUNCTION__])) {
2976 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2977 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2981 return $GLOBALS[__FUNCTION__];
2984 // Wrapper to check if output mode is AJAX
2985 function isAjaxOutputMode () {
2987 if (!isset($GLOBALS[__FUNCTION__])) {
2989 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2990 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2994 return $GLOBALS[__FUNCTION__];
2997 // Wrapper to check if output mode is image
2998 function isImageOutputMode () {
3000 if (!isset($GLOBALS[__FUNCTION__])) {
3002 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
3003 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
3007 return $GLOBALS[__FUNCTION__];
3010 // Wrapper to generate a user email link
3011 function generateWrappedUserEmailLink ($email) {
3012 // Just call the inner function
3013 return generateEmailLink($email, 'user_data');
3016 // Wrapper to check if user points are locked
3017 function ifUserPointsLocked ($userid) {
3018 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
3020 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
3022 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
3026 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
3027 return $GLOBALS[__FUNCTION__][$userid];
3030 // Appends a line to an existing file or creates it instantly with given content.
3031 // This function does always add a new-line character to every line.
3032 function appendLineToFile ($file, $line) {
3033 $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
3034 fwrite($fp, $line . PHP_EOL);
3038 // Wrapper for changeDataInFile() but with full path added
3039 function changeDataInInclude ($inc, $comment, $prefix, $suffix, $inserted, $seek=0) {
3041 $FQFN = getPath() . $inc;
3043 // Call inner function
3044 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
3047 // Wrapper for changing entries in config-local.php
3048 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
3049 // Call the inner function
3050 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
3053 // Shortens ucfirst(strtolower()) calls
3054 function firstCharUpperCase ($str) {
3055 return ucfirst(strtolower($str));
3058 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
3059 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
3060 // Get the configuration entry
3061 $configValue = getConfig($configEntry);
3063 // Call inner method
3064 return createTimeSelections($configValue, $configEntry, $stamps, $align);
3067 // Shortens converting of German comma to Computer's version in POST data
3068 function convertCommaToDotInPostData ($postEntry) {
3069 // Read and convert given entry
3070 $postValue = convertCommaToDot(postRequestElement($postEntry));
3073 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
3075 // ... and set it again
3076 setPostRequestElement($postEntry, $postValue);
3079 // Converts German commas to Computer's version in all entries
3080 function convertCommaToDotInPostDataArray ($postEntries) {
3081 // Replace german decimal comma with computer decimal dot
3082 foreach ($postEntries as $entry) {
3083 // Is the entry there?
3084 if (isPostRequestElementSet($entry)) {
3086 convertCommaToDotInPostData($entry);
3092 * Parses a string into a US formated float variable, taken from user comments
3093 * from PHP documentation website.
3095 * @param $floatString A string holding a float expression
3096 * @return $float Corresponding float variable
3097 * @author chris<at>georgakopoulos<dot>com
3098 * @link http://de.php.net/manual/en/function.floatval.php#92563
3100 function parseFloat ($floatString){
3102 $LocaleInfo = localeconv();
3104 // Remove thousand separators
3105 $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
3107 // Convert decimal point
3108 $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
3110 // Return float value of converted string
3111 return floatval($floatString);
3115 * Searches a multi-dimensional array (as used in many places) for given
3116 * key/value pair as taken from user comments from PHP documentation website.
3118 * @param $array An array with one or more dimensions
3119 * @param $key Key to look for
3120 * @param $value Value to look for
3121 * @param $parentIndex Parent index (ONLY INTERNAL USE!)
3122 * @return $results Resulted array or empty array if $array is no array
3123 * @author sunelbe<at>gmail<dot>com
3124 * @link http://de.php.net/manual/en/function.array-search.php#110120
3126 function search_array ($array, $key, $value, $parentIndex = NULL) {
3127 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
3128 // Init array result
3131 // Is $array really an array?
3132 if (is_array($array)) {
3133 // Search for whole array
3134 foreach ($array as $idx => $dummy) {
3135 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex);
3136 //* DEBUG: */ print 'idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',key=' . $key . ',value=' . $value . ',array=<pre>'.print_r($array, TRUE).'</pre>';
3137 // Is dummy an array?
3138 if ((is_array($dummy)) && ((is_null($parentIndex)) || ($parentIndex === $value))) {
3139 // Then search again
3140 $subResult = search_array($dummy, $key, $value, $idx);
3141 //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
3144 $results = merge_array($results, $subResult, TRUE);
3145 } elseif (($key == $idx) && (isset($array[$key])) && ($array[$key] === $value)) {
3146 // Is found, so add it
3147 $results[$parentIndex] = $array;
3148 //* DEBUG: */ print 'ARRAY: key=' . $key . ',idx=' . $idx . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',array=<pre>' . print_r($array, TRUE).'</pre>';
3153 // Return resulting array
3154 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
3158 // Generates a YES/NO option list from given default
3159 function generateYesNoOptions ($defaultValue = '') {
3161 return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
3164 // "Getter" for total available receivers
3165 function getTotalReceivers ($mode = 'normal') {
3167 $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
3173 // Wrapper "getter" to get total unconfirmed mails for given userid
3174 function getTotalUnconfirmedMails ($userid) {
3176 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
3178 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
3182 return $GLOBALS[__FUNCTION__][$userid];
3185 // Checks whether 'mailer_theme' was found in session
3186 function isMailerThemeSet () {
3188 if (!isset($GLOBALS[__FUNCTION__])) {
3190 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
3194 return $GLOBALS[__FUNCTION__];
3198 * Setter for theme in session (This setter does return the success of
3199 * setSession() which is required e.g. for destroySponsorSession().
3201 function setMailerTheme ($newTheme) {
3202 // Set it in session
3203 return setSession('mailer_theme', $newTheme);
3207 * Getter for theme from session (This getter does return 'mailer_theme' from
3208 * session data or throws an error if not possible
3210 function getMailerTheme () {
3212 if (!isset($GLOBALS[__FUNCTION__])) {
3213 // Is 'mailer_theme' set?
3214 if (!isMailerThemeSet()) {
3215 // No, then abort here
3216 reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
3219 // Get it and store it in cache
3220 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
3224 return $GLOBALS[__FUNCTION__];
3227 // "Getter" for last_module/last_what depending on ext-user version
3228 function getUserLastWhatName () {
3229 // Default is old one: last_module
3230 $columnName = 'last_module';
3232 // Is ext-user up-to-date?
3233 if (isExtensionInstalledAndNewer('user', '0.4.9')) {
3234 // Yes, then use new one
3235 $columnName = 'last_what';
3242 // "Getter" for all columns for given alias and separator
3243 function getAllPointColumns ($alias = NULL, $separator = ',') {
3244 // Prepare the filter array
3245 $filterData = array(
3248 'separator' => $separator
3252 $filterData = runFilterChain('get_all_point_columns', $filterData);
3254 // Return the columns
3255 return $filterData['columns'];
3258 // Checks whether the copyright footer (which breaks framesets) is enabled
3259 function ifCopyrightFooterEnabled () {
3260 // Is not unset and not 'N'?
3261 return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
3265 * Wrapper to check whether we have a "full page". This means that the actual
3266 * content is not delivered in any frame of a frameset.
3268 function isFullPage () {
3270 * The parameter 'frame' is generic and always indicates that this content
3271 * will be output into a frame. Furthermore, if a frameset is reported or
3272 * the copyright line is explicitly deactivated, this cannot be a "full
3275 // @TODO Find a way to not use direct module comparison
3276 $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
3282 // Checks whether frameset_mode is set to true
3283 function isFramesetModeEnabled () {
3285 return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
3288 // Function to determine correct 'what' value
3289 function determineWhat ($module = NULL) {
3290 // Init default 'what'
3294 if (is_null($module)) {
3296 $module = getModule();
3304 // Else try to get it from current module
3305 $what = getWhatFromModule($module);
3307 //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
3309 // Remove any spaces from variable
3310 $what = trim($what);
3314 // Default action for non-admin menus
3318 $what = secureString($what);
3325 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3326 function prependZeros ($str, $length = 2) {
3327 // Return prepended string
3328 return sprintf('%0' . (int) $length . 's', $str);
3331 // Wraps convertSelectionsToEpocheTime()
3332 function convertSelectionsToEpocheTimeInPostData ($id) {
3337 // Get all POST data
3338 $postData = postRequestArray();
3340 // Convert given selection id
3341 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3343 // Set the POST array back
3344 setPostRequestArray($postData);
3347 // Wraps checking if given points account type matches with given in POST data
3348 function ifPointsAccountTypeMatchesPost ($type) {
3350 exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
3353 // Gets given user's total referral
3354 function getUsersTotalReferrals ($userid, $level = NULL) {
3356 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3357 // Is the level NULL?
3358 if (is_null($level)) {
3359 // Get total amount (all levels)
3360 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
3362 // Get it from user refs
3363 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
3368 return $GLOBALS[__FUNCTION__][$userid][$level];
3371 // Gets given user's total referral
3372 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3373 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3375 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3376 // Default is all refs
3379 // Is the not level NULL?
3380 if (!is_null($level)) {
3381 // Then add referral level
3382 $add = ' AND `r`.`level`=' . bigintval($level);
3385 // Check for all referrals
3386 $result = sqlQueryEscaped("SELECT
3387 COUNT(`d`.`userid`) AS `cnt`
3389 `{?_MYSQL_PREFIX?}_user_data` AS `d`
3391 `{?_MYSQL_PREFIX?}_user_refs` AS `r`
3393 `d`.`userid`=`r`.`refid`
3395 `d`.`status` != 'CONFIRMED' AND
3403 ), __FUNCTION__, __LINE__);
3406 list($GLOBALS[__FUNCTION__][$userid][$level]) = sqlFetchRow($result);
3409 sqlFreeResult($result);
3413 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3414 return $GLOBALS[__FUNCTION__][$userid][$level];
3417 // Converts, if found, dollar data to get element
3418 function convertDollarDataToGetElement ($data) {
3419 // Is first char a dollar?
3420 if (substr($data, 0, 1) == chr(36)) {
3421 // Use last part for getRequestElement()
3422 $data = getRequestElement(substr($data, 1));
3429 // Wrapper function for SQL layer to speed-up things
3430 function isSqlDebugEnabled () {
3432 if (!isset($GLOBALS[__FUNCTION__])) {
3434 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3438 return $GLOBALS[__FUNCTION__];
3441 // Wrapper function to wrap call of wordwrap()
3442 function wrapWords ($text) {
3444 $wrapped = wordwrap($test, getWordWrap());
3450 // Encodes given data into a JSON object
3451 function encodeJson ($data) {
3453 return json_encode($data, JSON_FORCE_OBJECT);
3456 // Get all extension files
3457 function loadAllExtensionsByTemplate () {
3459 $extensions = getArrayFromDirectory(
3460 'templates/' . getLanguage() . '/html/ext/',
3474 // Wrapper function to allow full float values as supported by current database layout
3475 function translateFullComma ($dotted) {
3476 // Call inner function
3477 return translateComma($dotted, TRUE, 5);
3480 // Wrapper to check if the first element to be shifted is set to given value
3481 function shift_array (&$array, $value, $key = '0') {
3482 // Is the element set and value matches?
3483 assert(is_array($array));
3484 assert(isset($array[$key]));
3485 assert($array[$key] === $value);
3488 array_shift($array);
3491 // Wrapper for str_pad() with left padding zeros
3492 function padLeftZero ($str, $amount = 2) {
3493 // Is str_pad() there?
3494 if (!function_exists('str_pad')) {
3495 // Use prependZeros()
3496 return prependZeros($str, $amount);
3499 return str_pad($str, $amount, '0', STR_PAD_LEFT);
3503 // Calculates percentage
3504 function calculatePercentageRate ($current, $total) {
3508 // Is sent larger zero? (Prevents division-by-zero)
3510 // Calculate it (it should be "translated" alter on)
3511 $rate = ($current / $total * 100);
3514 // The should be a .0 at the end?
3515 if (strpos($rate, '.') === FALSE) {
3524 // Checks whether an array is filled with entries
3525 function isFilledArray ($array) {
3527 return ((is_array($array)) && (count($array) > 0));
3530 // Checks whether this script runs on a developer system (called with localhost/127.0.0.1 SERVER_NAME)
3531 function isDeveloperSystem () {
3533 return in_array(detectServerName(), array('localhost', 'daedalus', '127.0.0.1'));
3536 // Checks whether given subject line has '_ref' suffix
3537 function ifSubjectHasReferralSuffix ($subject) {
3539 if (!isset($GLOBALS[__FUNCTION__][$subject])) {
3541 $GLOBALS[__FUNCTION__][$subject] = (substr($subject, -4, 4) == '_ref');
3545 return $GLOBALS[__FUNCTION__][$subject];
3548 // Converts an API response to an associative array
3549 function convertApiResponseToArray ($responseString, $keyDelimiter, $valueDelimiter) {
3550 // Explode for key delimiter
3551 $keys = explode($keyDelimiter, $responseString);
3553 // Init returned array and "walk" through all entries
3554 $returned = array();
3555 foreach ($keys as $keyValue) {
3557 $parts = explode($valueDelimiter, $keyValue);
3560 assert(count($parts) == 2);
3562 // Then add both: 0=key, 1=value
3563 $returned[sqlEscapeString($parts[0])] = sqlEscapeString($parts[1]);
3566 // Return finished array
3570 // Getter for full (generic) hash file name
3571 function getGenericHashFileName () {
3573 return sprintf('%s%s.%s%s', getPath(), getCachePath(), getFileHash(), getCacheExtension());
3576 // "Compiles" the given value and sets it in given key
3577 function setSessionCompiled ($key, $value) {
3579 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key[]=' . gettype($key) . ',value[]=' . gettype($value));
3581 // Is the value not an array?
3582 if (!is_array($value)) {
3583 // "Compile" the value
3584 $value = doFinalCompilation(compileRawCode($value));
3588 return setSession($key, $value);