2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 04/04/2009 *
4 * =================== Last change: 04/04/2009 *
6 * -------------------------------------------------------------------- *
7 * File : wrapper-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Wrapper functions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Wrapper-Funktionen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
44 function readFromFile ($FQFN) {
45 // Sanity-check if file is there (should be there, but just to make it sure)
46 if (!isFileReadable($FQFN)) {
47 // This should not happen
48 debug_report_bug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!');
49 } elseif (!isset($GLOBALS['file_content'][$FQFN])) {
51 if (function_exists('file_get_contents')) {
53 $GLOBALS['file_content'][$FQFN] = file_get_contents($FQFN);
55 // Fall-back to implode-file chain
56 $GLOBALS['file_content'][$FQFN] = implode('', file($FQFN));
61 return $GLOBALS['file_content'][$FQFN];
64 // Writes content to a file
65 function writeToFile ($FQFN, $content, $aquireLock = false) {
66 // Is the file writeable?
67 if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
69 logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN)));
75 // By default all is failed...
76 $GLOBALS['file_readable'][$FQFN] = false;
77 unset($GLOBALS['file_content'][$FQFN]);
80 // Is the function there?
81 if (function_exists('file_put_contents')) {
83 if ($aquireLock === true) {
84 // Write it directly with lock
85 $return = file_put_contents($FQFN, $content, LOCK_EX);
88 $return = file_put_contents($FQFN, $content);
91 // Write it with fopen
92 $fp = fopen($FQFN, 'w') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
94 // Do we need to aquire a lock?
95 if ($aquireLock === true) {
101 $return = fwrite($fp, $content);
107 // Was something written?
108 if ($return !== false) {
109 // Mark it as readable
110 $GLOBALS['file_readable'][$FQFN] = true;
112 // Remember content in cache
113 $GLOBALS['file_content'][$FQFN] = $content;
117 return (($return !== false) && (changeMode($FQFN, 0644)));
120 // Clears the output buffer. This function does *NOT* backup sent content.
121 function clearOutputBuffer () {
122 // Trigger an error on failure
123 if ((ob_get_length() > 0) && (!ob_end_clean())) {
125 debug_report_bug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
130 // @TODO Implement $compress
131 function encodeString ($str, $compress = true) {
132 $str = urlencode(base64_encode(compileUriCode($str)));
136 // Decode strings encoded with encodeString()
137 // @TODO Implement $decompress
138 function decodeString ($str, $decompress = true) {
139 $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
143 // Decode entities in a nicer way
144 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
145 // Decode the entities to UTF-8 now
146 $decodedString = html_entity_decode($str, $quote, 'UTF-8');
148 // Return decoded string
149 return $decodedString;
152 // Merges an array together but only if both are arrays
153 function merge_array ($array1, $array2) {
154 // Are both an array?
155 if ((!is_array($array1)) && (!is_array($array2))) {
156 // Both are not arrays
157 debug_report_bug(__FUNCTION__, __LINE__, 'No arrays provided!');
158 } elseif (!is_array($array1)) {
159 // Left one is not an array
160 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
161 } elseif (!is_array($array2)) {
162 // Right one is not an array
163 debug_report_bug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
166 // Merge all together
167 return array_merge($array1, $array2);
170 // Check if given FQFN is a readable file
171 function isFileReadable ($FQFN) {
173 if (!isset($GLOBALS['file_readable'][$FQFN])) {
175 $GLOBALS['file_readable'][$FQFN] = ((file_exists($FQFN)) && (is_file($FQFN)) && (is_readable($FQFN)));
179 return $GLOBALS['file_readable'][$FQFN];
182 // Checks wether the given FQFN is a directory and not ., .. or .svn
183 function isDirectory ($FQFN) {
185 if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
187 $baseName = basename($FQFN);
190 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
194 return $GLOBALS[__FUNCTION__][$FQFN];
197 // "Getter" for the real remote IP number
198 function detectRealIpAddress () {
199 // Get remote ip from environment
200 $remoteAddr = determineRealRemoteAddress();
202 // Is removeip installed?
203 if (isExtensionActive('removeip')) {
205 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
212 // "Getter" for remote IP number
213 function detectRemoteAddr () {
214 // Get remote ip from environment
215 $remoteAddr = determineRealRemoteAddress(true);
217 // Is removeip installed?
218 if (isExtensionActive('removeip')) {
220 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
227 // "Getter" for remote hostname
228 function detectRemoteHostname () {
229 // Get remote ip from environment
230 $remoteHost = getenv('REMOTE_HOST');
232 // Is removeip installed?
233 if (isExtensionActive('removeip')) {
235 $remoteHost = getAnonymousRemoteHost($remoteHost);
242 // "Getter" for user agent
243 function detectUserAgent ($alwaysReal = false) {
244 // Get remote ip from environment
245 $userAgent = getenv('HTTP_USER_AGENT');
247 // Is removeip installed?
248 if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
250 $userAgent = getAnonymousUserAgent($userAgent);
257 // "Getter" for referer
258 function detectReferer () {
259 // Get remote ip from environment
260 $referer = getenv('HTTP_REFERER');
262 // Is removeip installed?
263 if (isExtensionActive('removeip')) {
265 $referer = getAnonymousReferer($referer);
272 // "Getter" for request URI
273 function detectRequestUri () {
275 return (getenv('REQUEST_URI'));
278 // "Getter" for query string
279 function detectQueryString () {
280 return str_replace('&', '&', (getenv('QUERY_STRING')));
283 // "Getter" for SERVER_NAME
284 function detectServerName () {
286 return (getenv('SERVER_NAME'));
289 // Removes any existing www. from SERVER_NAME. This is very silly but enough
290 // for our purpose here.
291 function detectDomainName () {
293 if (!isset($GLOBALS[__FUNCTION__])) {
295 $domainName = detectServerName();
297 // Is there any www. ?
298 if (substr($domainName, 0, 4) == 'www.') {
300 $domainName = substr($domainName, 4);
304 $GLOBALS[__FUNCTION__] = $domainName;
308 return $GLOBALS[__FUNCTION__];
311 // Check wether we are installing
312 function isInstalling () {
313 // Determine wether we are installing
314 if (!isset($GLOBALS['mailer_installing'])) {
315 // Check URL (css.php/js.php need this)
316 $GLOBALS['mailer_installing'] = isGetRequestParameterSet('installing');
320 return $GLOBALS['mailer_installing'];
323 // Check wether this script is installed
324 function isInstalled () {
326 if (!isset($GLOBALS[__FUNCTION__])) {
327 // Determine wether this script is installed
328 $GLOBALS[__FUNCTION__] = (
333 isConfigEntrySet('MXCHANGE_INSTALLED')
335 getConfig('MXCHANGE_INSTALLED') == 'Y'
339 // New config file found and loaded
340 isIncludeReadable(getCachePath() . 'config-local.php')
343 // New config file found, but not yet read
344 isIncludeReadable(getCachePath() . 'config-local.php')
347 // Only new config file is found
348 !isIncludeReadable('inc/config.php')
350 // Is installation mode
357 // Then use the cache
358 return $GLOBALS[__FUNCTION__];
361 // Check wether an admin is registered
362 function isAdminRegistered () {
364 if (!isset($GLOBALS[__FUNCTION__])) {
366 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
370 return $GLOBALS[__FUNCTION__];
373 // Checks wether the hourly reset mode is active
374 function isHourlyResetEnabled () {
375 // Now simply check it
376 return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === true));
379 // Checks wether the reset mode is active
380 function isResetModeEnabled () {
381 // Now simply check it
382 return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
385 // Checks wether the debug mode is enabled
386 function isDebugModeEnabled () {
388 if (!isset($GLOBALS[__FUNCTION__])) {
390 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
394 return $GLOBALS[__FUNCTION__];
397 // Checks wether the debug reset is enabled
398 function isDebugResetEnabled () {
400 if (!isset($GLOBALS[__FUNCTION__])) {
402 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'));
406 return $GLOBALS[__FUNCTION__];
409 // Checks wether SQL debugging is enabled
410 function isSqlDebuggingEnabled () {
412 if (!isset($GLOBALS[__FUNCTION__])) {
413 // Determine if SQL debugging is enabled
414 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
418 return $GLOBALS[__FUNCTION__];
421 // Checks wether we shall debug regular expressions
422 function isDebugRegularExpressionEnabled () {
424 if (!isset($GLOBALS[__FUNCTION__])) {
426 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
430 return $GLOBALS[__FUNCTION__];
433 // Checks wether the cache instance is valid
434 function isCacheInstanceValid () {
436 if (!isset($GLOBALS[__FUNCTION__])) {
438 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
442 return $GLOBALS[__FUNCTION__];
445 // Copies a file from source to destination and verifies if that goes fine.
446 // This function should wrap the copy() command and make a nicer debug backtrace
447 // even if there is no xdebug extension installed.
448 function copyFileVerified ($source, $dest, $chmod = '') {
449 // Failed is the default
452 // Is the source file there?
453 if (!isFileReadable($source)) {
455 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
458 // Is the target directory there?
459 if (!isDirectory(dirname($dest))) {
461 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
464 // Now try to copy it
465 if (!copy($source, $dest)) {
466 // Something went wrong
467 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
470 $GLOBALS['file_readable'][$dest] = true;
473 // If there are chmod rights set, apply them
474 if (!empty($chmod)) {
476 $status = changeMode($dest, $chmod);
486 // Wrapper function for header()
487 // Send a header but checks before if we can do so
488 function sendHeader ($header) {
490 //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header);
491 $GLOBALS['header'][] = trim($header);
494 // Flushes all headers
495 function flushHeaders () {
496 // Is the header already sent?
497 if (headers_sent()) {
499 debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!');
502 // Flush all headers if found
503 if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) {
504 foreach ($GLOBALS['header'] as $header) {
509 // Mark them as flushed
510 $GLOBALS['header'] = array();
513 // Wrapper function for chmod()
514 // @TODO Do some more sanity check here
515 function changeMode ($FQFN, $mode) {
516 // Is the file/directory there?
517 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
518 // Neither, so abort here
519 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
523 return chmod($FQFN, $mode);
526 // Wrapper for unlink()
527 function removeFile ($FQFN) {
528 // Is the file there?
529 if (isFileReadable($FQFN)) {
531 $GLOBALS['file_readable'][$FQFN] = false;
534 return unlink($FQFN);
537 // All fine if no file was removed. If we change this to 'false' or rewrite
538 // above if() block it would be to restrictive.
542 // Wrapper for $_POST['sel']
543 function countPostSelection ($element = 'sel') {
545 if (isPostRequestParameterSet($element)) {
546 // Return counted elements
547 return countSelection(postRequestParameter($element));
549 // Return zero if not found
554 // Checks wether the config-local.php is loaded
555 function isConfigLocalLoaded () {
556 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
559 // Checks wether a nickname or userid was entered and caches the result
560 function isNicknameUsed ($userid) {
561 // Is the cache there
562 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
564 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . round($userid) . '') != $userid));
568 return $GLOBALS[__FUNCTION__][$userid];
571 // Getter for 'what' value
572 function getWhat () {
577 if (isWhatSet(true)) {
579 $what = $GLOBALS['what'];
586 // Setter for 'what' value
587 function setWhat ($newWhat) {
588 $GLOBALS['what'] = SQL_ESCAPE($newWhat);
591 // Setter for 'what' from configuration
592 function setWhatFromConfig ($configEntry) {
593 // Get 'what' from config
594 $what = getConfig($configEntry);
600 // Checks wether what is set and optionally aborts on miss
601 function isWhatSet ($strict = false) {
603 $isset = isset($GLOBALS['what']);
605 // Should we abort here?
606 if (($strict === true) && ($isset === false)) {
608 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
615 // Getter for 'action' value
616 function getAction ($strict = true) {
621 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
623 $action = $GLOBALS['action'];
630 // Setter for 'action' value
631 function setAction ($newAction) {
632 $GLOBALS['action'] = SQL_ESCAPE($newAction);
635 // Checks wether action is set and optionally aborts on miss
636 function isActionSet ($strict = false) {
638 $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action'])));
640 // Should we abort here?
641 if (($strict === true) && ($isset === false)) {
643 debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.');
650 // Getter for 'module' value
651 function getModule ($strict = true) {
656 if (isModuleSet($strict)) {
658 $module = $GLOBALS['module'];
665 // Setter for 'module' value
666 function setModule ($newModule) {
667 // Secure it and make all modules lower-case
668 $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
671 // Checks wether module is set and optionally aborts on miss
672 function isModuleSet ($strict = false) {
674 $isset = (!empty($GLOBALS['module']));
676 // Should we abort here?
677 if (($strict === true) && ($isset === false)) {
679 debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.');
683 return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
686 // Getter for 'output_mode' value
687 function getScriptOutputMode () {
689 if (!isset($GLOBALS[__FUNCTION__])) {
694 if (isOutputModeSet(true)) {
696 $output_mode = $GLOBALS['output_mode'];
700 $GLOBALS[__FUNCTION__] = $output_mode;
704 return $GLOBALS[__FUNCTION__];
707 // Setter for 'output_mode' value
708 function setOutputMode ($newOutputMode) {
709 $GLOBALS['output_mode'] = (int) $newOutputMode;
712 // Checks wether output_mode is set and optionally aborts on miss
713 function isOutputModeSet ($strict = false) {
715 $isset = (isset($GLOBALS['output_mode']));
717 // Should we abort here?
718 if (($strict === true) && ($isset === false)) {
720 debug_report_bug(__FUNCTION__, __LINE__, 'Output mode is not set.');
727 // Enables block-mode
728 function enableBlockMode ($enabled = true) {
729 $GLOBALS['block_mode'] = $enabled;
732 // Checks wether block-mode is enabled
733 function isBlockModeEnabled () {
735 if (!isset($GLOBALS['block_mode'])) {
737 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
741 return $GLOBALS['block_mode'];
745 * Wrapper function for addPointsThroughReferalSystem(), you should generally
746 * avoid this function and use addPointsThroughReferalSystem() directly and add
747 * your special payment method entry to points_data instead.
749 * @param $subject A string-encoded subject for this add
750 * @param $userid The recipient (member) for given points
751 * @param $points Points to be added to member's account
752 * @return $added Wether the points has been added to the user's account
754 function addPointsDirectly ($subject, $userid, $points) {
758 // Call more complicated method (due to more parameters)
759 return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'DIRECT');
762 // Wrapper for redirectToUrl but URL comes from a configuration entry
763 function redirectToConfiguredUrl ($configEntry) {
765 redirectToUrl(getConfig($configEntry));
768 // Wrapper function to redirect from member-only modules to index
769 function redirectToIndexMemberOnlyModule () {
770 // Do the redirect here
771 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
774 // Wrapper function to redirect to current URL
775 function redirectToRequestUri () {
776 redirectToUrl(basename(detectRequestUri()));
779 // Wrapper function to redirect to de-refered URL
780 function redirectToDereferedUrl ($url) {
782 redirectToUrl(generateDerefererUrl($url));
785 // Wrapper function for checking if extension is installed and newer or same version
786 function isExtensionInstalledAndNewer ($ext_name, $version) {
787 // Is an cache entry found?
788 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
790 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
792 // Cache hits should be incremented twice
793 incrementStatsEntry('cache_hits', 2);
797 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
798 return $GLOBALS[__FUNCTION__][$ext_name][$version];
801 // Wrapper function for checking if extension is installed and older than given version
802 function isExtensionInstalledAndOlder ($ext_name, $version) {
803 // Is an cache entry found?
804 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
806 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
808 // Cache hits should be incremented twice
809 incrementStatsEntry('cache_hits', 2);
813 //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
814 return $GLOBALS[__FUNCTION__][$ext_name][$version];
818 function setUsername ($userName) {
819 $GLOBALS['username'] = (string) $userName;
823 function getUsername () {
825 if (!isset($GLOBALS['username'])) {
826 // No, so it has to be a guest
827 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
831 return $GLOBALS['username'];
834 // Wrapper function for installation phase
835 function isInstallationPhase () {
837 if (!isset($GLOBALS[__FUNCTION__])) {
839 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
843 return $GLOBALS[__FUNCTION__];
846 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
847 function isDemoModeActive () {
849 if (!isset($GLOBALS[__FUNCTION__])) {
851 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
855 return $GLOBALS[__FUNCTION__];
858 // Getter for PHP caching value
859 function getPhpCaching () {
860 return $GLOBALS['php_caching'];
863 // Checks wether the admin hash is set
864 function isAdminHashSet ($adminId) {
865 // Is the array there?
866 if (!isset($GLOBALS['cache_array']['admin'])) {
867 // Missing array should be reported
868 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
871 // Check for admin hash
872 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
875 // Setter for admin hash
876 function setAdminHash ($adminId, $hash) {
877 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
880 // Getter for current admin login
881 function getCurrentAdminLogin () {
883 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
886 if (!isset($GLOBALS[__FUNCTION__])) {
888 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
892 return $GLOBALS[__FUNCTION__];
895 // Setter for admin id (and current)
896 function setAdminId ($adminId) {
898 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
901 $status = setSession('admin_id', bigintval($adminId));
904 setCurrentAdminId($adminId);
910 // Setter for admin_last
911 function setAdminLast ($adminLast) {
913 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
916 $status = setSession('admin_last', $adminLast);
922 // Setter for admin_md5
923 function setAdminMd5 ($adminMd5) {
925 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
928 $status = setSession('admin_md5', $adminMd5);
934 // Getter for admin_md5
935 function getAdminMd5 () {
937 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
940 return getSession('admin_md5');
943 // Init user data array
944 function initUserData () {
945 // User id should not be zero
946 if (!isValidUserId(getCurrentUserId())) {
947 // Should be always valid
948 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
952 $GLOBALS['user_data'][getCurrentUserId()] = array();
955 // Getter for user data
956 function getUserData ($column) {
957 // User id should not be zero
958 if (!isValidUserId(getCurrentUserId())) {
959 // Should be always valid
960 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
966 if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
968 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
975 // Checks wether given user data is set to 'Y'
976 function isUserDataEnabled ($column) {
978 if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
980 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
984 return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
987 // Geter for whole user data array
988 function getUserDataArray () {
990 $userid = getCurrentUserId();
992 // Is the current userid valid?
993 if (!isValidUserId($userid)) {
994 // Should be always valid
995 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
998 // Get the whole array if found
999 if (isset($GLOBALS['user_data'][$userid])) {
1000 // Found, so return it
1001 return $GLOBALS['user_data'][$userid];
1003 // Return empty array
1008 // Checks if the user data is valid, this may indicate that the user has logged
1009 // in, but you should use isMember() if you want to find that out.
1010 function isUserDataValid () {
1011 // User id should not be zero so abort here
1012 if (!isCurrentUserIdSet()) return false;
1015 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
1017 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
1020 // Return the result
1021 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1024 // Setter for current userid
1025 function setCurrentUserId ($userid) {
1027 $GLOBALS['current_userid'] = bigintval($userid);
1029 // Unset it to re-determine the actual state
1030 unset($GLOBALS['is_userdata_valid'][$userid]);
1033 // Getter for current userid
1034 function getCurrentUserId () {
1035 // Userid must be set before it can be used
1036 if (!isCurrentUserIdSet()) {
1038 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
1041 // Return the userid
1042 return $GLOBALS['current_userid'];
1045 // Checks if current userid is set
1046 function isCurrentUserIdSet () {
1047 return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
1050 // Checks wether we are debugging template cache
1051 function isDebuggingTemplateCache () {
1052 // Do we have cache?
1053 if (!isset($GLOBALS[__FUNCTION__])) {
1055 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1059 return $GLOBALS[__FUNCTION__];
1062 // Wrapper for fetchUserData() and getUserData() calls
1063 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1064 /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1066 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1067 // Default is 'guest'
1068 $data = '{--USERNAME_GUEST--}';
1070 // Can we fetch the user data?
1071 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
1072 // Now get the data back
1073 $data = getUserData($valueColumn);
1077 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1081 /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1082 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1085 // Wrapper for strpos() to ease porting from deprecated ereg() function
1086 function isInString ($needle, $haystack) {
1087 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
1088 return (strpos($haystack, $needle) !== false);
1091 // Wrapper for strpos() to ease porting from deprecated eregi() function
1092 // This function is case-insensitive
1093 function isInStringIgnoreCase ($needle, $haystack) {
1094 return (isInString(strtolower($needle), strtolower($haystack)));
1097 // Wrapper to check for if fatal errors where detected
1098 function ifFatalErrorsDetected () {
1099 // Just call the inner function
1100 return (getTotalFatalErrors() > 0);
1103 // Setter for HTTP status
1104 function setHttpStatus ($status) {
1105 $GLOBALS['http_status'] = (string) $status;
1108 // Getter for HTTP status
1109 function getHttpStatus () {
1110 // Is the status set?
1111 if (!isset($GLOBALS['http_status'])) {
1113 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1117 return $GLOBALS['http_status'];
1121 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1122 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1124 * ----------------------------------------------------------------------------
1125 * If you want to redirect, please use redirectToUrl(); instead
1126 * ----------------------------------------------------------------------------
1128 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1130 * @link http://support.microsoft.com/kb/q176113/
1131 * @author Andreas Gohr <andi@splitbrain.org>
1134 function sendRawRedirect ($url) {
1135 // Send helping header
1136 setHttpStatus('302 Found');
1138 // always close the session
1139 session_write_close();
1141 // Revert entity &
1142 $url = str_replace('&', '&', $url);
1144 // check if running on IIS < 6 with CGI-PHP
1145 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1146 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
1147 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1148 ($matches[1] < 6)) {
1149 // Send the IIS header
1150 sendHeader('Refresh: 0;url=' . $url);
1152 // Send generic header
1153 sendHeader('Location: ' . $url);
1160 // Determines the country of the given user id
1161 function determineCountry ($userid) {
1162 // Do we have cache?
1163 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1164 // Default is 'invalid'
1165 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1167 // Is extension country active?
1168 if (isExtensionActive('country')) {
1169 // Determine the right country code through the country id
1170 $id = getUserData('country_code');
1172 // Then handle it over
1173 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1175 // Get raw code from user data
1176 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1181 return $GLOBALS[__FUNCTION__][$userid];
1184 // "Getter" for total confirmed user accounts
1185 function getTotalConfirmedUser () {
1187 if (!isset($GLOBALS[__FUNCTION__])) {
1189 if (isExtensionActive('user')) {
1190 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1192 $GLOBALS[__FUNCTION__] = 0;
1196 // Return cached value
1197 return $GLOBALS[__FUNCTION__];
1200 // "Getter" for total unconfirmed user accounts
1201 function getTotalUnconfirmedUser () {
1203 if (!isset($GLOBALS[__FUNCTION__])) {
1205 if (isExtensionActive('user')) {
1206 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1208 $GLOBALS[__FUNCTION__] = 0;
1212 // Return cached value
1213 return $GLOBALS[__FUNCTION__];
1216 // "Getter" for total locked user accounts
1217 function getTotalLockedUser () {
1219 if (!isset($GLOBALS[__FUNCTION__])) {
1221 if (isExtensionActive('user')) {
1222 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1224 $GLOBALS[__FUNCTION__] = 0;
1228 // Return cached value
1229 return $GLOBALS[__FUNCTION__];
1232 // "Getter" for total locked user accounts
1233 function getTotalRandomRefidUser () {
1235 if (!isset($GLOBALS[__FUNCTION__])) {
1237 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1238 $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, '', '>=');
1240 $GLOBALS[__FUNCTION__] = 0;
1244 // Return cached value
1245 return $GLOBALS[__FUNCTION__];
1248 // Is given userid valid?
1249 function isValidUserId ($userid) {
1250 // Do we have cache?
1251 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1253 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1257 return $GLOBALS[__FUNCTION__][$userid];
1261 function encodeEntities ($str) {
1263 $str = secureString($str, true, true);
1265 // Encode dollar sign as well
1266 $str = str_replace('$', '$', $str);
1272 // "Getter" for date from patch_ctime
1273 function getDateFromPatchTime () {
1275 if (!isset($GLOBALS[__FUNCTION__])) {
1277 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1281 return $GLOBALS[__FUNCTION__];
1284 // Getter for current year (default)
1285 function getYear ($timestamp = null) {
1287 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1289 if (is_null($timestamp)) {
1290 $timestamp = time();
1294 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1298 return $GLOBALS[__FUNCTION__][$timestamp];
1301 // Getter for current month (default)
1302 function getMonth ($timestamp = null) {
1304 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1305 // If null is set, use time()
1306 if (is_null($timestamp)) {
1307 // Use time() which is current timestamp
1308 $timestamp = time();
1312 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1316 return $GLOBALS[__FUNCTION__][$timestamp];
1319 // Getter for current hour (default)
1320 function getHour ($timestamp = null) {
1322 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1324 if (is_null($timestamp)) {
1325 $timestamp = time();
1329 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1333 return $GLOBALS[__FUNCTION__][$timestamp];
1336 // Getter for current day (default)
1337 function getDay ($timestamp = null) {
1339 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1341 if (is_null($timestamp)) {
1342 $timestamp = time();
1346 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1350 return $GLOBALS[__FUNCTION__][$timestamp];
1353 // Getter for current week (default)
1354 function getWeek ($timestamp = null) {
1356 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1358 if (is_null($timestamp)) $timestamp = time();
1361 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1365 return $GLOBALS[__FUNCTION__][$timestamp];
1368 // Getter for current short_hour (default)
1369 function getShortHour ($timestamp = null) {
1371 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1373 if (is_null($timestamp)) $timestamp = time();
1376 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1380 return $GLOBALS[__FUNCTION__][$timestamp];
1383 // Getter for current long_hour (default)
1384 function getLongHour ($timestamp = null) {
1386 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1388 if (is_null($timestamp)) $timestamp = time();
1391 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1395 return $GLOBALS[__FUNCTION__][$timestamp];
1398 // Getter for current second (default)
1399 function getSecond ($timestamp = null) {
1401 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1403 if (is_null($timestamp)) $timestamp = time();
1406 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1410 return $GLOBALS[__FUNCTION__][$timestamp];
1413 // Getter for current minute (default)
1414 function getMinute ($timestamp = null) {
1416 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1418 if (is_null($timestamp)) $timestamp = time();
1421 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1425 return $GLOBALS[__FUNCTION__][$timestamp];
1428 // Checks wether the title decoration is enabled
1429 function isTitleDecorationEnabled () {
1430 // Do we have cache?
1431 if (!isset($GLOBALS[__FUNCTION__])) {
1433 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1437 return $GLOBALS[__FUNCTION__];
1440 // Checks wether filter usage updates are enabled (expensive queries!)
1441 function isFilterUsageUpdateEnabled () {
1442 // Do we have cache?
1443 if (!isset($GLOBALS[__FUNCTION__])) {
1445 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1449 return $GLOBALS[__FUNCTION__];
1452 // Checks wether debugging of weekly resets is enabled
1453 function isWeeklyResetDebugEnabled () {
1454 // Do we have cache?
1455 if (!isset($GLOBALS[__FUNCTION__])) {
1457 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1461 return $GLOBALS[__FUNCTION__];
1464 // Checks wether debugging of monthly resets is enabled
1465 function isMonthlyResetDebugEnabled () {
1466 // Do we have cache?
1467 if (!isset($GLOBALS[__FUNCTION__])) {
1469 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1473 return $GLOBALS[__FUNCTION__];
1476 // Checks wether displaying of debug SQLs are enabled
1477 function isDisplayDebugSqlEnabled () {
1478 // Do we have cache?
1479 if (!isset($GLOBALS[__FUNCTION__])) {
1481 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1485 return $GLOBALS[__FUNCTION__];
1488 // Checks wether module title is enabled
1489 function isModuleTitleEnabled () {
1490 // Do we have cache?
1491 if (!isset($GLOBALS[__FUNCTION__])) {
1493 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1497 return $GLOBALS[__FUNCTION__];
1500 // Checks wether what title is enabled
1501 function isWhatTitleEnabled () {
1502 // Do we have cache?
1503 if (!isset($GLOBALS[__FUNCTION__])) {
1505 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1509 return $GLOBALS[__FUNCTION__];
1512 // Checks wether stats are enabled
1513 function ifStatsAreEnabled () {
1514 // Do we have cache?
1515 if (!isset($GLOBALS[__FUNCTION__])) {
1516 // Then determine it
1517 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1520 // Return cached value
1521 return $GLOBALS[__FUNCTION__];
1524 // Checks wether admin-notification of certain user actions is enabled
1525 function isAdminNotificationEnabled () {
1526 // Do we have cache?
1527 if (!isset($GLOBALS[__FUNCTION__])) {
1529 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1533 return $GLOBALS[__FUNCTION__];
1536 // Checks wether random referal id selection is enabled
1537 function isRandomReferalIdEnabled () {
1538 // Do we have cache?
1539 if (!isset($GLOBALS[__FUNCTION__])) {
1541 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1545 return $GLOBALS[__FUNCTION__];
1548 // "Getter" for default language
1549 function getDefaultLanguage () {
1550 // Do we have cache?
1551 if (!isset($GLOBALS[__FUNCTION__])) {
1553 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1557 return $GLOBALS[__FUNCTION__];
1560 // "Getter" for default referal id
1561 function getDefRefid () {
1562 // Do we have cache?
1563 if (!isset($GLOBALS[__FUNCTION__])) {
1565 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1569 return $GLOBALS[__FUNCTION__];
1572 // "Getter" for path
1573 function getPath () {
1574 // Do we have cache?
1575 if (!isset($GLOBALS[__FUNCTION__])) {
1577 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1581 return $GLOBALS[__FUNCTION__];
1585 function getUrl () {
1586 // Do we have cache?
1587 if (!isset($GLOBALS[__FUNCTION__])) {
1589 $GLOBALS[__FUNCTION__] = getConfig('URL');
1593 return $GLOBALS[__FUNCTION__];
1596 // "Getter" for cache_path
1597 function getCachePath () {
1598 // Do we have cache?
1599 if (!isset($GLOBALS[__FUNCTION__])) {
1601 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1605 return $GLOBALS[__FUNCTION__];
1608 // "Getter" for secret_key
1609 function getSecretKey () {
1610 // Do we have cache?
1611 if (!isset($GLOBALS[__FUNCTION__])) {
1613 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1617 return $GLOBALS[__FUNCTION__];
1620 // "Getter" for SITE_KEY
1621 function getSiteKey () {
1622 // Do we have cache?
1623 if (!isset($GLOBALS[__FUNCTION__])) {
1625 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1629 return $GLOBALS[__FUNCTION__];
1632 // "Getter" for DATE_KEY
1633 function getDateKey () {
1634 // Do we have cache?
1635 if (!isset($GLOBALS[__FUNCTION__])) {
1637 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1641 return $GLOBALS[__FUNCTION__];
1644 // "Getter" for master_salt
1645 function getMasterSalt () {
1646 // Do we have cache?
1647 if (!isset($GLOBALS[__FUNCTION__])) {
1649 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1653 return $GLOBALS[__FUNCTION__];
1656 // "Getter" for prime
1657 function getPrime () {
1658 // Do we have cache?
1659 if (!isset($GLOBALS[__FUNCTION__])) {
1661 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1665 return $GLOBALS[__FUNCTION__];
1668 // "Getter" for encrypt_seperator
1669 function getEncryptSeperator () {
1670 // Do we have cache?
1671 if (!isset($GLOBALS[__FUNCTION__])) {
1673 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1677 return $GLOBALS[__FUNCTION__];
1680 // "Getter" for mysql_prefix
1681 function getMysqlPrefix () {
1682 // Do we have cache?
1683 if (!isset($GLOBALS[__FUNCTION__])) {
1685 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1689 return $GLOBALS[__FUNCTION__];
1692 // "Getter" for table_type
1693 function getTableType () {
1694 // Do we have cache?
1695 if (!isset($GLOBALS[__FUNCTION__])) {
1697 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1701 return $GLOBALS[__FUNCTION__];
1704 // "Getter" for salt_length
1705 function getSaltLength () {
1706 // Do we have cache?
1707 if (!isset($GLOBALS[__FUNCTION__])) {
1709 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1713 return $GLOBALS[__FUNCTION__];
1716 // "Getter" for output_mode
1717 function getOutputMode () {
1718 // Do we have cache?
1719 if (!isset($GLOBALS[__FUNCTION__])) {
1721 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1725 return $GLOBALS[__FUNCTION__];
1728 // "Getter" for full_version
1729 function getFullVersion () {
1730 // Do we have cache?
1731 if (!isset($GLOBALS[__FUNCTION__])) {
1733 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1737 return $GLOBALS[__FUNCTION__];
1740 // "Getter" for title
1741 function getTitle () {
1742 // Do we have cache?
1743 if (!isset($GLOBALS[__FUNCTION__])) {
1745 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1749 return $GLOBALS[__FUNCTION__];
1752 // "Getter" for curr_svn_revision
1753 function getCurrentRepositoryRevision () {
1754 // Do we have cache?
1755 if (!isset($GLOBALS[__FUNCTION__])) {
1757 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1761 return $GLOBALS[__FUNCTION__];
1764 // "Getter" for server_url
1765 function getServerUrl () {
1766 // Do we have cache?
1767 if (!isset($GLOBALS[__FUNCTION__])) {
1769 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1773 return $GLOBALS[__FUNCTION__];
1776 // "Getter" for mt_word
1777 function getMtWord () {
1778 // Do we have cache?
1779 if (!isset($GLOBALS[__FUNCTION__])) {
1781 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1785 return $GLOBALS[__FUNCTION__];
1788 // "Getter" for mt_word2
1789 function getMtWord2 () {
1790 // Do we have cache?
1791 if (!isset($GLOBALS[__FUNCTION__])) {
1793 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1797 return $GLOBALS[__FUNCTION__];
1800 // "Getter" for main_title
1801 function getMainTitle () {
1802 // Do we have cache?
1803 if (!isset($GLOBALS[__FUNCTION__])) {
1805 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1809 return $GLOBALS[__FUNCTION__];
1812 // "Getter" for file_hash
1813 function getFileHash () {
1814 // Do we have cache?
1815 if (!isset($GLOBALS[__FUNCTION__])) {
1817 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1821 return $GLOBALS[__FUNCTION__];
1824 // "Getter" for pass_scramble
1825 function getPassScramble () {
1826 // Do we have cache?
1827 if (!isset($GLOBALS[__FUNCTION__])) {
1829 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1833 return $GLOBALS[__FUNCTION__];
1836 // "Getter" for ap_inactive_since
1837 function getApInactiveSince () {
1838 // Do we have cache?
1839 if (!isset($GLOBALS[__FUNCTION__])) {
1841 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1845 return $GLOBALS[__FUNCTION__];
1848 // "Getter" for user_min_confirmed
1849 function getUserMinConfirmed () {
1850 // Do we have cache?
1851 if (!isset($GLOBALS[__FUNCTION__])) {
1853 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1857 return $GLOBALS[__FUNCTION__];
1860 // "Getter" for auto_purge
1861 function getAutoPurge () {
1862 // Do we have cache?
1863 if (!isset($GLOBALS[__FUNCTION__])) {
1865 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1869 return $GLOBALS[__FUNCTION__];
1872 // "Getter" for bonus_userid
1873 function getBonusUserid () {
1874 // Do we have cache?
1875 if (!isset($GLOBALS[__FUNCTION__])) {
1877 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1881 return $GLOBALS[__FUNCTION__];
1884 // "Getter" for ap_inactive_time
1885 function getApInactiveTime () {
1886 // Do we have cache?
1887 if (!isset($GLOBALS[__FUNCTION__])) {
1889 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1893 return $GLOBALS[__FUNCTION__];
1896 // "Getter" for ap_dm_timeout
1897 function getApDmTimeout () {
1898 // Do we have cache?
1899 if (!isset($GLOBALS[__FUNCTION__])) {
1901 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1905 return $GLOBALS[__FUNCTION__];
1908 // "Getter" for ap_tasks_time
1909 function getApTasksTime () {
1910 // Do we have cache?
1911 if (!isset($GLOBALS[__FUNCTION__])) {
1913 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1917 return $GLOBALS[__FUNCTION__];
1920 // "Getter" for ap_unconfirmed_time
1921 function getApUnconfirmedTime () {
1922 // Do we have cache?
1923 if (!isset($GLOBALS[__FUNCTION__])) {
1925 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1929 return $GLOBALS[__FUNCTION__];
1932 // "Getter" for points
1933 function getPoints () {
1934 // Do we have cache?
1935 if (!isset($GLOBALS[__FUNCTION__])) {
1937 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1941 return $GLOBALS[__FUNCTION__];
1944 // "Getter" for slogan
1945 function getSlogan () {
1946 // Do we have cache?
1947 if (!isset($GLOBALS[__FUNCTION__])) {
1949 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1953 return $GLOBALS[__FUNCTION__];
1956 // "Getter" for copy
1957 function getCopy () {
1958 // Do we have cache?
1959 if (!isset($GLOBALS[__FUNCTION__])) {
1961 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1965 return $GLOBALS[__FUNCTION__];
1968 // "Getter" for webmaster
1969 function getWebmaster () {
1970 // Do we have cache?
1971 if (!isset($GLOBALS[__FUNCTION__])) {
1973 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1977 return $GLOBALS[__FUNCTION__];
1980 // "Getter" for sql_count
1981 function getSqlCount () {
1982 // Do we have cache?
1983 if (!isset($GLOBALS[__FUNCTION__])) {
1985 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1989 return $GLOBALS[__FUNCTION__];
1992 // "Getter" for num_templates
1993 function getNumTemplates () {
1994 // Do we have cache?
1995 if (!isset($GLOBALS[__FUNCTION__])) {
1997 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2001 return $GLOBALS[__FUNCTION__];
2004 // "Getter" for dns_cache_timeout
2005 function getDnsCacheTimeout () {
2006 // Do we have cache?
2007 if (!isset($GLOBALS[__FUNCTION__])) {
2009 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2013 return $GLOBALS[__FUNCTION__];
2016 // "Getter" for menu_blur_spacer
2017 function getMenuBlurSpacer () {
2018 // Do we have cache?
2019 if (!isset($GLOBALS[__FUNCTION__])) {
2021 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2025 return $GLOBALS[__FUNCTION__];
2028 // "Getter" for points_register
2029 function getPointsRegister () {
2030 // Do we have cache?
2031 if (!isset($GLOBALS[__FUNCTION__])) {
2033 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2037 return $GLOBALS[__FUNCTION__];
2040 // "Getter" for points_ref
2041 function getPointsRef () {
2042 // Do we have cache?
2043 if (!isset($GLOBALS[__FUNCTION__])) {
2045 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2049 return $GLOBALS[__FUNCTION__];
2052 // "Getter" for ref_payout
2053 function getRefPayout () {
2054 // Do we have cache?
2055 if (!isset($GLOBALS[__FUNCTION__])) {
2057 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2061 return $GLOBALS[__FUNCTION__];
2064 // "Getter" for online_timeout
2065 function getOnlineTimeout () {
2066 // Do we have cache?
2067 if (!isset($GLOBALS[__FUNCTION__])) {
2069 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2073 return $GLOBALS[__FUNCTION__];
2076 // "Getter" for index_home
2077 function getIndexHome () {
2078 // Do we have cache?
2079 if (!isset($GLOBALS[__FUNCTION__])) {
2081 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2085 return $GLOBALS[__FUNCTION__];
2088 // "Getter" for one_day
2089 function getOneDay () {
2090 // Do we have cache?
2091 if (!isset($GLOBALS[__FUNCTION__])) {
2093 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2097 return $GLOBALS[__FUNCTION__];
2100 // "Getter" for activate_xchange
2101 function getActivateXchange () {
2102 // Do we have cache?
2103 if (!isset($GLOBALS[__FUNCTION__])) {
2105 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
2109 return $GLOBALS[__FUNCTION__];
2112 // "Getter" for img_type
2113 function getImgType () {
2114 // Do we have cache?
2115 if (!isset($GLOBALS[__FUNCTION__])) {
2117 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2121 return $GLOBALS[__FUNCTION__];
2124 // "Getter" for code_length
2125 function getCodeLength () {
2126 // Do we have cache?
2127 if (!isset($GLOBALS[__FUNCTION__])) {
2129 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2133 return $GLOBALS[__FUNCTION__];
2136 // "Getter" for least_cats
2137 function getLeastCats () {
2138 // Do we have cache?
2139 if (!isset($GLOBALS[__FUNCTION__])) {
2141 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
2145 return $GLOBALS[__FUNCTION__];
2148 // "Getter" for pass_len
2149 function getPassLen () {
2150 // Do we have cache?
2151 if (!isset($GLOBALS[__FUNCTION__])) {
2153 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2157 return $GLOBALS[__FUNCTION__];
2160 // "Getter" for admin_menu
2161 function getAdminMenu () {
2162 // Do we have cache?
2163 if (!isset($GLOBALS[__FUNCTION__])) {
2165 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2169 return $GLOBALS[__FUNCTION__];
2172 // "Getter" for last_month
2173 function getLastMonth () {
2174 // Do we have cache?
2175 if (!isset($GLOBALS[__FUNCTION__])) {
2177 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2181 return $GLOBALS[__FUNCTION__];
2184 // "Getter" for max_send
2185 function getMaxSend () {
2186 // Do we have cache?
2187 if (!isset($GLOBALS[__FUNCTION__])) {
2189 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2193 return $GLOBALS[__FUNCTION__];
2196 // "Getter" for mails_page
2197 function getMailsPage () {
2198 // Do we have cache?
2199 if (!isset($GLOBALS[__FUNCTION__])) {
2201 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2205 return $GLOBALS[__FUNCTION__];
2208 // "Getter" for rand_no
2209 function getRandNo () {
2210 // Do we have cache?
2211 if (!isset($GLOBALS[__FUNCTION__])) {
2213 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2217 return $GLOBALS[__FUNCTION__];
2220 // "Getter" for __DB_NAME
2221 function getDbName () {
2222 // Do we have cache?
2223 if (!isset($GLOBALS[__FUNCTION__])) {
2225 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2229 return $GLOBALS[__FUNCTION__];
2232 // "Getter" for DOMAIN
2233 function getDomain () {
2234 // Do we have cache?
2235 if (!isset($GLOBALS[__FUNCTION__])) {
2237 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2241 return $GLOBALS[__FUNCTION__];
2244 // "Getter" for proxy_username
2245 function getProxyUsername () {
2246 // Do we have cache?
2247 if (!isset($GLOBALS[__FUNCTION__])) {
2249 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2253 return $GLOBALS[__FUNCTION__];
2256 // "Getter" for proxy_password
2257 function getProxyPassword () {
2258 // Do we have cache?
2259 if (!isset($GLOBALS[__FUNCTION__])) {
2261 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2265 return $GLOBALS[__FUNCTION__];
2268 // "Getter" for proxy_host
2269 function getProxyHost () {
2270 // Do we have cache?
2271 if (!isset($GLOBALS[__FUNCTION__])) {
2273 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2277 return $GLOBALS[__FUNCTION__];
2280 // "Getter" for proxy_port
2281 function getProxyPort () {
2282 // Do we have cache?
2283 if (!isset($GLOBALS[__FUNCTION__])) {
2285 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2289 return $GLOBALS[__FUNCTION__];
2292 // "Getter" for SMTP_HOSTNAME
2293 function getSmtpHostname () {
2294 // Do we have cache?
2295 if (!isset($GLOBALS[__FUNCTION__])) {
2297 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2301 return $GLOBALS[__FUNCTION__];
2304 // "Getter" for SMTP_USER
2305 function getSmtpUser () {
2306 // Do we have cache?
2307 if (!isset($GLOBALS[__FUNCTION__])) {
2309 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2313 return $GLOBALS[__FUNCTION__];
2316 // "Getter" for SMTP_PASSWORD
2317 function getSmtpPassword () {
2318 // Do we have cache?
2319 if (!isset($GLOBALS[__FUNCTION__])) {
2321 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2325 return $GLOBALS[__FUNCTION__];
2328 // "Getter" for points_word
2329 function getPointsWord () {
2330 // Do we have cache?
2331 if (!isset($GLOBALS[__FUNCTION__])) {
2333 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2337 return $GLOBALS[__FUNCTION__];
2340 // "Getter" for profile_lock
2341 function getProfileLock () {
2342 // Do we have cache?
2343 if (!isset($GLOBALS[__FUNCTION__])) {
2345 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2349 return $GLOBALS[__FUNCTION__];
2352 // "Getter" for url_tlock
2353 function getUrlTlock () {
2354 // Do we have cache?
2355 if (!isset($GLOBALS[__FUNCTION__])) {
2357 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2361 return $GLOBALS[__FUNCTION__];
2364 // Checks wether proxy configuration is used
2365 function isProxyUsed () {
2366 // Do we have cache?
2367 if (!isset($GLOBALS[__FUNCTION__])) {
2369 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2373 return $GLOBALS[__FUNCTION__];
2376 // Checks wether POST data contains selections
2377 function ifPostContainsSelections ($element = 'sel') {
2378 // Do we have cache?
2379 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2381 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
2385 return $GLOBALS[__FUNCTION__][$element];
2388 // Checks wether verbose_sql is Y and returns true/false if so
2389 function isVerboseSqlEnabled () {
2390 // Do we have cache?
2391 if (!isset($GLOBALS[__FUNCTION__])) {
2393 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2397 return $GLOBALS[__FUNCTION__];
2400 // "Getter" for total user points
2401 function getTotalPoints ($userid) {
2402 // Do we have cache?
2403 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2404 // Init array for filter chain
2406 'userid' => $userid,
2410 // Run filter chain for getting more point values
2411 $data = runFilterChain('get_total_points', $data);
2414 $GLOBALS[__FUNCTION__][$userid] = $data['points'] - countSumTotalData($userid, 'user_data', 'used_points');
2418 return $GLOBALS[__FUNCTION__][$userid];
2421 // Wrapper to check if url_blacklist is enabled
2422 function isUrlBlacklistEnabled () {
2423 // Do we have cache?
2424 if (!isset($GLOBALS[__FUNCTION__])) {
2426 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2430 return $GLOBALS[__FUNCTION__];
2433 // Checks wether direct payment is allowed in configuration
2434 function isDirectPaymentEnabled () {
2435 // Do we have cache?
2436 if (!isset($GLOBALS[__FUNCTION__])) {
2438 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2442 return $GLOBALS[__FUNCTION__];
2445 // Wrapper to check if current task is for extension (not update)
2446 function isExtensionTask ($content) {
2447 // Do we have cache?
2448 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2450 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2454 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2457 // Wrapper to check if output mode is CSS
2458 function isCssOutputMode () {
2460 return (getScriptOutputMode() == 1);
2463 // Wrapper to check if output mode is HTML
2464 function isHtmlOutputMode () {
2466 return (getScriptOutputMode() == 0);
2469 // Wrapper to check if output mode is RAW
2470 function isRawOutputMode () {
2472 return (getScriptOutputMode() == -1);
2475 // Wrapper to generate a user email link
2476 function generateWrappedUserEmailLink ($email) {
2477 // Just call the inner function
2478 return generateEmailLink($email, 'user_data');
2481 // Wrapper to check if user points are locked
2482 function ifUserPointsLocked ($userid) {
2483 /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2484 // Do we have cache?
2485 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2487 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2491 /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2492 return $GLOBALS[__FUNCTION__][$userid];
2495 // Appends a line to an existing file or creates it instantly with given content.
2496 // This function does always add a new-line character to every line.
2497 function appendLineToFile ($file, $line) {
2498 $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2499 fwrite($fp, $line . "\n");
2503 // Wrapper for changeDataInFile() but with full path added
2504 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2506 $FQFN = getPath() . $FQFN;
2508 // Call inner function
2509 return changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);
2512 // Wrapper for changing entries in config-local.php
2513 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $DATA, $seek = 0) {
2514 // Call the inner function
2515 return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $DATA, $seek);
2518 // Shortens ucfirst(strtolower()) calls
2519 function firstCharUpperCase ($str) {
2520 return ucfirst(strtolower($str));
2523 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
2524 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
2525 // Get the configuration entry
2526 $configValue = getConfig($configEntry);
2528 // Call inner method
2529 return createTimeSelections($configValue, $configEntry, $stamps, $align);
2532 // Shortens converting of German comma to Computer's version in POST data
2533 function convertCommaToDotInPostData ($postEntry) {
2534 // Read and convert given entry
2535 $postValue = convertCommaToDot(postRequestParameter($postEntry));
2537 // ... and set it again
2538 setPostRequestParameter($postEntry, $postValue);
2541 // Converts German commas to Computer's version in all entries
2542 function convertCommaToDotInPostDataArray ($postEntries) {
2543 // Replace german decimal comma with computer decimal dot
2544 foreach ($postEntries as $entry) {
2545 // Is the entry there?
2546 if (isPostRequestParameterSet($entry)) {
2548 convertCommaToDotInPostData($entry);
2554 * Parses a string into a US formated float variable, taken from user comments
2555 * from PHP documentation website.
2557 * @param $floatString A string holding a float expression
2558 * @return $float Corresponding float variable
2559 * @author chris<at>georgakopoulos<dot>com
2560 * @link http://de.php.net/manual/en/function.floatval.php#92563
2562 function parseFloat ($floatString){
2563 $LocaleInfo = localeconv();
2564 $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '', $floatString);
2565 $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
2566 return floatval($floatString);
2569 // Generates a YES/NO option list from given default
2570 function generateYesNoOptionList ($default = '') {
2572 return generateOptionList('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $default);
2575 //-----------------------------------------------------------------------------
2576 // Configuration wrapper
2577 //-----------------------------------------------------------------------------
2579 // Getter for 'check_double_email'
2580 function getCheckDoubleEmail () {
2581 // Is the cache entry set?
2582 if (!isset($GLOBALS[__FUNCTION__])) {
2583 // No, so determine it
2584 $GLOBALS[__FUNCTION__] = getConfig('check_double_email');
2587 // Return cached entry
2588 return $GLOBALS[__FUNCTION__];
2591 // Checks wether 'check_double_email' is 'Y'
2592 function isCheckDoubleEmailEnabled () {
2593 // Is the cache entry set?
2594 if (!isset($GLOBALS[__FUNCTION__])) {
2595 // No, so determine it
2596 $GLOBALS[__FUNCTION__] = (getCheckDoubleEmail() == 'Y');
2599 // Return cached entry
2600 return $GLOBALS[__FUNCTION__];