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 reset mode is active
374 function isResetModeEnabled () {
375 // Now simply check it
376 return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
379 // Checks wether the debug mode is enabled
380 function isDebugModeEnabled () {
382 if (!isset($GLOBALS[__FUNCTION__])) {
384 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
388 return $GLOBALS[__FUNCTION__];
391 // Checks wether SQL debugging is enabled
392 function isSqlDebuggingEnabled () {
394 if (!isset($GLOBALS[__FUNCTION__])) {
395 // Determine if SQL debugging is enabled
396 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
400 return $GLOBALS[__FUNCTION__];
403 // Checks wether we shall debug regular expressions
404 function isDebugRegularExpressionEnabled () {
406 if (!isset($GLOBALS[__FUNCTION__])) {
408 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
412 return $GLOBALS[__FUNCTION__];
415 // Checks wether the cache instance is valid
416 function isCacheInstanceValid () {
417 return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
420 // Copies a file from source to destination and verifies if that goes fine.
421 // This function should wrap the copy() command and make a nicer debug backtrace
422 // even if there is no xdebug extension installed.
423 function copyFileVerified ($source, $dest, $chmod = '') {
424 // Failed is the default
427 // Is the source file there?
428 if (!isFileReadable($source)) {
430 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
433 // Is the target directory there?
434 if (!isDirectory(dirname($dest))) {
436 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
439 // Now try to copy it
440 if (!copy($source, $dest)) {
441 // Something went wrong
442 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
445 $GLOBALS['file_readable'][$dest] = true;
448 // If there are chmod rights set, apply them
449 if (!empty($chmod)) {
451 $status = changeMode($dest, $chmod);
461 // Wrapper function for header()
462 // Send a header but checks before if we can do so
463 function sendHeader ($header) {
465 //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header);
466 $GLOBALS['header'][] = trim($header);
469 // Flushes all headers
470 function flushHeaders () {
471 // Is the header already sent?
472 if (headers_sent()) {
474 debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!');
477 // Flush all headers if found
478 if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) {
479 foreach ($GLOBALS['header'] as $header) {
484 // Mark them as flushed
485 $GLOBALS['header'] = array();
488 // Wrapper function for chmod()
489 // @TODO Do some more sanity check here
490 function changeMode ($FQFN, $mode) {
491 // Is the file/directory there?
492 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
493 // Neither, so abort here
494 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
498 return chmod($FQFN, $mode);
501 // Wrapper for unlink()
502 function removeFile ($FQFN) {
503 // Is the file there?
504 if (isFileReadable($FQFN)) {
506 $GLOBALS['file_readable'][$FQFN] = false;
509 return unlink($FQFN);
512 // All fine if no file was removed. If we change this to 'false' or rewrite
513 // above if() block it would be to restrictive.
517 // Wrapper for $_POST['sel']
518 function countPostSelection ($element = 'sel') {
520 if (isPostRequestParameterSet($element)) {
521 // Return counted elements
522 return countSelection(postRequestParameter($element));
524 // Return zero if not found
529 // Checks wether the config-local.php is loaded
530 function isConfigLocalLoaded () {
531 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
534 // Checks wether a nickname or userid was entered and caches the result
535 function isNicknameUsed ($userid) {
536 // Is the cache there
537 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
539 $GLOBALS[__FUNCTION__][$userid] = (('' . round($userid) . '') != $userid);
543 return $GLOBALS[__FUNCTION__][$userid];
546 // Getter for 'what' value
547 function getWhat () {
552 if (isWhatSet(true)) {
554 $what = $GLOBALS['what'];
561 // Setter for 'what' value
562 function setWhat ($newWhat) {
563 $GLOBALS['what'] = SQL_ESCAPE($newWhat);
566 // Setter for 'what' from configuration
567 function setWhatFromConfig ($configEntry) {
568 // Get 'what' from config
569 $what = getConfig($configEntry);
575 // Checks wether what is set and optionally aborts on miss
576 function isWhatSet ($strict = false) {
578 $isset = isset($GLOBALS['what']);
580 // Should we abort here?
581 if (($strict === true) && ($isset === false)) {
583 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
590 // Getter for 'action' value
591 function getAction ($strict = true) {
596 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
598 $action = $GLOBALS['action'];
605 // Setter for 'action' value
606 function setAction ($newAction) {
607 $GLOBALS['action'] = SQL_ESCAPE($newAction);
610 // Checks wether action is set and optionally aborts on miss
611 function isActionSet ($strict = false) {
613 $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action'])));
615 // Should we abort here?
616 if (($strict === true) && ($isset === false)) {
618 debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.');
625 // Getter for 'module' value
626 function getModule ($strict = true) {
631 if (isModuleSet($strict)) {
633 $module = $GLOBALS['module'];
640 // Setter for 'module' value
641 function setModule ($newModule) {
642 // Secure it and make all modules lower-case
643 $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
646 // Checks wether module is set and optionally aborts on miss
647 function isModuleSet ($strict = false) {
649 $isset = (!empty($GLOBALS['module']));
651 // Should we abort here?
652 if (($strict === true) && ($isset === false)) {
654 debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.');
658 return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
661 // Getter for 'output_mode' value
662 function getScriptOutputMode () {
664 if (!isset($GLOBALS[__FUNCTION__])) {
669 if (isOutputModeSet(true)) {
671 $output_mode = $GLOBALS['output_mode'];
675 $GLOBALS[__FUNCTION__] = $output_mode;
679 return $GLOBALS[__FUNCTION__];
682 // Setter for 'output_mode' value
683 function setOutputMode ($newOutputMode) {
684 $GLOBALS['output_mode'] = (int) $newOutputMode;
687 // Checks wether output_mode is set and optionally aborts on miss
688 function isOutputModeSet ($strict = false) {
690 $isset = (isset($GLOBALS['output_mode']));
692 // Should we abort here?
693 if (($strict === true) && ($isset === false)) {
695 debug_report_bug(__FUNCTION__, __LINE__, 'Output mode is not set.');
702 // Enables block-mode
703 function enableBlockMode ($enabled = true) {
704 $GLOBALS['block_mode'] = $enabled;
707 // Checks wether block-mode is enabled
708 function isBlockModeEnabled () {
710 if (!isset($GLOBALS['block_mode'])) {
712 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
716 return $GLOBALS['block_mode'];
719 // Wrapper function for addPointsThroughReferalSystem()
720 function addPointsDirectly ($subject, $userid, $points) {
722 unset($GLOBALS['ref_level']);
724 // Call more complicated method (due to more parameters)
725 return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'direct');
728 // Wrapper for redirectToUrl but URL comes from a configuration entry
729 function redirectToConfiguredUrl ($configEntry) {
731 redirectToUrl(getConfig($configEntry));
734 // Wrapper function to redirect from member-only modules to index
735 function redirectToIndexMemberOnlyModule () {
736 // Do the redirect here
737 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
740 // Wrapper function to redirect to current URL
741 function redirectToRequestUri () {
742 redirectToUrl(basename(detectRequestUri()));
745 // Wrapper function to redirect to de-refered URL
746 function redirectToDereferedUrl ($URL) {
748 redirectToUrl(generateDerefererUrl($URL));
751 // Wrapper function for checking if extension is installed and newer or same version
752 function isExtensionInstalledAndNewer ($ext_name, $version) {
753 // Is an cache entry found?
754 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
756 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
758 // Cache hits should be incremented twice
759 incrementStatsEntry('cache_hits', 2);
763 //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'=>'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
764 return $GLOBALS[__FUNCTION__][$ext_name][$version];
767 // Wrapper function for checking if extension is installed and older than given version
768 function isExtensionInstalledAndOlder ($ext_name, $version) {
769 // Is an cache entry found?
770 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
772 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
774 // Cache hits should be incremented twice
775 incrementStatsEntry('cache_hits', 2);
779 //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'<'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
780 return $GLOBALS[__FUNCTION__][$ext_name][$version];
784 function setUsername ($userName) {
785 $GLOBALS['username'] = (string) $userName;
789 function getUsername () {
791 if (!isset($GLOBALS['username'])) {
792 // No, so it has to be a guest
793 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
797 return $GLOBALS['username'];
800 // Wrapper function for installation phase
801 function isInstallationPhase () {
803 if (!isset($GLOBALS[__FUNCTION__])) {
805 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
809 return $GLOBALS[__FUNCTION__];
812 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
813 function isDemoModeActive () {
815 if (!isset($GLOBALS[__FUNCTION__])) {
817 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
821 return $GLOBALS[__FUNCTION__];
824 // Getter for PHP caching value
825 function getPhpCaching () {
826 return $GLOBALS['php_caching'];
829 // Checks wether the admin hash is set
830 function isAdminHashSet ($adminId) {
831 // Is the array there?
832 if (!isset($GLOBALS['cache_array']['admin'])) {
833 // Missing array should be reported
834 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
837 // Check for admin hash
838 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
841 // Setter for admin hash
842 function setAdminHash ($adminId, $hash) {
843 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
846 // Getter for current admin login
847 function getCurrentAdminLogin () {
849 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
852 if (!isset($GLOBALS[__FUNCTION__])) {
854 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
858 return $GLOBALS[__FUNCTION__];
861 // Setter for admin id (and current)
862 function setAdminId ($adminId) {
864 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
867 $status = setSession('admin_id', bigintval($adminId));
870 setCurrentAdminId($adminId);
876 // Setter for admin_last
877 function setAdminLast ($adminLast) {
879 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
882 $status = setSession('admin_last', $adminLast);
888 // Setter for admin_md5
889 function setAdminMd5 ($adminMd5) {
891 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
894 $status = setSession('admin_md5', $adminMd5);
900 // Getter for admin_md5
901 function getAdminMd5 () {
903 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
906 return getSession('admin_md5');
909 // Init user data array
910 function initUserData () {
911 // User id should not be zero
912 if (!isValidUserId(getCurrentUserId())) {
913 // Should be always valid
914 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
918 $GLOBALS['user_data'][getCurrentUserId()] = array();
921 // Getter for user data
922 function getUserData ($column) {
923 // User id should not be zero
924 if (!isValidUserId(getCurrentUserId())) {
925 // Should be always valid
926 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
930 return $GLOBALS['user_data'][getCurrentUserId()][$column];
933 // Geter for whole user data array
934 function getUserDataArray () {
936 $userid = getCurrentUserId();
938 // Is the current userid valid?
939 if (!isValidUserId($userid)) {
940 // Should be always valid
941 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
944 // Get the whole array if found
945 if (isset($GLOBALS['user_data'][$userid])) {
946 // Found, so return it
947 return $GLOBALS['user_data'][$userid];
949 // Return empty array
954 // Checks if the user data is valid, this may indicate that the user has logged
955 // in, but you should use isMember() if you want to find that out.
956 function isUserDataValid () {
957 // User id should not be zero so abort here
958 if (!isCurrentUserIdSet()) return false;
961 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
963 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
967 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
970 // Setter for current userid
971 function setCurrentUserId ($userid) {
973 $GLOBALS['current_userid'] = bigintval($userid);
975 // Unset it to re-determine the actual state
976 unset($GLOBALS['is_userdata_valid'][$userid]);
979 // Getter for current userid
980 function getCurrentUserId () {
981 // Userid must be set before it can be used
982 if (!isCurrentUserIdSet()) {
984 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
988 return $GLOBALS['current_userid'];
991 // Checks if current userid is set
992 function isCurrentUserIdSet () {
993 return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
996 // Checks wether we are debugging template cache
997 function isDebuggingTemplateCache () {
999 if (!isset($GLOBALS[__FUNCTION__])) {
1001 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1005 return $GLOBALS[__FUNCTION__];
1008 // Wrapper for fetchUserData() and getUserData() calls
1009 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1011 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1012 // Default is 'guest'
1013 $data = '{--USERNAME_GUEST--}';
1015 // Can we fetch the user data?
1016 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1017 // Now get the data back
1018 $data = getUserData($valueColumn);
1022 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1026 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1029 // Wrapper for strpos() to ease porting from deprecated ereg() function
1030 function isInString ($needle, $haystack) {
1031 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1032 return (strpos($haystack, $needle) !== false);
1035 // Wrapper for strpos() to ease porting from deprecated eregi() function
1036 // This function is case-insensitive
1037 function isInStringIgnoreCase ($needle, $haystack) {
1038 return (isInString(strtolower($needle), strtolower($haystack)));
1041 // Wrapper to check for if fatal errors where detected
1042 function ifFatalErrorsDetected () {
1043 // Just call the inner function
1044 return (getTotalFatalErrors() > 0);
1047 // Setter for HTTP status
1048 function setHttpStatus ($status) {
1049 $GLOBALS['http_status'] = (string) $status;
1052 // Getter for HTTP status
1053 function getHttpStatus () {
1054 // Is the status set?
1055 if (!isset($GLOBALS['http_status'])) {
1057 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1061 return $GLOBALS['http_status'];
1065 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1066 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1068 * ----------------------------------------------------------------------------
1069 * If you want to redirect, please use redirectToUrl(); instead
1070 * ----------------------------------------------------------------------------
1072 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1074 * @link http://support.microsoft.com/kb/q176113/
1075 * @author Andreas Gohr <andi@splitbrain.org>
1078 function sendRawRedirect ($url) {
1079 // Send helping header
1080 setHttpStatus('302 Found');
1082 // always close the session
1083 session_write_close();
1085 // Revert entity &
1086 $url = str_replace('&', '&', $url);
1088 // check if running on IIS < 6 with CGI-PHP
1089 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1090 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
1091 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1092 ($matches[1] < 6)) {
1093 // Send the IIS header
1094 sendHeader('Refresh: 0;url=' . $url);
1096 // Send generic header
1097 sendHeader('Location: ' . $url);
1104 // Determines the country of the given user id
1105 function determineCountry ($userid) {
1106 // Do we have cache?
1107 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1108 // Default is 'invalid'
1109 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1111 // Is extension country active?
1112 if (isExtensionActive('country')) {
1113 // Determine the right country code through the country id
1114 $id = getUserData('country_code');
1116 // Then handle it over
1117 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1119 // Get raw code from user data
1120 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1125 return $GLOBALS[__FUNCTION__][$userid];
1128 // "Getter" for total confirmed user accounts
1129 function getTotalConfirmedUser () {
1131 if (!isset($GLOBALS[__FUNCTION__])) {
1133 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1136 // Return cached value
1137 return $GLOBALS[__FUNCTION__];
1140 // "Getter" for total unconfirmed user accounts
1141 function getTotalUnconfirmedUser () {
1143 if (!isset($GLOBALS[__FUNCTION__])) {
1145 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1148 // Return cached value
1149 return $GLOBALS[__FUNCTION__];
1152 // "Getter" for total locked user accounts
1153 function getTotalLockedUser () {
1155 if (!isset($GLOBALS[__FUNCTION__])) {
1157 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1160 // Return cached value
1161 return $GLOBALS[__FUNCTION__];
1164 // Is given userid valid?
1165 function isValidUserId ($userid) {
1166 // Do we have cache?
1167 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1169 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1173 return $GLOBALS[__FUNCTION__][$userid];
1177 function encodeEntities ($str) {
1179 $str = secureString($str, true, true);
1181 // Encode dollar sign as well
1182 $str = str_replace('$', '$', $str);
1188 // "Getter" for date from patch_ctime
1189 function getDateFromPatchTime () {
1191 if (!isset($GLOBALS[__FUNCTION__])) {
1193 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1197 return $GLOBALS[__FUNCTION__];
1200 // Getter for current year (default)
1201 function getYear ($timestamp = null) {
1203 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1205 if (is_null($timestamp)) $timestamp = time();
1208 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1212 return $GLOBALS[__FUNCTION__][$timestamp];
1215 // Getter for current month (default)
1216 function getMonth ($timestamp = null) {
1218 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1219 // If null is set, use time()
1220 if (is_null($timestamp)) {
1221 // Use time() which is current timestamp
1222 $timestamp = time();
1226 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1230 return $GLOBALS[__FUNCTION__][$timestamp];
1233 // Getter for current day (default)
1234 function getDay ($timestamp = null) {
1236 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1238 if (is_null($timestamp)) $timestamp = time();
1241 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1245 return $GLOBALS[__FUNCTION__][$timestamp];
1248 // Getter for current week (default)
1249 function getWeek ($timestamp = null) {
1251 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1253 if (is_null($timestamp)) $timestamp = time();
1256 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1260 return $GLOBALS[__FUNCTION__][$timestamp];
1263 // Getter for current short_hour (default)
1264 function getShortHour ($timestamp = null) {
1266 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1268 if (is_null($timestamp)) $timestamp = time();
1271 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1275 return $GLOBALS[__FUNCTION__][$timestamp];
1278 // Getter for current long_hour (default)
1279 function getLongHour ($timestamp = null) {
1281 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1283 if (is_null($timestamp)) $timestamp = time();
1286 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1290 return $GLOBALS[__FUNCTION__][$timestamp];
1293 // Getter for current second (default)
1294 function getSecond ($timestamp = null) {
1296 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1298 if (is_null($timestamp)) $timestamp = time();
1301 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1305 return $GLOBALS[__FUNCTION__][$timestamp];
1308 // Getter for current minute (default)
1309 function getMinute ($timestamp = null) {
1311 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1313 if (is_null($timestamp)) $timestamp = time();
1316 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1320 return $GLOBALS[__FUNCTION__][$timestamp];
1323 // Checks wether the title decoration is enabled
1324 function isTitleDecorationEnabled () {
1325 // Do we have cache?
1326 if (!isset($GLOBALS[__FUNCTION__])) {
1328 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1332 return $GLOBALS[__FUNCTION__];
1335 // Checks wether filter usage updates are enabled (expensive queries!)
1336 function isFilterUsageUpdateEnabled () {
1337 // Do we have cache?
1338 if (!isset($GLOBALS[__FUNCTION__])) {
1340 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1344 return $GLOBALS[__FUNCTION__];
1347 // Checks wether debugging of weekly resets is enabled
1348 function isWeeklyResetDebugEnabled () {
1349 // Do we have cache?
1350 if (!isset($GLOBALS[__FUNCTION__])) {
1352 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1356 return $GLOBALS[__FUNCTION__];
1359 // Checks wether debugging of monthly resets is enabled
1360 function isMonthlyResetDebugEnabled () {
1361 // Do we have cache?
1362 if (!isset($GLOBALS[__FUNCTION__])) {
1364 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1368 return $GLOBALS[__FUNCTION__];
1371 // Checks wether displaying of debug SQLs are enabled
1372 function isDisplayDebugSqlEnabled () {
1373 // Do we have cache?
1374 if (!isset($GLOBALS[__FUNCTION__])) {
1376 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1380 return $GLOBALS[__FUNCTION__];
1383 // Checks wether module title is enabled
1384 function isModuleTitleEnabled () {
1385 // Do we have cache?
1386 if (!isset($GLOBALS[__FUNCTION__])) {
1388 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1392 return $GLOBALS[__FUNCTION__];
1395 // Checks wether what title is enabled
1396 function isWhatTitleEnabled () {
1397 // Do we have cache?
1398 if (!isset($GLOBALS[__FUNCTION__])) {
1400 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1404 return $GLOBALS[__FUNCTION__];
1407 // Checks wether stats are enabled
1408 function ifStatsAreEnabled () {
1409 // Do we have cache?
1410 if (!isset($GLOBALS[__FUNCTION__])) {
1411 // Then determine it
1412 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1415 // Return cached value
1416 return $GLOBALS[__FUNCTION__];
1419 // Checks wether admin-notification of certain user actions is enabled
1420 function isAdminNotificationEnabled () {
1421 // Do we have cache?
1422 if (!isset($GLOBALS[__FUNCTION__])) {
1424 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1428 return $GLOBALS[__FUNCTION__];
1431 // Checks wether random referal id selection is enabled
1432 function isRandomReferalIdEnabled () {
1433 // Do we have cache?
1434 if (!isset($GLOBALS[__FUNCTION__])) {
1436 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1440 return $GLOBALS[__FUNCTION__];
1443 // "Getter" for default language
1444 function getDefaultLanguage () {
1445 // Do we have cache?
1446 if (!isset($GLOBALS[__FUNCTION__])) {
1448 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1452 return $GLOBALS[__FUNCTION__];
1455 // "Getter" for default referal id
1456 function getDefRefid () {
1457 // Do we have cache?
1458 if (!isset($GLOBALS[__FUNCTION__])) {
1460 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1464 return $GLOBALS[__FUNCTION__];
1467 // "Getter" for path
1468 function getPath () {
1469 // Do we have cache?
1470 if (!isset($GLOBALS[__FUNCTION__])) {
1472 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1476 return $GLOBALS[__FUNCTION__];
1480 function getUrl () {
1481 // Do we have cache?
1482 if (!isset($GLOBALS[__FUNCTION__])) {
1484 $GLOBALS[__FUNCTION__] = getConfig('URL');
1488 return $GLOBALS[__FUNCTION__];
1491 // "Getter" for cache_path
1492 function getCachePath () {
1493 // Do we have cache?
1494 if (!isset($GLOBALS[__FUNCTION__])) {
1496 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1500 return $GLOBALS[__FUNCTION__];
1503 // "Getter" for secret_key
1504 function getSecretKey () {
1505 // Do we have cache?
1506 if (!isset($GLOBALS[__FUNCTION__])) {
1508 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1512 return $GLOBALS[__FUNCTION__];
1515 // "Getter" for master_salt
1516 function getMasterSalt () {
1517 // Do we have cache?
1518 if (!isset($GLOBALS[__FUNCTION__])) {
1520 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1524 return $GLOBALS[__FUNCTION__];
1527 // "Getter" for prime
1528 function getPrime () {
1529 // Do we have cache?
1530 if (!isset($GLOBALS[__FUNCTION__])) {
1532 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1536 return $GLOBALS[__FUNCTION__];
1539 // "Getter" for encrypt_seperator
1540 function getEncryptSeperator () {
1541 // Do we have cache?
1542 if (!isset($GLOBALS[__FUNCTION__])) {
1544 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1548 return $GLOBALS[__FUNCTION__];
1551 // "Getter" for mysql_prefix
1552 function getMysqlPrefix () {
1553 // Do we have cache?
1554 if (!isset($GLOBALS[__FUNCTION__])) {
1556 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1560 return $GLOBALS[__FUNCTION__];
1563 // "Getter" for table_type
1564 function getTableType () {
1565 // Do we have cache?
1566 if (!isset($GLOBALS[__FUNCTION__])) {
1568 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1572 return $GLOBALS[__FUNCTION__];
1575 // "Getter" for salt_length
1576 function getSaltLength () {
1577 // Do we have cache?
1578 if (!isset($GLOBALS[__FUNCTION__])) {
1580 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1584 return $GLOBALS[__FUNCTION__];
1587 // "Getter" for output_mode
1588 function getOutputMode () {
1589 // Do we have cache?
1590 if (!isset($GLOBALS[__FUNCTION__])) {
1592 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1596 return $GLOBALS[__FUNCTION__];
1599 // "Getter" for full_version
1600 function getFullVersion () {
1601 // Do we have cache?
1602 if (!isset($GLOBALS[__FUNCTION__])) {
1604 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1608 return $GLOBALS[__FUNCTION__];
1611 // "Getter" for title
1612 function getTitle () {
1613 // Do we have cache?
1614 if (!isset($GLOBALS[__FUNCTION__])) {
1616 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1620 return $GLOBALS[__FUNCTION__];
1623 // "Getter" for curr_svn_revision
1624 function getCurrentRepositoryRevision () {
1625 // Do we have cache?
1626 if (!isset($GLOBALS[__FUNCTION__])) {
1628 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1632 return $GLOBALS[__FUNCTION__];
1635 // "Getter" for server_url
1636 function getServerUrl () {
1637 // Do we have cache?
1638 if (!isset($GLOBALS[__FUNCTION__])) {
1640 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1644 return $GLOBALS[__FUNCTION__];
1647 // "Getter" for mt_word
1648 function getMtWord () {
1649 // Do we have cache?
1650 if (!isset($GLOBALS[__FUNCTION__])) {
1652 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1656 return $GLOBALS[__FUNCTION__];
1659 // "Getter" for mt_word2
1660 function getMtWord2 () {
1661 // Do we have cache?
1662 if (!isset($GLOBALS[__FUNCTION__])) {
1664 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1668 return $GLOBALS[__FUNCTION__];
1671 // "Getter" for main_title
1672 function getMainTitle () {
1673 // Do we have cache?
1674 if (!isset($GLOBALS[__FUNCTION__])) {
1676 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1680 return $GLOBALS[__FUNCTION__];
1683 // "Getter" for file_hash
1684 function getFileHash () {
1685 // Do we have cache?
1686 if (!isset($GLOBALS[__FUNCTION__])) {
1688 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1692 return $GLOBALS[__FUNCTION__];
1695 // "Getter" for pass_scramble
1696 function getPassScramble () {
1697 // Do we have cache?
1698 if (!isset($GLOBALS[__FUNCTION__])) {
1700 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1704 return $GLOBALS[__FUNCTION__];
1707 // "Getter" for ap_inactive_since
1708 function getApInactiveSince () {
1709 // Do we have cache?
1710 if (!isset($GLOBALS[__FUNCTION__])) {
1712 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1716 return $GLOBALS[__FUNCTION__];
1719 // "Getter" for user_min_confirmed
1720 function getUserMinConfirmed () {
1721 // Do we have cache?
1722 if (!isset($GLOBALS[__FUNCTION__])) {
1724 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1728 return $GLOBALS[__FUNCTION__];
1731 // "Getter" for auto_purge
1732 function getAutoPurge () {
1733 // Do we have cache?
1734 if (!isset($GLOBALS[__FUNCTION__])) {
1736 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1740 return $GLOBALS[__FUNCTION__];
1743 // "Getter" for bonus_userid
1744 function getBonusUserid () {
1745 // Do we have cache?
1746 if (!isset($GLOBALS[__FUNCTION__])) {
1748 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1752 return $GLOBALS[__FUNCTION__];
1755 // "Getter" for ap_inactive_time
1756 function getApInactiveTime () {
1757 // Do we have cache?
1758 if (!isset($GLOBALS[__FUNCTION__])) {
1760 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1764 return $GLOBALS[__FUNCTION__];
1767 // "Getter" for ap_dm_timeout
1768 function getApDmTimeout () {
1769 // Do we have cache?
1770 if (!isset($GLOBALS[__FUNCTION__])) {
1772 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1776 return $GLOBALS[__FUNCTION__];
1779 // "Getter" for ap_tasks_time
1780 function getApTasksTime () {
1781 // Do we have cache?
1782 if (!isset($GLOBALS[__FUNCTION__])) {
1784 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1788 return $GLOBALS[__FUNCTION__];
1791 // "Getter" for ap_unconfirmed_time
1792 function getApUnconfirmedTime () {
1793 // Do we have cache?
1794 if (!isset($GLOBALS[__FUNCTION__])) {
1796 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1800 return $GLOBALS[__FUNCTION__];
1803 // "Getter" for points
1804 function getPoints () {
1805 // Do we have cache?
1806 if (!isset($GLOBALS[__FUNCTION__])) {
1808 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1812 return $GLOBALS[__FUNCTION__];
1815 // "Getter" for slogan
1816 function getSlogan () {
1817 // Do we have cache?
1818 if (!isset($GLOBALS[__FUNCTION__])) {
1820 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1824 return $GLOBALS[__FUNCTION__];
1827 // "Getter" for copy
1828 function getCopy () {
1829 // Do we have cache?
1830 if (!isset($GLOBALS[__FUNCTION__])) {
1832 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1836 return $GLOBALS[__FUNCTION__];
1839 // "Getter" for webmaster
1840 function getWebmaster () {
1841 // Do we have cache?
1842 if (!isset($GLOBALS[__FUNCTION__])) {
1844 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1848 return $GLOBALS[__FUNCTION__];
1851 // "Getter" for sql_count
1852 function getSqlCount () {
1853 // Do we have cache?
1854 if (!isset($GLOBALS[__FUNCTION__])) {
1856 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1860 return $GLOBALS[__FUNCTION__];
1863 // "Getter" for num_templates
1864 function getNumTemplates () {
1865 // Do we have cache?
1866 if (!isset($GLOBALS[__FUNCTION__])) {
1868 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1872 return $GLOBALS[__FUNCTION__];
1875 // "Getter" for dns_cache_timeout
1876 function getDnsCacheTimeout () {
1877 // Do we have cache?
1878 if (!isset($GLOBALS[__FUNCTION__])) {
1880 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1884 return $GLOBALS[__FUNCTION__];
1887 // "Getter" for menu_blur_spacer
1888 function getMenuBlurSpacer () {
1889 // Do we have cache?
1890 if (!isset($GLOBALS[__FUNCTION__])) {
1892 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
1896 return $GLOBALS[__FUNCTION__];
1899 // "Getter" for points_register
1900 function getPointsRegister () {
1901 // Do we have cache?
1902 if (!isset($GLOBALS[__FUNCTION__])) {
1904 $GLOBALS[__FUNCTION__] = getConfig('points_register');
1908 return $GLOBALS[__FUNCTION__];
1911 // "Getter" for points_ref
1912 function getPointsRef () {
1913 // Do we have cache?
1914 if (!isset($GLOBALS[__FUNCTION__])) {
1916 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
1920 return $GLOBALS[__FUNCTION__];
1923 // "Getter" for ref_payout
1924 function getRefPayout () {
1925 // Do we have cache?
1926 if (!isset($GLOBALS[__FUNCTION__])) {
1928 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
1932 return $GLOBALS[__FUNCTION__];
1935 // "Getter" for online_timeout
1936 function getOnlineTimeout () {
1937 // Do we have cache?
1938 if (!isset($GLOBALS[__FUNCTION__])) {
1940 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
1944 return $GLOBALS[__FUNCTION__];
1947 // "Getter" for index_home
1948 function getIndexHome () {
1949 // Do we have cache?
1950 if (!isset($GLOBALS[__FUNCTION__])) {
1952 $GLOBALS[__FUNCTION__] = getConfig('index_home');
1956 return $GLOBALS[__FUNCTION__];
1959 // "Getter" for one_day
1960 function getOneDay () {
1961 // Do we have cache?
1962 if (!isset($GLOBALS[__FUNCTION__])) {
1964 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
1968 return $GLOBALS[__FUNCTION__];
1971 // "Getter" for activate_xchange
1972 function getActivateXchange () {
1973 // Do we have cache?
1974 if (!isset($GLOBALS[__FUNCTION__])) {
1976 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
1980 return $GLOBALS[__FUNCTION__];
1983 // "Getter" for img_type
1984 function getImgType () {
1985 // Do we have cache?
1986 if (!isset($GLOBALS[__FUNCTION__])) {
1988 $GLOBALS[__FUNCTION__] = getConfig('img_type');
1992 return $GLOBALS[__FUNCTION__];
1995 // "Getter" for code_length
1996 function getCodeLength () {
1997 // Do we have cache?
1998 if (!isset($GLOBALS[__FUNCTION__])) {
2000 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2004 return $GLOBALS[__FUNCTION__];
2007 // "Getter" for least_cats
2008 function getLeastCats () {
2009 // Do we have cache?
2010 if (!isset($GLOBALS[__FUNCTION__])) {
2012 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2016 return $GLOBALS[__FUNCTION__];
2019 // "Getter" for pass_len
2020 function getPassLen () {
2021 // Do we have cache?
2022 if (!isset($GLOBALS[__FUNCTION__])) {
2024 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2028 return $GLOBALS[__FUNCTION__];
2031 // "Getter" for admin_menu
2032 function getAdminMenu () {
2033 // Do we have cache?
2034 if (!isset($GLOBALS[__FUNCTION__])) {
2036 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2040 return $GLOBALS[__FUNCTION__];
2043 // "Getter" for last_month
2044 function getLastMonth () {
2045 // Do we have cache?
2046 if (!isset($GLOBALS[__FUNCTION__])) {
2048 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2052 return $GLOBALS[__FUNCTION__];
2055 // "Getter" for max_send
2056 function getMaxSend () {
2057 // Do we have cache?
2058 if (!isset($GLOBALS[__FUNCTION__])) {
2060 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2064 return $GLOBALS[__FUNCTION__];
2067 // "Getter" for mails_page
2068 function getMailsPage () {
2069 // Do we have cache?
2070 if (!isset($GLOBALS[__FUNCTION__])) {
2072 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2076 return $GLOBALS[__FUNCTION__];
2079 // "Getter" for __DB_NAME
2080 function getDbName () {
2081 // Do we have cache?
2082 if (!isset($GLOBALS[__FUNCTION__])) {
2084 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2088 return $GLOBALS[__FUNCTION__];
2091 // Checks wether proxy configuration is used
2092 function isProxyUsed () {
2093 // Do we have cache?
2094 if (!isset($GLOBALS[__FUNCTION__])) {
2096 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2100 return $GLOBALS[__FUNCTION__];
2103 // Checks wether POST data contains selections
2104 function ifPostContainsSelections ($element = 'sel') {
2105 // Do we have cache?
2106 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2108 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
2112 return $GLOBALS[__FUNCTION__][$element];
2115 // Checks wether verbose_sql is Y and returns true/false if so
2116 function isVerboseSqlEnabled () {
2117 // Do we have cache?
2118 if (!isset($GLOBALS[__FUNCTION__])) {
2120 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2124 return $GLOBALS[__FUNCTION__];
2127 // "Getter" for total user points
2128 function getTotalPoints ($userid) {
2129 // Do we have cache?
2130 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2132 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points');
2136 return $GLOBALS[__FUNCTION__][$userid];
2139 // Wrapper to check if url_blacklist is enabled
2140 function isUrlBlacklistEnabled () {
2141 // Do we have cache?
2142 if (!isset($GLOBALS[__FUNCTION__])) {
2144 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2148 return $GLOBALS[__FUNCTION__];
2151 // Checks wether direct payment is allowed in configuration
2152 function isDirectPaymentEnabled () {
2153 // Do we have cache?
2154 if (!isset($GLOBALS[__FUNCTION__])) {
2156 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2160 return $GLOBALS[__FUNCTION__];
2163 // Wrapper to check if current task is for extension (not update)
2164 function isExtensionTask ($content) {
2165 // Do we have cache?
2166 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2168 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2172 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2175 // Wrapper to check if output mode is CSS
2176 function isCssOutputMode () {
2178 return (getScriptOutputMode() == 1);
2181 // Wrapper to check if output mode is HTML
2182 function isHtmlOutputMode () {
2184 return (getScriptOutputMode() == 0);
2187 // Wrapper to check if output mode is RAW
2188 function isRawOutputMode () {
2190 return (getScriptOutputMode() == -1);
2193 // Wrapper to generate a user email link
2194 function generateWrappedUserEmailLink ($email) {
2195 // Just call the inner function
2196 return generateEmailLink($email, 'user_data');
2199 // Wrapper to check if user points are locked
2200 function ifUserPointsLocked ($userid) {
2201 // Do we have cache?
2202 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2204 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2208 return $GLOBALS[__FUNCTION__][$userid];
2211 // Appends a line to an existing file or creates it instantly with given content.
2212 // This function does always add a new-line character to every line.
2213 function appendLineToFile ($file, $line) {
2214 $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2215 fwrite($fp, $line . "\n");
2219 // Wrapper for changeDataInFile() but with full path added
2220 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2222 $FQFN = getPath() . $FQFN;
2224 // Call inner function
2225 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);
2228 // Shortens ucfirst(strtolower()) calls
2229 function firstCharUpperCase ($str) {
2230 return ucfirst(strtolower($str));