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 - 2016 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 // Detects server protocol (http/s)
297 function detectServerProtocol () {
299 if (!isset($GLOBALS[__FUNCTION__])) {
301 $GLOBALS[__FUNCTION__] = 'http';
303 // Are some specific fields set?
304 if (((isset($_SERVER['HTTPS'])) && (strtolower($_SERVER['HTTPS']) == 'on')) || ((isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) && (strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https'))) {
306 $GLOBALS[__FUNCTION__] = 'https';
310 // Return cached value
311 return $GLOBALS[__FUNCTION__];
314 // Removes any existing www. from SERVER_NAME. This is very silly but enough
315 // for our purpose here.
316 function detectDomainName () {
318 if (!isset($GLOBALS[__FUNCTION__])) {
320 $domainName = detectServerName();
322 // Is there any www. ?
323 if (substr($domainName, 0, 4) == 'www.') {
325 $domainName = substr($domainName, 4);
329 $GLOBALS[__FUNCTION__] = $domainName;
333 return $GLOBALS[__FUNCTION__];
336 // Check whether we are installing
337 function isInstalling () {
338 // Determine whether we are installing
339 if (!isset($GLOBALS['__mailer_installing'])) {
340 // Check URL (css.php/js.php need this)
341 $GLOBALS['__mailer_installing'] = (isGetRequestElementSet('installing') || ((isAjaxOutputMode()) && (isGetRequestElementSet('level')) && (getRequestElement('level') == 'install')));
345 return $GLOBALS['__mailer_installing'];
348 // Check whether this script is installed
349 function isInstalled () {
351 if (!isset($GLOBALS[__FUNCTION__])) {
352 // Determine whether this script is installed
353 $GLOBALS[__FUNCTION__] = (
358 isConfigEntrySet('MAILER_INSTALLED')
360 getConfig('MAILER_INSTALLED') == 'Y'
364 // New config file found and loaded
365 isIncludeReadable(getCachePath() . 'config-local.php')
368 // New config file found, but not yet read
369 isIncludeReadable(getCachePath() . 'config-local.php')
372 // Only new config file is found
373 !isIncludeReadable('inc/config.php')
375 // Is installation mode
382 // Then use the cache
383 return $GLOBALS[__FUNCTION__];
386 // Check whether an admin is registered
387 function isAdminRegistered () {
389 if (!isset($GLOBALS[__FUNCTION__])) {
391 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
395 return $GLOBALS[__FUNCTION__];
398 // Checks whether the hourly reset mode is active
399 function isHourlyResetEnabled () {
400 // Now simply check it
401 return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE));
404 // Checks whether the daily reset mode is active
405 function isDailyResetEnabled () {
406 // Now simply check it
407 return ((isset($GLOBALS['daily_enabled'])) && ($GLOBALS['daily_enabled'] === TRUE));
410 // Checks whether the weekly reset mode is active
411 function isWeeklyResetEnabled () {
412 // Now simply check it
413 return ((isset($GLOBALS['weekly_enabled'])) && ($GLOBALS['weekly_enabled'] === TRUE));
416 // Checks whether the monthly reset mode is active
417 function isMonthlyResetEnabled () {
418 // Now simply check it
419 return ((isset($GLOBALS['monthly_enabled'])) && ($GLOBALS['monthly_enabled'] === TRUE));
422 // Checks whether the yearly reset mode is active
423 function isYearlyResetEnabled () {
424 // Now simply check it
425 return ((isset($GLOBALS['yearly_enabled'])) && ($GLOBALS['yearly_enabled'] === TRUE));
428 // Checks whether one of the reset modes is enabled
429 function isResetModeEnabled () {
430 // Now simply check it
431 return ((isHourlyResetEnabled()) || (isDailyResetEnabled()) || (isWeeklyResetEnabled()) || (isMonthlyResetEnabled()) || (isYearlyResetEnabled()));
434 // Checks whether the debug mode is enabled
435 function isDebugModeEnabled () {
437 if (!isset($GLOBALS[__FUNCTION__])) {
439 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
443 return $GLOBALS[__FUNCTION__];
446 // Checks whether the debug hourly is enabled
447 function isDebugHourlyEnabled () {
449 if (!isset($GLOBALS[__FUNCTION__])) {
451 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_HOURLY')) && (getConfig('DEBUG_HOURLY') == 'Y'));
455 return $GLOBALS[__FUNCTION__];
458 // Checks whether the debug daily is enabled
459 function isDebugDailyEnabled () {
461 if (!isset($GLOBALS[__FUNCTION__])) {
463 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_DAILY')) && (getConfig('DEBUG_DAILY') == 'Y'));
467 return $GLOBALS[__FUNCTION__];
470 // Checks whether the debug weekly is enabled
471 function isDebugWeeklyEnabled () {
473 if (!isset($GLOBALS[__FUNCTION__])) {
475 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
479 return $GLOBALS[__FUNCTION__];
482 // Checks whether the debug monthly is enabled
483 function isDebugMonthlyEnabled () {
485 if (!isset($GLOBALS[__FUNCTION__])) {
487 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
491 return $GLOBALS[__FUNCTION__];
494 // Checks whether the debug yearly is enabled
495 function isDebugYearlyEnabled () {
497 if (!isset($GLOBALS[__FUNCTION__])) {
499 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y'));
503 return $GLOBALS[__FUNCTION__];
506 // Checks whether SQL debugging is enabled
507 function isSqlDebuggingEnabled () {
509 if (!isset($GLOBALS[__FUNCTION__])) {
510 // Determine if SQL debugging is enabled
511 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
515 return $GLOBALS[__FUNCTION__];
518 // Checks whether we shall debug regular expressions
519 function isDebugRegularExpressionEnabled () {
521 if (!isset($GLOBALS[__FUNCTION__])) {
523 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
527 return $GLOBALS[__FUNCTION__];
530 // Checks whether debugging of build mails is enabled
531 function isDebugBuildMailsEnabled () {
533 if (!isset($GLOBALS[__FUNCTION__])) {
535 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_BUILD_MAILS')) && (getConfig('DEBUG_BUILD_MAILS') == 'Y'));
539 return $GLOBALS[__FUNCTION__];
542 // Checks whether the cache instance is valid
543 function isValidCacheInstance () {
545 if (!isset($GLOBALS[__FUNCTION__])) {
547 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
551 return $GLOBALS[__FUNCTION__];
554 // Copies a file from source to destination and verifies if that goes fine.
555 // This function should wrap the copy() command and make a nicer debug backtrace
556 // even if there is no xdebug extension installed.
557 function copyFileVerified ($source, $dest, $chmod = '') {
558 // Failed is the default
561 // Is the source file there?
562 if (!isFileReadable($source)) {
564 reportBug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
567 // Is the target directory there?
568 if (!isDirectory(dirname($dest))) {
570 reportBug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
573 // Now try to copy it
574 if (!copy($source, $dest)) {
575 // Something went wrong
576 reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
579 $GLOBALS['file_readable'][$dest] = TRUE;
582 // All fine by default
585 // If there are chmod rights set, apply them
586 if (!empty($chmod)) {
588 $status = changeMode($dest, $chmod);
595 // Wrapper function for chmod()
596 // @TODO Do some more sanity check here
597 function changeMode ($FQFN, $mode) {
598 // Is the file/directory there?
599 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
600 // Neither, so abort here
601 reportBug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
605 return chmod($FQFN, $mode);
608 // Wrapper for unlink()
609 function removeFile ($FQFN) {
610 // Is the file there?
611 if (isFileReadable($FQFN)) {
613 $GLOBALS['file_readable'][$FQFN] = FALSE;
616 return unlink($FQFN);
619 // All fine if no file was removed. If we change this to 'false' or rewrite
620 // above if() block it would be to restrictive.
624 // Wrapper for $_POST['sel']
625 function countPostSelection ($element = 'sel') {
627 if (!isset($GLOBALS[__FUNCTION__][$element])) {
629 $GLOBALS[__FUNCTION__][$element] = '0';
632 if (isPostRequestElementSet($element)) {
633 // Return counted elements
634 $GLOBALS[__FUNCTION__][$element] = countSelection(postRequestElement($element));
638 // Return cached value
639 return $GLOBALS[__FUNCTION__][$element];
642 // Checks whether the config-local.php is loaded
643 function isConfigLocalLoaded () {
644 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === TRUE));
647 // Checks whether a nickname or userid was entered and caches the result
648 function isNicknameUsed ($userid) {
649 // Is the cache there
650 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
652 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL'));
656 return $GLOBALS[__FUNCTION__][$userid];
659 // Getter for 'what' value
660 function getWhat ($strict = TRUE) {
665 if (isWhatSet($strict)) {
667 $what = $GLOBALS['__what'];
674 // Setter for 'what' value
675 function setWhat ($newWhat) {
676 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat);
677 $GLOBALS['__what'] = $newWhat;
680 // Setter for 'what' from configuration
681 function setWhatFromConfig ($configEntry) {
682 // Get 'what' from config
683 $what = getConfig($configEntry);
689 // Checks whether what is set and optionally aborts on miss
690 function isWhatSet ($strict = FALSE) {
692 $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
694 // Should we abort here?
695 if (($strict === TRUE) && ($isset === FALSE)) {
697 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
704 // Getter for 'action' value
705 function getAction ($strict = TRUE) {
710 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
712 $action = $GLOBALS['__action'];
719 // Setter for 'action' value
720 function setAction ($newAction) {
721 $GLOBALS['__action'] = $newAction;
724 // Checks whether action is set and optionally aborts on miss
725 function isActionSet ($strict = FALSE) {
727 $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
729 // Should we abort here?
730 if (($strict === TRUE) && ($isset === FALSE)) {
732 reportBug(__FUNCTION__, __LINE__, 'action is empty.');
739 // Getter for 'module' value
740 function getModule ($strict = TRUE) {
745 if (isModuleSet($strict)) {
747 $module = $GLOBALS['__module'];
754 // Setter for 'module' value
755 function setModule ($newModule) {
756 // Secure it and make all modules lower-case
757 $GLOBALS['__module'] = strtolower($newModule);
760 // Wrapper to get extra module names
761 function getExtraModule () {
765 // Is 'tab/step' set?
766 if (isPostRequestElementSet('tab')) {
768 $extra = 'tab=' . postRequestElement('tab');
769 } elseif (isPostRequestElementSet('step')) {
771 $extra = 'step=' . postRequestElement('step');
772 } elseif ((isActionSet()) && (isWhatSet())) {
774 $extra = 'action=' . getAction() . ':what=' . getWhat();
781 // Checks whether module is set and optionally aborts on miss
782 function isModuleSet ($strict = FALSE) {
784 $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
786 // Should we abort here?
787 if (($strict === TRUE) && ($isset === FALSE)) {
789 reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
793 return (($isset === TRUE) && ($GLOBALS['__module'] != 'unknown')) ;
796 // Getter for 'output_mode' value
797 function getScriptOutputMode () {
799 if (!isset($GLOBALS[__FUNCTION__])) {
800 // Is the output mode set?
801 if (!isOutputModeSet()) {
802 // No, then abort here
803 reportBug(__FUNCTION__, __LINE__, 'Output mode not set.');
807 $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode'];
811 return $GLOBALS[__FUNCTION__];
814 // Setter for 'output_mode' value
815 function setScriptOutputMode ($newOutputMode) {
816 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
817 $GLOBALS['__output_mode'] = (int) $newOutputMode;
820 // Checks whether output_mode is set and optionally aborts on miss
821 function isOutputModeSet ($strict = FALSE) {
823 $isset = (isset($GLOBALS['__output_mode']));
825 // Should we abort here?
826 if (($strict === TRUE) && ($isset === FALSE)) {
828 reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
835 // Enables block-mode
836 function enableBlockMode ($enabled = TRUE) {
837 $GLOBALS['__block_mode'] = $enabled;
840 // Checks whether block-mode is enabled
841 function isBlockModeEnabled () {
843 if (!isset($GLOBALS['__block_mode'])) {
845 reportBug(__FUNCTION__, __LINE__, '__block_mode is not set.');
849 return $GLOBALS['__block_mode'];
852 // Wrapper for redirectToUrl but URL comes from a configuration entry
853 function redirectToConfiguredUrl ($configEntry) {
855 redirectToUrl(getConfig($configEntry));
858 // Wrapper function to redirect from member-only modules to index
859 function redirectToIndexMemberOnlyModule () {
860 // Do the redirect here
861 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
864 // Wrapper function to redirect to current URL
865 function redirectToRequestUri () {
866 redirectToUrl(basename(detectRequestUri()));
869 // Wrapper function to redirect to de-refered URL
870 function redirectToDereferedUrl ($url) {
872 redirectToUrl(generateDereferrerUrl($url));
875 // Wrapper function for checking if extension is installed and newer or same version
876 function isExtensionInstalledAndNewer ($ext_name, $ext_ver) {
877 // Is an cache entry found?
878 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
880 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE));
882 // Cache hits should be incremented twice
883 incrementStatsEntry('cache_hits', 2);
887 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
888 return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
891 // Wrapper function for checking if extension is installed and older than given version
892 function isExtensionInstalledAndOlder ($ext_name, $ext_ver) {
893 // Is an cache entry found?
894 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
896 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '<') === TRUE));
898 // Cache hits should be incremented twice
899 incrementStatsEntry('cache_hits', 2);
903 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
904 return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
908 function setUsername ($userName) {
909 $GLOBALS['username'] = (string) $userName;
913 function getUsername () {
915 if (!isset($GLOBALS['username'])) {
916 // No, so it has to be a guest
917 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
921 return $GLOBALS['username'];
924 // Wrapper function for installation phase
925 function isInstaller () {
927 if (!isset($GLOBALS[__FUNCTION__])) {
929 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
933 return $GLOBALS[__FUNCTION__];
936 // Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
937 function isDemoModeActive () {
939 if (!isset($GLOBALS[__FUNCTION__])) {
941 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
945 return $GLOBALS[__FUNCTION__];
948 // Getter for PHP caching value
949 function getPhpCaching () {
950 return $GLOBALS['php_caching'];
953 // Checks whether the admin hash is set
954 function isAdminHashSet ($adminId) {
955 // Is the array there?
956 if (!isset($GLOBALS['cache_array']['admin'])) {
957 // Missing array should be reported
958 reportBug(__FUNCTION__, __LINE__, 'Cache not set.');
961 // Check for admin hash
962 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
965 // Setter for admin hash
966 function setAdminHash ($adminId, $hash) {
967 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
970 // Getter for current admin login
971 function getCurrentAdminLogin () {
973 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
976 if (!isset($GLOBALS[__FUNCTION__])) {
978 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
982 return $GLOBALS[__FUNCTION__];
985 // Setter for admin id (and current)
986 function setAdminId ($adminId) {
988 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
991 $status = setSession('admin_id', bigintval($adminId));
994 setCurrentAdminId($adminId);
1000 // Setter for admin_last
1001 function setAdminLast ($adminLast) {
1002 // Log debug message
1003 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
1006 $status = setSession('admin_last', $adminLast);
1012 // Setter for admin_md5
1013 function setAdminMd5 ($adminMd5) {
1014 // Log debug message
1015 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
1018 $status = setSession('admin_md5', $adminMd5);
1020 // Remove cache to get correct results
1021 unset($GLOBALS['isAdmin']);
1027 // Getter for admin_md5
1028 function getAdminMd5 () {
1029 // Log debug message
1030 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
1033 return getSession('admin_md5');
1036 // Init user data array
1037 function initUserData () {
1038 // User id should not be zero
1039 if (!isValidId(getCurrentUserId())) {
1040 // Should be always valid
1041 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
1045 unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
1046 $GLOBALS['user_data'][getCurrentUserId()] = array();
1049 // Getter for user data
1050 function getUserData ($column) {
1051 // User id should not be zero
1052 if (!isValidId(getCurrentUserId())) {
1053 // Should be always valid
1054 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
1060 if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
1062 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
1069 // Checks whether given user data is set to 'Y'
1070 function isUserDataEnabled ($column) {
1072 if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
1074 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
1078 return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
1081 // Geter for whole user data array
1082 function getUserDataArray () {
1084 $userid = getCurrentUserId();
1086 // Is the current userid valid?
1087 if (!isValidId($userid)) {
1088 // Should be always valid
1089 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
1092 // Get the whole array if found
1093 if (isset($GLOBALS['user_data'][$userid])) {
1094 // Found, so return it
1095 return $GLOBALS['user_data'][$userid];
1097 // Return empty array
1102 // Checks if the user data is valid, this may indicate that the user has logged
1103 // in, but you should use isMember() if you want to find that out.
1104 function isValidUserData () {
1105 // User id should not be zero so abort here
1106 if (!isCurrentUserIdSet()) {
1107 // Debug message, may be noisy
1108 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
1115 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
1117 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
1120 // Return the result
1121 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1124 // Setter for current userid
1125 function setCurrentUserId ($userid) {
1127 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - ENTERED!');
1129 // Is the cache from below functions different?
1130 if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) {
1132 unsetCurrentUserId();
1136 $GLOBALS['current_userid'] = bigintval($userid);
1138 // Unset it to re-determine the actual state
1139 unset($GLOBALS['is_userdata_valid'][$userid]);
1142 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - EXIT!');
1145 // Getter for current userid
1146 function getCurrentUserId () {
1148 if (!isset($GLOBALS[__FUNCTION__])) {
1149 // Userid must be set before it can be used
1150 if (!isCurrentUserIdSet()) {
1152 reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1155 // Set userid in cache
1156 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1160 return $GLOBALS[__FUNCTION__];
1163 // Checks if current userid is set
1164 function isCurrentUserIdSet () {
1166 if (!isset($GLOBALS[__FUNCTION__])) {
1168 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidId($GLOBALS['current_userid'])));
1172 return $GLOBALS[__FUNCTION__];
1175 // Unsets current userid
1176 function unsetCurrentUserId () {
1178 if (isset($GLOBALS['current_userid'])) {
1180 unset($GLOBALS['isValidId'][$GLOBALS['current_userid']]);
1183 // Unset all cache entries
1184 unset($GLOBALS['current_userid']);
1185 unset($GLOBALS['getCurrentUserId']);
1186 unset($GLOBALS['isCurrentUserIdSet']);
1189 // Checks whether we are debugging template cache
1190 function isDebugTemplateCacheEnabled () {
1192 if (!isset($GLOBALS[__FUNCTION__])) {
1194 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_TEMPLATE_CACHE')) && (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y'));
1198 return $GLOBALS[__FUNCTION__];
1201 // Wrapper for fetchUserData() and getUserData() calls
1202 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1203 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1205 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1209 // Can we fetch the user data?
1210 if ((isValidId($userid)) && (fetchUserData($userid, $keyColumn))) {
1211 // Now get the data back
1212 $data = getUserData($valueColumn);
1216 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1220 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1221 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1224 // Wrapper for strpos() to ease porting from deprecated ereg() function
1225 function isInString ($needle, $haystack) {
1226 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== FALSE));
1227 return (strpos($haystack, $needle) !== FALSE);
1230 // Wrapper for strpos() to ease porting from deprecated eregi() function
1231 // This function is case-insensitive
1232 function isInStringIgnoreCase ($needle, $haystack) {
1233 return (isInString(strtolower($needle), strtolower($haystack)));
1236 // Wrapper to check for if fatal errors where detected
1237 function ifFatalErrorsDetected () {
1238 // Just call the inner function
1239 return (getTotalFatalErrors() > 0);
1242 // Checks whether a HTTP status has been set
1243 function isHttpStatusSet () {
1244 // Is it set and not empty?
1245 return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1248 // Setter for HTTP status
1249 function setHttpStatus ($status) {
1250 $GLOBALS['http_status'] = (string) $status;
1253 // Getter for HTTP status
1254 function getHttpStatus () {
1255 // Is the status set?
1256 if (!isHttpStatusSet()) {
1258 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1262 return $GLOBALS['http_status'];
1266 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1267 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1269 * ----------------------------------------------------------------------------
1270 * If you want to redirect, please use redirectToUrl(); instead
1271 * ----------------------------------------------------------------------------
1273 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1275 * @link http://support.microsoft.com/kb/q176113/
1276 * @author Andreas Gohr <andi@splitbrain.org>
1279 function sendRawRedirect ($url) {
1280 //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url);
1282 // Clear output buffer
1283 clearOutputBuffer();
1285 // Clear own output buffer
1286 $GLOBALS['__output'] = '';
1288 // To make redirects working (no content type), output mode must be raw
1289 setScriptOutputMode(-1);
1291 // Send helping header
1292 setHttpStatus('302 Found');
1294 // always close the session
1295 session_write_close();
1297 // Revert entity &
1298 $url = str_replace('&', '&', $url);
1299 //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url);
1301 // check if running on IIS < 6 with CGI-PHP
1302 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1303 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1304 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1305 ($matches[1] < 6)) {
1306 // Send the IIS header
1307 addHttpHeader('Refresh: 0;url=' . $url);
1309 // Send generic header
1310 addHttpHeader('Location: ' . $url);
1317 // Determines the country of the given user id
1318 function determineCountry ($userid) {
1320 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1321 // Default is 'invalid'
1322 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1324 // Is extension country active?
1325 if (isExtensionActive('country')) {
1326 // Determine the right country code through the country id
1327 $id = getUserData('country_code');
1329 // Then handle it over
1330 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1332 // Get raw code from user data
1333 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1338 return $GLOBALS[__FUNCTION__][$userid];
1341 // "Getter" for total confirmed user accounts
1342 function getTotalConfirmedUser () {
1344 if (!isset($GLOBALS[__FUNCTION__])) {
1346 if (isExtensionActive('user')) {
1347 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1349 $GLOBALS[__FUNCTION__] = 0;
1353 // Return cached value
1354 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1355 return $GLOBALS[__FUNCTION__];
1358 // "Getter" for total unconfirmed user accounts
1359 function getTotalUnconfirmedUser () {
1361 if (!isset($GLOBALS[__FUNCTION__])) {
1363 if (isExtensionActive('user')) {
1364 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1366 $GLOBALS[__FUNCTION__] = 0;
1370 // Return cached value
1371 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1372 return $GLOBALS[__FUNCTION__];
1375 // "Getter" for total locked user accounts
1376 function getTotalLockedUser () {
1378 if (!isset($GLOBALS[__FUNCTION__])) {
1380 if (isExtensionActive('user')) {
1381 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1383 $GLOBALS[__FUNCTION__] = 0;
1387 // Return cached value
1388 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1389 return $GLOBALS[__FUNCTION__];
1392 // "Getter" for total locked user accounts
1393 function getTotalRandomRefidUser () {
1395 if (!isset($GLOBALS[__FUNCTION__])) {
1397 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1398 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
1400 $GLOBALS[__FUNCTION__] = 0;
1404 // Return cached value
1405 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1406 return $GLOBALS[__FUNCTION__];
1409 // Is given id number valid?
1410 function isValidId ($id) {
1412 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id[' . gettype($id) . ']=' . $id);
1415 if (!isset($GLOBALS[__FUNCTION__][$id])) {
1417 $GLOBALS[__FUNCTION__][$id] = ((isValidNumber($id)) && (!is_bool($id)) && ($id != '00000') && ($id > 0));
1421 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',result=' . intval($GLOBALS[__FUNCTION__][$id]));
1422 return $GLOBALS[__FUNCTION__][$id];
1425 // Checks whether a valid number is given
1426 function isValidNumber ($num) {
1428 return ((!is_null($num)) && (!empty($num)) && ('*' . bigintval($num, TRUE, FALSE) . '*' == '*' . $num . '*'));
1432 function encodeEntities ($str) {
1434 $str = secureString($str, TRUE, TRUE);
1436 // Encode dollar sign as well
1437 $str = str_replace('$', '$', $str);
1443 // Getter for current year (default)
1444 function getYear ($timestamp = NULL) {
1446 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1447 // If NULL is set, use time()
1448 if (is_null($timestamp)) {
1449 $timestamp = time();
1453 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1457 return $GLOBALS[__FUNCTION__][$timestamp];
1460 // Getter for current month (default)
1461 function getMonth ($timestamp = NULL) {
1463 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1464 // If NULL is set, use time()
1465 if (is_null($timestamp)) {
1466 // Use time() which is current timestamp
1467 $timestamp = time();
1471 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1475 return $GLOBALS[__FUNCTION__][$timestamp];
1478 // Getter for current hour (default)
1479 function getHour ($timestamp = NULL) {
1481 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1483 if (is_null($timestamp)) {
1484 $timestamp = time();
1488 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1492 return $GLOBALS[__FUNCTION__][$timestamp];
1495 // Getter for current day (default)
1496 function getDay ($timestamp = NULL) {
1498 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1500 if (is_null($timestamp)) {
1501 $timestamp = time();
1505 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1509 return $GLOBALS[__FUNCTION__][$timestamp];
1512 // Getter for current week (default)
1513 function getWeek ($timestamp = NULL) {
1515 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1517 if (is_null($timestamp)) $timestamp = time();
1520 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1524 return $GLOBALS[__FUNCTION__][$timestamp];
1527 // Getter for current short_hour (default)
1528 function getShortHour ($timestamp = NULL) {
1530 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1532 if (is_null($timestamp)) $timestamp = time();
1535 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1539 return $GLOBALS[__FUNCTION__][$timestamp];
1542 // Getter for current long_hour (default)
1543 function getLongHour ($timestamp = NULL) {
1545 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1547 if (is_null($timestamp)) $timestamp = time();
1550 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1554 return $GLOBALS[__FUNCTION__][$timestamp];
1557 // Getter for current second (default)
1558 function getSecond ($timestamp = NULL) {
1560 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1562 if (is_null($timestamp)) $timestamp = time();
1565 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1569 return $GLOBALS[__FUNCTION__][$timestamp];
1572 // Getter for current minute (default)
1573 function getMinute ($timestamp = NULL) {
1575 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1577 if (is_null($timestamp)) $timestamp = time();
1580 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1584 return $GLOBALS[__FUNCTION__][$timestamp];
1587 // Checks whether the title decoration is enabled
1588 function isTitleDecorationEnabled () {
1590 if (!isset($GLOBALS[__FUNCTION__])) {
1592 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_title_deco')) && (getConfig('enable_title_deco') == 'Y'));
1596 return $GLOBALS[__FUNCTION__];
1599 // Checks whether filter usage updates are enabled (expensive queries!)
1600 function isFilterUsageUpdateEnabled () {
1602 if (!isset($GLOBALS[__FUNCTION__])) {
1604 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1608 return $GLOBALS[__FUNCTION__];
1611 // Checks whether debugging of weekly resets is enabled
1612 function isWeeklyResetDebugEnabled () {
1614 if (!isset($GLOBALS[__FUNCTION__])) {
1616 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1620 return $GLOBALS[__FUNCTION__];
1623 // Checks whether debugging of monthly resets is enabled
1624 function isMonthlyResetDebugEnabled () {
1626 if (!isset($GLOBALS[__FUNCTION__])) {
1628 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1632 return $GLOBALS[__FUNCTION__];
1635 // Checks whether debugging of yearly resets is enabled
1636 function isYearlyResetDebugEnabled () {
1638 if (!isset($GLOBALS[__FUNCTION__])) {
1640 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_YEARLY')) && (getConfig('DEBUG_YEARLY') == 'Y'));
1644 return $GLOBALS[__FUNCTION__];
1647 // Checks whether displaying of debug SQLs are enabled
1648 function isDisplayDebugSqlEnabled () {
1650 if (!isset($GLOBALS[__FUNCTION__])) {
1652 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (isConfigEntrySet('display_debug_sql')) && (getDisplayDebugSqls() == 'Y'));
1656 return $GLOBALS[__FUNCTION__];
1659 // Checks whether module title is enabled
1660 function isModuleTitleEnabled () {
1662 if (!isset($GLOBALS[__FUNCTION__])) {
1664 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_mod_title')) && (getConfig('enable_mod_title') == 'Y'));
1668 return $GLOBALS[__FUNCTION__];
1671 // Checks whether what title is enabled
1672 function isWhatTitleEnabled () {
1674 if (!isset($GLOBALS[__FUNCTION__])) {
1676 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.1.6')) && (isConfigEntrySet('enable_what_title')) && (getConfig('enable_what_title') == 'Y'));
1680 return $GLOBALS[__FUNCTION__];
1683 // "Getter" for internal_stats
1684 function getInternalStats () {
1686 if (!isset($GLOBALS[__FUNCTION__])) {
1688 $GLOBALS[__FUNCTION__] = getConfig('internal_stats');
1692 return $GLOBALS[__FUNCTION__];
1695 // Checks whether stats are enabled
1696 function ifInternalStatsEnabled () {
1698 if (!isset($GLOBALS[__FUNCTION__])) {
1699 // Then determine it, do not add isExtensionInstalledAndNewer() here as it breaks very first SQL query
1700 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('internal_stats')) && (getInternalStats() == 'Y'));
1703 // Return cached value
1704 return $GLOBALS[__FUNCTION__];
1707 // Checks whether admin-notification of certain user actions is enabled
1708 function isAdminNotificationEnabled () {
1710 if (!isset($GLOBALS[__FUNCTION__])) {
1712 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.3.0')) && (isConfigEntrySet('admin_notify')) && (getAdminNotify() == 'Y'));
1716 return $GLOBALS[__FUNCTION__];
1719 // Checks whether random referral id selection is enabled
1720 function isRandomReferralIdEnabled () {
1722 if (!isset($GLOBALS[__FUNCTION__])) {
1724 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isConfigEntrySet('select_user_zero_refid')) && (getSelectUserZeroRefid() == 'Y'));
1728 return $GLOBALS[__FUNCTION__];
1731 // "Getter" for default language
1732 function getDefaultLanguage () {
1734 if (!isset($GLOBALS[__FUNCTION__])) {
1736 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1740 return $GLOBALS[__FUNCTION__];
1743 // "Getter" for default referral id
1744 function getDefRefid () {
1746 if (!isset($GLOBALS[__FUNCTION__])) {
1748 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1752 return $GLOBALS[__FUNCTION__];
1755 // "Getter" for path
1756 function getPath () {
1758 if (!isset($GLOBALS[__FUNCTION__])) {
1760 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1764 return $GLOBALS[__FUNCTION__];
1768 function getUrl () {
1770 if (!isset($GLOBALS[__FUNCTION__])) {
1772 $GLOBALS[__FUNCTION__] = getConfig('URL');
1776 return $GLOBALS[__FUNCTION__];
1779 // "Getter" for cache_path
1780 function getCachePath () {
1782 if (!isset($GLOBALS[__FUNCTION__])) {
1784 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1788 return $GLOBALS[__FUNCTION__];
1791 // "Getter" for cache_extension
1792 function getCacheExtension () {
1794 if (!isset($GLOBALS[__FUNCTION__])) {
1796 $GLOBALS[__FUNCTION__] = getConfig('CACHE_EXTENSION');
1800 return $GLOBALS[__FUNCTION__];
1803 // "Getter" for WRITE_FOOTER
1804 function getWriteFooter () {
1806 if (!isset($GLOBALS[__FUNCTION__])) {
1808 $GLOBALS[__FUNCTION__] = getConfig('WRITE_FOOTER');
1812 return $GLOBALS[__FUNCTION__];
1815 // "Getter" for secret_key
1816 function getSecretKey () {
1818 if (!isset($GLOBALS[__FUNCTION__])) {
1820 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1824 return $GLOBALS[__FUNCTION__];
1827 // "Getter" for SITE_KEY
1828 function getSiteKey () {
1830 if (!isset($GLOBALS[__FUNCTION__])) {
1832 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1836 return $GLOBALS[__FUNCTION__];
1839 // "Getter" for DATE_KEY
1840 function getDateKey () {
1842 if (!isset($GLOBALS[__FUNCTION__])) {
1844 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1848 return $GLOBALS[__FUNCTION__];
1851 // "Getter" for master_salt
1852 function getMasterSalt () {
1854 if (!isset($GLOBALS[__FUNCTION__])) {
1856 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1860 return $GLOBALS[__FUNCTION__];
1863 // "Getter" for prime
1864 function getPrime () {
1866 if (!isset($GLOBALS[__FUNCTION__])) {
1868 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1872 return $GLOBALS[__FUNCTION__];
1875 // "Getter" for encrypt_separator
1876 function getEncryptSeparator () {
1878 if (!isset($GLOBALS[__FUNCTION__])) {
1880 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1884 return $GLOBALS[__FUNCTION__];
1887 // "Getter" for mysql_prefix
1888 function getMysqlPrefix () {
1890 if (!isset($GLOBALS[__FUNCTION__])) {
1892 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1896 return $GLOBALS[__FUNCTION__];
1899 // "Getter" for table_type
1900 function getTableType () {
1902 if (!isset($GLOBALS[__FUNCTION__])) {
1904 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1908 return $GLOBALS[__FUNCTION__];
1911 // "Getter" for db_type
1912 function getDbType () {
1914 if (!isset($GLOBALS[__FUNCTION__])) {
1916 $GLOBALS[__FUNCTION__] = getConfig('_DB_TYPE');
1920 return $GLOBALS[__FUNCTION__];
1923 // "Getter" for salt_length
1924 function getSaltLength () {
1926 if (!isset($GLOBALS[__FUNCTION__])) {
1928 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1932 return $GLOBALS[__FUNCTION__];
1935 // "Getter" for output_mode
1936 function getOutputMode () {
1938 if (!isset($GLOBALS[__FUNCTION__])) {
1940 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1944 return $GLOBALS[__FUNCTION__];
1947 // "Getter" for full_version
1948 function getFullVersion () {
1950 if (!isset($GLOBALS[__FUNCTION__])) {
1952 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1956 return $GLOBALS[__FUNCTION__];
1959 // "Getter" for title
1960 function getTitle () {
1962 if (!isset($GLOBALS[__FUNCTION__])) {
1964 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1968 return $GLOBALS[__FUNCTION__];
1971 // "Getter" for server_url
1972 function getServerUrl () {
1974 if (!isset($GLOBALS[__FUNCTION__])) {
1976 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1980 return $GLOBALS[__FUNCTION__];
1983 // "Getter" for mt_word
1984 function getMtWord () {
1986 if (!isset($GLOBALS[__FUNCTION__])) {
1988 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1992 return $GLOBALS[__FUNCTION__];
1995 // "Getter" for mt_word2
1996 function getMtWord2 () {
1998 if (!isset($GLOBALS[__FUNCTION__])) {
2000 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
2004 return $GLOBALS[__FUNCTION__];
2007 // "Getter" for mt_word3
2008 function getMtWord3 () {
2010 if (!isset($GLOBALS[__FUNCTION__])) {
2012 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
2016 return $GLOBALS[__FUNCTION__];
2019 // "Getter" for START_TDAY
2020 function getStartTday () {
2022 if (!isset($GLOBALS[__FUNCTION__])) {
2024 $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
2028 return $GLOBALS[__FUNCTION__];
2031 // "Getter" for START_YDAY
2032 function getStartYday () {
2034 if (!isset($GLOBALS[__FUNCTION__])) {
2036 $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
2040 return $GLOBALS[__FUNCTION__];
2043 // "Getter" for main_title
2044 function getMainTitle () {
2046 if (!isset($GLOBALS[__FUNCTION__])) {
2048 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
2052 return $GLOBALS[__FUNCTION__];
2055 // "Getter" for file_hash
2056 function getFileHash () {
2058 if (!isset($GLOBALS[__FUNCTION__])) {
2060 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
2064 return $GLOBALS[__FUNCTION__];
2067 // "Getter" for pass_scramble
2068 function getPassScramble () {
2070 if (!isset($GLOBALS[__FUNCTION__])) {
2072 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
2076 return $GLOBALS[__FUNCTION__];
2079 // "Getter" for ap_inactive_since
2080 function getApInactiveSince () {
2082 if (!isset($GLOBALS[__FUNCTION__])) {
2084 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
2088 return $GLOBALS[__FUNCTION__];
2091 // "Getter" for user_min_confirmed
2092 function getUserMinConfirmed () {
2094 if (!isset($GLOBALS[__FUNCTION__])) {
2096 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
2100 return $GLOBALS[__FUNCTION__];
2102 // "Getter" for points
2103 function getPoints () {
2105 if (!isset($GLOBALS[__FUNCTION__])) {
2107 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
2111 return $GLOBALS[__FUNCTION__];
2114 // "Getter" for slogan
2115 function getSlogan () {
2117 if (!isset($GLOBALS[__FUNCTION__])) {
2119 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
2123 return $GLOBALS[__FUNCTION__];
2126 // "Getter" for copy
2127 function getCopy () {
2129 if (!isset($GLOBALS[__FUNCTION__])) {
2131 $GLOBALS[__FUNCTION__] = getConfig('COPY');
2135 return $GLOBALS[__FUNCTION__];
2138 // "Getter" for webmaster
2139 function getWebmaster () {
2141 if (!isset($GLOBALS[__FUNCTION__])) {
2143 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
2147 return $GLOBALS[__FUNCTION__];
2150 // "Getter" for sql_count
2151 function getSqlCount () {
2153 if (!isset($GLOBALS[__FUNCTION__])) {
2155 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2159 return $GLOBALS[__FUNCTION__];
2162 // "Getter" for num_templates
2163 function getNumTemplates () {
2165 if (!isset($GLOBALS[__FUNCTION__])) {
2167 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2171 return $GLOBALS[__FUNCTION__];
2174 // "Getter" for dns_cache_timeout
2175 function getDnsCacheTimeout () {
2177 if (!isset($GLOBALS[__FUNCTION__])) {
2179 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2183 return $GLOBALS[__FUNCTION__];
2186 // "Getter" for menu_blur_spacer
2187 function getMenuBlurSpacer () {
2189 if (!isset($GLOBALS[__FUNCTION__])) {
2191 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2195 return $GLOBALS[__FUNCTION__];
2198 // "Getter" for points_register
2199 function getPointsRegister () {
2201 if (!isset($GLOBALS[__FUNCTION__])) {
2203 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2207 return $GLOBALS[__FUNCTION__];
2210 // "Getter" for points_ref
2211 function getPointsRef () {
2213 if (!isset($GLOBALS[__FUNCTION__])) {
2215 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2219 return $GLOBALS[__FUNCTION__];
2222 // "Getter" for ref_payout
2223 function getRefPayout () {
2225 if (!isset($GLOBALS[__FUNCTION__])) {
2227 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2231 return $GLOBALS[__FUNCTION__];
2234 // "Getter" for online_timeout
2235 function getOnlineTimeout () {
2237 if (!isset($GLOBALS[__FUNCTION__])) {
2239 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2243 return $GLOBALS[__FUNCTION__];
2246 // "Getter" for index_home
2247 function getIndexHome () {
2249 if (!isset($GLOBALS[__FUNCTION__])) {
2251 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2255 return $GLOBALS[__FUNCTION__];
2258 // "Getter" for one_day
2259 function getOneDay () {
2261 if (!isset($GLOBALS[__FUNCTION__])) {
2263 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2267 return $GLOBALS[__FUNCTION__];
2270 // "Getter" for img_type
2271 function getImgType () {
2273 if (!isset($GLOBALS[__FUNCTION__])) {
2275 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2279 return $GLOBALS[__FUNCTION__];
2282 // "Getter" for code_length
2283 function getCodeLength () {
2285 if (!isset($GLOBALS[__FUNCTION__])) {
2287 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2291 return $GLOBALS[__FUNCTION__];
2294 // "Getter" for min_password_length
2295 function getMinPasswordLength () {
2297 if (!isset($GLOBALS[__FUNCTION__])) {
2299 $GLOBALS[__FUNCTION__] = getConfig('min_password_length');
2303 return $GLOBALS[__FUNCTION__];
2306 // "Getter" for min_password_score
2307 function getMinPasswordScore () {
2309 if (!isset($GLOBALS[__FUNCTION__])) {
2311 $GLOBALS[__FUNCTION__] = getConfig('min_password_score');
2315 return $GLOBALS[__FUNCTION__];
2318 // "Getter" for admin_menu
2319 function getAdminMenu () {
2321 if (!isset($GLOBALS[__FUNCTION__])) {
2323 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2327 return $GLOBALS[__FUNCTION__];
2330 // "Getter" for last_hourly
2331 function getLastHourly () {
2333 if (!isset($GLOBALS[__FUNCTION__])) {
2335 $GLOBALS[__FUNCTION__] = getConfig('last_hourly');
2339 return $GLOBALS[__FUNCTION__];
2342 // "Getter" for last_daily
2343 function getLastDaily () {
2345 if (!isset($GLOBALS[__FUNCTION__])) {
2347 $GLOBALS[__FUNCTION__] = getConfig('last_daily');
2351 return $GLOBALS[__FUNCTION__];
2354 // "Getter" for last_weekly
2355 function getLastWeekly () {
2357 if (!isset($GLOBALS[__FUNCTION__])) {
2359 $GLOBALS[__FUNCTION__] = getConfig('last_weekly');
2363 return $GLOBALS[__FUNCTION__];
2366 // "Getter" for last_monthly
2367 function getLastMonthly () {
2369 if (!isset($GLOBALS[__FUNCTION__])) {
2371 $GLOBALS[__FUNCTION__] = getConfig('last_monthly');
2375 return $GLOBALS[__FUNCTION__];
2378 // "Getter" for last_yearly
2379 function getLastYearly () {
2381 if (!isset($GLOBALS[__FUNCTION__])) {
2383 $GLOBALS[__FUNCTION__] = getConfig('last_yearly');
2387 return $GLOBALS[__FUNCTION__];
2390 // "Getter" for mails_page
2391 function getMailsPage () {
2393 if (!isset($GLOBALS[__FUNCTION__])) {
2395 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2399 return $GLOBALS[__FUNCTION__];
2402 // "Getter" for rand_no
2403 function getRandNo () {
2405 if (!isset($GLOBALS[__FUNCTION__])) {
2407 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2411 return $GLOBALS[__FUNCTION__];
2414 // "Getter" for __DB_NAME
2415 function getDbName () {
2417 if (!isset($GLOBALS[__FUNCTION__])) {
2419 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2423 return $GLOBALS[__FUNCTION__];
2426 // "Getter" for DOMAIN
2427 function getDomain () {
2429 if (!isset($GLOBALS[__FUNCTION__])) {
2431 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2435 return $GLOBALS[__FUNCTION__];
2438 // "Getter" for proxy_username
2439 function getProxyUsername () {
2441 if (!isset($GLOBALS[__FUNCTION__])) {
2443 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2447 return $GLOBALS[__FUNCTION__];
2450 // "Getter" for proxy_password
2451 function getProxyPassword () {
2453 if (!isset($GLOBALS[__FUNCTION__])) {
2455 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2459 return $GLOBALS[__FUNCTION__];
2462 // "Getter" for proxy_host
2463 function getProxyHost () {
2465 if (!isset($GLOBALS[__FUNCTION__])) {
2467 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2471 return $GLOBALS[__FUNCTION__];
2474 // "Getter" for proxy_port
2475 function getProxyPort () {
2477 if (!isset($GLOBALS[__FUNCTION__])) {
2479 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2483 return $GLOBALS[__FUNCTION__];
2486 // "Getter" for SMTP_HOSTNAME
2487 function getSmtpHostname () {
2489 if (!isset($GLOBALS[__FUNCTION__])) {
2491 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2495 return $GLOBALS[__FUNCTION__];
2498 // "Getter" for SMTP_USER
2499 function getSmtpUser () {
2501 if (!isset($GLOBALS[__FUNCTION__])) {
2503 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2507 return $GLOBALS[__FUNCTION__];
2510 // "Getter" for SMTP_PASSWORD
2511 function getSmtpPassword () {
2513 if (!isset($GLOBALS[__FUNCTION__])) {
2515 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2519 return $GLOBALS[__FUNCTION__];
2522 // "Getter" for points_word
2523 function getPointsWord () {
2525 if (!isset($GLOBALS[__FUNCTION__])) {
2527 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2531 return $GLOBALS[__FUNCTION__];
2534 // "Getter" for profile_lock
2535 function getProfileLock () {
2537 if (!isset($GLOBALS[__FUNCTION__])) {
2539 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2543 return $GLOBALS[__FUNCTION__];
2546 // "Getter" for url_tlock
2547 function getUrlTlock () {
2549 if (!isset($GLOBALS[__FUNCTION__])) {
2551 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2555 return $GLOBALS[__FUNCTION__];
2558 // "Getter" for title_left
2559 function getTitleLeft () {
2561 if (!isset($GLOBALS[__FUNCTION__])) {
2563 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2567 return $GLOBALS[__FUNCTION__];
2570 // "Getter" for title_right
2571 function getTitleRight () {
2573 if (!isset($GLOBALS[__FUNCTION__])) {
2575 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2579 return $GLOBALS[__FUNCTION__];
2582 // "Getter" for title_middle
2583 function getTitleMiddle () {
2585 if (!isset($GLOBALS[__FUNCTION__])) {
2587 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2591 return $GLOBALS[__FUNCTION__];
2594 // Getter for 'display_home_in_index'
2595 function getDisplayHomeInIndex () {
2596 // Is the cache entry set?
2597 if (!isset($GLOBALS[__FUNCTION__])) {
2598 // No, so determine it
2599 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2602 // Return cached entry
2603 return $GLOBALS[__FUNCTION__];
2606 // Checks whether 'display_home_in_index' is 'Y'
2607 function isDisplayHomeInIndexEnabled () {
2608 // Is the cache entry set?
2609 if (!isset($GLOBALS[__FUNCTION__])) {
2610 // No, so determine it
2611 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isConfigEntrySet('display_home_in_index')) && (getDisplayHomeInIndex() == 'Y'));
2614 // Return cached entry
2615 return $GLOBALS[__FUNCTION__];
2618 // Getter for 'show_points_unconfirmed'
2619 function getShowPointsUnconfirmed () {
2620 // Is the cache entry set?
2621 if (!isset($GLOBALS[__FUNCTION__])) {
2622 // No, so determine it
2623 $GLOBALS[__FUNCTION__] = getConfig('show_points_unconfirmed');
2626 // Return cached entry
2627 return $GLOBALS[__FUNCTION__];
2630 // Checks whether 'show_points_unconfirmed' is 'Y'
2631 function isShowPointsUnconfirmedEnabled () {
2632 // Is the cache entry set?
2633 if (!isset($GLOBALS[__FUNCTION__])) {
2634 // No, so determine it
2635 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.5.5')) && (isConfigEntrySet('show_points_unconfirmed')) && (getShowPointsUnconfirmed() == 'Y'));
2638 // Return cached entry
2639 return $GLOBALS[__FUNCTION__];
2642 // Getter for 'youre_here'
2643 function getYoureHere () {
2644 // Is the cache entry set?
2645 if (!isset($GLOBALS[__FUNCTION__])) {
2646 // No, so determine it
2647 $GLOBALS[__FUNCTION__] = getConfig('youre_here');
2650 // Return cached entry
2651 return $GLOBALS[__FUNCTION__];
2654 // Checks whether 'show_timings' is 'Y'
2655 function isYoureHereEnabled () {
2656 // Is the cache entry set?
2657 if (!isset($GLOBALS[__FUNCTION__])) {
2658 // No, so determine it
2659 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (isConfigEntrySet('youre_here')) && (getYoureHere() == 'Y'));
2662 // Return cached entry
2663 return $GLOBALS[__FUNCTION__];
2666 // Getter for 'show_timings'
2667 function getShowTimings () {
2668 // Is the cache entry set?
2669 if (!isset($GLOBALS[__FUNCTION__])) {
2670 // No, so determine it
2671 $GLOBALS[__FUNCTION__] = getConfig('show_timings');
2674 // Return cached entry
2675 return $GLOBALS[__FUNCTION__];
2678 // Checks whether 'show_timings' is 'Y'
2679 function isShowTimingsEnabled () {
2680 // Is the cache entry set?
2681 if (!isset($GLOBALS[__FUNCTION__])) {
2682 // No, so determine it
2683 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.1')) && (isConfigEntrySet('show_timings')) && (getShowTimings() == 'Y'));
2686 // Return cached entry
2687 return $GLOBALS[__FUNCTION__];
2690 // Getter for 'ap_server_name_since'
2691 function getApServerNameSince () {
2692 // Is the cache entry set?
2693 if (!isset($GLOBALS[__FUNCTION__])) {
2694 // No, so determine it
2695 $GLOBALS[__FUNCTION__] = getConfig('ap_server_name_since');
2698 // Return cached entry
2699 return $GLOBALS[__FUNCTION__];
2702 // Getter for 'ap_server_name'
2703 function getApServerName () {
2704 // Is the cache entry set?
2705 if (!isset($GLOBALS[__FUNCTION__])) {
2706 // No, so determine it
2707 $GLOBALS[__FUNCTION__] = getConfig('ap_server_name');
2710 // Return cached entry
2711 return $GLOBALS[__FUNCTION__];
2714 // Getter for 'index_delay'
2715 function getIndexDelay () {
2716 // Is the cache entry set?
2717 if (!isset($GLOBALS[__FUNCTION__])) {
2718 // No, so determine it
2719 $GLOBALS[__FUNCTION__] = getConfig('index_delay');
2722 // Return cached entry
2723 return $GLOBALS[__FUNCTION__];
2726 // Checks whether 'ap_server_name' is 'Y'
2727 function isApServerNameEnabled () {
2728 // Is the cache entry set?
2729 if (!isset($GLOBALS[__FUNCTION__])) {
2730 // No, so determine it
2731 $GLOBALS[__FUNCTION__] = (getApServerName() == 'Y');
2734 // Return cached entry
2735 return $GLOBALS[__FUNCTION__];
2738 // Getter for 'admin_menu_javascript'
2739 function getAdminMenuJavascript () {
2740 // Is the cache entry set?
2741 if (!isset($GLOBALS[__FUNCTION__])) {
2742 // No, so determine it
2743 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2746 // Return cached entry
2747 return $GLOBALS[__FUNCTION__];
2750 // Getter for 'points_remove_account'
2751 function getPointsRemoveAccount () {
2752 // Is the cache entry set?
2753 if (!isset($GLOBALS[__FUNCTION__])) {
2754 // No, so determine it
2755 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2758 // Return cached entry
2759 return $GLOBALS[__FUNCTION__];
2762 // Getter for 'css_php'
2763 function getCssPhp () {
2764 // Is the cache entry set?
2765 if (!isset($GLOBALS[__FUNCTION__])) {
2766 // No, so determine it
2767 $GLOBALS[__FUNCTION__] = getConfig('css_php');
2770 // Return cached entry
2771 return $GLOBALS[__FUNCTION__];
2774 // Getter for 'guest_menu'
2775 function getGuestMenu () {
2776 // Is the cache entry set?
2777 if (!isset($GLOBALS[__FUNCTION__])) {
2778 // No, so determine it
2779 $GLOBALS[__FUNCTION__] = getConfig('guest_menu');
2782 // Return cached entry
2783 return $GLOBALS[__FUNCTION__];
2786 // Checks if guest menu is enabled
2787 function isGuestMenuEnabled () {
2788 // Is the cache entry set?
2789 if (!isset($GLOBALS[__FUNCTION__])) {
2790 // No, so determine it
2791 $GLOBALS[__FUNCTION__] = (getGuestMenu() == 'Y');
2794 // Return cached entry
2795 return $GLOBALS[__FUNCTION__];
2798 // Getter for 'member_menu'
2799 function getMemberMenu () {
2800 // Is the cache entry set?
2801 if (!isset($GLOBALS[__FUNCTION__])) {
2802 // No, so determine it
2803 $GLOBALS[__FUNCTION__] = getConfig('member_menu');
2806 // Return cached entry
2807 return $GLOBALS[__FUNCTION__];
2810 // Checks if member menu is enabled
2811 function isMemberMenuEnabled () {
2812 // Is the cache entry set?
2813 if (!isset($GLOBALS[__FUNCTION__])) {
2814 // No, so determine it
2815 $GLOBALS[__FUNCTION__] = (getMemberMenu() == 'Y');
2818 // Return cached entry
2819 return $GLOBALS[__FUNCTION__];
2822 // Getter for 'word_wrap'
2823 function getWordWrap () {
2824 // Is the cache entry set?
2825 if (!isset($GLOBALS[__FUNCTION__])) {
2826 // Construct config entry name
2827 $configEntry = getMenuModeFromModule() . '_word_wrap_' . getWhat();
2829 // Is a special config entry found or ext-sql_patches updated?
2830 if (isConfigEntrySet($configEntry)) {
2831 // A special config entry has been found, then use it
2832 $GLOBALS[__FUNCTION__] = getConfig($configEntry);
2833 } elseif (isExtensionInstalledAndNewer('other', '0.2.9')) {
2834 // No special config entry found, then use it as "fall-back"
2835 $GLOBALS[__FUNCTION__] = getConfig('word_wrap');
2837 // No, use default (15 characters)
2838 $GLOBALS[__FUNCTION__] = 15;
2842 // Return cached entry
2843 return $GLOBALS[__FUNCTION__];
2846 // Checks whether proxy configuration is used
2847 function isProxyUsed () {
2849 if (!isset($GLOBALS[__FUNCTION__])) {
2851 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (isValidNumber(getConfig('proxy_port'))));
2855 return $GLOBALS[__FUNCTION__];
2858 // Checks whether POST data contains selections
2859 function ifPostContainsSelections ($element = 'sel') {
2861 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2863 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2867 return $GLOBALS[__FUNCTION__][$element];
2870 // Checks whether verbose_sql is Y and returns true/false if so
2871 function isVerboseSqlEnabled () {
2873 if (!isset($GLOBALS[__FUNCTION__])) {
2875 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2879 return $GLOBALS[__FUNCTION__];
2882 // "Getter" for total user points
2883 function getTotalPoints ($userid) {
2885 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2886 // Init array for filter chain
2888 'userid' => $userid,
2892 // Run filter chain for getting more point values
2893 $data = runFilterChain('get_total_points', $data);
2896 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - getUserUsedPoints($userid);
2900 return $GLOBALS[__FUNCTION__][$userid];
2903 // Wrapper to get used points for given userid
2904 function getUserUsedPoints ($userid) {
2906 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2908 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2912 return $GLOBALS[__FUNCTION__][$userid];
2915 // Checks whether direct payment is allowed in configuration
2916 function isDirectPaymentEnabled () {
2918 if (!isset($GLOBALS[__FUNCTION__])) {
2920 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('allow_direct_pay')) && (getConfig('allow_direct_pay') == 'Y'));
2924 return $GLOBALS[__FUNCTION__];
2927 // Checks whether JavaScript-based admin menu is enabled
2928 function isAdminMenuJavascriptEnabled () {
2930 if (!isset($GLOBALS[__FUNCTION__])) {
2932 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (isConfigEntrySet('admin_menu_javascript')) && (getAdminMenuJavaScript() == 'Y'));
2936 return $GLOBALS[__FUNCTION__];
2939 // Wrapper to check if current task is for extension (not update)
2940 function isExtensionTask ($content) {
2942 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2944 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2948 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2951 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2952 function ifTesterAccountsAllowed () {
2953 // Is the cache entry set?
2954 if (!isset($GLOBALS[__FUNCTION__])) {
2955 // No, so determine it
2956 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2959 // Return cached entry
2960 return $GLOBALS[__FUNCTION__];
2963 // Wrapper to check if output mode is CSS
2964 function isCssOutputMode () {
2966 if (!isset($GLOBALS[__FUNCTION__])) {
2968 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2969 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2973 return $GLOBALS[__FUNCTION__];
2976 // Wrapper to check if output mode is HTML
2977 function isHtmlOutputMode () {
2979 if (!isset($GLOBALS[__FUNCTION__])) {
2981 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2982 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2986 return $GLOBALS[__FUNCTION__];
2989 // Wrapper to check if output mode is RAW
2990 function isRawOutputMode () {
2992 if (!isset($GLOBALS[__FUNCTION__])) {
2994 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2995 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2999 return $GLOBALS[__FUNCTION__];
3002 // Wrapper to check if output mode is AJAX
3003 function isAjaxOutputMode () {
3005 if (!isset($GLOBALS[__FUNCTION__])) {
3007 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
3008 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
3012 return $GLOBALS[__FUNCTION__];
3015 // Wrapper to check if output mode is image
3016 function isImageOutputMode () {
3018 if (!isset($GLOBALS[__FUNCTION__])) {
3020 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
3021 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
3025 return $GLOBALS[__FUNCTION__];
3028 // Wrapper to generate a user email link
3029 function generateWrappedUserEmailLink ($email) {
3030 // Just call the inner function
3031 return generateEmailLink($email, 'user_data');
3034 // Wrapper to check if user points are locked
3035 function ifUserPointsLocked ($userid) {
3036 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
3038 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
3040 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
3044 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
3045 return $GLOBALS[__FUNCTION__][$userid];
3048 // Appends a line to an existing file or creates it instantly with given content.
3049 // This function does always add a new-line character to every line.
3050 function appendLineToFile ($file, $line) {
3051 $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
3052 fwrite($fp, $line . PHP_EOL);
3056 // Wrapper for changeDataInFile() but with full path added
3057 function changeDataInInclude ($inc, $comment, $prefix, $suffix, $inserted, $seek=0) {
3059 $FQFN = getPath() . $inc;
3061 // Call inner function
3062 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
3065 // Wrapper for changing entries in config-local.php
3066 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
3067 // Call the inner function
3068 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
3071 // Shortens ucfirst(strtolower()) calls
3072 function firstCharUpperCase ($str) {
3073 return ucfirst(strtolower($str));
3076 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
3077 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
3078 // Get the configuration entry
3079 $configValue = getConfig($configEntry);
3081 // Call inner method
3082 return createTimeSelections($configValue, $configEntry, $stamps, $align);
3085 // Shortens converting of German comma to Computer's version in POST data
3086 function convertCommaToDotInPostData ($postEntry) {
3087 // Read and convert given entry
3088 $postValue = convertCommaToDot(postRequestElement($postEntry));
3091 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
3093 // ... and set it again
3094 setPostRequestElement($postEntry, $postValue);
3097 // Converts German commas to Computer's version in all entries
3098 function convertCommaToDotInPostDataArray ($postEntries) {
3099 // Replace german decimal comma with computer decimal dot
3100 foreach ($postEntries as $entry) {
3101 // Is the entry there?
3102 if (isPostRequestElementSet($entry)) {
3104 convertCommaToDotInPostData($entry);
3110 * Parses a string into a US formated float variable, taken from user comments
3111 * from PHP documentation website.
3113 * @param $floatString A string holding a float expression
3114 * @return $float Corresponding float variable
3115 * @author chris<at>georgakopoulos<dot>com
3116 * @link http://de.php.net/manual/en/function.floatval.php#92563
3118 function parseFloat ($floatString){
3120 $LocaleInfo = localeconv();
3122 // Remove thousand separators
3123 $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
3125 // Convert decimal point
3126 $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
3128 // Return float value of converted string
3129 return floatval($floatString);
3133 * Searches a multi-dimensional array (as used in many places) for given
3134 * key/value pair as taken from user comments from PHP documentation website.
3136 * @param $array An array with one or more dimensions
3137 * @param $key Key to look for
3138 * @param $value Value to look for
3139 * @param $parentIndex Parent index (ONLY INTERNAL USE!)
3140 * @return $results Resulted array or empty array if $array is no array
3141 * @author sunelbe<at>gmail<dot>com
3142 * @link http://de.php.net/manual/en/function.array-search.php#110120
3144 function search_array ($array, $key, $value, $parentIndex = NULL) {
3145 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
3146 // Init array result
3149 // Is $array really an array?
3150 if (is_array($array)) {
3151 // Search for whole array
3152 foreach ($array as $idx => $dummy) {
3153 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex);
3154 //* DEBUG: */ print 'idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',key=' . $key . ',value=' . $value . ',array=<pre>'.print_r($array, TRUE).'</pre>';
3155 // Is dummy an array?
3156 if ((is_array($dummy)) && ((is_null($parentIndex)) || ($parentIndex === $value))) {
3157 // Then search again
3158 $subResult = search_array($dummy, $key, $value, $idx);
3159 //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
3162 $results = merge_array($results, $subResult, TRUE);
3163 } elseif (($key == $idx) && (isset($array[$key])) && ($array[$key] === $value)) {
3164 // Is found, so add it
3165 $results[$parentIndex] = $array;
3166 //* DEBUG: */ print 'ARRAY: key=' . $key . ',idx=' . $idx . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',array=<pre>' . print_r($array, TRUE).'</pre>';
3171 // Return resulting array
3172 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
3176 // Generates a YES/NO option list from given default
3177 function generateYesNoOptions ($defaultValue = '') {
3179 return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
3182 // "Getter" for total available receivers
3183 function getTotalReceivers ($mode = 'normal') {
3185 $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
3191 // Wrapper "getter" to get total unconfirmed mails for given userid
3192 function getTotalUnconfirmedMails ($userid) {
3194 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
3196 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
3200 return $GLOBALS[__FUNCTION__][$userid];
3203 // Checks whether 'mailer_theme' was found in session
3204 function isMailerThemeSet () {
3206 if (!isset($GLOBALS[__FUNCTION__])) {
3208 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
3212 return $GLOBALS[__FUNCTION__];
3216 * Setter for theme in session (This setter does return the success of
3217 * setSession() which is required e.g. for destroySponsorSession().
3219 function setMailerTheme ($newTheme) {
3220 // Set it in session
3221 return setSession('mailer_theme', $newTheme);
3225 * Getter for theme from session (This getter does return 'mailer_theme' from
3226 * session data or throws an error if not possible
3228 function getMailerTheme () {
3230 if (!isset($GLOBALS[__FUNCTION__])) {
3231 // Is 'mailer_theme' set?
3232 if (!isMailerThemeSet()) {
3233 // No, then abort here
3234 reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
3237 // Get it and store it in cache
3238 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
3242 return $GLOBALS[__FUNCTION__];
3245 // "Getter" for last_module/last_what depending on ext-user version
3246 function getUserLastWhatName () {
3247 // Default is old one: last_module
3248 $columnName = 'last_module';
3250 // Is ext-user up-to-date?
3251 if (isExtensionInstalledAndNewer('user', '0.4.9')) {
3252 // Yes, then use new one
3253 $columnName = 'last_what';
3260 // "Getter" for all columns for given alias and separator
3261 function getAllPointColumns ($alias = NULL, $separator = ',') {
3262 // Prepare the filter array
3263 $filterData = array(
3266 'separator' => $separator
3270 $filterData = runFilterChain('get_all_point_columns', $filterData);
3272 // Return the columns
3273 return $filterData['columns'];
3276 // Checks whether the copyright footer (which breaks framesets) is enabled
3277 function ifCopyrightFooterEnabled () {
3278 // Is not unset and not 'N'?
3279 return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
3283 * Wrapper to check whether we have a "full page". This means that the actual
3284 * content is not delivered in any frame of a frameset.
3286 function isFullPage () {
3288 * The parameter 'frame' is generic and always indicates that this content
3289 * will be output into a frame. Furthermore, if a frameset is reported or
3290 * the copyright line is explicitly deactivated, this cannot be a "full
3293 // @TODO Find a way to not use direct module comparison
3294 $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
3300 // Checks whether frameset_mode is set to true
3301 function isFramesetModeEnabled () {
3303 return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
3306 // Function to determine correct 'what' value
3307 function determineWhat ($module = NULL) {
3308 // Init default 'what'
3312 if (is_null($module)) {
3314 $module = getModule();
3322 // Else try to get it from current module
3323 $what = getWhatFromModule($module);
3325 //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
3327 // Remove any spaces from variable
3328 $what = trim($what);
3332 // Default action for non-admin menus
3336 $what = secureString($what);
3343 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3344 function prependZeros ($str, $length = 2) {
3345 // Return prepended string
3346 return sprintf('%0' . (int) $length . 's', $str);
3349 // Wraps convertSelectionsToEpocheTime()
3350 function convertSelectionsToEpocheTimeInPostData ($id) {
3355 // Get all POST data
3356 $postData = postRequestArray();
3358 // Convert given selection id
3359 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3361 // Set the POST array back
3362 setPostRequestArray($postData);
3365 // Wraps checking if given points account type matches with given in POST data
3366 function ifPointsAccountTypeMatchesPost ($type) {
3368 exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
3371 // Gets given user's total referral
3372 function getUsersTotalReferrals ($userid, $level = NULL) {
3374 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3375 // Is the level NULL?
3376 if (is_null($level)) {
3377 // Get total amount (all levels)
3378 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
3380 // Get it from user refs
3381 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
3386 return $GLOBALS[__FUNCTION__][$userid][$level];
3389 // Gets given user's total referral
3390 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3391 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3393 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3394 // Default is all refs
3397 // Is the not level NULL?
3398 if (!is_null($level)) {
3399 // Then add referral level
3400 $add = ' AND `r`.`level`=' . bigintval($level);
3403 // Check for all referrals
3404 $result = sqlQueryEscaped("SELECT
3405 COUNT(`d`.`userid`) AS `cnt`
3407 `{?_MYSQL_PREFIX?}_user_data` AS `d`
3409 `{?_MYSQL_PREFIX?}_user_refs` AS `r`
3411 `d`.`userid`=`r`.`refid`
3413 `d`.`status` != 'CONFIRMED' AND
3421 ), __FUNCTION__, __LINE__);
3424 list($GLOBALS[__FUNCTION__][$userid][$level]) = sqlFetchRow($result);
3427 sqlFreeResult($result);
3431 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3432 return $GLOBALS[__FUNCTION__][$userid][$level];
3435 // Converts, if found, dollar data to get element
3436 function convertDollarDataToGetElement ($data) {
3437 // Is first char a dollar?
3438 if (substr($data, 0, 1) == chr(36)) {
3439 // Use last part for getRequestElement()
3440 $data = getRequestElement(substr($data, 1));
3447 // Wrapper function for SQL layer to speed-up things
3448 function isSqlDebugEnabled () {
3450 if (!isset($GLOBALS[__FUNCTION__])) {
3452 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3456 return $GLOBALS[__FUNCTION__];
3459 // Wrapper function to wrap call of wordwrap()
3460 function wrapWords ($text) {
3462 $wrapped = wordwrap($test, getWordWrap());
3468 // Encodes given data into a JSON object
3469 function encodeJson ($data) {
3471 return json_encode($data, JSON_FORCE_OBJECT);
3474 // Get all extension files
3475 function loadAllExtensionsByTemplate () {
3477 $extensions = getArrayFromDirectory(
3478 'templates/' . getLanguage() . '/html/ext/',
3492 // Wrapper function to allow full float values as supported by current database layout
3493 function translateFullComma ($dotted) {
3494 // Call inner function
3495 return translateComma($dotted, TRUE, 5);
3498 // Wrapper to check if the first element to be shifted is set to given value
3499 function shift_array (&$array, $value, $key = '0') {
3500 // Is the element set and value matches?
3501 assert(is_array($array));
3502 assert(isset($array[$key]));
3503 assert($array[$key] === $value);
3506 array_shift($array);
3509 // Wrapper for str_pad() with left padding zeros
3510 function padLeftZero ($str, $amount = 2) {
3511 // Is str_pad() there?
3512 if (!function_exists('str_pad')) {
3513 // Use prependZeros()
3514 return prependZeros($str, $amount);
3517 return str_pad($str, $amount, '0', STR_PAD_LEFT);
3521 // Calculates percentage
3522 function calculatePercentageRate ($current, $total) {
3526 // Is sent larger zero? (Prevents division-by-zero)
3528 // Calculate it (it should be "translated" alter on)
3529 $rate = ($current / $total * 100);
3532 // The should be a .0 at the end?
3533 if (strpos($rate, '.') === FALSE) {
3542 // Checks whether an array is filled with entries
3543 function isFilledArray ($array) {
3545 return ((is_array($array)) && (count($array) > 0));
3548 // Checks whether this script runs on a developer system (called with localhost/127.0.0.1 SERVER_NAME)
3549 function isDeveloperSystem () {
3551 return in_array(detectServerName(), array('localhost', 'daedalus', '127.0.0.1'));
3554 // Checks whether given subject line has '_ref' suffix
3555 function ifSubjectHasReferralSuffix ($subject) {
3557 if (!isset($GLOBALS[__FUNCTION__][$subject])) {
3559 $GLOBALS[__FUNCTION__][$subject] = (substr($subject, -4, 4) == '_ref');
3563 return $GLOBALS[__FUNCTION__][$subject];
3566 // Converts an API response to an associative array
3567 function convertApiResponseToArray ($responseString, $keyDelimiter, $valueDelimiter) {
3568 // Explode for key delimiter
3569 $keys = explode($keyDelimiter, $responseString);
3571 // Init returned array and "walk" through all entries
3572 $returned = array();
3573 foreach ($keys as $keyValue) {
3575 $parts = explode($valueDelimiter, $keyValue);
3578 assert(count($parts) == 2);
3580 // Then add both: 0=key, 1=value
3581 $returned[sqlEscapeString($parts[0])] = sqlEscapeString($parts[1]);
3584 // Return finished array
3588 // Getter for full (generic) hash file name
3589 function getGenericHashFileName () {
3591 return sprintf('%s%s.%s%s', getPath(), getCachePath(), getFileHash(), getCacheExtension());
3594 // "Compiles" the given value and sets it in given key
3595 function setSessionCompiled ($key, $value) {
3597 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key[]=' . gettype($key) . ',value[]=' . gettype($value));
3599 // Is the value not an array?
3600 if (!is_array($value)) {
3601 // "Compile" the value
3602 $value = doFinalCompilation(compileRawCode($value));
3606 return setSession($key, $value);