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, $keepIndex = FALSE) {
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 // Maintain index of array2?
174 if ($keepIndex === TRUE) {
175 // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :(
176 foreach ($array2 as $key => $value) {
178 $array1[$key] = $value;
184 // Merge both together normally
185 return array_merge($array1, $array2);
189 // Check if given FQFN is a readable file
190 function isFileReadable ($FQFN) {
192 if (!isset($GLOBALS['file_readable'][$FQFN])) {
194 $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN)));
198 return $GLOBALS['file_readable'][$FQFN];
201 // Checks whether the given FQFN is a directory and not ., .. or .svn
202 function isDirectory ($FQFN) {
204 if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
206 $baseName = basename($FQFN);
209 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
213 return $GLOBALS[__FUNCTION__][$FQFN];
216 // "Getter" for the real remote IP number
217 function detectRealIpAddress () {
218 // Get remote ip from environment
219 $remoteAddr = determineRealRemoteAddress();
221 // Is removeip installed?
222 if (isExtensionActive('removeip')) {
224 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
231 // "Getter" for remote IP number
232 function detectRemoteAddr () {
233 // Get remote ip from environment
234 $remoteAddr = determineRealRemoteAddress(TRUE);
236 // Is removeip installed?
237 if (isExtensionActive('removeip')) {
239 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
246 // "Getter" for remote hostname
247 function detectRemoteHostname () {
248 // Get remote ip from environment
249 $remoteHost = getenv('REMOTE_HOST');
251 // Is removeip installed?
252 if (isExtensionActive('removeip')) {
254 $remoteHost = getAnonymousRemoteHost($remoteHost);
261 // "Getter" for user agent
262 function detectUserAgent ($alwaysReal = FALSE) {
263 // Get remote ip from environment
264 $userAgent = getenv('HTTP_USER_AGENT');
266 // Is removeip installed?
267 if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
269 $userAgent = getAnonymousUserAgent($userAgent);
276 // "Getter" for referer
277 function detectReferer () {
278 // Get remote ip from environment
279 $referer = getenv('HTTP_REFERER');
281 // Is removeip installed?
282 if (isExtensionActive('removeip')) {
284 $referer = getAnonymousReferer($referer);
291 // "Getter" for request URI
292 function detectRequestUri () {
294 return (getenv('REQUEST_URI'));
297 // "Getter" for query string
298 function detectQueryString () {
299 return str_replace('&', '&', (getenv('QUERY_STRING')));
302 // "Getter" for SERVER_NAME
303 function detectServerName () {
305 return (getenv('SERVER_NAME'));
308 // Removes any existing www. from SERVER_NAME. This is very silly but enough
309 // for our purpose here.
310 function detectDomainName () {
312 if (!isset($GLOBALS[__FUNCTION__])) {
314 $domainName = detectServerName();
316 // Is there any www. ?
317 if (substr($domainName, 0, 4) == 'www.') {
319 $domainName = substr($domainName, 4);
323 $GLOBALS[__FUNCTION__] = $domainName;
327 return $GLOBALS[__FUNCTION__];
330 // Check whether we are installing
331 function isInstalling () {
332 // Determine whether we are installing
333 if (!isset($GLOBALS['__mailer_installing'])) {
334 // Check URL (css.php/js.php need this)
335 $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing');
339 return $GLOBALS['__mailer_installing'];
342 // Check whether this script is installed
343 function isInstalled () {
345 if (!isset($GLOBALS[__FUNCTION__])) {
346 // Determine whether this script is installed
347 $GLOBALS[__FUNCTION__] = (
352 isConfigEntrySet('MXCHANGE_INSTALLED')
354 getConfig('MXCHANGE_INSTALLED') == 'Y'
358 // New config file found and loaded
359 isIncludeReadable(getCachePath() . 'config-local.php')
362 // New config file found, but not yet read
363 isIncludeReadable(getCachePath() . 'config-local.php')
366 // Only new config file is found
367 !isIncludeReadable('inc/config.php')
369 // Is installation mode
376 // Then use the cache
377 return $GLOBALS[__FUNCTION__];
380 // Check whether an admin is registered
381 function isAdminRegistered () {
383 if (!isset($GLOBALS[__FUNCTION__])) {
385 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
389 return $GLOBALS[__FUNCTION__];
392 // Checks whether the hourly reset mode is active
393 function isHourlyResetEnabled () {
394 // Now simply check it
395 return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE));
398 // Checks whether the reset mode is active
399 function isResetModeEnabled () {
400 // Now simply check it
401 return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === TRUE));
404 // Checks whether the debug mode is enabled
405 function isDebugModeEnabled () {
407 if (!isset($GLOBALS[__FUNCTION__])) {
409 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
413 return $GLOBALS[__FUNCTION__];
416 // Checks whether the debug reset is enabled
417 function isDebugResetEnabled () {
419 if (!isset($GLOBALS[__FUNCTION__])) {
421 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
425 return $GLOBALS[__FUNCTION__];
428 // Checks whether SQL debugging is enabled
429 function isSqlDebuggingEnabled () {
431 if (!isset($GLOBALS[__FUNCTION__])) {
432 // Determine if SQL debugging is enabled
433 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
437 return $GLOBALS[__FUNCTION__];
440 // Checks whether we shall debug regular expressions
441 function isDebugRegularExpressionEnabled () {
443 if (!isset($GLOBALS[__FUNCTION__])) {
445 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
449 return $GLOBALS[__FUNCTION__];
452 // Checks whether the cache instance is valid
453 function isCacheInstanceValid () {
455 if (!isset($GLOBALS[__FUNCTION__])) {
457 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
461 return $GLOBALS[__FUNCTION__];
464 // Copies a file from source to destination and verifies if that goes fine.
465 // This function should wrap the copy() command and make a nicer debug backtrace
466 // even if there is no xdebug extension installed.
467 function copyFileVerified ($source, $dest, $chmod = '') {
468 // Failed is the default
471 // Is the source file there?
472 if (!isFileReadable($source)) {
474 reportBug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
477 // Is the target directory there?
478 if (!isDirectory(dirname($dest))) {
480 reportBug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
483 // Now try to copy it
484 if (!copy($source, $dest)) {
485 // Something went wrong
486 reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
489 $GLOBALS['file_readable'][$dest] = TRUE;
492 // All fine by default
495 // If there are chmod rights set, apply them
496 if (!empty($chmod)) {
498 $status = changeMode($dest, $chmod);
505 // Wrapper function for chmod()
506 // @TODO Do some more sanity check here
507 function changeMode ($FQFN, $mode) {
508 // Is the file/directory there?
509 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
510 // Neither, so abort here
511 reportBug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
515 return chmod($FQFN, $mode);
518 // Wrapper for unlink()
519 function removeFile ($FQFN) {
520 // Is the file there?
521 if (isFileReadable($FQFN)) {
523 $GLOBALS['file_readable'][$FQFN] = FALSE;
526 return unlink($FQFN);
529 // All fine if no file was removed. If we change this to 'false' or rewrite
530 // above if() block it would be to restrictive.
534 // Wrapper for $_POST['sel']
535 function countPostSelection ($element = 'sel') {
537 if (!isset($GLOBALS[__FUNCTION__][$element])) {
539 $GLOBALS[__FUNCTION__][$element] = '0';
542 if (isPostRequestElementSet($element)) {
543 // Return counted elements
544 $GLOBALS[__FUNCTION__][$element] = countSelection(postRequestElement($element));
548 // Return cached value
549 return $GLOBALS[__FUNCTION__][$element];
552 // Checks whether the config-local.php is loaded
553 function isConfigLocalLoaded () {
554 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === TRUE));
557 // Checks whether a nickname or userid was entered and caches the result
558 function isNicknameUsed ($userid) {
559 // Is the cache there
560 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
562 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL'));
566 return $GLOBALS[__FUNCTION__][$userid];
569 // Getter for 'what' value
570 function getWhat ($strict = TRUE) {
575 if (isWhatSet($strict)) {
577 $what = $GLOBALS['__what'];
584 // Setter for 'what' value
585 function setWhat ($newWhat) {
586 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat);
587 $GLOBALS['__what'] = $newWhat;
590 // Setter for 'what' from configuration
591 function setWhatFromConfig ($configEntry) {
592 // Get 'what' from config
593 $what = getConfig($configEntry);
599 // Checks whether what is set and optionally aborts on miss
600 function isWhatSet ($strict = false) {
602 $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
604 // Should we abort here?
605 if (($strict === TRUE) && ($isset === FALSE)) {
607 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
614 // Getter for 'action' value
615 function getAction ($strict = TRUE) {
620 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
622 $action = $GLOBALS['__action'];
629 // Setter for 'action' value
630 function setAction ($newAction) {
631 $GLOBALS['__action'] = $newAction;
634 // Checks whether action is set and optionally aborts on miss
635 function isActionSet ($strict = false) {
637 $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
639 // Should we abort here?
640 if (($strict === TRUE) && ($isset === FALSE)) {
642 reportBug(__FUNCTION__, __LINE__, 'action is empty.');
649 // Getter for 'module' value
650 function getModule ($strict = TRUE) {
655 if (isModuleSet($strict)) {
657 $module = $GLOBALS['__module'];
664 // Setter for 'module' value
665 function setModule ($newModule) {
666 // Secure it and make all modules lower-case
667 $GLOBALS['__module'] = strtolower($newModule);
670 // Checks whether module is set and optionally aborts on miss
671 function isModuleSet ($strict = false) {
673 $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
675 // Should we abort here?
676 if (($strict === TRUE) && ($isset === FALSE)) {
678 reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
682 return (($isset === TRUE) && ($GLOBALS['__module'] != 'unknown')) ;
685 // Getter for 'output_mode' value
686 function getScriptOutputMode () {
688 if (!isset($GLOBALS[__FUNCTION__])) {
689 // Is the output mode set?
690 if (!isOutputModeSet()) {
691 // No, then abort here
692 reportBug(__FUNCTION__, __LINE__, 'Output mode not set.');
696 $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode'];
700 return $GLOBALS[__FUNCTION__];
703 // Setter for 'output_mode' value
704 function setOutputMode ($newOutputMode) {
705 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
706 $GLOBALS['__output_mode'] = (int) $newOutputMode;
709 // Checks whether output_mode is set and optionally aborts on miss
710 function isOutputModeSet ($strict = false) {
712 $isset = (isset($GLOBALS['__output_mode']));
714 // Should we abort here?
715 if (($strict === TRUE) && ($isset === FALSE)) {
717 reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
724 // Enables block-mode
725 function enableBlockMode ($enabled = TRUE) {
726 $GLOBALS['__block_mode'] = $enabled;
729 // Checks whether block-mode is enabled
730 function isBlockModeEnabled () {
732 if (!isset($GLOBALS['__block_mode'])) {
734 reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
738 return $GLOBALS['__block_mode'];
741 // Wrapper for redirectToUrl but URL comes from a configuration entry
742 function redirectToConfiguredUrl ($configEntry) {
744 redirectToUrl(getConfig($configEntry));
747 // Wrapper function to redirect from member-only modules to index
748 function redirectToIndexMemberOnlyModule () {
749 // Do the redirect here
750 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
753 // Wrapper function to redirect to current URL
754 function redirectToRequestUri () {
755 redirectToUrl(basename(detectRequestUri()));
758 // Wrapper function to redirect to de-refered URL
759 function redirectToDereferedUrl ($url) {
761 redirectToUrl(generateDereferrerUrl($url));
764 // Wrapper function for checking if extension is installed and newer or same version
765 function isExtensionInstalledAndNewer ($ext_name, $version) {
766 // Is an cache entry found?
767 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
769 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
771 // Cache hits should be incremented twice
772 incrementStatsEntry('cache_hits', 2);
776 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
777 return $GLOBALS[__FUNCTION__][$ext_name][$version];
780 // Wrapper function for checking if extension is installed and older than given version
781 function isExtensionInstalledAndOlder ($ext_name, $version) {
782 // Is an cache entry found?
783 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
785 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
787 // Cache hits should be incremented twice
788 incrementStatsEntry('cache_hits', 2);
792 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
793 return $GLOBALS[__FUNCTION__][$ext_name][$version];
797 function setUsername ($userName) {
798 $GLOBALS['username'] = (string) $userName;
802 function getUsername () {
804 if (!isset($GLOBALS['username'])) {
805 // No, so it has to be a guest
806 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
810 return $GLOBALS['username'];
813 // Wrapper function for installation phase
814 function isInstallationPhase () {
816 if (!isset($GLOBALS[__FUNCTION__])) {
818 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
822 return $GLOBALS[__FUNCTION__];
825 // Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
826 function isDemoModeActive () {
828 if (!isset($GLOBALS[__FUNCTION__])) {
830 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
834 return $GLOBALS[__FUNCTION__];
837 // Getter for PHP caching value
838 function getPhpCaching () {
839 return $GLOBALS['php_caching'];
842 // Checks whether the admin hash is set
843 function isAdminHashSet ($adminId) {
844 // Is the array there?
845 if (!isset($GLOBALS['cache_array']['admin'])) {
846 // Missing array should be reported
847 reportBug(__FUNCTION__, __LINE__, 'Cache not set.');
850 // Check for admin hash
851 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
854 // Setter for admin hash
855 function setAdminHash ($adminId, $hash) {
856 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
859 // Getter for current admin login
860 function getCurrentAdminLogin () {
862 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
865 if (!isset($GLOBALS[__FUNCTION__])) {
867 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
871 return $GLOBALS[__FUNCTION__];
874 // Setter for admin id (and current)
875 function setAdminId ($adminId) {
877 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
880 $status = setSession('admin_id', bigintval($adminId));
883 setCurrentAdminId($adminId);
889 // Setter for admin_last
890 function setAdminLast ($adminLast) {
892 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
895 $status = setSession('admin_last', $adminLast);
901 // Setter for admin_md5
902 function setAdminMd5 ($adminMd5) {
904 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
907 $status = setSession('admin_md5', $adminMd5);
913 // Getter for admin_md5
914 function getAdminMd5 () {
916 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
919 return getSession('admin_md5');
922 // Init user data array
923 function initUserData () {
924 // User id should not be zero
925 if (!isValidUserId(getCurrentUserId())) {
926 // Should be always valid
927 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
931 unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
932 $GLOBALS['user_data'][getCurrentUserId()] = array();
935 // Getter for user data
936 function getUserData ($column) {
937 // User id should not be zero
938 if (!isValidUserId(getCurrentUserId())) {
939 // Should be always valid
940 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
946 if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
948 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
955 // Checks whether given user data is set to 'Y'
956 function isUserDataEnabled ($column) {
958 if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
960 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
964 return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
967 // Geter for whole user data array
968 function getUserDataArray () {
970 $userid = getCurrentUserId();
972 // Is the current userid valid?
973 if (!isValidUserId($userid)) {
974 // Should be always valid
975 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
978 // Get the whole array if found
979 if (isset($GLOBALS['user_data'][$userid])) {
980 // Found, so return it
981 return $GLOBALS['user_data'][$userid];
983 // Return empty array
988 // Checks if the user data is valid, this may indicate that the user has logged
989 // in, but you should use isMember() if you want to find that out.
990 function isUserDataValid () {
991 // User id should not be zero so abort here
992 if (!isCurrentUserIdSet()) {
993 // Debug message, may be noisy
994 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
1001 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
1003 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
1006 // Return the result
1007 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1010 // Setter for current userid
1011 function setCurrentUserId ($userid) {
1013 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - ENTERED!');
1015 // Is the cache from below functions different?
1016 if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) {
1018 unsetCurrentUserId();
1022 $GLOBALS['current_userid'] = bigintval($userid);
1024 // Unset it to re-determine the actual state
1025 unset($GLOBALS['is_userdata_valid'][$userid]);
1028 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - EXIT!');
1031 // Getter for current userid
1032 function getCurrentUserId () {
1034 if (!isset($GLOBALS[__FUNCTION__])) {
1035 // Userid must be set before it can be used
1036 if (!isCurrentUserIdSet()) {
1038 reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1041 // Set userid in cache
1042 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1046 return $GLOBALS[__FUNCTION__];
1049 // Checks if current userid is set
1050 function isCurrentUserIdSet () {
1052 if (!isset($GLOBALS[__FUNCTION__])) {
1054 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1058 return $GLOBALS[__FUNCTION__];
1061 // Unsets current userid
1062 function unsetCurrentUserId () {
1064 if (isset($GLOBALS['current_userid'])) {
1066 unset($GLOBALS['isValidUserId'][$GLOBALS['current_userid']]);
1069 // Unset all cache entries
1070 unset($GLOBALS['current_userid']);
1071 unset($GLOBALS['getCurrentUserId']);
1072 unset($GLOBALS['isCurrentUserIdSet']);
1075 // Checks whether we are debugging template cache
1076 function isDebuggingTemplateCache () {
1078 if (!isset($GLOBALS[__FUNCTION__])) {
1080 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1084 return $GLOBALS[__FUNCTION__];
1087 // Wrapper for fetchUserData() and getUserData() calls
1088 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1089 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1091 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1095 // Can we fetch the user data?
1096 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1097 // Now get the data back
1098 $data = getUserData($valueColumn);
1102 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1106 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1107 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1110 // Wrapper for strpos() to ease porting from deprecated ereg() function
1111 function isInString ($needle, $haystack) {
1112 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== FALSE));
1113 return (strpos($haystack, $needle) !== FALSE);
1116 // Wrapper for strpos() to ease porting from deprecated eregi() function
1117 // This function is case-insensitive
1118 function isInStringIgnoreCase ($needle, $haystack) {
1119 return (isInString(strtolower($needle), strtolower($haystack)));
1122 // Wrapper to check for if fatal errors where detected
1123 function ifFatalErrorsDetected () {
1124 // Just call the inner function
1125 return (getTotalFatalErrors() > 0);
1128 // Checks whether a HTTP status has been set
1129 function isHttpStatusSet () {
1130 // Is it set and not empty?
1131 return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1134 // Setter for HTTP status
1135 function setHttpStatus ($status) {
1136 $GLOBALS['http_status'] = (string) $status;
1139 // Getter for HTTP status
1140 function getHttpStatus () {
1141 // Is the status set?
1142 if (!isHttpStatusSet()) {
1144 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1148 return $GLOBALS['http_status'];
1152 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1153 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1155 * ----------------------------------------------------------------------------
1156 * If you want to redirect, please use redirectToUrl(); instead
1157 * ----------------------------------------------------------------------------
1159 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1161 * @link http://support.microsoft.com/kb/q176113/
1162 * @author Andreas Gohr <andi@splitbrain.org>
1165 function sendRawRedirect ($url) {
1166 // Clear output buffer
1167 clearOutputBuffer();
1169 // Clear own output buffer
1170 $GLOBALS['__output'] = '';
1172 // To make redirects working (no content type), output mode must be raw
1175 // Send helping header
1176 setHttpStatus('302 Found');
1178 // always close the session
1179 session_write_close();
1181 // Revert entity &
1182 $url = str_replace('&', '&', $url);
1184 // check if running on IIS < 6 with CGI-PHP
1185 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1186 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1187 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1188 ($matches[1] < 6)) {
1189 // Send the IIS header
1190 addHttpHeader('Refresh: 0;url=' . $url);
1192 // Send generic header
1193 addHttpHeader('Location: ' . $url);
1200 // Determines the country of the given user id
1201 function determineCountry ($userid) {
1203 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1204 // Default is 'invalid'
1205 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1207 // Is extension country active?
1208 if (isExtensionActive('country')) {
1209 // Determine the right country code through the country id
1210 $id = getUserData('country_code');
1212 // Then handle it over
1213 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1215 // Get raw code from user data
1216 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1221 return $GLOBALS[__FUNCTION__][$userid];
1224 // "Getter" for total confirmed user accounts
1225 function getTotalConfirmedUser () {
1227 if (!isset($GLOBALS[__FUNCTION__])) {
1229 if (isExtensionActive('user')) {
1230 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1232 $GLOBALS[__FUNCTION__] = 0;
1236 // Return cached value
1237 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1238 return $GLOBALS[__FUNCTION__];
1241 // "Getter" for total unconfirmed user accounts
1242 function getTotalUnconfirmedUser () {
1244 if (!isset($GLOBALS[__FUNCTION__])) {
1246 if (isExtensionActive('user')) {
1247 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1249 $GLOBALS[__FUNCTION__] = 0;
1253 // Return cached value
1254 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1255 return $GLOBALS[__FUNCTION__];
1258 // "Getter" for total locked user accounts
1259 function getTotalLockedUser () {
1261 if (!isset($GLOBALS[__FUNCTION__])) {
1263 if (isExtensionActive('user')) {
1264 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1266 $GLOBALS[__FUNCTION__] = 0;
1270 // Return cached value
1271 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1272 return $GLOBALS[__FUNCTION__];
1275 // "Getter" for total locked user accounts
1276 function getTotalRandomRefidUser () {
1278 if (!isset($GLOBALS[__FUNCTION__])) {
1280 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1281 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
1283 $GLOBALS[__FUNCTION__] = 0;
1287 // Return cached value
1288 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1289 return $GLOBALS[__FUNCTION__];
1292 // Is given userid valid?
1293 function isValidUserId ($userid) {
1295 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid);
1298 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1300 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1304 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',result=' . intval($GLOBALS[__FUNCTION__][$userid]));
1305 return $GLOBALS[__FUNCTION__][$userid];
1309 function encodeEntities ($str) {
1311 $str = secureString($str, TRUE, TRUE);
1313 // Encode dollar sign as well
1314 $str = str_replace('$', '$', $str);
1320 // "Getter" for date from patch_ctime
1321 function getDateFromRepository () {
1323 if (!isset($GLOBALS[__FUNCTION__])) {
1325 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1329 return $GLOBALS[__FUNCTION__];
1332 // "Getter" for date/time from patch_ctime
1333 function getDateTimeFromRepository () {
1335 if (!isset($GLOBALS[__FUNCTION__])) {
1337 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1341 return $GLOBALS[__FUNCTION__];
1344 // Getter for current year (default)
1345 function getYear ($timestamp = NULL) {
1347 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1349 if (is_null($timestamp)) {
1350 $timestamp = time();
1354 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1358 return $GLOBALS[__FUNCTION__][$timestamp];
1361 // Getter for current month (default)
1362 function getMonth ($timestamp = NULL) {
1364 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1365 // If null is set, use time()
1366 if (is_null($timestamp)) {
1367 // Use time() which is current timestamp
1368 $timestamp = time();
1372 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1376 return $GLOBALS[__FUNCTION__][$timestamp];
1379 // Getter for current hour (default)
1380 function getHour ($timestamp = NULL) {
1382 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1384 if (is_null($timestamp)) {
1385 $timestamp = time();
1389 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1393 return $GLOBALS[__FUNCTION__][$timestamp];
1396 // Getter for current day (default)
1397 function getDay ($timestamp = NULL) {
1399 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1401 if (is_null($timestamp)) {
1402 $timestamp = time();
1406 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1410 return $GLOBALS[__FUNCTION__][$timestamp];
1413 // Getter for current week (default)
1414 function getWeek ($timestamp = NULL) {
1416 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1418 if (is_null($timestamp)) $timestamp = time();
1421 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1425 return $GLOBALS[__FUNCTION__][$timestamp];
1428 // Getter for current short_hour (default)
1429 function getShortHour ($timestamp = NULL) {
1431 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1433 if (is_null($timestamp)) $timestamp = time();
1436 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1440 return $GLOBALS[__FUNCTION__][$timestamp];
1443 // Getter for current long_hour (default)
1444 function getLongHour ($timestamp = NULL) {
1446 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1448 if (is_null($timestamp)) $timestamp = time();
1451 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1455 return $GLOBALS[__FUNCTION__][$timestamp];
1458 // Getter for current second (default)
1459 function getSecond ($timestamp = NULL) {
1461 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1463 if (is_null($timestamp)) $timestamp = time();
1466 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1470 return $GLOBALS[__FUNCTION__][$timestamp];
1473 // Getter for current minute (default)
1474 function getMinute ($timestamp = NULL) {
1476 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1478 if (is_null($timestamp)) $timestamp = time();
1481 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1485 return $GLOBALS[__FUNCTION__][$timestamp];
1488 // Checks whether the title decoration is enabled
1489 function isTitleDecorationEnabled () {
1491 if (!isset($GLOBALS[__FUNCTION__])) {
1493 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1497 return $GLOBALS[__FUNCTION__];
1500 // Checks whether filter usage updates are enabled (expensive queries!)
1501 function isFilterUsageUpdateEnabled () {
1503 if (!isset($GLOBALS[__FUNCTION__])) {
1505 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1509 return $GLOBALS[__FUNCTION__];
1512 // Checks whether debugging of weekly resets is enabled
1513 function isWeeklyResetDebugEnabled () {
1515 if (!isset($GLOBALS[__FUNCTION__])) {
1517 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1521 return $GLOBALS[__FUNCTION__];
1524 // Checks whether debugging of monthly resets is enabled
1525 function isMonthlyResetDebugEnabled () {
1527 if (!isset($GLOBALS[__FUNCTION__])) {
1529 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1533 return $GLOBALS[__FUNCTION__];
1536 // Checks whether displaying of debug SQLs are enabled
1537 function isDisplayDebugSqlEnabled () {
1539 if (!isset($GLOBALS[__FUNCTION__])) {
1541 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1545 return $GLOBALS[__FUNCTION__];
1548 // Checks whether module title is enabled
1549 function isModuleTitleEnabled () {
1551 if (!isset($GLOBALS[__FUNCTION__])) {
1553 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1557 return $GLOBALS[__FUNCTION__];
1560 // Checks whether what title is enabled
1561 function isWhatTitleEnabled () {
1563 if (!isset($GLOBALS[__FUNCTION__])) {
1565 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1569 return $GLOBALS[__FUNCTION__];
1572 // Checks whether stats are enabled
1573 function ifInternalStatsEnabled () {
1575 if (!isset($GLOBALS[__FUNCTION__])) {
1576 // Then determine it
1577 $GLOBALS[__FUNCTION__] = (getConfig('internal_stats') == 'Y');
1580 // Return cached value
1581 return $GLOBALS[__FUNCTION__];
1584 // Checks whether admin-notification of certain user actions is enabled
1585 function isAdminNotificationEnabled () {
1587 if (!isset($GLOBALS[__FUNCTION__])) {
1589 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1593 return $GLOBALS[__FUNCTION__];
1596 // Checks whether random referral id selection is enabled
1597 function isRandomReferralIdEnabled () {
1599 if (!isset($GLOBALS[__FUNCTION__])) {
1601 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1605 return $GLOBALS[__FUNCTION__];
1608 // "Getter" for default language
1609 function getDefaultLanguage () {
1611 if (!isset($GLOBALS[__FUNCTION__])) {
1613 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1617 return $GLOBALS[__FUNCTION__];
1620 // "Getter" for default referral id
1621 function getDefRefid () {
1623 if (!isset($GLOBALS[__FUNCTION__])) {
1625 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1629 return $GLOBALS[__FUNCTION__];
1632 // "Getter" for path
1633 function getPath () {
1635 if (!isset($GLOBALS[__FUNCTION__])) {
1637 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1641 return $GLOBALS[__FUNCTION__];
1645 function getUrl () {
1647 if (!isset($GLOBALS[__FUNCTION__])) {
1649 $GLOBALS[__FUNCTION__] = getConfig('URL');
1653 return $GLOBALS[__FUNCTION__];
1656 // "Getter" for cache_path
1657 function getCachePath () {
1659 if (!isset($GLOBALS[__FUNCTION__])) {
1661 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1665 return $GLOBALS[__FUNCTION__];
1668 // "Getter" for secret_key
1669 function getSecretKey () {
1671 if (!isset($GLOBALS[__FUNCTION__])) {
1673 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1677 return $GLOBALS[__FUNCTION__];
1680 // "Getter" for SITE_KEY
1681 function getSiteKey () {
1683 if (!isset($GLOBALS[__FUNCTION__])) {
1685 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1689 return $GLOBALS[__FUNCTION__];
1692 // "Getter" for DATE_KEY
1693 function getDateKey () {
1695 if (!isset($GLOBALS[__FUNCTION__])) {
1697 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1701 return $GLOBALS[__FUNCTION__];
1704 // "Getter" for master_salt
1705 function getMasterSalt () {
1707 if (!isset($GLOBALS[__FUNCTION__])) {
1709 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1713 return $GLOBALS[__FUNCTION__];
1716 // "Getter" for prime
1717 function getPrime () {
1719 if (!isset($GLOBALS[__FUNCTION__])) {
1721 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1725 return $GLOBALS[__FUNCTION__];
1728 // "Getter" for encrypt_separator
1729 function getEncryptSeparator () {
1731 if (!isset($GLOBALS[__FUNCTION__])) {
1733 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1737 return $GLOBALS[__FUNCTION__];
1740 // "Getter" for mysql_prefix
1741 function getMysqlPrefix () {
1743 if (!isset($GLOBALS[__FUNCTION__])) {
1745 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1749 return $GLOBALS[__FUNCTION__];
1752 // "Getter" for table_type
1753 function getTableType () {
1755 if (!isset($GLOBALS[__FUNCTION__])) {
1757 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1761 return $GLOBALS[__FUNCTION__];
1764 // "Getter" for salt_length
1765 function getSaltLength () {
1767 if (!isset($GLOBALS[__FUNCTION__])) {
1769 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1773 return $GLOBALS[__FUNCTION__];
1776 // "Getter" for output_mode
1777 function getOutputMode () {
1779 if (!isset($GLOBALS[__FUNCTION__])) {
1781 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1785 return $GLOBALS[__FUNCTION__];
1788 // "Getter" for full_version
1789 function getFullVersion () {
1791 if (!isset($GLOBALS[__FUNCTION__])) {
1793 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1797 return $GLOBALS[__FUNCTION__];
1800 // "Getter" for title
1801 function getTitle () {
1803 if (!isset($GLOBALS[__FUNCTION__])) {
1805 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1809 return $GLOBALS[__FUNCTION__];
1812 // "Getter" for curr_svn_revision
1813 function getCurrentRepositoryRevision () {
1815 if (!isset($GLOBALS[__FUNCTION__])) {
1817 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1821 return $GLOBALS[__FUNCTION__];
1824 // "Getter" for server_url
1825 function getServerUrl () {
1827 if (!isset($GLOBALS[__FUNCTION__])) {
1829 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1833 return $GLOBALS[__FUNCTION__];
1836 // "Getter" for mt_word
1837 function getMtWord () {
1839 if (!isset($GLOBALS[__FUNCTION__])) {
1841 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1845 return $GLOBALS[__FUNCTION__];
1848 // "Getter" for mt_word2
1849 function getMtWord2 () {
1851 if (!isset($GLOBALS[__FUNCTION__])) {
1853 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1857 return $GLOBALS[__FUNCTION__];
1860 // "Getter" for mt_word3
1861 function getMtWord3 () {
1863 if (!isset($GLOBALS[__FUNCTION__])) {
1865 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
1869 return $GLOBALS[__FUNCTION__];
1872 // "Getter" for START_TDAY
1873 function getStartTday () {
1875 if (!isset($GLOBALS[__FUNCTION__])) {
1877 $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
1881 return $GLOBALS[__FUNCTION__];
1884 // "Getter" for START_YDAY
1885 function getStartYday () {
1887 if (!isset($GLOBALS[__FUNCTION__])) {
1889 $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
1893 return $GLOBALS[__FUNCTION__];
1896 // "Getter" for main_title
1897 function getMainTitle () {
1899 if (!isset($GLOBALS[__FUNCTION__])) {
1901 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1905 return $GLOBALS[__FUNCTION__];
1908 // "Getter" for file_hash
1909 function getFileHash () {
1911 if (!isset($GLOBALS[__FUNCTION__])) {
1913 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1917 return $GLOBALS[__FUNCTION__];
1920 // "Getter" for pass_scramble
1921 function getPassScramble () {
1923 if (!isset($GLOBALS[__FUNCTION__])) {
1925 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1929 return $GLOBALS[__FUNCTION__];
1932 // "Getter" for ap_inactive_since
1933 function getApInactiveSince () {
1935 if (!isset($GLOBALS[__FUNCTION__])) {
1937 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1941 return $GLOBALS[__FUNCTION__];
1944 // "Getter" for user_min_confirmed
1945 function getUserMinConfirmed () {
1947 if (!isset($GLOBALS[__FUNCTION__])) {
1949 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1953 return $GLOBALS[__FUNCTION__];
1956 // "Getter" for auto_purge
1957 function getAutoPurge () {
1959 if (!isset($GLOBALS[__FUNCTION__])) {
1961 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1965 return $GLOBALS[__FUNCTION__];
1968 // "Getter" for bonus_userid
1969 function getBonusUserid () {
1971 if (!isset($GLOBALS[__FUNCTION__])) {
1973 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1977 return $GLOBALS[__FUNCTION__];
1980 // "Getter" for ap_inactive_time
1981 function getApInactiveTime () {
1983 if (!isset($GLOBALS[__FUNCTION__])) {
1985 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1989 return $GLOBALS[__FUNCTION__];
1992 // "Getter" for ap_dm_timeout
1993 function getApDmTimeout () {
1995 if (!isset($GLOBALS[__FUNCTION__])) {
1997 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
2001 return $GLOBALS[__FUNCTION__];
2004 // "Getter" for ap_tasks_time
2005 function getApTasksTime () {
2007 if (!isset($GLOBALS[__FUNCTION__])) {
2009 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
2013 return $GLOBALS[__FUNCTION__];
2016 // "Getter" for ap_unconfirmed_time
2017 function getApUnconfirmedTime () {
2019 if (!isset($GLOBALS[__FUNCTION__])) {
2021 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
2025 return $GLOBALS[__FUNCTION__];
2028 // "Getter" for points
2029 function getPoints () {
2031 if (!isset($GLOBALS[__FUNCTION__])) {
2033 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
2037 return $GLOBALS[__FUNCTION__];
2040 // "Getter" for slogan
2041 function getSlogan () {
2043 if (!isset($GLOBALS[__FUNCTION__])) {
2045 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
2049 return $GLOBALS[__FUNCTION__];
2052 // "Getter" for copy
2053 function getCopy () {
2055 if (!isset($GLOBALS[__FUNCTION__])) {
2057 $GLOBALS[__FUNCTION__] = getConfig('COPY');
2061 return $GLOBALS[__FUNCTION__];
2064 // "Getter" for webmaster
2065 function getWebmaster () {
2067 if (!isset($GLOBALS[__FUNCTION__])) {
2069 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
2073 return $GLOBALS[__FUNCTION__];
2076 // "Getter" for sql_count
2077 function getSqlCount () {
2079 if (!isset($GLOBALS[__FUNCTION__])) {
2081 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2085 return $GLOBALS[__FUNCTION__];
2088 // "Getter" for num_templates
2089 function getNumTemplates () {
2091 if (!isset($GLOBALS[__FUNCTION__])) {
2093 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2097 return $GLOBALS[__FUNCTION__];
2100 // "Getter" for dns_cache_timeout
2101 function getDnsCacheTimeout () {
2103 if (!isset($GLOBALS[__FUNCTION__])) {
2105 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2109 return $GLOBALS[__FUNCTION__];
2112 // "Getter" for menu_blur_spacer
2113 function getMenuBlurSpacer () {
2115 if (!isset($GLOBALS[__FUNCTION__])) {
2117 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2121 return $GLOBALS[__FUNCTION__];
2124 // "Getter" for points_register
2125 function getPointsRegister () {
2127 if (!isset($GLOBALS[__FUNCTION__])) {
2129 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2133 return $GLOBALS[__FUNCTION__];
2136 // "Getter" for points_ref
2137 function getPointsRef () {
2139 if (!isset($GLOBALS[__FUNCTION__])) {
2141 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2145 return $GLOBALS[__FUNCTION__];
2148 // "Getter" for ref_payout
2149 function getRefPayout () {
2151 if (!isset($GLOBALS[__FUNCTION__])) {
2153 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2157 return $GLOBALS[__FUNCTION__];
2160 // "Getter" for online_timeout
2161 function getOnlineTimeout () {
2163 if (!isset($GLOBALS[__FUNCTION__])) {
2165 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2169 return $GLOBALS[__FUNCTION__];
2172 // "Getter" for index_home
2173 function getIndexHome () {
2175 if (!isset($GLOBALS[__FUNCTION__])) {
2177 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2181 return $GLOBALS[__FUNCTION__];
2184 // "Getter" for one_day
2185 function getOneDay () {
2187 if (!isset($GLOBALS[__FUNCTION__])) {
2189 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2193 return $GLOBALS[__FUNCTION__];
2196 // "Getter" for activate_xchange
2197 function getActivateXchange () {
2199 if (!isset($GLOBALS[__FUNCTION__])) {
2201 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2205 return $GLOBALS[__FUNCTION__];
2208 // "Getter" for img_type
2209 function getImgType () {
2211 if (!isset($GLOBALS[__FUNCTION__])) {
2213 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2217 return $GLOBALS[__FUNCTION__];
2220 // "Getter" for code_length
2221 function getCodeLength () {
2223 if (!isset($GLOBALS[__FUNCTION__])) {
2225 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2229 return $GLOBALS[__FUNCTION__];
2232 // "Getter" for least_cats
2233 function getLeastCats () {
2235 if (!isset($GLOBALS[__FUNCTION__])) {
2237 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2241 return $GLOBALS[__FUNCTION__];
2244 // "Getter" for pass_len
2245 function getPassLen () {
2247 if (!isset($GLOBALS[__FUNCTION__])) {
2249 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2253 return $GLOBALS[__FUNCTION__];
2256 // "Getter" for admin_menu
2257 function getAdminMenu () {
2259 if (!isset($GLOBALS[__FUNCTION__])) {
2261 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2265 return $GLOBALS[__FUNCTION__];
2268 // "Getter" for last_month
2269 function getLastMonth () {
2271 if (!isset($GLOBALS[__FUNCTION__])) {
2273 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2277 return $GLOBALS[__FUNCTION__];
2280 // "Getter" for max_send
2281 function getMaxSend () {
2283 if (!isset($GLOBALS[__FUNCTION__])) {
2285 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2289 return $GLOBALS[__FUNCTION__];
2292 // "Getter" for mails_page
2293 function getMailsPage () {
2295 if (!isset($GLOBALS[__FUNCTION__])) {
2297 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2301 return $GLOBALS[__FUNCTION__];
2304 // "Getter" for rand_no
2305 function getRandNo () {
2307 if (!isset($GLOBALS[__FUNCTION__])) {
2309 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2313 return $GLOBALS[__FUNCTION__];
2316 // "Getter" for __DB_NAME
2317 function getDbName () {
2319 if (!isset($GLOBALS[__FUNCTION__])) {
2321 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2325 return $GLOBALS[__FUNCTION__];
2328 // "Getter" for DOMAIN
2329 function getDomain () {
2331 if (!isset($GLOBALS[__FUNCTION__])) {
2333 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2337 return $GLOBALS[__FUNCTION__];
2340 // "Getter" for proxy_username
2341 function getProxyUsername () {
2343 if (!isset($GLOBALS[__FUNCTION__])) {
2345 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2349 return $GLOBALS[__FUNCTION__];
2352 // "Getter" for proxy_password
2353 function getProxyPassword () {
2355 if (!isset($GLOBALS[__FUNCTION__])) {
2357 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2361 return $GLOBALS[__FUNCTION__];
2364 // "Getter" for proxy_host
2365 function getProxyHost () {
2367 if (!isset($GLOBALS[__FUNCTION__])) {
2369 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2373 return $GLOBALS[__FUNCTION__];
2376 // "Getter" for proxy_port
2377 function getProxyPort () {
2379 if (!isset($GLOBALS[__FUNCTION__])) {
2381 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2385 return $GLOBALS[__FUNCTION__];
2388 // "Getter" for SMTP_HOSTNAME
2389 function getSmtpHostname () {
2391 if (!isset($GLOBALS[__FUNCTION__])) {
2393 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2397 return $GLOBALS[__FUNCTION__];
2400 // "Getter" for SMTP_USER
2401 function getSmtpUser () {
2403 if (!isset($GLOBALS[__FUNCTION__])) {
2405 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2409 return $GLOBALS[__FUNCTION__];
2412 // "Getter" for SMTP_PASSWORD
2413 function getSmtpPassword () {
2415 if (!isset($GLOBALS[__FUNCTION__])) {
2417 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2421 return $GLOBALS[__FUNCTION__];
2424 // "Getter" for points_word
2425 function getPointsWord () {
2427 if (!isset($GLOBALS[__FUNCTION__])) {
2429 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2433 return $GLOBALS[__FUNCTION__];
2436 // "Getter" for profile_lock
2437 function getProfileLock () {
2439 if (!isset($GLOBALS[__FUNCTION__])) {
2441 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2445 return $GLOBALS[__FUNCTION__];
2448 // "Getter" for url_tlock
2449 function getUrlTlock () {
2451 if (!isset($GLOBALS[__FUNCTION__])) {
2453 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2457 return $GLOBALS[__FUNCTION__];
2460 // "Getter" for title_left
2461 function getTitleLeft () {
2463 if (!isset($GLOBALS[__FUNCTION__])) {
2465 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2469 return $GLOBALS[__FUNCTION__];
2472 // "Getter" for title_right
2473 function getTitleRight () {
2475 if (!isset($GLOBALS[__FUNCTION__])) {
2477 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2481 return $GLOBALS[__FUNCTION__];
2484 // "Getter" for title_middle
2485 function getTitleMiddle () {
2487 if (!isset($GLOBALS[__FUNCTION__])) {
2489 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2493 return $GLOBALS[__FUNCTION__];
2496 // Getter for 'check_double_email'
2497 function getCheckDoubleEmail () {
2498 // Is the cache entry set?
2499 if (!isset($GLOBALS[__FUNCTION__])) {
2500 // No, so determine it
2501 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2504 // Return cached entry
2505 return $GLOBALS[__FUNCTION__];
2508 // Checks whether 'check_double_email' is 'Y'
2509 function isCheckDoubleEmailEnabled () {
2510 // Is the cache entry set?
2511 if (!isset($GLOBALS[__FUNCTION__])) {
2512 // No, so determine it
2513 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2516 // Return cached entry
2517 return $GLOBALS[__FUNCTION__];
2520 // Getter for 'display_home_in_index'
2521 function getDisplayHomeInIndex () {
2522 // Is the cache entry set?
2523 if (!isset($GLOBALS[__FUNCTION__])) {
2524 // No, so determine it
2525 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2528 // Return cached entry
2529 return $GLOBALS[__FUNCTION__];
2532 // Checks whether 'display_home_in_index' is 'Y'
2533 function isDisplayHomeInIndexEnabled () {
2534 // Is the cache entry set?
2535 if (!isset($GLOBALS[__FUNCTION__])) {
2536 // No, so determine it
2537 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2540 // Return cached entry
2541 return $GLOBALS[__FUNCTION__];
2544 // Getter for 'admin_menu_javascript'
2545 function getAdminMenuJavascript () {
2546 // Is the cache entry set?
2547 if (!isset($GLOBALS[__FUNCTION__])) {
2548 // No, so determine it
2549 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2552 // Return cached entry
2553 return $GLOBALS[__FUNCTION__];
2556 // Getter for 'points_remove_account'
2557 function getPointsRemoveAccount () {
2558 // Is the cache entry set?
2559 if (!isset($GLOBALS[__FUNCTION__])) {
2560 // No, so determine it
2561 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2564 // Return cached entry
2565 return $GLOBALS[__FUNCTION__];
2568 // Checks whether proxy configuration is used
2569 function isProxyUsed () {
2571 if (!isset($GLOBALS[__FUNCTION__])) {
2573 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2577 return $GLOBALS[__FUNCTION__];
2580 // Checks whether POST data contains selections
2581 function ifPostContainsSelections ($element = 'sel') {
2583 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2585 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2589 return $GLOBALS[__FUNCTION__][$element];
2592 // Checks whether verbose_sql is Y and returns true/false if so
2593 function isVerboseSqlEnabled () {
2595 if (!isset($GLOBALS[__FUNCTION__])) {
2597 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2601 return $GLOBALS[__FUNCTION__];
2604 // "Getter" for total user points
2605 function getTotalPoints ($userid) {
2607 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2608 // Init array for filter chain
2610 'userid' => $userid,
2614 // Run filter chain for getting more point values
2615 $data = runFilterChain('get_total_points', $data);
2618 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - getUserUsedPoints($userid);
2622 return $GLOBALS[__FUNCTION__][$userid];
2625 // Wrapper to get used points for given userid
2626 function getUserUsedPoints ($userid) {
2628 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2630 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2634 return $GLOBALS[__FUNCTION__][$userid];
2637 // Wrapper to check if url_blacklist is enabled
2638 function isUrlBlacklistEnabled () {
2640 if (!isset($GLOBALS[__FUNCTION__])) {
2642 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2646 return $GLOBALS[__FUNCTION__];
2649 // Checks whether direct payment is allowed in configuration
2650 function isDirectPaymentEnabled () {
2652 if (!isset($GLOBALS[__FUNCTION__])) {
2654 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2658 return $GLOBALS[__FUNCTION__];
2661 // Checks whether JavaScript-based admin menu is enabled
2662 function isAdminMenuJavascriptEnabled () {
2664 if (!isset($GLOBALS[__FUNCTION__])) {
2666 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
2670 return $GLOBALS[__FUNCTION__];
2673 // Wrapper to check if current task is for extension (not update)
2674 function isExtensionTask ($content) {
2676 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2678 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2682 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2685 // Getter for 'mt_start'
2686 function getMtStart () {
2687 // Is the cache entry set?
2688 if (!isset($GLOBALS[__FUNCTION__])) {
2689 // No, so determine it
2690 $GLOBALS[__FUNCTION__] = getConfig('mt_start');
2693 // Return cached entry
2694 return $GLOBALS[__FUNCTION__];
2697 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2698 function ifTesterAccountsAllowed () {
2699 // Is the cache entry set?
2700 if (!isset($GLOBALS[__FUNCTION__])) {
2701 // No, so determine it
2702 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2705 // Return cached entry
2706 return $GLOBALS[__FUNCTION__];
2709 // Wrapper to check if output mode is CSS
2710 function isCssOutputMode () {
2712 if (!isset($GLOBALS[__FUNCTION__])) {
2714 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2715 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2719 return $GLOBALS[__FUNCTION__];
2722 // Wrapper to check if output mode is HTML
2723 function isHtmlOutputMode () {
2725 if (!isset($GLOBALS[__FUNCTION__])) {
2727 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2728 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2732 return $GLOBALS[__FUNCTION__];
2735 // Wrapper to check if output mode is RAW
2736 function isRawOutputMode () {
2738 if (!isset($GLOBALS[__FUNCTION__])) {
2740 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2741 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2745 return $GLOBALS[__FUNCTION__];
2748 // Wrapper to check if output mode is AJAX
2749 function isAjaxOutputMode () {
2751 if (!isset($GLOBALS[__FUNCTION__])) {
2753 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2754 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2758 return $GLOBALS[__FUNCTION__];
2761 // Wrapper to check if output mode is image
2762 function isImageOutputMode () {
2764 if (!isset($GLOBALS[__FUNCTION__])) {
2766 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2767 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
2771 return $GLOBALS[__FUNCTION__];
2774 // Wrapper to generate a user email link
2775 function generateWrappedUserEmailLink ($email) {
2776 // Just call the inner function
2777 return generateEmailLink($email, 'user_data');
2780 // Wrapper to check if user points are locked
2781 function ifUserPointsLocked ($userid) {
2782 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2784 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2786 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2790 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2791 return $GLOBALS[__FUNCTION__][$userid];
2794 // Appends a line to an existing file or creates it instantly with given content.
2795 // This function does always add a new-line character to every line.
2796 function appendLineToFile ($file, $line) {
2797 $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2798 fwrite($fp, $line . chr(10));
2802 // Wrapper for changeDataInFile() but with full path added
2803 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2805 $FQFN = getPath() . $FQFN;
2807 // Call inner function
2808 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2811 // Wrapper for changing entries in config-local.php
2812 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
2813 // Call the inner function
2814 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
2817 // Shortens ucfirst(strtolower()) calls
2818 function firstCharUpperCase ($str) {
2819 return ucfirst(strtolower($str));
2822 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2823 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2824 // Get the configuration entry
2825 $configValue = getConfig($configEntry);
2827 // Call inner method
2828 return createTimeSelections($configValue, $configEntry, $stamps, $align);
2831 // Shortens converting of German comma to Computer's version in POST data
2832 function convertCommaToDotInPostData ($postEntry) {
2833 // Read and convert given entry
2834 $postValue = convertCommaToDot(postRequestElement($postEntry));
2837 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
2839 // ... and set it again
2840 setPostRequestElement($postEntry, $postValue);
2843 // Converts German commas to Computer's version in all entries
2844 function convertCommaToDotInPostDataArray ($postEntries) {
2845 // Replace german decimal comma with computer decimal dot
2846 foreach ($postEntries as $entry) {
2847 // Is the entry there?
2848 if (isPostRequestElementSet($entry)) {
2850 convertCommaToDotInPostData($entry);
2856 * Parses a string into a US formated float variable, taken from user comments
2857 * from PHP documentation website.
2859 * @param $floatString A string holding a float expression
2860 * @return $float Corresponding float variable
2861 * @author chris<at>georgakopoulos<dot>com
2862 * @link http://de.php.net/manual/en/function.floatval.php#92563
2864 function parseFloat ($floatString){
2866 $LocaleInfo = localeconv();
2868 // Remove thousand separators
2869 $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
2871 // Convert decimal point
2872 $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2874 // Return float value of converted string
2875 return floatval($floatString);
2879 * Searches a multi-dimensional array (as used in many places) for given
2880 * key/value pair as taken from user comments from PHP documentation website.
2882 * @param $array An array with one or more dimensions
2883 * @param $key Key to look for
2884 * @param $value Value to look for
2885 * @param $parentIndex Parent index (ONLY INTERNAL USE!)
2886 * @return $results Resulted array or empty array if $array is no array
2887 * @author sunelbe<at>gmail<dot>com
2888 * @link http://de.php.net/manual/en/function.array-search.php#110120
2890 function search_array ($array, $key, $value, $parentIndex = NULL) {
2891 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
2892 // Init array result
2895 // Is $array really an array?
2896 if (is_array($array)) {
2897 // Search for whole array
2898 foreach ($array as $idx => $dummy) {
2899 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx);
2900 // Is dummy an array?
2901 if (is_array($dummy)) {
2902 // Then search again
2903 $subResult = search_array($dummy, $key, $value, $idx);
2904 //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
2907 $results = merge_array($results, $subResult, TRUE);
2908 } elseif ((isset($array[$key])) && ($array[$key] == $value)) {
2909 // Is found, so add it
2910 $results[$parentIndex] = $array;
2915 // Return resulting array
2916 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
2920 // Generates a YES/NO option list from given default
2921 function generateYesNoOptions ($defaultValue = '') {
2923 return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
2926 // "Getter" for total available receivers
2927 function getTotalReceivers ($mode = 'normal') {
2929 $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
2935 // Wrapper "getter" to get total unconfirmed mails for given userid
2936 function getTotalUnconfirmedMails ($userid) {
2938 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2940 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
2944 return $GLOBALS[__FUNCTION__][$userid];
2947 // Checks whether 'mailer_theme' was found in session
2948 function isMailerThemeSet () {
2950 if (!isset($GLOBALS[__FUNCTION__])) {
2952 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
2956 return $GLOBALS[__FUNCTION__];
2960 * Setter for theme in session (This setter does return the success of
2961 * setSession() which is required e.g. for destroySponsorSession().
2963 function setMailerTheme ($newTheme) {
2964 // Set it in session
2965 return setSession('mailer_theme', $newTheme);
2969 * Getter for theme from session (This getter does return 'mailer_theme' from
2970 * session data or throws an error if not possible
2972 function getMailerTheme () {
2974 if (!isset($GLOBALS[__FUNCTION__])) {
2975 // Is 'mailer_theme' set?
2976 if (!isMailerThemeSet()) {
2977 // No, then abort here
2978 reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
2981 // Get it and store it in cache
2982 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
2986 return $GLOBALS[__FUNCTION__];
2989 // "Getter" for last_module/last_what depending on ext-user version
2990 function getUserLastWhatName () {
2991 // Default is old one: last_module
2992 $columnName = 'last_module';
2994 // Is ext-user up-to-date?
2995 if (isExtensionInstalledAndNewer('user', '0.4.9')) {
2996 // Yes, then use new one
2997 $columnName = 'last_what';
3004 // "Getter" for all columns for given alias and separator
3005 function getAllPointColumns ($alias = NULL, $separator = ',') {
3006 // Prepare the filter array
3007 $filterData = array(
3010 'separator' => $separator
3014 $filterData = runFilterChain('get_all_point_columns', $filterData);
3016 // Return the columns
3017 return $filterData['columns'];
3020 // Checks whether the copyright footer (which breaks framesets) is enabled
3021 function ifCopyrightFooterEnabled () {
3022 // Is not unset and not 'N'?
3023 return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
3027 * Wrapper to check whether we have a "full page". This means that the actual
3028 * content is not delivered in any frame of a frameset.
3030 function isFullPage () {
3032 * The parameter 'frame' is generic and always indicates that this content
3033 * will be output into a frame. Furthermore, if a frameset is reported or
3034 * the copyright line is explicitly deactivated, this cannot be a "full
3037 // @TODO Find a way to not use direct module comparison
3038 $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
3044 // Checks whether frameset_mode is set to true
3045 function isFramesetModeEnabled () {
3047 return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
3050 // Function to determine correct 'what' value
3051 function determineWhat ($module = NULL) {
3052 // Init default 'what'
3056 if (is_null($module)) {
3058 $module = getModule();
3066 // Else try to get it from current module
3067 $what = getWhatFromModule($module);
3069 //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
3071 // Remove any spaces from variable
3072 $what = trim($what);
3076 // Default action for non-admin menus
3080 $what = secureString($what);
3087 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3088 function prependZeros ($mStretch, $length = 2) {
3089 // Return prepended string
3090 return sprintf('%0' . (int) $length . 's', $mStretch);
3093 // Wraps convertSelectionsToEpocheTime()
3094 function convertSelectionsToEpocheTimeInPostData ($id) {
3099 // Get all POST data
3100 $postData = postRequestArray();
3102 // Convert given selection id
3103 convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3105 // Set the POST array back
3106 setPostRequestArray($postData);
3109 // Wraps checking if given points account type matches with given in POST data
3110 function ifPointsAccountTypeMatchesPost ($type) {
3112 exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
3115 // Gets given user's total referral
3116 function getUsersTotalReferrals ($userid, $level = NULL) {
3118 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3119 // Is the level NULL?
3120 if (is_null($level)) {
3121 // Get total amount (all levels)
3122 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
3124 // Get it from user refs
3125 $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
3130 return $GLOBALS[__FUNCTION__][$userid][$level];
3133 // Gets given user's total referral
3134 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3135 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3137 if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3138 // Default is all refs
3141 // Is the not level NULL?
3142 if (!is_null($level)) {
3143 // Then add referral level
3144 $add = ' AND r.`level`=' . bigintval($level);
3147 // Check for all referrals
3148 $result = SQL_QUERY_ESC("SELECT
3149 COUNT(d.`userid`) AS `cnt`
3151 `{?_MYSQL_PREFIX?}_user_data` AS d
3153 `{?_MYSQL_PREFIX?}_user_refs` AS r
3155 d.`userid`=r.`refid`
3157 d.`status` != 'CONFIRMED' AND
3165 ), __FUNCTION__, __LINE__);
3168 list($GLOBALS[__FUNCTION__][$userid][$level]) = SQL_FETCHROW($result);
3171 SQL_FREERESULT($result);
3175 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3176 return $GLOBALS[__FUNCTION__][$userid][$level];
3179 // Converts, if found, dollar data to get element
3180 function convertDollarDataToGetElement ($data) {
3181 // Is first char a dollar?
3182 if (substr($data, 0, 1) == chr(36)) {
3183 // Use last part for getRequestElement()
3184 $data = getRequestElement(substr($data, 1));
3191 // Wrapper function for SQL layer to speed-up things
3192 function SQL_DEBUG_ENABLED () {
3194 if (!isset($GLOBALS[__FUNCTION__])) {
3196 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3200 return $GLOBALS[__FUNCTION__];