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] = ((!empty($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 // Checks wether given user data is set to 'Y'
952 function isUserDataEnabled ($column) {
954 if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
956 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
960 return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
963 // Geter for whole user data array
964 function getUserDataArray () {
966 $userid = getCurrentUserId();
968 // Is the current userid valid?
969 if (!isValidUserId($userid)) {
970 // Should be always valid
971 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
974 // Get the whole array if found
975 if (isset($GLOBALS['user_data'][$userid])) {
976 // Found, so return it
977 return $GLOBALS['user_data'][$userid];
979 // Return empty array
984 // Checks if the user data is valid, this may indicate that the user has logged
985 // in, but you should use isMember() if you want to find that out.
986 function isUserDataValid () {
987 // User id should not be zero so abort here
988 if (!isCurrentUserIdSet()) return false;
991 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
993 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
997 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1000 // Setter for current userid
1001 function setCurrentUserId ($userid) {
1003 $GLOBALS['current_userid'] = bigintval($userid);
1005 // Unset it to re-determine the actual state
1006 unset($GLOBALS['is_userdata_valid'][$userid]);
1009 // Getter for current userid
1010 function getCurrentUserId () {
1011 // Userid must be set before it can be used
1012 if (!isCurrentUserIdSet()) {
1014 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
1017 // Return the userid
1018 return $GLOBALS['current_userid'];
1021 // Checks if current userid is set
1022 function isCurrentUserIdSet () {
1023 return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1026 // Checks wether we are debugging template cache
1027 function isDebuggingTemplateCache () {
1028 // Do we have cache?
1029 if (!isset($GLOBALS[__FUNCTION__])) {
1031 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1035 return $GLOBALS[__FUNCTION__];
1038 // Wrapper for fetchUserData() and getUserData() calls
1039 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1041 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1042 // Default is 'guest'
1043 $data = '{--USERNAME_GUEST--}';
1045 // Can we fetch the user data?
1046 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1047 // Now get the data back
1048 $data = getUserData($valueColumn);
1052 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1056 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1059 // Wrapper for strpos() to ease porting from deprecated ereg() function
1060 function isInString ($needle, $haystack) {
1061 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1062 return (strpos($haystack, $needle) !== false);
1065 // Wrapper for strpos() to ease porting from deprecated eregi() function
1066 // This function is case-insensitive
1067 function isInStringIgnoreCase ($needle, $haystack) {
1068 return (isInString(strtolower($needle), strtolower($haystack)));
1071 // Wrapper to check for if fatal errors where detected
1072 function ifFatalErrorsDetected () {
1073 // Just call the inner function
1074 return (getTotalFatalErrors() > 0);
1077 // Setter for HTTP status
1078 function setHttpStatus ($status) {
1079 $GLOBALS['http_status'] = (string) $status;
1082 // Getter for HTTP status
1083 function getHttpStatus () {
1084 // Is the status set?
1085 if (!isset($GLOBALS['http_status'])) {
1087 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1091 return $GLOBALS['http_status'];
1095 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1096 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1098 * ----------------------------------------------------------------------------
1099 * If you want to redirect, please use redirectToUrl(); instead
1100 * ----------------------------------------------------------------------------
1102 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1104 * @link http://support.microsoft.com/kb/q176113/
1105 * @author Andreas Gohr <andi@splitbrain.org>
1108 function sendRawRedirect ($url) {
1109 // Send helping header
1110 setHttpStatus('302 Found');
1112 // always close the session
1113 session_write_close();
1115 // Revert entity &
1116 $url = str_replace('&', '&', $url);
1118 // check if running on IIS < 6 with CGI-PHP
1119 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1120 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
1121 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1122 ($matches[1] < 6)) {
1123 // Send the IIS header
1124 sendHeader('Refresh: 0;url=' . $url);
1126 // Send generic header
1127 sendHeader('Location: ' . $url);
1134 // Determines the country of the given user id
1135 function determineCountry ($userid) {
1136 // Do we have cache?
1137 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1138 // Default is 'invalid'
1139 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1141 // Is extension country active?
1142 if (isExtensionActive('country')) {
1143 // Determine the right country code through the country id
1144 $id = getUserData('country_code');
1146 // Then handle it over
1147 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1149 // Get raw code from user data
1150 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1155 return $GLOBALS[__FUNCTION__][$userid];
1158 // "Getter" for total confirmed user accounts
1159 function getTotalConfirmedUser () {
1161 if (!isset($GLOBALS[__FUNCTION__])) {
1163 if (isExtensionActive('user')) {
1164 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1166 $GLOBALS[__FUNCTION__] = 0;
1170 // Return cached value
1171 return $GLOBALS[__FUNCTION__];
1174 // "Getter" for total unconfirmed user accounts
1175 function getTotalUnconfirmedUser () {
1177 if (!isset($GLOBALS[__FUNCTION__])) {
1179 if (isExtensionActive('user')) {
1180 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1182 $GLOBALS[__FUNCTION__] = 0;
1186 // Return cached value
1187 return $GLOBALS[__FUNCTION__];
1190 // "Getter" for total locked user accounts
1191 function getTotalLockedUser () {
1193 if (!isset($GLOBALS[__FUNCTION__])) {
1195 if (isExtensionActive('user')) {
1196 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1198 $GLOBALS[__FUNCTION__] = 0;
1202 // Return cached value
1203 return $GLOBALS[__FUNCTION__];
1206 // Is given userid valid?
1207 function isValidUserId ($userid) {
1208 // Do we have cache?
1209 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1211 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1215 return $GLOBALS[__FUNCTION__][$userid];
1219 function encodeEntities ($str) {
1221 $str = secureString($str, true, true);
1223 // Encode dollar sign as well
1224 $str = str_replace('$', '$', $str);
1230 // "Getter" for date from patch_ctime
1231 function getDateFromPatchTime () {
1233 if (!isset($GLOBALS[__FUNCTION__])) {
1235 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1239 return $GLOBALS[__FUNCTION__];
1242 // Getter for current year (default)
1243 function getYear ($timestamp = null) {
1245 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1247 if (is_null($timestamp)) {
1248 $timestamp = time();
1252 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1256 return $GLOBALS[__FUNCTION__][$timestamp];
1259 // Getter for current month (default)
1260 function getMonth ($timestamp = null) {
1262 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1263 // If null is set, use time()
1264 if (is_null($timestamp)) {
1265 // Use time() which is current timestamp
1266 $timestamp = time();
1270 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1274 return $GLOBALS[__FUNCTION__][$timestamp];
1277 // Getter for current hour (default)
1278 function getHour ($timestamp = null) {
1280 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1282 if (is_null($timestamp)) {
1283 $timestamp = time();
1287 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1291 return $GLOBALS[__FUNCTION__][$timestamp];
1294 // Getter for current day (default)
1295 function getDay ($timestamp = null) {
1297 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1299 if (is_null($timestamp)) {
1300 $timestamp = time();
1304 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1308 return $GLOBALS[__FUNCTION__][$timestamp];
1311 // Getter for current week (default)
1312 function getWeek ($timestamp = null) {
1314 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1316 if (is_null($timestamp)) $timestamp = time();
1319 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1323 return $GLOBALS[__FUNCTION__][$timestamp];
1326 // Getter for current short_hour (default)
1327 function getShortHour ($timestamp = null) {
1329 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1331 if (is_null($timestamp)) $timestamp = time();
1334 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1338 return $GLOBALS[__FUNCTION__][$timestamp];
1341 // Getter for current long_hour (default)
1342 function getLongHour ($timestamp = null) {
1344 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1346 if (is_null($timestamp)) $timestamp = time();
1349 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1353 return $GLOBALS[__FUNCTION__][$timestamp];
1356 // Getter for current second (default)
1357 function getSecond ($timestamp = null) {
1359 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1361 if (is_null($timestamp)) $timestamp = time();
1364 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1368 return $GLOBALS[__FUNCTION__][$timestamp];
1371 // Getter for current minute (default)
1372 function getMinute ($timestamp = null) {
1374 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1376 if (is_null($timestamp)) $timestamp = time();
1379 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1383 return $GLOBALS[__FUNCTION__][$timestamp];
1386 // Checks wether the title decoration is enabled
1387 function isTitleDecorationEnabled () {
1388 // Do we have cache?
1389 if (!isset($GLOBALS[__FUNCTION__])) {
1391 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1395 return $GLOBALS[__FUNCTION__];
1398 // Checks wether filter usage updates are enabled (expensive queries!)
1399 function isFilterUsageUpdateEnabled () {
1400 // Do we have cache?
1401 if (!isset($GLOBALS[__FUNCTION__])) {
1403 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1407 return $GLOBALS[__FUNCTION__];
1410 // Checks wether debugging of weekly resets is enabled
1411 function isWeeklyResetDebugEnabled () {
1412 // Do we have cache?
1413 if (!isset($GLOBALS[__FUNCTION__])) {
1415 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1419 return $GLOBALS[__FUNCTION__];
1422 // Checks wether debugging of monthly resets is enabled
1423 function isMonthlyResetDebugEnabled () {
1424 // Do we have cache?
1425 if (!isset($GLOBALS[__FUNCTION__])) {
1427 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1431 return $GLOBALS[__FUNCTION__];
1434 // Checks wether displaying of debug SQLs are enabled
1435 function isDisplayDebugSqlEnabled () {
1436 // Do we have cache?
1437 if (!isset($GLOBALS[__FUNCTION__])) {
1439 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1443 return $GLOBALS[__FUNCTION__];
1446 // Checks wether module title is enabled
1447 function isModuleTitleEnabled () {
1448 // Do we have cache?
1449 if (!isset($GLOBALS[__FUNCTION__])) {
1451 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1455 return $GLOBALS[__FUNCTION__];
1458 // Checks wether what title is enabled
1459 function isWhatTitleEnabled () {
1460 // Do we have cache?
1461 if (!isset($GLOBALS[__FUNCTION__])) {
1463 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1467 return $GLOBALS[__FUNCTION__];
1470 // Checks wether stats are enabled
1471 function ifStatsAreEnabled () {
1472 // Do we have cache?
1473 if (!isset($GLOBALS[__FUNCTION__])) {
1474 // Then determine it
1475 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1478 // Return cached value
1479 return $GLOBALS[__FUNCTION__];
1482 // Checks wether admin-notification of certain user actions is enabled
1483 function isAdminNotificationEnabled () {
1484 // Do we have cache?
1485 if (!isset($GLOBALS[__FUNCTION__])) {
1487 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1491 return $GLOBALS[__FUNCTION__];
1494 // Checks wether random referal id selection is enabled
1495 function isRandomReferalIdEnabled () {
1496 // Do we have cache?
1497 if (!isset($GLOBALS[__FUNCTION__])) {
1499 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1503 return $GLOBALS[__FUNCTION__];
1506 // "Getter" for default language
1507 function getDefaultLanguage () {
1508 // Do we have cache?
1509 if (!isset($GLOBALS[__FUNCTION__])) {
1511 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1515 return $GLOBALS[__FUNCTION__];
1518 // "Getter" for default referal id
1519 function getDefRefid () {
1520 // Do we have cache?
1521 if (!isset($GLOBALS[__FUNCTION__])) {
1523 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1527 return $GLOBALS[__FUNCTION__];
1530 // "Getter" for path
1531 function getPath () {
1532 // Do we have cache?
1533 if (!isset($GLOBALS[__FUNCTION__])) {
1535 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1539 return $GLOBALS[__FUNCTION__];
1543 function getUrl () {
1544 // Do we have cache?
1545 if (!isset($GLOBALS[__FUNCTION__])) {
1547 $GLOBALS[__FUNCTION__] = getConfig('URL');
1551 return $GLOBALS[__FUNCTION__];
1554 // "Getter" for cache_path
1555 function getCachePath () {
1556 // Do we have cache?
1557 if (!isset($GLOBALS[__FUNCTION__])) {
1559 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1563 return $GLOBALS[__FUNCTION__];
1566 // "Getter" for secret_key
1567 function getSecretKey () {
1568 // Do we have cache?
1569 if (!isset($GLOBALS[__FUNCTION__])) {
1571 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1575 return $GLOBALS[__FUNCTION__];
1578 // "Getter" for SITE_KEY
1579 function getSiteKey () {
1580 // Do we have cache?
1581 if (!isset($GLOBALS[__FUNCTION__])) {
1583 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1587 return $GLOBALS[__FUNCTION__];
1590 // "Getter" for DATE_KEY
1591 function getDateKey () {
1592 // Do we have cache?
1593 if (!isset($GLOBALS[__FUNCTION__])) {
1595 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1599 return $GLOBALS[__FUNCTION__];
1602 // "Getter" for master_salt
1603 function getMasterSalt () {
1604 // Do we have cache?
1605 if (!isset($GLOBALS[__FUNCTION__])) {
1607 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1611 return $GLOBALS[__FUNCTION__];
1614 // "Getter" for prime
1615 function getPrime () {
1616 // Do we have cache?
1617 if (!isset($GLOBALS[__FUNCTION__])) {
1619 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1623 return $GLOBALS[__FUNCTION__];
1626 // "Getter" for encrypt_seperator
1627 function getEncryptSeperator () {
1628 // Do we have cache?
1629 if (!isset($GLOBALS[__FUNCTION__])) {
1631 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1635 return $GLOBALS[__FUNCTION__];
1638 // "Getter" for mysql_prefix
1639 function getMysqlPrefix () {
1640 // Do we have cache?
1641 if (!isset($GLOBALS[__FUNCTION__])) {
1643 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1647 return $GLOBALS[__FUNCTION__];
1650 // "Getter" for table_type
1651 function getTableType () {
1652 // Do we have cache?
1653 if (!isset($GLOBALS[__FUNCTION__])) {
1655 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1659 return $GLOBALS[__FUNCTION__];
1662 // "Getter" for salt_length
1663 function getSaltLength () {
1664 // Do we have cache?
1665 if (!isset($GLOBALS[__FUNCTION__])) {
1667 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1671 return $GLOBALS[__FUNCTION__];
1674 // "Getter" for output_mode
1675 function getOutputMode () {
1676 // Do we have cache?
1677 if (!isset($GLOBALS[__FUNCTION__])) {
1679 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1683 return $GLOBALS[__FUNCTION__];
1686 // "Getter" for full_version
1687 function getFullVersion () {
1688 // Do we have cache?
1689 if (!isset($GLOBALS[__FUNCTION__])) {
1691 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1695 return $GLOBALS[__FUNCTION__];
1698 // "Getter" for title
1699 function getTitle () {
1700 // Do we have cache?
1701 if (!isset($GLOBALS[__FUNCTION__])) {
1703 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1707 return $GLOBALS[__FUNCTION__];
1710 // "Getter" for curr_svn_revision
1711 function getCurrentRepositoryRevision () {
1712 // Do we have cache?
1713 if (!isset($GLOBALS[__FUNCTION__])) {
1715 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1719 return $GLOBALS[__FUNCTION__];
1722 // "Getter" for server_url
1723 function getServerUrl () {
1724 // Do we have cache?
1725 if (!isset($GLOBALS[__FUNCTION__])) {
1727 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1731 return $GLOBALS[__FUNCTION__];
1734 // "Getter" for mt_word
1735 function getMtWord () {
1736 // Do we have cache?
1737 if (!isset($GLOBALS[__FUNCTION__])) {
1739 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1743 return $GLOBALS[__FUNCTION__];
1746 // "Getter" for mt_word2
1747 function getMtWord2 () {
1748 // Do we have cache?
1749 if (!isset($GLOBALS[__FUNCTION__])) {
1751 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1755 return $GLOBALS[__FUNCTION__];
1758 // "Getter" for main_title
1759 function getMainTitle () {
1760 // Do we have cache?
1761 if (!isset($GLOBALS[__FUNCTION__])) {
1763 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1767 return $GLOBALS[__FUNCTION__];
1770 // "Getter" for file_hash
1771 function getFileHash () {
1772 // Do we have cache?
1773 if (!isset($GLOBALS[__FUNCTION__])) {
1775 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1779 return $GLOBALS[__FUNCTION__];
1782 // "Getter" for pass_scramble
1783 function getPassScramble () {
1784 // Do we have cache?
1785 if (!isset($GLOBALS[__FUNCTION__])) {
1787 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1791 return $GLOBALS[__FUNCTION__];
1794 // "Getter" for ap_inactive_since
1795 function getApInactiveSince () {
1796 // Do we have cache?
1797 if (!isset($GLOBALS[__FUNCTION__])) {
1799 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1803 return $GLOBALS[__FUNCTION__];
1806 // "Getter" for user_min_confirmed
1807 function getUserMinConfirmed () {
1808 // Do we have cache?
1809 if (!isset($GLOBALS[__FUNCTION__])) {
1811 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1815 return $GLOBALS[__FUNCTION__];
1818 // "Getter" for auto_purge
1819 function getAutoPurge () {
1820 // Do we have cache?
1821 if (!isset($GLOBALS[__FUNCTION__])) {
1823 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1827 return $GLOBALS[__FUNCTION__];
1830 // "Getter" for bonus_userid
1831 function getBonusUserid () {
1832 // Do we have cache?
1833 if (!isset($GLOBALS[__FUNCTION__])) {
1835 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1839 return $GLOBALS[__FUNCTION__];
1842 // "Getter" for ap_inactive_time
1843 function getApInactiveTime () {
1844 // Do we have cache?
1845 if (!isset($GLOBALS[__FUNCTION__])) {
1847 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1851 return $GLOBALS[__FUNCTION__];
1854 // "Getter" for ap_dm_timeout
1855 function getApDmTimeout () {
1856 // Do we have cache?
1857 if (!isset($GLOBALS[__FUNCTION__])) {
1859 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1863 return $GLOBALS[__FUNCTION__];
1866 // "Getter" for ap_tasks_time
1867 function getApTasksTime () {
1868 // Do we have cache?
1869 if (!isset($GLOBALS[__FUNCTION__])) {
1871 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1875 return $GLOBALS[__FUNCTION__];
1878 // "Getter" for ap_unconfirmed_time
1879 function getApUnconfirmedTime () {
1880 // Do we have cache?
1881 if (!isset($GLOBALS[__FUNCTION__])) {
1883 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1887 return $GLOBALS[__FUNCTION__];
1890 // "Getter" for points
1891 function getPoints () {
1892 // Do we have cache?
1893 if (!isset($GLOBALS[__FUNCTION__])) {
1895 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1899 return $GLOBALS[__FUNCTION__];
1902 // "Getter" for slogan
1903 function getSlogan () {
1904 // Do we have cache?
1905 if (!isset($GLOBALS[__FUNCTION__])) {
1907 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1911 return $GLOBALS[__FUNCTION__];
1914 // "Getter" for copy
1915 function getCopy () {
1916 // Do we have cache?
1917 if (!isset($GLOBALS[__FUNCTION__])) {
1919 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1923 return $GLOBALS[__FUNCTION__];
1926 // "Getter" for webmaster
1927 function getWebmaster () {
1928 // Do we have cache?
1929 if (!isset($GLOBALS[__FUNCTION__])) {
1931 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1935 return $GLOBALS[__FUNCTION__];
1938 // "Getter" for sql_count
1939 function getSqlCount () {
1940 // Do we have cache?
1941 if (!isset($GLOBALS[__FUNCTION__])) {
1943 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1947 return $GLOBALS[__FUNCTION__];
1950 // "Getter" for num_templates
1951 function getNumTemplates () {
1952 // Do we have cache?
1953 if (!isset($GLOBALS[__FUNCTION__])) {
1955 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1959 return $GLOBALS[__FUNCTION__];
1962 // "Getter" for dns_cache_timeout
1963 function getDnsCacheTimeout () {
1964 // Do we have cache?
1965 if (!isset($GLOBALS[__FUNCTION__])) {
1967 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1971 return $GLOBALS[__FUNCTION__];
1974 // "Getter" for menu_blur_spacer
1975 function getMenuBlurSpacer () {
1976 // Do we have cache?
1977 if (!isset($GLOBALS[__FUNCTION__])) {
1979 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
1983 return $GLOBALS[__FUNCTION__];
1986 // "Getter" for points_register
1987 function getPointsRegister () {
1988 // Do we have cache?
1989 if (!isset($GLOBALS[__FUNCTION__])) {
1991 $GLOBALS[__FUNCTION__] = getConfig('points_register');
1995 return $GLOBALS[__FUNCTION__];
1998 // "Getter" for points_ref
1999 function getPointsRef () {
2000 // Do we have cache?
2001 if (!isset($GLOBALS[__FUNCTION__])) {
2003 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2007 return $GLOBALS[__FUNCTION__];
2010 // "Getter" for ref_payout
2011 function getRefPayout () {
2012 // Do we have cache?
2013 if (!isset($GLOBALS[__FUNCTION__])) {
2015 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2019 return $GLOBALS[__FUNCTION__];
2022 // "Getter" for online_timeout
2023 function getOnlineTimeout () {
2024 // Do we have cache?
2025 if (!isset($GLOBALS[__FUNCTION__])) {
2027 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2031 return $GLOBALS[__FUNCTION__];
2034 // "Getter" for index_home
2035 function getIndexHome () {
2036 // Do we have cache?
2037 if (!isset($GLOBALS[__FUNCTION__])) {
2039 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2043 return $GLOBALS[__FUNCTION__];
2046 // "Getter" for one_day
2047 function getOneDay () {
2048 // Do we have cache?
2049 if (!isset($GLOBALS[__FUNCTION__])) {
2051 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2055 return $GLOBALS[__FUNCTION__];
2058 // "Getter" for activate_xchange
2059 function getActivateXchange () {
2060 // Do we have cache?
2061 if (!isset($GLOBALS[__FUNCTION__])) {
2063 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2067 return $GLOBALS[__FUNCTION__];
2070 // "Getter" for img_type
2071 function getImgType () {
2072 // Do we have cache?
2073 if (!isset($GLOBALS[__FUNCTION__])) {
2075 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2079 return $GLOBALS[__FUNCTION__];
2082 // "Getter" for code_length
2083 function getCodeLength () {
2084 // Do we have cache?
2085 if (!isset($GLOBALS[__FUNCTION__])) {
2087 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2091 return $GLOBALS[__FUNCTION__];
2094 // "Getter" for least_cats
2095 function getLeastCats () {
2096 // Do we have cache?
2097 if (!isset($GLOBALS[__FUNCTION__])) {
2099 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2103 return $GLOBALS[__FUNCTION__];
2106 // "Getter" for pass_len
2107 function getPassLen () {
2108 // Do we have cache?
2109 if (!isset($GLOBALS[__FUNCTION__])) {
2111 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2115 return $GLOBALS[__FUNCTION__];
2118 // "Getter" for admin_menu
2119 function getAdminMenu () {
2120 // Do we have cache?
2121 if (!isset($GLOBALS[__FUNCTION__])) {
2123 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2127 return $GLOBALS[__FUNCTION__];
2130 // "Getter" for last_month
2131 function getLastMonth () {
2132 // Do we have cache?
2133 if (!isset($GLOBALS[__FUNCTION__])) {
2135 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2139 return $GLOBALS[__FUNCTION__];
2142 // "Getter" for max_send
2143 function getMaxSend () {
2144 // Do we have cache?
2145 if (!isset($GLOBALS[__FUNCTION__])) {
2147 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2151 return $GLOBALS[__FUNCTION__];
2154 // "Getter" for mails_page
2155 function getMailsPage () {
2156 // Do we have cache?
2157 if (!isset($GLOBALS[__FUNCTION__])) {
2159 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2163 return $GLOBALS[__FUNCTION__];
2166 // "Getter" for rand_no
2167 function getRandNo () {
2168 // Do we have cache?
2169 if (!isset($GLOBALS[__FUNCTION__])) {
2171 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2175 return $GLOBALS[__FUNCTION__];
2178 // "Getter" for __DB_NAME
2179 function getDbName () {
2180 // Do we have cache?
2181 if (!isset($GLOBALS[__FUNCTION__])) {
2183 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2187 return $GLOBALS[__FUNCTION__];
2190 // "Getter" for DOMAIN
2191 function getDomain () {
2192 // Do we have cache?
2193 if (!isset($GLOBALS[__FUNCTION__])) {
2195 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2199 return $GLOBALS[__FUNCTION__];
2202 // "Getter" for proxy_username
2203 function getProxyUsername () {
2204 // Do we have cache?
2205 if (!isset($GLOBALS[__FUNCTION__])) {
2207 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2211 return $GLOBALS[__FUNCTION__];
2214 // "Getter" for proxy_password
2215 function getProxyPassword () {
2216 // Do we have cache?
2217 if (!isset($GLOBALS[__FUNCTION__])) {
2219 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2223 return $GLOBALS[__FUNCTION__];
2226 // "Getter" for proxy_host
2227 function getProxyHost () {
2228 // Do we have cache?
2229 if (!isset($GLOBALS[__FUNCTION__])) {
2231 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2235 return $GLOBALS[__FUNCTION__];
2238 // "Getter" for proxy_port
2239 function getProxyPort () {
2240 // Do we have cache?
2241 if (!isset($GLOBALS[__FUNCTION__])) {
2243 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2247 return $GLOBALS[__FUNCTION__];
2250 // "Getter" for SMTP_HOSTNAME
2251 function getSmtpHostname () {
2252 // Do we have cache?
2253 if (!isset($GLOBALS[__FUNCTION__])) {
2255 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2259 return $GLOBALS[__FUNCTION__];
2262 // "Getter" for SMTP_USER
2263 function getSmtpUser () {
2264 // Do we have cache?
2265 if (!isset($GLOBALS[__FUNCTION__])) {
2267 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2271 return $GLOBALS[__FUNCTION__];
2274 // "Getter" for SMTP_PASSWORD
2275 function getSmtpPassword () {
2276 // Do we have cache?
2277 if (!isset($GLOBALS[__FUNCTION__])) {
2279 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2283 return $GLOBALS[__FUNCTION__];
2286 // "Getter" for points_word
2287 function getPointsWord () {
2288 // Do we have cache?
2289 if (!isset($GLOBALS[__FUNCTION__])) {
2291 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2295 return $GLOBALS[__FUNCTION__];
2298 // "Getter" for profile_lock
2299 function getProfileLock () {
2300 // Do we have cache?
2301 if (!isset($GLOBALS[__FUNCTION__])) {
2303 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2307 return $GLOBALS[__FUNCTION__];
2310 // "Getter" for url_tlock
2311 function getUrlTlock () {
2312 // Do we have cache?
2313 if (!isset($GLOBALS[__FUNCTION__])) {
2315 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2319 return $GLOBALS[__FUNCTION__];
2322 // Checks wether proxy configuration is used
2323 function isProxyUsed () {
2324 // Do we have cache?
2325 if (!isset($GLOBALS[__FUNCTION__])) {
2327 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2331 return $GLOBALS[__FUNCTION__];
2334 // Checks wether POST data contains selections
2335 function ifPostContainsSelections ($element = 'sel') {
2336 // Do we have cache?
2337 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2339 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
2343 return $GLOBALS[__FUNCTION__][$element];
2346 // Checks wether verbose_sql is Y and returns true/false if so
2347 function isVerboseSqlEnabled () {
2348 // Do we have cache?
2349 if (!isset($GLOBALS[__FUNCTION__])) {
2351 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2355 return $GLOBALS[__FUNCTION__];
2358 // "Getter" for total user points
2359 function getTotalPoints ($userid) {
2360 // Do we have cache?
2361 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2362 // Init array for filter chain
2364 'userid' => $userid,
2368 // Run filter chain for getting more point values
2369 $data = runFilterChain('get_total_points', $data);
2372 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - countSumTotalData($userid, 'user_data', 'used_points');
2376 return $GLOBALS[__FUNCTION__][$userid];
2379 // Wrapper to check if url_blacklist is enabled
2380 function isUrlBlacklistEnabled () {
2381 // Do we have cache?
2382 if (!isset($GLOBALS[__FUNCTION__])) {
2384 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2388 return $GLOBALS[__FUNCTION__];
2391 // Checks wether direct payment is allowed in configuration
2392 function isDirectPaymentEnabled () {
2393 // Do we have cache?
2394 if (!isset($GLOBALS[__FUNCTION__])) {
2396 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2400 return $GLOBALS[__FUNCTION__];
2403 // Wrapper to check if current task is for extension (not update)
2404 function isExtensionTask ($content) {
2405 // Do we have cache?
2406 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2408 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2412 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2415 // Wrapper to check if output mode is CSS
2416 function isCssOutputMode () {
2418 return (getScriptOutputMode() == 1);
2421 // Wrapper to check if output mode is HTML
2422 function isHtmlOutputMode () {
2424 return (getScriptOutputMode() == 0);
2427 // Wrapper to check if output mode is RAW
2428 function isRawOutputMode () {
2430 return (getScriptOutputMode() == -1);
2433 // Wrapper to generate a user email link
2434 function generateWrappedUserEmailLink ($email) {
2435 // Just call the inner function
2436 return generateEmailLink($email, 'user_data');
2439 // Wrapper to check if user points are locked
2440 function ifUserPointsLocked ($userid) {
2441 // Do we have cache?
2442 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2444 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2448 return $GLOBALS[__FUNCTION__][$userid];
2451 // Appends a line to an existing file or creates it instantly with given content.
2452 // This function does always add a new-line character to every line.
2453 function appendLineToFile ($file, $line) {
2454 $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2455 fwrite($fp, $line . "\n");
2459 // Wrapper for changeDataInFile() but with full path added
2460 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2462 $FQFN = getPath() . $FQFN;
2464 // Call inner function
2465 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);
2468 // Wrapper for changing entries in config-local.php
2469 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $DATA, $seek = 0) {
2470 // Call the inner function
2471 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $DATA, $seek);
2474 // Shortens ucfirst(strtolower()) calls
2475 function firstCharUpperCase ($str) {
2476 return ucfirst(strtolower($str));
2479 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2480 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2481 // Get the configuration entry
2482 $configValue = getConfig($configEntry);
2484 // Call inner method
2485 return createTimeSelections($configValue, $configEntry, $stamps, $align);
2488 // Shortens converting of German comma to Computer's version in POST data
2489 function convertCommaToDotInPostData ($postEntry) {
2490 // Read and convert given entry
2491 $postValue = convertCommaToDot(postRequestParameter($postEntry));
2493 // ... and set it again
2494 setPostRequestParameter($postEntry, $postValue);
2497 // Converts German commas to Computer's version in all entries
2498 function convertCommaToDotInPostDataArray (array $postEntries) {
2499 // Replace german decimal comma with computer decimal dot
2500 foreach ($postEntries as $entry) {
2501 // Is the entry there?
2502 if (isPostRequestParameterSet($entry)) {
2504 convertCommaToDotInPostData($entry);
2509 // Getter for 'check_double_email'
2510 function getCheckDoubleEmail () {
2511 // Is the cache entry set?
2512 if (!isset($GLOBALS[__FUNCTION__])) {
2513 // No, so determine it
2514 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2517 // Return cached entry
2518 return $GLOBALS[__FUNCTION__];
2521 // Checks wether 'check_double_email' is "YES"
2522 function isCheckDoubleEmailEnabled () {
2523 // Is the cache entry set?
2524 if (!isset($GLOBALS[__FUNCTION__])) {
2525 // No, so determine it
2526 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2529 // Return cached entry
2530 return $GLOBALS[__FUNCTION__];