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 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.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 debug_report_bug(__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 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
94 // Do we need to aquire a lock?
95 if ($aquireLock === true) {
101 $return = fwrite($fp, $content);
107 // Was something written?
108 if ($return !== false) {
109 // Mark it as readable
110 $GLOBALS['file_readable'][$FQFN] = true;
112 // Remember content in cache
113 $GLOBALS['file_content'][$FQFN] = $content;
117 return (($return !== false) && (changeMode($FQFN, 0644)));
120 // Clears the output buffer. This function does *NOT* backup sent content.
121 function clearOutputBuffer () {
122 // Trigger an error on failure
123 if ((ob_get_length() > 0) && (!ob_end_clean())) {
125 debug_report_bug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
130 // @TODO Implement $compress
131 function encodeString ($str, $compress = true) {
132 $str = urlencode(base64_encode(compileUriCode($str)));
136 // Decode strings encoded with encodeString()
137 // @TODO Implement $decompress
138 function decodeString ($str, $decompress = true) {
139 $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
143 // Decode entities in a nicer way
144 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
145 // Decode the entities to UTF-8 now
146 $decodedString = html_entity_decode($str, $quote, 'UTF-8');
148 // Return decoded string
149 return $decodedString;
152 // Merges an array together but only if both are arrays
153 function merge_array ($array1, $array2) {
154 // Are both an array?
155 if ((!is_array($array1)) && (!is_array($array2))) {
156 // Both are not arrays
157 debug_report_bug(__FUNCTION__, __LINE__, 'No arrays provided!');
158 } elseif (!is_array($array1)) {
159 // Left one is not an array
160 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
161 } elseif (!is_array($array2)) {
162 // Right one is not an array
163 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
166 // Merge all together
167 return array_merge($array1, $array2);
170 // Check if given FQFN is a readable file
171 function isFileReadable ($FQFN) {
173 if (!isset($GLOBALS['file_readable'][$FQFN])) {
175 $GLOBALS['file_readable'][$FQFN] = ((file_exists($FQFN)) && (is_file($FQFN)) && (is_readable($FQFN)));
179 return $GLOBALS['file_readable'][$FQFN];
182 // Checks wether the given FQFN is a directory and not ., .. or .svn
183 function isDirectory ($FQFN) {
185 if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
187 $baseName = basename($FQFN);
190 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
194 return $GLOBALS[__FUNCTION__][$FQFN];
197 // "Getter" for the real remote IP number
198 function detectRealIpAddress () {
199 // Get remote ip from environment
200 $remoteAddr = determineRealRemoteAddress();
202 // Is removeip installed?
203 if (isExtensionActive('removeip')) {
205 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
212 // "Getter" for remote IP number
213 function detectRemoteAddr () {
214 // Get remote ip from environment
215 $remoteAddr = determineRealRemoteAddress(true);
217 // Is removeip installed?
218 if (isExtensionActive('removeip')) {
220 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
227 // "Getter" for remote hostname
228 function detectRemoteHostname () {
229 // Get remote ip from environment
230 $remoteHost = getenv('REMOTE_HOST');
232 // Is removeip installed?
233 if (isExtensionActive('removeip')) {
235 $remoteHost = getAnonymousRemoteHost($remoteHost);
242 // "Getter" for user agent
243 function detectUserAgent ($alwaysReal = false) {
244 // Get remote ip from environment
245 $userAgent = getenv('HTTP_USER_AGENT');
247 // Is removeip installed?
248 if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
250 $userAgent = getAnonymousUserAgent($userAgent);
257 // "Getter" for referer
258 function detectReferer () {
259 // Get remote ip from environment
260 $referer = getenv('HTTP_REFERER');
262 // Is removeip installed?
263 if (isExtensionActive('removeip')) {
265 $referer = getAnonymousReferer($referer);
272 // "Getter" for request URI
273 function detectRequestUri () {
275 return (getenv('REQUEST_URI'));
278 // "Getter" for query string
279 function detectQueryString () {
280 return str_replace('&', '&', (getenv('QUERY_STRING')));
283 // "Getter" for SERVER_NAME
284 function detectServerName () {
286 return (getenv('SERVER_NAME'));
289 // Removes any existing www. from SERVER_NAME. This is very silly but enough
290 // for our purpose here.
291 function detectDomainName () {
293 if (!isset($GLOBALS[__FUNCTION__])) {
295 $domainName = detectServerName();
297 // Is there any www. ?
298 if (substr($domainName, 0, 4) == 'www.') {
300 $domainName = substr($domainName, 4);
304 $GLOBALS[__FUNCTION__] = $domainName;
308 return $GLOBALS[__FUNCTION__];
311 // Check wether we are installing
312 function isInstalling () {
313 // Determine wether we are installing
314 if (!isset($GLOBALS['mailer_installing'])) {
315 // Check URL (css.php/js.php need this)
316 $GLOBALS['mailer_installing'] = isGetRequestParameterSet('installing');
320 return $GLOBALS['mailer_installing'];
323 // Check wether this script is installed
324 function isInstalled () {
326 if (!isset($GLOBALS[__FUNCTION__])) {
327 // Determine wether this script is installed
328 $GLOBALS[__FUNCTION__] = (
333 isConfigEntrySet('MXCHANGE_INSTALLED')
335 getConfig('MXCHANGE_INSTALLED') == 'Y'
339 // New config file found and loaded
340 isIncludeReadable(getCachePath() . 'config-local.php')
343 // New config file found, but not yet read
344 isIncludeReadable(getCachePath() . 'config-local.php')
347 // Only new config file is found
348 !isIncludeReadable('inc/config.php')
350 // Is installation mode
357 // Then use the cache
358 return $GLOBALS[__FUNCTION__];
361 // Check wether an admin is registered
362 function isAdminRegistered () {
364 if (!isset($GLOBALS[__FUNCTION__])) {
366 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
370 return $GLOBALS[__FUNCTION__];
373 // Checks wether the hourly reset mode is active
374 function isHourlyResetEnabled () {
375 // Now simply check it
376 return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === true));
379 // Checks wether the reset mode is active
380 function isResetModeEnabled () {
381 // Now simply check it
382 return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
385 // Checks wether the debug mode is enabled
386 function isDebugModeEnabled () {
388 if (!isset($GLOBALS[__FUNCTION__])) {
390 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
394 return $GLOBALS[__FUNCTION__];
397 // Checks wether the debug reset is enabled
398 function isDebugResetEnabled () {
400 if (!isset($GLOBALS[__FUNCTION__])) {
402 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
406 return $GLOBALS[__FUNCTION__];
409 // Checks wether SQL debugging is enabled
410 function isSqlDebuggingEnabled () {
412 if (!isset($GLOBALS[__FUNCTION__])) {
413 // Determine if SQL debugging is enabled
414 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
418 return $GLOBALS[__FUNCTION__];
421 // Checks wether we shall debug regular expressions
422 function isDebugRegularExpressionEnabled () {
424 if (!isset($GLOBALS[__FUNCTION__])) {
426 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
430 return $GLOBALS[__FUNCTION__];
433 // Checks wether the cache instance is valid
434 function isCacheInstanceValid () {
436 if (!isset($GLOBALS[__FUNCTION__])) {
438 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
442 return $GLOBALS[__FUNCTION__];
445 // Copies a file from source to destination and verifies if that goes fine.
446 // This function should wrap the copy() command and make a nicer debug backtrace
447 // even if there is no xdebug extension installed.
448 function copyFileVerified ($source, $dest, $chmod = '') {
449 // Failed is the default
452 // Is the source file there?
453 if (!isFileReadable($source)) {
455 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
458 // Is the target directory there?
459 if (!isDirectory(dirname($dest))) {
461 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
464 // Now try to copy it
465 if (!copy($source, $dest)) {
466 // Something went wrong
467 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
470 $GLOBALS['file_readable'][$dest] = true;
473 // If there are chmod rights set, apply them
474 if (!empty($chmod)) {
476 $status = changeMode($dest, $chmod);
486 // Wrapper function for header()
487 // Send a header but checks before if we can do so
488 function sendHeader ($header) {
490 //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header);
491 $GLOBALS['header'][] = trim($header);
494 // Flushes all headers
495 function flushHeaders () {
496 // Is the header already sent?
497 if (headers_sent()) {
499 debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!');
502 // Flush all headers if found
503 if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) {
504 foreach ($GLOBALS['header'] as $header) {
509 // Mark them as flushed
510 $GLOBALS['header'] = array();
513 // Wrapper function for chmod()
514 // @TODO Do some more sanity check here
515 function changeMode ($FQFN, $mode) {
516 // Is the file/directory there?
517 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
518 // Neither, so abort here
519 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
523 return chmod($FQFN, $mode);
526 // Wrapper for unlink()
527 function removeFile ($FQFN) {
528 // Is the file there?
529 if (isFileReadable($FQFN)) {
531 $GLOBALS['file_readable'][$FQFN] = false;
534 return unlink($FQFN);
537 // All fine if no file was removed. If we change this to 'false' or rewrite
538 // above if() block it would be to restrictive.
542 // Wrapper for $_POST['sel']
543 function countPostSelection ($element = 'sel') {
545 if (isPostRequestParameterSet($element)) {
546 // Return counted elements
547 return countSelection(postRequestParameter($element));
549 // Return zero if not found
554 // Checks wether the config-local.php is loaded
555 function isConfigLocalLoaded () {
556 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
559 // Checks wether a nickname or userid was entered and caches the result
560 function isNicknameUsed ($userid) {
561 // Is the cache there
562 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
564 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . round($userid) . '') != $userid));
568 return $GLOBALS[__FUNCTION__][$userid];
571 // Getter for 'what' value
572 function getWhat () {
577 if (isWhatSet(true)) {
579 $what = $GLOBALS['what'];
586 // Setter for 'what' value
587 function setWhat ($newWhat) {
588 $GLOBALS['what'] = SQL_ESCAPE($newWhat);
591 // Setter for 'what' from configuration
592 function setWhatFromConfig ($configEntry) {
593 // Get 'what' from config
594 $what = getConfig($configEntry);
600 // Checks wether what is set and optionally aborts on miss
601 function isWhatSet ($strict = false) {
603 $isset = isset($GLOBALS['what']);
605 // Should we abort here?
606 if (($strict === true) && ($isset === false)) {
608 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
615 // Getter for 'action' value
616 function getAction ($strict = true) {
621 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
623 $action = $GLOBALS['action'];
630 // Setter for 'action' value
631 function setAction ($newAction) {
632 $GLOBALS['action'] = SQL_ESCAPE($newAction);
635 // Checks wether action is set and optionally aborts on miss
636 function isActionSet ($strict = false) {
638 $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action'])));
640 // Should we abort here?
641 if (($strict === true) && ($isset === false)) {
643 debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.');
650 // Getter for 'module' value
651 function getModule ($strict = true) {
656 if (isModuleSet($strict)) {
658 $module = $GLOBALS['module'];
665 // Setter for 'module' value
666 function setModule ($newModule) {
667 // Secure it and make all modules lower-case
668 $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
671 // Checks wether module is set and optionally aborts on miss
672 function isModuleSet ($strict = false) {
674 $isset = (!empty($GLOBALS['module']));
676 // Should we abort here?
677 if (($strict === true) && ($isset === false)) {
679 debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.');
683 return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
686 // Getter for 'output_mode' value
687 function getScriptOutputMode () {
689 if (!isset($GLOBALS[__FUNCTION__])) {
694 if (isOutputModeSet(true)) {
696 $output_mode = $GLOBALS['output_mode'];
700 $GLOBALS[__FUNCTION__] = $output_mode;
704 return $GLOBALS[__FUNCTION__];
707 // Setter for 'output_mode' value
708 function setOutputMode ($newOutputMode) {
709 $GLOBALS['output_mode'] = (int) $newOutputMode;
712 // Checks wether output_mode is set and optionally aborts on miss
713 function isOutputModeSet ($strict = false) {
715 $isset = (isset($GLOBALS['output_mode']));
717 // Should we abort here?
718 if (($strict === true) && ($isset === false)) {
720 debug_report_bug(__FUNCTION__, __LINE__, 'Output mode is not set.');
727 // Enables block-mode
728 function enableBlockMode ($enabled = true) {
729 $GLOBALS['block_mode'] = $enabled;
732 // Checks wether block-mode is enabled
733 function isBlockModeEnabled () {
735 if (!isset($GLOBALS['block_mode'])) {
737 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
741 return $GLOBALS['block_mode'];
744 // Wrapper function for addPointsThroughReferalSystem()
745 function addPointsDirectly ($subject, $userid, $points) {
747 unset($GLOBALS['ref_level']);
749 // Call more complicated method (due to more parameters)
750 return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'DIRECT');
753 // Wrapper for redirectToUrl but URL comes from a configuration entry
754 function redirectToConfiguredUrl ($configEntry) {
756 redirectToUrl(getConfig($configEntry));
759 // Wrapper function to redirect from member-only modules to index
760 function redirectToIndexMemberOnlyModule () {
761 // Do the redirect here
762 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
765 // Wrapper function to redirect to current URL
766 function redirectToRequestUri () {
767 redirectToUrl(basename(detectRequestUri()));
770 // Wrapper function to redirect to de-refered URL
771 function redirectToDereferedUrl ($url) {
773 redirectToUrl(generateDerefererUrl($url));
776 // Wrapper function for checking if extension is installed and newer or same version
777 function isExtensionInstalledAndNewer ($ext_name, $version) {
778 // Is an cache entry found?
779 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
781 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
783 // Cache hits should be incremented twice
784 incrementStatsEntry('cache_hits', 2);
788 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
789 return $GLOBALS[__FUNCTION__][$ext_name][$version];
792 // Wrapper function for checking if extension is installed and older than given version
793 function isExtensionInstalledAndOlder ($ext_name, $version) {
794 // Is an cache entry found?
795 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
797 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
799 // Cache hits should be incremented twice
800 incrementStatsEntry('cache_hits', 2);
804 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
805 return $GLOBALS[__FUNCTION__][$ext_name][$version];
809 function setUsername ($userName) {
810 $GLOBALS['username'] = (string) $userName;
814 function getUsername () {
816 if (!isset($GLOBALS['username'])) {
817 // No, so it has to be a guest
818 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
822 return $GLOBALS['username'];
825 // Wrapper function for installation phase
826 function isInstallationPhase () {
828 if (!isset($GLOBALS[__FUNCTION__])) {
830 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
834 return $GLOBALS[__FUNCTION__];
837 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
838 function isDemoModeActive () {
840 if (!isset($GLOBALS[__FUNCTION__])) {
842 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
846 return $GLOBALS[__FUNCTION__];
849 // Getter for PHP caching value
850 function getPhpCaching () {
851 return $GLOBALS['php_caching'];
854 // Checks wether the admin hash is set
855 function isAdminHashSet ($adminId) {
856 // Is the array there?
857 if (!isset($GLOBALS['cache_array']['admin'])) {
858 // Missing array should be reported
859 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
862 // Check for admin hash
863 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
866 // Setter for admin hash
867 function setAdminHash ($adminId, $hash) {
868 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
871 // Getter for current admin login
872 function getCurrentAdminLogin () {
874 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
877 if (!isset($GLOBALS[__FUNCTION__])) {
879 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
883 return $GLOBALS[__FUNCTION__];
886 // Setter for admin id (and current)
887 function setAdminId ($adminId) {
889 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
892 $status = setSession('admin_id', bigintval($adminId));
895 setCurrentAdminId($adminId);
901 // Setter for admin_last
902 function setAdminLast ($adminLast) {
904 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
907 $status = setSession('admin_last', $adminLast);
913 // Setter for admin_md5
914 function setAdminMd5 ($adminMd5) {
916 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
919 $status = setSession('admin_md5', $adminMd5);
925 // Getter for admin_md5
926 function getAdminMd5 () {
928 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
931 return getSession('admin_md5');
934 // Init user data array
935 function initUserData () {
936 // User id should not be zero
937 if (!isValidUserId(getCurrentUserId())) {
938 // Should be always valid
939 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
943 $GLOBALS['user_data'][getCurrentUserId()] = array();
946 // Getter for user data
947 function getUserData ($column) {
948 // User id should not be zero
949 if (!isValidUserId(getCurrentUserId())) {
950 // Should be always valid
951 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
957 if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
959 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
966 // Checks wether given user data is set to 'Y'
967 function isUserDataEnabled ($column) {
969 if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
971 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
975 return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
978 // Geter for whole user data array
979 function getUserDataArray () {
981 $userid = getCurrentUserId();
983 // Is the current userid valid?
984 if (!isValidUserId($userid)) {
985 // Should be always valid
986 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
989 // Get the whole array if found
990 if (isset($GLOBALS['user_data'][$userid])) {
991 // Found, so return it
992 return $GLOBALS['user_data'][$userid];
994 // Return empty array
999 // Checks if the user data is valid, this may indicate that the user has logged
1000 // in, but you should use isMember() if you want to find that out.
1001 function isUserDataValid () {
1002 // User id should not be zero so abort here
1003 if (!isCurrentUserIdSet()) return false;
1006 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
1008 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
1011 // Return the result
1012 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1015 // Setter for current userid
1016 function setCurrentUserId ($userid) {
1018 $GLOBALS['current_userid'] = bigintval($userid);
1020 // Unset it to re-determine the actual state
1021 unset($GLOBALS['is_userdata_valid'][$userid]);
1024 // Getter for current userid
1025 function getCurrentUserId () {
1026 // Userid must be set before it can be used
1027 if (!isCurrentUserIdSet()) {
1029 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
1032 // Return the userid
1033 return $GLOBALS['current_userid'];
1036 // Checks if current userid is set
1037 function isCurrentUserIdSet () {
1038 return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1041 // Checks wether we are debugging template cache
1042 function isDebuggingTemplateCache () {
1043 // Do we have cache?
1044 if (!isset($GLOBALS[__FUNCTION__])) {
1046 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1050 return $GLOBALS[__FUNCTION__];
1053 // Wrapper for fetchUserData() and getUserData() calls
1054 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1056 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1057 // Default is 'guest'
1058 $data = '{--USERNAME_GUEST--}';
1060 // Can we fetch the user data?
1061 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1062 // Now get the data back
1063 $data = getUserData($valueColumn);
1067 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1071 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1074 // Wrapper for strpos() to ease porting from deprecated ereg() function
1075 function isInString ($needle, $haystack) {
1076 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1077 return (strpos($haystack, $needle) !== false);
1080 // Wrapper for strpos() to ease porting from deprecated eregi() function
1081 // This function is case-insensitive
1082 function isInStringIgnoreCase ($needle, $haystack) {
1083 return (isInString(strtolower($needle), strtolower($haystack)));
1086 // Wrapper to check for if fatal errors where detected
1087 function ifFatalErrorsDetected () {
1088 // Just call the inner function
1089 return (getTotalFatalErrors() > 0);
1092 // Setter for HTTP status
1093 function setHttpStatus ($status) {
1094 $GLOBALS['http_status'] = (string) $status;
1097 // Getter for HTTP status
1098 function getHttpStatus () {
1099 // Is the status set?
1100 if (!isset($GLOBALS['http_status'])) {
1102 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1106 return $GLOBALS['http_status'];
1110 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1111 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1113 * ----------------------------------------------------------------------------
1114 * If you want to redirect, please use redirectToUrl(); instead
1115 * ----------------------------------------------------------------------------
1117 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1119 * @link http://support.microsoft.com/kb/q176113/
1120 * @author Andreas Gohr <andi@splitbrain.org>
1123 function sendRawRedirect ($url) {
1124 // Send helping header
1125 setHttpStatus('302 Found');
1127 // always close the session
1128 session_write_close();
1130 // Revert entity &
1131 $url = str_replace('&', '&', $url);
1133 // check if running on IIS < 6 with CGI-PHP
1134 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1135 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
1136 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1137 ($matches[1] < 6)) {
1138 // Send the IIS header
1139 sendHeader('Refresh: 0;url=' . $url);
1141 // Send generic header
1142 sendHeader('Location: ' . $url);
1149 // Determines the country of the given user id
1150 function determineCountry ($userid) {
1151 // Do we have cache?
1152 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1153 // Default is 'invalid'
1154 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1156 // Is extension country active?
1157 if (isExtensionActive('country')) {
1158 // Determine the right country code through the country id
1159 $id = getUserData('country_code');
1161 // Then handle it over
1162 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1164 // Get raw code from user data
1165 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1170 return $GLOBALS[__FUNCTION__][$userid];
1173 // "Getter" for total confirmed user accounts
1174 function getTotalConfirmedUser () {
1176 if (!isset($GLOBALS[__FUNCTION__])) {
1178 if (isExtensionActive('user')) {
1179 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1181 $GLOBALS[__FUNCTION__] = 0;
1185 // Return cached value
1186 return $GLOBALS[__FUNCTION__];
1189 // "Getter" for total unconfirmed user accounts
1190 function getTotalUnconfirmedUser () {
1192 if (!isset($GLOBALS[__FUNCTION__])) {
1194 if (isExtensionActive('user')) {
1195 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1197 $GLOBALS[__FUNCTION__] = 0;
1201 // Return cached value
1202 return $GLOBALS[__FUNCTION__];
1205 // "Getter" for total locked user accounts
1206 function getTotalLockedUser () {
1208 if (!isset($GLOBALS[__FUNCTION__])) {
1210 if (isExtensionActive('user')) {
1211 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1213 $GLOBALS[__FUNCTION__] = 0;
1217 // Return cached value
1218 return $GLOBALS[__FUNCTION__];
1221 // "Getter" for total locked user accounts
1222 function getTotalRandomRefidUser () {
1224 if (!isset($GLOBALS[__FUNCTION__])) {
1226 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1227 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, '', '>=');
1229 $GLOBALS[__FUNCTION__] = 0;
1233 // Return cached value
1234 return $GLOBALS[__FUNCTION__];
1237 // Is given userid valid?
1238 function isValidUserId ($userid) {
1239 // Do we have cache?
1240 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1242 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1246 return $GLOBALS[__FUNCTION__][$userid];
1250 function encodeEntities ($str) {
1252 $str = secureString($str, true, true);
1254 // Encode dollar sign as well
1255 $str = str_replace('$', '$', $str);
1261 // "Getter" for date from patch_ctime
1262 function getDateFromPatchTime () {
1264 if (!isset($GLOBALS[__FUNCTION__])) {
1266 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1270 return $GLOBALS[__FUNCTION__];
1273 // Getter for current year (default)
1274 function getYear ($timestamp = null) {
1276 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1278 if (is_null($timestamp)) {
1279 $timestamp = time();
1283 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1287 return $GLOBALS[__FUNCTION__][$timestamp];
1290 // Getter for current month (default)
1291 function getMonth ($timestamp = null) {
1293 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1294 // If null is set, use time()
1295 if (is_null($timestamp)) {
1296 // Use time() which is current timestamp
1297 $timestamp = time();
1301 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1305 return $GLOBALS[__FUNCTION__][$timestamp];
1308 // Getter for current hour (default)
1309 function getHour ($timestamp = null) {
1311 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1313 if (is_null($timestamp)) {
1314 $timestamp = time();
1318 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1322 return $GLOBALS[__FUNCTION__][$timestamp];
1325 // Getter for current day (default)
1326 function getDay ($timestamp = null) {
1328 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1330 if (is_null($timestamp)) {
1331 $timestamp = time();
1335 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1339 return $GLOBALS[__FUNCTION__][$timestamp];
1342 // Getter for current week (default)
1343 function getWeek ($timestamp = null) {
1345 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1347 if (is_null($timestamp)) $timestamp = time();
1350 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1354 return $GLOBALS[__FUNCTION__][$timestamp];
1357 // Getter for current short_hour (default)
1358 function getShortHour ($timestamp = null) {
1360 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1362 if (is_null($timestamp)) $timestamp = time();
1365 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1369 return $GLOBALS[__FUNCTION__][$timestamp];
1372 // Getter for current long_hour (default)
1373 function getLongHour ($timestamp = null) {
1375 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1377 if (is_null($timestamp)) $timestamp = time();
1380 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1384 return $GLOBALS[__FUNCTION__][$timestamp];
1387 // Getter for current second (default)
1388 function getSecond ($timestamp = null) {
1390 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1392 if (is_null($timestamp)) $timestamp = time();
1395 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1399 return $GLOBALS[__FUNCTION__][$timestamp];
1402 // Getter for current minute (default)
1403 function getMinute ($timestamp = null) {
1405 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1407 if (is_null($timestamp)) $timestamp = time();
1410 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1414 return $GLOBALS[__FUNCTION__][$timestamp];
1417 // Checks wether the title decoration is enabled
1418 function isTitleDecorationEnabled () {
1419 // Do we have cache?
1420 if (!isset($GLOBALS[__FUNCTION__])) {
1422 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1426 return $GLOBALS[__FUNCTION__];
1429 // Checks wether filter usage updates are enabled (expensive queries!)
1430 function isFilterUsageUpdateEnabled () {
1431 // Do we have cache?
1432 if (!isset($GLOBALS[__FUNCTION__])) {
1434 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1438 return $GLOBALS[__FUNCTION__];
1441 // Checks wether debugging of weekly resets is enabled
1442 function isWeeklyResetDebugEnabled () {
1443 // Do we have cache?
1444 if (!isset($GLOBALS[__FUNCTION__])) {
1446 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1450 return $GLOBALS[__FUNCTION__];
1453 // Checks wether debugging of monthly resets is enabled
1454 function isMonthlyResetDebugEnabled () {
1455 // Do we have cache?
1456 if (!isset($GLOBALS[__FUNCTION__])) {
1458 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1462 return $GLOBALS[__FUNCTION__];
1465 // Checks wether displaying of debug SQLs are enabled
1466 function isDisplayDebugSqlEnabled () {
1467 // Do we have cache?
1468 if (!isset($GLOBALS[__FUNCTION__])) {
1470 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1474 return $GLOBALS[__FUNCTION__];
1477 // Checks wether module title is enabled
1478 function isModuleTitleEnabled () {
1479 // Do we have cache?
1480 if (!isset($GLOBALS[__FUNCTION__])) {
1482 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1486 return $GLOBALS[__FUNCTION__];
1489 // Checks wether what title is enabled
1490 function isWhatTitleEnabled () {
1491 // Do we have cache?
1492 if (!isset($GLOBALS[__FUNCTION__])) {
1494 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1498 return $GLOBALS[__FUNCTION__];
1501 // Checks wether stats are enabled
1502 function ifStatsAreEnabled () {
1503 // Do we have cache?
1504 if (!isset($GLOBALS[__FUNCTION__])) {
1505 // Then determine it
1506 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1509 // Return cached value
1510 return $GLOBALS[__FUNCTION__];
1513 // Checks wether admin-notification of certain user actions is enabled
1514 function isAdminNotificationEnabled () {
1515 // Do we have cache?
1516 if (!isset($GLOBALS[__FUNCTION__])) {
1518 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1522 return $GLOBALS[__FUNCTION__];
1525 // Checks wether random referal id selection is enabled
1526 function isRandomReferalIdEnabled () {
1527 // Do we have cache?
1528 if (!isset($GLOBALS[__FUNCTION__])) {
1530 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1534 return $GLOBALS[__FUNCTION__];
1537 // "Getter" for default language
1538 function getDefaultLanguage () {
1539 // Do we have cache?
1540 if (!isset($GLOBALS[__FUNCTION__])) {
1542 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1546 return $GLOBALS[__FUNCTION__];
1549 // "Getter" for default referal id
1550 function getDefRefid () {
1551 // Do we have cache?
1552 if (!isset($GLOBALS[__FUNCTION__])) {
1554 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1558 return $GLOBALS[__FUNCTION__];
1561 // "Getter" for path
1562 function getPath () {
1563 // Do we have cache?
1564 if (!isset($GLOBALS[__FUNCTION__])) {
1566 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1570 return $GLOBALS[__FUNCTION__];
1574 function getUrl () {
1575 // Do we have cache?
1576 if (!isset($GLOBALS[__FUNCTION__])) {
1578 $GLOBALS[__FUNCTION__] = getConfig('URL');
1582 return $GLOBALS[__FUNCTION__];
1585 // "Getter" for cache_path
1586 function getCachePath () {
1587 // Do we have cache?
1588 if (!isset($GLOBALS[__FUNCTION__])) {
1590 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1594 return $GLOBALS[__FUNCTION__];
1597 // "Getter" for secret_key
1598 function getSecretKey () {
1599 // Do we have cache?
1600 if (!isset($GLOBALS[__FUNCTION__])) {
1602 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1606 return $GLOBALS[__FUNCTION__];
1609 // "Getter" for SITE_KEY
1610 function getSiteKey () {
1611 // Do we have cache?
1612 if (!isset($GLOBALS[__FUNCTION__])) {
1614 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1618 return $GLOBALS[__FUNCTION__];
1621 // "Getter" for DATE_KEY
1622 function getDateKey () {
1623 // Do we have cache?
1624 if (!isset($GLOBALS[__FUNCTION__])) {
1626 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1630 return $GLOBALS[__FUNCTION__];
1633 // "Getter" for master_salt
1634 function getMasterSalt () {
1635 // Do we have cache?
1636 if (!isset($GLOBALS[__FUNCTION__])) {
1638 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1642 return $GLOBALS[__FUNCTION__];
1645 // "Getter" for prime
1646 function getPrime () {
1647 // Do we have cache?
1648 if (!isset($GLOBALS[__FUNCTION__])) {
1650 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1654 return $GLOBALS[__FUNCTION__];
1657 // "Getter" for encrypt_seperator
1658 function getEncryptSeperator () {
1659 // Do we have cache?
1660 if (!isset($GLOBALS[__FUNCTION__])) {
1662 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1666 return $GLOBALS[__FUNCTION__];
1669 // "Getter" for mysql_prefix
1670 function getMysqlPrefix () {
1671 // Do we have cache?
1672 if (!isset($GLOBALS[__FUNCTION__])) {
1674 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1678 return $GLOBALS[__FUNCTION__];
1681 // "Getter" for table_type
1682 function getTableType () {
1683 // Do we have cache?
1684 if (!isset($GLOBALS[__FUNCTION__])) {
1686 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1690 return $GLOBALS[__FUNCTION__];
1693 // "Getter" for salt_length
1694 function getSaltLength () {
1695 // Do we have cache?
1696 if (!isset($GLOBALS[__FUNCTION__])) {
1698 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1702 return $GLOBALS[__FUNCTION__];
1705 // "Getter" for output_mode
1706 function getOutputMode () {
1707 // Do we have cache?
1708 if (!isset($GLOBALS[__FUNCTION__])) {
1710 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1714 return $GLOBALS[__FUNCTION__];
1717 // "Getter" for full_version
1718 function getFullVersion () {
1719 // Do we have cache?
1720 if (!isset($GLOBALS[__FUNCTION__])) {
1722 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1726 return $GLOBALS[__FUNCTION__];
1729 // "Getter" for title
1730 function getTitle () {
1731 // Do we have cache?
1732 if (!isset($GLOBALS[__FUNCTION__])) {
1734 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1738 return $GLOBALS[__FUNCTION__];
1741 // "Getter" for curr_svn_revision
1742 function getCurrentRepositoryRevision () {
1743 // Do we have cache?
1744 if (!isset($GLOBALS[__FUNCTION__])) {
1746 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1750 return $GLOBALS[__FUNCTION__];
1753 // "Getter" for server_url
1754 function getServerUrl () {
1755 // Do we have cache?
1756 if (!isset($GLOBALS[__FUNCTION__])) {
1758 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1762 return $GLOBALS[__FUNCTION__];
1765 // "Getter" for mt_word
1766 function getMtWord () {
1767 // Do we have cache?
1768 if (!isset($GLOBALS[__FUNCTION__])) {
1770 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1774 return $GLOBALS[__FUNCTION__];
1777 // "Getter" for mt_word2
1778 function getMtWord2 () {
1779 // Do we have cache?
1780 if (!isset($GLOBALS[__FUNCTION__])) {
1782 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1786 return $GLOBALS[__FUNCTION__];
1789 // "Getter" for main_title
1790 function getMainTitle () {
1791 // Do we have cache?
1792 if (!isset($GLOBALS[__FUNCTION__])) {
1794 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1798 return $GLOBALS[__FUNCTION__];
1801 // "Getter" for file_hash
1802 function getFileHash () {
1803 // Do we have cache?
1804 if (!isset($GLOBALS[__FUNCTION__])) {
1806 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1810 return $GLOBALS[__FUNCTION__];
1813 // "Getter" for pass_scramble
1814 function getPassScramble () {
1815 // Do we have cache?
1816 if (!isset($GLOBALS[__FUNCTION__])) {
1818 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1822 return $GLOBALS[__FUNCTION__];
1825 // "Getter" for ap_inactive_since
1826 function getApInactiveSince () {
1827 // Do we have cache?
1828 if (!isset($GLOBALS[__FUNCTION__])) {
1830 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1834 return $GLOBALS[__FUNCTION__];
1837 // "Getter" for user_min_confirmed
1838 function getUserMinConfirmed () {
1839 // Do we have cache?
1840 if (!isset($GLOBALS[__FUNCTION__])) {
1842 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1846 return $GLOBALS[__FUNCTION__];
1849 // "Getter" for auto_purge
1850 function getAutoPurge () {
1851 // Do we have cache?
1852 if (!isset($GLOBALS[__FUNCTION__])) {
1854 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1858 return $GLOBALS[__FUNCTION__];
1861 // "Getter" for bonus_userid
1862 function getBonusUserid () {
1863 // Do we have cache?
1864 if (!isset($GLOBALS[__FUNCTION__])) {
1866 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1870 return $GLOBALS[__FUNCTION__];
1873 // "Getter" for ap_inactive_time
1874 function getApInactiveTime () {
1875 // Do we have cache?
1876 if (!isset($GLOBALS[__FUNCTION__])) {
1878 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1882 return $GLOBALS[__FUNCTION__];
1885 // "Getter" for ap_dm_timeout
1886 function getApDmTimeout () {
1887 // Do we have cache?
1888 if (!isset($GLOBALS[__FUNCTION__])) {
1890 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1894 return $GLOBALS[__FUNCTION__];
1897 // "Getter" for ap_tasks_time
1898 function getApTasksTime () {
1899 // Do we have cache?
1900 if (!isset($GLOBALS[__FUNCTION__])) {
1902 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1906 return $GLOBALS[__FUNCTION__];
1909 // "Getter" for ap_unconfirmed_time
1910 function getApUnconfirmedTime () {
1911 // Do we have cache?
1912 if (!isset($GLOBALS[__FUNCTION__])) {
1914 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1918 return $GLOBALS[__FUNCTION__];
1921 // "Getter" for points
1922 function getPoints () {
1923 // Do we have cache?
1924 if (!isset($GLOBALS[__FUNCTION__])) {
1926 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1930 return $GLOBALS[__FUNCTION__];
1933 // "Getter" for slogan
1934 function getSlogan () {
1935 // Do we have cache?
1936 if (!isset($GLOBALS[__FUNCTION__])) {
1938 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1942 return $GLOBALS[__FUNCTION__];
1945 // "Getter" for copy
1946 function getCopy () {
1947 // Do we have cache?
1948 if (!isset($GLOBALS[__FUNCTION__])) {
1950 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1954 return $GLOBALS[__FUNCTION__];
1957 // "Getter" for webmaster
1958 function getWebmaster () {
1959 // Do we have cache?
1960 if (!isset($GLOBALS[__FUNCTION__])) {
1962 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1966 return $GLOBALS[__FUNCTION__];
1969 // "Getter" for sql_count
1970 function getSqlCount () {
1971 // Do we have cache?
1972 if (!isset($GLOBALS[__FUNCTION__])) {
1974 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1978 return $GLOBALS[__FUNCTION__];
1981 // "Getter" for num_templates
1982 function getNumTemplates () {
1983 // Do we have cache?
1984 if (!isset($GLOBALS[__FUNCTION__])) {
1986 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1990 return $GLOBALS[__FUNCTION__];
1993 // "Getter" for dns_cache_timeout
1994 function getDnsCacheTimeout () {
1995 // Do we have cache?
1996 if (!isset($GLOBALS[__FUNCTION__])) {
1998 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2002 return $GLOBALS[__FUNCTION__];
2005 // "Getter" for menu_blur_spacer
2006 function getMenuBlurSpacer () {
2007 // Do we have cache?
2008 if (!isset($GLOBALS[__FUNCTION__])) {
2010 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2014 return $GLOBALS[__FUNCTION__];
2017 // "Getter" for points_register
2018 function getPointsRegister () {
2019 // Do we have cache?
2020 if (!isset($GLOBALS[__FUNCTION__])) {
2022 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2026 return $GLOBALS[__FUNCTION__];
2029 // "Getter" for points_ref
2030 function getPointsRef () {
2031 // Do we have cache?
2032 if (!isset($GLOBALS[__FUNCTION__])) {
2034 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2038 return $GLOBALS[__FUNCTION__];
2041 // "Getter" for ref_payout
2042 function getRefPayout () {
2043 // Do we have cache?
2044 if (!isset($GLOBALS[__FUNCTION__])) {
2046 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2050 return $GLOBALS[__FUNCTION__];
2053 // "Getter" for online_timeout
2054 function getOnlineTimeout () {
2055 // Do we have cache?
2056 if (!isset($GLOBALS[__FUNCTION__])) {
2058 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2062 return $GLOBALS[__FUNCTION__];
2065 // "Getter" for index_home
2066 function getIndexHome () {
2067 // Do we have cache?
2068 if (!isset($GLOBALS[__FUNCTION__])) {
2070 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2074 return $GLOBALS[__FUNCTION__];
2077 // "Getter" for one_day
2078 function getOneDay () {
2079 // Do we have cache?
2080 if (!isset($GLOBALS[__FUNCTION__])) {
2082 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2086 return $GLOBALS[__FUNCTION__];
2089 // "Getter" for activate_xchange
2090 function getActivateXchange () {
2091 // Do we have cache?
2092 if (!isset($GLOBALS[__FUNCTION__])) {
2094 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2098 return $GLOBALS[__FUNCTION__];
2101 // "Getter" for img_type
2102 function getImgType () {
2103 // Do we have cache?
2104 if (!isset($GLOBALS[__FUNCTION__])) {
2106 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2110 return $GLOBALS[__FUNCTION__];
2113 // "Getter" for code_length
2114 function getCodeLength () {
2115 // Do we have cache?
2116 if (!isset($GLOBALS[__FUNCTION__])) {
2118 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2122 return $GLOBALS[__FUNCTION__];
2125 // "Getter" for least_cats
2126 function getLeastCats () {
2127 // Do we have cache?
2128 if (!isset($GLOBALS[__FUNCTION__])) {
2130 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2134 return $GLOBALS[__FUNCTION__];
2137 // "Getter" for pass_len
2138 function getPassLen () {
2139 // Do we have cache?
2140 if (!isset($GLOBALS[__FUNCTION__])) {
2142 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2146 return $GLOBALS[__FUNCTION__];
2149 // "Getter" for admin_menu
2150 function getAdminMenu () {
2151 // Do we have cache?
2152 if (!isset($GLOBALS[__FUNCTION__])) {
2154 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2158 return $GLOBALS[__FUNCTION__];
2161 // "Getter" for last_month
2162 function getLastMonth () {
2163 // Do we have cache?
2164 if (!isset($GLOBALS[__FUNCTION__])) {
2166 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2170 return $GLOBALS[__FUNCTION__];
2173 // "Getter" for max_send
2174 function getMaxSend () {
2175 // Do we have cache?
2176 if (!isset($GLOBALS[__FUNCTION__])) {
2178 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2182 return $GLOBALS[__FUNCTION__];
2185 // "Getter" for mails_page
2186 function getMailsPage () {
2187 // Do we have cache?
2188 if (!isset($GLOBALS[__FUNCTION__])) {
2190 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2194 return $GLOBALS[__FUNCTION__];
2197 // "Getter" for rand_no
2198 function getRandNo () {
2199 // Do we have cache?
2200 if (!isset($GLOBALS[__FUNCTION__])) {
2202 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2206 return $GLOBALS[__FUNCTION__];
2209 // "Getter" for __DB_NAME
2210 function getDbName () {
2211 // Do we have cache?
2212 if (!isset($GLOBALS[__FUNCTION__])) {
2214 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2218 return $GLOBALS[__FUNCTION__];
2221 // "Getter" for DOMAIN
2222 function getDomain () {
2223 // Do we have cache?
2224 if (!isset($GLOBALS[__FUNCTION__])) {
2226 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2230 return $GLOBALS[__FUNCTION__];
2233 // "Getter" for proxy_username
2234 function getProxyUsername () {
2235 // Do we have cache?
2236 if (!isset($GLOBALS[__FUNCTION__])) {
2238 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2242 return $GLOBALS[__FUNCTION__];
2245 // "Getter" for proxy_password
2246 function getProxyPassword () {
2247 // Do we have cache?
2248 if (!isset($GLOBALS[__FUNCTION__])) {
2250 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2254 return $GLOBALS[__FUNCTION__];
2257 // "Getter" for proxy_host
2258 function getProxyHost () {
2259 // Do we have cache?
2260 if (!isset($GLOBALS[__FUNCTION__])) {
2262 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2266 return $GLOBALS[__FUNCTION__];
2269 // "Getter" for proxy_port
2270 function getProxyPort () {
2271 // Do we have cache?
2272 if (!isset($GLOBALS[__FUNCTION__])) {
2274 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2278 return $GLOBALS[__FUNCTION__];
2281 // "Getter" for SMTP_HOSTNAME
2282 function getSmtpHostname () {
2283 // Do we have cache?
2284 if (!isset($GLOBALS[__FUNCTION__])) {
2286 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2290 return $GLOBALS[__FUNCTION__];
2293 // "Getter" for SMTP_USER
2294 function getSmtpUser () {
2295 // Do we have cache?
2296 if (!isset($GLOBALS[__FUNCTION__])) {
2298 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2302 return $GLOBALS[__FUNCTION__];
2305 // "Getter" for SMTP_PASSWORD
2306 function getSmtpPassword () {
2307 // Do we have cache?
2308 if (!isset($GLOBALS[__FUNCTION__])) {
2310 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2314 return $GLOBALS[__FUNCTION__];
2317 // "Getter" for points_word
2318 function getPointsWord () {
2319 // Do we have cache?
2320 if (!isset($GLOBALS[__FUNCTION__])) {
2322 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2326 return $GLOBALS[__FUNCTION__];
2329 // "Getter" for profile_lock
2330 function getProfileLock () {
2331 // Do we have cache?
2332 if (!isset($GLOBALS[__FUNCTION__])) {
2334 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2338 return $GLOBALS[__FUNCTION__];
2341 // "Getter" for url_tlock
2342 function getUrlTlock () {
2343 // Do we have cache?
2344 if (!isset($GLOBALS[__FUNCTION__])) {
2346 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2350 return $GLOBALS[__FUNCTION__];
2353 // Checks wether proxy configuration is used
2354 function isProxyUsed () {
2355 // Do we have cache?
2356 if (!isset($GLOBALS[__FUNCTION__])) {
2358 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2362 return $GLOBALS[__FUNCTION__];
2365 // Checks wether POST data contains selections
2366 function ifPostContainsSelections ($element = 'sel') {
2367 // Do we have cache?
2368 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2370 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
2374 return $GLOBALS[__FUNCTION__][$element];
2377 // Checks wether verbose_sql is Y and returns true/false if so
2378 function isVerboseSqlEnabled () {
2379 // Do we have cache?
2380 if (!isset($GLOBALS[__FUNCTION__])) {
2382 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2386 return $GLOBALS[__FUNCTION__];
2389 // "Getter" for total user points
2390 function getTotalPoints ($userid) {
2391 // Do we have cache?
2392 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2393 // Init array for filter chain
2395 'userid' => $userid,
2399 // Run filter chain for getting more point values
2400 $data = runFilterChain('get_total_points', $data);
2403 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - countSumTotalData($userid, 'user_data', 'used_points');
2407 return $GLOBALS[__FUNCTION__][$userid];
2410 // Wrapper to check if url_blacklist is enabled
2411 function isUrlBlacklistEnabled () {
2412 // Do we have cache?
2413 if (!isset($GLOBALS[__FUNCTION__])) {
2415 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2419 return $GLOBALS[__FUNCTION__];
2422 // Checks wether direct payment is allowed in configuration
2423 function isDirectPaymentEnabled () {
2424 // Do we have cache?
2425 if (!isset($GLOBALS[__FUNCTION__])) {
2427 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2431 return $GLOBALS[__FUNCTION__];
2434 // Wrapper to check if current task is for extension (not update)
2435 function isExtensionTask ($content) {
2436 // Do we have cache?
2437 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2439 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2443 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2446 // Wrapper to check if output mode is CSS
2447 function isCssOutputMode () {
2449 return (getScriptOutputMode() == 1);
2452 // Wrapper to check if output mode is HTML
2453 function isHtmlOutputMode () {
2455 return (getScriptOutputMode() == 0);
2458 // Wrapper to check if output mode is RAW
2459 function isRawOutputMode () {
2461 return (getScriptOutputMode() == -1);
2464 // Wrapper to generate a user email link
2465 function generateWrappedUserEmailLink ($email) {
2466 // Just call the inner function
2467 return generateEmailLink($email, 'user_data');
2470 // Wrapper to check if user points are locked
2471 function ifUserPointsLocked ($userid) {
2472 // Do we have cache?
2473 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2475 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2479 return $GLOBALS[__FUNCTION__][$userid];
2482 // Appends a line to an existing file or creates it instantly with given content.
2483 // This function does always add a new-line character to every line.
2484 function appendLineToFile ($file, $line) {
2485 $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2486 fwrite($fp, $line . "\n");
2490 // Wrapper for changeDataInFile() but with full path added
2491 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2493 $FQFN = getPath() . $FQFN;
2495 // Call inner function
2496 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);
2499 // Wrapper for changing entries in config-local.php
2500 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $DATA, $seek = 0) {
2501 // Call the inner function
2502 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $DATA, $seek);
2505 // Shortens ucfirst(strtolower()) calls
2506 function firstCharUpperCase ($str) {
2507 return ucfirst(strtolower($str));
2510 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2511 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2512 // Get the configuration entry
2513 $configValue = getConfig($configEntry);
2515 // Call inner method
2516 return createTimeSelections($configValue, $configEntry, $stamps, $align);
2519 // Shortens converting of German comma to Computer's version in POST data
2520 function convertCommaToDotInPostData ($postEntry) {
2521 // Read and convert given entry
2522 $postValue = convertCommaToDot(postRequestParameter($postEntry));
2524 // ... and set it again
2525 setPostRequestParameter($postEntry, $postValue);
2528 // Converts German commas to Computer's version in all entries
2529 function convertCommaToDotInPostDataArray ($postEntries) {
2530 // Replace german decimal comma with computer decimal dot
2531 foreach ($postEntries as $entry) {
2532 // Is the entry there?
2533 if (isPostRequestParameterSet($entry)) {
2535 convertCommaToDotInPostData($entry);
2541 * Parses a string into a US formated float variable, taken from user comments
2542 * from PHP documentation website.
2544 * @param $floatString A string holding a float expression
2545 * @return $float Corresponding float variable
2546 * @author chris<at>georgakopoulos<dot>com
2547 * @link http://de.php.net/manual/en/function.floatval.php#92563
2549 function parseFloat ($floatString){
2550 $LocaleInfo = localeconv();
2551 $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '', $floatString);
2552 $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2553 return floatval($floatString);
2556 //-----------------------------------------------------------------------------
2557 // Configuration wrapper
2558 //-----------------------------------------------------------------------------
2560 // Getter for 'check_double_email'
2561 function getCheckDoubleEmail () {
2562 // Is the cache entry set?
2563 if (!isset($GLOBALS[__FUNCTION__])) {
2564 // No, so determine it
2565 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2568 // Return cached entry
2569 return $GLOBALS[__FUNCTION__];
2572 // Checks wether 'check_double_email' is 'Y'
2573 function isCheckDoubleEmailEnabled () {
2574 // Is the cache entry set?
2575 if (!isset($GLOBALS[__FUNCTION__])) {
2576 // No, so determine it
2577 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2580 // Return cached entry
2581 return $GLOBALS[__FUNCTION__];