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 () {
435 return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
438 // Copies a file from source to destination and verifies if that goes fine.
439 // This function should wrap the copy() command and make a nicer debug backtrace
440 // even if there is no xdebug extension installed.
441 function copyFileVerified ($source, $dest, $chmod = '') {
442 // Failed is the default
445 // Is the source file there?
446 if (!isFileReadable($source)) {
448 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
451 // Is the target directory there?
452 if (!isDirectory(dirname($dest))) {
454 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
457 // Now try to copy it
458 if (!copy($source, $dest)) {
459 // Something went wrong
460 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
463 $GLOBALS['file_readable'][$dest] = true;
466 // If there are chmod rights set, apply them
467 if (!empty($chmod)) {
469 $status = changeMode($dest, $chmod);
479 // Wrapper function for header()
480 // Send a header but checks before if we can do so
481 function sendHeader ($header) {
483 //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header);
484 $GLOBALS['header'][] = trim($header);
487 // Flushes all headers
488 function flushHeaders () {
489 // Is the header already sent?
490 if (headers_sent()) {
492 debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!');
495 // Flush all headers if found
496 if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) {
497 foreach ($GLOBALS['header'] as $header) {
502 // Mark them as flushed
503 $GLOBALS['header'] = array();
506 // Wrapper function for chmod()
507 // @TODO Do some more sanity check here
508 function changeMode ($FQFN, $mode) {
509 // Is the file/directory there?
510 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
511 // Neither, so abort here
512 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
516 return chmod($FQFN, $mode);
519 // Wrapper for unlink()
520 function removeFile ($FQFN) {
521 // Is the file there?
522 if (isFileReadable($FQFN)) {
524 $GLOBALS['file_readable'][$FQFN] = false;
527 return unlink($FQFN);
530 // All fine if no file was removed. If we change this to 'false' or rewrite
531 // above if() block it would be to restrictive.
535 // Wrapper for $_POST['sel']
536 function countPostSelection ($element = 'sel') {
538 if (isPostRequestParameterSet($element)) {
539 // Return counted elements
540 return countSelection(postRequestParameter($element));
542 // Return zero if not found
547 // Checks wether the config-local.php is loaded
548 function isConfigLocalLoaded () {
549 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
552 // Checks wether a nickname or userid was entered and caches the result
553 function isNicknameUsed ($userid) {
554 // Is the cache there
555 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
557 $GLOBALS[__FUNCTION__][$userid] = (('' . round($userid) . '') != $userid);
561 return $GLOBALS[__FUNCTION__][$userid];
564 // Getter for 'what' value
565 function getWhat () {
570 if (isWhatSet(true)) {
572 $what = $GLOBALS['what'];
579 // Setter for 'what' value
580 function setWhat ($newWhat) {
581 $GLOBALS['what'] = SQL_ESCAPE($newWhat);
584 // Setter for 'what' from configuration
585 function setWhatFromConfig ($configEntry) {
586 // Get 'what' from config
587 $what = getConfig($configEntry);
593 // Checks wether what is set and optionally aborts on miss
594 function isWhatSet ($strict = false) {
596 $isset = isset($GLOBALS['what']);
598 // Should we abort here?
599 if (($strict === true) && ($isset === false)) {
601 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
608 // Getter for 'action' value
609 function getAction ($strict = true) {
614 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
616 $action = $GLOBALS['action'];
623 // Setter for 'action' value
624 function setAction ($newAction) {
625 $GLOBALS['action'] = SQL_ESCAPE($newAction);
628 // Checks wether action is set and optionally aborts on miss
629 function isActionSet ($strict = false) {
631 $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action'])));
633 // Should we abort here?
634 if (($strict === true) && ($isset === false)) {
636 debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.');
643 // Getter for 'module' value
644 function getModule ($strict = true) {
649 if (isModuleSet($strict)) {
651 $module = $GLOBALS['module'];
658 // Setter for 'module' value
659 function setModule ($newModule) {
660 // Secure it and make all modules lower-case
661 $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
664 // Checks wether module is set and optionally aborts on miss
665 function isModuleSet ($strict = false) {
667 $isset = (!empty($GLOBALS['module']));
669 // Should we abort here?
670 if (($strict === true) && ($isset === false)) {
672 debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.');
676 return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
679 // Getter for 'output_mode' value
680 function getScriptOutputMode () {
682 if (!isset($GLOBALS[__FUNCTION__])) {
687 if (isOutputModeSet(true)) {
689 $output_mode = $GLOBALS['output_mode'];
693 $GLOBALS[__FUNCTION__] = $output_mode;
697 return $GLOBALS[__FUNCTION__];
700 // Setter for 'output_mode' value
701 function setOutputMode ($newOutputMode) {
702 $GLOBALS['output_mode'] = (int) $newOutputMode;
705 // Checks wether output_mode is set and optionally aborts on miss
706 function isOutputModeSet ($strict = false) {
708 $isset = (isset($GLOBALS['output_mode']));
710 // Should we abort here?
711 if (($strict === true) && ($isset === false)) {
713 debug_report_bug(__FUNCTION__, __LINE__, 'Output mode is not set.');
720 // Enables block-mode
721 function enableBlockMode ($enabled = true) {
722 $GLOBALS['block_mode'] = $enabled;
725 // Checks wether block-mode is enabled
726 function isBlockModeEnabled () {
728 if (!isset($GLOBALS['block_mode'])) {
730 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
734 return $GLOBALS['block_mode'];
737 // Wrapper function for addPointsThroughReferalSystem()
738 function addPointsDirectly ($subject, $userid, $points) {
740 unset($GLOBALS['ref_level']);
742 // Call more complicated method (due to more parameters)
743 return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'direct');
746 // Wrapper for redirectToUrl but URL comes from a configuration entry
747 function redirectToConfiguredUrl ($configEntry) {
749 redirectToUrl(getConfig($configEntry));
752 // Wrapper function to redirect from member-only modules to index
753 function redirectToIndexMemberOnlyModule () {
754 // Do the redirect here
755 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
758 // Wrapper function to redirect to current URL
759 function redirectToRequestUri () {
760 redirectToUrl(basename(detectRequestUri()));
763 // Wrapper function to redirect to de-refered URL
764 function redirectToDereferedUrl ($URL) {
766 redirectToUrl(generateDerefererUrl($URL));
769 // Wrapper function for checking if extension is installed and newer or same version
770 function isExtensionInstalledAndNewer ($ext_name, $version) {
771 // Is an cache entry found?
772 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
774 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
776 // Cache hits should be incremented twice
777 incrementStatsEntry('cache_hits', 2);
781 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
782 return $GLOBALS[__FUNCTION__][$ext_name][$version];
785 // Wrapper function for checking if extension is installed and older than given version
786 function isExtensionInstalledAndOlder ($ext_name, $version) {
787 // Is an cache entry found?
788 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
790 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
792 // Cache hits should be incremented twice
793 incrementStatsEntry('cache_hits', 2);
797 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
798 return $GLOBALS[__FUNCTION__][$ext_name][$version];
802 function setUsername ($userName) {
803 $GLOBALS['username'] = (string) $userName;
807 function getUsername () {
809 if (!isset($GLOBALS['username'])) {
810 // No, so it has to be a guest
811 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
815 return $GLOBALS['username'];
818 // Wrapper function for installation phase
819 function isInstallationPhase () {
821 if (!isset($GLOBALS[__FUNCTION__])) {
823 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
827 return $GLOBALS[__FUNCTION__];
830 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
831 function isDemoModeActive () {
833 if (!isset($GLOBALS[__FUNCTION__])) {
835 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
839 return $GLOBALS[__FUNCTION__];
842 // Getter for PHP caching value
843 function getPhpCaching () {
844 return $GLOBALS['php_caching'];
847 // Checks wether the admin hash is set
848 function isAdminHashSet ($adminId) {
849 // Is the array there?
850 if (!isset($GLOBALS['cache_array']['admin'])) {
851 // Missing array should be reported
852 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
855 // Check for admin hash
856 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
859 // Setter for admin hash
860 function setAdminHash ($adminId, $hash) {
861 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
864 // Getter for current admin login
865 function getCurrentAdminLogin () {
867 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
870 if (!isset($GLOBALS[__FUNCTION__])) {
872 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
876 return $GLOBALS[__FUNCTION__];
879 // Setter for admin id (and current)
880 function setAdminId ($adminId) {
882 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
885 $status = setSession('admin_id', bigintval($adminId));
888 setCurrentAdminId($adminId);
894 // Setter for admin_last
895 function setAdminLast ($adminLast) {
897 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
900 $status = setSession('admin_last', $adminLast);
906 // Setter for admin_md5
907 function setAdminMd5 ($adminMd5) {
909 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
912 $status = setSession('admin_md5', $adminMd5);
918 // Getter for admin_md5
919 function getAdminMd5 () {
921 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
924 return getSession('admin_md5');
927 // Init user data array
928 function initUserData () {
929 // User id should not be zero
930 if (!isValidUserId(getCurrentUserId())) {
931 // Should be always valid
932 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
936 $GLOBALS['user_data'][getCurrentUserId()] = array();
939 // Getter for user data
940 function getUserData ($column) {
941 // User id should not be zero
942 if (!isValidUserId(getCurrentUserId())) {
943 // Should be always valid
944 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
948 return $GLOBALS['user_data'][getCurrentUserId()][$column];
951 // Geter for whole user data array
952 function getUserDataArray () {
954 $userid = getCurrentUserId();
956 // Is the current userid valid?
957 if (!isValidUserId($userid)) {
958 // Should be always valid
959 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
962 // Get the whole array if found
963 if (isset($GLOBALS['user_data'][$userid])) {
964 // Found, so return it
965 return $GLOBALS['user_data'][$userid];
967 // Return empty array
972 // Checks if the user data is valid, this may indicate that the user has logged
973 // in, but you should use isMember() if you want to find that out.
974 function isUserDataValid () {
975 // User id should not be zero so abort here
976 if (!isCurrentUserIdSet()) return false;
979 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
981 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
985 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
988 // Setter for current userid
989 function setCurrentUserId ($userid) {
991 $GLOBALS['current_userid'] = bigintval($userid);
993 // Unset it to re-determine the actual state
994 unset($GLOBALS['is_userdata_valid'][$userid]);
997 // Getter for current userid
998 function getCurrentUserId () {
999 // Userid must be set before it can be used
1000 if (!isCurrentUserIdSet()) {
1002 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
1005 // Return the userid
1006 return $GLOBALS['current_userid'];
1009 // Checks if current userid is set
1010 function isCurrentUserIdSet () {
1011 return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1014 // Checks wether we are debugging template cache
1015 function isDebuggingTemplateCache () {
1016 // Do we have cache?
1017 if (!isset($GLOBALS[__FUNCTION__])) {
1019 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1023 return $GLOBALS[__FUNCTION__];
1026 // Wrapper for fetchUserData() and getUserData() calls
1027 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1029 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1030 // Default is 'guest'
1031 $data = '{--USERNAME_GUEST--}';
1033 // Can we fetch the user data?
1034 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1035 // Now get the data back
1036 $data = getUserData($valueColumn);
1040 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1044 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1047 // Wrapper for strpos() to ease porting from deprecated ereg() function
1048 function isInString ($needle, $haystack) {
1049 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1050 return (strpos($haystack, $needle) !== false);
1053 // Wrapper for strpos() to ease porting from deprecated eregi() function
1054 // This function is case-insensitive
1055 function isInStringIgnoreCase ($needle, $haystack) {
1056 return (isInString(strtolower($needle), strtolower($haystack)));
1059 // Wrapper to check for if fatal errors where detected
1060 function ifFatalErrorsDetected () {
1061 // Just call the inner function
1062 return (getTotalFatalErrors() > 0);
1065 // Setter for HTTP status
1066 function setHttpStatus ($status) {
1067 $GLOBALS['http_status'] = (string) $status;
1070 // Getter for HTTP status
1071 function getHttpStatus () {
1072 // Is the status set?
1073 if (!isset($GLOBALS['http_status'])) {
1075 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1079 return $GLOBALS['http_status'];
1083 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1084 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1086 * ----------------------------------------------------------------------------
1087 * If you want to redirect, please use redirectToUrl(); instead
1088 * ----------------------------------------------------------------------------
1090 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1092 * @link http://support.microsoft.com/kb/q176113/
1093 * @author Andreas Gohr <andi@splitbrain.org>
1096 function sendRawRedirect ($url) {
1097 // Send helping header
1098 setHttpStatus('302 Found');
1100 // always close the session
1101 session_write_close();
1103 // Revert entity &
1104 $url = str_replace('&', '&', $url);
1106 // check if running on IIS < 6 with CGI-PHP
1107 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1108 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
1109 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1110 ($matches[1] < 6)) {
1111 // Send the IIS header
1112 sendHeader('Refresh: 0;url=' . $url);
1114 // Send generic header
1115 sendHeader('Location: ' . $url);
1122 // Determines the country of the given user id
1123 function determineCountry ($userid) {
1124 // Do we have cache?
1125 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1126 // Default is 'invalid'
1127 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1129 // Is extension country active?
1130 if (isExtensionActive('country')) {
1131 // Determine the right country code through the country id
1132 $id = getUserData('country_code');
1134 // Then handle it over
1135 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1137 // Get raw code from user data
1138 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1143 return $GLOBALS[__FUNCTION__][$userid];
1146 // "Getter" for total confirmed user accounts
1147 function getTotalConfirmedUser () {
1149 if (!isset($GLOBALS[__FUNCTION__])) {
1151 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1154 // Return cached value
1155 return $GLOBALS[__FUNCTION__];
1158 // "Getter" for total unconfirmed user accounts
1159 function getTotalUnconfirmedUser () {
1161 if (!isset($GLOBALS[__FUNCTION__])) {
1163 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1166 // Return cached value
1167 return $GLOBALS[__FUNCTION__];
1170 // "Getter" for total locked user accounts
1171 function getTotalLockedUser () {
1173 if (!isset($GLOBALS[__FUNCTION__])) {
1175 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1178 // Return cached value
1179 return $GLOBALS[__FUNCTION__];
1182 // Is given userid valid?
1183 function isValidUserId ($userid) {
1184 // Do we have cache?
1185 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1187 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1191 return $GLOBALS[__FUNCTION__][$userid];
1195 function encodeEntities ($str) {
1197 $str = secureString($str, true, true);
1199 // Encode dollar sign as well
1200 $str = str_replace('$', '$', $str);
1206 // "Getter" for date from patch_ctime
1207 function getDateFromPatchTime () {
1209 if (!isset($GLOBALS[__FUNCTION__])) {
1211 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1215 return $GLOBALS[__FUNCTION__];
1218 // Getter for current year (default)
1219 function getYear ($timestamp = null) {
1221 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1223 if (is_null($timestamp)) $timestamp = time();
1226 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1230 return $GLOBALS[__FUNCTION__][$timestamp];
1233 // Getter for current month (default)
1234 function getMonth ($timestamp = null) {
1236 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1237 // If null is set, use time()
1238 if (is_null($timestamp)) {
1239 // Use time() which is current timestamp
1240 $timestamp = time();
1244 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1248 return $GLOBALS[__FUNCTION__][$timestamp];
1251 // Getter for current hour (default)
1252 function getHour ($timestamp = null) {
1254 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1256 if (is_null($timestamp)) {
1257 $timestamp = time();
1261 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1265 return $GLOBALS[__FUNCTION__][$timestamp];
1268 // Getter for current day (default)
1269 function getDay ($timestamp = null) {
1271 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1273 if (is_null($timestamp)) {
1274 $timestamp = time();
1278 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1282 return $GLOBALS[__FUNCTION__][$timestamp];
1285 // Getter for current week (default)
1286 function getWeek ($timestamp = null) {
1288 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1290 if (is_null($timestamp)) $timestamp = time();
1293 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1297 return $GLOBALS[__FUNCTION__][$timestamp];
1300 // Getter for current short_hour (default)
1301 function getShortHour ($timestamp = null) {
1303 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1305 if (is_null($timestamp)) $timestamp = time();
1308 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1312 return $GLOBALS[__FUNCTION__][$timestamp];
1315 // Getter for current long_hour (default)
1316 function getLongHour ($timestamp = null) {
1318 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1320 if (is_null($timestamp)) $timestamp = time();
1323 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1327 return $GLOBALS[__FUNCTION__][$timestamp];
1330 // Getter for current second (default)
1331 function getSecond ($timestamp = null) {
1333 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1335 if (is_null($timestamp)) $timestamp = time();
1338 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1342 return $GLOBALS[__FUNCTION__][$timestamp];
1345 // Getter for current minute (default)
1346 function getMinute ($timestamp = null) {
1348 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1350 if (is_null($timestamp)) $timestamp = time();
1353 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1357 return $GLOBALS[__FUNCTION__][$timestamp];
1360 // Checks wether the title decoration is enabled
1361 function isTitleDecorationEnabled () {
1362 // Do we have cache?
1363 if (!isset($GLOBALS[__FUNCTION__])) {
1365 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1369 return $GLOBALS[__FUNCTION__];
1372 // Checks wether filter usage updates are enabled (expensive queries!)
1373 function isFilterUsageUpdateEnabled () {
1374 // Do we have cache?
1375 if (!isset($GLOBALS[__FUNCTION__])) {
1377 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1381 return $GLOBALS[__FUNCTION__];
1384 // Checks wether debugging of weekly resets is enabled
1385 function isWeeklyResetDebugEnabled () {
1386 // Do we have cache?
1387 if (!isset($GLOBALS[__FUNCTION__])) {
1389 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1393 return $GLOBALS[__FUNCTION__];
1396 // Checks wether debugging of monthly resets is enabled
1397 function isMonthlyResetDebugEnabled () {
1398 // Do we have cache?
1399 if (!isset($GLOBALS[__FUNCTION__])) {
1401 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1405 return $GLOBALS[__FUNCTION__];
1408 // Checks wether displaying of debug SQLs are enabled
1409 function isDisplayDebugSqlEnabled () {
1410 // Do we have cache?
1411 if (!isset($GLOBALS[__FUNCTION__])) {
1413 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1417 return $GLOBALS[__FUNCTION__];
1420 // Checks wether module title is enabled
1421 function isModuleTitleEnabled () {
1422 // Do we have cache?
1423 if (!isset($GLOBALS[__FUNCTION__])) {
1425 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1429 return $GLOBALS[__FUNCTION__];
1432 // Checks wether what title is enabled
1433 function isWhatTitleEnabled () {
1434 // Do we have cache?
1435 if (!isset($GLOBALS[__FUNCTION__])) {
1437 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1441 return $GLOBALS[__FUNCTION__];
1444 // Checks wether stats are enabled
1445 function ifStatsAreEnabled () {
1446 // Do we have cache?
1447 if (!isset($GLOBALS[__FUNCTION__])) {
1448 // Then determine it
1449 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1452 // Return cached value
1453 return $GLOBALS[__FUNCTION__];
1456 // Checks wether admin-notification of certain user actions is enabled
1457 function isAdminNotificationEnabled () {
1458 // Do we have cache?
1459 if (!isset($GLOBALS[__FUNCTION__])) {
1461 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1465 return $GLOBALS[__FUNCTION__];
1468 // Checks wether random referal id selection is enabled
1469 function isRandomReferalIdEnabled () {
1470 // Do we have cache?
1471 if (!isset($GLOBALS[__FUNCTION__])) {
1473 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1477 return $GLOBALS[__FUNCTION__];
1480 // "Getter" for default language
1481 function getDefaultLanguage () {
1482 // Do we have cache?
1483 if (!isset($GLOBALS[__FUNCTION__])) {
1485 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1489 return $GLOBALS[__FUNCTION__];
1492 // "Getter" for default referal id
1493 function getDefRefid () {
1494 // Do we have cache?
1495 if (!isset($GLOBALS[__FUNCTION__])) {
1497 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1501 return $GLOBALS[__FUNCTION__];
1504 // "Getter" for path
1505 function getPath () {
1506 // Do we have cache?
1507 if (!isset($GLOBALS[__FUNCTION__])) {
1509 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1513 return $GLOBALS[__FUNCTION__];
1517 function getUrl () {
1518 // Do we have cache?
1519 if (!isset($GLOBALS[__FUNCTION__])) {
1521 $GLOBALS[__FUNCTION__] = getConfig('URL');
1525 return $GLOBALS[__FUNCTION__];
1528 // "Getter" for cache_path
1529 function getCachePath () {
1530 // Do we have cache?
1531 if (!isset($GLOBALS[__FUNCTION__])) {
1533 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1537 return $GLOBALS[__FUNCTION__];
1540 // "Getter" for secret_key
1541 function getSecretKey () {
1542 // Do we have cache?
1543 if (!isset($GLOBALS[__FUNCTION__])) {
1545 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1549 return $GLOBALS[__FUNCTION__];
1552 // "Getter" for SITE_KEY
1553 function getSiteKey () {
1554 // Do we have cache?
1555 if (!isset($GLOBALS[__FUNCTION__])) {
1557 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1561 return $GLOBALS[__FUNCTION__];
1564 // "Getter" for DATE_KEY
1565 function getDateKey () {
1566 // Do we have cache?
1567 if (!isset($GLOBALS[__FUNCTION__])) {
1569 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1573 return $GLOBALS[__FUNCTION__];
1576 // "Getter" for master_salt
1577 function getMasterSalt () {
1578 // Do we have cache?
1579 if (!isset($GLOBALS[__FUNCTION__])) {
1581 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1585 return $GLOBALS[__FUNCTION__];
1588 // "Getter" for prime
1589 function getPrime () {
1590 // Do we have cache?
1591 if (!isset($GLOBALS[__FUNCTION__])) {
1593 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1597 return $GLOBALS[__FUNCTION__];
1600 // "Getter" for encrypt_seperator
1601 function getEncryptSeperator () {
1602 // Do we have cache?
1603 if (!isset($GLOBALS[__FUNCTION__])) {
1605 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1609 return $GLOBALS[__FUNCTION__];
1612 // "Getter" for mysql_prefix
1613 function getMysqlPrefix () {
1614 // Do we have cache?
1615 if (!isset($GLOBALS[__FUNCTION__])) {
1617 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1621 return $GLOBALS[__FUNCTION__];
1624 // "Getter" for table_type
1625 function getTableType () {
1626 // Do we have cache?
1627 if (!isset($GLOBALS[__FUNCTION__])) {
1629 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1633 return $GLOBALS[__FUNCTION__];
1636 // "Getter" for salt_length
1637 function getSaltLength () {
1638 // Do we have cache?
1639 if (!isset($GLOBALS[__FUNCTION__])) {
1641 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1645 return $GLOBALS[__FUNCTION__];
1648 // "Getter" for output_mode
1649 function getOutputMode () {
1650 // Do we have cache?
1651 if (!isset($GLOBALS[__FUNCTION__])) {
1653 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1657 return $GLOBALS[__FUNCTION__];
1660 // "Getter" for full_version
1661 function getFullVersion () {
1662 // Do we have cache?
1663 if (!isset($GLOBALS[__FUNCTION__])) {
1665 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1669 return $GLOBALS[__FUNCTION__];
1672 // "Getter" for title
1673 function getTitle () {
1674 // Do we have cache?
1675 if (!isset($GLOBALS[__FUNCTION__])) {
1677 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1681 return $GLOBALS[__FUNCTION__];
1684 // "Getter" for curr_svn_revision
1685 function getCurrentRepositoryRevision () {
1686 // Do we have cache?
1687 if (!isset($GLOBALS[__FUNCTION__])) {
1689 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1693 return $GLOBALS[__FUNCTION__];
1696 // "Getter" for server_url
1697 function getServerUrl () {
1698 // Do we have cache?
1699 if (!isset($GLOBALS[__FUNCTION__])) {
1701 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1705 return $GLOBALS[__FUNCTION__];
1708 // "Getter" for mt_word
1709 function getMtWord () {
1710 // Do we have cache?
1711 if (!isset($GLOBALS[__FUNCTION__])) {
1713 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1717 return $GLOBALS[__FUNCTION__];
1720 // "Getter" for mt_word2
1721 function getMtWord2 () {
1722 // Do we have cache?
1723 if (!isset($GLOBALS[__FUNCTION__])) {
1725 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1729 return $GLOBALS[__FUNCTION__];
1732 // "Getter" for main_title
1733 function getMainTitle () {
1734 // Do we have cache?
1735 if (!isset($GLOBALS[__FUNCTION__])) {
1737 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1741 return $GLOBALS[__FUNCTION__];
1744 // "Getter" for file_hash
1745 function getFileHash () {
1746 // Do we have cache?
1747 if (!isset($GLOBALS[__FUNCTION__])) {
1749 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1753 return $GLOBALS[__FUNCTION__];
1756 // "Getter" for pass_scramble
1757 function getPassScramble () {
1758 // Do we have cache?
1759 if (!isset($GLOBALS[__FUNCTION__])) {
1761 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1765 return $GLOBALS[__FUNCTION__];
1768 // "Getter" for ap_inactive_since
1769 function getApInactiveSince () {
1770 // Do we have cache?
1771 if (!isset($GLOBALS[__FUNCTION__])) {
1773 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1777 return $GLOBALS[__FUNCTION__];
1780 // "Getter" for user_min_confirmed
1781 function getUserMinConfirmed () {
1782 // Do we have cache?
1783 if (!isset($GLOBALS[__FUNCTION__])) {
1785 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1789 return $GLOBALS[__FUNCTION__];
1792 // "Getter" for auto_purge
1793 function getAutoPurge () {
1794 // Do we have cache?
1795 if (!isset($GLOBALS[__FUNCTION__])) {
1797 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1801 return $GLOBALS[__FUNCTION__];
1804 // "Getter" for bonus_userid
1805 function getBonusUserid () {
1806 // Do we have cache?
1807 if (!isset($GLOBALS[__FUNCTION__])) {
1809 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1813 return $GLOBALS[__FUNCTION__];
1816 // "Getter" for ap_inactive_time
1817 function getApInactiveTime () {
1818 // Do we have cache?
1819 if (!isset($GLOBALS[__FUNCTION__])) {
1821 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1825 return $GLOBALS[__FUNCTION__];
1828 // "Getter" for ap_dm_timeout
1829 function getApDmTimeout () {
1830 // Do we have cache?
1831 if (!isset($GLOBALS[__FUNCTION__])) {
1833 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1837 return $GLOBALS[__FUNCTION__];
1840 // "Getter" for ap_tasks_time
1841 function getApTasksTime () {
1842 // Do we have cache?
1843 if (!isset($GLOBALS[__FUNCTION__])) {
1845 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1849 return $GLOBALS[__FUNCTION__];
1852 // "Getter" for ap_unconfirmed_time
1853 function getApUnconfirmedTime () {
1854 // Do we have cache?
1855 if (!isset($GLOBALS[__FUNCTION__])) {
1857 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1861 return $GLOBALS[__FUNCTION__];
1864 // "Getter" for points
1865 function getPoints () {
1866 // Do we have cache?
1867 if (!isset($GLOBALS[__FUNCTION__])) {
1869 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1873 return $GLOBALS[__FUNCTION__];
1876 // "Getter" for slogan
1877 function getSlogan () {
1878 // Do we have cache?
1879 if (!isset($GLOBALS[__FUNCTION__])) {
1881 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1885 return $GLOBALS[__FUNCTION__];
1888 // "Getter" for copy
1889 function getCopy () {
1890 // Do we have cache?
1891 if (!isset($GLOBALS[__FUNCTION__])) {
1893 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1897 return $GLOBALS[__FUNCTION__];
1900 // "Getter" for webmaster
1901 function getWebmaster () {
1902 // Do we have cache?
1903 if (!isset($GLOBALS[__FUNCTION__])) {
1905 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1909 return $GLOBALS[__FUNCTION__];
1912 // "Getter" for sql_count
1913 function getSqlCount () {
1914 // Do we have cache?
1915 if (!isset($GLOBALS[__FUNCTION__])) {
1917 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1921 return $GLOBALS[__FUNCTION__];
1924 // "Getter" for num_templates
1925 function getNumTemplates () {
1926 // Do we have cache?
1927 if (!isset($GLOBALS[__FUNCTION__])) {
1929 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1933 return $GLOBALS[__FUNCTION__];
1936 // "Getter" for dns_cache_timeout
1937 function getDnsCacheTimeout () {
1938 // Do we have cache?
1939 if (!isset($GLOBALS[__FUNCTION__])) {
1941 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1945 return $GLOBALS[__FUNCTION__];
1948 // "Getter" for menu_blur_spacer
1949 function getMenuBlurSpacer () {
1950 // Do we have cache?
1951 if (!isset($GLOBALS[__FUNCTION__])) {
1953 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
1957 return $GLOBALS[__FUNCTION__];
1960 // "Getter" for points_register
1961 function getPointsRegister () {
1962 // Do we have cache?
1963 if (!isset($GLOBALS[__FUNCTION__])) {
1965 $GLOBALS[__FUNCTION__] = getConfig('points_register');
1969 return $GLOBALS[__FUNCTION__];
1972 // "Getter" for points_ref
1973 function getPointsRef () {
1974 // Do we have cache?
1975 if (!isset($GLOBALS[__FUNCTION__])) {
1977 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
1981 return $GLOBALS[__FUNCTION__];
1984 // "Getter" for ref_payout
1985 function getRefPayout () {
1986 // Do we have cache?
1987 if (!isset($GLOBALS[__FUNCTION__])) {
1989 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
1993 return $GLOBALS[__FUNCTION__];
1996 // "Getter" for online_timeout
1997 function getOnlineTimeout () {
1998 // Do we have cache?
1999 if (!isset($GLOBALS[__FUNCTION__])) {
2001 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2005 return $GLOBALS[__FUNCTION__];
2008 // "Getter" for index_home
2009 function getIndexHome () {
2010 // Do we have cache?
2011 if (!isset($GLOBALS[__FUNCTION__])) {
2013 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2017 return $GLOBALS[__FUNCTION__];
2020 // "Getter" for one_day
2021 function getOneDay () {
2022 // Do we have cache?
2023 if (!isset($GLOBALS[__FUNCTION__])) {
2025 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2029 return $GLOBALS[__FUNCTION__];
2032 // "Getter" for activate_xchange
2033 function getActivateXchange () {
2034 // Do we have cache?
2035 if (!isset($GLOBALS[__FUNCTION__])) {
2037 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2041 return $GLOBALS[__FUNCTION__];
2044 // "Getter" for img_type
2045 function getImgType () {
2046 // Do we have cache?
2047 if (!isset($GLOBALS[__FUNCTION__])) {
2049 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2053 return $GLOBALS[__FUNCTION__];
2056 // "Getter" for code_length
2057 function getCodeLength () {
2058 // Do we have cache?
2059 if (!isset($GLOBALS[__FUNCTION__])) {
2061 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2065 return $GLOBALS[__FUNCTION__];
2068 // "Getter" for least_cats
2069 function getLeastCats () {
2070 // Do we have cache?
2071 if (!isset($GLOBALS[__FUNCTION__])) {
2073 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2077 return $GLOBALS[__FUNCTION__];
2080 // "Getter" for pass_len
2081 function getPassLen () {
2082 // Do we have cache?
2083 if (!isset($GLOBALS[__FUNCTION__])) {
2085 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2089 return $GLOBALS[__FUNCTION__];
2092 // "Getter" for admin_menu
2093 function getAdminMenu () {
2094 // Do we have cache?
2095 if (!isset($GLOBALS[__FUNCTION__])) {
2097 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2101 return $GLOBALS[__FUNCTION__];
2104 // "Getter" for last_month
2105 function getLastMonth () {
2106 // Do we have cache?
2107 if (!isset($GLOBALS[__FUNCTION__])) {
2109 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2113 return $GLOBALS[__FUNCTION__];
2116 // "Getter" for max_send
2117 function getMaxSend () {
2118 // Do we have cache?
2119 if (!isset($GLOBALS[__FUNCTION__])) {
2121 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2125 return $GLOBALS[__FUNCTION__];
2128 // "Getter" for mails_page
2129 function getMailsPage () {
2130 // Do we have cache?
2131 if (!isset($GLOBALS[__FUNCTION__])) {
2133 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2137 return $GLOBALS[__FUNCTION__];
2140 // "Getter" for rand_no
2141 function getRandNo () {
2142 // Do we have cache?
2143 if (!isset($GLOBALS[__FUNCTION__])) {
2145 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2149 return $GLOBALS[__FUNCTION__];
2152 // "Getter" for __DB_NAME
2153 function getDbName () {
2154 // Do we have cache?
2155 if (!isset($GLOBALS[__FUNCTION__])) {
2157 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2161 return $GLOBALS[__FUNCTION__];
2164 // "Getter" for DOMAIN
2165 function getDomain () {
2166 // Do we have cache?
2167 if (!isset($GLOBALS[__FUNCTION__])) {
2169 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2173 return $GLOBALS[__FUNCTION__];
2176 // "Getter" for proxy_username
2177 function getProxyUsername () {
2178 // Do we have cache?
2179 if (!isset($GLOBALS[__FUNCTION__])) {
2181 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2185 return $GLOBALS[__FUNCTION__];
2188 // "Getter" for proxy_password
2189 function getProxyPassword () {
2190 // Do we have cache?
2191 if (!isset($GLOBALS[__FUNCTION__])) {
2193 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2197 return $GLOBALS[__FUNCTION__];
2200 // "Getter" for proxy_host
2201 function getProxyHost () {
2202 // Do we have cache?
2203 if (!isset($GLOBALS[__FUNCTION__])) {
2205 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2209 return $GLOBALS[__FUNCTION__];
2212 // "Getter" for proxy_port
2213 function getProxyPort () {
2214 // Do we have cache?
2215 if (!isset($GLOBALS[__FUNCTION__])) {
2217 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2221 return $GLOBALS[__FUNCTION__];
2224 // "Getter" for SMTP_HOSTNAME
2225 function getSmtpHostname () {
2226 // Do we have cache?
2227 if (!isset($GLOBALS[__FUNCTION__])) {
2229 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2233 return $GLOBALS[__FUNCTION__];
2236 // "Getter" for SMTP_USER
2237 function getSmtpUser () {
2238 // Do we have cache?
2239 if (!isset($GLOBALS[__FUNCTION__])) {
2241 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2245 return $GLOBALS[__FUNCTION__];
2248 // "Getter" for SMTP_PASSWORD
2249 function getSmtpPassword () {
2250 // Do we have cache?
2251 if (!isset($GLOBALS[__FUNCTION__])) {
2253 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2257 return $GLOBALS[__FUNCTION__];
2260 // "Getter" for points_word
2261 function getPointsWord () {
2262 // Do we have cache?
2263 if (!isset($GLOBALS[__FUNCTION__])) {
2265 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2269 return $GLOBALS[__FUNCTION__];
2272 // "Getter" for profile_lock
2273 function getProfileLock () {
2274 // Do we have cache?
2275 if (!isset($GLOBALS[__FUNCTION__])) {
2277 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2281 return $GLOBALS[__FUNCTION__];
2284 // "Getter" for url_tlock
2285 function getUrlTlock () {
2286 // Do we have cache?
2287 if (!isset($GLOBALS[__FUNCTION__])) {
2289 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2293 return $GLOBALS[__FUNCTION__];
2296 // Checks wether proxy configuration is used
2297 function isProxyUsed () {
2298 // Do we have cache?
2299 if (!isset($GLOBALS[__FUNCTION__])) {
2301 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2305 return $GLOBALS[__FUNCTION__];
2308 // Checks wether POST data contains selections
2309 function ifPostContainsSelections ($element = 'sel') {
2310 // Do we have cache?
2311 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2313 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
2317 return $GLOBALS[__FUNCTION__][$element];
2320 // Checks wether verbose_sql is Y and returns true/false if so
2321 function isVerboseSqlEnabled () {
2322 // Do we have cache?
2323 if (!isset($GLOBALS[__FUNCTION__])) {
2325 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2329 return $GLOBALS[__FUNCTION__];
2332 // "Getter" for total user points
2333 function getTotalPoints ($userid) {
2334 // Do we have cache?
2335 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2337 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points');
2341 return $GLOBALS[__FUNCTION__][$userid];
2344 // Wrapper to check if url_blacklist is enabled
2345 function isUrlBlacklistEnabled () {
2346 // Do we have cache?
2347 if (!isset($GLOBALS[__FUNCTION__])) {
2349 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2353 return $GLOBALS[__FUNCTION__];
2356 // Checks wether direct payment is allowed in configuration
2357 function isDirectPaymentEnabled () {
2358 // Do we have cache?
2359 if (!isset($GLOBALS[__FUNCTION__])) {
2361 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2365 return $GLOBALS[__FUNCTION__];
2368 // Wrapper to check if current task is for extension (not update)
2369 function isExtensionTask ($content) {
2370 // Do we have cache?
2371 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2373 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2377 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2380 // Wrapper to check if output mode is CSS
2381 function isCssOutputMode () {
2383 return (getScriptOutputMode() == 1);
2386 // Wrapper to check if output mode is HTML
2387 function isHtmlOutputMode () {
2389 return (getScriptOutputMode() == 0);
2392 // Wrapper to check if output mode is RAW
2393 function isRawOutputMode () {
2395 return (getScriptOutputMode() == -1);
2398 // Wrapper to generate a user email link
2399 function generateWrappedUserEmailLink ($email) {
2400 // Just call the inner function
2401 return generateEmailLink($email, 'user_data');
2404 // Wrapper to check if user points are locked
2405 function ifUserPointsLocked ($userid) {
2406 // Do we have cache?
2407 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2409 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2413 return $GLOBALS[__FUNCTION__][$userid];
2416 // Appends a line to an existing file or creates it instantly with given content.
2417 // This function does always add a new-line character to every line.
2418 function appendLineToFile ($file, $line) {
2419 $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2420 fwrite($fp, $line . "\n");
2424 // Wrapper for changeDataInFile() but with full path added
2425 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2427 $FQFN = getPath() . $FQFN;
2429 // Call inner function
2430 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);
2433 // Wrapper for changing entries in config-local.php
2434 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $DATA, $seek = 0) {
2435 // Call the inner function
2436 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $DATA, $seek);
2439 // Shortens ucfirst(strtolower()) calls
2440 function firstCharUpperCase ($str) {
2441 return ucfirst(strtolower($str));