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')) && (getAdminLogin(getSession('admin_id')) == '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 // Init user data array
804 function initUserData () {
805 // User id should not be zero
806 if (!isValidUserId(getCurrentUserId())) {
807 // Should be always valid
808 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
812 $GLOBALS['user_data'][getCurrentUserId()] = array();
815 // Getter for user data
816 function getUserData ($column) {
817 // User id should not be zero
818 if (!isValidUserId(getCurrentUserId())) {
819 // Should be always valid
820 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
824 return $GLOBALS['user_data'][getCurrentUserId()][$column];
827 // Geter for whole user data array
828 function getUserDataArray () {
830 $userid = getCurrentUserId();
832 // Is the current userid valid?
833 if (!isValidUserId($userid)) {
834 // Should be always valid
835 debug_report_bug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
838 // Get the whole array if found
839 if (isset($GLOBALS['user_data'][$userid])) {
840 // Found, so return it
841 return $GLOBALS['user_data'][$userid];
843 // Return empty array
848 // Checks if the user data is valid, this may indicate that the user has logged
849 // in, but you should use isMember() if you want to find that out.
850 function isUserDataValid () {
851 // User id should not be zero so abort here
852 if (!isCurrentUserIdSet()) return false;
855 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
857 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
861 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
864 // Setter for current userid
865 function setCurrentUserId ($userid) {
867 $GLOBALS['current_userid'] = bigintval($userid);
869 // Unset it to re-determine the actual state
870 unset($GLOBALS['is_userdata_valid'][$userid]);
873 // Getter for current userid
874 function getCurrentUserId () {
875 // Userid must be set before it can be used
876 if (!isCurrentUserIdSet()) {
878 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
882 return $GLOBALS['current_userid'];
885 // Checks if current userid is set
886 function isCurrentUserIdSet () {
887 return ((isset($GLOBALS['current_userid'])) && (isValidUserId($GLOBALS['current_userid'])));
890 // Checks wether we are debugging template cache
891 function isDebuggingTemplateCache () {
893 if (!isset($GLOBALS[__FUNCTION__])) {
895 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
899 return $GLOBALS[__FUNCTION__];
902 // Wrapper for fetchUserData() and getUserData() calls
903 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
905 if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
906 // Default is 'guest'
907 $data = '{--USERNAME_GUEST--}';
909 // Can we fetch the user data?
910 if ((isValidUserId($userid)) && (fetchUserData($userid, $keyColumn))) {
911 // Now get the data back
912 $data = getUserData($valueColumn);
916 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
920 return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
923 // Wrapper for strpos() to ease porting from deprecated ereg() function
924 function isInString ($needle, $haystack) {
925 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
926 return (strpos($haystack, $needle) !== false);
929 // Wrapper for strpos() to ease porting from deprecated eregi() function
930 // This function is case-insensitive
931 function isInStringIgnoreCase ($needle, $haystack) {
932 return (isInString(strtolower($needle), strtolower($haystack)));
935 // Wrapper to check for if fatal errors where detected
936 function ifFatalErrorsDetected () {
937 // Just call the inner function
938 return (getTotalFatalErrors() > 0);
941 // Setter for HTTP status
942 function setHttpStatus ($status) {
943 $GLOBALS['http_status'] = (string) $status;
946 // Getter for HTTP status
947 function getHttpStatus () {
948 // Is the status set?
949 if (!isset($GLOBALS['http_status'])) {
951 debug_report_bug(__FUNCTION__, __LINE__, 'No HTTP status set!');
955 return $GLOBALS['http_status'];
959 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
960 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
962 * ----------------------------------------------------------------------------
963 * If you want to redirect, please use redirectToUrl(); instead
964 * ----------------------------------------------------------------------------
966 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
968 * @link http://support.microsoft.com/kb/q176113/
969 * @author Andreas Gohr <andi@splitbrain.org>
972 function sendRawRedirect ($url) {
973 // Send helping header
974 setHttpStatus('302 Found');
976 // always close the session
977 session_write_close();
979 // Revert entity &
980 $url = str_replace('&', '&', $url);
982 // check if running on IIS < 6 with CGI-PHP
983 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
984 (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
985 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
987 // Send the IIS header
988 sendHeader('Refresh: 0;url=' . $url);
990 // Send generic header
991 sendHeader('Location: ' . $url);
998 // Determines the country of the given user id
999 function determineCountry ($userid) {
1000 // Do we have cache?
1001 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1002 // Default is 'invalid'
1003 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1005 // Is extension country active?
1006 if (isExtensionActive('country')) {
1007 // Determine the right country code through the country id
1008 $id = getUserData('country_code');
1010 // Then handle it over
1011 $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1013 // Get raw code from user data
1014 $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1019 return $GLOBALS[__FUNCTION__][$userid];
1022 // "Getter" for total confirmed user accounts
1023 function getTotalConfirmedUser () {
1025 if (!isset($GLOBALS[__FUNCTION__])) {
1027 $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1030 // Return cached value
1031 return $GLOBALS[__FUNCTION__];
1034 // "Getter" for total unconfirmed user accounts
1035 function getTotalUnconfirmedUser () {
1037 if (!isset($GLOBALS[__FUNCTION__])) {
1039 $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
1042 // Return cached value
1043 return $GLOBALS[__FUNCTION__];
1046 // "Getter" for total locked user accounts
1047 function getTotalLockedUser () {
1049 if (!isset($GLOBALS[__FUNCTION__])) {
1051 $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true);
1054 // Return cached value
1055 return $GLOBALS[__FUNCTION__];
1058 // Is given userid valid?
1059 function isValidUserId ($userid) {
1060 // Do we have cache?
1061 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1063 $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1067 return $GLOBALS[__FUNCTION__][$userid];
1071 function encodeEntities ($str) {
1073 $str = secureString($str, true, true);
1075 // Encode dollar sign as well
1076 $str = str_replace('$', '$', $str);
1082 // "Getter" for date from patch_ctime
1083 function getDateFromPatchTime () {
1085 if (!isset($GLOBALS[__FUNCTION__])) {
1087 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1091 return $GLOBALS[__FUNCTION__];
1094 // Getter for current year (default)
1095 function getYear ($timestamp = null) {
1097 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1099 if (is_null($timestamp)) $timestamp = time();
1102 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1106 return $GLOBALS[__FUNCTION__][$timestamp];
1109 // Getter for current month (default)
1110 function getMonth ($timestamp = null) {
1112 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1113 // If null is set, use time()
1114 if (is_null($timestamp)) {
1115 // Use time() which is current timestamp
1116 $timestamp = time();
1120 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1124 return $GLOBALS[__FUNCTION__][$timestamp];
1127 // Getter for current day (default)
1128 function getDay ($timestamp = null) {
1130 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1132 if (is_null($timestamp)) $timestamp = time();
1135 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1139 return $GLOBALS[__FUNCTION__][$timestamp];
1142 // Getter for current week (default)
1143 function getWeek ($timestamp = null) {
1145 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1147 if (is_null($timestamp)) $timestamp = time();
1150 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1154 return $GLOBALS[__FUNCTION__][$timestamp];
1157 // Getter for current short_hour (default)
1158 function getShortHour ($timestamp = null) {
1160 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1162 if (is_null($timestamp)) $timestamp = time();
1165 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1169 return $GLOBALS[__FUNCTION__][$timestamp];
1172 // Getter for current long_hour (default)
1173 function getLongHour ($timestamp = null) {
1175 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1177 if (is_null($timestamp)) $timestamp = time();
1180 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1184 return $GLOBALS[__FUNCTION__][$timestamp];
1187 // Getter for current second (default)
1188 function getSecond ($timestamp = null) {
1190 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1192 if (is_null($timestamp)) $timestamp = time();
1195 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1199 return $GLOBALS[__FUNCTION__][$timestamp];
1202 // Getter for current minute (default)
1203 function getMinute ($timestamp = null) {
1205 if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1207 if (is_null($timestamp)) $timestamp = time();
1210 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1214 return $GLOBALS[__FUNCTION__][$timestamp];
1217 // Checks wether the title decoration is enabled
1218 function isTitleDecorationEnabled () {
1219 // Do we have cache?
1220 if (!isset($GLOBALS[__FUNCTION__])) {
1222 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1226 return $GLOBALS[__FUNCTION__];
1229 // Checks wether filter usage updates are enabled (expensive queries!)
1230 function isFilterUsageUpdateEnabled () {
1231 // Do we have cache?
1232 if (!isset($GLOBALS[__FUNCTION__])) {
1234 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1238 return $GLOBALS[__FUNCTION__];
1241 // Checks wether debugging of weekly resets is enabled
1242 function isWeeklyResetDebugEnabled () {
1243 // Do we have cache?
1244 if (!isset($GLOBALS[__FUNCTION__])) {
1246 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1250 return $GLOBALS[__FUNCTION__];
1253 // Checks wether debugging of monthly resets is enabled
1254 function isMonthlyResetDebugEnabled () {
1255 // Do we have cache?
1256 if (!isset($GLOBALS[__FUNCTION__])) {
1258 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1262 return $GLOBALS[__FUNCTION__];
1265 // Checks wether displaying of debug SQLs are enabled
1266 function isDisplayDebugSqlEnabled () {
1267 // Do we have cache?
1268 if (!isset($GLOBALS[__FUNCTION__])) {
1270 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
1274 return $GLOBALS[__FUNCTION__];
1277 // Checks wether module title is enabled
1278 function isModuleTitleEnabled () {
1279 // Do we have cache?
1280 if (!isset($GLOBALS[__FUNCTION__])) {
1282 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1286 return $GLOBALS[__FUNCTION__];
1289 // Checks wether what title is enabled
1290 function isWhatTitleEnabled () {
1291 // Do we have cache?
1292 if (!isset($GLOBALS[__FUNCTION__])) {
1294 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1298 return $GLOBALS[__FUNCTION__];
1301 // Checks wether stats are enabled
1302 function ifStatsAreEnabled () {
1303 // Do we have cache?
1304 if (!isset($GLOBALS[__FUNCTION__])) {
1305 // Then determine it
1306 $GLOBALS[__FUNCTION__] = (getConfig('stats_enabled') == 'Y');
1309 // Return cached value
1310 return $GLOBALS[__FUNCTION__];
1313 // Checks wether admin-notification of certain user actions is enabled
1314 function isAdminNotificationEnabled () {
1315 // Do we have cache?
1316 if (!isset($GLOBALS[__FUNCTION__])) {
1318 $GLOBALS[__FUNCTION__] = (getConfig('admin_notify') == 'Y');
1322 return $GLOBALS[__FUNCTION__];
1325 // Checks wether random referal id selection is enabled
1326 function isRandomReferalIdEnabled () {
1327 // Do we have cache?
1328 if (!isset($GLOBALS[__FUNCTION__])) {
1330 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
1334 return $GLOBALS[__FUNCTION__];
1337 // "Getter" for default language
1338 function getDefaultLanguage () {
1339 // Do we have cache?
1340 if (!isset($GLOBALS[__FUNCTION__])) {
1342 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1346 return $GLOBALS[__FUNCTION__];
1349 // "Getter" for default referal id
1350 function getDefRefid () {
1351 // Do we have cache?
1352 if (!isset($GLOBALS[__FUNCTION__])) {
1354 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1358 return $GLOBALS[__FUNCTION__];
1361 // "Getter" for path
1362 function getPath () {
1363 // Do we have cache?
1364 if (!isset($GLOBALS[__FUNCTION__])) {
1366 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1370 return $GLOBALS[__FUNCTION__];
1374 function getUrl () {
1375 // Do we have cache?
1376 if (!isset($GLOBALS[__FUNCTION__])) {
1378 $GLOBALS[__FUNCTION__] = getConfig('URL');
1382 return $GLOBALS[__FUNCTION__];
1385 // "Getter" for cache_path
1386 function getCachePath () {
1387 // Do we have cache?
1388 if (!isset($GLOBALS[__FUNCTION__])) {
1390 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1394 return $GLOBALS[__FUNCTION__];
1397 // "Getter" for secret_key
1398 function getSecretKey () {
1399 // Do we have cache?
1400 if (!isset($GLOBALS[__FUNCTION__])) {
1402 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1406 return $GLOBALS[__FUNCTION__];
1409 // "Getter" for master_salt
1410 function getMasterSalt () {
1411 // Do we have cache?
1412 if (!isset($GLOBALS[__FUNCTION__])) {
1414 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1418 return $GLOBALS[__FUNCTION__];
1421 // "Getter" for prime
1422 function getPrime () {
1423 // Do we have cache?
1424 if (!isset($GLOBALS[__FUNCTION__])) {
1426 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1430 return $GLOBALS[__FUNCTION__];
1433 // "Getter" for encrypt_seperator
1434 function getEncryptSeperator () {
1435 // Do we have cache?
1436 if (!isset($GLOBALS[__FUNCTION__])) {
1438 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPERATOR');
1442 return $GLOBALS[__FUNCTION__];
1445 // "Getter" for mysql_prefix
1446 function getMysqlPrefix () {
1447 // Do we have cache?
1448 if (!isset($GLOBALS[__FUNCTION__])) {
1450 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1454 return $GLOBALS[__FUNCTION__];
1457 // "Getter" for table_type
1458 function getTableType () {
1459 // Do we have cache?
1460 if (!isset($GLOBALS[__FUNCTION__])) {
1462 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1466 return $GLOBALS[__FUNCTION__];
1469 // "Getter" for salt_length
1470 function getSaltLength () {
1471 // Do we have cache?
1472 if (!isset($GLOBALS[__FUNCTION__])) {
1474 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1478 return $GLOBALS[__FUNCTION__];
1481 // "Getter" for output_mode
1482 function getOutputMode () {
1483 // Do we have cache?
1484 if (!isset($GLOBALS[__FUNCTION__])) {
1486 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1490 return $GLOBALS[__FUNCTION__];
1493 // "Getter" for full_version
1494 function getFullVersion () {
1495 // Do we have cache?
1496 if (!isset($GLOBALS[__FUNCTION__])) {
1498 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1502 return $GLOBALS[__FUNCTION__];
1505 // "Getter" for title
1506 function getTitle () {
1507 // Do we have cache?
1508 if (!isset($GLOBALS[__FUNCTION__])) {
1510 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1514 return $GLOBALS[__FUNCTION__];
1517 // "Getter" for curr_svn_revision
1518 function getCurrentRepositoryRevision () {
1519 // Do we have cache?
1520 if (!isset($GLOBALS[__FUNCTION__])) {
1522 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1526 return $GLOBALS[__FUNCTION__];
1529 // "Getter" for server_url
1530 function getServerUrl () {
1531 // Do we have cache?
1532 if (!isset($GLOBALS[__FUNCTION__])) {
1534 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1538 return $GLOBALS[__FUNCTION__];
1541 // "Getter" for mt_word
1542 function getMtWord () {
1543 // Do we have cache?
1544 if (!isset($GLOBALS[__FUNCTION__])) {
1546 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1550 return $GLOBALS[__FUNCTION__];
1553 // "Getter" for mt_word2
1554 function getMtWord2 () {
1555 // Do we have cache?
1556 if (!isset($GLOBALS[__FUNCTION__])) {
1558 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1562 return $GLOBALS[__FUNCTION__];
1565 // "Getter" for main_title
1566 function getMainTitle () {
1567 // Do we have cache?
1568 if (!isset($GLOBALS[__FUNCTION__])) {
1570 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
1574 return $GLOBALS[__FUNCTION__];
1577 // "Getter" for file_hash
1578 function getFileHash () {
1579 // Do we have cache?
1580 if (!isset($GLOBALS[__FUNCTION__])) {
1582 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
1586 return $GLOBALS[__FUNCTION__];
1589 // "Getter" for pass_scramble
1590 function getPassScramble () {
1591 // Do we have cache?
1592 if (!isset($GLOBALS[__FUNCTION__])) {
1594 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
1598 return $GLOBALS[__FUNCTION__];
1601 // "Getter" for ap_inactive_since
1602 function getApInactiveSince () {
1603 // Do we have cache?
1604 if (!isset($GLOBALS[__FUNCTION__])) {
1606 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
1610 return $GLOBALS[__FUNCTION__];
1613 // "Getter" for user_min_confirmed
1614 function getUserMinConfirmed () {
1615 // Do we have cache?
1616 if (!isset($GLOBALS[__FUNCTION__])) {
1618 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
1622 return $GLOBALS[__FUNCTION__];
1625 // "Getter" for auto_purge
1626 function getAutoPurge () {
1627 // Do we have cache?
1628 if (!isset($GLOBALS[__FUNCTION__])) {
1630 $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
1634 return $GLOBALS[__FUNCTION__];
1637 // "Getter" for bonus_userid
1638 function getBonusUserid () {
1639 // Do we have cache?
1640 if (!isset($GLOBALS[__FUNCTION__])) {
1642 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
1646 return $GLOBALS[__FUNCTION__];
1649 // "Getter" for ap_inactive_time
1650 function getApInactiveTime () {
1651 // Do we have cache?
1652 if (!isset($GLOBALS[__FUNCTION__])) {
1654 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
1658 return $GLOBALS[__FUNCTION__];
1661 // "Getter" for ap_dm_timeout
1662 function getApDmTimeout () {
1663 // Do we have cache?
1664 if (!isset($GLOBALS[__FUNCTION__])) {
1666 $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
1670 return $GLOBALS[__FUNCTION__];
1673 // "Getter" for ap_tasks_time
1674 function getApTasksTime () {
1675 // Do we have cache?
1676 if (!isset($GLOBALS[__FUNCTION__])) {
1678 $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
1682 return $GLOBALS[__FUNCTION__];
1685 // "Getter" for ap_unconfirmed_time
1686 function getApUnconfirmedTime () {
1687 // Do we have cache?
1688 if (!isset($GLOBALS[__FUNCTION__])) {
1690 $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
1694 return $GLOBALS[__FUNCTION__];
1697 // "Getter" for points
1698 function getPoints () {
1699 // Do we have cache?
1700 if (!isset($GLOBALS[__FUNCTION__])) {
1702 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
1706 return $GLOBALS[__FUNCTION__];
1709 // "Getter" for slogan
1710 function getSlogan () {
1711 // Do we have cache?
1712 if (!isset($GLOBALS[__FUNCTION__])) {
1714 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
1718 return $GLOBALS[__FUNCTION__];
1721 // "Getter" for copy
1722 function getCopy () {
1723 // Do we have cache?
1724 if (!isset($GLOBALS[__FUNCTION__])) {
1726 $GLOBALS[__FUNCTION__] = getConfig('COPY');
1730 return $GLOBALS[__FUNCTION__];
1733 // "Getter" for webmaster
1734 function getWebmaster () {
1735 // Do we have cache?
1736 if (!isset($GLOBALS[__FUNCTION__])) {
1738 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
1742 return $GLOBALS[__FUNCTION__];
1745 // "Getter" for sql_count
1746 function getSqlCount () {
1747 // Do we have cache?
1748 if (!isset($GLOBALS[__FUNCTION__])) {
1750 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
1754 return $GLOBALS[__FUNCTION__];
1757 // "Getter" for num_templates
1758 function getNumTemplates () {
1759 // Do we have cache?
1760 if (!isset($GLOBALS[__FUNCTION__])) {
1762 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
1766 return $GLOBALS[__FUNCTION__];
1769 // "Getter" for dns_cache_timeout
1770 function getDnsCacheTimeout () {
1771 // Do we have cache?
1772 if (!isset($GLOBALS[__FUNCTION__])) {
1774 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
1778 return $GLOBALS[__FUNCTION__];
1781 // "Getter" for menu_blur_spacer
1782 function getMenuBlurSpacer () {
1783 // Do we have cache?
1784 if (!isset($GLOBALS[__FUNCTION__])) {
1786 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
1790 return $GLOBALS[__FUNCTION__];
1793 // "Getter" for points_register
1794 function getPointsRegister () {
1795 // Do we have cache?
1796 if (!isset($GLOBALS[__FUNCTION__])) {
1798 $GLOBALS[__FUNCTION__] = getConfig('points_register');
1802 return $GLOBALS[__FUNCTION__];
1805 // "Getter" for points_ref
1806 function getPointsRef () {
1807 // Do we have cache?
1808 if (!isset($GLOBALS[__FUNCTION__])) {
1810 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
1814 return $GLOBALS[__FUNCTION__];
1817 // "Getter" for ref_payout
1818 function getRefPayout () {
1819 // Do we have cache?
1820 if (!isset($GLOBALS[__FUNCTION__])) {
1822 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
1826 return $GLOBALS[__FUNCTION__];
1829 // "Getter" for online_timeout
1830 function getOnlineTimeout () {
1831 // Do we have cache?
1832 if (!isset($GLOBALS[__FUNCTION__])) {
1834 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
1838 return $GLOBALS[__FUNCTION__];
1841 // "Getter" for index_home
1842 function getIndexHome () {
1843 // Do we have cache?
1844 if (!isset($GLOBALS[__FUNCTION__])) {
1846 $GLOBALS[__FUNCTION__] = getConfig('index_home');
1850 return $GLOBALS[__FUNCTION__];
1853 // "Getter" for one_day
1854 function getOneDay () {
1855 // Do we have cache?
1856 if (!isset($GLOBALS[__FUNCTION__])) {
1858 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
1862 return $GLOBALS[__FUNCTION__];
1865 // "Getter" for activate_xchange
1866 function getActivateXchange () {
1867 // Do we have cache?
1868 if (!isset($GLOBALS[__FUNCTION__])) {
1870 $GLOBALS[__FUNCTION__] = getConfig('activate_xchange');
1874 return $GLOBALS[__FUNCTION__];
1877 // "Getter" for img_type
1878 function getImgType () {
1879 // Do we have cache?
1880 if (!isset($GLOBALS[__FUNCTION__])) {
1882 $GLOBALS[__FUNCTION__] = getConfig('img_type');
1886 return $GLOBALS[__FUNCTION__];
1889 // "Getter" for code_length
1890 function getCodeLength () {
1891 // Do we have cache?
1892 if (!isset($GLOBALS[__FUNCTION__])) {
1894 $GLOBALS[__FUNCTION__] = getConfig('code_length');
1898 return $GLOBALS[__FUNCTION__];
1901 // "Getter" for least_cats
1902 function getLeastCats () {
1903 // Do we have cache?
1904 if (!isset($GLOBALS[__FUNCTION__])) {
1906 $GLOBALS[__FUNCTION__] = getConfig('least_cats');
1910 return $GLOBALS[__FUNCTION__];
1913 // "Getter" for pass_len
1914 function getPassLen () {
1915 // Do we have cache?
1916 if (!isset($GLOBALS[__FUNCTION__])) {
1918 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
1922 return $GLOBALS[__FUNCTION__];
1925 // "Getter" for admin_menu
1926 function getAdminMenu () {
1927 // Do we have cache?
1928 if (!isset($GLOBALS[__FUNCTION__])) {
1930 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
1934 return $GLOBALS[__FUNCTION__];
1937 // "Getter" for last_month
1938 function getLastMonth () {
1939 // Do we have cache?
1940 if (!isset($GLOBALS[__FUNCTION__])) {
1942 $GLOBALS[__FUNCTION__] = getConfig('last_month');
1946 return $GLOBALS[__FUNCTION__];
1949 // "Getter" for __DB_NAME
1950 function getDbName () {
1951 // Do we have cache?
1952 if (!isset($GLOBALS[__FUNCTION__])) {
1954 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
1958 return $GLOBALS[__FUNCTION__];
1961 // Checks wether proxy configuration is used
1962 function isProxyUsed () {
1963 // Do we have cache?
1964 if (!isset($GLOBALS[__FUNCTION__])) {
1966 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
1970 return $GLOBALS[__FUNCTION__];
1973 // Checks wether POST data contains selections
1974 function ifPostContainsSelections ($element = 'sel') {
1975 // Do we have cache?
1976 if (!isset($GLOBALS[__FUNCTION__][$element])) {
1978 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestParameterSet($element)) && (countPostSelection($element) > 0));
1982 return $GLOBALS[__FUNCTION__][$element];
1985 // Checks wether verbose_sql is Y and returns true/false if so
1986 function isVerboseSqlEnabled () {
1987 // Do we have cache?
1988 if (!isset($GLOBALS[__FUNCTION__])) {
1990 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
1994 return $GLOBALS[__FUNCTION__];
1997 // "Getter" for total user points
1998 function getTotalPoints ($userid) {
1999 // Do we have cache?
2000 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2002 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points');
2006 return $GLOBALS[__FUNCTION__][$userid];
2009 // Wrapper to check if url_blacklist is enabled
2010 function isUrlBlacklistEnabled () {
2011 // Do we have cache?
2012 if (!isset($GLOBALS[__FUNCTION__])) {
2014 $GLOBALS[__FUNCTION__] = (getConfig('url_blacklist') == 'Y');
2018 return $GLOBALS[__FUNCTION__];
2021 // Checks wether direct payment is allowed in configuration
2022 function isDirectPaymentEnabled () {
2023 // Do we have cache?
2024 if (!isset($GLOBALS[__FUNCTION__])) {
2026 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2030 return $GLOBALS[__FUNCTION__];
2033 // Wrapper to check if current task is for extension (not update)
2034 function isExtensionTask ($content) {
2035 // Do we have cache?
2036 if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2038 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos'])));
2042 return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2045 // Wrapper to check if output mode is CSS
2046 function isCssOutputMode () {
2048 return (getScriptOutputMode() == 1);
2051 // Wrapper to check if output mode is HTML
2052 function isHtmlOutputMode () {
2054 return (getScriptOutputMode() == 0);
2057 // Wrapper to check if output mode is RAW
2058 function isRawOutputMode () {
2060 return (getScriptOutputMode() == -1);
2063 // Wrapper to generate a user email link
2064 function generateWrappedUserEmailLink ($email) {
2065 // Just call the inner function
2066 return generateEmailLink($email, 'user_data');
2069 // Wrapper to check if user points are locked
2070 function ifUserPointsLocked ($userid) {
2071 // Do we have cache?
2072 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2074 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2078 return $GLOBALS[__FUNCTION__][$userid];
2081 // Appends a line to an existing file or creates it instantly with given content.
2082 // This function does always add a new-line character to every line.
2083 function appendLineToFile ($file, $line) {
2084 $fp = fopen($file, 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2085 fwrite($fp, $line . "\n");
2089 // Wrapper for changeDataInFile() but with full path added
2090 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
2092 $FQFN = getPath() . $FQFN;
2094 // Call inner function
2095 changeDataInFile($FQFN, $comment, $prefix, $suffix, $DATA, $seek);