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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
44 function readFromFile ($FQFN) {
45 // Sanity-check if file is there (should be there, but just to make it sure)
46 if (!isFileReadable($FQFN)) {
47 // This should not happen
48 reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!');
49 } elseif (!isset($GLOBALS['file_content'][$FQFN])) {
51 if (function_exists('file_get_contents')) {
53 $GLOBALS['file_content'][$FQFN] = file_get_contents($FQFN);
55 // Fall-back to implode-file chain
56 $GLOBALS['file_content'][$FQFN] = implode('', file($FQFN));
61 return $GLOBALS['file_content'][$FQFN];
64 // Writes content to a file
65 function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
66 // Is the file writeable?
67 if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
69 logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN)));
75 // By default all is failed...
76 $GLOBALS['file_readable'][$FQFN] = FALSE;
77 unset($GLOBALS['file_content'][$FQFN]);
80 // Is the function there?
81 if (function_exists('file_put_contents')) {
83 if ($aquireLock === TRUE) {
84 // Write it directly with lock
85 $return = file_put_contents($FQFN, $content, LOCK_EX);
88 $return = file_put_contents($FQFN, $content);
91 // Write it with fopen
92 $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
95 if ($aquireLock === TRUE) {
101 $return = fwrite($fp, $content);
107 // Was something written?
108 if ($return !== FALSE) {
109 // Mark it as readable
110 $GLOBALS['file_readable'][$FQFN] = TRUE;
112 // Remember content in cache
113 $GLOBALS['file_content'][$FQFN] = $content;
117 return (($return !== FALSE) && (changeMode($FQFN, 0644)));
120 // Clears the output buffer. This function does *NOT* backup sent content.
121 function clearOutputBuffer () {
122 // Make sure this function is not called twice (no double-cleaning!)
123 if (isset($GLOBALS[__FUNCTION__])) {
124 // This function is called twice
125 reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.');
128 // Trigger an error on failure
129 if ((ob_get_length() > 0) && (!ob_end_clean())) {
131 reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
134 // Mark this function as called
135 $GLOBALS[__FUNCTION__] = TRUE;
139 function encodeString ($str) {
140 $str = urlencode(base64_encode(compileUriCode($str)));
144 // Decode strings encoded with encodeString()
145 function decodeString ($str) {
146 $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
150 // Decode entities in a nicer way
151 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
152 // Decode the entities to UTF-8 now
153 $decodedString = html_entity_decode($str, $quote, 'UTF-8');
155 // Return decoded string
156 return $decodedString;
159 // Merges an array together but only if both are arrays
160 function merge_array ($array1, $array2) {
161 // Are both an array?
162 if ((!is_array($array1)) && (!is_array($array2))) {
163 // Both are not arrays
164 reportBug(__FUNCTION__, __LINE__, 'No arrays provided!');
165 } elseif (!is_array($array1)) {
166 // Left one is not an array
167 reportBug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
168 } elseif (!is_array($array2)) {
169 // Right one is not an array
170 reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
173 // Merge both together
174 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)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
201 return $GLOBALS[__FUNCTION__][$FQFN];
204 // "Getter" for the real remote IP number
205 function detectRealIpAddress () {
206 // Get remote ip from environment
207 $remoteAddr = determineRealRemoteAddress();
209 // Is removeip installed?
210 if (isExtensionActive('removeip')) {
212 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
219 // "Getter" for remote IP number
220 function detectRemoteAddr () {
221 // Get remote ip from environment
222 $remoteAddr = determineRealRemoteAddress(TRUE);
224 // Is removeip installed?
225 if (isExtensionActive('removeip')) {
227 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
234 // "Getter" for remote hostname
235 function detectRemoteHostname () {
236 // Get remote ip from environment
237 $remoteHost = getenv('REMOTE_HOST');
239 // Is removeip installed?
240 if (isExtensionActive('removeip')) {
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 () {
266 // Get remote ip from environment
267 $referer = getenv('HTTP_REFERER');
269 // Is removeip installed?
270 if (isExtensionActive('removeip')) {
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');
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('MXCHANGE_INSTALLED')
342 getConfig('MXCHANGE_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 reset mode is active
387 function isResetModeEnabled () {
388 // Now simply check it
389 return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === TRUE));
392 // Checks whether the debug mode is enabled
393 function isDebugModeEnabled () {
395 if (!isset($GLOBALS[__FUNCTION__])) {
397 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
401 return $GLOBALS[__FUNCTION__];
404 // Checks whether the debug reset is enabled
405 function isDebugResetEnabled () {
407 if (!isset($GLOBALS[__FUNCTION__])) {
409 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
413 return $GLOBALS[__FUNCTION__];
416 // Checks whether SQL debugging is enabled
417 function isSqlDebuggingEnabled () {
419 if (!isset($GLOBALS[__FUNCTION__])) {
420 // Determine if SQL debugging is enabled
421 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
425 return $GLOBALS[__FUNCTION__];
428 // Checks whether we shall debug regular expressions
429 function isDebugRegularExpressionEnabled () {
431 if (!isset($GLOBALS[__FUNCTION__])) {
433 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
437 return $GLOBALS[__FUNCTION__];
440 // Checks whether the cache instance is valid
441 function isCacheInstanceValid () {
443 if (!isset($GLOBALS[__FUNCTION__])) {
445 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
449 return $GLOBALS[__FUNCTION__];
452 // Copies a file from source to destination and verifies if that goes fine.
453 // This function should wrap the copy() command and make a nicer debug backtrace
454 // even if there is no xdebug extension installed.
455 function copyFileVerified ($source, $dest, $chmod = '') {
456 // Failed is the default
459 // Is the source file there?
460 if (!isFileReadable($source)) {
462 reportBug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
465 // Is the target directory there?
466 if (!isDirectory(dirname($dest))) {
468 reportBug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
471 // Now try to copy it
472 if (!copy($source, $dest)) {
473 // Something went wrong
474 reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
477 $GLOBALS['file_readable'][$dest] = TRUE;
480 // All fine by default
483 // If there are chmod rights set, apply them
484 if (!empty($chmod)) {
486 $status = changeMode($dest, $chmod);
493 // Wrapper function for chmod()
494 // @TODO Do some more sanity check here
495 function changeMode ($FQFN, $mode) {
496 // Is the file/directory there?
497 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
498 // Neither, so abort here
499 reportBug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
503 return chmod($FQFN, $mode);
506 // Wrapper for unlink()
507 function removeFile ($FQFN) {
508 // Is the file there?
509 if (isFileReadable($FQFN)) {
511 $GLOBALS['file_readable'][$FQFN] = FALSE;
514 return unlink($FQFN);
517 // All fine if no file was removed. If we change this to 'false' or rewrite
518 // above if() block it would be to restrictive.
522 // Wrapper for $_POST['sel']
523 function countPostSelection ($element = 'sel') {
525 if (!isset($GLOBALS[__FUNCTION__][$element])) {
527 $GLOBALS[__FUNCTION__][$element] = '0';
530 if (isPostRequestElementSet($element)) {
531 // Return counted elements
532 $GLOBALS[__FUNCTION__][$element] = countSelection(postRequestElement($element));
536 // Return cached value
537 return $GLOBALS[__FUNCTION__][$element];
540 // Checks whether the config-local.php is loaded
541 function isConfigLocalLoaded () {
542 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === TRUE));
545 // Checks whether a nickname or userid was entered and caches the result
546 function isNicknameUsed ($userid) {
547 // Is the cache there
548 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
550 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL'));
554 return $GLOBALS[__FUNCTION__][$userid];
557 // Getter for 'what' value
558 function getWhat ($strict = TRUE) {
563 if (isWhatSet($strict)) {
565 $what = $GLOBALS['__what'];
572 // Setter for 'what' value
573 function setWhat ($newWhat) {
574 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat);
575 $GLOBALS['__what'] = $newWhat;
578 // Setter for 'what' from configuration
579 function setWhatFromConfig ($configEntry) {
580 // Get 'what' from config
581 $what = getConfig($configEntry);
587 // Checks whether what is set and optionally aborts on miss
588 function isWhatSet ($strict = false) {
590 $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
592 // Should we abort here?
593 if (($strict === TRUE) && ($isset === FALSE)) {
595 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
602 // Getter for 'action' value
603 function getAction ($strict = TRUE) {
608 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
610 $action = $GLOBALS['__action'];
617 // Setter for 'action' value
618 function setAction ($newAction) {
619 $GLOBALS['__action'] = $newAction;
622 // Checks whether action is set and optionally aborts on miss
623 function isActionSet ($strict = false) {
625 $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
627 // Should we abort here?
628 if (($strict === TRUE) && ($isset === FALSE)) {
630 reportBug(__FUNCTION__, __LINE__, 'action is empty.');
637 // Getter for 'module' value
638 function getModule ($strict = TRUE) {
643 if (isModuleSet($strict)) {
645 $module = $GLOBALS['__module'];
652 // Setter for 'module' value
653 function setModule ($newModule) {
654 // Secure it and make all modules lower-case
655 $GLOBALS['__module'] = strtolower($newModule);
658 // Checks whether module is set and optionally aborts on miss
659 function isModuleSet ($strict = false) {
661 $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
663 // Should we abort here?
664 if (($strict === TRUE) && ($isset === FALSE)) {
666 reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
670 return (($isset === TRUE) && ($GLOBALS['__module'] != 'unknown')) ;
673 // Getter for 'output_mode' value
674 function getScriptOutputMode () {
676 if (!isset($GLOBALS[__FUNCTION__])) {
677 // Is the output mode set?
678 if (!isOutputModeSet()) {
679 // No, then abort here
680 reportBug(__FUNCTION__, __LINE__, 'Output mode not set.');
684 $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode'];
688 return $GLOBALS[__FUNCTION__];
691 // Setter for 'output_mode' value
692 function setOutputMode ($newOutputMode) {
693 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
694 $GLOBALS['__output_mode'] = (int) $newOutputMode;
697 // Checks whether output_mode is set and optionally aborts on miss
698 function isOutputModeSet ($strict = false) {
700 $isset = (isset($GLOBALS['__output_mode']));
702 // Should we abort here?
703 if (($strict === TRUE) && ($isset === FALSE)) {
705 reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
712 // Enables block-mode
713 function enableBlockMode ($enabled = TRUE) {
714 $GLOBALS['__block_mode'] = $enabled;
717 // Checks whether block-mode is enabled
718 function isBlockModeEnabled () {
720 if (!isset($GLOBALS['__block_mode'])) {
722 reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
726 return $GLOBALS['__block_mode'];
729 // Wrapper for redirectToUrl but URL comes from a configuration entry
730 function redirectToConfiguredUrl ($configEntry) {
732 redirectToUrl(getConfig($configEntry));
735 // Wrapper function to redirect from member-only modules to index
736 function redirectToIndexMemberOnlyModule () {
737 // Do the redirect here
738 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
741 // Wrapper function to redirect to current URL
742 function redirectToRequestUri () {
743 redirectToUrl(basename(detectRequestUri()));
746 // Wrapper function to redirect to de-refered URL
747 function redirectToDereferedUrl ($url) {
749 redirectToUrl(generateDereferrerUrl($url));
752 // Wrapper function for checking if extension is installed and newer or same version
753 function isExtensionInstalledAndNewer ($ext_name, $version) {
754 // Is an cache entry found?
755 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
757 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
759 // Cache hits should be incremented twice
760 incrementStatsEntry('cache_hits', 2);
764 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
765 return $GLOBALS[__FUNCTION__][$ext_name][$version];
768 // Wrapper function for checking if extension is installed and older than given version
769 function isExtensionInstalledAndOlder ($ext_name, $version) {
770 // Is an cache entry found?
771 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
773 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
775 // Cache hits should be incremented twice
776 incrementStatsEntry('cache_hits', 2);
780 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
781 return $GLOBALS[__FUNCTION__][$ext_name][$version];
785 function setUsername ($userName) {
786 $GLOBALS['username'] = (string) $userName;
790 function getUsername () {
792 if (!isset($GLOBALS['username'])) {
793 // No, so it has to be a guest
794 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
798 return $GLOBALS['username'];
801 // Wrapper function for installation phase
802 function isInstallationPhase () {
804 if (!isset($GLOBALS[__FUNCTION__])) {
806 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
810 return $GLOBALS[__FUNCTION__];
813 // Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
814 function isDemoModeActive () {
816 if (!isset($GLOBALS[__FUNCTION__])) {
818 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
822 return $GLOBALS[__FUNCTION__];
825 // Getter for PHP caching value
826 function getPhpCaching () {
827 return $GLOBALS['php_caching'];
830 // Checks whether the admin hash is set
831 function isAdminHashSet ($adminId) {
832 // Is the array there?
833 if (!isset($GLOBALS['cache_array']['admin'])) {
834 // Missing array should be reported
835 reportBug(__FUNCTION__, __LINE__, 'Cache not set.');
838 // Check for admin hash
839 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
842 // Setter for admin hash
843 function setAdminHash ($adminId, $hash) {
844 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
847 // Getter for current admin login
848 function getCurrentAdminLogin () {
850 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
853 if (!isset($GLOBALS[__FUNCTION__])) {
855 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
859 return $GLOBALS[__FUNCTION__];
862 // Setter for admin id (and current)
863 function setAdminId ($adminId) {
865 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
868 $status = setSession('admin_id', bigintval($adminId));
871 setCurrentAdminId($adminId);
877 // Setter for admin_last
878 function setAdminLast ($adminLast) {
880 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
883 $status = setSession('admin_last', $adminLast);
889 // Setter for admin_md5
890 function setAdminMd5 ($adminMd5) {
892 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
895 $status = setSession('admin_md5', $adminMd5);
901 // Getter for admin_md5
902 function getAdminMd5 () {
904 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
907 return getSession('admin_md5');
910 // Init user data array
911 function initUserData () {
912 // User id should not be zero
913 if (!isValidUserId(getCurrentUserId())) {
914 // Should be always valid
915 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
919 unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
920 $GLOBALS['user_data'][getCurrentUserId()] = array();
923 // Getter for user data
924 function getUserData ($column) {
925 // User id should not be zero
926 if (!isValidUserId(getCurrentUserId())) {
927 // Should be always valid
928 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
934 if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
936 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
943 // Checks whether given user data is set to 'Y'
944 function isUserDataEnabled ($column) {
946 if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
948 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
952 return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
955 // Geter for whole user data array
956 function getUserDataArray () {
958 $userid = getCurrentUserId();
960 // Is the current userid valid?
961 if (!isValidUserId($userid)) {
962 // Should be always valid
963 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
966 // Get the whole array if found
967 if (isset($GLOBALS['user_data'][$userid])) {
968 // Found, so return it
969 return $GLOBALS['user_data'][$userid];
971 // Return empty array
976 // Checks if the user data is valid, this may indicate that the user has logged
977 // in, but you should use isMember() if you want to find that out.
978 function isUserDataValid () {
979 // User id should not be zero so abort here
980 if (!isCurrentUserIdSet()) {
981 // Debug message, may be noisy
982 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
989 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
991 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
995 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
998 // Setter for current userid
999 function setCurrentUserId ($userid) {
1001 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - ENTERED!');
1003 // Is the cache from below functions different?
1004 if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) {
1006 unsetCurrentUserId();
1010 $GLOBALS['current_userid'] = bigintval($userid);
1012 // Unset it to re-determine the actual state
1013 unset($GLOBALS['is_userdata_valid'][$userid]);
1016 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - EXIT!');
1019 // Getter for current userid
1020 function getCurrentUserId () {
1022 if (!isset($GLOBALS[__FUNCTION__])) {
1023 // Userid must be set before it can be used
1024 if (!isCurrentUserIdSet()) {
1026 reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1029 // Set userid in cache
1030 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1034 return $GLOBALS[__FUNCTION__];
1037 // Checks if current userid is set
1038 function isCurrentUserIdSet () {
1040 if (!isset($GLOBALS[__FUNCTION__])) {
1042 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1046 return $GLOBALS[__FUNCTION__];
1049 // Unsets current userid
1050 function unsetCurrentUserId () {
1052 if (isset($GLOBALS['current_userid'])) {
1054 unset($GLOBALS['isValidUserId'][$GLOBALS['current_userid']]);
1057 // Unset all cache entries
1058 unset($GLOBALS['current_userid']);
1059 unset($GLOBALS['getCurrentUserId']);
1060 unset($GLOBALS['isCurrentUserIdSet']);
1063 // Checks whether we are debugging template cache
1064 function isDebuggingTemplateCache () {
1066 if (!isset($GLOBALS[__FUNCTION__])) {
1068 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1072 return $GLOBALS[__FUNCTION__];
1075 // Wrapper for fetchUserData() and getUserData() calls
1076 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1077 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1079 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1083 // Can we fetch the user data?
1084 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1085 // Now get the data back
1086 $data = getUserData($valueColumn);
1090 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1094 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1095 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1098 // Wrapper for strpos() to ease porting from deprecated ereg() function
1099 function isInString ($needle, $haystack) {
1100 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== FALSE));
1101 return (strpos($haystack, $needle) !== FALSE);
1104 // Wrapper for strpos() to ease porting from deprecated eregi() function
1105 // This function is case-insensitive
1106 function isInStringIgnoreCase ($needle, $haystack) {
1107 return (isInString(strtolower($needle), strtolower($haystack)));
1110 // Wrapper to check for if fatal errors where detected
1111 function ifFatalErrorsDetected () {
1112 // Just call the inner function
1113 return (getTotalFatalErrors() > 0);
1116 // Checks whether a HTTP status has been set
1117 function isHttpStatusSet () {
1118 // Is it set and not empty?
1119 return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1122 // Setter for HTTP status
1123 function setHttpStatus ($status) {
1124 $GLOBALS['http_status'] = (string) $status;
1127 // Getter for HTTP status
1128 function getHttpStatus () {
1129 // Is the status set?
1130 if (!isHttpStatusSet()) {
1132 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1136 return $GLOBALS['http_status'];
1140 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1141 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1143 * ----------------------------------------------------------------------------
1144 * If you want to redirect, please use redirectToUrl(); instead
1145 * ----------------------------------------------------------------------------
1147 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1149 * @link http://support.microsoft.com/kb/q176113/
1150 * @author Andreas Gohr <andi@splitbrain.org>
1153 function sendRawRedirect ($url) {
1154 // Clear output buffer
1155 clearOutputBuffer();
1157 // Clear own output buffer
1158 $GLOBALS['__output'] = '';
1160 // To make redirects working (no content type), output mode must be raw
1163 // Send helping header
1164 setHttpStatus('302 Found');
1166 // always close the session
1167 session_write_close();
1169 // Revert entity &
1170 $url = str_replace('&', '&', $url);
1172 // check if running on IIS < 6 with CGI-PHP
1173 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1174 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1175 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1176 ($matches[1] < 6)) {
1177 // Send the IIS header
1178 addHttpHeader('Refresh: 0;url=' . $url);
1180 // Send generic header
1181 addHttpHeader('Location: ' . $url);
1188 // Determines the country of the given user id
1189 function determineCountry ($userid) {
1191 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1192 // Default is 'invalid'
1193 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1195 // Is extension country active?
1196 if (isExtensionActive('country')) {
1197 // Determine the right country code through the country id
1198 $id = getUserData('country_code');
1200 // Then handle it over
1201 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1203 // Get raw code from user data
1204 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1209 return $GLOBALS[__FUNCTION__][$userid];
1212 // "Getter" for total confirmed user accounts
1213 function getTotalConfirmedUser () {
1215 if (!isset($GLOBALS[__FUNCTION__])) {
1217 if (isExtensionActive('user')) {
1218 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1220 $GLOBALS[__FUNCTION__] = 0;
1224 // Return cached value
1225 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1226 return $GLOBALS[__FUNCTION__];
1229 // "Getter" for total unconfirmed user accounts
1230 function getTotalUnconfirmedUser () {
1232 if (!isset($GLOBALS[__FUNCTION__])) {
1234 if (isExtensionActive('user')) {
1235 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1237 $GLOBALS[__FUNCTION__] = 0;
1241 // Return cached value
1242 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1243 return $GLOBALS[__FUNCTION__];
1246 // "Getter" for total locked user accounts
1247 function getTotalLockedUser () {
1249 if (!isset($GLOBALS[__FUNCTION__])) {
1251 if (isExtensionActive('user')) {
1252 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1254 $GLOBALS[__FUNCTION__] = 0;
1258 // Return cached value
1259 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1260 return $GLOBALS[__FUNCTION__];
1263 // "Getter" for total locked user accounts
1264 function getTotalRandomRefidUser () {
1266 if (!isset($GLOBALS[__FUNCTION__])) {
1268 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1269 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
1271 $GLOBALS[__FUNCTION__] = 0;
1275 // Return cached value
1276 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1277 return $GLOBALS[__FUNCTION__];
1280 // Is given userid valid?
1281 function isValidUserId ($userid) {
1283 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid);
1286 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1288 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1292 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',result=' . intval($GLOBALS[__FUNCTION__][$userid]));
1293 return $GLOBALS[__FUNCTION__][$userid];
1297 function encodeEntities ($str) {
1299 $str = secureString($str, TRUE, TRUE);
1301 // Encode dollar sign as well
1302 $str = str_replace('$', '$', $str);
1308 // "Getter" for date from patch_ctime
1309 function getDateFromRepository () {
1311 if (!isset($GLOBALS[__FUNCTION__])) {
1313 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1317 return $GLOBALS[__FUNCTION__];
1320 // "Getter" for date/time from patch_ctime
1321 function getDateTimeFromRepository () {
1323 if (!isset($GLOBALS[__FUNCTION__])) {
1325 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1329 return $GLOBALS[__FUNCTION__];
1332 // Getter for current year (default)
1333 function getYear ($timestamp = NULL) {
1335 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1337 if (is_null($timestamp)) {
1338 $timestamp = time();
1342 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1346 return $GLOBALS[__FUNCTION__][$timestamp];
1349 // Getter for current month (default)
1350 function getMonth ($timestamp = NULL) {
1352 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1353 // If null is set, use time()
1354 if (is_null($timestamp)) {
1355 // Use time() which is current timestamp
1356 $timestamp = time();
1360 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1364 return $GLOBALS[__FUNCTION__][$timestamp];
1367 // Getter for current hour (default)
1368 function getHour ($timestamp = NULL) {
1370 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1372 if (is_null($timestamp)) {
1373 $timestamp = time();
1377 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1381 return $GLOBALS[__FUNCTION__][$timestamp];
1384 // Getter for current day (default)
1385 function getDay ($timestamp = NULL) {
1387 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1389 if (is_null($timestamp)) {
1390 $timestamp = time();
1394 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1398 return $GLOBALS[__FUNCTION__][$timestamp];
1401 // Getter for current week (default)
1402 function getWeek ($timestamp = NULL) {
1404 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1406 if (is_null($timestamp)) $timestamp = time();
1409 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1413 return $GLOBALS[__FUNCTION__][$timestamp];
1416 // Getter for current short_hour (default)
1417 function getShortHour ($timestamp = NULL) {
1419 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1421 if (is_null($timestamp)) $timestamp = time();
1424 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1428 return $GLOBALS[__FUNCTION__][$timestamp];
1431 // Getter for current long_hour (default)
1432 function getLongHour ($timestamp = NULL) {
1434 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1436 if (is_null($timestamp)) $timestamp = time();
1439 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1443 return $GLOBALS[__FUNCTION__][$timestamp];
1446 // Getter for current second (default)
1447 function getSecond ($timestamp = NULL) {
1449 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1451 if (is_null($timestamp)) $timestamp = time();
1454 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1458 return $GLOBALS[__FUNCTION__][$timestamp];
1461 // Getter for current minute (default)
1462 function getMinute ($timestamp = NULL) {
1464 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1466 if (is_null($timestamp)) $timestamp = time();
1469 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1473 return $GLOBALS[__FUNCTION__][$timestamp];
1476 // Checks whether the title decoration is enabled
1477 function isTitleDecorationEnabled () {
1479 if (!isset($GLOBALS[__FUNCTION__])) {
1481 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1485 return $GLOBALS[__FUNCTION__];
1488 // Checks whether filter usage updates are enabled (expensive queries!)
1489 function isFilterUsageUpdateEnabled () {
1491 if (!isset($GLOBALS[__FUNCTION__])) {
1493 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1497 return $GLOBALS[__FUNCTION__];
1500 // Checks whether debugging of weekly resets is enabled
1501 function isWeeklyResetDebugEnabled () {
1503 if (!isset($GLOBALS[__FUNCTION__])) {
1505 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1509 return $GLOBALS[__FUNCTION__];
1512 // Checks whether debugging of monthly resets is enabled
1513 function isMonthlyResetDebugEnabled () {
1515 if (!isset($GLOBALS[__FUNCTION__])) {
1517 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1521 return $GLOBALS[__FUNCTION__];
1524 // Checks whether displaying of debug SQLs are enabled
1525 function isDisplayDebugSqlEnabled () {
1527 if (!isset($GLOBALS[__FUNCTION__])) {
1529 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1533 return $GLOBALS[__FUNCTION__];
1536 // Checks whether module title is enabled
1537 function isModuleTitleEnabled () {
1539 if (!isset($GLOBALS[__FUNCTION__])) {
1541 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1545 return $GLOBALS[__FUNCTION__];
1548 // Checks whether what title is enabled
1549 function isWhatTitleEnabled () {
1551 if (!isset($GLOBALS[__FUNCTION__])) {
1553 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1557 return $GLOBALS[__FUNCTION__];
1560 // Checks whether stats are enabled
1561 function ifInternalStatsEnabled () {
1563 if (!isset($GLOBALS[__FUNCTION__])) {
1564 // Then determine it
1565 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1568 // Return cached value
1569 return $GLOBALS[__FUNCTION__];
1572 // Checks whether admin-notification of certain user actions is enabled
1573 function isAdminNotificationEnabled () {
1575 if (!isset($GLOBALS[__FUNCTION__])) {
1577 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1581 return $GLOBALS[__FUNCTION__];
1584 // Checks whether random referral id selection is enabled
1585 function isRandomReferralIdEnabled () {
1587 if (!isset($GLOBALS[__FUNCTION__])) {
1589 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1593 return $GLOBALS[__FUNCTION__];
1596 // "Getter" for default language
1597 function getDefaultLanguage () {
1599 if (!isset($GLOBALS[__FUNCTION__])) {
1601 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1605 return $GLOBALS[__FUNCTION__];
1608 // "Getter" for default referral id
1609 function getDefRefid () {
1611 if (!isset($GLOBALS[__FUNCTION__])) {
1613 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1617 return $GLOBALS[__FUNCTION__];
1620 // "Getter" for path
1621 function getPath () {
1623 if (!isset($GLOBALS[__FUNCTION__])) {
1625 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1629 return $GLOBALS[__FUNCTION__];
1633 function getUrl () {
1635 if (!isset($GLOBALS[__FUNCTION__])) {
1637 $GLOBALS[__FUNCTION__] = getConfig('URL');
1641 return $GLOBALS[__FUNCTION__];
1644 // "Getter" for cache_path
1645 function getCachePath () {
1647 if (!isset($GLOBALS[__FUNCTION__])) {
1649 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1653 return $GLOBALS[__FUNCTION__];
1656 // "Getter" for secret_key
1657 function getSecretKey () {
1659 if (!isset($GLOBALS[__FUNCTION__])) {
1661 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1665 return $GLOBALS[__FUNCTION__];
1668 // "Getter" for SITE_KEY
1669 function getSiteKey () {
1671 if (!isset($GLOBALS[__FUNCTION__])) {
1673 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1677 return $GLOBALS[__FUNCTION__];
1680 // "Getter" for DATE_KEY
1681 function getDateKey () {
1683 if (!isset($GLOBALS[__FUNCTION__])) {
1685 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1689 return $GLOBALS[__FUNCTION__];
1692 // "Getter" for master_salt
1693 function getMasterSalt () {
1695 if (!isset($GLOBALS[__FUNCTION__])) {
1697 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1701 return $GLOBALS[__FUNCTION__];
1704 // "Getter" for prime
1705 function getPrime () {
1707 if (!isset($GLOBALS[__FUNCTION__])) {
1709 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1713 return $GLOBALS[__FUNCTION__];
1716 // "Getter" for encrypt_separator
1717 function getEncryptSeparator () {
1719 if (!isset($GLOBALS[__FUNCTION__])) {
1721 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1725 return $GLOBALS[__FUNCTION__];
1728 // "Getter" for mysql_prefix
1729 function getMysqlPrefix () {
1731 if (!isset($GLOBALS[__FUNCTION__])) {
1733 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1737 return $GLOBALS[__FUNCTION__];
1740 // "Getter" for table_type
1741 function getTableType () {
1743 if (!isset($GLOBALS[__FUNCTION__])) {
1745 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1749 return $GLOBALS[__FUNCTION__];
1752 // "Getter" for salt_length
1753 function getSaltLength () {
1755 if (!isset($GLOBALS[__FUNCTION__])) {
1757 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1761 return $GLOBALS[__FUNCTION__];
1764 // "Getter" for output_mode
1765 function getOutputMode () {
1767 if (!isset($GLOBALS[__FUNCTION__])) {
1769 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1773 return $GLOBALS[__FUNCTION__];
1776 // "Getter" for full_version
1777 function getFullVersion () {
1779 if (!isset($GLOBALS[__FUNCTION__])) {
1781 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1785 return $GLOBALS[__FUNCTION__];
1788 // "Getter" for title
1789 function getTitle () {
1791 if (!isset($GLOBALS[__FUNCTION__])) {
1793 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1797 return $GLOBALS[__FUNCTION__];
1800 // "Getter" for curr_svn_revision
1801 function getCurrentRepositoryRevision () {
1803 if (!isset($GLOBALS[__FUNCTION__])) {
1805 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1809 return $GLOBALS[__FUNCTION__];
1812 // "Getter" for server_url
1813 function getServerUrl () {
1815 if (!isset($GLOBALS[__FUNCTION__])) {
1817 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1821 return $GLOBALS[__FUNCTION__];
1824 // "Getter" for mt_word
1825 function getMtWord () {
1827 if (!isset($GLOBALS[__FUNCTION__])) {
1829 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1833 return $GLOBALS[__FUNCTION__];
1836 // "Getter" for mt_word2
1837 function getMtWord2 () {
1839 if (!isset($GLOBALS[__FUNCTION__])) {
1841 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1845 return $GLOBALS[__FUNCTION__];
1848 // "Getter" for mt_word3
1849 function getMtWord3 () {
1851 if (!isset($GLOBALS[__FUNCTION__])) {
1853 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
1857 return $GLOBALS[__FUNCTION__];
1860 // "Getter" for START_TDAY
1861 function getStartTday () {
1863 if (!isset($GLOBALS[__FUNCTION__])) {
1865 $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
1869 return $GLOBALS[__FUNCTION__];
1872 // "Getter" for START_YDAY
1873 function getStartYday () {
1875 if (!isset($GLOBALS[__FUNCTION__])) {
1877 $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
1881 return $GLOBALS[__FUNCTION__];
1884 // "Getter" for main_title
1885 function getMainTitle () {
1887 if (!isset($GLOBALS[__FUNCTION__])) {
1889 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1893 return $GLOBALS[__FUNCTION__];
1896 // "Getter" for file_hash
1897 function getFileHash () {
1899 if (!isset($GLOBALS[__FUNCTION__])) {
1901 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1905 return $GLOBALS[__FUNCTION__];
1908 // "Getter" for pass_scramble
1909 function getPassScramble () {
1911 if (!isset($GLOBALS[__FUNCTION__])) {
1913 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1917 return $GLOBALS[__FUNCTION__];
1920 // "Getter" for ap_inactive_since
1921 function getApInactiveSince () {
1923 if (!isset($GLOBALS[__FUNCTION__])) {
1925 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1929 return $GLOBALS[__FUNCTION__];
1932 // "Getter" for user_min_confirmed
1933 function getUserMinConfirmed () {
1935 if (!isset($GLOBALS[__FUNCTION__])) {
1937 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1941 return $GLOBALS[__FUNCTION__];
1944 // "Getter" for auto_purge
1945 function getAutoPurge () {
1947 if (!isset($GLOBALS[__FUNCTION__])) {
1949 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1953 return $GLOBALS[__FUNCTION__];
1956 // "Getter" for bonus_userid
1957 function getBonusUserid () {
1959 if (!isset($GLOBALS[__FUNCTION__])) {
1961 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1965 return $GLOBALS[__FUNCTION__];
1968 // "Getter" for ap_inactive_time
1969 function getApInactiveTime () {
1971 if (!isset($GLOBALS[__FUNCTION__])) {
1973 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1977 return $GLOBALS[__FUNCTION__];
1980 // "Getter" for ap_dm_timeout
1981 function getApDmTimeout () {
1983 if (!isset($GLOBALS[__FUNCTION__])) {
1985 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1989 return $GLOBALS[__FUNCTION__];
1992 // "Getter" for ap_tasks_time
1993 function getApTasksTime () {
1995 if (!isset($GLOBALS[__FUNCTION__])) {
1997 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
2001 return $GLOBALS[__FUNCTION__];
2004 // "Getter" for ap_unconfirmed_time
2005 function getApUnconfirmedTime () {
2007 if (!isset($GLOBALS[__FUNCTION__])) {
2009 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
2013 return $GLOBALS[__FUNCTION__];
2016 // "Getter" for points
2017 function getPoints () {
2019 if (!isset($GLOBALS[__FUNCTION__])) {
2021 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
2025 return $GLOBALS[__FUNCTION__];
2028 // "Getter" for slogan
2029 function getSlogan () {
2031 if (!isset($GLOBALS[__FUNCTION__])) {
2033 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
2037 return $GLOBALS[__FUNCTION__];
2040 // "Getter" for copy
2041 function getCopy () {
2043 if (!isset($GLOBALS[__FUNCTION__])) {
2045 $GLOBALS[__FUNCTION__] = getConfig('COPY');
2049 return $GLOBALS[__FUNCTION__];
2052 // "Getter" for webmaster
2053 function getWebmaster () {
2055 if (!isset($GLOBALS[__FUNCTION__])) {
2057 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
2061 return $GLOBALS[__FUNCTION__];
2064 // "Getter" for sql_count
2065 function getSqlCount () {
2067 if (!isset($GLOBALS[__FUNCTION__])) {
2069 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2073 return $GLOBALS[__FUNCTION__];
2076 // "Getter" for num_templates
2077 function getNumTemplates () {
2079 if (!isset($GLOBALS[__FUNCTION__])) {
2081 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2085 return $GLOBALS[__FUNCTION__];
2088 // "Getter" for dns_cache_timeout
2089 function getDnsCacheTimeout () {
2091 if (!isset($GLOBALS[__FUNCTION__])) {
2093 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2097 return $GLOBALS[__FUNCTION__];
2100 // "Getter" for menu_blur_spacer
2101 function getMenuBlurSpacer () {
2103 if (!isset($GLOBALS[__FUNCTION__])) {
2105 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2109 return $GLOBALS[__FUNCTION__];
2112 // "Getter" for points_register
2113 function getPointsRegister () {
2115 if (!isset($GLOBALS[__FUNCTION__])) {
2117 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2121 return $GLOBALS[__FUNCTION__];
2124 // "Getter" for points_ref
2125 function getPointsRef () {
2127 if (!isset($GLOBALS[__FUNCTION__])) {
2129 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2133 return $GLOBALS[__FUNCTION__];
2136 // "Getter" for ref_payout
2137 function getRefPayout () {
2139 if (!isset($GLOBALS[__FUNCTION__])) {
2141 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2145 return $GLOBALS[__FUNCTION__];
2148 // "Getter" for online_timeout
2149 function getOnlineTimeout () {
2151 if (!isset($GLOBALS[__FUNCTION__])) {
2153 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2157 return $GLOBALS[__FUNCTION__];
2160 // "Getter" for index_home
2161 function getIndexHome () {
2163 if (!isset($GLOBALS[__FUNCTION__])) {
2165 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2169 return $GLOBALS[__FUNCTION__];
2172 // "Getter" for one_day
2173 function getOneDay () {
2175 if (!isset($GLOBALS[__FUNCTION__])) {
2177 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2181 return $GLOBALS[__FUNCTION__];
2184 // "Getter" for activate_xchange
2185 function getActivateXchange () {
2187 if (!isset($GLOBALS[__FUNCTION__])) {
2189 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2193 return $GLOBALS[__FUNCTION__];
2196 // "Getter" for img_type
2197 function getImgType () {
2199 if (!isset($GLOBALS[__FUNCTION__])) {
2201 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2205 return $GLOBALS[__FUNCTION__];
2208 // "Getter" for code_length
2209 function getCodeLength () {
2211 if (!isset($GLOBALS[__FUNCTION__])) {
2213 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2217 return $GLOBALS[__FUNCTION__];
2220 // "Getter" for least_cats
2221 function getLeastCats () {
2223 if (!isset($GLOBALS[__FUNCTION__])) {
2225 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2229 return $GLOBALS[__FUNCTION__];
2232 // "Getter" for pass_len
2233 function getPassLen () {
2235 if (!isset($GLOBALS[__FUNCTION__])) {
2237 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2241 return $GLOBALS[__FUNCTION__];
2244 // "Getter" for admin_menu
2245 function getAdminMenu () {
2247 if (!isset($GLOBALS[__FUNCTION__])) {
2249 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2253 return $GLOBALS[__FUNCTION__];
2256 // "Getter" for last_month
2257 function getLastMonth () {
2259 if (!isset($GLOBALS[__FUNCTION__])) {
2261 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2265 return $GLOBALS[__FUNCTION__];
2268 // "Getter" for max_send
2269 function getMaxSend () {
2271 if (!isset($GLOBALS[__FUNCTION__])) {
2273 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2277 return $GLOBALS[__FUNCTION__];
2280 // "Getter" for mails_page
2281 function getMailsPage () {
2283 if (!isset($GLOBALS[__FUNCTION__])) {
2285 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2289 return $GLOBALS[__FUNCTION__];
2292 // "Getter" for rand_no
2293 function getRandNo () {
2295 if (!isset($GLOBALS[__FUNCTION__])) {
2297 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2301 return $GLOBALS[__FUNCTION__];
2304 // "Getter" for __DB_NAME
2305 function getDbName () {
2307 if (!isset($GLOBALS[__FUNCTION__])) {
2309 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2313 return $GLOBALS[__FUNCTION__];
2316 // "Getter" for DOMAIN
2317 function getDomain () {
2319 if (!isset($GLOBALS[__FUNCTION__])) {
2321 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2325 return $GLOBALS[__FUNCTION__];
2328 // "Getter" for proxy_username
2329 function getProxyUsername () {
2331 if (!isset($GLOBALS[__FUNCTION__])) {
2333 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2337 return $GLOBALS[__FUNCTION__];
2340 // "Getter" for proxy_password
2341 function getProxyPassword () {
2343 if (!isset($GLOBALS[__FUNCTION__])) {
2345 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2349 return $GLOBALS[__FUNCTION__];
2352 // "Getter" for proxy_host
2353 function getProxyHost () {
2355 if (!isset($GLOBALS[__FUNCTION__])) {
2357 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2361 return $GLOBALS[__FUNCTION__];
2364 // "Getter" for proxy_port
2365 function getProxyPort () {
2367 if (!isset($GLOBALS[__FUNCTION__])) {
2369 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2373 return $GLOBALS[__FUNCTION__];
2376 // "Getter" for SMTP_HOSTNAME
2377 function getSmtpHostname () {
2379 if (!isset($GLOBALS[__FUNCTION__])) {
2381 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2385 return $GLOBALS[__FUNCTION__];
2388 // "Getter" for SMTP_USER
2389 function getSmtpUser () {
2391 if (!isset($GLOBALS[__FUNCTION__])) {
2393 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2397 return $GLOBALS[__FUNCTION__];
2400 // "Getter" for SMTP_PASSWORD
2401 function getSmtpPassword () {
2403 if (!isset($GLOBALS[__FUNCTION__])) {
2405 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2409 return $GLOBALS[__FUNCTION__];
2412 // "Getter" for points_word
2413 function getPointsWord () {
2415 if (!isset($GLOBALS[__FUNCTION__])) {
2417 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2421 return $GLOBALS[__FUNCTION__];
2424 // "Getter" for profile_lock
2425 function getProfileLock () {
2427 if (!isset($GLOBALS[__FUNCTION__])) {
2429 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2433 return $GLOBALS[__FUNCTION__];
2436 // "Getter" for url_tlock
2437 function getUrlTlock () {
2439 if (!isset($GLOBALS[__FUNCTION__])) {
2441 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2445 return $GLOBALS[__FUNCTION__];
2448 // "Getter" for title_left
2449 function getTitleLeft () {
2451 if (!isset($GLOBALS[__FUNCTION__])) {
2453 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2457 return $GLOBALS[__FUNCTION__];
2460 // "Getter" for title_right
2461 function getTitleRight () {
2463 if (!isset($GLOBALS[__FUNCTION__])) {
2465 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2469 return $GLOBALS[__FUNCTION__];
2472 // "Getter" for title_middle
2473 function getTitleMiddle () {
2475 if (!isset($GLOBALS[__FUNCTION__])) {
2477 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2481 return $GLOBALS[__FUNCTION__];
2484 // Getter for 'check_double_email'
2485 function getCheckDoubleEmail () {
2486 // Is the cache entry set?
2487 if (!isset($GLOBALS[__FUNCTION__])) {
2488 // No, so determine it
2489 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2492 // Return cached entry
2493 return $GLOBALS[__FUNCTION__];
2496 // Checks whether 'check_double_email' is 'Y'
2497 function isCheckDoubleEmailEnabled () {
2498 // Is the cache entry set?
2499 if (!isset($GLOBALS[__FUNCTION__])) {
2500 // No, so determine it
2501 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2504 // Return cached entry
2505 return $GLOBALS[__FUNCTION__];
2508 // Getter for 'display_home_in_index'
2509 function getDisplayHomeInIndex () {
2510 // Is the cache entry set?
2511 if (!isset($GLOBALS[__FUNCTION__])) {
2512 // No, so determine it
2513 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2516 // Return cached entry
2517 return $GLOBALS[__FUNCTION__];
2520 // Checks whether 'display_home_in_index' is 'Y'
2521 function isDisplayHomeInIndexEnabled () {
2522 // Is the cache entry set?
2523 if (!isset($GLOBALS[__FUNCTION__])) {
2524 // No, so determine it
2525 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2528 // Return cached entry
2529 return $GLOBALS[__FUNCTION__];
2532 // Getter for 'admin_menu_javascript'
2533 function getAdminMenuJavascript () {
2534 // Is the cache entry set?
2535 if (!isset($GLOBALS[__FUNCTION__])) {
2536 // No, so determine it
2537 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2540 // Return cached entry
2541 return $GLOBALS[__FUNCTION__];
2544 // Getter for 'points_remove_account'
2545 function getPointsRemoveAccount () {
2546 // Is the cache entry set?
2547 if (!isset($GLOBALS[__FUNCTION__])) {
2548 // No, so determine it
2549 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2552 // Return cached entry
2553 return $GLOBALS[__FUNCTION__];
2556 // Checks whether proxy configuration is used
2557 function isProxyUsed () {
2559 if (!isset($GLOBALS[__FUNCTION__])) {
2561 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2565 return $GLOBALS[__FUNCTION__];
2568 // Checks whether POST data contains selections
2569 function ifPostContainsSelections ($element = 'sel') {
2571 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2573 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2577 return $GLOBALS[__FUNCTION__][$element];
2580 // Checks whether verbose_sql is Y and returns true/false if so
2581 function isVerboseSqlEnabled () {
2583 if (!isset($GLOBALS[__FUNCTION__])) {
2585 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2589 return $GLOBALS[__FUNCTION__];
2592 // "Getter" for total user points
2593 function getTotalPoints ($userid) {
2595 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2596 // Init array for filter chain
2598 'userid' => $userid,
2602 // Run filter chain for getting more point values
2603 $data = runFilterChain('get_total_points', $data);
2606 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - getUserUsedPoints($userid);
2610 return $GLOBALS[__FUNCTION__][$userid];
2613 // Wrapper to get used points for given userid
2614 function getUserUsedPoints ($userid) {
2616 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2618 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2622 return $GLOBALS[__FUNCTION__][$userid];
2625 // Wrapper to check if url_blacklist is enabled
2626 function isUrlBlacklistEnabled () {
2628 if (!isset($GLOBALS[__FUNCTION__])) {
2630 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2634 return $GLOBALS[__FUNCTION__];
2637 // Checks whether direct payment is allowed in configuration
2638 function isDirectPaymentEnabled () {
2640 if (!isset($GLOBALS[__FUNCTION__])) {
2642 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2646 return $GLOBALS[__FUNCTION__];
2649 // Checks whether JavaScript-based admin menu is enabled
2650 function isAdminMenuJavascriptEnabled () {
2652 if (!isset($GLOBALS[__FUNCTION__])) {
2654 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
2658 return $GLOBALS[__FUNCTION__];
2661 // Wrapper to check if current task is for extension (not update)
2662 function isExtensionTask ($content) {
2664 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2666 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2670 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2673 // Getter for 'mt_start'
2674 function getMtStart () {
2675 // Is the cache entry set?
2676 if (!isset($GLOBALS[__FUNCTION__])) {
2677 // No, so determine it
2678 $GLOBALS[__FUNCTION__] = getConfig('mt_start');
2681 // Return cached entry
2682 return $GLOBALS[__FUNCTION__];
2685 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2686 function ifTesterAccountsAllowed () {
2687 // Is the cache entry set?
2688 if (!isset($GLOBALS[__FUNCTION__])) {
2689 // No, so determine it
2690 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2693 // Return cached entry
2694 return $GLOBALS[__FUNCTION__];
2697 // Wrapper to check if output mode is CSS
2698 function isCssOutputMode () {
2700 if (!isset($GLOBALS[__FUNCTION__])) {
2702 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2703 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2707 return $GLOBALS[__FUNCTION__];
2710 // Wrapper to check if output mode is HTML
2711 function isHtmlOutputMode () {
2713 if (!isset($GLOBALS[__FUNCTION__])) {
2715 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2716 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2720 return $GLOBALS[__FUNCTION__];
2723 // Wrapper to check if output mode is RAW
2724 function isRawOutputMode () {
2726 if (!isset($GLOBALS[__FUNCTION__])) {
2728 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2729 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2733 return $GLOBALS[__FUNCTION__];
2736 // Wrapper to check if output mode is AJAX
2737 function isAjaxOutputMode () {
2739 if (!isset($GLOBALS[__FUNCTION__])) {
2741 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2742 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2746 return $GLOBALS[__FUNCTION__];
2749 // Wrapper to check if output mode is image
2750 function isImageOutputMode () {
2752 if (!isset($GLOBALS[__FUNCTION__])) {
2754 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2755 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
2759 return $GLOBALS[__FUNCTION__];
2762 // Wrapper to generate a user email link
2763 function generateWrappedUserEmailLink ($email) {
2764 // Just call the inner function
2765 return generateEmailLink($email, 'user_data');
2768 // Wrapper to check if user points are locked
2769 function ifUserPointsLocked ($userid) {
2770 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2772 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2774 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2778 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2779 return $GLOBALS[__FUNCTION__][$userid];
2782 // Appends a line to an existing file or creates it instantly with given content.
2783 // This function does always add a new-line character to every line.
2784 function appendLineToFile ($file, $line) {
2785 $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2786 fwrite($fp, $line . chr(10));
2790 // Wrapper for changeDataInFile() but with full path added
2791 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2793 $FQFN = getPath() . $FQFN;
2795 // Call inner function
2796 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2799 // Wrapper for changing entries in config-local.php
2800 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2801 // Call the inner function
2802 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2805 // Shortens ucfirst(strtolower()) calls
2806 function firstCharUpperCase ($str) {
2807 return ucfirst(strtolower($str));
2810 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2811 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2812 // Get the configuration entry
2813 $configValue = getConfig($configEntry);
2815 // Call inner method
2816 return createTimeSelections($configValue, $configEntry, $stamps, $align);
2819 // Shortens converting of German comma to Computer's version in POST data
2820 function convertCommaToDotInPostData ($postEntry) {
2821 // Read and convert given entry
2822 $postValue = convertCommaToDot(postRequestElement($postEntry));
2825 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
2827 // ... and set it again
2828 setPostRequestElement($postEntry, $postValue);
2831 // Converts German commas to Computer's version in all entries
2832 function convertCommaToDotInPostDataArray ($postEntries) {
2833 // Replace german decimal comma with computer decimal dot
2834 foreach ($postEntries as $entry) {
2835 // Is the entry there?
2836 if (isPostRequestElementSet($entry)) {
2838 convertCommaToDotInPostData($entry);
2844 * Parses a string into a US formated float variable, taken from user comments
2845 * from PHP documentation website.
2847 * @param $floatString A string holding a float expression
2848 * @return $float Corresponding float variable
2849 * @author chris<at>georgakopoulos<dot>com
2850 * @link http://de.php.net/manual/en/function.floatval.php#92563
2852 function parseFloat ($floatString){
2854 $LocaleInfo = localeconv();
2856 // Remove thousand separators
2857 $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
2859 // Convert decimal point
2860 $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2862 // Return float value of converted string
2863 return floatval($floatString);
2867 * Searches a multi-dimensional array (as used in many places) for given
2868 * key/value pair as taken from user comments from PHP documentation website.
2870 * @param $array An array with one or more dimensions
2871 * @param $key Key to look for
2872 * @param $valur Value to look for
2873 * @return $results Resulted array or empty array if $array is no array
2874 * @author sunelbe<at>gmail<dot>com
2875 * @link http://de.php.net/manual/en/function.array-search.php#110120
2877 function search_array ($array, $key, $value) {
2878 // Init array result
2881 // Is $array really an array?
2882 if (is_array($array)) {
2883 // Does key and value match?
2884 if (isset($array[$key]) && $array[$key] == $value) {
2885 // Then add it as result
2886 $results[] = $array;
2889 // Search for whole array
2890 foreach ($array as $subArray) {
2891 // Search recursive and merge again
2892 $results = merge_array($results, search_array($subArray, $key, $value));
2896 // Return resulting array
2900 // Generates a YES/NO option list from given default
2901 function generateYesNoOptions ($defaultValue = '') {
2903 return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2906 // "Getter" for total available receivers
2907 function getTotalReceivers ($mode = 'normal') {
2909 $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
2915 // Wrapper "getter" to get total unconfirmed mails for given userid
2916 function getTotalUnconfirmedMails ($userid) {
2918 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2920 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
2924 return $GLOBALS[__FUNCTION__][$userid];
2927 // Checks whether 'mailer_theme' was found in session
2928 function isMailerThemeSet () {
2930 if (!isset($GLOBALS[__FUNCTION__])) {
2932 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
2936 return $GLOBALS[__FUNCTION__];
2940 * Setter for theme in session (This setter does return the success of
2941 * setSession() which is required e.g. for destroySponsorSession().
2943 function setMailerTheme ($newTheme) {
2944 // Set it in session
2945 return setSession('mailer_theme', $newTheme);
2949 * Getter for theme from session (This getter does return 'mailer_theme' from
2950 * session data or throws an error if not possible
2952 function getMailerTheme () {
2954 if (!isset($GLOBALS[__FUNCTION__])) {
2955 // Is 'mailer_theme' set?
2956 if (!isMailerThemeSet()) {
2957 // No, then abort here
2958 reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2961 // Get it and store it in cache
2962 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
2966 return $GLOBALS[__FUNCTION__];
2969 // "Getter" for last_module/last_what depending on ext-user version
2970 function getUserLastWhatName () {
2971 // Default is old one: last_module
2972 $columnName = 'last_module';
2974 // Is ext-user up-to-date?
2975 if (isExtensionInstalledAndNewer('user', '0.4.9')) {
2976 // Yes, then use new one
2977 $columnName = 'last_what';
2984 // "Getter" for all columns for given alias and separator
2985 function getAllPointColumns ($alias = NULL, $separator = ',') {
2986 // Prepare the filter array
2987 $filterData = array(
2990 'separator' => $separator
2994 $filterData = runFilterChain('get_all_point_columns', $filterData);
2996 // Return the columns
2997 return $filterData['columns'];
3000 // Checks whether the copyright footer (which breaks framesets) is enabled
3001 function ifCopyrightFooterEnabled () {
3002 // Is not unset and not 'N'?
3003 return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
3007 * Wrapper to check whether we have a "full page". This means that the actual
3008 * content is not delivered in any frame of a frameset.
3010 function isFullPage () {
3012 * The parameter 'frame' is generic and always indicates that this content
3013 * will be output into a frame. Furthermore, if a frameset is reported or
3014 * the copyright line is explicitly deactivated, this cannot be a "full
3017 // @TODO Find a way to not use direct module comparison
3018 $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
3024 // Checks whether frameset_mode is set to true
3025 function isFramesetModeEnabled () {
3027 return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
3030 // Function to determine correct 'what' value
3031 function determineWhat ($module = NULL) {
3032 // Init default 'what'
3036 if (is_null($module)) {
3038 $module = getModule();
3046 // Else try to get it from current module
3047 $what = getWhatFromModule($module);
3049 //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
3051 // Remove any spaces from variable
3052 $what = trim($what);
3056 // Default action for non-admin menus
3060 $what = secureString($what);
3067 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3068 function prependZeros ($mStretch, $length = 2) {
3069 // Return prepended string
3070 return sprintf('%0' . (int) $length . 's', $mStretch);
3073 // Wraps convertSelectionsToEpocheTime()
3074 function convertSelectionsToEpocheTimeInPostData ($id) {
3079 // Get all POST data
3080 $postData = postRequestArray();
3082 // Convert given selection id
3083 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3085 // Set the POST array back
3086 setPostRequestArray($postData);
3089 // Wraps checking if given points account type matches with given in POST data
3090 function ifPointsAccountTypeMatchesPost ($type) {
3092 exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
3095 // Gets given user's total referral
3096 function getUsersTotalReferrals ($userid, $level = NULL) {
3098 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3099 // Is the level NULL?
3100 if (is_null($level)) {
3101 // Get total amount (all levels)
3102 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
3104 // Get it from user refs
3105 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
3110 return $GLOBALS[__FUNCTION__][$userid][$level];
3113 // Gets given user's total referral
3114 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3115 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3117 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3118 // Default is all refs
3121 // Is the not level NULL?
3122 if (!is_null($level)) {
3123 // Then add referral level
3124 $add = ' AND r.`level`=' . bigintval($level);
3127 // Check for all referrals
3128 $result = SQL_QUERY_ESC("SELECT
3129 COUNT(d.`userid`) AS `cnt`
3131 `{?_MYSQL_PREFIX?}_user_data` AS d
3133 `{?_MYSQL_PREFIX?}_user_refs` AS r
3135 d.`userid`=r.`refid`
3137 d.`status` != 'CONFIRMED' AND
3145 ), __FUNCTION__, __LINE__);
3148 list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
3151 SQL_FREERESULT($result);
3155 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3156 return $GLOBALS[__FUNCTION__][$userid][$level];
3159 // Converts, if found, dollar data to get element
3160 function convertDollarDataToGetElement ($data) {
3161 // Is first char a dollar?
3162 if (substr($data, 0, 1) == chr(36)) {
3163 // Use last part for getRequestElement()
3164 $data = getRequestElement(substr($data, 1));
3171 // Wrapper function for SQL layer to speed-up things
3172 function SQL_DEBUG_ENABLED () {
3174 if (!isset($GLOBALS[__FUNCTION__])) {
3176 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3180 return $GLOBALS[__FUNCTION__];