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 () {
667 if (isOutputModeSet(true)) {
669 $output_mode = $GLOBALS['output_mode'];
676 // Setter for 'output_mode' value
677 function setOutputMode ($newOutputMode) {
678 $GLOBALS['output_mode'] = (int) $newOutputMode;
681 // Checks wether output_mode is set and optionally aborts on miss
682 function isOutputModeSet ($strict = false) {
684 $isset = (isset($GLOBALS['output_mode']));
686 // Should we abort here?
687 if (($strict === true) && ($isset === false)) {
689 debug_report_bug(__FUNCTION__, __LINE__, 'Output_mode is empty.');
696 // Enables block-mode
697 function enableBlockMode ($enabled = true) {
698 $GLOBALS['block_mode'] = $enabled;
701 // Checks wether block-mode is enabled
702 function isBlockModeEnabled () {
704 if (!isset($GLOBALS['block_mode'])) {
706 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
710 return $GLOBALS['block_mode'];
713 // Wrapper function for addPointsThroughReferalSystem()
714 function addPointsDirectly ($subject, $userid, $points) {
716 unset($GLOBALS['ref_level']);
718 // Call more complicated method (due to more parameters)
719 return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'direct');
722 // Wrapper for redirectToUrl but URL comes from a configuration entry
723 function redirectToConfiguredUrl ($configEntry) {
725 redirectToUrl(getConfig($configEntry));
728 // Wrapper function to redirect from member-only modules to index
729 function redirectToIndexMemberOnlyModule () {
730 // Do the redirect here
731 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
734 // Wrapper function to redirect to current URL
735 function redirectToRequestUri () {
736 redirectToUrl(basename(detectRequestUri()));
739 // Wrapper function to redirect to de-refered URL
740 function redirectToDereferedUrl ($URL) {
742 redirectToUrl(generateDerefererUrl($URL));
745 // Wrapper function for checking if extension is installed and newer or same version
746 function isExtensionInstalledAndNewer ($ext_name, $version) {
747 // Is an cache entry found?
748 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
750 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
752 // Cache hits should be incremented twice
753 incrementStatsEntry('cache_hits', 2);
757 //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'=>'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
758 return $GLOBALS[__FUNCTION__][$ext_name][$version];
761 // Wrapper function for checking if extension is installed and older than given version
762 function isExtensionInstalledAndOlder ($ext_name, $version) {
763 // Is an cache entry found?
764 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
766 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
768 // Cache hits should be incremented twice
769 incrementStatsEntry('cache_hits', 2);
773 //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'<'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
774 return $GLOBALS[__FUNCTION__][$ext_name][$version];
778 function setUsername ($userName) {
779 $GLOBALS['username'] = (string) $userName;
783 function getUsername () {
785 if (!isset($GLOBALS['username'])) {
786 // No, so it has to be a guest
787 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
791 return $GLOBALS['username'];
794 // Wrapper function for installation phase
795 function isInstallationPhase () {
797 if (!isset($GLOBALS[__FUNCTION__])) {
799 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
803 return $GLOBALS[__FUNCTION__];
806 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
807 function isDemoModeActive () {
809 if (!isset($GLOBALS[__FUNCTION__])) {
811 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
815 return $GLOBALS[__FUNCTION__];
818 // Getter for PHP caching value
819 function getPhpCaching () {
820 return $GLOBALS['php_caching'];
823 // Checks wether the admin hash is set
824 function isAdminHashSet ($adminId) {
825 // Is the array there?
826 if (!isset($GLOBALS['cache_array']['admin'])) {
827 // Missing array should be reported
828 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
831 // Check for admin hash
832 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
835 // Setter for admin hash
836 function setAdminHash ($adminId, $hash) {
837 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
840 // Getter for current admin login
841 function getCurrentAdminLogin () {
843 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
846 if (!isset($GLOBALS[__FUNCTION__])) {
848 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
852 return $GLOBALS[__FUNCTION__];
855 // Setter for admin id (and current)
856 function setAdminId ($adminId) {
858 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
861 $status = setSession('admin_id', bigintval($adminId));
864 setCurrentAdminId($adminId);
870 // Setter for admin_last
871 function setAdminLast ($adminLast) {
873 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
876 $status = setSession('admin_last', $adminLast);
882 // Setter for admin_md5
883 function setAdminMd5 ($adminMd5) {
885 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
888 $status = setSession('admin_md5', $adminMd5);
894 // Getter for admin_md5
895 function getAdminMd5 () {
897 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
900 return getSession('admin_md5');
903 // Init user data array
904 function initUserData () {
905 // User id should not be zero
906 if (!isValidUserId(getCurrentUserId())) {
907 // Should be always valid
908 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
912 $GLOBALS['user_data'][getCurrentUserId()] = array();
915 // Getter for user data
916 function getUserData ($column) {
917 // User id should not be zero
918 if (!isValidUserId(getCurrentUserId())) {
919 // Should be always valid
920 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
924 return $GLOBALS['user_data'][getCurrentUserId()][$column];
927 // Geter for whole user data array
928 function getUserDataArray () {
930 $userid = getCurrentUserId();
932 // Is the current userid valid?
933 if (!isValidUserId($userid)) {
934 // Should be always valid
935 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
938 // Get the whole array if found
939 if (isset($GLOBALS['user_data'][$userid])) {
940 // Found, so return it
941 return $GLOBALS['user_data'][$userid];
943 // Return empty array
948 // Checks if the user data is valid, this may indicate that the user has logged
949 // in, but you should use isMember() if you want to find that out.
950 function isUserDataValid () {
951 // User id should not be zero so abort here
952 if (!isCurrentUserIdSet()) return false;
955 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
957 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
961 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
964 // Setter for current userid
965 function setCurrentUserId ($userid) {
967 $GLOBALS['current_userid'] = bigintval($userid);
969 // Unset it to re-determine the actual state
970 unset($GLOBALS['is_userdata_valid'][$userid]);
973 // Getter for current userid
974 function getCurrentUserId () {
975 // Userid must be set before it can be used
976 if (!isCurrentUserIdSet()) {
978 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
982 return $GLOBALS['current_userid'];
985 // Checks if current userid is set
986 function isCurrentUserIdSet () {
987 return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
990 // Checks wether we are debugging template cache
991 function isDebuggingTemplateCache () {
993 if (!isset($GLOBALS[__FUNCTION__])) {
995 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
999 return $GLOBALS[__FUNCTION__];
1002 // Wrapper for fetchUserData() and getUserData() calls
1003 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1005 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1006 // Default is 'guest'
1007 $data = '{--USERNAME_GUEST--}';
1009 // Can we fetch the user data?
1010 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1011 // Now get the data back
1012 $data = getUserData($valueColumn);
1016 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1020 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1023 // Wrapper for strpos() to ease porting from deprecated ereg() function
1024 function isInString ($needle, $haystack) {
1025 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1026 return (strpos($haystack, $needle) !== false);
1029 // Wrapper for strpos() to ease porting from deprecated eregi() function
1030 // This function is case-insensitive
1031 function isInStringIgnoreCase ($needle, $haystack) {
1032 return (isInString(strtolower($needle), strtolower($haystack)));
1035 // Wrapper to check for if fatal errors where detected
1036 function ifFatalErrorsDetected () {
1037 // Just call the inner function
1038 return (getTotalFatalErrors() > 0);
1041 // Setter for HTTP status
1042 function setHttpStatus ($status) {
1043 $GLOBALS['http_status'] = (string) $status;
1046 // Getter for HTTP status
1047 function getHttpStatus () {
1048 // Is the status set?
1049 if (!isset($GLOBALS['http_status'])) {
1051 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1055 return $GLOBALS['http_status'];
1059 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1060 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1062 * ----------------------------------------------------------------------------
1063 * If you want to redirect, please use redirectToUrl(); instead
1064 * ----------------------------------------------------------------------------
1066 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1068 * @link http://support.microsoft.com/kb/q176113/
1069 * @author Andreas Gohr <andi@splitbrain.org>
1072 function sendRawRedirect ($url) {
1073 // Send helping header
1074 setHttpStatus('302 Found');
1076 // always close the session
1077 session_write_close();
1079 // Revert entity &
1080 $url = str_replace('&', '&', $url);
1082 // check if running on IIS < 6 with CGI-PHP
1083 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1084 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
1085 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1086 ($matches[1] < 6)) {
1087 // Send the IIS header
1088 sendHeader('Refresh: 0;url=' . $url);
1090 // Send generic header
1091 sendHeader('Location: ' . $url);
1098 // Determines the country of the given user id
1099 function determineCountry ($userid) {
1100 // Do we have cache?
1101 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1102 // Default is 'invalid'
1103 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1105 // Is extension country active?
1106 if (isExtensionActive('country')) {
1107 // Determine the right country code through the country id
1108 $id = getUserData('country_code');
1110 // Then handle it over
1111 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1113 // Get raw code from user data
1114 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1119 return $GLOBALS[__FUNCTION__][$userid];
1122 // "Getter" for total confirmed user accounts
1123 function getTotalConfirmedUser () {
1125 if (!isset($GLOBALS[__FUNCTION__])) {
1127 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1130 // Return cached value
1131 return $GLOBALS[__FUNCTION__];
1134 // "Getter" for total unconfirmed user accounts
1135 function getTotalUnconfirmedUser () {
1137 if (!isset($GLOBALS[__FUNCTION__])) {
1139 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1142 // Return cached value
1143 return $GLOBALS[__FUNCTION__];
1146 // "Getter" for total locked user accounts
1147 function getTotalLockedUser () {
1149 if (!isset($GLOBALS[__FUNCTION__])) {
1151 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1154 // Return cached value
1155 return $GLOBALS[__FUNCTION__];
1158 // Is given userid valid?
1159 function isValidUserId ($userid) {
1160 // Do we have cache?
1161 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1163 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1167 return $GLOBALS[__FUNCTION__][$userid];
1171 function encodeEntities ($str) {
1173 $str = secureString($str, true, true);
1175 // Encode dollar sign as well
1176 $str = str_replace('$', '$', $str);
1182 // "Getter" for date from patch_ctime
1183 function getDateFromPatchTime () {
1185 if (!isset($GLOBALS[__FUNCTION__])) {
1187 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1191 return $GLOBALS[__FUNCTION__];
1194 // Getter for current year (default)
1195 function getYear ($timestamp = null) {
1197 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1199 if (is_null($timestamp)) $timestamp = time();
1202 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1206 return $GLOBALS[__FUNCTION__][$timestamp];
1209 // Getter for current month (default)
1210 function getMonth ($timestamp = null) {
1212 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1213 // If null is set, use time()
1214 if (is_null($timestamp)) {
1215 // Use time() which is current timestamp
1216 $timestamp = time();
1220 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1224 return $GLOBALS[__FUNCTION__][$timestamp];
1227 // Getter for current day (default)
1228 function getDay ($timestamp = null) {
1230 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1232 if (is_null($timestamp)) $timestamp = time();
1235 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1239 return $GLOBALS[__FUNCTION__][$timestamp];
1242 // Getter for current week (default)
1243 function getWeek ($timestamp = null) {
1245 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1247 if (is_null($timestamp)) $timestamp = time();
1250 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1254 return $GLOBALS[__FUNCTION__][$timestamp];
1257 // Getter for current short_hour (default)
1258 function getShortHour ($timestamp = null) {
1260 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1262 if (is_null($timestamp)) $timestamp = time();
1265 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1269 return $GLOBALS[__FUNCTION__][$timestamp];
1272 // Getter for current long_hour (default)
1273 function getLongHour ($timestamp = null) {
1275 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1277 if (is_null($timestamp)) $timestamp = time();
1280 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1284 return $GLOBALS[__FUNCTION__][$timestamp];
1287 // Getter for current second (default)
1288 function getSecond ($timestamp = null) {
1290 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1292 if (is_null($timestamp)) $timestamp = time();
1295 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1299 return $GLOBALS[__FUNCTION__][$timestamp];
1302 // Getter for current minute (default)
1303 function getMinute ($timestamp = null) {
1305 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1307 if (is_null($timestamp)) $timestamp = time();
1310 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1314 return $GLOBALS[__FUNCTION__][$timestamp];
1317 // Checks wether the title decoration is enabled
1318 function isTitleDecorationEnabled () {
1319 // Do we have cache?
1320 if (!isset($GLOBALS[__FUNCTION__])) {
1322 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1326 return $GLOBALS[__FUNCTION__];
1329 // Checks wether filter usage updates are enabled (expensive queries!)
1330 function isFilterUsageUpdateEnabled () {
1331 // Do we have cache?
1332 if (!isset($GLOBALS[__FUNCTION__])) {
1334 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1338 return $GLOBALS[__FUNCTION__];
1341 // Checks wether debugging of weekly resets is enabled
1342 function isWeeklyResetDebugEnabled () {
1343 // Do we have cache?
1344 if (!isset($GLOBALS[__FUNCTION__])) {
1346 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1350 return $GLOBALS[__FUNCTION__];
1353 // Checks wether debugging of monthly resets is enabled
1354 function isMonthlyResetDebugEnabled () {
1355 // Do we have cache?
1356 if (!isset($GLOBALS[__FUNCTION__])) {
1358 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1362 return $GLOBALS[__FUNCTION__];
1365 // Checks wether displaying of debug SQLs are enabled
1366 function isDisplayDebugSqlEnabled () {
1367 // Do we have cache?
1368 if (!isset($GLOBALS[__FUNCTION__])) {
1370 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1374 return $GLOBALS[__FUNCTION__];
1377 // Checks wether module title is enabled
1378 function isModuleTitleEnabled () {
1379 // Do we have cache?
1380 if (!isset($GLOBALS[__FUNCTION__])) {
1382 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1386 return $GLOBALS[__FUNCTION__];
1389 // Checks wether what title is enabled
1390 function isWhatTitleEnabled () {
1391 // Do we have cache?
1392 if (!isset($GLOBALS[__FUNCTION__])) {
1394 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1398 return $GLOBALS[__FUNCTION__];
1401 // Checks wether stats are enabled
1402 function ifStatsAreEnabled () {
1403 // Do we have cache?
1404 if (!isset($GLOBALS[__FUNCTION__])) {
1405 // Then determine it
1406 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1409 // Return cached value
1410 return $GLOBALS[__FUNCTION__];
1413 // Checks wether admin-notification of certain user actions is enabled
1414 function isAdminNotificationEnabled () {
1415 // Do we have cache?
1416 if (!isset($GLOBALS[__FUNCTION__])) {
1418 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1422 return $GLOBALS[__FUNCTION__];
1425 // Checks wether random referal id selection is enabled
1426 function isRandomReferalIdEnabled () {
1427 // Do we have cache?
1428 if (!isset($GLOBALS[__FUNCTION__])) {
1430 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1434 return $GLOBALS[__FUNCTION__];
1437 // "Getter" for default language
1438 function getDefaultLanguage () {
1439 // Do we have cache?
1440 if (!isset($GLOBALS[__FUNCTION__])) {
1442 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1446 return $GLOBALS[__FUNCTION__];
1449 // "Getter" for default referal id
1450 function getDefRefid () {
1451 // Do we have cache?
1452 if (!isset($GLOBALS[__FUNCTION__])) {
1454 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1458 return $GLOBALS[__FUNCTION__];
1461 // "Getter" for path
1462 function getPath () {
1463 // Do we have cache?
1464 if (!isset($GLOBALS[__FUNCTION__])) {
1466 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1470 return $GLOBALS[__FUNCTION__];
1474 function getUrl () {
1475 // Do we have cache?
1476 if (!isset($GLOBALS[__FUNCTION__])) {
1478 $GLOBALS[__FUNCTION__] = getConfig('URL');
1482 return $GLOBALS[__FUNCTION__];
1485 // "Getter" for cache_path
1486 function getCachePath () {
1487 // Do we have cache?
1488 if (!isset($GLOBALS[__FUNCTION__])) {
1490 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1494 return $GLOBALS[__FUNCTION__];
1497 // "Getter" for secret_key
1498 function getSecretKey () {
1499 // Do we have cache?
1500 if (!isset($GLOBALS[__FUNCTION__])) {
1502 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1506 return $GLOBALS[__FUNCTION__];
1509 // "Getter" for master_salt
1510 function getMasterSalt () {
1511 // Do we have cache?
1512 if (!isset($GLOBALS[__FUNCTION__])) {
1514 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1518 return $GLOBALS[__FUNCTION__];
1521 // "Getter" for prime
1522 function getPrime () {
1523 // Do we have cache?
1524 if (!isset($GLOBALS[__FUNCTION__])) {
1526 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1530 return $GLOBALS[__FUNCTION__];
1533 // "Getter" for encrypt_seperator
1534 function getEncryptSeperator () {
1535 // Do we have cache?
1536 if (!isset($GLOBALS[__FUNCTION__])) {
1538 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1542 return $GLOBALS[__FUNCTION__];
1545 // "Getter" for mysql_prefix
1546 function getMysqlPrefix () {
1547 // Do we have cache?
1548 if (!isset($GLOBALS[__FUNCTION__])) {
1550 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1554 return $GLOBALS[__FUNCTION__];
1557 // "Getter" for table_type
1558 function getTableType () {
1559 // Do we have cache?
1560 if (!isset($GLOBALS[__FUNCTION__])) {
1562 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1566 return $GLOBALS[__FUNCTION__];
1569 // "Getter" for salt_length
1570 function getSaltLength () {
1571 // Do we have cache?
1572 if (!isset($GLOBALS[__FUNCTION__])) {
1574 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1578 return $GLOBALS[__FUNCTION__];
1581 // "Getter" for output_mode
1582 function getOutputMode () {
1583 // Do we have cache?
1584 if (!isset($GLOBALS[__FUNCTION__])) {
1586 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1590 return $GLOBALS[__FUNCTION__];
1593 // "Getter" for full_version
1594 function getFullVersion () {
1595 // Do we have cache?
1596 if (!isset($GLOBALS[__FUNCTION__])) {
1598 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1602 return $GLOBALS[__FUNCTION__];
1605 // "Getter" for title
1606 function getTitle () {
1607 // Do we have cache?
1608 if (!isset($GLOBALS[__FUNCTION__])) {
1610 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1614 return $GLOBALS[__FUNCTION__];
1617 // "Getter" for curr_svn_revision
1618 function getCurrentRepositoryRevision () {
1619 // Do we have cache?
1620 if (!isset($GLOBALS[__FUNCTION__])) {
1622 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1626 return $GLOBALS[__FUNCTION__];
1629 // "Getter" for server_url
1630 function getServerUrl () {
1631 // Do we have cache?
1632 if (!isset($GLOBALS[__FUNCTION__])) {
1634 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1638 return $GLOBALS[__FUNCTION__];
1641 // "Getter" for mt_word
1642 function getMtWord () {
1643 // Do we have cache?
1644 if (!isset($GLOBALS[__FUNCTION__])) {
1646 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1650 return $GLOBALS[__FUNCTION__];
1653 // "Getter" for mt_word2
1654 function getMtWord2 () {
1655 // Do we have cache?
1656 if (!isset($GLOBALS[__FUNCTION__])) {
1658 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1662 return $GLOBALS[__FUNCTION__];
1665 // "Getter" for main_title
1666 function getMainTitle () {
1667 // Do we have cache?
1668 if (!isset($GLOBALS[__FUNCTION__])) {
1670 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1674 return $GLOBALS[__FUNCTION__];
1677 // "Getter" for file_hash
1678 function getFileHash () {
1679 // Do we have cache?
1680 if (!isset($GLOBALS[__FUNCTION__])) {
1682 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1686 return $GLOBALS[__FUNCTION__];
1689 // "Getter" for pass_scramble
1690 function getPassScramble () {
1691 // Do we have cache?
1692 if (!isset($GLOBALS[__FUNCTION__])) {
1694 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1698 return $GLOBALS[__FUNCTION__];
1701 // "Getter" for ap_inactive_since
1702 function getApInactiveSince () {
1703 // Do we have cache?
1704 if (!isset($GLOBALS[__FUNCTION__])) {
1706 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1710 return $GLOBALS[__FUNCTION__];
1713 // "Getter" for user_min_confirmed
1714 function getUserMinConfirmed () {
1715 // Do we have cache?
1716 if (!isset($GLOBALS[__FUNCTION__])) {
1718 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1722 return $GLOBALS[__FUNCTION__];
1725 // "Getter" for auto_purge
1726 function getAutoPurge () {
1727 // Do we have cache?
1728 if (!isset($GLOBALS[__FUNCTION__])) {
1730 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1734 return $GLOBALS[__FUNCTION__];
1737 // "Getter" for bonus_userid
1738 function getBonusUserid () {
1739 // Do we have cache?
1740 if (!isset($GLOBALS[__FUNCTION__])) {
1742 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1746 return $GLOBALS[__FUNCTION__];
1749 // "Getter" for ap_inactive_time
1750 function getApInactiveTime () {
1751 // Do we have cache?
1752 if (!isset($GLOBALS[__FUNCTION__])) {
1754 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1758 return $GLOBALS[__FUNCTION__];
1761 // "Getter" for ap_dm_timeout
1762 function getApDmTimeout () {
1763 // Do we have cache?
1764 if (!isset($GLOBALS[__FUNCTION__])) {
1766 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1770 return $GLOBALS[__FUNCTION__];
1773 // "Getter" for ap_tasks_time
1774 function getApTasksTime () {
1775 // Do we have cache?
1776 if (!isset($GLOBALS[__FUNCTION__])) {
1778 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1782 return $GLOBALS[__FUNCTION__];
1785 // "Getter" for ap_unconfirmed_time
1786 function getApUnconfirmedTime () {
1787 // Do we have cache?
1788 if (!isset($GLOBALS[__FUNCTION__])) {
1790 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1794 return $GLOBALS[__FUNCTION__];
1797 // "Getter" for points
1798 function getPoints () {
1799 // Do we have cache?
1800 if (!isset($GLOBALS[__FUNCTION__])) {
1802 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1806 return $GLOBALS[__FUNCTION__];
1809 // "Getter" for slogan
1810 function getSlogan () {
1811 // Do we have cache?
1812 if (!isset($GLOBALS[__FUNCTION__])) {
1814 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1818 return $GLOBALS[__FUNCTION__];
1821 // "Getter" for copy
1822 function getCopy () {
1823 // Do we have cache?
1824 if (!isset($GLOBALS[__FUNCTION__])) {
1826 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1830 return $GLOBALS[__FUNCTION__];
1833 // "Getter" for webmaster
1834 function getWebmaster () {
1835 // Do we have cache?
1836 if (!isset($GLOBALS[__FUNCTION__])) {
1838 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1842 return $GLOBALS[__FUNCTION__];
1845 // "Getter" for sql_count
1846 function getSqlCount () {
1847 // Do we have cache?
1848 if (!isset($GLOBALS[__FUNCTION__])) {
1850 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1854 return $GLOBALS[__FUNCTION__];
1857 // "Getter" for num_templates
1858 function getNumTemplates () {
1859 // Do we have cache?
1860 if (!isset($GLOBALS[__FUNCTION__])) {
1862 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1866 return $GLOBALS[__FUNCTION__];
1869 // "Getter" for dns_cache_timeout
1870 function getDnsCacheTimeout () {
1871 // Do we have cache?
1872 if (!isset($GLOBALS[__FUNCTION__])) {
1874 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1878 return $GLOBALS[__FUNCTION__];
1881 // "Getter" for menu_blur_spacer
1882 function getMenuBlurSpacer () {
1883 // Do we have cache?
1884 if (!isset($GLOBALS[__FUNCTION__])) {
1886 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
1890 return $GLOBALS[__FUNCTION__];
1893 // "Getter" for points_register
1894 function getPointsRegister () {
1895 // Do we have cache?
1896 if (!isset($GLOBALS[__FUNCTION__])) {
1898 $GLOBALS[__FUNCTION__] = getConfig('points_register');
1902 return $GLOBALS[__FUNCTION__];
1905 // "Getter" for points_ref
1906 function getPointsRef () {
1907 // Do we have cache?
1908 if (!isset($GLOBALS[__FUNCTION__])) {
1910 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
1914 return $GLOBALS[__FUNCTION__];
1917 // "Getter" for ref_payout
1918 function getRefPayout () {
1919 // Do we have cache?
1920 if (!isset($GLOBALS[__FUNCTION__])) {
1922 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
1926 return $GLOBALS[__FUNCTION__];
1929 // "Getter" for online_timeout
1930 function getOnlineTimeout () {
1931 // Do we have cache?
1932 if (!isset($GLOBALS[__FUNCTION__])) {
1934 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
1938 return $GLOBALS[__FUNCTION__];
1941 // "Getter" for index_home
1942 function getIndexHome () {
1943 // Do we have cache?
1944 if (!isset($GLOBALS[__FUNCTION__])) {
1946 $GLOBALS[__FUNCTION__] = getConfig('index_home');
1950 return $GLOBALS[__FUNCTION__];
1953 // "Getter" for one_day
1954 function getOneDay () {
1955 // Do we have cache?
1956 if (!isset($GLOBALS[__FUNCTION__])) {
1958 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
1962 return $GLOBALS[__FUNCTION__];
1965 // "Getter" for activate_xchange
1966 function getActivateXchange () {
1967 // Do we have cache?
1968 if (!isset($GLOBALS[__FUNCTION__])) {
1970 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
1974 return $GLOBALS[__FUNCTION__];
1977 // "Getter" for img_type
1978 function getImgType () {
1979 // Do we have cache?
1980 if (!isset($GLOBALS[__FUNCTION__])) {
1982 $GLOBALS[__FUNCTION__] = getConfig('img_type');
1986 return $GLOBALS[__FUNCTION__];
1989 // "Getter" for code_length
1990 function getCodeLength () {
1991 // Do we have cache?
1992 if (!isset($GLOBALS[__FUNCTION__])) {
1994 $GLOBALS[__FUNCTION__] = getConfig('code_length');
1998 return $GLOBALS[__FUNCTION__];
2001 // "Getter" for least_cats
2002 function getLeastCats () {
2003 // Do we have cache?
2004 if (!isset($GLOBALS[__FUNCTION__])) {
2006 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2010 return $GLOBALS[__FUNCTION__];
2013 // "Getter" for pass_len
2014 function getPassLen () {
2015 // Do we have cache?
2016 if (!isset($GLOBALS[__FUNCTION__])) {
2018 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2022 return $GLOBALS[__FUNCTION__];
2025 // "Getter" for admin_menu
2026 function getAdminMenu () {
2027 // Do we have cache?
2028 if (!isset($GLOBALS[__FUNCTION__])) {
2030 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2034 return $GLOBALS[__FUNCTION__];
2037 // "Getter" for last_month
2038 function getLastMonth () {
2039 // Do we have cache?
2040 if (!isset($GLOBALS[__FUNCTION__])) {
2042 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2046 return $GLOBALS[__FUNCTION__];
2049 // "Getter" for max_send
2050 function getMaxSend () {
2051 // Do we have cache?
2052 if (!isset($GLOBALS[__FUNCTION__])) {
2054 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2058 return $GLOBALS[__FUNCTION__];
2061 // "Getter" for mails_page
2062 function getMailsPage () {
2063 // Do we have cache?
2064 if (!isset($GLOBALS[__FUNCTION__])) {
2066 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2070 return $GLOBALS[__FUNCTION__];
2073 // "Getter" for __DB_NAME
2074 function getDbName () {
2075 // Do we have cache?
2076 if (!isset($GLOBALS[__FUNCTION__])) {
2078 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2082 return $GLOBALS[__FUNCTION__];
2085 // Checks wether proxy configuration is used
2086 function isProxyUsed () {
2087 // Do we have cache?
2088 if (!isset($GLOBALS[__FUNCTION__])) {
2090 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2094 return $GLOBALS[__FUNCTION__];
2097 // Checks wether POST data contains selections
2098 function ifPostContainsSelections ($element = 'sel') {
2099 // Do we have cache?
2100 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2102 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
2106 return $GLOBALS[__FUNCTION__][$element];
2109 // Checks wether verbose_sql is Y and returns true/false if so
2110 function isVerboseSqlEnabled () {
2111 // Do we have cache?
2112 if (!isset($GLOBALS[__FUNCTION__])) {
2114 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2118 return $GLOBALS[__FUNCTION__];
2121 // "Getter" for total user points
2122 function getTotalPoints ($userid) {
2123 // Do we have cache?
2124 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2126 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points');
2130 return $GLOBALS[__FUNCTION__][$userid];
2133 // Wrapper to check if url_blacklist is enabled
2134 function isUrlBlacklistEnabled () {
2135 // Do we have cache?
2136 if (!isset($GLOBALS[__FUNCTION__])) {
2138 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2142 return $GLOBALS[__FUNCTION__];
2145 // Checks wether direct payment is allowed in configuration
2146 function isDirectPaymentEnabled () {
2147 // Do we have cache?
2148 if (!isset($GLOBALS[__FUNCTION__])) {
2150 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2154 return $GLOBALS[__FUNCTION__];
2157 // Wrapper to check if current task is for extension (not update)
2158 function isExtensionTask ($content) {
2159 // Do we have cache?
2160 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2162 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2166 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2169 // Wrapper to check if output mode is CSS
2170 function isCssOutputMode () {
2172 return (getScriptOutputMode() == 1);
2175 // Wrapper to check if output mode is HTML
2176 function isHtmlOutputMode () {
2178 return (getScriptOutputMode() == 0);
2181 // Wrapper to check if output mode is RAW
2182 function isRawOutputMode () {
2184 return (getScriptOutputMode() == -1);
2187 // Wrapper to generate a user email link
2188 function generateWrappedUserEmailLink ($email) {
2189 // Just call the inner function
2190 return generateEmailLink($email, 'user_data');
2193 // Wrapper to check if user points are locked
2194 function ifUserPointsLocked ($userid) {
2195 // Do we have cache?
2196 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2198 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2202 return $GLOBALS[__FUNCTION__][$userid];
2205 // Appends a line to an existing file or creates it instantly with given content.
2206 // This function does always add a new-line character to every line.
2207 function appendLineToFile ($file, $line) {
2208 $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2209 fwrite($fp, $line . "\n");
2213 // Wrapper for changeDataInFile() but with full path added
2214 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2216 $FQFN = getPath() . $FQFN;
2218 // Call inner function
2219 changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);
2222 // Shortens ucfirst(strtolower()) calls
2223 function firstCharUpperCase ($str) {
2224 return ucfirst(strtolower($str));