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!');
52 if (function_exists('file_get_contents')) {
54 $fileContent = file_get_contents($FQFN);
56 // Fall-back to implode-file chain
57 $fileContent = implode('', file($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 or cannot change CHMOD to 0644.", basename($FQFN)));
75 // By default all is failed...
76 $GLOBALS['file_readable'][$FQFN] = FALSE;
79 // Is the function there?
80 if (function_exists('file_put_contents')) {
82 if ($aquireLock === TRUE) {
83 // Write it directly with lock
84 $return = file_put_contents($FQFN, $content, LOCK_EX);
87 $return = file_put_contents($FQFN, $content);
90 // Write it with fopen
91 $fp = fopen($FQFN, 'w')
92 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;
114 return (($return !== FALSE) && (changeMode($FQFN, 0644)));
117 // Clears the output buffer. This function does *NOT* backup sent content.
118 function clearOutputBuffer () {
119 // Make sure this function is not called twice (no double-cleaning!)
120 if (isset($GLOBALS[__FUNCTION__])) {
121 // This function is called twice
122 reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.');
123 } elseif ((ob_get_length() > 0) && (!ob_end_clean())) {
125 reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
128 // Mark this function as called
129 $GLOBALS[__FUNCTION__] = TRUE;
133 function encodeString ($str) {
134 $str = urlencode(base64_encode(compileUriCode($str)));
138 // Decode strings encoded with encodeString()
139 function decodeString ($str) {
140 $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
144 // Decode entities in a nicer way
145 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
146 // Decode the entities to UTF-8 now
147 $decodedString = html_entity_decode($str, $quote, 'UTF-8');
149 // Return decoded string
150 return $decodedString;
153 // Merges an array together but only if both are arrays
154 function merge_array ($array1, $array2, $keepIndex = FALSE) {
155 // Are both an array?
156 if ((!is_array($array1)) && (!is_array($array2))) {
157 // Both are not arrays
158 reportBug(__FUNCTION__, __LINE__, 'No arrays provided!');
159 } elseif (!is_array($array1)) {
160 // Left one is not an array
161 reportBug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
162 } elseif (!is_array($array2)) {
163 // Right one is not an array
164 reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
167 // Maintain index of array2?
168 if ($keepIndex === TRUE) {
169 // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :(
170 foreach ($array2 as $key => $value) {
172 $array1[$key] = $value;
178 // Merge both together normally
179 return array_merge($array1, $array2);
183 // Check if given FQFN is a readable file
184 function isFileReadable ($FQFN) {
186 if (!isset($GLOBALS['file_readable'][$FQFN])) {
188 $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN)));
192 return $GLOBALS['file_readable'][$FQFN];
195 // Checks whether the given FQFN is a directory and not ., .. or .svn
196 function isDirectory ($FQFN) {
198 if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
200 $baseName = basename($FQFN);
203 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
207 return $GLOBALS[__FUNCTION__][$FQFN];
210 // "Getter" for the real remote IP number
211 function detectRealIpAddress ($alwaysReal = FALSE) {
212 // Get remote ip from environment
213 $remoteAddr = determineRealRemoteAddress();
215 // Is removeip installed?
216 if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
218 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
225 // "Getter" for remote IP number
226 function detectRemoteAddr ($alwaysReal = FALSE) {
227 // Get remote ip from environment
228 $remoteAddr = determineRealRemoteAddress(TRUE);
230 // Is removeip installed?
231 if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
233 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
240 // "Getter" for remote hostname
241 function detectRemoteHostname ($alwaysReal = FALSE) {
242 // Get remote ip from environment
243 $remoteHost = getenv('REMOTE_HOST');
245 // Is removeip installed?
246 if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
248 $remoteHost = getAnonymousRemoteHost($remoteHost);
255 // "Getter" for user agent
256 function detectUserAgent ($alwaysReal = FALSE) {
257 // Get remote ip from environment
258 $userAgent = getenv('HTTP_USER_AGENT');
260 // Is removeip installed?
261 if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
263 $userAgent = getAnonymousUserAgent($userAgent);
270 // "Getter" for referer
271 function detectReferer ($alwaysReal = FALSE) {
272 // Get remote ip from environment
273 $referer = getenv('HTTP_REFERER');
275 // Is removeip installed?
276 if ((isExtensionActive('removeip')) && ($alwaysReal === TRUE)) {
278 $referer = getAnonymousReferer($referer);
285 // "Getter" for request URI
286 function detectRequestUri () {
288 return (getenv('REQUEST_URI'));
291 // "Getter" for query string
292 function detectQueryString () {
293 return str_replace('&', '&', (getenv('QUERY_STRING')));
296 // "Getter" for SERVER_NAME
297 function detectServerName () {
299 return (getenv('SERVER_NAME'));
302 // Removes any existing www. from SERVER_NAME. This is very silly but enough
303 // for our purpose here.
304 function detectDomainName () {
306 if (!isset($GLOBALS[__FUNCTION__])) {
308 $domainName = detectServerName();
310 // Is there any www. ?
311 if (substr($domainName, 0, 4) == 'www.') {
313 $domainName = substr($domainName, 4);
317 $GLOBALS[__FUNCTION__] = $domainName;
321 return $GLOBALS[__FUNCTION__];
324 // Check whether we are installing
325 function isInstalling () {
326 // Determine whether we are installing
327 if (!isset($GLOBALS['__mailer_installing'])) {
328 // Check URL (css.php/js.php need this)
329 $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing');
333 return $GLOBALS['__mailer_installing'];
336 // Check whether this script is installed
337 function isInstalled () {
339 if (!isset($GLOBALS[__FUNCTION__])) {
340 // Determine whether this script is installed
341 $GLOBALS[__FUNCTION__] = (
346 isConfigEntrySet('MXCHANGE_INSTALLED')
348 getConfig('MXCHANGE_INSTALLED') == 'Y'
352 // New config file found and loaded
353 isIncludeReadable(getCachePath() . 'config-local.php')
356 // New config file found, but not yet read
357 isIncludeReadable(getCachePath() . 'config-local.php')
360 // Only new config file is found
361 !isIncludeReadable('inc/config.php')
363 // Is installation mode
370 // Then use the cache
371 return $GLOBALS[__FUNCTION__];
374 // Check whether an admin is registered
375 function isAdminRegistered () {
377 if (!isset($GLOBALS[__FUNCTION__])) {
379 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
383 return $GLOBALS[__FUNCTION__];
386 // Checks whether the hourly reset mode is active
387 function isHourlyResetEnabled () {
388 // Now simply check it
389 return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE));
392 // Checks whether the reset mode is active
393 function isResetModeEnabled () {
394 // Now simply check it
395 return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === TRUE));
398 // Checks whether the debug mode is enabled
399 function isDebugModeEnabled () {
401 if (!isset($GLOBALS[__FUNCTION__])) {
403 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
407 return $GLOBALS[__FUNCTION__];
410 // Checks whether the debug reset is enabled
411 function isDebugResetEnabled () {
413 if (!isset($GLOBALS[__FUNCTION__])) {
415 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
419 return $GLOBALS[__FUNCTION__];
422 // Checks whether SQL debugging is enabled
423 function isSqlDebuggingEnabled () {
425 if (!isset($GLOBALS[__FUNCTION__])) {
426 // Determine if SQL debugging is enabled
427 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
431 return $GLOBALS[__FUNCTION__];
434 // Checks whether we shall debug regular expressions
435 function isDebugRegularExpressionEnabled () {
437 if (!isset($GLOBALS[__FUNCTION__])) {
439 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
443 return $GLOBALS[__FUNCTION__];
446 // Checks whether the cache instance is valid
447 function isCacheInstanceValid () {
449 if (!isset($GLOBALS[__FUNCTION__])) {
451 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
455 return $GLOBALS[__FUNCTION__];
458 // Copies a file from source to destination and verifies if that goes fine.
459 // This function should wrap the copy() command and make a nicer debug backtrace
460 // even if there is no xdebug extension installed.
461 function copyFileVerified ($source, $dest, $chmod = '') {
462 // Failed is the default
465 // Is the source file there?
466 if (!isFileReadable($source)) {
468 reportBug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
471 // Is the target directory there?
472 if (!isDirectory(dirname($dest))) {
474 reportBug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
477 // Now try to copy it
478 if (!copy($source, $dest)) {
479 // Something went wrong
480 reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
483 $GLOBALS['file_readable'][$dest] = TRUE;
486 // All fine by default
489 // If there are chmod rights set, apply them
490 if (!empty($chmod)) {
492 $status = changeMode($dest, $chmod);
499 // Wrapper function for chmod()
500 // @TODO Do some more sanity check here
501 function changeMode ($FQFN, $mode) {
502 // Is the file/directory there?
503 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
504 // Neither, so abort here
505 reportBug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
509 return chmod($FQFN, $mode);
512 // Wrapper for unlink()
513 function removeFile ($FQFN) {
514 // Is the file there?
515 if (isFileReadable($FQFN)) {
517 $GLOBALS['file_readable'][$FQFN] = FALSE;
520 return unlink($FQFN);
523 // All fine if no file was removed. If we change this to 'false' or rewrite
524 // above if() block it would be to restrictive.
528 // Wrapper for $_POST['sel']
529 function countPostSelection ($element = 'sel') {
531 if (!isset($GLOBALS[__FUNCTION__][$element])) {
533 $GLOBALS[__FUNCTION__][$element] = '0';
536 if (isPostRequestElementSet($element)) {
537 // Return counted elements
538 $GLOBALS[__FUNCTION__][$element] = countSelection(postRequestElement($element));
542 // Return cached value
543 return $GLOBALS[__FUNCTION__][$element];
546 // Checks whether the config-local.php is loaded
547 function isConfigLocalLoaded () {
548 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === TRUE));
551 // Checks whether a nickname or userid was entered and caches the result
552 function isNicknameUsed ($userid) {
553 // Is the cache there
554 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
556 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL'));
560 return $GLOBALS[__FUNCTION__][$userid];
563 // Getter for 'what' value
564 function getWhat ($strict = TRUE) {
569 if (isWhatSet($strict)) {
571 $what = $GLOBALS['__what'];
578 // Setter for 'what' value
579 function setWhat ($newWhat) {
580 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat);
581 $GLOBALS['__what'] = $newWhat;
584 // Setter for 'what' from configuration
585 function setWhatFromConfig ($configEntry) {
586 // Get 'what' from config
587 $what = getConfig($configEntry);
593 // Checks whether what is set and optionally aborts on miss
594 function isWhatSet ($strict = false) {
596 $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
598 // Should we abort here?
599 if (($strict === TRUE) && ($isset === FALSE)) {
601 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
608 // Getter for 'action' value
609 function getAction ($strict = TRUE) {
614 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
616 $action = $GLOBALS['__action'];
623 // Setter for 'action' value
624 function setAction ($newAction) {
625 $GLOBALS['__action'] = $newAction;
628 // Checks whether action is set and optionally aborts on miss
629 function isActionSet ($strict = false) {
631 $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
633 // Should we abort here?
634 if (($strict === TRUE) && ($isset === FALSE)) {
636 reportBug(__FUNCTION__, __LINE__, 'action is empty.');
643 // Getter for 'module' value
644 function getModule ($strict = TRUE) {
649 if (isModuleSet($strict)) {
651 $module = $GLOBALS['__module'];
658 // Setter for 'module' value
659 function setModule ($newModule) {
660 // Secure it and make all modules lower-case
661 $GLOBALS['__module'] = strtolower($newModule);
664 // Checks whether module is set and optionally aborts on miss
665 function isModuleSet ($strict = false) {
667 $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
669 // Should we abort here?
670 if (($strict === TRUE) && ($isset === FALSE)) {
672 reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
676 return (($isset === TRUE) && ($GLOBALS['__module'] != 'unknown')) ;
679 // Getter for 'output_mode' value
680 function getScriptOutputMode () {
682 if (!isset($GLOBALS[__FUNCTION__])) {
683 // Is the output mode set?
684 if (!isOutputModeSet()) {
685 // No, then abort here
686 reportBug(__FUNCTION__, __LINE__, 'Output mode not set.');
690 $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode'];
694 return $GLOBALS[__FUNCTION__];
697 // Setter for 'output_mode' value
698 function setOutputMode ($newOutputMode) {
699 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
700 $GLOBALS['__output_mode'] = (int) $newOutputMode;
703 // Checks whether output_mode is set and optionally aborts on miss
704 function isOutputModeSet ($strict = false) {
706 $isset = (isset($GLOBALS['__output_mode']));
708 // Should we abort here?
709 if (($strict === TRUE) && ($isset === FALSE)) {
711 reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
718 // Enables block-mode
719 function enableBlockMode ($enabled = TRUE) {
720 $GLOBALS['__block_mode'] = $enabled;
723 // Checks whether block-mode is enabled
724 function isBlockModeEnabled () {
726 if (!isset($GLOBALS['__block_mode'])) {
728 reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
732 return $GLOBALS['__block_mode'];
735 // Wrapper for redirectToUrl but URL comes from a configuration entry
736 function redirectToConfiguredUrl ($configEntry) {
738 redirectToUrl(getConfig($configEntry));
741 // Wrapper function to redirect from member-only modules to index
742 function redirectToIndexMemberOnlyModule () {
743 // Do the redirect here
744 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
747 // Wrapper function to redirect to current URL
748 function redirectToRequestUri () {
749 redirectToUrl(basename(detectRequestUri()));
752 // Wrapper function to redirect to de-refered URL
753 function redirectToDereferedUrl ($url) {
755 redirectToUrl(generateDereferrerUrl($url));
758 // Wrapper function for checking if extension is installed and newer or same version
759 function isExtensionInstalledAndNewer ($ext_name, $ext_ver) {
760 // Is an cache entry found?
761 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
763 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE));
765 // Cache hits should be incremented twice
766 incrementStatsEntry('cache_hits', 2);
770 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
771 return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
774 // Wrapper function for checking if extension is installed and older than given version
775 function isExtensionInstalledAndOlder ($ext_name, $ext_ver) {
776 // Is an cache entry found?
777 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
779 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '<') === TRUE));
781 // Cache hits should be incremented twice
782 incrementStatsEntry('cache_hits', 2);
786 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
787 return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
791 function setUsername ($userName) {
792 $GLOBALS['username'] = (string) $userName;
796 function getUsername () {
798 if (!isset($GLOBALS['username'])) {
799 // No, so it has to be a guest
800 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
804 return $GLOBALS['username'];
807 // Wrapper function for installation phase
808 function isInstallationPhase () {
810 if (!isset($GLOBALS[__FUNCTION__])) {
812 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
816 return $GLOBALS[__FUNCTION__];
819 // Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
820 function isDemoModeActive () {
822 if (!isset($GLOBALS[__FUNCTION__])) {
824 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
828 return $GLOBALS[__FUNCTION__];
831 // Getter for PHP caching value
832 function getPhpCaching () {
833 return $GLOBALS['php_caching'];
836 // Checks whether the admin hash is set
837 function isAdminHashSet ($adminId) {
838 // Is the array there?
839 if (!isset($GLOBALS['cache_array']['admin'])) {
840 // Missing array should be reported
841 reportBug(__FUNCTION__, __LINE__, 'Cache not set.');
844 // Check for admin hash
845 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
848 // Setter for admin hash
849 function setAdminHash ($adminId, $hash) {
850 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
853 // Getter for current admin login
854 function getCurrentAdminLogin () {
856 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
859 if (!isset($GLOBALS[__FUNCTION__])) {
861 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
865 return $GLOBALS[__FUNCTION__];
868 // Setter for admin id (and current)
869 function setAdminId ($adminId) {
871 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
874 $status = setSession('admin_id', bigintval($adminId));
877 setCurrentAdminId($adminId);
883 // Setter for admin_last
884 function setAdminLast ($adminLast) {
886 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
889 $status = setSession('admin_last', $adminLast);
895 // Setter for admin_md5
896 function setAdminMd5 ($adminMd5) {
898 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
901 $status = setSession('admin_md5', $adminMd5);
907 // Getter for admin_md5
908 function getAdminMd5 () {
910 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
913 return getSession('admin_md5');
916 // Init user data array
917 function initUserData () {
918 // User id should not be zero
919 if (!isValidUserId(getCurrentUserId())) {
920 // Should be always valid
921 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
925 unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
926 $GLOBALS['user_data'][getCurrentUserId()] = array();
929 // Getter for user data
930 function getUserData ($column) {
931 // User id should not be zero
932 if (!isValidUserId(getCurrentUserId())) {
933 // Should be always valid
934 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
940 if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
942 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
949 // Checks whether given user data is set to 'Y'
950 function isUserDataEnabled ($column) {
952 if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
954 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
958 return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
961 // Geter for whole user data array
962 function getUserDataArray () {
964 $userid = getCurrentUserId();
966 // Is the current userid valid?
967 if (!isValidUserId($userid)) {
968 // Should be always valid
969 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
972 // Get the whole array if found
973 if (isset($GLOBALS['user_data'][$userid])) {
974 // Found, so return it
975 return $GLOBALS['user_data'][$userid];
977 // Return empty array
982 // Checks if the user data is valid, this may indicate that the user has logged
983 // in, but you should use isMember() if you want to find that out.
984 function isUserDataValid () {
985 // User id should not be zero so abort here
986 if (!isCurrentUserIdSet()) {
987 // Debug message, may be noisy
988 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
995 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
997 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
1000 // Return the result
1001 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1004 // Setter for current userid
1005 function setCurrentUserId ($userid) {
1007 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - ENTERED!');
1009 // Is the cache from below functions different?
1010 if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) {
1012 unsetCurrentUserId();
1016 $GLOBALS['current_userid'] = bigintval($userid);
1018 // Unset it to re-determine the actual state
1019 unset($GLOBALS['is_userdata_valid'][$userid]);
1022 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - EXIT!');
1025 // Getter for current userid
1026 function getCurrentUserId () {
1028 if (!isset($GLOBALS[__FUNCTION__])) {
1029 // Userid must be set before it can be used
1030 if (!isCurrentUserIdSet()) {
1032 reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1035 // Set userid in cache
1036 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1040 return $GLOBALS[__FUNCTION__];
1043 // Checks if current userid is set
1044 function isCurrentUserIdSet () {
1046 if (!isset($GLOBALS[__FUNCTION__])) {
1048 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1052 return $GLOBALS[__FUNCTION__];
1055 // Unsets current userid
1056 function unsetCurrentUserId () {
1058 if (isset($GLOBALS['current_userid'])) {
1060 unset($GLOBALS['isValidUserId'][$GLOBALS['current_userid']]);
1063 // Unset all cache entries
1064 unset($GLOBALS['current_userid']);
1065 unset($GLOBALS['getCurrentUserId']);
1066 unset($GLOBALS['isCurrentUserIdSet']);
1069 // Checks whether we are debugging template cache
1070 function isDebuggingTemplateCache () {
1072 if (!isset($GLOBALS[__FUNCTION__])) {
1074 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1078 return $GLOBALS[__FUNCTION__];
1081 // Wrapper for fetchUserData() and getUserData() calls
1082 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1083 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1085 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1089 // Can we fetch the user data?
1090 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1091 // Now get the data back
1092 $data = getUserData($valueColumn);
1096 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1100 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1101 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1104 // Wrapper for strpos() to ease porting from deprecated ereg() function
1105 function isInString ($needle, $haystack) {
1106 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== FALSE));
1107 return (strpos($haystack, $needle) !== FALSE);
1110 // Wrapper for strpos() to ease porting from deprecated eregi() function
1111 // This function is case-insensitive
1112 function isInStringIgnoreCase ($needle, $haystack) {
1113 return (isInString(strtolower($needle), strtolower($haystack)));
1116 // Wrapper to check for if fatal errors where detected
1117 function ifFatalErrorsDetected () {
1118 // Just call the inner function
1119 return (getTotalFatalErrors() > 0);
1122 // Checks whether a HTTP status has been set
1123 function isHttpStatusSet () {
1124 // Is it set and not empty?
1125 return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1128 // Setter for HTTP status
1129 function setHttpStatus ($status) {
1130 $GLOBALS['http_status'] = (string) $status;
1133 // Getter for HTTP status
1134 function getHttpStatus () {
1135 // Is the status set?
1136 if (!isHttpStatusSet()) {
1138 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1142 return $GLOBALS['http_status'];
1146 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1147 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1149 * ----------------------------------------------------------------------------
1150 * If you want to redirect, please use redirectToUrl(); instead
1151 * ----------------------------------------------------------------------------
1153 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1155 * @link http://support.microsoft.com/kb/q176113/
1156 * @author Andreas Gohr <andi@splitbrain.org>
1159 function sendRawRedirect ($url) {
1160 // Clear output buffer
1161 clearOutputBuffer();
1163 // Clear own output buffer
1164 $GLOBALS['__output'] = '';
1166 // To make redirects working (no content type), output mode must be raw
1169 // Send helping header
1170 setHttpStatus('302 Found');
1172 // always close the session
1173 session_write_close();
1175 // Revert entity &
1176 $url = str_replace('&', '&', $url);
1178 // check if running on IIS < 6 with CGI-PHP
1179 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1180 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1181 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1182 ($matches[1] < 6)) {
1183 // Send the IIS header
1184 addHttpHeader('Refresh: 0;url=' . $url);
1186 // Send generic header
1187 addHttpHeader('Location: ' . $url);
1194 // Determines the country of the given user id
1195 function determineCountry ($userid) {
1197 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1198 // Default is 'invalid'
1199 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1201 // Is extension country active?
1202 if (isExtensionActive('country')) {
1203 // Determine the right country code through the country id
1204 $id = getUserData('country_code');
1206 // Then handle it over
1207 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1209 // Get raw code from user data
1210 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1215 return $GLOBALS[__FUNCTION__][$userid];
1218 // "Getter" for total confirmed user accounts
1219 function getTotalConfirmedUser () {
1221 if (!isset($GLOBALS[__FUNCTION__])) {
1223 if (isExtensionActive('user')) {
1224 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1226 $GLOBALS[__FUNCTION__] = 0;
1230 // Return cached value
1231 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1232 return $GLOBALS[__FUNCTION__];
1235 // "Getter" for total unconfirmed user accounts
1236 function getTotalUnconfirmedUser () {
1238 if (!isset($GLOBALS[__FUNCTION__])) {
1240 if (isExtensionActive('user')) {
1241 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1243 $GLOBALS[__FUNCTION__] = 0;
1247 // Return cached value
1248 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1249 return $GLOBALS[__FUNCTION__];
1252 // "Getter" for total locked user accounts
1253 function getTotalLockedUser () {
1255 if (!isset($GLOBALS[__FUNCTION__])) {
1257 if (isExtensionActive('user')) {
1258 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1260 $GLOBALS[__FUNCTION__] = 0;
1264 // Return cached value
1265 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1266 return $GLOBALS[__FUNCTION__];
1269 // "Getter" for total locked user accounts
1270 function getTotalRandomRefidUser () {
1272 if (!isset($GLOBALS[__FUNCTION__])) {
1274 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1275 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
1277 $GLOBALS[__FUNCTION__] = 0;
1281 // Return cached value
1282 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1283 return $GLOBALS[__FUNCTION__];
1286 // Is given userid valid?
1287 function isValidUserId ($userid) {
1289 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid);
1292 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1294 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1298 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',result=' . intval($GLOBALS[__FUNCTION__][$userid]));
1299 return $GLOBALS[__FUNCTION__][$userid];
1303 function encodeEntities ($str) {
1305 $str = secureString($str, TRUE, TRUE);
1307 // Encode dollar sign as well
1308 $str = str_replace('$', '$', $str);
1314 // "Getter" for date from patch_ctime
1315 function getDateFromRepository () {
1317 if (!isset($GLOBALS[__FUNCTION__])) {
1319 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1323 return $GLOBALS[__FUNCTION__];
1326 // "Getter" for date/time from patch_ctime
1327 function getDateTimeFromRepository () {
1329 if (!isset($GLOBALS[__FUNCTION__])) {
1331 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1335 return $GLOBALS[__FUNCTION__];
1338 // Getter for current year (default)
1339 function getYear ($timestamp = NULL) {
1341 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1343 if (is_null($timestamp)) {
1344 $timestamp = time();
1348 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1352 return $GLOBALS[__FUNCTION__][$timestamp];
1355 // Getter for current month (default)
1356 function getMonth ($timestamp = NULL) {
1358 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1359 // If null is set, use time()
1360 if (is_null($timestamp)) {
1361 // Use time() which is current timestamp
1362 $timestamp = time();
1366 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1370 return $GLOBALS[__FUNCTION__][$timestamp];
1373 // Getter for current hour (default)
1374 function getHour ($timestamp = NULL) {
1376 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1378 if (is_null($timestamp)) {
1379 $timestamp = time();
1383 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1387 return $GLOBALS[__FUNCTION__][$timestamp];
1390 // Getter for current day (default)
1391 function getDay ($timestamp = NULL) {
1393 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1395 if (is_null($timestamp)) {
1396 $timestamp = time();
1400 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1404 return $GLOBALS[__FUNCTION__][$timestamp];
1407 // Getter for current week (default)
1408 function getWeek ($timestamp = NULL) {
1410 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1412 if (is_null($timestamp)) $timestamp = time();
1415 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1419 return $GLOBALS[__FUNCTION__][$timestamp];
1422 // Getter for current short_hour (default)
1423 function getShortHour ($timestamp = NULL) {
1425 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1427 if (is_null($timestamp)) $timestamp = time();
1430 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1434 return $GLOBALS[__FUNCTION__][$timestamp];
1437 // Getter for current long_hour (default)
1438 function getLongHour ($timestamp = NULL) {
1440 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1442 if (is_null($timestamp)) $timestamp = time();
1445 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1449 return $GLOBALS[__FUNCTION__][$timestamp];
1452 // Getter for current second (default)
1453 function getSecond ($timestamp = NULL) {
1455 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1457 if (is_null($timestamp)) $timestamp = time();
1460 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1464 return $GLOBALS[__FUNCTION__][$timestamp];
1467 // Getter for current minute (default)
1468 function getMinute ($timestamp = NULL) {
1470 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1472 if (is_null($timestamp)) $timestamp = time();
1475 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1479 return $GLOBALS[__FUNCTION__][$timestamp];
1482 // Checks whether the title decoration is enabled
1483 function isTitleDecorationEnabled () {
1485 if (!isset($GLOBALS[__FUNCTION__])) {
1487 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1491 return $GLOBALS[__FUNCTION__];
1494 // Checks whether filter usage updates are enabled (expensive queries!)
1495 function isFilterUsageUpdateEnabled () {
1497 if (!isset($GLOBALS[__FUNCTION__])) {
1499 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1503 return $GLOBALS[__FUNCTION__];
1506 // Checks whether debugging of weekly resets is enabled
1507 function isWeeklyResetDebugEnabled () {
1509 if (!isset($GLOBALS[__FUNCTION__])) {
1511 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1515 return $GLOBALS[__FUNCTION__];
1518 // Checks whether debugging of monthly resets is enabled
1519 function isMonthlyResetDebugEnabled () {
1521 if (!isset($GLOBALS[__FUNCTION__])) {
1523 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1527 return $GLOBALS[__FUNCTION__];
1530 // Checks whether displaying of debug SQLs are enabled
1531 function isDisplayDebugSqlEnabled () {
1533 if (!isset($GLOBALS[__FUNCTION__])) {
1535 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1539 return $GLOBALS[__FUNCTION__];
1542 // Checks whether module title is enabled
1543 function isModuleTitleEnabled () {
1545 if (!isset($GLOBALS[__FUNCTION__])) {
1547 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1551 return $GLOBALS[__FUNCTION__];
1554 // Checks whether what title is enabled
1555 function isWhatTitleEnabled () {
1557 if (!isset($GLOBALS[__FUNCTION__])) {
1559 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1563 return $GLOBALS[__FUNCTION__];
1566 // Checks whether stats are enabled
1567 function ifInternalStatsEnabled () {
1569 if (!isset($GLOBALS[__FUNCTION__])) {
1570 // Then determine it
1571 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1574 // Return cached value
1575 return $GLOBALS[__FUNCTION__];
1578 // Checks whether admin-notification of certain user actions is enabled
1579 function isAdminNotificationEnabled () {
1581 if (!isset($GLOBALS[__FUNCTION__])) {
1583 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1587 return $GLOBALS[__FUNCTION__];
1590 // Checks whether random referral id selection is enabled
1591 function isRandomReferralIdEnabled () {
1593 if (!isset($GLOBALS[__FUNCTION__])) {
1595 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1599 return $GLOBALS[__FUNCTION__];
1602 // "Getter" for default language
1603 function getDefaultLanguage () {
1605 if (!isset($GLOBALS[__FUNCTION__])) {
1607 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1611 return $GLOBALS[__FUNCTION__];
1614 // "Getter" for default referral id
1615 function getDefRefid () {
1617 if (!isset($GLOBALS[__FUNCTION__])) {
1619 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1623 return $GLOBALS[__FUNCTION__];
1626 // "Getter" for path
1627 function getPath () {
1629 if (!isset($GLOBALS[__FUNCTION__])) {
1631 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1635 return $GLOBALS[__FUNCTION__];
1639 function getUrl () {
1641 if (!isset($GLOBALS[__FUNCTION__])) {
1643 $GLOBALS[__FUNCTION__] = getConfig('URL');
1647 return $GLOBALS[__FUNCTION__];
1650 // "Getter" for cache_path
1651 function getCachePath () {
1653 if (!isset($GLOBALS[__FUNCTION__])) {
1655 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1659 return $GLOBALS[__FUNCTION__];
1662 // "Getter" for secret_key
1663 function getSecretKey () {
1665 if (!isset($GLOBALS[__FUNCTION__])) {
1667 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1671 return $GLOBALS[__FUNCTION__];
1674 // "Getter" for SITE_KEY
1675 function getSiteKey () {
1677 if (!isset($GLOBALS[__FUNCTION__])) {
1679 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1683 return $GLOBALS[__FUNCTION__];
1686 // "Getter" for DATE_KEY
1687 function getDateKey () {
1689 if (!isset($GLOBALS[__FUNCTION__])) {
1691 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1695 return $GLOBALS[__FUNCTION__];
1698 // "Getter" for master_salt
1699 function getMasterSalt () {
1701 if (!isset($GLOBALS[__FUNCTION__])) {
1703 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1707 return $GLOBALS[__FUNCTION__];
1710 // "Getter" for prime
1711 function getPrime () {
1713 if (!isset($GLOBALS[__FUNCTION__])) {
1715 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1719 return $GLOBALS[__FUNCTION__];
1722 // "Getter" for encrypt_separator
1723 function getEncryptSeparator () {
1725 if (!isset($GLOBALS[__FUNCTION__])) {
1727 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1731 return $GLOBALS[__FUNCTION__];
1734 // "Getter" for mysql_prefix
1735 function getMysqlPrefix () {
1737 if (!isset($GLOBALS[__FUNCTION__])) {
1739 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1743 return $GLOBALS[__FUNCTION__];
1746 // "Getter" for table_type
1747 function getTableType () {
1749 if (!isset($GLOBALS[__FUNCTION__])) {
1751 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1755 return $GLOBALS[__FUNCTION__];
1758 // "Getter" for salt_length
1759 function getSaltLength () {
1761 if (!isset($GLOBALS[__FUNCTION__])) {
1763 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1767 return $GLOBALS[__FUNCTION__];
1770 // "Getter" for output_mode
1771 function getOutputMode () {
1773 if (!isset($GLOBALS[__FUNCTION__])) {
1775 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1779 return $GLOBALS[__FUNCTION__];
1782 // "Getter" for full_version
1783 function getFullVersion () {
1785 if (!isset($GLOBALS[__FUNCTION__])) {
1787 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1791 return $GLOBALS[__FUNCTION__];
1794 // "Getter" for title
1795 function getTitle () {
1797 if (!isset($GLOBALS[__FUNCTION__])) {
1799 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1803 return $GLOBALS[__FUNCTION__];
1806 // "Getter" for curr_svn_revision
1807 function getCurrentRepositoryRevision () {
1809 if (!isset($GLOBALS[__FUNCTION__])) {
1811 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1815 return $GLOBALS[__FUNCTION__];
1818 // "Getter" for server_url
1819 function getServerUrl () {
1821 if (!isset($GLOBALS[__FUNCTION__])) {
1823 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1827 return $GLOBALS[__FUNCTION__];
1830 // "Getter" for mt_word
1831 function getMtWord () {
1833 if (!isset($GLOBALS[__FUNCTION__])) {
1835 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1839 return $GLOBALS[__FUNCTION__];
1842 // "Getter" for mt_word2
1843 function getMtWord2 () {
1845 if (!isset($GLOBALS[__FUNCTION__])) {
1847 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1851 return $GLOBALS[__FUNCTION__];
1854 // "Getter" for mt_word3
1855 function getMtWord3 () {
1857 if (!isset($GLOBALS[__FUNCTION__])) {
1859 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
1863 return $GLOBALS[__FUNCTION__];
1866 // "Getter" for START_TDAY
1867 function getStartTday () {
1869 if (!isset($GLOBALS[__FUNCTION__])) {
1871 $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
1875 return $GLOBALS[__FUNCTION__];
1878 // "Getter" for START_YDAY
1879 function getStartYday () {
1881 if (!isset($GLOBALS[__FUNCTION__])) {
1883 $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
1887 return $GLOBALS[__FUNCTION__];
1890 // "Getter" for main_title
1891 function getMainTitle () {
1893 if (!isset($GLOBALS[__FUNCTION__])) {
1895 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1899 return $GLOBALS[__FUNCTION__];
1902 // "Getter" for file_hash
1903 function getFileHash () {
1905 if (!isset($GLOBALS[__FUNCTION__])) {
1907 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1911 return $GLOBALS[__FUNCTION__];
1914 // "Getter" for pass_scramble
1915 function getPassScramble () {
1917 if (!isset($GLOBALS[__FUNCTION__])) {
1919 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1923 return $GLOBALS[__FUNCTION__];
1926 // "Getter" for ap_inactive_since
1927 function getApInactiveSince () {
1929 if (!isset($GLOBALS[__FUNCTION__])) {
1931 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1935 return $GLOBALS[__FUNCTION__];
1938 // "Getter" for user_min_confirmed
1939 function getUserMinConfirmed () {
1941 if (!isset($GLOBALS[__FUNCTION__])) {
1943 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1947 return $GLOBALS[__FUNCTION__];
1949 // "Getter" for points
1950 function getPoints () {
1952 if (!isset($GLOBALS[__FUNCTION__])) {
1954 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1958 return $GLOBALS[__FUNCTION__];
1961 // "Getter" for slogan
1962 function getSlogan () {
1964 if (!isset($GLOBALS[__FUNCTION__])) {
1966 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1970 return $GLOBALS[__FUNCTION__];
1973 // "Getter" for copy
1974 function getCopy () {
1976 if (!isset($GLOBALS[__FUNCTION__])) {
1978 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1982 return $GLOBALS[__FUNCTION__];
1985 // "Getter" for webmaster
1986 function getWebmaster () {
1988 if (!isset($GLOBALS[__FUNCTION__])) {
1990 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1994 return $GLOBALS[__FUNCTION__];
1997 // "Getter" for sql_count
1998 function getSqlCount () {
2000 if (!isset($GLOBALS[__FUNCTION__])) {
2002 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2006 return $GLOBALS[__FUNCTION__];
2009 // "Getter" for num_templates
2010 function getNumTemplates () {
2012 if (!isset($GLOBALS[__FUNCTION__])) {
2014 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2018 return $GLOBALS[__FUNCTION__];
2021 // "Getter" for dns_cache_timeout
2022 function getDnsCacheTimeout () {
2024 if (!isset($GLOBALS[__FUNCTION__])) {
2026 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2030 return $GLOBALS[__FUNCTION__];
2033 // "Getter" for menu_blur_spacer
2034 function getMenuBlurSpacer () {
2036 if (!isset($GLOBALS[__FUNCTION__])) {
2038 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2042 return $GLOBALS[__FUNCTION__];
2045 // "Getter" for points_register
2046 function getPointsRegister () {
2048 if (!isset($GLOBALS[__FUNCTION__])) {
2050 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2054 return $GLOBALS[__FUNCTION__];
2057 // "Getter" for points_ref
2058 function getPointsRef () {
2060 if (!isset($GLOBALS[__FUNCTION__])) {
2062 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2066 return $GLOBALS[__FUNCTION__];
2069 // "Getter" for ref_payout
2070 function getRefPayout () {
2072 if (!isset($GLOBALS[__FUNCTION__])) {
2074 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2078 return $GLOBALS[__FUNCTION__];
2081 // "Getter" for online_timeout
2082 function getOnlineTimeout () {
2084 if (!isset($GLOBALS[__FUNCTION__])) {
2086 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2090 return $GLOBALS[__FUNCTION__];
2093 // "Getter" for index_home
2094 function getIndexHome () {
2096 if (!isset($GLOBALS[__FUNCTION__])) {
2098 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2102 return $GLOBALS[__FUNCTION__];
2105 // "Getter" for one_day
2106 function getOneDay () {
2108 if (!isset($GLOBALS[__FUNCTION__])) {
2110 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2114 return $GLOBALS[__FUNCTION__];
2117 // "Getter" for activate_xchange
2118 function getActivateXchange () {
2120 if (!isset($GLOBALS[__FUNCTION__])) {
2122 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2126 return $GLOBALS[__FUNCTION__];
2129 // "Getter" for img_type
2130 function getImgType () {
2132 if (!isset($GLOBALS[__FUNCTION__])) {
2134 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2138 return $GLOBALS[__FUNCTION__];
2141 // "Getter" for code_length
2142 function getCodeLength () {
2144 if (!isset($GLOBALS[__FUNCTION__])) {
2146 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2150 return $GLOBALS[__FUNCTION__];
2153 // "Getter" for least_cats
2154 function getLeastCats () {
2156 if (!isset($GLOBALS[__FUNCTION__])) {
2158 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2162 return $GLOBALS[__FUNCTION__];
2165 // "Getter" for pass_len
2166 function getPassLen () {
2168 if (!isset($GLOBALS[__FUNCTION__])) {
2170 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2174 return $GLOBALS[__FUNCTION__];
2177 // "Getter" for admin_menu
2178 function getAdminMenu () {
2180 if (!isset($GLOBALS[__FUNCTION__])) {
2182 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2186 return $GLOBALS[__FUNCTION__];
2189 // "Getter" for last_month
2190 function getLastMonth () {
2192 if (!isset($GLOBALS[__FUNCTION__])) {
2194 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2198 return $GLOBALS[__FUNCTION__];
2201 // "Getter" for max_send
2202 function getMaxSend () {
2204 if (!isset($GLOBALS[__FUNCTION__])) {
2206 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2210 return $GLOBALS[__FUNCTION__];
2213 // "Getter" for mails_page
2214 function getMailsPage () {
2216 if (!isset($GLOBALS[__FUNCTION__])) {
2218 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2222 return $GLOBALS[__FUNCTION__];
2225 // "Getter" for rand_no
2226 function getRandNo () {
2228 if (!isset($GLOBALS[__FUNCTION__])) {
2230 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2234 return $GLOBALS[__FUNCTION__];
2237 // "Getter" for __DB_NAME
2238 function getDbName () {
2240 if (!isset($GLOBALS[__FUNCTION__])) {
2242 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2246 return $GLOBALS[__FUNCTION__];
2249 // "Getter" for DOMAIN
2250 function getDomain () {
2252 if (!isset($GLOBALS[__FUNCTION__])) {
2254 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2258 return $GLOBALS[__FUNCTION__];
2261 // "Getter" for proxy_username
2262 function getProxyUsername () {
2264 if (!isset($GLOBALS[__FUNCTION__])) {
2266 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2270 return $GLOBALS[__FUNCTION__];
2273 // "Getter" for proxy_password
2274 function getProxyPassword () {
2276 if (!isset($GLOBALS[__FUNCTION__])) {
2278 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2282 return $GLOBALS[__FUNCTION__];
2285 // "Getter" for proxy_host
2286 function getProxyHost () {
2288 if (!isset($GLOBALS[__FUNCTION__])) {
2290 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2294 return $GLOBALS[__FUNCTION__];
2297 // "Getter" for proxy_port
2298 function getProxyPort () {
2300 if (!isset($GLOBALS[__FUNCTION__])) {
2302 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2306 return $GLOBALS[__FUNCTION__];
2309 // "Getter" for SMTP_HOSTNAME
2310 function getSmtpHostname () {
2312 if (!isset($GLOBALS[__FUNCTION__])) {
2314 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2318 return $GLOBALS[__FUNCTION__];
2321 // "Getter" for SMTP_USER
2322 function getSmtpUser () {
2324 if (!isset($GLOBALS[__FUNCTION__])) {
2326 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2330 return $GLOBALS[__FUNCTION__];
2333 // "Getter" for SMTP_PASSWORD
2334 function getSmtpPassword () {
2336 if (!isset($GLOBALS[__FUNCTION__])) {
2338 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2342 return $GLOBALS[__FUNCTION__];
2345 // "Getter" for points_word
2346 function getPointsWord () {
2348 if (!isset($GLOBALS[__FUNCTION__])) {
2350 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2354 return $GLOBALS[__FUNCTION__];
2357 // "Getter" for profile_lock
2358 function getProfileLock () {
2360 if (!isset($GLOBALS[__FUNCTION__])) {
2362 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2366 return $GLOBALS[__FUNCTION__];
2369 // "Getter" for url_tlock
2370 function getUrlTlock () {
2372 if (!isset($GLOBALS[__FUNCTION__])) {
2374 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2378 return $GLOBALS[__FUNCTION__];
2381 // "Getter" for title_left
2382 function getTitleLeft () {
2384 if (!isset($GLOBALS[__FUNCTION__])) {
2386 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2390 return $GLOBALS[__FUNCTION__];
2393 // "Getter" for title_right
2394 function getTitleRight () {
2396 if (!isset($GLOBALS[__FUNCTION__])) {
2398 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2402 return $GLOBALS[__FUNCTION__];
2405 // "Getter" for title_middle
2406 function getTitleMiddle () {
2408 if (!isset($GLOBALS[__FUNCTION__])) {
2410 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2414 return $GLOBALS[__FUNCTION__];
2417 // Getter for 'check_double_email'
2418 function getCheckDoubleEmail () {
2419 // Is the cache entry set?
2420 if (!isset($GLOBALS[__FUNCTION__])) {
2421 // No, so determine it
2422 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2425 // Return cached entry
2426 return $GLOBALS[__FUNCTION__];
2429 // Checks whether 'check_double_email' is 'Y'
2430 function isCheckDoubleEmailEnabled () {
2431 // Is the cache entry set?
2432 if (!isset($GLOBALS[__FUNCTION__])) {
2433 // No, so determine it
2434 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2437 // Return cached entry
2438 return $GLOBALS[__FUNCTION__];
2441 // Getter for 'display_home_in_index'
2442 function getDisplayHomeInIndex () {
2443 // Is the cache entry set?
2444 if (!isset($GLOBALS[__FUNCTION__])) {
2445 // No, so determine it
2446 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2449 // Return cached entry
2450 return $GLOBALS[__FUNCTION__];
2453 // Checks whether 'display_home_in_index' is 'Y'
2454 function isDisplayHomeInIndexEnabled () {
2455 // Is the cache entry set?
2456 if (!isset($GLOBALS[__FUNCTION__])) {
2457 // No, so determine it
2458 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2461 // Return cached entry
2462 return $GLOBALS[__FUNCTION__];
2465 // Getter for 'admin_menu_javascript'
2466 function getAdminMenuJavascript () {
2467 // Is the cache entry set?
2468 if (!isset($GLOBALS[__FUNCTION__])) {
2469 // No, so determine it
2470 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2473 // Return cached entry
2474 return $GLOBALS[__FUNCTION__];
2477 // Getter for 'points_remove_account'
2478 function getPointsRemoveAccount () {
2479 // Is the cache entry set?
2480 if (!isset($GLOBALS[__FUNCTION__])) {
2481 // No, so determine it
2482 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2485 // Return cached entry
2486 return $GLOBALS[__FUNCTION__];
2489 // Checks whether proxy configuration is used
2490 function isProxyUsed () {
2492 if (!isset($GLOBALS[__FUNCTION__])) {
2494 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2498 return $GLOBALS[__FUNCTION__];
2501 // Checks whether POST data contains selections
2502 function ifPostContainsSelections ($element = 'sel') {
2504 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2506 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2510 return $GLOBALS[__FUNCTION__][$element];
2513 // Checks whether verbose_sql is Y and returns true/false if so
2514 function isVerboseSqlEnabled () {
2516 if (!isset($GLOBALS[__FUNCTION__])) {
2518 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2522 return $GLOBALS[__FUNCTION__];
2525 // "Getter" for total user points
2526 function getTotalPoints ($userid) {
2528 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2529 // Init array for filter chain
2531 'userid' => $userid,
2535 // Run filter chain for getting more point values
2536 $data = runFilterChain('get_total_points', $data);
2539 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - getUserUsedPoints($userid);
2543 return $GLOBALS[__FUNCTION__][$userid];
2546 // Wrapper to get used points for given userid
2547 function getUserUsedPoints ($userid) {
2549 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2551 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2555 return $GLOBALS[__FUNCTION__][$userid];
2558 // Wrapper to check if url_blacklist is enabled
2559 function isUrlBlacklistEnabled () {
2561 if (!isset($GLOBALS[__FUNCTION__])) {
2563 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2567 return $GLOBALS[__FUNCTION__];
2570 // Checks whether direct payment is allowed in configuration
2571 function isDirectPaymentEnabled () {
2573 if (!isset($GLOBALS[__FUNCTION__])) {
2575 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2579 return $GLOBALS[__FUNCTION__];
2582 // Checks whether JavaScript-based admin menu is enabled
2583 function isAdminMenuJavascriptEnabled () {
2585 if (!isset($GLOBALS[__FUNCTION__])) {
2587 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
2591 return $GLOBALS[__FUNCTION__];
2594 // Wrapper to check if current task is for extension (not update)
2595 function isExtensionTask ($content) {
2597 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2599 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2603 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2606 // Getter for 'mt_start'
2607 function getMtStart () {
2608 // Is the cache entry set?
2609 if (!isset($GLOBALS[__FUNCTION__])) {
2610 // No, so determine it
2611 $GLOBALS[__FUNCTION__] = getConfig('mt_start');
2614 // Return cached entry
2615 return $GLOBALS[__FUNCTION__];
2618 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2619 function ifTesterAccountsAllowed () {
2620 // Is the cache entry set?
2621 if (!isset($GLOBALS[__FUNCTION__])) {
2622 // No, so determine it
2623 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2626 // Return cached entry
2627 return $GLOBALS[__FUNCTION__];
2630 // Wrapper to check if output mode is CSS
2631 function isCssOutputMode () {
2633 if (!isset($GLOBALS[__FUNCTION__])) {
2635 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2636 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2640 return $GLOBALS[__FUNCTION__];
2643 // Wrapper to check if output mode is HTML
2644 function isHtmlOutputMode () {
2646 if (!isset($GLOBALS[__FUNCTION__])) {
2648 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2649 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2653 return $GLOBALS[__FUNCTION__];
2656 // Wrapper to check if output mode is RAW
2657 function isRawOutputMode () {
2659 if (!isset($GLOBALS[__FUNCTION__])) {
2661 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2662 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2666 return $GLOBALS[__FUNCTION__];
2669 // Wrapper to check if output mode is AJAX
2670 function isAjaxOutputMode () {
2672 if (!isset($GLOBALS[__FUNCTION__])) {
2674 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2675 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2679 return $GLOBALS[__FUNCTION__];
2682 // Wrapper to check if output mode is image
2683 function isImageOutputMode () {
2685 if (!isset($GLOBALS[__FUNCTION__])) {
2687 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2688 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
2692 return $GLOBALS[__FUNCTION__];
2695 // Wrapper to generate a user email link
2696 function generateWrappedUserEmailLink ($email) {
2697 // Just call the inner function
2698 return generateEmailLink($email, 'user_data');
2701 // Wrapper to check if user points are locked
2702 function ifUserPointsLocked ($userid) {
2703 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2705 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2707 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2711 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2712 return $GLOBALS[__FUNCTION__][$userid];
2715 // Appends a line to an existing file or creates it instantly with given content.
2716 // This function does always add a new-line character to every line.
2717 function appendLineToFile ($file, $line) {
2718 $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2719 fwrite($fp, $line . PHP_EOL);
2723 // Wrapper for changeDataInFile() but with full path added
2724 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2726 $FQFN = getPath() . $FQFN;
2728 // Call inner function
2729 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2732 // Wrapper for changing entries in config-local.php
2733 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2734 // Call the inner function
2735 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2738 // Shortens ucfirst(strtolower()) calls
2739 function firstCharUpperCase ($str) {
2740 return ucfirst(strtolower($str));
2743 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2744 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2745 // Get the configuration entry
2746 $configValue = getConfig($configEntry);
2748 // Call inner method
2749 return createTimeSelections($configValue, $configEntry, $stamps, $align);
2752 // Shortens converting of German comma to Computer's version in POST data
2753 function convertCommaToDotInPostData ($postEntry) {
2754 // Read and convert given entry
2755 $postValue = convertCommaToDot(postRequestElement($postEntry));
2758 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
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);
2800 * Searches a multi-dimensional array (as used in many places) for given
2801 * key/value pair as taken from user comments from PHP documentation website.
2803 * @param $array An array with one or more dimensions
2804 * @param $key Key to look for
2805 * @param $value Value to look for
2806 * @param $parentIndex Parent index (ONLY INTERNAL USE!)
2807 * @return $results Resulted array or empty array if $array is no array
2808 * @author sunelbe<at>gmail<dot>com
2809 * @link http://de.php.net/manual/en/function.array-search.php#110120
2811 function search_array ($array, $key, $value, $parentIndex = NULL) {
2812 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
2813 // Init array result
2816 // Is $array really an array?
2817 if (is_array($array)) {
2818 // Search for whole array
2819 foreach ($array as $idx => $dummy) {
2820 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx);
2821 // Is dummy an array?
2822 if (is_array($dummy)) {
2823 // Then search again
2824 $subResult = search_array($dummy, $key, $value, $idx);
2825 //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
2828 $results = merge_array($results, $subResult, TRUE);
2829 } elseif ((isset($array[$key])) && ($array[$key] == $value)) {
2830 // Is found, so add it
2831 $results[$parentIndex] = $array;
2836 // Return resulting array
2837 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
2841 // Generates a YES/NO option list from given default
2842 function generateYesNoOptions ($defaultValue = '') {
2844 return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2847 // "Getter" for total available receivers
2848 function getTotalReceivers ($mode = 'normal') {
2850 $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
2856 // Wrapper "getter" to get total unconfirmed mails for given userid
2857 function getTotalUnconfirmedMails ($userid) {
2859 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2861 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
2865 return $GLOBALS[__FUNCTION__][$userid];
2868 // Checks whether 'mailer_theme' was found in session
2869 function isMailerThemeSet () {
2871 if (!isset($GLOBALS[__FUNCTION__])) {
2873 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
2877 return $GLOBALS[__FUNCTION__];
2881 * Setter for theme in session (This setter does return the success of
2882 * setSession() which is required e.g. for destroySponsorSession().
2884 function setMailerTheme ($newTheme) {
2885 // Set it in session
2886 return setSession('mailer_theme', $newTheme);
2890 * Getter for theme from session (This getter does return 'mailer_theme' from
2891 * session data or throws an error if not possible
2893 function getMailerTheme () {
2895 if (!isset($GLOBALS[__FUNCTION__])) {
2896 // Is 'mailer_theme' set?
2897 if (!isMailerThemeSet()) {
2898 // No, then abort here
2899 reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2902 // Get it and store it in cache
2903 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
2907 return $GLOBALS[__FUNCTION__];
2910 // "Getter" for last_module/last_what depending on ext-user version
2911 function getUserLastWhatName () {
2912 // Default is old one: last_module
2913 $columnName = 'last_module';
2915 // Is ext-user up-to-date?
2916 if (isExtensionInstalledAndNewer('user', '0.4.9')) {
2917 // Yes, then use new one
2918 $columnName = 'last_what';
2925 // "Getter" for all columns for given alias and separator
2926 function getAllPointColumns ($alias = NULL, $separator = ',') {
2927 // Prepare the filter array
2928 $filterData = array(
2931 'separator' => $separator
2935 $filterData = runFilterChain('get_all_point_columns', $filterData);
2937 // Return the columns
2938 return $filterData['columns'];
2941 // Checks whether the copyright footer (which breaks framesets) is enabled
2942 function ifCopyrightFooterEnabled () {
2943 // Is not unset and not 'N'?
2944 return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
2948 * Wrapper to check whether we have a "full page". This means that the actual
2949 * content is not delivered in any frame of a frameset.
2951 function isFullPage () {
2953 * The parameter 'frame' is generic and always indicates that this content
2954 * will be output into a frame. Furthermore, if a frameset is reported or
2955 * the copyright line is explicitly deactivated, this cannot be a "full
2958 // @TODO Find a way to not use direct module comparison
2959 $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
2965 // Checks whether frameset_mode is set to true
2966 function isFramesetModeEnabled () {
2968 return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
2971 // Function to determine correct 'what' value
2972 function determineWhat ($module = NULL) {
2973 // Init default 'what'
2977 if (is_null($module)) {
2979 $module = getModule();
2987 // Else try to get it from current module
2988 $what = getWhatFromModule($module);
2990 //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
2992 // Remove any spaces from variable
2993 $what = trim($what);
2997 // Default action for non-admin menus
3001 $what = secureString($what);
3008 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3009 function prependZeros ($mStretch, $length = 2) {
3010 // Return prepended string
3011 return sprintf('%0' . (int) $length . 's', $mStretch);
3014 // Wraps convertSelectionsToEpocheTime()
3015 function convertSelectionsToEpocheTimeInPostData ($id) {
3020 // Get all POST data
3021 $postData = postRequestArray();
3023 // Convert given selection id
3024 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3026 // Set the POST array back
3027 setPostRequestArray($postData);
3030 // Wraps checking if given points account type matches with given in POST data
3031 function ifPointsAccountTypeMatchesPost ($type) {
3033 exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
3036 // Gets given user's total referral
3037 function getUsersTotalReferrals ($userid, $level = NULL) {
3039 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3040 // Is the level NULL?
3041 if (is_null($level)) {
3042 // Get total amount (all levels)
3043 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
3045 // Get it from user refs
3046 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
3051 return $GLOBALS[__FUNCTION__][$userid][$level];
3054 // Gets given user's total referral
3055 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3056 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3058 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3059 // Default is all refs
3062 // Is the not level NULL?
3063 if (!is_null($level)) {
3064 // Then add referral level
3065 $add = ' AND r.`level`=' . bigintval($level);
3068 // Check for all referrals
3069 $result = SQL_QUERY_ESC("SELECT
3070 COUNT(d.`userid`) AS `cnt`
3072 `{?_MYSQL_PREFIX?}_user_data` AS d
3074 `{?_MYSQL_PREFIX?}_user_refs` AS r
3076 d.`userid`=r.`refid`
3078 d.`status` != 'CONFIRMED' AND
3086 ), __FUNCTION__, __LINE__);
3089 list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
3092 SQL_FREERESULT($result);
3096 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3097 return $GLOBALS[__FUNCTION__][$userid][$level];
3100 // Converts, if found, dollar data to get element
3101 function convertDollarDataToGetElement ($data) {
3102 // Is first char a dollar?
3103 if (substr($data, 0, 1) == chr(36)) {
3104 // Use last part for getRequestElement()
3105 $data = getRequestElement(substr($data, 1));
3112 // Wrapper function for SQL layer to speed-up things
3113 function SQL_DEBUG_ENABLED () {
3115 if (!isset($GLOBALS[__FUNCTION__])) {
3117 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3121 return $GLOBALS[__FUNCTION__];