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 - 2013 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 // Clear output buffer
1263 clearOutputBuffer();
1265 // Clear own output buffer
1266 $GLOBALS['__output'] = '';
1268 // To make redirects working (no content type), output mode must be raw
1269 setScriptOutputMode(-1);
1271 // Send helping header
1272 setHttpStatus('302 Found');
1274 // always close the session
1275 session_write_close();
1277 // Revert entity &
1278 $url = str_replace('&', '&', $url);
1280 // check if running on IIS < 6 with CGI-PHP
1281 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1282 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1283 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1284 ($matches[1] < 6)) {
1285 // Send the IIS header
1286 addHttpHeader('Refresh: 0;url=' . $url);
1288 // Send generic header
1289 addHttpHeader('Location: ' . $url);
1296 // Determines the country of the given user id
1297 function determineCountry ($userid) {
1299 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1300 // Default is 'invalid'
1301 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1303 // Is extension country active?
1304 if (isExtensionActive('country')) {
1305 // Determine the right country code through the country id
1306 $id = getUserData('country_code');
1308 // Then handle it over
1309 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1311 // Get raw code from user data
1312 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1317 return $GLOBALS[__FUNCTION__][$userid];
1320 // "Getter" for total confirmed user accounts
1321 function getTotalConfirmedUser () {
1323 if (!isset($GLOBALS[__FUNCTION__])) {
1325 if (isExtensionActive('user')) {
1326 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1328 $GLOBALS[__FUNCTION__] = 0;
1332 // Return cached value
1333 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1334 return $GLOBALS[__FUNCTION__];
1337 // "Getter" for total unconfirmed user accounts
1338 function getTotalUnconfirmedUser () {
1340 if (!isset($GLOBALS[__FUNCTION__])) {
1342 if (isExtensionActive('user')) {
1343 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1345 $GLOBALS[__FUNCTION__] = 0;
1349 // Return cached value
1350 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1351 return $GLOBALS[__FUNCTION__];
1354 // "Getter" for total locked user accounts
1355 function getTotalLockedUser () {
1357 if (!isset($GLOBALS[__FUNCTION__])) {
1359 if (isExtensionActive('user')) {
1360 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1362 $GLOBALS[__FUNCTION__] = 0;
1366 // Return cached value
1367 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1368 return $GLOBALS[__FUNCTION__];
1371 // "Getter" for total locked user accounts
1372 function getTotalRandomRefidUser () {
1374 if (!isset($GLOBALS[__FUNCTION__])) {
1376 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1377 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
1379 $GLOBALS[__FUNCTION__] = 0;
1383 // Return cached value
1384 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1385 return $GLOBALS[__FUNCTION__];
1388 // Is given id number valid?
1389 function isValidId ($id) {
1391 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id[' . gettype($id) . ']=' . $id);
1394 if (!isset($GLOBALS[__FUNCTION__][$id])) {
1396 $GLOBALS[__FUNCTION__][$id] = ((isValidNumber($id)) && (!is_bool($id)) && ($id != '00000') && ($id > 0));
1400 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',result=' . intval($GLOBALS[__FUNCTION__][$id]));
1401 return $GLOBALS[__FUNCTION__][$id];
1404 // Checks whether a valid number is given
1405 function isValidNumber ($num) {
1407 return ((!is_null($num)) && (!empty($num)) && ('*' . bigintval($num, TRUE, FALSE) . '*' == '*' . $num . '*'));
1411 function encodeEntities ($str) {
1413 $str = secureString($str, TRUE, TRUE);
1415 // Encode dollar sign as well
1416 $str = str_replace('$', '$', $str);
1422 // Getter for current year (default)
1423 function getYear ($timestamp = NULL) {
1425 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1426 // If NULL is set, use time()
1427 if (is_null($timestamp)) {
1428 $timestamp = time();
1432 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1436 return $GLOBALS[__FUNCTION__][$timestamp];
1439 // Getter for current month (default)
1440 function getMonth ($timestamp = NULL) {
1442 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1443 // If NULL is set, use time()
1444 if (is_null($timestamp)) {
1445 // Use time() which is current timestamp
1446 $timestamp = time();
1450 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1454 return $GLOBALS[__FUNCTION__][$timestamp];
1457 // Getter for current hour (default)
1458 function getHour ($timestamp = NULL) {
1460 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1462 if (is_null($timestamp)) {
1463 $timestamp = time();
1467 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1471 return $GLOBALS[__FUNCTION__][$timestamp];
1474 // Getter for current day (default)
1475 function getDay ($timestamp = NULL) {
1477 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1479 if (is_null($timestamp)) {
1480 $timestamp = time();
1484 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1488 return $GLOBALS[__FUNCTION__][$timestamp];
1491 // Getter for current week (default)
1492 function getWeek ($timestamp = NULL) {
1494 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1496 if (is_null($timestamp)) $timestamp = time();
1499 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1503 return $GLOBALS[__FUNCTION__][$timestamp];
1506 // Getter for current short_hour (default)
1507 function getShortHour ($timestamp = NULL) {
1509 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1511 if (is_null($timestamp)) $timestamp = time();
1514 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1518 return $GLOBALS[__FUNCTION__][$timestamp];
1521 // Getter for current long_hour (default)
1522 function getLongHour ($timestamp = NULL) {
1524 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1526 if (is_null($timestamp)) $timestamp = time();
1529 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1533 return $GLOBALS[__FUNCTION__][$timestamp];
1536 // Getter for current second (default)
1537 function getSecond ($timestamp = NULL) {
1539 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1541 if (is_null($timestamp)) $timestamp = time();
1544 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1548 return $GLOBALS[__FUNCTION__][$timestamp];
1551 // Getter for current minute (default)
1552 function getMinute ($timestamp = NULL) {
1554 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1556 if (is_null($timestamp)) $timestamp = time();
1559 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1563 return $GLOBALS[__FUNCTION__][$timestamp];
1566 // Checks whether the title decoration is enabled
1567 function isTitleDecorationEnabled () {
1569 if (!isset($GLOBALS[__FUNCTION__])) {
1571 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_title_deco')) && (getConfig('enable_title_deco') == 'Y'));
1575 return $GLOBALS[__FUNCTION__];
1578 // Checks whether filter usage updates are enabled (expensive queries!)
1579 function isFilterUsageUpdateEnabled () {
1581 if (!isset($GLOBALS[__FUNCTION__])) {
1583 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1587 return $GLOBALS[__FUNCTION__];
1590 // Checks whether debugging of weekly resets is enabled
1591 function isWeeklyResetDebugEnabled () {
1593 if (!isset($GLOBALS[__FUNCTION__])) {
1595 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1599 return $GLOBALS[__FUNCTION__];
1602 // Checks whether debugging of monthly resets is enabled
1603 function isMonthlyResetDebugEnabled () {
1605 if (!isset($GLOBALS[__FUNCTION__])) {
1607 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1611 return $GLOBALS[__FUNCTION__];
1614 // Checks whether debugging of yearly resets is enabled
1615 function isYearlyResetDebugEnabled () {
1617 if (!isset($GLOBALS[__FUNCTION__])) {
1619 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y'));
1623 return $GLOBALS[__FUNCTION__];
1626 // Checks whether displaying of debug SQLs are enabled
1627 function isDisplayDebugSqlEnabled () {
1629 if (!isset($GLOBALS[__FUNCTION__])) {
1631 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (isConfigEntrySet('display_debug_sql')) && (getDisplayDebugSqls() == 'Y'));
1635 return $GLOBALS[__FUNCTION__];
1638 // Checks whether module title is enabled
1639 function isModuleTitleEnabled () {
1641 if (!isset($GLOBALS[__FUNCTION__])) {
1643 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_mod_title')) && (getConfig('enable_mod_title') == 'Y'));
1647 return $GLOBALS[__FUNCTION__];
1650 // Checks whether what title is enabled
1651 function isWhatTitleEnabled () {
1653 if (!isset($GLOBALS[__FUNCTION__])) {
1655 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_what_title')) && (getConfig('enable_what_title') == 'Y'));
1659 return $GLOBALS[__FUNCTION__];
1662 // "Getter" for internal_stats
1663 function getInternalStats () {
1665 if (!isset($GLOBALS[__FUNCTION__])) {
1667 $GLOBALS[__FUNCTION__] = getConfig('internal_stats');
1671 return $GLOBALS[__FUNCTION__];
1674 // Checks whether stats are enabled
1675 function ifInternalStatsEnabled () {
1677 if (!isset($GLOBALS[__FUNCTION__])) {
1678 // Then determine it, do not add isExtensionInstalledAndNewer() here as it breaks very first SQL query
1679 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('internal_stats')) && (getInternalStats() == 'Y'));
1682 // Return cached value
1683 return $GLOBALS[__FUNCTION__];
1686 // Checks whether admin-notification of certain user actions is enabled
1687 function isAdminNotificationEnabled () {
1689 if (!isset($GLOBALS[__FUNCTION__])) {
1691 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.3.0')) && (isConfigEntrySet('admin_notify')) && (getAdminNotify() == 'Y'));
1695 return $GLOBALS[__FUNCTION__];
1698 // Checks whether random referral id selection is enabled
1699 function isRandomReferralIdEnabled () {
1701 if (!isset($GLOBALS[__FUNCTION__])) {
1703 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isConfigEntrySet('select_user_zero_refid')) && (getSelectUserZeroRefid() == 'Y'));
1707 return $GLOBALS[__FUNCTION__];
1710 // "Getter" for default language
1711 function getDefaultLanguage () {
1713 if (!isset($GLOBALS[__FUNCTION__])) {
1715 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1719 return $GLOBALS[__FUNCTION__];
1722 // "Getter" for default referral id
1723 function getDefRefid () {
1725 if (!isset($GLOBALS[__FUNCTION__])) {
1727 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1731 return $GLOBALS[__FUNCTION__];
1734 // "Getter" for path
1735 function getPath () {
1737 if (!isset($GLOBALS[__FUNCTION__])) {
1739 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1743 return $GLOBALS[__FUNCTION__];
1747 function getUrl () {
1749 if (!isset($GLOBALS[__FUNCTION__])) {
1751 $GLOBALS[__FUNCTION__] = getConfig('URL');
1755 return $GLOBALS[__FUNCTION__];
1758 // "Getter" for cache_path
1759 function getCachePath () {
1761 if (!isset($GLOBALS[__FUNCTION__])) {
1763 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1767 return $GLOBALS[__FUNCTION__];
1770 // "Getter" for cache_extension
1771 function getCacheExtension () {
1773 if (!isset($GLOBALS[__FUNCTION__])) {
1775 $GLOBALS[__FUNCTION__] = getConfig('CACHE_EXTENSION');
1779 return $GLOBALS[__FUNCTION__];
1782 // "Getter" for WRITE_FOOTER
1783 function getWriteFooter () {
1785 if (!isset($GLOBALS[__FUNCTION__])) {
1787 $GLOBALS[__FUNCTION__] = getConfig('WRITE_FOOTER');
1791 return $GLOBALS[__FUNCTION__];
1794 // "Getter" for secret_key
1795 function getSecretKey () {
1797 if (!isset($GLOBALS[__FUNCTION__])) {
1799 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1803 return $GLOBALS[__FUNCTION__];
1806 // "Getter" for SITE_KEY
1807 function getSiteKey () {
1809 if (!isset($GLOBALS[__FUNCTION__])) {
1811 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1815 return $GLOBALS[__FUNCTION__];
1818 // "Getter" for DATE_KEY
1819 function getDateKey () {
1821 if (!isset($GLOBALS[__FUNCTION__])) {
1823 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1827 return $GLOBALS[__FUNCTION__];
1830 // "Getter" for master_salt
1831 function getMasterSalt () {
1833 if (!isset($GLOBALS[__FUNCTION__])) {
1835 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1839 return $GLOBALS[__FUNCTION__];
1842 // "Getter" for prime
1843 function getPrime () {
1845 if (!isset($GLOBALS[__FUNCTION__])) {
1847 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1851 return $GLOBALS[__FUNCTION__];
1854 // "Getter" for encrypt_separator
1855 function getEncryptSeparator () {
1857 if (!isset($GLOBALS[__FUNCTION__])) {
1859 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1863 return $GLOBALS[__FUNCTION__];
1866 // "Getter" for mysql_prefix
1867 function getMysqlPrefix () {
1869 if (!isset($GLOBALS[__FUNCTION__])) {
1871 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1875 return $GLOBALS[__FUNCTION__];
1878 // "Getter" for table_type
1879 function getTableType () {
1881 if (!isset($GLOBALS[__FUNCTION__])) {
1883 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1887 return $GLOBALS[__FUNCTION__];
1890 // "Getter" for db_type
1891 function getDbType () {
1893 if (!isset($GLOBALS[__FUNCTION__])) {
1895 $GLOBALS[__FUNCTION__] = getConfig('_DB_TYPE');
1899 return $GLOBALS[__FUNCTION__];
1902 // "Getter" for salt_length
1903 function getSaltLength () {
1905 if (!isset($GLOBALS[__FUNCTION__])) {
1907 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1911 return $GLOBALS[__FUNCTION__];
1914 // "Getter" for output_mode
1915 function getOutputMode () {
1917 if (!isset($GLOBALS[__FUNCTION__])) {
1919 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1923 return $GLOBALS[__FUNCTION__];
1926 // "Getter" for full_version
1927 function getFullVersion () {
1929 if (!isset($GLOBALS[__FUNCTION__])) {
1931 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1935 return $GLOBALS[__FUNCTION__];
1938 // "Getter" for title
1939 function getTitle () {
1941 if (!isset($GLOBALS[__FUNCTION__])) {
1943 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1947 return $GLOBALS[__FUNCTION__];
1950 // "Getter" for server_url
1951 function getServerUrl () {
1953 if (!isset($GLOBALS[__FUNCTION__])) {
1955 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1959 return $GLOBALS[__FUNCTION__];
1962 // "Getter" for mt_word
1963 function getMtWord () {
1965 if (!isset($GLOBALS[__FUNCTION__])) {
1967 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1971 return $GLOBALS[__FUNCTION__];
1974 // "Getter" for mt_word2
1975 function getMtWord2 () {
1977 if (!isset($GLOBALS[__FUNCTION__])) {
1979 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1983 return $GLOBALS[__FUNCTION__];
1986 // "Getter" for mt_word3
1987 function getMtWord3 () {
1989 if (!isset($GLOBALS[__FUNCTION__])) {
1991 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
1995 return $GLOBALS[__FUNCTION__];
1998 // "Getter" for START_TDAY
1999 function getStartTday () {
2001 if (!isset($GLOBALS[__FUNCTION__])) {
2003 $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
2007 return $GLOBALS[__FUNCTION__];
2010 // "Getter" for START_YDAY
2011 function getStartYday () {
2013 if (!isset($GLOBALS[__FUNCTION__])) {
2015 $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
2019 return $GLOBALS[__FUNCTION__];
2022 // "Getter" for main_title
2023 function getMainTitle () {
2025 if (!isset($GLOBALS[__FUNCTION__])) {
2027 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
2031 return $GLOBALS[__FUNCTION__];
2034 // "Getter" for file_hash
2035 function getFileHash () {
2037 if (!isset($GLOBALS[__FUNCTION__])) {
2039 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
2043 return $GLOBALS[__FUNCTION__];
2046 // "Getter" for pass_scramble
2047 function getPassScramble () {
2049 if (!isset($GLOBALS[__FUNCTION__])) {
2051 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
2055 return $GLOBALS[__FUNCTION__];
2058 // "Getter" for ap_inactive_since
2059 function getApInactiveSince () {
2061 if (!isset($GLOBALS[__FUNCTION__])) {
2063 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
2067 return $GLOBALS[__FUNCTION__];
2070 // "Getter" for user_min_confirmed
2071 function getUserMinConfirmed () {
2073 if (!isset($GLOBALS[__FUNCTION__])) {
2075 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
2079 return $GLOBALS[__FUNCTION__];
2081 // "Getter" for points
2082 function getPoints () {
2084 if (!isset($GLOBALS[__FUNCTION__])) {
2086 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
2090 return $GLOBALS[__FUNCTION__];
2093 // "Getter" for slogan
2094 function getSlogan () {
2096 if (!isset($GLOBALS[__FUNCTION__])) {
2098 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
2102 return $GLOBALS[__FUNCTION__];
2105 // "Getter" for copy
2106 function getCopy () {
2108 if (!isset($GLOBALS[__FUNCTION__])) {
2110 $GLOBALS[__FUNCTION__] = getConfig('COPY');
2114 return $GLOBALS[__FUNCTION__];
2117 // "Getter" for webmaster
2118 function getWebmaster () {
2120 if (!isset($GLOBALS[__FUNCTION__])) {
2122 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
2126 return $GLOBALS[__FUNCTION__];
2129 // "Getter" for sql_count
2130 function getSqlCount () {
2132 if (!isset($GLOBALS[__FUNCTION__])) {
2134 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2138 return $GLOBALS[__FUNCTION__];
2141 // "Getter" for num_templates
2142 function getNumTemplates () {
2144 if (!isset($GLOBALS[__FUNCTION__])) {
2146 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2150 return $GLOBALS[__FUNCTION__];
2153 // "Getter" for dns_cache_timeout
2154 function getDnsCacheTimeout () {
2156 if (!isset($GLOBALS[__FUNCTION__])) {
2158 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2162 return $GLOBALS[__FUNCTION__];
2165 // "Getter" for menu_blur_spacer
2166 function getMenuBlurSpacer () {
2168 if (!isset($GLOBALS[__FUNCTION__])) {
2170 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2174 return $GLOBALS[__FUNCTION__];
2177 // "Getter" for points_register
2178 function getPointsRegister () {
2180 if (!isset($GLOBALS[__FUNCTION__])) {
2182 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2186 return $GLOBALS[__FUNCTION__];
2189 // "Getter" for points_ref
2190 function getPointsRef () {
2192 if (!isset($GLOBALS[__FUNCTION__])) {
2194 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2198 return $GLOBALS[__FUNCTION__];
2201 // "Getter" for ref_payout
2202 function getRefPayout () {
2204 if (!isset($GLOBALS[__FUNCTION__])) {
2206 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2210 return $GLOBALS[__FUNCTION__];
2213 // "Getter" for online_timeout
2214 function getOnlineTimeout () {
2216 if (!isset($GLOBALS[__FUNCTION__])) {
2218 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2222 return $GLOBALS[__FUNCTION__];
2225 // "Getter" for index_home
2226 function getIndexHome () {
2228 if (!isset($GLOBALS[__FUNCTION__])) {
2230 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2234 return $GLOBALS[__FUNCTION__];
2237 // "Getter" for one_day
2238 function getOneDay () {
2240 if (!isset($GLOBALS[__FUNCTION__])) {
2242 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2246 return $GLOBALS[__FUNCTION__];
2249 // "Getter" for img_type
2250 function getImgType () {
2252 if (!isset($GLOBALS[__FUNCTION__])) {
2254 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2258 return $GLOBALS[__FUNCTION__];
2261 // "Getter" for code_length
2262 function getCodeLength () {
2264 if (!isset($GLOBALS[__FUNCTION__])) {
2266 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2270 return $GLOBALS[__FUNCTION__];
2273 // "Getter" for min_password_length
2274 function getMinPasswordLength () {
2276 if (!isset($GLOBALS[__FUNCTION__])) {
2278 $GLOBALS[__FUNCTION__] = getConfig('min_password_length');
2282 return $GLOBALS[__FUNCTION__];
2285 // "Getter" for min_password_score
2286 function getMinPasswordScore () {
2288 if (!isset($GLOBALS[__FUNCTION__])) {
2290 $GLOBALS[__FUNCTION__] = getConfig('min_password_score');
2294 return $GLOBALS[__FUNCTION__];
2297 // "Getter" for admin_menu
2298 function getAdminMenu () {
2300 if (!isset($GLOBALS[__FUNCTION__])) {
2302 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2306 return $GLOBALS[__FUNCTION__];
2309 // "Getter" for last_hourly
2310 function getLastHourly () {
2312 if (!isset($GLOBALS[__FUNCTION__])) {
2314 $GLOBALS[__FUNCTION__] = getConfig('last_hourly');
2318 return $GLOBALS[__FUNCTION__];
2321 // "Getter" for last_daily
2322 function getLastDaily () {
2324 if (!isset($GLOBALS[__FUNCTION__])) {
2326 $GLOBALS[__FUNCTION__] = getConfig('last_daily');
2330 return $GLOBALS[__FUNCTION__];
2333 // "Getter" for last_weekly
2334 function getLastWeekly () {
2336 if (!isset($GLOBALS[__FUNCTION__])) {
2338 $GLOBALS[__FUNCTION__] = getConfig('last_weekly');
2342 return $GLOBALS[__FUNCTION__];
2345 // "Getter" for last_monthly
2346 function getLastMonthly () {
2348 if (!isset($GLOBALS[__FUNCTION__])) {
2350 $GLOBALS[__FUNCTION__] = getConfig('last_monthly');
2354 return $GLOBALS[__FUNCTION__];
2357 // "Getter" for last_yearly
2358 function getLastYearly () {
2360 if (!isset($GLOBALS[__FUNCTION__])) {
2362 $GLOBALS[__FUNCTION__] = getConfig('last_yearly');
2366 return $GLOBALS[__FUNCTION__];
2369 // "Getter" for mails_page
2370 function getMailsPage () {
2372 if (!isset($GLOBALS[__FUNCTION__])) {
2374 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2378 return $GLOBALS[__FUNCTION__];
2381 // "Getter" for rand_no
2382 function getRandNo () {
2384 if (!isset($GLOBALS[__FUNCTION__])) {
2386 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2390 return $GLOBALS[__FUNCTION__];
2393 // "Getter" for __DB_NAME
2394 function getDbName () {
2396 if (!isset($GLOBALS[__FUNCTION__])) {
2398 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2402 return $GLOBALS[__FUNCTION__];
2405 // "Getter" for DOMAIN
2406 function getDomain () {
2408 if (!isset($GLOBALS[__FUNCTION__])) {
2410 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2414 return $GLOBALS[__FUNCTION__];
2417 // "Getter" for proxy_username
2418 function getProxyUsername () {
2420 if (!isset($GLOBALS[__FUNCTION__])) {
2422 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2426 return $GLOBALS[__FUNCTION__];
2429 // "Getter" for proxy_password
2430 function getProxyPassword () {
2432 if (!isset($GLOBALS[__FUNCTION__])) {
2434 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2438 return $GLOBALS[__FUNCTION__];
2441 // "Getter" for proxy_host
2442 function getProxyHost () {
2444 if (!isset($GLOBALS[__FUNCTION__])) {
2446 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2450 return $GLOBALS[__FUNCTION__];
2453 // "Getter" for proxy_port
2454 function getProxyPort () {
2456 if (!isset($GLOBALS[__FUNCTION__])) {
2458 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2462 return $GLOBALS[__FUNCTION__];
2465 // "Getter" for SMTP_HOSTNAME
2466 function getSmtpHostname () {
2468 if (!isset($GLOBALS[__FUNCTION__])) {
2470 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2474 return $GLOBALS[__FUNCTION__];
2477 // "Getter" for SMTP_USER
2478 function getSmtpUser () {
2480 if (!isset($GLOBALS[__FUNCTION__])) {
2482 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2486 return $GLOBALS[__FUNCTION__];
2489 // "Getter" for SMTP_PASSWORD
2490 function getSmtpPassword () {
2492 if (!isset($GLOBALS[__FUNCTION__])) {
2494 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2498 return $GLOBALS[__FUNCTION__];
2501 // "Getter" for points_word
2502 function getPointsWord () {
2504 if (!isset($GLOBALS[__FUNCTION__])) {
2506 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2510 return $GLOBALS[__FUNCTION__];
2513 // "Getter" for profile_lock
2514 function getProfileLock () {
2516 if (!isset($GLOBALS[__FUNCTION__])) {
2518 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2522 return $GLOBALS[__FUNCTION__];
2525 // "Getter" for url_tlock
2526 function getUrlTlock () {
2528 if (!isset($GLOBALS[__FUNCTION__])) {
2530 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2534 return $GLOBALS[__FUNCTION__];
2537 // "Getter" for title_left
2538 function getTitleLeft () {
2540 if (!isset($GLOBALS[__FUNCTION__])) {
2542 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2546 return $GLOBALS[__FUNCTION__];
2549 // "Getter" for title_right
2550 function getTitleRight () {
2552 if (!isset($GLOBALS[__FUNCTION__])) {
2554 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2558 return $GLOBALS[__FUNCTION__];
2561 // "Getter" for title_middle
2562 function getTitleMiddle () {
2564 if (!isset($GLOBALS[__FUNCTION__])) {
2566 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2570 return $GLOBALS[__FUNCTION__];
2573 // Getter for 'display_home_in_index'
2574 function getDisplayHomeInIndex () {
2575 // Is the cache entry set?
2576 if (!isset($GLOBALS[__FUNCTION__])) {
2577 // No, so determine it
2578 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2581 // Return cached entry
2582 return $GLOBALS[__FUNCTION__];
2585 // Checks whether 'display_home_in_index' is 'Y'
2586 function isDisplayHomeInIndexEnabled () {
2587 // Is the cache entry set?
2588 if (!isset($GLOBALS[__FUNCTION__])) {
2589 // No, so determine it
2590 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isConfigEntrySet('display_home_in_index')) && (getDisplayHomeInIndex() == 'Y'));
2593 // Return cached entry
2594 return $GLOBALS[__FUNCTION__];
2597 // Getter for 'show_points_unconfirmed'
2598 function getShowPointsUnconfirmed () {
2599 // Is the cache entry set?
2600 if (!isset($GLOBALS[__FUNCTION__])) {
2601 // No, so determine it
2602 $GLOBALS[__FUNCTION__] = getConfig('show_points_unconfirmed');
2605 // Return cached entry
2606 return $GLOBALS[__FUNCTION__];
2609 // Checks whether 'show_points_unconfirmed' is 'Y'
2610 function isShowPointsUnconfirmedEnabled () {
2611 // Is the cache entry set?
2612 if (!isset($GLOBALS[__FUNCTION__])) {
2613 // No, so determine it
2614 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.5.5')) && (isConfigEntrySet('show_points_unconfirmed')) && (getShowPointsUnconfirmed() == 'Y'));
2617 // Return cached entry
2618 return $GLOBALS[__FUNCTION__];
2621 // Getter for 'youre_here'
2622 function getYoureHere () {
2623 // Is the cache entry set?
2624 if (!isset($GLOBALS[__FUNCTION__])) {
2625 // No, so determine it
2626 $GLOBALS[__FUNCTION__] = getConfig('youre_here');
2629 // Return cached entry
2630 return $GLOBALS[__FUNCTION__];
2633 // Checks whether 'show_timings' is 'Y'
2634 function isYoureHereEnabled () {
2635 // Is the cache entry set?
2636 if (!isset($GLOBALS[__FUNCTION__])) {
2637 // No, so determine it
2638 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (isConfigEntrySet('youre_here')) && (getYoureHere() == 'Y'));
2641 // Return cached entry
2642 return $GLOBALS[__FUNCTION__];
2645 // Getter for 'show_timings'
2646 function getShowTimings () {
2647 // Is the cache entry set?
2648 if (!isset($GLOBALS[__FUNCTION__])) {
2649 // No, so determine it
2650 $GLOBALS[__FUNCTION__] = getConfig('show_timings');
2653 // Return cached entry
2654 return $GLOBALS[__FUNCTION__];
2657 // Checks whether 'show_timings' is 'Y'
2658 function isShowTimingsEnabled () {
2659 // Is the cache entry set?
2660 if (!isset($GLOBALS[__FUNCTION__])) {
2661 // No, so determine it
2662 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (isConfigEntrySet('show_timings')) && (getShowTimings() == 'Y'));
2665 // Return cached entry
2666 return $GLOBALS[__FUNCTION__];
2669 // Getter for 'ap_server_name_since'
2670 function getApServerNameSince () {
2671 // Is the cache entry set?
2672 if (!isset($GLOBALS[__FUNCTION__])) {
2673 // No, so determine it
2674 $GLOBALS[__FUNCTION__] = getConfig('ap_server_name_since');
2677 // Return cached entry
2678 return $GLOBALS[__FUNCTION__];
2681 // Getter for 'ap_server_name'
2682 function getApServerName () {
2683 // Is the cache entry set?
2684 if (!isset($GLOBALS[__FUNCTION__])) {
2685 // No, so determine it
2686 $GLOBALS[__FUNCTION__] = getConfig('ap_server_name');
2689 // Return cached entry
2690 return $GLOBALS[__FUNCTION__];
2693 // Getter for 'index_delay'
2694 function getIndexDelay () {
2695 // Is the cache entry set?
2696 if (!isset($GLOBALS[__FUNCTION__])) {
2697 // No, so determine it
2698 $GLOBALS[__FUNCTION__] = getConfig('index_delay');
2701 // Return cached entry
2702 return $GLOBALS[__FUNCTION__];
2705 // Checks whether 'ap_server_name' is 'Y'
2706 function isApServerNameEnabled () {
2707 // Is the cache entry set?
2708 if (!isset($GLOBALS[__FUNCTION__])) {
2709 // No, so determine it
2710 $GLOBALS[__FUNCTION__] = (getApServerName() == 'Y');
2713 // Return cached entry
2714 return $GLOBALS[__FUNCTION__];
2717 // Getter for 'admin_menu_javascript'
2718 function getAdminMenuJavascript () {
2719 // Is the cache entry set?
2720 if (!isset($GLOBALS[__FUNCTION__])) {
2721 // No, so determine it
2722 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2725 // Return cached entry
2726 return $GLOBALS[__FUNCTION__];
2729 // Getter for 'points_remove_account'
2730 function getPointsRemoveAccount () {
2731 // Is the cache entry set?
2732 if (!isset($GLOBALS[__FUNCTION__])) {
2733 // No, so determine it
2734 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2737 // Return cached entry
2738 return $GLOBALS[__FUNCTION__];
2741 // Getter for 'css_php'
2742 function getCssPhp () {
2743 // Is the cache entry set?
2744 if (!isset($GLOBALS[__FUNCTION__])) {
2745 // No, so determine it
2746 $GLOBALS[__FUNCTION__] = getConfig('css_php');
2749 // Return cached entry
2750 return $GLOBALS[__FUNCTION__];
2753 // Getter for 'guest_menu'
2754 function getGuestMenu () {
2755 // Is the cache entry set?
2756 if (!isset($GLOBALS[__FUNCTION__])) {
2757 // No, so determine it
2758 $GLOBALS[__FUNCTION__] = getConfig('guest_menu');
2761 // Return cached entry
2762 return $GLOBALS[__FUNCTION__];
2765 // Checks if guest menu is enabled
2766 function isGuestMenuEnabled () {
2767 // Is the cache entry set?
2768 if (!isset($GLOBALS[__FUNCTION__])) {
2769 // No, so determine it
2770 $GLOBALS[__FUNCTION__] = (getGuestMenu() == 'Y');
2773 // Return cached entry
2774 return $GLOBALS[__FUNCTION__];
2777 // Getter for 'member_menu'
2778 function getMemberMenu () {
2779 // Is the cache entry set?
2780 if (!isset($GLOBALS[__FUNCTION__])) {
2781 // No, so determine it
2782 $GLOBALS[__FUNCTION__] = getConfig('member_menu');
2785 // Return cached entry
2786 return $GLOBALS[__FUNCTION__];
2789 // Checks if member menu is enabled
2790 function isMemberMenuEnabled () {
2791 // Is the cache entry set?
2792 if (!isset($GLOBALS[__FUNCTION__])) {
2793 // No, so determine it
2794 $GLOBALS[__FUNCTION__] = (getMemberMenu() == 'Y');
2797 // Return cached entry
2798 return $GLOBALS[__FUNCTION__];
2801 // Getter for 'word_wrap'
2802 function getWordWrap () {
2803 // Is the cache entry set?
2804 if (!isset($GLOBALS[__FUNCTION__])) {
2805 // Construct config entry name
2806 $configEntry = getMenuModeFromModule() . '_word_wrap_' . getWhat();
2808 // Is a special config entry found or ext-sql_patches updated?
2809 if (isConfigEntrySet($configEntry)) {
2810 // A special config entry has been found, then use it
2811 $GLOBALS[__FUNCTION__] = getConfig($configEntry);
2812 } elseif (isExtensionInstalledAndNewer('other', '0.2.9')) {
2813 // No special config entry found, then use it as "fall-back"
2814 $GLOBALS[__FUNCTION__] = getConfig('word_wrap');
2816 // No, use default (15 characters)
2817 $GLOBALS[__FUNCTION__] = 15;
2821 // Return cached entry
2822 return $GLOBALS[__FUNCTION__];
2825 // Checks whether proxy configuration is used
2826 function isProxyUsed () {
2828 if (!isset($GLOBALS[__FUNCTION__])) {
2830 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (isValidNumber(getConfig('proxy_port'))));
2834 return $GLOBALS[__FUNCTION__];
2837 // Checks whether POST data contains selections
2838 function ifPostContainsSelections ($element = 'sel') {
2840 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2842 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2846 return $GLOBALS[__FUNCTION__][$element];
2849 // Checks whether verbose_sql is Y and returns true/false if so
2850 function isVerboseSqlEnabled () {
2852 if (!isset($GLOBALS[__FUNCTION__])) {
2854 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2858 return $GLOBALS[__FUNCTION__];
2861 // "Getter" for total user points
2862 function getTotalPoints ($userid) {
2864 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2865 // Init array for filter chain
2867 'userid' => $userid,
2871 // Run filter chain for getting more point values
2872 $data = runFilterChain('get_total_points', $data);
2875 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - getUserUsedPoints($userid);
2879 return $GLOBALS[__FUNCTION__][$userid];
2882 // Wrapper to get used points for given userid
2883 function getUserUsedPoints ($userid) {
2885 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2887 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2891 return $GLOBALS[__FUNCTION__][$userid];
2894 // Checks whether direct payment is allowed in configuration
2895 function isDirectPaymentEnabled () {
2897 if (!isset($GLOBALS[__FUNCTION__])) {
2899 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('allow_direct_pay')) && (getConfig('allow_direct_pay') == 'Y'));
2903 return $GLOBALS[__FUNCTION__];
2906 // Checks whether JavaScript-based admin menu is enabled
2907 function isAdminMenuJavascriptEnabled () {
2909 if (!isset($GLOBALS[__FUNCTION__])) {
2911 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (isConfigEntrySet('admin_menu_javascript')) && (getAdminMenuJavaScript() == 'Y'));
2915 return $GLOBALS[__FUNCTION__];
2918 // Wrapper to check if current task is for extension (not update)
2919 function isExtensionTask ($content) {
2921 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2923 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2927 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2930 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2931 function ifTesterAccountsAllowed () {
2932 // Is the cache entry set?
2933 if (!isset($GLOBALS[__FUNCTION__])) {
2934 // No, so determine it
2935 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2938 // Return cached entry
2939 return $GLOBALS[__FUNCTION__];
2942 // Wrapper to check if output mode is CSS
2943 function isCssOutputMode () {
2945 if (!isset($GLOBALS[__FUNCTION__])) {
2947 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2948 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2952 return $GLOBALS[__FUNCTION__];
2955 // Wrapper to check if output mode is HTML
2956 function isHtmlOutputMode () {
2958 if (!isset($GLOBALS[__FUNCTION__])) {
2960 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2961 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2965 return $GLOBALS[__FUNCTION__];
2968 // Wrapper to check if output mode is RAW
2969 function isRawOutputMode () {
2971 if (!isset($GLOBALS[__FUNCTION__])) {
2973 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2974 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2978 return $GLOBALS[__FUNCTION__];
2981 // Wrapper to check if output mode is AJAX
2982 function isAjaxOutputMode () {
2984 if (!isset($GLOBALS[__FUNCTION__])) {
2986 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2987 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2991 return $GLOBALS[__FUNCTION__];
2994 // Wrapper to check if output mode is image
2995 function isImageOutputMode () {
2997 if (!isset($GLOBALS[__FUNCTION__])) {
2999 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
3000 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
3004 return $GLOBALS[__FUNCTION__];
3007 // Wrapper to generate a user email link
3008 function generateWrappedUserEmailLink ($email) {
3009 // Just call the inner function
3010 return generateEmailLink($email, 'user_data');
3013 // Wrapper to check if user points are locked
3014 function ifUserPointsLocked ($userid) {
3015 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
3017 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
3019 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
3023 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
3024 return $GLOBALS[__FUNCTION__][$userid];
3027 // Appends a line to an existing file or creates it instantly with given content.
3028 // This function does always add a new-line character to every line.
3029 function appendLineToFile ($file, $line) {
3030 $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
3031 fwrite($fp, $line . PHP_EOL);
3035 // Wrapper for changeDataInFile() but with full path added
3036 function changeDataInInclude ($inc, $comment, $prefix, $suffix, $inserted, $seek=0) {
3038 $FQFN = getPath() . $inc;
3040 // Call inner function
3041 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
3044 // Wrapper for changing entries in config-local.php
3045 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
3046 // Call the inner function
3047 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
3050 // Shortens ucfirst(strtolower()) calls
3051 function firstCharUpperCase ($str) {
3052 return ucfirst(strtolower($str));
3055 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
3056 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
3057 // Get the configuration entry
3058 $configValue = getConfig($configEntry);
3060 // Call inner method
3061 return createTimeSelections($configValue, $configEntry, $stamps, $align);
3064 // Shortens converting of German comma to Computer's version in POST data
3065 function convertCommaToDotInPostData ($postEntry) {
3066 // Read and convert given entry
3067 $postValue = convertCommaToDot(postRequestElement($postEntry));
3070 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
3072 // ... and set it again
3073 setPostRequestElement($postEntry, $postValue);
3076 // Converts German commas to Computer's version in all entries
3077 function convertCommaToDotInPostDataArray ($postEntries) {
3078 // Replace german decimal comma with computer decimal dot
3079 foreach ($postEntries as $entry) {
3080 // Is the entry there?
3081 if (isPostRequestElementSet($entry)) {
3083 convertCommaToDotInPostData($entry);
3089 * Parses a string into a US formated float variable, taken from user comments
3090 * from PHP documentation website.
3092 * @param $floatString A string holding a float expression
3093 * @return $float Corresponding float variable
3094 * @author chris<at>georgakopoulos<dot>com
3095 * @link http://de.php.net/manual/en/function.floatval.php#92563
3097 function parseFloat ($floatString){
3099 $LocaleInfo = localeconv();
3101 // Remove thousand separators
3102 $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
3104 // Convert decimal point
3105 $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
3107 // Return float value of converted string
3108 return floatval($floatString);
3112 * Searches a multi-dimensional array (as used in many places) for given
3113 * key/value pair as taken from user comments from PHP documentation website.
3115 * @param $array An array with one or more dimensions
3116 * @param $key Key to look for
3117 * @param $value Value to look for
3118 * @param $parentIndex Parent index (ONLY INTERNAL USE!)
3119 * @return $results Resulted array or empty array if $array is no array
3120 * @author sunelbe<at>gmail<dot>com
3121 * @link http://de.php.net/manual/en/function.array-search.php#110120
3123 function search_array ($array, $key, $value, $parentIndex = NULL) {
3124 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
3125 // Init array result
3128 // Is $array really an array?
3129 if (is_array($array)) {
3130 // Search for whole array
3131 foreach ($array as $idx => $dummy) {
3132 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex);
3133 //* DEBUG: */ print 'idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',key=' . $key . ',value=' . $value . ',array=<pre>'.print_r($array, TRUE).'</pre>';
3134 // Is dummy an array?
3135 if ((is_array($dummy)) && ((is_null($parentIndex)) || ($parentIndex === $value))) {
3136 // Then search again
3137 $subResult = search_array($dummy, $key, $value, $idx);
3138 //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
3141 $results = merge_array($results, $subResult, TRUE);
3142 } elseif (($key == $idx) && (isset($array[$key])) && ($array[$key] === $value)) {
3143 // Is found, so add it
3144 $results[$parentIndex] = $array;
3145 //* DEBUG: */ print 'ARRAY: key=' . $key . ',idx=' . $idx . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',array=<pre>' . print_r($array, TRUE).'</pre>';
3150 // Return resulting array
3151 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
3155 // Generates a YES/NO option list from given default
3156 function generateYesNoOptions ($defaultValue = '') {
3158 return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
3161 // "Getter" for total available receivers
3162 function getTotalReceivers ($mode = 'normal') {
3164 $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
3170 // Wrapper "getter" to get total unconfirmed mails for given userid
3171 function getTotalUnconfirmedMails ($userid) {
3173 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
3175 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
3179 return $GLOBALS[__FUNCTION__][$userid];
3182 // Checks whether 'mailer_theme' was found in session
3183 function isMailerThemeSet () {
3185 if (!isset($GLOBALS[__FUNCTION__])) {
3187 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
3191 return $GLOBALS[__FUNCTION__];
3195 * Setter for theme in session (This setter does return the success of
3196 * setSession() which is required e.g. for destroySponsorSession().
3198 function setMailerTheme ($newTheme) {
3199 // Set it in session
3200 return setSession('mailer_theme', $newTheme);
3204 * Getter for theme from session (This getter does return 'mailer_theme' from
3205 * session data or throws an error if not possible
3207 function getMailerTheme () {
3209 if (!isset($GLOBALS[__FUNCTION__])) {
3210 // Is 'mailer_theme' set?
3211 if (!isMailerThemeSet()) {
3212 // No, then abort here
3213 reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
3216 // Get it and store it in cache
3217 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
3221 return $GLOBALS[__FUNCTION__];
3224 // "Getter" for last_module/last_what depending on ext-user version
3225 function getUserLastWhatName () {
3226 // Default is old one: last_module
3227 $columnName = 'last_module';
3229 // Is ext-user up-to-date?
3230 if (isExtensionInstalledAndNewer('user', '0.4.9')) {
3231 // Yes, then use new one
3232 $columnName = 'last_what';
3239 // "Getter" for all columns for given alias and separator
3240 function getAllPointColumns ($alias = NULL, $separator = ',') {
3241 // Prepare the filter array
3242 $filterData = array(
3245 'separator' => $separator
3249 $filterData = runFilterChain('get_all_point_columns', $filterData);
3251 // Return the columns
3252 return $filterData['columns'];
3255 // Checks whether the copyright footer (which breaks framesets) is enabled
3256 function ifCopyrightFooterEnabled () {
3257 // Is not unset and not 'N'?
3258 return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
3262 * Wrapper to check whether we have a "full page". This means that the actual
3263 * content is not delivered in any frame of a frameset.
3265 function isFullPage () {
3267 * The parameter 'frame' is generic and always indicates that this content
3268 * will be output into a frame. Furthermore, if a frameset is reported or
3269 * the copyright line is explicitly deactivated, this cannot be a "full
3272 // @TODO Find a way to not use direct module comparison
3273 $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
3279 // Checks whether frameset_mode is set to true
3280 function isFramesetModeEnabled () {
3282 return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
3285 // Function to determine correct 'what' value
3286 function determineWhat ($module = NULL) {
3287 // Init default 'what'
3291 if (is_null($module)) {
3293 $module = getModule();
3301 // Else try to get it from current module
3302 $what = getWhatFromModule($module);
3304 //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
3306 // Remove any spaces from variable
3307 $what = trim($what);
3311 // Default action for non-admin menus
3315 $what = secureString($what);
3322 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3323 function prependZeros ($str, $length = 2) {
3324 // Return prepended string
3325 return sprintf('%0' . (int) $length . 's', $str);
3328 // Wraps convertSelectionsToEpocheTime()
3329 function convertSelectionsToEpocheTimeInPostData ($id) {
3334 // Get all POST data
3335 $postData = postRequestArray();
3337 // Convert given selection id
3338 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3340 // Set the POST array back
3341 setPostRequestArray($postData);
3344 // Wraps checking if given points account type matches with given in POST data
3345 function ifPointsAccountTypeMatchesPost ($type) {
3347 exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
3350 // Gets given user's total referral
3351 function getUsersTotalReferrals ($userid, $level = NULL) {
3353 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3354 // Is the level NULL?
3355 if (is_null($level)) {
3356 // Get total amount (all levels)
3357 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
3359 // Get it from user refs
3360 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
3365 return $GLOBALS[__FUNCTION__][$userid][$level];
3368 // Gets given user's total referral
3369 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3370 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3372 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3373 // Default is all refs
3376 // Is the not level NULL?
3377 if (!is_null($level)) {
3378 // Then add referral level
3379 $add = ' AND `r`.`level`=' . bigintval($level);
3382 // Check for all referrals
3383 $result = sqlQueryEscaped("SELECT
3384 COUNT(`d`.`userid`) AS `cnt`
3386 `{?_MYSQL_PREFIX?}_user_data` AS `d`
3388 `{?_MYSQL_PREFIX?}_user_refs` AS `r`
3390 `d`.`userid`=`r`.`refid`
3392 `d`.`status` != 'CONFIRMED' AND
3400 ), __FUNCTION__, __LINE__);
3403 list($GLOBALS[__FUNCTION__][$userid][$level]) = sqlFetchRow($result);
3406 sqlFreeResult($result);
3410 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3411 return $GLOBALS[__FUNCTION__][$userid][$level];
3414 // Converts, if found, dollar data to get element
3415 function convertDollarDataToGetElement ($data) {
3416 // Is first char a dollar?
3417 if (substr($data, 0, 1) == chr(36)) {
3418 // Use last part for getRequestElement()
3419 $data = getRequestElement(substr($data, 1));
3426 // Wrapper function for SQL layer to speed-up things
3427 function isSqlDebugEnabled () {
3429 if (!isset($GLOBALS[__FUNCTION__])) {
3431 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3435 return $GLOBALS[__FUNCTION__];
3438 // Wrapper function to wrap call of wordwrap()
3439 function wrapWords ($text) {
3441 $wrapped = wordwrap($test, getWordWrap());
3447 // Encodes given data into a JSON object
3448 function encodeJson ($data) {
3450 return json_encode($data, JSON_FORCE_OBJECT);
3453 // Get all extension files
3454 function loadAllExtensionsByTemplate () {
3456 $extensions = getArrayFromDirectory(
3457 'templates/' . getLanguage() . '/html/ext/',
3471 // Wrapper function to allow full float values as supported by current database layout
3472 function translateFullComma ($dotted) {
3473 // Call inner function
3474 return translateComma($dotted, TRUE, 5);
3477 // Wrapper to check if the first element to be shifted is set to given value
3478 function shift_array (&$array, $value, $key = '0') {
3479 // Is the element set and value matches?
3480 assert(is_array($array));
3481 assert(isset($array[$key]));
3482 assert($array[$key] === $value);
3485 array_shift($array);
3488 // Wrapper for str_pad() with left padding zeros
3489 function padLeftZero ($str, $amount = 2) {
3490 // Is str_pad() there?
3491 if (!function_exists('str_pad')) {
3492 // Use prependZeros()
3493 return prependZeros($str, $amount);
3496 return str_pad($str, $amount, '0', STR_PAD_LEFT);
3500 // Calculates percentage
3501 function calculatePercentageRate ($current, $total) {
3505 // Is sent larger zero? (Prevents division-by-zero)
3507 // Calculate it (it should be "translated" alter on)
3508 $rate = ($current / $total * 100);
3511 // The should be a .0 at the end?
3512 if (strpos($rate, '.') === FALSE) {
3521 // Checks whether an array is filled with entries
3522 function isFilledArray ($array) {
3524 return ((is_array($array)) && (count($array) > 0));
3527 // Checks whether this script runs on a developer system (called with localhost/127.0.0.1 SERVER_NAME)
3528 function isDeveloperSystem () {
3530 return in_array(detectServerName(), array('localhost', '127.0.0.1'));
3533 // Checks whether given subject line has '_ref' suffix
3534 function ifSubjectHasReferralSuffix ($subject) {
3536 if (!isset($GLOBALS[__FUNCTION__][$subject])) {
3538 $GLOBALS[__FUNCTION__][$subject] = (substr($subject, -4, 4) == '_ref');
3542 return $GLOBALS[__FUNCTION__][$subject];
3545 // Converts an API response to an associative array
3546 function convertApiResponseToArray ($responseString, $keyDelimiter, $valueDelimiter) {
3547 // Explode for key delimiter
3548 $keys = explode($keyDelimiter, $responseString);
3550 // Init returned array and "walk" through all entries
3551 $returned = array();
3552 foreach ($keys as $keyValue) {
3554 $parts = explode($valueDelimiter, $keyValue);
3557 assert(count($parts) == 2);
3559 // Then add both: 0=key, 1=value
3560 $returned[sqlEscapeString($parts[0])] = sqlEscapeString($parts[1]);
3563 // Return finished array
3567 // Getter for full (generic) hash file name
3568 function getGenericHashFileName () {
3570 return sprintf('%s%s.%s%s', getPath(), getCachePath(), getFileHash(), getCacheExtension());
3573 // "Compiles" the given value and sets it in given key
3574 function setSessionCompiled ($key, $value) {
3575 // "Compile" the value
3576 $value = doFinalCompilation(compileRawCode($value));
3579 return setSession($key, $value);