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) . '!');
94 // Do we need to aquire a lock?
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 // If there are chmod rights set, apply them
481 if (!empty($chmod)) {
483 $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 (isPostRequestElementSet($element)) {
526 // Return counted elements
527 return countSelection(postRequestElement($element));
529 // Return zero if not found
534 // Checks whether the config-local.php is loaded
535 function isConfigLocalLoaded () {
536 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
539 // Checks whether a nickname or userid was entered and caches the result
540 function isNicknameUsed ($userid) {
541 // Is the cache there
542 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
544 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, true, false) . '') != $userid) && ($userid != 'NULL'));
548 return $GLOBALS[__FUNCTION__][$userid];
551 // Getter for 'what' value
552 function getWhat ($strict = true) {
557 if (isWhatSet($strict)) {
559 $what = $GLOBALS['__what'];
566 // Setter for 'what' value
567 function setWhat ($newWhat) {
568 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat);
569 $GLOBALS['__what'] = $newWhat;
572 // Setter for 'what' from configuration
573 function setWhatFromConfig ($configEntry) {
574 // Get 'what' from config
575 $what = getConfig($configEntry);
581 // Checks whether what is set and optionally aborts on miss
582 function isWhatSet ($strict = false) {
584 $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
586 // Should we abort here?
587 if (($strict === true) && ($isset === false)) {
589 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
596 // Getter for 'action' value
597 function getAction ($strict = true) {
602 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
604 $action = $GLOBALS['__action'];
611 // Setter for 'action' value
612 function setAction ($newAction) {
613 $GLOBALS['__action'] = $newAction;
616 // Checks whether action is set and optionally aborts on miss
617 function isActionSet ($strict = false) {
619 $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
621 // Should we abort here?
622 if (($strict === true) && ($isset === false)) {
624 reportBug(__FUNCTION__, __LINE__, 'action is empty.');
631 // Getter for 'module' value
632 function getModule ($strict = true) {
637 if (isModuleSet($strict)) {
639 $module = $GLOBALS['__module'];
646 // Setter for 'module' value
647 function setModule ($newModule) {
648 // Secure it and make all modules lower-case
649 $GLOBALS['__module'] = strtolower($newModule);
652 // Checks whether module is set and optionally aborts on miss
653 function isModuleSet ($strict = false) {
655 $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
657 // Should we abort here?
658 if (($strict === true) && ($isset === false)) {
660 reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
664 return (($isset === true) && ($GLOBALS['__module'] != 'unknown')) ;
667 // Getter for 'output_mode' value
668 function getScriptOutputMode () {
670 if (!isset($GLOBALS[__FUNCTION__])) {
671 // Is the output mode set?
672 if (!isOutputModeSet()) {
673 // No, then abort here
674 reportBug(__FUNCTION__, __LINE__, 'Output mode not set.');
678 $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode'];
682 return $GLOBALS[__FUNCTION__];
685 // Setter for 'output_mode' value
686 function setOutputMode ($newOutputMode) {
687 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
688 $GLOBALS['__output_mode'] = (int) $newOutputMode;
691 // Checks whether output_mode is set and optionally aborts on miss
692 function isOutputModeSet ($strict = false) {
694 $isset = (isset($GLOBALS['__output_mode']));
696 // Should we abort here?
697 if (($strict === true) && ($isset === false)) {
699 reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
706 // Enables block-mode
707 function enableBlockMode ($enabled = true) {
708 $GLOBALS['__block_mode'] = $enabled;
711 // Checks whether block-mode is enabled
712 function isBlockModeEnabled () {
714 if (!isset($GLOBALS['__block_mode'])) {
716 reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
720 return $GLOBALS['__block_mode'];
723 // Wrapper for redirectToUrl but URL comes from a configuration entry
724 function redirectToConfiguredUrl ($configEntry) {
726 redirectToUrl(getConfig($configEntry));
729 // Wrapper function to redirect from member-only modules to index
730 function redirectToIndexMemberOnlyModule () {
731 // Do the redirect here
732 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
735 // Wrapper function to redirect to current URL
736 function redirectToRequestUri () {
737 redirectToUrl(basename(detectRequestUri()));
740 // Wrapper function to redirect to de-refered URL
741 function redirectToDereferedUrl ($url) {
743 redirectToUrl(generateDerefererUrl($url));
746 // Wrapper function for checking if extension is installed and newer or same version
747 function isExtensionInstalledAndNewer ($ext_name, $version) {
748 // Is an cache entry found?
749 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
751 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
753 // Cache hits should be incremented twice
754 incrementStatsEntry('cache_hits', 2);
758 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
759 return $GLOBALS[__FUNCTION__][$ext_name][$version];
762 // Wrapper function for checking if extension is installed and older than given version
763 function isExtensionInstalledAndOlder ($ext_name, $version) {
764 // Is an cache entry found?
765 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
767 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
769 // Cache hits should be incremented twice
770 incrementStatsEntry('cache_hits', 2);
774 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
775 return $GLOBALS[__FUNCTION__][$ext_name][$version];
779 function setUsername ($userName) {
780 $GLOBALS['username'] = (string) $userName;
784 function getUsername () {
786 if (!isset($GLOBALS['username'])) {
787 // No, so it has to be a guest
788 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
792 return $GLOBALS['username'];
795 // Wrapper function for installation phase
796 function isInstallationPhase () {
798 if (!isset($GLOBALS[__FUNCTION__])) {
800 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
804 return $GLOBALS[__FUNCTION__];
807 // Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
808 function isDemoModeActive () {
810 if (!isset($GLOBALS[__FUNCTION__])) {
812 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
816 return $GLOBALS[__FUNCTION__];
819 // Getter for PHP caching value
820 function getPhpCaching () {
821 return $GLOBALS['php_caching'];
824 // Checks whether the admin hash is set
825 function isAdminHashSet ($adminId) {
826 // Is the array there?
827 if (!isset($GLOBALS['cache_array']['admin'])) {
828 // Missing array should be reported
829 reportBug(__FUNCTION__, __LINE__, 'Cache not set.');
832 // Check for admin hash
833 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
836 // Setter for admin hash
837 function setAdminHash ($adminId, $hash) {
838 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
841 // Getter for current admin login
842 function getCurrentAdminLogin () {
844 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
847 if (!isset($GLOBALS[__FUNCTION__])) {
849 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
853 return $GLOBALS[__FUNCTION__];
856 // Setter for admin id (and current)
857 function setAdminId ($adminId) {
859 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
862 $status = setSession('admin_id', bigintval($adminId));
865 setCurrentAdminId($adminId);
871 // Setter for admin_last
872 function setAdminLast ($adminLast) {
874 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
877 $status = setSession('admin_last', $adminLast);
883 // Setter for admin_md5
884 function setAdminMd5 ($adminMd5) {
886 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
889 $status = setSession('admin_md5', $adminMd5);
895 // Getter for admin_md5
896 function getAdminMd5 () {
898 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
901 return getSession('admin_md5');
904 // Init user data array
905 function initUserData () {
906 // User id should not be zero
907 if (!isValidUserId(getCurrentUserId())) {
908 // Should be always valid
909 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
913 unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
914 $GLOBALS['user_data'][getCurrentUserId()] = array();
917 // Getter for user data
918 function getUserData ($column) {
919 // User id should not be zero
920 if (!isValidUserId(getCurrentUserId())) {
921 // Should be always valid
922 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
928 if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
930 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
937 // Checks whether given user data is set to 'Y'
938 function isUserDataEnabled ($column) {
940 if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
942 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
946 return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
949 // Geter for whole user data array
950 function getUserDataArray () {
952 $userid = getCurrentUserId();
954 // Is the current userid valid?
955 if (!isValidUserId($userid)) {
956 // Should be always valid
957 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
960 // Get the whole array if found
961 if (isset($GLOBALS['user_data'][$userid])) {
962 // Found, so return it
963 return $GLOBALS['user_data'][$userid];
965 // Return empty array
970 // Checks if the user data is valid, this may indicate that the user has logged
971 // in, but you should use isMember() if you want to find that out.
972 function isUserDataValid () {
973 // User id should not be zero so abort here
974 if (!isCurrentUserIdSet()) {
979 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
981 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
985 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
988 // Setter for current userid
989 function setCurrentUserId ($userid) {
991 $GLOBALS['current_userid'] = bigintval($userid);
993 // Unset it to re-determine the actual state
994 unset($GLOBALS['is_userdata_valid'][$userid]);
996 // Is the cache from below functions different?
997 if ((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) {
999 unset($GLOBALS['getCurrentUserId']);
1000 unset($GLOBALS['isCurrentUserIdSet']);
1004 // Getter for current userid
1005 function getCurrentUserId () {
1007 if (!isset($GLOBALS[__FUNCTION__])) {
1008 // Userid must be set before it can be used
1009 if (!isCurrentUserIdSet()) {
1011 reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1014 // Set userid in cache
1015 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1019 return $GLOBALS[__FUNCTION__];
1022 // Checks if current userid is set
1023 function isCurrentUserIdSet () {
1024 // Do we have cache?
1025 if (!isset($GLOBALS[__FUNCTION__])) {
1027 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1031 return $GLOBALS[__FUNCTION__];
1034 // Checks whether we are debugging template cache
1035 function isDebuggingTemplateCache () {
1036 // Do we have cache?
1037 if (!isset($GLOBALS[__FUNCTION__])) {
1039 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1043 return $GLOBALS[__FUNCTION__];
1046 // Wrapper for fetchUserData() and getUserData() calls
1047 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1048 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1050 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1054 // Can we fetch the user data?
1055 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1056 // Now get the data back
1057 $data = getUserData($valueColumn);
1061 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1065 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1066 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1069 // Wrapper for strpos() to ease porting from deprecated ereg() function
1070 function isInString ($needle, $haystack) {
1071 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1072 return (strpos($haystack, $needle) !== false);
1075 // Wrapper for strpos() to ease porting from deprecated eregi() function
1076 // This function is case-insensitive
1077 function isInStringIgnoreCase ($needle, $haystack) {
1078 return (isInString(strtolower($needle), strtolower($haystack)));
1081 // Wrapper to check for if fatal errors where detected
1082 function ifFatalErrorsDetected () {
1083 // Just call the inner function
1084 return (getTotalFatalErrors() > 0);
1087 // Checks whether a HTTP status has been set
1088 function isHttpStatusSet () {
1089 // Is it set and not empty?
1090 return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1093 // Setter for HTTP status
1094 function setHttpStatus ($status) {
1095 $GLOBALS['http_status'] = (string) $status;
1098 // Getter for HTTP status
1099 function getHttpStatus () {
1100 // Is the status set?
1101 if (!isHttpStatusSet()) {
1103 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1107 return $GLOBALS['http_status'];
1111 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1112 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1114 * ----------------------------------------------------------------------------
1115 * If you want to redirect, please use redirectToUrl(); instead
1116 * ----------------------------------------------------------------------------
1118 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1120 * @link http://support.microsoft.com/kb/q176113/
1121 * @author Andreas Gohr <andi@splitbrain.org>
1124 function sendRawRedirect ($url) {
1125 // Clear output buffer
1126 clearOutputBuffer();
1128 // Clear own output buffer
1129 $GLOBALS['__output'] = '';
1131 // To make redirects working (no content type), output mode must be raw
1134 // Send helping header
1135 setHttpStatus('302 Found');
1137 // always close the session
1138 session_write_close();
1140 // Revert entity &
1141 $url = str_replace('&', '&', $url);
1143 // check if running on IIS < 6 with CGI-PHP
1144 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1145 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1146 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1147 ($matches[1] < 6)) {
1148 // Send the IIS header
1149 addHttpHeader('Refresh: 0;url=' . $url);
1151 // Send generic header
1152 addHttpHeader('Location: ' . $url);
1159 // Determines the country of the given user id
1160 function determineCountry ($userid) {
1161 // Do we have cache?
1162 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1163 // Default is 'invalid'
1164 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1166 // Is extension country active?
1167 if (isExtensionActive('country')) {
1168 // Determine the right country code through the country id
1169 $id = getUserData('country_code');
1171 // Then handle it over
1172 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1174 // Get raw code from user data
1175 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1180 return $GLOBALS[__FUNCTION__][$userid];
1183 // "Getter" for total confirmed user accounts
1184 function getTotalConfirmedUser () {
1186 if (!isset($GLOBALS[__FUNCTION__])) {
1188 if (isExtensionActive('user')) {
1189 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1191 $GLOBALS[__FUNCTION__] = 0;
1195 // Return cached value
1196 return $GLOBALS[__FUNCTION__];
1199 // "Getter" for total unconfirmed user accounts
1200 function getTotalUnconfirmedUser () {
1202 if (!isset($GLOBALS[__FUNCTION__])) {
1204 if (isExtensionActive('user')) {
1205 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1207 $GLOBALS[__FUNCTION__] = 0;
1211 // Return cached value
1212 return $GLOBALS[__FUNCTION__];
1215 // "Getter" for total locked user accounts
1216 function getTotalLockedUser () {
1218 if (!isset($GLOBALS[__FUNCTION__])) {
1220 if (isExtensionActive('user')) {
1221 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1223 $GLOBALS[__FUNCTION__] = 0;
1227 // Return cached value
1228 return $GLOBALS[__FUNCTION__];
1231 // "Getter" for total locked user accounts
1232 function getTotalRandomRefidUser () {
1234 if (!isset($GLOBALS[__FUNCTION__])) {
1236 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1237 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, runFilterChain('user_exclusion_sql', ' '), '>=');
1239 $GLOBALS[__FUNCTION__] = 0;
1243 // Return cached value
1244 return $GLOBALS[__FUNCTION__];
1247 // Is given userid valid?
1248 function isValidUserId ($userid) {
1250 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid);
1253 if (is_null($userid)) {
1254 // Do not handle this as of below isset() will always return false
1258 // Do we have cache?
1259 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1261 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1265 return $GLOBALS[__FUNCTION__][$userid];
1269 function encodeEntities ($str) {
1271 $str = secureString($str, true, true);
1273 // Encode dollar sign as well
1274 $str = str_replace('$', '$', $str);
1280 // "Getter" for date from patch_ctime
1281 function getDateFromRepository () {
1283 if (!isset($GLOBALS[__FUNCTION__])) {
1285 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1289 return $GLOBALS[__FUNCTION__];
1292 // "Getter" for date/time from patch_ctime
1293 function getDateTimeFromRepository () {
1295 if (!isset($GLOBALS[__FUNCTION__])) {
1297 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1301 return $GLOBALS[__FUNCTION__];
1304 // Getter for current year (default)
1305 function getYear ($timestamp = NULL) {
1307 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1309 if (is_null($timestamp)) {
1310 $timestamp = time();
1314 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1318 return $GLOBALS[__FUNCTION__][$timestamp];
1321 // Getter for current month (default)
1322 function getMonth ($timestamp = NULL) {
1324 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1325 // If null is set, use time()
1326 if (is_null($timestamp)) {
1327 // Use time() which is current timestamp
1328 $timestamp = time();
1332 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1336 return $GLOBALS[__FUNCTION__][$timestamp];
1339 // Getter for current hour (default)
1340 function getHour ($timestamp = NULL) {
1342 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1344 if (is_null($timestamp)) {
1345 $timestamp = time();
1349 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1353 return $GLOBALS[__FUNCTION__][$timestamp];
1356 // Getter for current day (default)
1357 function getDay ($timestamp = NULL) {
1359 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1361 if (is_null($timestamp)) {
1362 $timestamp = time();
1366 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1370 return $GLOBALS[__FUNCTION__][$timestamp];
1373 // Getter for current week (default)
1374 function getWeek ($timestamp = NULL) {
1376 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1378 if (is_null($timestamp)) $timestamp = time();
1381 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1385 return $GLOBALS[__FUNCTION__][$timestamp];
1388 // Getter for current short_hour (default)
1389 function getShortHour ($timestamp = NULL) {
1391 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1393 if (is_null($timestamp)) $timestamp = time();
1396 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1400 return $GLOBALS[__FUNCTION__][$timestamp];
1403 // Getter for current long_hour (default)
1404 function getLongHour ($timestamp = NULL) {
1406 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1408 if (is_null($timestamp)) $timestamp = time();
1411 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1415 return $GLOBALS[__FUNCTION__][$timestamp];
1418 // Getter for current second (default)
1419 function getSecond ($timestamp = NULL) {
1421 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1423 if (is_null($timestamp)) $timestamp = time();
1426 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1430 return $GLOBALS[__FUNCTION__][$timestamp];
1433 // Getter for current minute (default)
1434 function getMinute ($timestamp = NULL) {
1436 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1438 if (is_null($timestamp)) $timestamp = time();
1441 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1445 return $GLOBALS[__FUNCTION__][$timestamp];
1448 // Checks whether the title decoration is enabled
1449 function isTitleDecorationEnabled () {
1450 // Do we have cache?
1451 if (!isset($GLOBALS[__FUNCTION__])) {
1453 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1457 return $GLOBALS[__FUNCTION__];
1460 // Checks whether filter usage updates are enabled (expensive queries!)
1461 function isFilterUsageUpdateEnabled () {
1462 // Do we have cache?
1463 if (!isset($GLOBALS[__FUNCTION__])) {
1465 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1469 return $GLOBALS[__FUNCTION__];
1472 // Checks whether debugging of weekly resets is enabled
1473 function isWeeklyResetDebugEnabled () {
1474 // Do we have cache?
1475 if (!isset($GLOBALS[__FUNCTION__])) {
1477 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1481 return $GLOBALS[__FUNCTION__];
1484 // Checks whether debugging of monthly resets is enabled
1485 function isMonthlyResetDebugEnabled () {
1486 // Do we have cache?
1487 if (!isset($GLOBALS[__FUNCTION__])) {
1489 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1493 return $GLOBALS[__FUNCTION__];
1496 // Checks whether displaying of debug SQLs are enabled
1497 function isDisplayDebugSqlEnabled () {
1498 // Do we have cache?
1499 if (!isset($GLOBALS[__FUNCTION__])) {
1501 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1505 return $GLOBALS[__FUNCTION__];
1508 // Checks whether module title is enabled
1509 function isModuleTitleEnabled () {
1510 // Do we have cache?
1511 if (!isset($GLOBALS[__FUNCTION__])) {
1513 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1517 return $GLOBALS[__FUNCTION__];
1520 // Checks whether what title is enabled
1521 function isWhatTitleEnabled () {
1522 // Do we have cache?
1523 if (!isset($GLOBALS[__FUNCTION__])) {
1525 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1529 return $GLOBALS[__FUNCTION__];
1532 // Checks whether stats are enabled
1533 function ifInternalStatsEnabled () {
1534 // Do we have cache?
1535 if (!isset($GLOBALS[__FUNCTION__])) {
1536 // Then determine it
1537 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1540 // Return cached value
1541 return $GLOBALS[__FUNCTION__];
1544 // Checks whether admin-notification of certain user actions is enabled
1545 function isAdminNotificationEnabled () {
1546 // Do we have cache?
1547 if (!isset($GLOBALS[__FUNCTION__])) {
1549 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1553 return $GLOBALS[__FUNCTION__];
1556 // Checks whether random referral id selection is enabled
1557 function isRandomReferralIdEnabled () {
1558 // Do we have cache?
1559 if (!isset($GLOBALS[__FUNCTION__])) {
1561 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1565 return $GLOBALS[__FUNCTION__];
1568 // "Getter" for default language
1569 function getDefaultLanguage () {
1570 // Do we have cache?
1571 if (!isset($GLOBALS[__FUNCTION__])) {
1573 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1577 return $GLOBALS[__FUNCTION__];
1580 // "Getter" for default referral id
1581 function getDefRefid () {
1582 // Do we have cache?
1583 if (!isset($GLOBALS[__FUNCTION__])) {
1585 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1589 return $GLOBALS[__FUNCTION__];
1592 // "Getter" for path
1593 function getPath () {
1594 // Do we have cache?
1595 if (!isset($GLOBALS[__FUNCTION__])) {
1597 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1601 return $GLOBALS[__FUNCTION__];
1605 function getUrl () {
1606 // Do we have cache?
1607 if (!isset($GLOBALS[__FUNCTION__])) {
1609 $GLOBALS[__FUNCTION__] = getConfig('URL');
1613 return $GLOBALS[__FUNCTION__];
1616 // "Getter" for cache_path
1617 function getCachePath () {
1618 // Do we have cache?
1619 if (!isset($GLOBALS[__FUNCTION__])) {
1621 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1625 return $GLOBALS[__FUNCTION__];
1628 // "Getter" for secret_key
1629 function getSecretKey () {
1630 // Do we have cache?
1631 if (!isset($GLOBALS[__FUNCTION__])) {
1633 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1637 return $GLOBALS[__FUNCTION__];
1640 // "Getter" for SITE_KEY
1641 function getSiteKey () {
1642 // Do we have cache?
1643 if (!isset($GLOBALS[__FUNCTION__])) {
1645 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1649 return $GLOBALS[__FUNCTION__];
1652 // "Getter" for DATE_KEY
1653 function getDateKey () {
1654 // Do we have cache?
1655 if (!isset($GLOBALS[__FUNCTION__])) {
1657 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1661 return $GLOBALS[__FUNCTION__];
1664 // "Getter" for master_salt
1665 function getMasterSalt () {
1666 // Do we have cache?
1667 if (!isset($GLOBALS[__FUNCTION__])) {
1669 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1673 return $GLOBALS[__FUNCTION__];
1676 // "Getter" for prime
1677 function getPrime () {
1678 // Do we have cache?
1679 if (!isset($GLOBALS[__FUNCTION__])) {
1681 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1685 return $GLOBALS[__FUNCTION__];
1688 // "Getter" for encrypt_separator
1689 function getEncryptSeparator () {
1690 // Do we have cache?
1691 if (!isset($GLOBALS[__FUNCTION__])) {
1693 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1697 return $GLOBALS[__FUNCTION__];
1700 // "Getter" for mysql_prefix
1701 function getMysqlPrefix () {
1702 // Do we have cache?
1703 if (!isset($GLOBALS[__FUNCTION__])) {
1705 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1709 return $GLOBALS[__FUNCTION__];
1712 // "Getter" for table_type
1713 function getTableType () {
1714 // Do we have cache?
1715 if (!isset($GLOBALS[__FUNCTION__])) {
1717 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1721 return $GLOBALS[__FUNCTION__];
1724 // "Getter" for salt_length
1725 function getSaltLength () {
1726 // Do we have cache?
1727 if (!isset($GLOBALS[__FUNCTION__])) {
1729 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1733 return $GLOBALS[__FUNCTION__];
1736 // "Getter" for output_mode
1737 function getOutputMode () {
1738 // Do we have cache?
1739 if (!isset($GLOBALS[__FUNCTION__])) {
1741 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1745 return $GLOBALS[__FUNCTION__];
1748 // "Getter" for full_version
1749 function getFullVersion () {
1750 // Do we have cache?
1751 if (!isset($GLOBALS[__FUNCTION__])) {
1753 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1757 return $GLOBALS[__FUNCTION__];
1760 // "Getter" for title
1761 function getTitle () {
1762 // Do we have cache?
1763 if (!isset($GLOBALS[__FUNCTION__])) {
1765 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1769 return $GLOBALS[__FUNCTION__];
1772 // "Getter" for curr_svn_revision
1773 function getCurrentRepositoryRevision () {
1774 // Do we have cache?
1775 if (!isset($GLOBALS[__FUNCTION__])) {
1777 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1781 return $GLOBALS[__FUNCTION__];
1784 // "Getter" for server_url
1785 function getServerUrl () {
1786 // Do we have cache?
1787 if (!isset($GLOBALS[__FUNCTION__])) {
1789 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1793 return $GLOBALS[__FUNCTION__];
1796 // "Getter" for mt_word
1797 function getMtWord () {
1798 // Do we have cache?
1799 if (!isset($GLOBALS[__FUNCTION__])) {
1801 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1805 return $GLOBALS[__FUNCTION__];
1808 // "Getter" for mt_word2
1809 function getMtWord2 () {
1810 // Do we have cache?
1811 if (!isset($GLOBALS[__FUNCTION__])) {
1813 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1817 return $GLOBALS[__FUNCTION__];
1820 // "Getter" for main_title
1821 function getMainTitle () {
1822 // Do we have cache?
1823 if (!isset($GLOBALS[__FUNCTION__])) {
1825 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1829 return $GLOBALS[__FUNCTION__];
1832 // "Getter" for file_hash
1833 function getFileHash () {
1834 // Do we have cache?
1835 if (!isset($GLOBALS[__FUNCTION__])) {
1837 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1841 return $GLOBALS[__FUNCTION__];
1844 // "Getter" for pass_scramble
1845 function getPassScramble () {
1846 // Do we have cache?
1847 if (!isset($GLOBALS[__FUNCTION__])) {
1849 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1853 return $GLOBALS[__FUNCTION__];
1856 // "Getter" for ap_inactive_since
1857 function getApInactiveSince () {
1858 // Do we have cache?
1859 if (!isset($GLOBALS[__FUNCTION__])) {
1861 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1865 return $GLOBALS[__FUNCTION__];
1868 // "Getter" for user_min_confirmed
1869 function getUserMinConfirmed () {
1870 // Do we have cache?
1871 if (!isset($GLOBALS[__FUNCTION__])) {
1873 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1877 return $GLOBALS[__FUNCTION__];
1880 // "Getter" for auto_purge
1881 function getAutoPurge () {
1882 // Do we have cache?
1883 if (!isset($GLOBALS[__FUNCTION__])) {
1885 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1889 return $GLOBALS[__FUNCTION__];
1892 // "Getter" for bonus_userid
1893 function getBonusUserid () {
1894 // Do we have cache?
1895 if (!isset($GLOBALS[__FUNCTION__])) {
1897 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1901 return $GLOBALS[__FUNCTION__];
1904 // "Getter" for ap_inactive_time
1905 function getApInactiveTime () {
1906 // Do we have cache?
1907 if (!isset($GLOBALS[__FUNCTION__])) {
1909 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1913 return $GLOBALS[__FUNCTION__];
1916 // "Getter" for ap_dm_timeout
1917 function getApDmTimeout () {
1918 // Do we have cache?
1919 if (!isset($GLOBALS[__FUNCTION__])) {
1921 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1925 return $GLOBALS[__FUNCTION__];
1928 // "Getter" for ap_tasks_time
1929 function getApTasksTime () {
1930 // Do we have cache?
1931 if (!isset($GLOBALS[__FUNCTION__])) {
1933 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1937 return $GLOBALS[__FUNCTION__];
1940 // "Getter" for ap_unconfirmed_time
1941 function getApUnconfirmedTime () {
1942 // Do we have cache?
1943 if (!isset($GLOBALS[__FUNCTION__])) {
1945 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1949 return $GLOBALS[__FUNCTION__];
1952 // "Getter" for points
1953 function getPoints () {
1954 // Do we have cache?
1955 if (!isset($GLOBALS[__FUNCTION__])) {
1957 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1961 return $GLOBALS[__FUNCTION__];
1964 // "Getter" for slogan
1965 function getSlogan () {
1966 // Do we have cache?
1967 if (!isset($GLOBALS[__FUNCTION__])) {
1969 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1973 return $GLOBALS[__FUNCTION__];
1976 // "Getter" for copy
1977 function getCopy () {
1978 // Do we have cache?
1979 if (!isset($GLOBALS[__FUNCTION__])) {
1981 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1985 return $GLOBALS[__FUNCTION__];
1988 // "Getter" for webmaster
1989 function getWebmaster () {
1990 // Do we have cache?
1991 if (!isset($GLOBALS[__FUNCTION__])) {
1993 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1997 return $GLOBALS[__FUNCTION__];
2000 // "Getter" for sql_count
2001 function getSqlCount () {
2002 // Do we have cache?
2003 if (!isset($GLOBALS[__FUNCTION__])) {
2005 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2009 return $GLOBALS[__FUNCTION__];
2012 // "Getter" for num_templates
2013 function getNumTemplates () {
2014 // Do we have cache?
2015 if (!isset($GLOBALS[__FUNCTION__])) {
2017 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2021 return $GLOBALS[__FUNCTION__];
2024 // "Getter" for dns_cache_timeout
2025 function getDnsCacheTimeout () {
2026 // Do we have cache?
2027 if (!isset($GLOBALS[__FUNCTION__])) {
2029 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2033 return $GLOBALS[__FUNCTION__];
2036 // "Getter" for menu_blur_spacer
2037 function getMenuBlurSpacer () {
2038 // Do we have cache?
2039 if (!isset($GLOBALS[__FUNCTION__])) {
2041 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2045 return $GLOBALS[__FUNCTION__];
2048 // "Getter" for points_register
2049 function getPointsRegister () {
2050 // Do we have cache?
2051 if (!isset($GLOBALS[__FUNCTION__])) {
2053 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2057 return $GLOBALS[__FUNCTION__];
2060 // "Getter" for points_ref
2061 function getPointsRef () {
2062 // Do we have cache?
2063 if (!isset($GLOBALS[__FUNCTION__])) {
2065 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2069 return $GLOBALS[__FUNCTION__];
2072 // "Getter" for ref_payout
2073 function getRefPayout () {
2074 // Do we have cache?
2075 if (!isset($GLOBALS[__FUNCTION__])) {
2077 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2081 return $GLOBALS[__FUNCTION__];
2084 // "Getter" for online_timeout
2085 function getOnlineTimeout () {
2086 // Do we have cache?
2087 if (!isset($GLOBALS[__FUNCTION__])) {
2089 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2093 return $GLOBALS[__FUNCTION__];
2096 // "Getter" for index_home
2097 function getIndexHome () {
2098 // Do we have cache?
2099 if (!isset($GLOBALS[__FUNCTION__])) {
2101 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2105 return $GLOBALS[__FUNCTION__];
2108 // "Getter" for one_day
2109 function getOneDay () {
2110 // Do we have cache?
2111 if (!isset($GLOBALS[__FUNCTION__])) {
2113 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2117 return $GLOBALS[__FUNCTION__];
2120 // "Getter" for activate_xchange
2121 function getActivateXchange () {
2122 // Do we have cache?
2123 if (!isset($GLOBALS[__FUNCTION__])) {
2125 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2129 return $GLOBALS[__FUNCTION__];
2132 // "Getter" for img_type
2133 function getImgType () {
2134 // Do we have cache?
2135 if (!isset($GLOBALS[__FUNCTION__])) {
2137 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2141 return $GLOBALS[__FUNCTION__];
2144 // "Getter" for code_length
2145 function getCodeLength () {
2146 // Do we have cache?
2147 if (!isset($GLOBALS[__FUNCTION__])) {
2149 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2153 return $GLOBALS[__FUNCTION__];
2156 // "Getter" for least_cats
2157 function getLeastCats () {
2158 // Do we have cache?
2159 if (!isset($GLOBALS[__FUNCTION__])) {
2161 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2165 return $GLOBALS[__FUNCTION__];
2168 // "Getter" for pass_len
2169 function getPassLen () {
2170 // Do we have cache?
2171 if (!isset($GLOBALS[__FUNCTION__])) {
2173 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2177 return $GLOBALS[__FUNCTION__];
2180 // "Getter" for admin_menu
2181 function getAdminMenu () {
2182 // Do we have cache?
2183 if (!isset($GLOBALS[__FUNCTION__])) {
2185 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2189 return $GLOBALS[__FUNCTION__];
2192 // "Getter" for last_month
2193 function getLastMonth () {
2194 // Do we have cache?
2195 if (!isset($GLOBALS[__FUNCTION__])) {
2197 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2201 return $GLOBALS[__FUNCTION__];
2204 // "Getter" for max_send
2205 function getMaxSend () {
2206 // Do we have cache?
2207 if (!isset($GLOBALS[__FUNCTION__])) {
2209 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2213 return $GLOBALS[__FUNCTION__];
2216 // "Getter" for mails_page
2217 function getMailsPage () {
2218 // Do we have cache?
2219 if (!isset($GLOBALS[__FUNCTION__])) {
2221 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2225 return $GLOBALS[__FUNCTION__];
2228 // "Getter" for rand_no
2229 function getRandNo () {
2230 // Do we have cache?
2231 if (!isset($GLOBALS[__FUNCTION__])) {
2233 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2237 return $GLOBALS[__FUNCTION__];
2240 // "Getter" for __DB_NAME
2241 function getDbName () {
2242 // Do we have cache?
2243 if (!isset($GLOBALS[__FUNCTION__])) {
2245 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2249 return $GLOBALS[__FUNCTION__];
2252 // "Getter" for DOMAIN
2253 function getDomain () {
2254 // Do we have cache?
2255 if (!isset($GLOBALS[__FUNCTION__])) {
2257 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2261 return $GLOBALS[__FUNCTION__];
2264 // "Getter" for proxy_username
2265 function getProxyUsername () {
2266 // Do we have cache?
2267 if (!isset($GLOBALS[__FUNCTION__])) {
2269 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2273 return $GLOBALS[__FUNCTION__];
2276 // "Getter" for proxy_password
2277 function getProxyPassword () {
2278 // Do we have cache?
2279 if (!isset($GLOBALS[__FUNCTION__])) {
2281 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2285 return $GLOBALS[__FUNCTION__];
2288 // "Getter" for proxy_host
2289 function getProxyHost () {
2290 // Do we have cache?
2291 if (!isset($GLOBALS[__FUNCTION__])) {
2293 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2297 return $GLOBALS[__FUNCTION__];
2300 // "Getter" for proxy_port
2301 function getProxyPort () {
2302 // Do we have cache?
2303 if (!isset($GLOBALS[__FUNCTION__])) {
2305 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2309 return $GLOBALS[__FUNCTION__];
2312 // "Getter" for SMTP_HOSTNAME
2313 function getSmtpHostname () {
2314 // Do we have cache?
2315 if (!isset($GLOBALS[__FUNCTION__])) {
2317 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2321 return $GLOBALS[__FUNCTION__];
2324 // "Getter" for SMTP_USER
2325 function getSmtpUser () {
2326 // Do we have cache?
2327 if (!isset($GLOBALS[__FUNCTION__])) {
2329 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2333 return $GLOBALS[__FUNCTION__];
2336 // "Getter" for SMTP_PASSWORD
2337 function getSmtpPassword () {
2338 // Do we have cache?
2339 if (!isset($GLOBALS[__FUNCTION__])) {
2341 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2345 return $GLOBALS[__FUNCTION__];
2348 // "Getter" for points_word
2349 function getPointsWord () {
2350 // Do we have cache?
2351 if (!isset($GLOBALS[__FUNCTION__])) {
2353 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2357 return $GLOBALS[__FUNCTION__];
2360 // "Getter" for profile_lock
2361 function getProfileLock () {
2362 // Do we have cache?
2363 if (!isset($GLOBALS[__FUNCTION__])) {
2365 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2369 return $GLOBALS[__FUNCTION__];
2372 // "Getter" for url_tlock
2373 function getUrlTlock () {
2374 // Do we have cache?
2375 if (!isset($GLOBALS[__FUNCTION__])) {
2377 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2381 return $GLOBALS[__FUNCTION__];
2384 // "Getter" for title_left
2385 function getTitleLeft () {
2386 // Do we have cache?
2387 if (!isset($GLOBALS[__FUNCTION__])) {
2389 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2393 return $GLOBALS[__FUNCTION__];
2396 // "Getter" for title_right
2397 function getTitleRight () {
2398 // Do we have cache?
2399 if (!isset($GLOBALS[__FUNCTION__])) {
2401 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2405 return $GLOBALS[__FUNCTION__];
2408 // "Getter" for title_middle
2409 function getTitleMiddle () {
2410 // Do we have cache?
2411 if (!isset($GLOBALS[__FUNCTION__])) {
2413 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2417 return $GLOBALS[__FUNCTION__];
2420 // Getter for 'check_double_email'
2421 function getCheckDoubleEmail () {
2422 // Is the cache entry set?
2423 if (!isset($GLOBALS[__FUNCTION__])) {
2424 // No, so determine it
2425 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2428 // Return cached entry
2429 return $GLOBALS[__FUNCTION__];
2432 // Checks whether 'check_double_email' is 'Y'
2433 function isCheckDoubleEmailEnabled () {
2434 // Is the cache entry set?
2435 if (!isset($GLOBALS[__FUNCTION__])) {
2436 // No, so determine it
2437 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2440 // Return cached entry
2441 return $GLOBALS[__FUNCTION__];
2444 // Getter for 'display_home_in_index'
2445 function getDisplayHomeInIndex () {
2446 // Is the cache entry set?
2447 if (!isset($GLOBALS[__FUNCTION__])) {
2448 // No, so determine it
2449 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2452 // Return cached entry
2453 return $GLOBALS[__FUNCTION__];
2456 // Checks whether 'display_home_in_index' is 'Y'
2457 function isDisplayHomeInIndexEnabled () {
2458 // Is the cache entry set?
2459 if (!isset($GLOBALS[__FUNCTION__])) {
2460 // No, so determine it
2461 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2464 // Return cached entry
2465 return $GLOBALS[__FUNCTION__];
2468 // Getter for 'admin_menu_javascript'
2469 function getAdminMenuJavascript () {
2470 // Is the cache entry set?
2471 if (!isset($GLOBALS[__FUNCTION__])) {
2472 // No, so determine it
2473 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2476 // Return cached entry
2477 return $GLOBALS[__FUNCTION__];
2480 // Getter for 'points_remove_account'
2481 function getPointsRemoveAccount () {
2482 // Is the cache entry set?
2483 if (!isset($GLOBALS[__FUNCTION__])) {
2484 // No, so determine it
2485 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2488 // Return cached entry
2489 return $GLOBALS[__FUNCTION__];
2492 // Checks whether proxy configuration is used
2493 function isProxyUsed () {
2494 // Do we have cache?
2495 if (!isset($GLOBALS[__FUNCTION__])) {
2497 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2501 return $GLOBALS[__FUNCTION__];
2504 // Checks whether POST data contains selections
2505 function ifPostContainsSelections ($element = 'sel') {
2506 // Do we have cache?
2507 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2509 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2513 return $GLOBALS[__FUNCTION__][$element];
2516 // Checks whether verbose_sql is Y and returns true/false if so
2517 function isVerboseSqlEnabled () {
2518 // Do we have cache?
2519 if (!isset($GLOBALS[__FUNCTION__])) {
2521 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2525 return $GLOBALS[__FUNCTION__];
2528 // "Getter" for total user points
2529 function getTotalPoints ($userid) {
2530 // Do we have cache?
2531 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2532 // Init array for filter chain
2534 'userid' => $userid,
2538 // Run filter chain for getting more point values
2539 $data = runFilterChain('get_total_points', $data);
2542 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - getUserUsedPoints($userid);
2546 return $GLOBALS[__FUNCTION__][$userid];
2549 // Wrapper to get used points for given userid
2550 function getUserUsedPoints ($userid) {
2551 // Do we have cache?
2552 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2554 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2558 return $GLOBALS[__FUNCTION__][$userid];
2561 // Wrapper to check if url_blacklist is enabled
2562 function isUrlBlacklistEnabled () {
2563 // Do we have cache?
2564 if (!isset($GLOBALS[__FUNCTION__])) {
2566 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2570 return $GLOBALS[__FUNCTION__];
2573 // Checks whether direct payment is allowed in configuration
2574 function isDirectPaymentEnabled () {
2575 // Do we have cache?
2576 if (!isset($GLOBALS[__FUNCTION__])) {
2578 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2582 return $GLOBALS[__FUNCTION__];
2585 // Checks whether JavaScript-based admin menu is enabled
2586 function isAdminMenuJavascriptEnabled () {
2587 // Do we have cache?
2588 if (!isset($GLOBALS[__FUNCTION__])) {
2590 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
2594 return $GLOBALS[__FUNCTION__];
2597 // Wrapper to check if current task is for extension (not update)
2598 function isExtensionTask ($content) {
2599 // Do we have cache?
2600 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2602 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2606 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2609 // Getter for 'mt_start'
2610 function getMtStart () {
2611 // Is the cache entry set?
2612 if (!isset($GLOBALS[__FUNCTION__])) {
2613 // No, so determine it
2614 $GLOBALS[__FUNCTION__] = getConfig('mt_start');
2617 // Return cached entry
2618 return $GLOBALS[__FUNCTION__];
2621 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2622 function ifTesterAccountsAllowed () {
2623 // Is the cache entry set?
2624 if (!isset($GLOBALS[__FUNCTION__])) {
2625 // No, so determine it
2626 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2629 // Return cached entry
2630 return $GLOBALS[__FUNCTION__];
2633 // Wrapper to check if output mode is CSS
2634 function isCssOutputMode () {
2636 if (!isset($GLOBALS[__FUNCTION__])) {
2638 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2639 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2643 return $GLOBALS[__FUNCTION__];
2646 // Wrapper to check if output mode is HTML
2647 function isHtmlOutputMode () {
2649 if (!isset($GLOBALS[__FUNCTION__])) {
2651 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2652 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2656 return $GLOBALS[__FUNCTION__];
2659 // Wrapper to check if output mode is RAW
2660 function isRawOutputMode () {
2662 if (!isset($GLOBALS[__FUNCTION__])) {
2664 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2665 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2669 return $GLOBALS[__FUNCTION__];
2672 // Wrapper to check if output mode is AJAX
2673 function isAjaxOutputMode () {
2675 if (!isset($GLOBALS[__FUNCTION__])) {
2677 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2678 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2682 return $GLOBALS[__FUNCTION__];
2685 // Wrapper to check if output mode is image
2686 function isImageOutputMode () {
2688 if (!isset($GLOBALS[__FUNCTION__])) {
2690 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2691 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
2695 return $GLOBALS[__FUNCTION__];
2698 // Wrapper to generate a user email link
2699 function generateWrappedUserEmailLink ($email) {
2700 // Just call the inner function
2701 return generateEmailLink($email, 'user_data');
2704 // Wrapper to check if user points are locked
2705 function ifUserPointsLocked ($userid) {
2706 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2707 // Do we have cache?
2708 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2710 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2714 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2715 return $GLOBALS[__FUNCTION__][$userid];
2718 // Appends a line to an existing file or creates it instantly with given content.
2719 // This function does always add a new-line character to every line.
2720 function appendLineToFile ($file, $line) {
2721 $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2722 fwrite($fp, $line . chr(10));
2726 // Wrapper for changeDataInFile() but with full path added
2727 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2729 $FQFN = getPath() . $FQFN;
2731 // Call inner function
2732 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2735 // Wrapper for changing entries in config-local.php
2736 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2737 // Call the inner function
2738 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2741 // Shortens ucfirst(strtolower()) calls
2742 function firstCharUpperCase ($str) {
2743 return ucfirst(strtolower($str));
2746 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2747 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2748 // Get the configuration entry
2749 $configValue = getConfig($configEntry);
2751 // Call inner method
2752 return createTimeSelections($configValue, $configEntry, $stamps, $align);
2755 // Shortens converting of German comma to Computer's version in POST data
2756 function convertCommaToDotInPostData ($postEntry) {
2757 // Read and convert given entry
2758 $postValue = convertCommaToDot(postRequestElement($postEntry));
2760 // ... and set it again
2761 setPostRequestElement($postEntry, $postValue);
2764 // Converts German commas to Computer's version in all entries
2765 function convertCommaToDotInPostDataArray ($postEntries) {
2766 // Replace german decimal comma with computer decimal dot
2767 foreach ($postEntries as $entry) {
2768 // Is the entry there?
2769 if (isPostRequestElementSet($entry)) {
2771 convertCommaToDotInPostData($entry);
2777 * Parses a string into a US formated float variable, taken from user comments
2778 * from PHP documentation website.
2780 * @param $floatString A string holding a float expression
2781 * @return $float Corresponding float variable
2782 * @author chris<at>georgakopoulos<dot>com
2783 * @link http://de.php.net/manual/en/function.floatval.php#92563
2785 function parseFloat ($floatString){
2787 $LocaleInfo = localeconv();
2789 // Remove thousand separators
2790 $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
2792 // Convert decimal point
2793 $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2795 // Return float value of converted string
2796 return floatval($floatString);
2799 // Generates a YES/NO option list from given default
2800 function generateYesNoOptions ($defaultValue = '') {
2802 return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2805 // "Getter" for total available receivers
2806 function getTotalReceivers ($mode = 'normal') {
2808 $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
2814 // Wrapper "getter" to get total unconfirmed mails for given userid
2815 function getTotalUnconfirmedMails ($userid) {
2816 // Do we have cache?
2817 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2819 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
2823 return $GLOBALS[__FUNCTION__][$userid];
2826 // Checks whether 'mailer_theme' was found in session
2827 function isMailerThemeSet () {
2829 if (!isset($GLOBALS[__FUNCTION__])) {
2831 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
2835 return $GLOBALS[__FUNCTION__];
2839 * Setter for theme in session (This setter does return the success of
2840 * setSession() which is required e.g. for destroySponsorSession().
2842 function setMailerTheme ($newTheme) {
2843 // Set it in session
2844 return setSession('mailer_theme', $newTheme);
2848 * Getter for theme from session (This getter does return 'mailer_theme' from
2849 * session data or throws an error if not possible
2851 function getMailerTheme () {
2853 if (!isset($GLOBALS[__FUNCTION__])) {
2854 // Is 'mailer_theme' set?
2855 if (!isMailerThemeSet()) {
2856 // No, then abort here
2857 reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2860 // Get it and store it in cache
2861 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
2865 return $GLOBALS[__FUNCTION__];
2868 // "Getter" for last_module/last_what depending on ext-user version
2869 function getUserLastWhatName () {
2870 // Default is old one: last_module
2871 $columnName = 'last_module';
2873 // Is ext-user up-to-date?
2874 if (isExtensionInstalledAndNewer('user', '0.4.9')) {
2875 // Yes, then use new one
2876 $columnName = 'last_what';
2883 // "Getter" for all columns for given alias and separator
2884 function getAllPointColumns ($alias = NULL, $separator = ',') {
2885 // Prepare the filter array
2886 $filterData = array(
2889 'separator' => $separator
2893 $filterData = runFilterChain('get_all_point_columns', $filterData);
2895 // Return the columns
2896 return $filterData['columns'];
2899 // Checks whether the copyright footer (which breaks framesets) is enabled
2900 function ifCopyrightFooterEnabled () {
2901 // Is not unset and not 'N'?
2902 return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
2906 * Wrapper to check whether we have a "full page". This means that the actual
2907 * content is not delivered in any frame of a frameset.
2909 function isFullPage () {
2911 * The parameter 'frame' is generic and always indicates that this content
2912 * will be output into a frame. Furthermore, if a frameset is reported or
2913 * the copyright line is explicitly deactivated, this cannot be a "full
2916 // @TODO Find a way to not use direct module comparison
2917 $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
2923 // Checks whether frameset_mode is set to true
2924 function isFramesetModeEnabled () {
2926 return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === true));
2929 // Function to determine correct 'what' value
2930 function determineWhat ($module = NULL) {
2931 // Init default 'what'
2935 if (is_null($module)) {
2937 $module = getModule();
2945 // Else try to get it from current module
2946 $what = getWhatFromModule($module);
2948 //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
2950 // Remove any spaces from variable
2951 $what = trim($what);
2955 // Default action for non-admin menus
2959 $what = secureString($what);
2966 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
2967 function prependZeros ($mStretch, $length = 2) {
2968 // Return prepended string
2969 return sprintf('%0' . (int) $length . 's', $mStretch);
2972 // Wraps convertSelectionsToEpocheTime()
2973 function convertSelectionsToEpocheTimeInPostData ($id) {
2978 // Get all POST data
2979 $postData = postRequestArray();
2981 // Convert given selection id
2982 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
2984 // Set the POST array back
2985 setPostRequestArray($postData);
2988 // Wraps checking if given points account type matches with given in POST data
2989 function ifPointsAccountTypeMatchesPost ($type) {
2991 exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), true).'</pre>');
2994 // Gets given user's total referral
2995 function getUsersTotalReferrals ($userid, $level = NULL) {
2996 // Do we have cache?
2997 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
2998 // Is the level NULL?
2999 if (is_null($level)) {
3000 // Get total amount (all levels)
3001 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true);
3003 // Get it from user refs
3004 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true, ' AND `level`=' . bigintval($level));
3009 return $GLOBALS[__FUNCTION__][$userid][$level];
3012 // Gets given user's total referral
3013 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3014 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3015 // Do we have cache?
3016 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3017 // Default is all refs
3020 // Is the not level NULL?
3021 if (!is_null($level)) {
3022 // Then add referral level
3023 $add = ' AND r.`level`=' . bigintval($level);
3026 // Check for all referrals
3027 $result = SQL_QUERY_ESC("SELECT
3028 COUNT(d.`userid`) AS `cnt`
3030 `{?_MYSQL_PREFIX?}_user_data` AS d
3032 `{?_MYSQL_PREFIX?}_user_refs` AS r
3034 d.`userid`=r.`refid`
3036 d.`status` != 'CONFIRMED' AND
3044 ), __FUNCTION__, __LINE__);
3047 list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
3050 SQL_FREERESULT($result);
3054 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3055 return $GLOBALS[__FUNCTION__][$userid][$level];
3058 // Converts, if found, dollar data to get element
3059 function convertDollarDataToGetElement ($data) {
3060 // Is first char a dollar?
3061 if (substr($data, 0, 1) == chr(36)) {
3062 // Use last part for getRequestElement()
3063 $data = getRequestElement(substr($data, 1));
3070 // Wrapper function for SQL layer to speed-up things
3071 function SQL_DEBUG_ENABLED () {
3073 if (!isset($GLOBALS[__FUNCTION__])) {
3075 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3079 return $GLOBALS[__FUNCTION__];