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 return $GLOBALS[__FUNCTION__];
1228 // "Getter" for total unconfirmed user accounts
1229 function getTotalUnconfirmedUser () {
1231 if (!isset($GLOBALS[__FUNCTION__])) {
1233 if (isExtensionActive('user')) {
1234 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1236 $GLOBALS[__FUNCTION__] = 0;
1240 // Return cached value
1241 return $GLOBALS[__FUNCTION__];
1244 // "Getter" for total locked user accounts
1245 function getTotalLockedUser () {
1247 if (!isset($GLOBALS[__FUNCTION__])) {
1249 if (isExtensionActive('user')) {
1250 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
1252 $GLOBALS[__FUNCTION__] = 0;
1256 // Return cached value
1257 return $GLOBALS[__FUNCTION__];
1260 // "Getter" for total locked user accounts
1261 function getTotalRandomRefidUser () {
1263 if (!isset($GLOBALS[__FUNCTION__])) {
1265 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1266 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, runFilterChain('user_exclusion_sql', ' '), '>=');
1268 $GLOBALS[__FUNCTION__] = 0;
1272 // Return cached value
1273 return $GLOBALS[__FUNCTION__];
1276 // Is given userid valid?
1277 function isValidUserId ($userid) {
1279 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid);
1282 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1284 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1288 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',result=' . intval($GLOBALS[__FUNCTION__][$userid]));
1289 return $GLOBALS[__FUNCTION__][$userid];
1293 function encodeEntities ($str) {
1295 $str = secureString($str, true, true);
1297 // Encode dollar sign as well
1298 $str = str_replace('$', '$', $str);
1304 // "Getter" for date from patch_ctime
1305 function getDateFromRepository () {
1307 if (!isset($GLOBALS[__FUNCTION__])) {
1309 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1313 return $GLOBALS[__FUNCTION__];
1316 // "Getter" for date/time from patch_ctime
1317 function getDateTimeFromRepository () {
1319 if (!isset($GLOBALS[__FUNCTION__])) {
1321 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1325 return $GLOBALS[__FUNCTION__];
1328 // Getter for current year (default)
1329 function getYear ($timestamp = NULL) {
1331 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1333 if (is_null($timestamp)) {
1334 $timestamp = time();
1338 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1342 return $GLOBALS[__FUNCTION__][$timestamp];
1345 // Getter for current month (default)
1346 function getMonth ($timestamp = NULL) {
1348 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1349 // If null is set, use time()
1350 if (is_null($timestamp)) {
1351 // Use time() which is current timestamp
1352 $timestamp = time();
1356 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1360 return $GLOBALS[__FUNCTION__][$timestamp];
1363 // Getter for current hour (default)
1364 function getHour ($timestamp = NULL) {
1366 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1368 if (is_null($timestamp)) {
1369 $timestamp = time();
1373 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1377 return $GLOBALS[__FUNCTION__][$timestamp];
1380 // Getter for current day (default)
1381 function getDay ($timestamp = NULL) {
1383 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1385 if (is_null($timestamp)) {
1386 $timestamp = time();
1390 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1394 return $GLOBALS[__FUNCTION__][$timestamp];
1397 // Getter for current week (default)
1398 function getWeek ($timestamp = NULL) {
1400 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1402 if (is_null($timestamp)) $timestamp = time();
1405 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1409 return $GLOBALS[__FUNCTION__][$timestamp];
1412 // Getter for current short_hour (default)
1413 function getShortHour ($timestamp = NULL) {
1415 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1417 if (is_null($timestamp)) $timestamp = time();
1420 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1424 return $GLOBALS[__FUNCTION__][$timestamp];
1427 // Getter for current long_hour (default)
1428 function getLongHour ($timestamp = NULL) {
1430 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1432 if (is_null($timestamp)) $timestamp = time();
1435 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1439 return $GLOBALS[__FUNCTION__][$timestamp];
1442 // Getter for current second (default)
1443 function getSecond ($timestamp = NULL) {
1445 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1447 if (is_null($timestamp)) $timestamp = time();
1450 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1454 return $GLOBALS[__FUNCTION__][$timestamp];
1457 // Getter for current minute (default)
1458 function getMinute ($timestamp = NULL) {
1460 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1462 if (is_null($timestamp)) $timestamp = time();
1465 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1469 return $GLOBALS[__FUNCTION__][$timestamp];
1472 // Checks whether the title decoration is enabled
1473 function isTitleDecorationEnabled () {
1475 if (!isset($GLOBALS[__FUNCTION__])) {
1477 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1481 return $GLOBALS[__FUNCTION__];
1484 // Checks whether filter usage updates are enabled (expensive queries!)
1485 function isFilterUsageUpdateEnabled () {
1487 if (!isset($GLOBALS[__FUNCTION__])) {
1489 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1493 return $GLOBALS[__FUNCTION__];
1496 // Checks whether debugging of weekly resets is enabled
1497 function isWeeklyResetDebugEnabled () {
1499 if (!isset($GLOBALS[__FUNCTION__])) {
1501 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1505 return $GLOBALS[__FUNCTION__];
1508 // Checks whether debugging of monthly resets is enabled
1509 function isMonthlyResetDebugEnabled () {
1511 if (!isset($GLOBALS[__FUNCTION__])) {
1513 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1517 return $GLOBALS[__FUNCTION__];
1520 // Checks whether displaying of debug SQLs are enabled
1521 function isDisplayDebugSqlEnabled () {
1523 if (!isset($GLOBALS[__FUNCTION__])) {
1525 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1529 return $GLOBALS[__FUNCTION__];
1532 // Checks whether module title is enabled
1533 function isModuleTitleEnabled () {
1535 if (!isset($GLOBALS[__FUNCTION__])) {
1537 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1541 return $GLOBALS[__FUNCTION__];
1544 // Checks whether what title is enabled
1545 function isWhatTitleEnabled () {
1547 if (!isset($GLOBALS[__FUNCTION__])) {
1549 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1553 return $GLOBALS[__FUNCTION__];
1556 // Checks whether stats are enabled
1557 function ifInternalStatsEnabled () {
1559 if (!isset($GLOBALS[__FUNCTION__])) {
1560 // Then determine it
1561 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1564 // Return cached value
1565 return $GLOBALS[__FUNCTION__];
1568 // Checks whether admin-notification of certain user actions is enabled
1569 function isAdminNotificationEnabled () {
1571 if (!isset($GLOBALS[__FUNCTION__])) {
1573 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1577 return $GLOBALS[__FUNCTION__];
1580 // Checks whether random referral id selection is enabled
1581 function isRandomReferralIdEnabled () {
1583 if (!isset($GLOBALS[__FUNCTION__])) {
1585 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1589 return $GLOBALS[__FUNCTION__];
1592 // "Getter" for default language
1593 function getDefaultLanguage () {
1595 if (!isset($GLOBALS[__FUNCTION__])) {
1597 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1601 return $GLOBALS[__FUNCTION__];
1604 // "Getter" for default referral id
1605 function getDefRefid () {
1607 if (!isset($GLOBALS[__FUNCTION__])) {
1609 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1613 return $GLOBALS[__FUNCTION__];
1616 // "Getter" for path
1617 function getPath () {
1619 if (!isset($GLOBALS[__FUNCTION__])) {
1621 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1625 return $GLOBALS[__FUNCTION__];
1629 function getUrl () {
1631 if (!isset($GLOBALS[__FUNCTION__])) {
1633 $GLOBALS[__FUNCTION__] = getConfig('URL');
1637 return $GLOBALS[__FUNCTION__];
1640 // "Getter" for cache_path
1641 function getCachePath () {
1643 if (!isset($GLOBALS[__FUNCTION__])) {
1645 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1649 return $GLOBALS[__FUNCTION__];
1652 // "Getter" for secret_key
1653 function getSecretKey () {
1655 if (!isset($GLOBALS[__FUNCTION__])) {
1657 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1661 return $GLOBALS[__FUNCTION__];
1664 // "Getter" for SITE_KEY
1665 function getSiteKey () {
1667 if (!isset($GLOBALS[__FUNCTION__])) {
1669 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1673 return $GLOBALS[__FUNCTION__];
1676 // "Getter" for DATE_KEY
1677 function getDateKey () {
1679 if (!isset($GLOBALS[__FUNCTION__])) {
1681 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1685 return $GLOBALS[__FUNCTION__];
1688 // "Getter" for master_salt
1689 function getMasterSalt () {
1691 if (!isset($GLOBALS[__FUNCTION__])) {
1693 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1697 return $GLOBALS[__FUNCTION__];
1700 // "Getter" for prime
1701 function getPrime () {
1703 if (!isset($GLOBALS[__FUNCTION__])) {
1705 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1709 return $GLOBALS[__FUNCTION__];
1712 // "Getter" for encrypt_separator
1713 function getEncryptSeparator () {
1715 if (!isset($GLOBALS[__FUNCTION__])) {
1717 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1721 return $GLOBALS[__FUNCTION__];
1724 // "Getter" for mysql_prefix
1725 function getMysqlPrefix () {
1727 if (!isset($GLOBALS[__FUNCTION__])) {
1729 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1733 return $GLOBALS[__FUNCTION__];
1736 // "Getter" for table_type
1737 function getTableType () {
1739 if (!isset($GLOBALS[__FUNCTION__])) {
1741 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1745 return $GLOBALS[__FUNCTION__];
1748 // "Getter" for salt_length
1749 function getSaltLength () {
1751 if (!isset($GLOBALS[__FUNCTION__])) {
1753 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1757 return $GLOBALS[__FUNCTION__];
1760 // "Getter" for output_mode
1761 function getOutputMode () {
1763 if (!isset($GLOBALS[__FUNCTION__])) {
1765 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1769 return $GLOBALS[__FUNCTION__];
1772 // "Getter" for full_version
1773 function getFullVersion () {
1775 if (!isset($GLOBALS[__FUNCTION__])) {
1777 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1781 return $GLOBALS[__FUNCTION__];
1784 // "Getter" for title
1785 function getTitle () {
1787 if (!isset($GLOBALS[__FUNCTION__])) {
1789 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1793 return $GLOBALS[__FUNCTION__];
1796 // "Getter" for curr_svn_revision
1797 function getCurrentRepositoryRevision () {
1799 if (!isset($GLOBALS[__FUNCTION__])) {
1801 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1805 return $GLOBALS[__FUNCTION__];
1808 // "Getter" for server_url
1809 function getServerUrl () {
1811 if (!isset($GLOBALS[__FUNCTION__])) {
1813 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1817 return $GLOBALS[__FUNCTION__];
1820 // "Getter" for mt_word
1821 function getMtWord () {
1823 if (!isset($GLOBALS[__FUNCTION__])) {
1825 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1829 return $GLOBALS[__FUNCTION__];
1832 // "Getter" for mt_word2
1833 function getMtWord2 () {
1835 if (!isset($GLOBALS[__FUNCTION__])) {
1837 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1841 return $GLOBALS[__FUNCTION__];
1844 // "Getter" for mt_word3
1845 function getMtWord3 () {
1847 if (!isset($GLOBALS[__FUNCTION__])) {
1849 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
1853 return $GLOBALS[__FUNCTION__];
1856 // "Getter" for START_TDAY
1857 function getStartTday () {
1859 if (!isset($GLOBALS[__FUNCTION__])) {
1861 $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
1865 return $GLOBALS[__FUNCTION__];
1868 // "Getter" for START_YDAY
1869 function getStartYday () {
1871 if (!isset($GLOBALS[__FUNCTION__])) {
1873 $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
1877 return $GLOBALS[__FUNCTION__];
1880 // "Getter" for main_title
1881 function getMainTitle () {
1883 if (!isset($GLOBALS[__FUNCTION__])) {
1885 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1889 return $GLOBALS[__FUNCTION__];
1892 // "Getter" for file_hash
1893 function getFileHash () {
1895 if (!isset($GLOBALS[__FUNCTION__])) {
1897 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1901 return $GLOBALS[__FUNCTION__];
1904 // "Getter" for pass_scramble
1905 function getPassScramble () {
1907 if (!isset($GLOBALS[__FUNCTION__])) {
1909 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1913 return $GLOBALS[__FUNCTION__];
1916 // "Getter" for ap_inactive_since
1917 function getApInactiveSince () {
1919 if (!isset($GLOBALS[__FUNCTION__])) {
1921 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1925 return $GLOBALS[__FUNCTION__];
1928 // "Getter" for user_min_confirmed
1929 function getUserMinConfirmed () {
1931 if (!isset($GLOBALS[__FUNCTION__])) {
1933 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1937 return $GLOBALS[__FUNCTION__];
1940 // "Getter" for auto_purge
1941 function getAutoPurge () {
1943 if (!isset($GLOBALS[__FUNCTION__])) {
1945 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1949 return $GLOBALS[__FUNCTION__];
1952 // "Getter" for bonus_userid
1953 function getBonusUserid () {
1955 if (!isset($GLOBALS[__FUNCTION__])) {
1957 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1961 return $GLOBALS[__FUNCTION__];
1964 // "Getter" for ap_inactive_time
1965 function getApInactiveTime () {
1967 if (!isset($GLOBALS[__FUNCTION__])) {
1969 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1973 return $GLOBALS[__FUNCTION__];
1976 // "Getter" for ap_dm_timeout
1977 function getApDmTimeout () {
1979 if (!isset($GLOBALS[__FUNCTION__])) {
1981 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1985 return $GLOBALS[__FUNCTION__];
1988 // "Getter" for ap_tasks_time
1989 function getApTasksTime () {
1991 if (!isset($GLOBALS[__FUNCTION__])) {
1993 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1997 return $GLOBALS[__FUNCTION__];
2000 // "Getter" for ap_unconfirmed_time
2001 function getApUnconfirmedTime () {
2003 if (!isset($GLOBALS[__FUNCTION__])) {
2005 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
2009 return $GLOBALS[__FUNCTION__];
2012 // "Getter" for points
2013 function getPoints () {
2015 if (!isset($GLOBALS[__FUNCTION__])) {
2017 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
2021 return $GLOBALS[__FUNCTION__];
2024 // "Getter" for slogan
2025 function getSlogan () {
2027 if (!isset($GLOBALS[__FUNCTION__])) {
2029 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
2033 return $GLOBALS[__FUNCTION__];
2036 // "Getter" for copy
2037 function getCopy () {
2039 if (!isset($GLOBALS[__FUNCTION__])) {
2041 $GLOBALS[__FUNCTION__] = getConfig('COPY');
2045 return $GLOBALS[__FUNCTION__];
2048 // "Getter" for webmaster
2049 function getWebmaster () {
2051 if (!isset($GLOBALS[__FUNCTION__])) {
2053 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
2057 return $GLOBALS[__FUNCTION__];
2060 // "Getter" for sql_count
2061 function getSqlCount () {
2063 if (!isset($GLOBALS[__FUNCTION__])) {
2065 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2069 return $GLOBALS[__FUNCTION__];
2072 // "Getter" for num_templates
2073 function getNumTemplates () {
2075 if (!isset($GLOBALS[__FUNCTION__])) {
2077 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2081 return $GLOBALS[__FUNCTION__];
2084 // "Getter" for dns_cache_timeout
2085 function getDnsCacheTimeout () {
2087 if (!isset($GLOBALS[__FUNCTION__])) {
2089 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2093 return $GLOBALS[__FUNCTION__];
2096 // "Getter" for menu_blur_spacer
2097 function getMenuBlurSpacer () {
2099 if (!isset($GLOBALS[__FUNCTION__])) {
2101 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2105 return $GLOBALS[__FUNCTION__];
2108 // "Getter" for points_register
2109 function getPointsRegister () {
2111 if (!isset($GLOBALS[__FUNCTION__])) {
2113 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2117 return $GLOBALS[__FUNCTION__];
2120 // "Getter" for points_ref
2121 function getPointsRef () {
2123 if (!isset($GLOBALS[__FUNCTION__])) {
2125 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2129 return $GLOBALS[__FUNCTION__];
2132 // "Getter" for ref_payout
2133 function getRefPayout () {
2135 if (!isset($GLOBALS[__FUNCTION__])) {
2137 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2141 return $GLOBALS[__FUNCTION__];
2144 // "Getter" for online_timeout
2145 function getOnlineTimeout () {
2147 if (!isset($GLOBALS[__FUNCTION__])) {
2149 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2153 return $GLOBALS[__FUNCTION__];
2156 // "Getter" for index_home
2157 function getIndexHome () {
2159 if (!isset($GLOBALS[__FUNCTION__])) {
2161 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2165 return $GLOBALS[__FUNCTION__];
2168 // "Getter" for one_day
2169 function getOneDay () {
2171 if (!isset($GLOBALS[__FUNCTION__])) {
2173 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2177 return $GLOBALS[__FUNCTION__];
2180 // "Getter" for activate_xchange
2181 function getActivateXchange () {
2183 if (!isset($GLOBALS[__FUNCTION__])) {
2185 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2189 return $GLOBALS[__FUNCTION__];
2192 // "Getter" for img_type
2193 function getImgType () {
2195 if (!isset($GLOBALS[__FUNCTION__])) {
2197 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2201 return $GLOBALS[__FUNCTION__];
2204 // "Getter" for code_length
2205 function getCodeLength () {
2207 if (!isset($GLOBALS[__FUNCTION__])) {
2209 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2213 return $GLOBALS[__FUNCTION__];
2216 // "Getter" for least_cats
2217 function getLeastCats () {
2219 if (!isset($GLOBALS[__FUNCTION__])) {
2221 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2225 return $GLOBALS[__FUNCTION__];
2228 // "Getter" for pass_len
2229 function getPassLen () {
2231 if (!isset($GLOBALS[__FUNCTION__])) {
2233 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2237 return $GLOBALS[__FUNCTION__];
2240 // "Getter" for admin_menu
2241 function getAdminMenu () {
2243 if (!isset($GLOBALS[__FUNCTION__])) {
2245 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2249 return $GLOBALS[__FUNCTION__];
2252 // "Getter" for last_month
2253 function getLastMonth () {
2255 if (!isset($GLOBALS[__FUNCTION__])) {
2257 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2261 return $GLOBALS[__FUNCTION__];
2264 // "Getter" for max_send
2265 function getMaxSend () {
2267 if (!isset($GLOBALS[__FUNCTION__])) {
2269 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2273 return $GLOBALS[__FUNCTION__];
2276 // "Getter" for mails_page
2277 function getMailsPage () {
2279 if (!isset($GLOBALS[__FUNCTION__])) {
2281 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2285 return $GLOBALS[__FUNCTION__];
2288 // "Getter" for rand_no
2289 function getRandNo () {
2291 if (!isset($GLOBALS[__FUNCTION__])) {
2293 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2297 return $GLOBALS[__FUNCTION__];
2300 // "Getter" for __DB_NAME
2301 function getDbName () {
2303 if (!isset($GLOBALS[__FUNCTION__])) {
2305 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2309 return $GLOBALS[__FUNCTION__];
2312 // "Getter" for DOMAIN
2313 function getDomain () {
2315 if (!isset($GLOBALS[__FUNCTION__])) {
2317 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2321 return $GLOBALS[__FUNCTION__];
2324 // "Getter" for proxy_username
2325 function getProxyUsername () {
2327 if (!isset($GLOBALS[__FUNCTION__])) {
2329 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2333 return $GLOBALS[__FUNCTION__];
2336 // "Getter" for proxy_password
2337 function getProxyPassword () {
2339 if (!isset($GLOBALS[__FUNCTION__])) {
2341 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2345 return $GLOBALS[__FUNCTION__];
2348 // "Getter" for proxy_host
2349 function getProxyHost () {
2351 if (!isset($GLOBALS[__FUNCTION__])) {
2353 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2357 return $GLOBALS[__FUNCTION__];
2360 // "Getter" for proxy_port
2361 function getProxyPort () {
2363 if (!isset($GLOBALS[__FUNCTION__])) {
2365 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2369 return $GLOBALS[__FUNCTION__];
2372 // "Getter" for SMTP_HOSTNAME
2373 function getSmtpHostname () {
2375 if (!isset($GLOBALS[__FUNCTION__])) {
2377 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2381 return $GLOBALS[__FUNCTION__];
2384 // "Getter" for SMTP_USER
2385 function getSmtpUser () {
2387 if (!isset($GLOBALS[__FUNCTION__])) {
2389 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2393 return $GLOBALS[__FUNCTION__];
2396 // "Getter" for SMTP_PASSWORD
2397 function getSmtpPassword () {
2399 if (!isset($GLOBALS[__FUNCTION__])) {
2401 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2405 return $GLOBALS[__FUNCTION__];
2408 // "Getter" for points_word
2409 function getPointsWord () {
2411 if (!isset($GLOBALS[__FUNCTION__])) {
2413 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2417 return $GLOBALS[__FUNCTION__];
2420 // "Getter" for profile_lock
2421 function getProfileLock () {
2423 if (!isset($GLOBALS[__FUNCTION__])) {
2425 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2429 return $GLOBALS[__FUNCTION__];
2432 // "Getter" for url_tlock
2433 function getUrlTlock () {
2435 if (!isset($GLOBALS[__FUNCTION__])) {
2437 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2441 return $GLOBALS[__FUNCTION__];
2444 // "Getter" for title_left
2445 function getTitleLeft () {
2447 if (!isset($GLOBALS[__FUNCTION__])) {
2449 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2453 return $GLOBALS[__FUNCTION__];
2456 // "Getter" for title_right
2457 function getTitleRight () {
2459 if (!isset($GLOBALS[__FUNCTION__])) {
2461 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2465 return $GLOBALS[__FUNCTION__];
2468 // "Getter" for title_middle
2469 function getTitleMiddle () {
2471 if (!isset($GLOBALS[__FUNCTION__])) {
2473 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2477 return $GLOBALS[__FUNCTION__];
2480 // Getter for 'check_double_email'
2481 function getCheckDoubleEmail () {
2482 // Is the cache entry set?
2483 if (!isset($GLOBALS[__FUNCTION__])) {
2484 // No, so determine it
2485 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2488 // Return cached entry
2489 return $GLOBALS[__FUNCTION__];
2492 // Checks whether 'check_double_email' is 'Y'
2493 function isCheckDoubleEmailEnabled () {
2494 // Is the cache entry set?
2495 if (!isset($GLOBALS[__FUNCTION__])) {
2496 // No, so determine it
2497 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2500 // Return cached entry
2501 return $GLOBALS[__FUNCTION__];
2504 // Getter for 'display_home_in_index'
2505 function getDisplayHomeInIndex () {
2506 // Is the cache entry set?
2507 if (!isset($GLOBALS[__FUNCTION__])) {
2508 // No, so determine it
2509 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2512 // Return cached entry
2513 return $GLOBALS[__FUNCTION__];
2516 // Checks whether 'display_home_in_index' is 'Y'
2517 function isDisplayHomeInIndexEnabled () {
2518 // Is the cache entry set?
2519 if (!isset($GLOBALS[__FUNCTION__])) {
2520 // No, so determine it
2521 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2524 // Return cached entry
2525 return $GLOBALS[__FUNCTION__];
2528 // Getter for 'admin_menu_javascript'
2529 function getAdminMenuJavascript () {
2530 // Is the cache entry set?
2531 if (!isset($GLOBALS[__FUNCTION__])) {
2532 // No, so determine it
2533 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2536 // Return cached entry
2537 return $GLOBALS[__FUNCTION__];
2540 // Getter for 'points_remove_account'
2541 function getPointsRemoveAccount () {
2542 // Is the cache entry set?
2543 if (!isset($GLOBALS[__FUNCTION__])) {
2544 // No, so determine it
2545 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2548 // Return cached entry
2549 return $GLOBALS[__FUNCTION__];
2552 // Checks whether proxy configuration is used
2553 function isProxyUsed () {
2555 if (!isset($GLOBALS[__FUNCTION__])) {
2557 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2561 return $GLOBALS[__FUNCTION__];
2564 // Checks whether POST data contains selections
2565 function ifPostContainsSelections ($element = 'sel') {
2567 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2569 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2573 return $GLOBALS[__FUNCTION__][$element];
2576 // Checks whether verbose_sql is Y and returns true/false if so
2577 function isVerboseSqlEnabled () {
2579 if (!isset($GLOBALS[__FUNCTION__])) {
2581 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2585 return $GLOBALS[__FUNCTION__];
2588 // "Getter" for total user points
2589 function getTotalPoints ($userid) {
2591 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2592 // Init array for filter chain
2594 'userid' => $userid,
2598 // Run filter chain for getting more point values
2599 $data = runFilterChain('get_total_points', $data);
2602 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - getUserUsedPoints($userid);
2606 return $GLOBALS[__FUNCTION__][$userid];
2609 // Wrapper to get used points for given userid
2610 function getUserUsedPoints ($userid) {
2612 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2614 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2618 return $GLOBALS[__FUNCTION__][$userid];
2621 // Wrapper to check if url_blacklist is enabled
2622 function isUrlBlacklistEnabled () {
2624 if (!isset($GLOBALS[__FUNCTION__])) {
2626 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2630 return $GLOBALS[__FUNCTION__];
2633 // Checks whether direct payment is allowed in configuration
2634 function isDirectPaymentEnabled () {
2636 if (!isset($GLOBALS[__FUNCTION__])) {
2638 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2642 return $GLOBALS[__FUNCTION__];
2645 // Checks whether JavaScript-based admin menu is enabled
2646 function isAdminMenuJavascriptEnabled () {
2648 if (!isset($GLOBALS[__FUNCTION__])) {
2650 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
2654 return $GLOBALS[__FUNCTION__];
2657 // Wrapper to check if current task is for extension (not update)
2658 function isExtensionTask ($content) {
2660 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2662 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2666 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2669 // Getter for 'mt_start'
2670 function getMtStart () {
2671 // Is the cache entry set?
2672 if (!isset($GLOBALS[__FUNCTION__])) {
2673 // No, so determine it
2674 $GLOBALS[__FUNCTION__] = getConfig('mt_start');
2677 // Return cached entry
2678 return $GLOBALS[__FUNCTION__];
2681 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2682 function ifTesterAccountsAllowed () {
2683 // Is the cache entry set?
2684 if (!isset($GLOBALS[__FUNCTION__])) {
2685 // No, so determine it
2686 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2689 // Return cached entry
2690 return $GLOBALS[__FUNCTION__];
2693 // Wrapper to check if output mode is CSS
2694 function isCssOutputMode () {
2696 if (!isset($GLOBALS[__FUNCTION__])) {
2698 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2699 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2703 return $GLOBALS[__FUNCTION__];
2706 // Wrapper to check if output mode is HTML
2707 function isHtmlOutputMode () {
2709 if (!isset($GLOBALS[__FUNCTION__])) {
2711 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2712 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2716 return $GLOBALS[__FUNCTION__];
2719 // Wrapper to check if output mode is RAW
2720 function isRawOutputMode () {
2722 if (!isset($GLOBALS[__FUNCTION__])) {
2724 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2725 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2729 return $GLOBALS[__FUNCTION__];
2732 // Wrapper to check if output mode is AJAX
2733 function isAjaxOutputMode () {
2735 if (!isset($GLOBALS[__FUNCTION__])) {
2737 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2738 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2742 return $GLOBALS[__FUNCTION__];
2745 // Wrapper to check if output mode is image
2746 function isImageOutputMode () {
2748 if (!isset($GLOBALS[__FUNCTION__])) {
2750 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2751 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
2755 return $GLOBALS[__FUNCTION__];
2758 // Wrapper to generate a user email link
2759 function generateWrappedUserEmailLink ($email) {
2760 // Just call the inner function
2761 return generateEmailLink($email, 'user_data');
2764 // Wrapper to check if user points are locked
2765 function ifUserPointsLocked ($userid) {
2766 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2768 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2770 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2774 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2775 return $GLOBALS[__FUNCTION__][$userid];
2778 // Appends a line to an existing file or creates it instantly with given content.
2779 // This function does always add a new-line character to every line.
2780 function appendLineToFile ($file, $line) {
2781 $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2782 fwrite($fp, $line . chr(10));
2786 // Wrapper for changeDataInFile() but with full path added
2787 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2789 $FQFN = getPath() . $FQFN;
2791 // Call inner function
2792 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2795 // Wrapper for changing entries in config-local.php
2796 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2797 // Call the inner function
2798 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2801 // Shortens ucfirst(strtolower()) calls
2802 function firstCharUpperCase ($str) {
2803 return ucfirst(strtolower($str));
2806 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2807 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2808 // Get the configuration entry
2809 $configValue = getConfig($configEntry);
2811 // Call inner method
2812 return createTimeSelections($configValue, $configEntry, $stamps, $align);
2815 // Shortens converting of German comma to Computer's version in POST data
2816 function convertCommaToDotInPostData ($postEntry) {
2817 // Read and convert given entry
2818 $postValue = convertCommaToDot(postRequestElement($postEntry));
2820 // ... and set it again
2821 setPostRequestElement($postEntry, $postValue);
2824 // Converts German commas to Computer's version in all entries
2825 function convertCommaToDotInPostDataArray ($postEntries) {
2826 // Replace german decimal comma with computer decimal dot
2827 foreach ($postEntries as $entry) {
2828 // Is the entry there?
2829 if (isPostRequestElementSet($entry)) {
2831 convertCommaToDotInPostData($entry);
2837 * Parses a string into a US formated float variable, taken from user comments
2838 * from PHP documentation website.
2840 * @param $floatString A string holding a float expression
2841 * @return $float Corresponding float variable
2842 * @author chris<at>georgakopoulos<dot>com
2843 * @link http://de.php.net/manual/en/function.floatval.php#92563
2845 function parseFloat ($floatString){
2847 $LocaleInfo = localeconv();
2849 // Remove thousand separators
2850 $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
2852 // Convert decimal point
2853 $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2855 // Return float value of converted string
2856 return floatval($floatString);
2860 * Searches a multi-dimensional array (as used in many places) for given
2861 * key/value pair as taken from user comments from PHP documentation website.
2863 * @param $array An array with one or more dimensions
2864 * @param $key Key to look for
2865 * @param $valur Value to look for
2866 * @return $results Resulted array or empty array if $array is no array
2867 * @author sunelbe<at>gmail<dot>com
2868 * @link http://de.php.net/manual/en/function.array-search.php#110120
2870 function search_array ($array, $key, $value) {
2871 // Init array result
2874 // Is $array really an array?
2875 if (is_array($array)) {
2876 // Does key and value match?
2877 if (isset($array[$key]) && $array[$key] == $value) {
2878 // Then add it as result
2879 $results[] = $array;
2882 // Search for whole array
2883 foreach ($array as $subArray) {
2884 // Search recursive and merge again
2885 $results = merge_array($results, search_array($subArray, $key, $value));
2889 // Return resulting array
2893 // Generates a YES/NO option list from given default
2894 function generateYesNoOptions ($defaultValue = '') {
2896 return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2899 // "Getter" for total available receivers
2900 function getTotalReceivers ($mode = 'normal') {
2902 $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
2908 // Wrapper "getter" to get total unconfirmed mails for given userid
2909 function getTotalUnconfirmedMails ($userid) {
2911 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2913 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
2917 return $GLOBALS[__FUNCTION__][$userid];
2920 // Checks whether 'mailer_theme' was found in session
2921 function isMailerThemeSet () {
2923 if (!isset($GLOBALS[__FUNCTION__])) {
2925 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
2929 return $GLOBALS[__FUNCTION__];
2933 * Setter for theme in session (This setter does return the success of
2934 * setSession() which is required e.g. for destroySponsorSession().
2936 function setMailerTheme ($newTheme) {
2937 // Set it in session
2938 return setSession('mailer_theme', $newTheme);
2942 * Getter for theme from session (This getter does return 'mailer_theme' from
2943 * session data or throws an error if not possible
2945 function getMailerTheme () {
2947 if (!isset($GLOBALS[__FUNCTION__])) {
2948 // Is 'mailer_theme' set?
2949 if (!isMailerThemeSet()) {
2950 // No, then abort here
2951 reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2954 // Get it and store it in cache
2955 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
2959 return $GLOBALS[__FUNCTION__];
2962 // "Getter" for last_module/last_what depending on ext-user version
2963 function getUserLastWhatName () {
2964 // Default is old one: last_module
2965 $columnName = 'last_module';
2967 // Is ext-user up-to-date?
2968 if (isExtensionInstalledAndNewer('user', '0.4.9')) {
2969 // Yes, then use new one
2970 $columnName = 'last_what';
2977 // "Getter" for all columns for given alias and separator
2978 function getAllPointColumns ($alias = NULL, $separator = ',') {
2979 // Prepare the filter array
2980 $filterData = array(
2983 'separator' => $separator
2987 $filterData = runFilterChain('get_all_point_columns', $filterData);
2989 // Return the columns
2990 return $filterData['columns'];
2993 // Checks whether the copyright footer (which breaks framesets) is enabled
2994 function ifCopyrightFooterEnabled () {
2995 // Is not unset and not 'N'?
2996 return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
3000 * Wrapper to check whether we have a "full page". This means that the actual
3001 * content is not delivered in any frame of a frameset.
3003 function isFullPage () {
3005 * The parameter 'frame' is generic and always indicates that this content
3006 * will be output into a frame. Furthermore, if a frameset is reported or
3007 * the copyright line is explicitly deactivated, this cannot be a "full
3010 // @TODO Find a way to not use direct module comparison
3011 $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
3017 // Checks whether frameset_mode is set to true
3018 function isFramesetModeEnabled () {
3020 return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === true));
3023 // Function to determine correct 'what' value
3024 function determineWhat ($module = NULL) {
3025 // Init default 'what'
3029 if (is_null($module)) {
3031 $module = getModule();
3039 // Else try to get it from current module
3040 $what = getWhatFromModule($module);
3042 //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
3044 // Remove any spaces from variable
3045 $what = trim($what);
3049 // Default action for non-admin menus
3053 $what = secureString($what);
3060 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3061 function prependZeros ($mStretch, $length = 2) {
3062 // Return prepended string
3063 return sprintf('%0' . (int) $length . 's', $mStretch);
3066 // Wraps convertSelectionsToEpocheTime()
3067 function convertSelectionsToEpocheTimeInPostData ($id) {
3072 // Get all POST data
3073 $postData = postRequestArray();
3075 // Convert given selection id
3076 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3078 // Set the POST array back
3079 setPostRequestArray($postData);
3082 // Wraps checking if given points account type matches with given in POST data
3083 function ifPointsAccountTypeMatchesPost ($type) {
3085 exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), true).'</pre>');
3088 // Gets given user's total referral
3089 function getUsersTotalReferrals ($userid, $level = NULL) {
3091 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3092 // Is the level NULL?
3093 if (is_null($level)) {
3094 // Get total amount (all levels)
3095 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true);
3097 // Get it from user refs
3098 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true, ' AND `level`=' . bigintval($level));
3103 return $GLOBALS[__FUNCTION__][$userid][$level];
3106 // Gets given user's total referral
3107 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3108 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3110 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3111 // Default is all refs
3114 // Is the not level NULL?
3115 if (!is_null($level)) {
3116 // Then add referral level
3117 $add = ' AND r.`level`=' . bigintval($level);
3120 // Check for all referrals
3121 $result = SQL_QUERY_ESC("SELECT
3122 COUNT(d.`userid`) AS `cnt`
3124 `{?_MYSQL_PREFIX?}_user_data` AS d
3126 `{?_MYSQL_PREFIX?}_user_refs` AS r
3128 d.`userid`=r.`refid`
3130 d.`status` != 'CONFIRMED' AND
3138 ), __FUNCTION__, __LINE__);
3141 list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
3144 SQL_FREERESULT($result);
3148 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3149 return $GLOBALS[__FUNCTION__][$userid][$level];
3152 // Converts, if found, dollar data to get element
3153 function convertDollarDataToGetElement ($data) {
3154 // Is first char a dollar?
3155 if (substr($data, 0, 1) == chr(36)) {
3156 // Use last part for getRequestElement()
3157 $data = getRequestElement(substr($data, 1));
3164 // Wrapper function for SQL layer to speed-up things
3165 function SQL_DEBUG_ENABLED () {
3167 if (!isset($GLOBALS[__FUNCTION__])) {
3169 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3173 return $GLOBALS[__FUNCTION__];