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, 2010 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 remote IP number
198 function detectRemoteAddr () {
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 hostname
213 function detectRemoteHostname () {
214 // Get remote ip from environment
215 $remoteHost = getenv('REMOTE_HOST');
217 // Is removeip installed?
218 if (isExtensionActive('removeip')) {
220 $remoteHost = getAnonymousRemoteHost($remoteHost);
227 // "Getter" for user agent
228 function detectUserAgent ($alwaysReal = false) {
229 // Get remote ip from environment
230 $userAgent = getenv('HTTP_USER_AGENT');
232 // Is removeip installed?
233 if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
235 $userAgent = getAnonymousUserAgent($userAgent);
242 // "Getter" for referer
243 function detectReferer () {
244 // Get remote ip from environment
245 $referer = getenv('HTTP_REFERER');
247 // Is removeip installed?
248 if (isExtensionActive('removeip')) {
250 $referer = getAnonymousReferer($referer);
257 // "Getter" for request URI
258 function detectRequestUri () {
260 return (getenv('REQUEST_URI'));
263 // "Getter" for query string
264 function detectQueryString () {
265 return str_replace('&', '&', (getenv('QUERY_STRING')));
268 // "Getter" for SERVER_NAME
269 function detectServerName () {
271 return (getenv('SERVER_NAME'));
274 // Check wether we are installing
275 function isInstalling () {
276 // Determine wether we are installing
277 if (!isset($GLOBALS['mailer_installing'])) {
278 // Check URL (css.php/js.php need this)
279 $GLOBALS['mailer_installing'] = isGetRequestParameterSet('installing');
283 return $GLOBALS['mailer_installing'];
286 // Check wether this script is installed
287 function isInstalled () {
289 if (!isset($GLOBALS[__FUNCTION__])) {
290 // Determine wether this script is installed
291 $GLOBALS[__FUNCTION__] = (
296 isConfigEntrySet('MXCHANGE_INSTALLED')
298 getConfig('MXCHANGE_INSTALLED') == 'Y'
302 // New config file found and loaded
303 isIncludeReadable(getCachePath() . 'config-local.php')
306 // New config file found, but not yet read
307 isIncludeReadable(getCachePath() . 'config-local.php')
310 // Only new config file is found
311 !isIncludeReadable('inc/config.php')
313 // Is installation mode
320 // Then use the cache
321 return $GLOBALS[__FUNCTION__];
324 // Check wether an admin is registered
325 function isAdminRegistered () {
327 if (!isset($GLOBALS[__FUNCTION__])) {
329 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
333 return $GLOBALS[__FUNCTION__];
336 // Checks wether the reset mode is active
337 function isResetModeEnabled () {
338 // Now simply check it
339 return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
342 // Checks wether the debug mode is enabled
343 function isDebugModeEnabled () {
345 if (!isset($GLOBALS[__FUNCTION__])) {
347 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
351 return $GLOBALS[__FUNCTION__];
354 // Checks wether SQL debugging is enabled
355 function isSqlDebuggingEnabled () {
357 if (!isset($GLOBALS[__FUNCTION__])) {
358 // Determine if SQL debugging is enabled
359 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
363 return $GLOBALS[__FUNCTION__];
366 // Checks wether we shall debug regular expressions
367 function isDebugRegularExpressionEnabled () {
369 if (!isset($GLOBALS[__FUNCTION__])) {
371 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
375 return $GLOBALS[__FUNCTION__];
378 // Checks wether the cache instance is valid
379 function isCacheInstanceValid () {
380 return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
383 // Copies a file from source to destination and verifies if that goes fine.
384 // This function should wrap the copy() command and make a nicer debug backtrace
385 // even if there is no xdebug extension installed.
386 function copyFileVerified ($source, $dest, $chmod = '') {
387 // Failed is the default
390 // Is the source file there?
391 if (!isFileReadable($source)) {
393 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
396 // Is the target directory there?
397 if (!isDirectory(dirname($dest))) {
399 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
402 // Now try to copy it
403 if (!copy($source, $dest)) {
404 // Something went wrong
405 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
408 $GLOBALS['file_readable'][$dest] = true;
411 // If there are chmod rights set, apply them
412 if (!empty($chmod)) {
414 $status = changeMode($dest, $chmod);
424 // Wrapper function for header()
425 // Send a header but checks before if we can do so
426 function sendHeader ($header) {
428 //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header);
429 $GLOBALS['header'][] = trim($header);
432 // Flushes all headers
433 function flushHeaders () {
434 // Is the header already sent?
435 if (headers_sent()) {
437 debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!');
440 // Flush all headers if found
441 if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) {
442 foreach ($GLOBALS['header'] as $header) {
447 // Mark them as flushed
448 $GLOBALS['header'] = array();
451 // Wrapper function for chmod()
452 // @TODO Do some more sanity check here
453 function changeMode ($FQFN, $mode) {
454 // Is the file/directory there?
455 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
456 // Neither, so abort here
457 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
461 return chmod($FQFN, $mode);
464 // Wrapper for unlink()
465 function removeFile ($FQFN) {
466 // Is the file there?
467 if (isFileReadable($FQFN)) {
469 $GLOBALS['file_readable'][$FQFN] = false;
472 return unlink($FQFN);
475 // All fine if no file was removed. If we change this to 'false' or rewrite
476 // above if() block it would be to restrictive.
480 // Wrapper for $_POST['sel']
481 function countPostSelection ($element = 'sel') {
483 if (isPostRequestParameterSet($element)) {
484 // Return counted elements
485 return countSelection(postRequestParameter($element));
487 // Return zero if not found
492 // Checks wether the config-local.php is loaded
493 function isConfigLocalLoaded () {
494 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
497 // Checks wether a nickname or userid was entered and caches the result
498 function isNicknameUsed ($userid) {
499 // Is the cache there
500 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
502 $GLOBALS[__FUNCTION__][$userid] = (('' . round($userid) . '') != $userid);
506 return $GLOBALS[__FUNCTION__][$userid];
509 // Getter for 'what' value
510 function getWhat () {
515 if (isWhatSet(true)) {
517 $what = $GLOBALS['what'];
524 // Setter for 'what' value
525 function setWhat ($newWhat) {
526 $GLOBALS['what'] = SQL_ESCAPE($newWhat);
529 // Setter for 'what' from configuration
530 function setWhatFromConfig ($configEntry) {
531 // Get 'what' from config
532 $what = getConfig($configEntry);
538 // Checks wether what is set and optionally aborts on miss
539 function isWhatSet ($strict = false) {
541 $isset = isset($GLOBALS['what']);
543 // Should we abort here?
544 if (($strict === true) && ($isset === false)) {
546 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
553 // Getter for 'action' value
554 function getAction ($strict = true) {
559 if (isActionSet(($strict) && (isHtmlOutputMode()))) {
561 $action = $GLOBALS['action'];
568 // Setter for 'action' value
569 function setAction ($newAction) {
570 $GLOBALS['action'] = SQL_ESCAPE($newAction);
573 // Checks wether action is set and optionally aborts on miss
574 function isActionSet ($strict = false) {
576 $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action'])));
578 // Should we abort here?
579 if (($strict === true) && ($isset === false)) {
581 debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.');
588 // Getter for 'module' value
589 function getModule ($strict = true) {
594 if (isModuleSet($strict)) {
596 $module = $GLOBALS['module'];
603 // Setter for 'module' value
604 function setModule ($newModule) {
605 // Secure it and make all modules lower-case
606 $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
609 // Checks wether module is set and optionally aborts on miss
610 function isModuleSet ($strict = false) {
612 $isset = (!empty($GLOBALS['module']));
614 // Should we abort here?
615 if (($strict === true) && ($isset === false)) {
617 debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.');
621 return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
624 // Getter for 'output_mode' value
625 function getScriptOutputMode () {
630 if (isOutputModeSet(true)) {
632 $output_mode = $GLOBALS['output_mode'];
639 // Setter for 'output_mode' value
640 function setOutputMode ($newOutputMode) {
641 $GLOBALS['output_mode'] = (int) $newOutputMode;
644 // Checks wether output_mode is set and optionally aborts on miss
645 function isOutputModeSet ($strict = false) {
647 $isset = (isset($GLOBALS['output_mode']));
649 // Should we abort here?
650 if (($strict === true) && ($isset === false)) {
652 debug_report_bug(__FUNCTION__, __LINE__, 'Output_mode is empty.');
659 // Enables block-mode
660 function enableBlockMode ($enabled = true) {
661 $GLOBALS['block_mode'] = $enabled;
664 // Checks wether block-mode is enabled
665 function isBlockModeEnabled () {
667 if (!isset($GLOBALS['block_mode'])) {
669 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
673 return $GLOBALS['block_mode'];
676 // Wrapper function for addPointsThroughReferalSystem()
677 function addPointsDirectly ($subject, $userid, $points) {
679 unset($GLOBALS['ref_level']);
681 // Call more complicated method (due to more parameters)
682 return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, 'direct');
685 // Wrapper for redirectToUrl but URL comes from a configuration entry
686 function redirectToConfiguredUrl ($configEntry) {
688 redirectToUrl(getConfig($configEntry));
691 // Wrapper function to redirect from member-only modules to index
692 function redirectToIndexMemberOnlyModule () {
693 // Do the redirect here
694 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
697 // Wrapper function to redirect to current URL
698 function redirectToRequestUri () {
699 redirectToUrl(basename(detectRequestUri()));
702 // Wrapper function to redirect to de-refered URL
703 function redirectToDereferedUrl ($URL) {
705 redirectToUrl(generateDerefererUrl($URL));
708 // Wrapper function for checking if extension is installed and newer or same version
709 function isExtensionInstalledAndNewer ($ext_name, $version) {
710 // Is an cache entry found?
711 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
713 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
715 // Cache hits should be incremented twice
716 incrementStatsEntry('cache_hits', 2);
720 //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'=>'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
721 return $GLOBALS[__FUNCTION__][$ext_name][$version];
724 // Wrapper function for checking if extension is installed and older than given version
725 function isExtensionInstalledAndOlder ($ext_name, $version) {
726 // Is an cache entry found?
727 if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
729 $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
731 // Cache hits should be incremented twice
732 incrementStatsEntry('cache_hits', 2);
736 //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'<'.$version.':'.intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
737 return $GLOBALS[__FUNCTION__][$ext_name][$version];
741 function setUsername ($userName) {
742 $GLOBALS['username'] = (string) $userName;
746 function getUsername () {
748 if (!isset($GLOBALS['username'])) {
749 // No, so it has to be a guest
750 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
754 return $GLOBALS['username'];
757 // Wrapper function for installation phase
758 function isInstallationPhase () {
760 if (!isset($GLOBALS[__FUNCTION__])) {
762 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
766 return $GLOBALS[__FUNCTION__];
769 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
770 function isDemoModeActive () {
772 if (!isset($GLOBALS[__FUNCTION__])) {
774 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
778 return $GLOBALS[__FUNCTION__];
781 // Getter for PHP caching value
782 function getPhpCaching () {
783 return $GLOBALS['php_caching'];
786 // Checks wether the admin hash is set
787 function isAdminHashSet ($adminId) {
788 // Is the array there?
789 if (!isset($GLOBALS['cache_array']['admin'])) {
790 // Missing array should be reported
791 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
794 // Check for admin hash
795 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
798 // Setter for admin hash
799 function setAdminHash ($adminId, $hash) {
800 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
803 // Getter for current admin login
804 function getCurrentAdminLogin () {
806 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
809 if (!isset($GLOBALS[__FUNCTION__])) {
811 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
815 return $GLOBALS[__FUNCTION__];
818 // Setter for admin id (and current)
819 function setAdminId ($adminId) {
821 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
824 $status = setSession('admin_id', bigintval($adminId));
827 setCurrentAdminId($adminId);
833 // Setter for admin_last
834 function setAdminLast ($adminLast) {
836 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
839 $status = setSession('admin_last', $adminLast);
845 // Setter for admin_md5
846 function setAdminMd5 ($adminMd5) {
848 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
851 $status = setSession('admin_md5', $adminMd5);
857 // Getter for admin_md5
858 function getAdminMd5 () {
860 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
863 return getSession('admin_md5');
866 // Init user data array
867 function initUserData () {
868 // User id should not be zero
869 if (!isValidUserId(getCurrentUserId())) {
870 // Should be always valid
871 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
875 $GLOBALS['user_data'][getCurrentUserId()] = array();
878 // Getter for user data
879 function getUserData ($column) {
880 // User id should not be zero
881 if (!isValidUserId(getCurrentUserId())) {
882 // Should be always valid
883 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
887 return $GLOBALS['user_data'][getCurrentUserId()][$column];
890 // Geter for whole user data array
891 function getUserDataArray () {
893 $userid = getCurrentUserId();
895 // Is the current userid valid?
896 if (!isValidUserId($userid)) {
897 // Should be always valid
898 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
901 // Get the whole array if found
902 if (isset($GLOBALS['user_data'][$userid])) {
903 // Found, so return it
904 return $GLOBALS['user_data'][$userid];
906 // Return empty array
911 // Checks if the user data is valid, this may indicate that the user has logged
912 // in, but you should use isMember() if you want to find that out.
913 function isUserDataValid () {
914 // User id should not be zero so abort here
915 if (!isCurrentUserIdSet()) return false;
918 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
920 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
924 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
927 // Setter for current userid
928 function setCurrentUserId ($userid) {
930 $GLOBALS['current_userid'] = bigintval($userid);
932 // Unset it to re-determine the actual state
933 unset($GLOBALS['is_userdata_valid'][$userid]);
936 // Getter for current userid
937 function getCurrentUserId () {
938 // Userid must be set before it can be used
939 if (!isCurrentUserIdSet()) {
941 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
945 return $GLOBALS['current_userid'];
948 // Checks if current userid is set
949 function isCurrentUserIdSet () {
950 return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
953 // Checks wether we are debugging template cache
954 function isDebuggingTemplateCache () {
956 if (!isset($GLOBALS[__FUNCTION__])) {
958 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
962 return $GLOBALS[__FUNCTION__];
965 // Wrapper for fetchUserData() and getUserData() calls
966 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
968 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
969 // Default is 'guest'
970 $data = '{--USERNAME_GUEST--}';
972 // Can we fetch the user data?
973 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
974 // Now get the data back
975 $data = getUserData($valueColumn);
979 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
983 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
986 // Wrapper for strpos() to ease porting from deprecated ereg() function
987 function isInString ($needle, $haystack) {
988 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
989 return (strpos($haystack, $needle) !== false);
992 // Wrapper for strpos() to ease porting from deprecated eregi() function
993 // This function is case-insensitive
994 function isInStringIgnoreCase ($needle, $haystack) {
995 return (isInString(strtolower($needle), strtolower($haystack)));
998 // Wrapper to check for if fatal errors where detected
999 function ifFatalErrorsDetected () {
1000 // Just call the inner function
1001 return (getTotalFatalErrors() > 0);
1004 // Setter for HTTP status
1005 function setHttpStatus ($status) {
1006 $GLOBALS['http_status'] = (string) $status;
1009 // Getter for HTTP status
1010 function getHttpStatus () {
1011 // Is the status set?
1012 if (!isset($GLOBALS['http_status'])) {
1014 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1018 return $GLOBALS['http_status'];
1022 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1023 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1025 * ----------------------------------------------------------------------------
1026 * If you want to redirect, please use redirectToUrl(); instead
1027 * ----------------------------------------------------------------------------
1029 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1031 * @link http://support.microsoft.com/kb/q176113/
1032 * @author Andreas Gohr <andi@splitbrain.org>
1035 function sendRawRedirect ($url) {
1036 // Send helping header
1037 setHttpStatus('302 Found');
1039 // always close the session
1040 session_write_close();
1042 // Revert entity &
1043 $url = str_replace('&', '&', $url);
1045 // check if running on IIS < 6 with CGI-PHP
1046 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1047 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
1048 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1049 ($matches[1] < 6)) {
1050 // Send the IIS header
1051 sendHeader('Refresh: 0;url=' . $url);
1053 // Send generic header
1054 sendHeader('Location: ' . $url);
1061 // Determines the country of the given user id
1062 function determineCountry ($userid) {
1063 // Do we have cache?
1064 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1065 // Default is 'invalid'
1066 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1068 // Is extension country active?
1069 if (isExtensionActive('country')) {
1070 // Determine the right country code through the country id
1071 $id = getUserData('country_code');
1073 // Then handle it over
1074 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1076 // Get raw code from user data
1077 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1082 return $GLOBALS[__FUNCTION__][$userid];
1085 // "Getter" for total confirmed user accounts
1086 function getTotalConfirmedUser () {
1088 if (!isset($GLOBALS[__FUNCTION__])) {
1090 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1093 // Return cached value
1094 return $GLOBALS[__FUNCTION__];
1097 // "Getter" for total unconfirmed user accounts
1098 function getTotalUnconfirmedUser () {
1100 if (!isset($GLOBALS[__FUNCTION__])) {
1102 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1105 // Return cached value
1106 return $GLOBALS[__FUNCTION__];
1109 // "Getter" for total locked user accounts
1110 function getTotalLockedUser () {
1112 if (!isset($GLOBALS[__FUNCTION__])) {
1114 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1117 // Return cached value
1118 return $GLOBALS[__FUNCTION__];
1121 // Is given userid valid?
1122 function isValidUserId ($userid) {
1123 // Do we have cache?
1124 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1126 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1130 return $GLOBALS[__FUNCTION__][$userid];
1134 function encodeEntities ($str) {
1136 $str = secureString($str, true, true);
1138 // Encode dollar sign as well
1139 $str = str_replace('$', '$', $str);
1145 // "Getter" for date from patch_ctime
1146 function getDateFromPatchTime () {
1148 if (!isset($GLOBALS[__FUNCTION__])) {
1150 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1154 return $GLOBALS[__FUNCTION__];
1157 // Getter for current year (default)
1158 function getYear ($timestamp = null) {
1160 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1162 if (is_null($timestamp)) $timestamp = time();
1165 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1169 return $GLOBALS[__FUNCTION__][$timestamp];
1172 // Getter for current month (default)
1173 function getMonth ($timestamp = null) {
1175 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1176 // If null is set, use time()
1177 if (is_null($timestamp)) {
1178 // Use time() which is current timestamp
1179 $timestamp = time();
1183 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1187 return $GLOBALS[__FUNCTION__][$timestamp];
1190 // Getter for current day (default)
1191 function getDay ($timestamp = null) {
1193 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1195 if (is_null($timestamp)) $timestamp = time();
1198 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1202 return $GLOBALS[__FUNCTION__][$timestamp];
1205 // Getter for current week (default)
1206 function getWeek ($timestamp = null) {
1208 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1210 if (is_null($timestamp)) $timestamp = time();
1213 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1217 return $GLOBALS[__FUNCTION__][$timestamp];
1220 // Getter for current short_hour (default)
1221 function getShortHour ($timestamp = null) {
1223 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1225 if (is_null($timestamp)) $timestamp = time();
1228 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1232 return $GLOBALS[__FUNCTION__][$timestamp];
1235 // Getter for current long_hour (default)
1236 function getLongHour ($timestamp = null) {
1238 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1240 if (is_null($timestamp)) $timestamp = time();
1243 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1247 return $GLOBALS[__FUNCTION__][$timestamp];
1250 // Getter for current second (default)
1251 function getSecond ($timestamp = null) {
1253 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1255 if (is_null($timestamp)) $timestamp = time();
1258 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1262 return $GLOBALS[__FUNCTION__][$timestamp];
1265 // Getter for current minute (default)
1266 function getMinute ($timestamp = null) {
1268 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1270 if (is_null($timestamp)) $timestamp = time();
1273 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1277 return $GLOBALS[__FUNCTION__][$timestamp];
1280 // Checks wether the title decoration is enabled
1281 function isTitleDecorationEnabled () {
1282 // Do we have cache?
1283 if (!isset($GLOBALS[__FUNCTION__])) {
1285 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1289 return $GLOBALS[__FUNCTION__];
1292 // Checks wether filter usage updates are enabled (expensive queries!)
1293 function isFilterUsageUpdateEnabled () {
1294 // Do we have cache?
1295 if (!isset($GLOBALS[__FUNCTION__])) {
1297 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1301 return $GLOBALS[__FUNCTION__];
1304 // Checks wether debugging of weekly resets is enabled
1305 function isWeeklyResetDebugEnabled () {
1306 // Do we have cache?
1307 if (!isset($GLOBALS[__FUNCTION__])) {
1309 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1313 return $GLOBALS[__FUNCTION__];
1316 // Checks wether debugging of monthly resets is enabled
1317 function isMonthlyResetDebugEnabled () {
1318 // Do we have cache?
1319 if (!isset($GLOBALS[__FUNCTION__])) {
1321 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1325 return $GLOBALS[__FUNCTION__];
1328 // Checks wether displaying of debug SQLs are enabled
1329 function isDisplayDebugSqlEnabled () {
1330 // Do we have cache?
1331 if (!isset($GLOBALS[__FUNCTION__])) {
1333 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1337 return $GLOBALS[__FUNCTION__];
1340 // Checks wether module title is enabled
1341 function isModuleTitleEnabled () {
1342 // Do we have cache?
1343 if (!isset($GLOBALS[__FUNCTION__])) {
1345 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1349 return $GLOBALS[__FUNCTION__];
1352 // Checks wether what title is enabled
1353 function isWhatTitleEnabled () {
1354 // Do we have cache?
1355 if (!isset($GLOBALS[__FUNCTION__])) {
1357 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1361 return $GLOBALS[__FUNCTION__];
1364 // Checks wether stats are enabled
1365 function ifStatsAreEnabled () {
1366 // Do we have cache?
1367 if (!isset($GLOBALS[__FUNCTION__])) {
1368 // Then determine it
1369 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1372 // Return cached value
1373 return $GLOBALS[__FUNCTION__];
1376 // Checks wether admin-notification of certain user actions is enabled
1377 function isAdminNotificationEnabled () {
1378 // Do we have cache?
1379 if (!isset($GLOBALS[__FUNCTION__])) {
1381 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1385 return $GLOBALS[__FUNCTION__];
1388 // Checks wether random referal id selection is enabled
1389 function isRandomReferalIdEnabled () {
1390 // Do we have cache?
1391 if (!isset($GLOBALS[__FUNCTION__])) {
1393 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1397 return $GLOBALS[__FUNCTION__];
1400 // "Getter" for default language
1401 function getDefaultLanguage () {
1402 // Do we have cache?
1403 if (!isset($GLOBALS[__FUNCTION__])) {
1405 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1409 return $GLOBALS[__FUNCTION__];
1412 // "Getter" for default referal id
1413 function getDefRefid () {
1414 // Do we have cache?
1415 if (!isset($GLOBALS[__FUNCTION__])) {
1417 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1421 return $GLOBALS[__FUNCTION__];
1424 // "Getter" for path
1425 function getPath () {
1426 // Do we have cache?
1427 if (!isset($GLOBALS[__FUNCTION__])) {
1429 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1433 return $GLOBALS[__FUNCTION__];
1437 function getUrl () {
1438 // Do we have cache?
1439 if (!isset($GLOBALS[__FUNCTION__])) {
1441 $GLOBALS[__FUNCTION__] = getConfig('URL');
1445 return $GLOBALS[__FUNCTION__];
1448 // "Getter" for cache_path
1449 function getCachePath () {
1450 // Do we have cache?
1451 if (!isset($GLOBALS[__FUNCTION__])) {
1453 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1457 return $GLOBALS[__FUNCTION__];
1460 // "Getter" for secret_key
1461 function getSecretKey () {
1462 // Do we have cache?
1463 if (!isset($GLOBALS[__FUNCTION__])) {
1465 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1469 return $GLOBALS[__FUNCTION__];
1472 // "Getter" for master_salt
1473 function getMasterSalt () {
1474 // Do we have cache?
1475 if (!isset($GLOBALS[__FUNCTION__])) {
1477 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1481 return $GLOBALS[__FUNCTION__];
1484 // "Getter" for prime
1485 function getPrime () {
1486 // Do we have cache?
1487 if (!isset($GLOBALS[__FUNCTION__])) {
1489 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1493 return $GLOBALS[__FUNCTION__];
1496 // "Getter" for encrypt_seperator
1497 function getEncryptSeperator () {
1498 // Do we have cache?
1499 if (!isset($GLOBALS[__FUNCTION__])) {
1501 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1505 return $GLOBALS[__FUNCTION__];
1508 // "Getter" for mysql_prefix
1509 function getMysqlPrefix () {
1510 // Do we have cache?
1511 if (!isset($GLOBALS[__FUNCTION__])) {
1513 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1517 return $GLOBALS[__FUNCTION__];
1520 // "Getter" for table_type
1521 function getTableType () {
1522 // Do we have cache?
1523 if (!isset($GLOBALS[__FUNCTION__])) {
1525 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1529 return $GLOBALS[__FUNCTION__];
1532 // "Getter" for salt_length
1533 function getSaltLength () {
1534 // Do we have cache?
1535 if (!isset($GLOBALS[__FUNCTION__])) {
1537 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1541 return $GLOBALS[__FUNCTION__];
1544 // "Getter" for output_mode
1545 function getOutputMode () {
1546 // Do we have cache?
1547 if (!isset($GLOBALS[__FUNCTION__])) {
1549 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1553 return $GLOBALS[__FUNCTION__];
1556 // "Getter" for full_version
1557 function getFullVersion () {
1558 // Do we have cache?
1559 if (!isset($GLOBALS[__FUNCTION__])) {
1561 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1565 return $GLOBALS[__FUNCTION__];
1568 // "Getter" for title
1569 function getTitle () {
1570 // Do we have cache?
1571 if (!isset($GLOBALS[__FUNCTION__])) {
1573 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1577 return $GLOBALS[__FUNCTION__];
1580 // "Getter" for curr_svn_revision
1581 function getCurrentRepositoryRevision () {
1582 // Do we have cache?
1583 if (!isset($GLOBALS[__FUNCTION__])) {
1585 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1589 return $GLOBALS[__FUNCTION__];
1592 // "Getter" for server_url
1593 function getServerUrl () {
1594 // Do we have cache?
1595 if (!isset($GLOBALS[__FUNCTION__])) {
1597 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1601 return $GLOBALS[__FUNCTION__];
1604 // "Getter" for mt_word
1605 function getMtWord () {
1606 // Do we have cache?
1607 if (!isset($GLOBALS[__FUNCTION__])) {
1609 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1613 return $GLOBALS[__FUNCTION__];
1616 // "Getter" for mt_word2
1617 function getMtWord2 () {
1618 // Do we have cache?
1619 if (!isset($GLOBALS[__FUNCTION__])) {
1621 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1625 return $GLOBALS[__FUNCTION__];
1628 // "Getter" for main_title
1629 function getMainTitle () {
1630 // Do we have cache?
1631 if (!isset($GLOBALS[__FUNCTION__])) {
1633 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1637 return $GLOBALS[__FUNCTION__];
1640 // "Getter" for file_hash
1641 function getFileHash () {
1642 // Do we have cache?
1643 if (!isset($GLOBALS[__FUNCTION__])) {
1645 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1649 return $GLOBALS[__FUNCTION__];
1652 // "Getter" for pass_scramble
1653 function getPassScramble () {
1654 // Do we have cache?
1655 if (!isset($GLOBALS[__FUNCTION__])) {
1657 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1661 return $GLOBALS[__FUNCTION__];
1664 // "Getter" for ap_inactive_since
1665 function getApInactiveSince () {
1666 // Do we have cache?
1667 if (!isset($GLOBALS[__FUNCTION__])) {
1669 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1673 return $GLOBALS[__FUNCTION__];
1676 // "Getter" for user_min_confirmed
1677 function getUserMinConfirmed () {
1678 // Do we have cache?
1679 if (!isset($GLOBALS[__FUNCTION__])) {
1681 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1685 return $GLOBALS[__FUNCTION__];
1688 // "Getter" for auto_purge
1689 function getAutoPurge () {
1690 // Do we have cache?
1691 if (!isset($GLOBALS[__FUNCTION__])) {
1693 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1697 return $GLOBALS[__FUNCTION__];
1700 // "Getter" for bonus_userid
1701 function getBonusUserid () {
1702 // Do we have cache?
1703 if (!isset($GLOBALS[__FUNCTION__])) {
1705 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1709 return $GLOBALS[__FUNCTION__];
1712 // "Getter" for ap_inactive_time
1713 function getApInactiveTime () {
1714 // Do we have cache?
1715 if (!isset($GLOBALS[__FUNCTION__])) {
1717 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1721 return $GLOBALS[__FUNCTION__];
1724 // "Getter" for ap_dm_timeout
1725 function getApDmTimeout () {
1726 // Do we have cache?
1727 if (!isset($GLOBALS[__FUNCTION__])) {
1729 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1733 return $GLOBALS[__FUNCTION__];
1736 // "Getter" for ap_tasks_time
1737 function getApTasksTime () {
1738 // Do we have cache?
1739 if (!isset($GLOBALS[__FUNCTION__])) {
1741 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1745 return $GLOBALS[__FUNCTION__];
1748 // "Getter" for ap_unconfirmed_time
1749 function getApUnconfirmedTime () {
1750 // Do we have cache?
1751 if (!isset($GLOBALS[__FUNCTION__])) {
1753 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1757 return $GLOBALS[__FUNCTION__];
1760 // "Getter" for points
1761 function getPoints () {
1762 // Do we have cache?
1763 if (!isset($GLOBALS[__FUNCTION__])) {
1765 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1769 return $GLOBALS[__FUNCTION__];
1772 // "Getter" for slogan
1773 function getSlogan () {
1774 // Do we have cache?
1775 if (!isset($GLOBALS[__FUNCTION__])) {
1777 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1781 return $GLOBALS[__FUNCTION__];
1784 // "Getter" for copy
1785 function getCopy () {
1786 // Do we have cache?
1787 if (!isset($GLOBALS[__FUNCTION__])) {
1789 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1793 return $GLOBALS[__FUNCTION__];
1796 // "Getter" for webmaster
1797 function getWebmaster () {
1798 // Do we have cache?
1799 if (!isset($GLOBALS[__FUNCTION__])) {
1801 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1805 return $GLOBALS[__FUNCTION__];
1808 // "Getter" for sql_count
1809 function getSqlCount () {
1810 // Do we have cache?
1811 if (!isset($GLOBALS[__FUNCTION__])) {
1813 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1817 return $GLOBALS[__FUNCTION__];
1820 // "Getter" for num_templates
1821 function getNumTemplates () {
1822 // Do we have cache?
1823 if (!isset($GLOBALS[__FUNCTION__])) {
1825 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1829 return $GLOBALS[__FUNCTION__];
1832 // "Getter" for dns_cache_timeout
1833 function getDnsCacheTimeout () {
1834 // Do we have cache?
1835 if (!isset($GLOBALS[__FUNCTION__])) {
1837 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1841 return $GLOBALS[__FUNCTION__];
1844 // "Getter" for menu_blur_spacer
1845 function getMenuBlurSpacer () {
1846 // Do we have cache?
1847 if (!isset($GLOBALS[__FUNCTION__])) {
1849 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
1853 return $GLOBALS[__FUNCTION__];
1856 // "Getter" for points_register
1857 function getPointsRegister () {
1858 // Do we have cache?
1859 if (!isset($GLOBALS[__FUNCTION__])) {
1861 $GLOBALS[__FUNCTION__] = getConfig('points_register');
1865 return $GLOBALS[__FUNCTION__];
1868 // "Getter" for points_ref
1869 function getPointsRef () {
1870 // Do we have cache?
1871 if (!isset($GLOBALS[__FUNCTION__])) {
1873 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
1877 return $GLOBALS[__FUNCTION__];
1880 // "Getter" for ref_payout
1881 function getRefPayout () {
1882 // Do we have cache?
1883 if (!isset($GLOBALS[__FUNCTION__])) {
1885 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
1889 return $GLOBALS[__FUNCTION__];
1892 // "Getter" for online_timeout
1893 function getOnlineTimeout () {
1894 // Do we have cache?
1895 if (!isset($GLOBALS[__FUNCTION__])) {
1897 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
1901 return $GLOBALS[__FUNCTION__];
1904 // "Getter" for index_home
1905 function getIndexHome () {
1906 // Do we have cache?
1907 if (!isset($GLOBALS[__FUNCTION__])) {
1909 $GLOBALS[__FUNCTION__] = getConfig('index_home');
1913 return $GLOBALS[__FUNCTION__];
1916 // "Getter" for one_day
1917 function getOneDay () {
1918 // Do we have cache?
1919 if (!isset($GLOBALS[__FUNCTION__])) {
1921 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
1925 return $GLOBALS[__FUNCTION__];
1928 // "Getter" for activate_xchange
1929 function getActivateXchange () {
1930 // Do we have cache?
1931 if (!isset($GLOBALS[__FUNCTION__])) {
1933 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
1937 return $GLOBALS[__FUNCTION__];
1940 // "Getter" for img_type
1941 function getImgType () {
1942 // Do we have cache?
1943 if (!isset($GLOBALS[__FUNCTION__])) {
1945 $GLOBALS[__FUNCTION__] = getConfig('img_type');
1949 return $GLOBALS[__FUNCTION__];
1952 // "Getter" for code_length
1953 function getCodeLength () {
1954 // Do we have cache?
1955 if (!isset($GLOBALS[__FUNCTION__])) {
1957 $GLOBALS[__FUNCTION__] = getConfig('code_length');
1961 return $GLOBALS[__FUNCTION__];
1964 // "Getter" for least_cats
1965 function getLeastCats () {
1966 // Do we have cache?
1967 if (!isset($GLOBALS[__FUNCTION__])) {
1969 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
1973 return $GLOBALS[__FUNCTION__];
1976 // "Getter" for pass_len
1977 function getPassLen () {
1978 // Do we have cache?
1979 if (!isset($GLOBALS[__FUNCTION__])) {
1981 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
1985 return $GLOBALS[__FUNCTION__];
1988 // "Getter" for admin_menu
1989 function getAdminMenu () {
1990 // Do we have cache?
1991 if (!isset($GLOBALS[__FUNCTION__])) {
1993 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
1997 return $GLOBALS[__FUNCTION__];
2000 // "Getter" for last_month
2001 function getLastMonth () {
2002 // Do we have cache?
2003 if (!isset($GLOBALS[__FUNCTION__])) {
2005 $GLOBALS[__FUNCTION__] = getConfig('last_month');
2009 return $GLOBALS[__FUNCTION__];
2012 // "Getter" for max_send
2013 function getMaxSend () {
2014 // Do we have cache?
2015 if (!isset($GLOBALS[__FUNCTION__])) {
2017 $GLOBALS[__FUNCTION__] = getConfig('max_send');
2021 return $GLOBALS[__FUNCTION__];
2024 // "Getter" for __DB_NAME
2025 function getDbName () {
2026 // Do we have cache?
2027 if (!isset($GLOBALS[__FUNCTION__])) {
2029 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2033 return $GLOBALS[__FUNCTION__];
2036 // Checks wether proxy configuration is used
2037 function isProxyUsed () {
2038 // Do we have cache?
2039 if (!isset($GLOBALS[__FUNCTION__])) {
2041 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2045 return $GLOBALS[__FUNCTION__];
2048 // Checks wether POST data contains selections
2049 function ifPostContainsSelections ($element = 'sel') {
2050 // Do we have cache?
2051 if (!isset($GLOBALS[__FUNCTION__][$element])) {
2053 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
2057 return $GLOBALS[__FUNCTION__][$element];
2060 // Checks wether verbose_sql is Y and returns true/false if so
2061 function isVerboseSqlEnabled () {
2062 // Do we have cache?
2063 if (!isset($GLOBALS[__FUNCTION__])) {
2065 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2069 return $GLOBALS[__FUNCTION__];
2072 // "Getter" for total user points
2073 function getTotalPoints ($userid) {
2074 // Do we have cache?
2075 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2077 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points');
2081 return $GLOBALS[__FUNCTION__][$userid];
2084 // Wrapper to check if url_blacklist is enabled
2085 function isUrlBlacklistEnabled () {
2086 // Do we have cache?
2087 if (!isset($GLOBALS[__FUNCTION__])) {
2089 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2093 return $GLOBALS[__FUNCTION__];
2096 // Checks wether direct payment is allowed in configuration
2097 function isDirectPaymentEnabled () {
2098 // Do we have cache?
2099 if (!isset($GLOBALS[__FUNCTION__])) {
2101 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2105 return $GLOBALS[__FUNCTION__];
2108 // Wrapper to check if current task is for extension (not update)
2109 function isExtensionTask ($content) {
2110 // Do we have cache?
2111 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2113 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2117 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2120 // Wrapper to check if output mode is CSS
2121 function isCssOutputMode () {
2123 return (getScriptOutputMode() == 1);
2126 // Wrapper to check if output mode is HTML
2127 function isHtmlOutputMode () {
2129 return (getScriptOutputMode() == 0);
2132 // Wrapper to check if output mode is RAW
2133 function isRawOutputMode () {
2135 return (getScriptOutputMode() == -1);
2138 // Wrapper to generate a user email link
2139 function generateWrappedUserEmailLink ($email) {
2140 // Just call the inner function
2141 return generateEmailLink($email, 'user_data');
2144 // Wrapper to check if user points are locked
2145 function ifUserPointsLocked ($userid) {
2146 // Do we have cache?
2147 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2149 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2153 return $GLOBALS[__FUNCTION__][$userid];
2156 // Appends a line to an existing file or creates it instantly with given content.
2157 // This function does always add a new-line character to every line.
2158 function appendLineToFile ($file, $line) {
2159 $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2160 fwrite($fp, $line . "\n");
2164 // Wrapper for changeDataInFile() but with full path added
2165 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2167 $FQFN = getPath() . $FQFN;
2169 // Call inner function
2170 changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);