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 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
46 function readFromFile ($FQFN) {
47 // Sanity-check if file is there (should be there, but just to make it sure)
48 if (!isFileReadable($FQFN)) {
49 // This should not happen
50 debug_report_bug(__FUNCTION__.': File ' . basename($FQFN) . ' is not readable!');
54 if (!isset($GLOBALS['file_content'][$FQFN])) {
56 if (function_exists('file_get_contents')) {
58 $GLOBALS['file_content'][$FQFN] = file_get_contents($FQFN);
60 // Fall-back to implode-file chain
61 $GLOBALS['file_content'][$FQFN] = implode('', file($FQFN));
66 return $GLOBALS['file_content'][$FQFN];
69 // Writes content to a file
70 function writeToFile ($FQFN, $content, $aquireLock = false) {
71 // Is the file writeable?
72 if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
74 logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN)));
80 // By default all is failed...
83 // Is the function there?
84 if (function_exists('file_put_contents')) {
86 if ($aquireLock === true) {
87 // Write it directly with lock
88 $return = file_put_contents($FQFN, $content, LOCK_EX);
91 $return = file_put_contents($FQFN, $content);
94 // Write it with fopen
95 $fp = fopen($FQFN, 'w') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
98 if ($aquireLock === true) flock($fp, LOCK_EX);
101 fwrite($fp, $content);
107 // Mark it as readable
108 $GLOBALS['file_readable'][$FQFN] = true;
110 // Remember content in cache
111 $GLOBALS['file_content'][$FQFN] = $content;
114 return changeMode($FQFN, 0644);
117 // Clears the output buffer. This function does *NOT* backup sent content.
118 function clearOutputBuffer () {
119 // Trigger an error on failure
120 if ((ob_get_length() > 0) && (!ob_end_clean())) {
122 debug_report_bug(__FUNCTION__.': Failed to clean output buffer.');
127 // @TODO Implement $compress
128 function encodeString ($str, $compress = true) {
129 $str = urlencode(base64_encode(compileUriCode($str)));
133 // Decode strings encoded with encodeString()
134 // @TODO Implement $decompress
135 function decodeString ($str, $decompress = true) {
136 $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
140 // Decode entities in a nicer way
141 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
142 // Decode the entities to UTF-8 now
143 $decodedString = html_entity_decode($str, $quote, 'UTF-8');
145 // Return decoded string
146 return $decodedString;
149 // Merges an array together but only if both are arrays
150 function merge_array ($array1, $array2) {
151 // Are both an array?
152 if ((!is_array($array1)) && (!is_array($array2))) {
153 // Both are not arrays
154 debug_report_bug(__FUNCTION__, __LINE__, 'No arrays provided!');
155 } elseif (!is_array($array1)) {
156 // Left one is not an array
157 debug_report_bug(__FILE__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
158 } elseif (!is_array($array2)) {
159 // Right one is not an array
160 debug_report_bug(__FILE__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
163 // Merge all together
164 return array_merge($array1, $array2);
167 // Check if given FQFN is a readable file
168 function isFileReadable ($FQFN) {
170 if (!isset($GLOBALS['file_readable'][$FQFN])) {
172 $GLOBALS['file_readable'][$FQFN] = ((file_exists($FQFN)) && (is_file($FQFN)) && (is_readable($FQFN)));
175 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'file=' . basename($FQFN) . ' - CHECK! (' . intval($GLOBALS['file_readable'][$FQFN]) . ')');
178 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'file=' . basename($FQFN) . ' - CACHE! (' . intval($GLOBALS['file_readable'][$FQFN]) . ')');
182 return $GLOBALS['file_readable'][$FQFN];
185 // Checks wether the given FQFN is a directory and not ., .. or .svn
186 function isDirectory ($FQFN) {
188 if (!isset($GLOBALS['is_directory'][$FQFN])) {
190 $baseName = basename($FQFN);
193 $GLOBALS['is_directory'][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
197 return $GLOBALS['is_directory'][$FQFN];
200 // "Getter" for remote IP number
201 function detectRemoteAddr () {
202 // Get remote ip from environment
203 $remoteAddr = determineRealRemoteAddress();
205 // Is removeip installed?
206 if (isExtensionActive('removeip')) {
208 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
215 // "Getter" for remote hostname
216 function detectRemoteHostname () {
217 // Get remote ip from environment
218 $remoteHost = getenv('REMOTE_HOST');
220 // Is removeip installed?
221 if (isExtensionActive('removeip')) {
223 $remoteHost = getAnonymousRemoteHost($remoteHost);
230 // "Getter" for user agent
231 function detectUserAgent ($alwaysReal = false) {
232 // Get remote ip from environment
233 $userAgent = getenv('HTTP_USER_AGENT');
235 // Is removeip installed?
236 if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
238 $userAgent = getAnonymousUserAgent($userAgent);
245 // "Getter" for referer
246 function detectReferer () {
247 // Get remote ip from environment
248 $referer = getenv('HTTP_REFERER');
250 // Is removeip installed?
251 if (isExtensionActive('removeip')) {
253 $referer = getAnonymousReferer($referer);
260 // "Getter" for request URI
261 function detectRequestUri () {
263 return (getenv('REQUEST_URI'));
266 // "Getter" for query string
267 function detectQueryString () {
268 return str_replace('&', '&', (getenv('QUERY_STRING')));
271 // "Getter" for SERVER_NAME
272 function detectServerName () {
274 return (getenv('SERVER_NAME'));
277 // Check wether we are installing
278 function isInstalling () {
279 // Determine wether we are installing
280 if (!isset($GLOBALS['mailer_installing'])) {
281 // Check URL (css.php/js.php need this)
282 $GLOBALS['mailer_installing'] = isGetRequestParameterSet('installing');
286 return $GLOBALS['mailer_installing'];
289 // Check wether this script is installed
290 function isInstalled () {
292 if (!isset($GLOBALS['is_installed'])) {
293 // Determine wether this script is installed
294 $GLOBALS['is_installed'] = (
299 isConfigEntrySet('MXCHANGE_INSTALLED')
301 getConfig('MXCHANGE_INSTALLED') == 'Y'
305 // New config file found and loaded
306 isIncludeReadable(getConfig('CACHE_PATH') . 'config-local.php')
309 // New config file found, but not yet read
310 isIncludeReadable(getConfig('CACHE_PATH') . 'config-local.php')
313 // Only new config file is found
314 !isIncludeReadable('inc/config.php')
316 // Is installation mode
323 // Then use the cache
324 return $GLOBALS['is_installed'];
327 // Check wether an admin is registered
328 function isAdminRegistered () {
330 if (!isset($GLOBALS['is_admin_registered'])) {
332 $GLOBALS['is_admin_registered'] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
336 return $GLOBALS['is_admin_registered'];
339 // Checks wether the reset mode is active
340 function isResetModeEnabled () {
341 // Now simply check it
342 return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
345 // Checks wether the debug mode is enabled
346 function isDebugModeEnabled () {
348 if (!isset($GLOBALS['is_debugmode_enabled'])) {
350 $GLOBALS['is_debugmode_enabled'] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
354 return $GLOBALS['is_debugmode_enabled'];
357 // Checks wether SQL debugging is enabled
358 function isSqlDebuggingEnabled () {
360 if (!isset($GLOBALS['is_sql_debug_enabled'])) {
361 // Determine if SQL debugging is enabled
362 $GLOBALS['is_sql_debug_enabled'] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
366 return $GLOBALS['is_sql_debug_enabled'];
369 // Checks wether we shall debug regular expressions
370 function isDebugRegularExpressionEnabled () {
372 if (!isset($GLOBALS['is_regular_exp_debug_enabled'])) {
374 $GLOBALS['is_regular_exp_debug_enabled'] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
378 return $GLOBALS['is_regular_exp_debug_enabled'];
381 // Checks wether the cache instance is valid
382 function isCacheInstanceValid () {
383 return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
386 // Copies a file from source to destination and verifies if that goes fine.
387 // This function should wrap the copy() command and make a nicer debug backtrace
388 // even if there is no xdebug extension installed.
389 function copyFileVerified ($source, $dest, $chmod = '') {
390 // Failed is the default
393 // Is the source file there?
394 if (!isFileReadable($source)) {
396 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
399 // Is the target directory there?
400 if (!isDirectory(dirname($dest))) {
402 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getConfig('PATH'), '', dirname($dest)) . '.');
405 // Now try to copy it
406 if (!copy($source, $dest)) {
407 // Something went wrong
408 debug_report_bug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
411 $GLOBALS['file_readable'][$dest] = true;
414 // If there are chmod rights set, apply them
415 if (!empty($chmod)) {
417 $status = changeMode($dest, $chmod);
427 // Wrapper function for header()
428 // Send a header but checks before if we can do so
429 function sendHeader ($header) {
431 //* DEBUG: */ logDebugMessage(__FUNCTION__ . ': header=' . $header);
432 $GLOBALS['header'][] = trim($header);
435 // Flushes all headers
436 function flushHeaders () {
437 // Is the header already sent?
438 if (headers_sent()) {
440 debug_report_bug(__FUNCTION__, __LINE__, 'Headers already sent!');
443 // Flush all headers if found
444 if ((isset($GLOBALS['header'])) && (is_array($GLOBALS['header']))) {
445 foreach ($GLOBALS['header'] as $header) {
450 // Mark them as flushed
451 $GLOBALS['header'] = array();
454 // Wrapper function for chmod()
455 // @TODO Do some more sanity check here
456 function changeMode ($FQFN, $mode) {
457 // Is the file/directory there?
458 if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
459 // Neither, so abort here
460 debug_report_bug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
467 // Wrapper for unlink()
468 function removeFile ($FQFN) {
469 // Is the file there?
470 if (isFileReadable($FQFN)) {
472 $GLOBALS['file_readable'][$FQFN] = false;
475 return unlink($FQFN);
478 // All fine if no file was removed. If we change this to 'false' or rewrite
479 // above if() block it would be to restrictive.
483 // Wrapper for $_POST['sel']
484 function countPostSelection ($element = 'sel') {
486 if (isPostRequestParameterSet($element)) {
487 // Return counted elements
488 return countSelection(postRequestParameter($element));
490 // Return zero if not found
495 // Checks wether the config-local.php is loaded
496 function isConfigLocalLoaded () {
497 return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
500 // Checks wether a nickname or userid was entered and caches the result
501 function isNicknameUsed ($userid) {
505 // Is the cache there
506 if (isset($GLOBALS['is_nickname_used'][$userid])) {
508 $isUsed = $GLOBALS['is_nickname_used'][$userid];
511 $isUsed = (('' . round($userid) . '') != $userid);
513 // And write it to the cache
514 $GLOBALS['is_nickname_used'][$userid] = $isUsed;
521 // Getter for 'what' value
522 function getWhat () {
527 if (isWhatSet(true)) {
529 $what = $GLOBALS['what'];
536 // Setter for 'what' value
537 function setWhat ($newWhat) {
538 $GLOBALS['what'] = SQL_ESCAPE($newWhat);
541 // Setter for 'what' from configuration
542 function setWhatFromConfig ($configEntry) {
543 // Get 'what' from config
544 $what = getConfig($configEntry);
550 // Checks wether what is set and optionally aborts on miss
551 function isWhatSet ($strict = false) {
553 $isset = isset($GLOBALS['what']);
555 // Should we abort here?
556 if (($strict === true) && ($isset === false)) {
558 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
565 // Getter for 'action' value
566 function getAction ($strict = true) {
571 if (isActionSet(($strict) && (getOutputMode() == 0))) {
573 $action = $GLOBALS['action'];
580 // Setter for 'action' value
581 function setAction ($newAction) {
582 $GLOBALS['action'] = SQL_ESCAPE($newAction);
585 // Checks wether action is set and optionally aborts on miss
586 function isActionSet ($strict = false) {
588 $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action'])));
590 // Should we abort here?
591 if (($strict === true) && ($isset === false)) {
593 debug_report_bug(__FUNCTION__, __LINE__, 'action is empty.');
600 // Getter for 'module' value
601 function getModule ($strict = true) {
606 if (isModuleSet($strict)) {
608 $module = $GLOBALS['module'];
615 // Setter for 'module' value
616 function setModule ($newModule) {
617 // Secure it and make all modules lower-case
618 $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
621 // Checks wether module is set and optionally aborts on miss
622 function isModuleSet ($strict = false) {
624 $isset = (!empty($GLOBALS['module']));
626 // Should we abort here?
627 if (($strict === true) && ($isset === false)) {
629 debug_report_bug(__FUNCTION__, __LINE__, 'module is empty.');
633 return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
636 // Getter for 'output_mode' value
637 function getOutputMode () {
642 if (isOutputModeSet(true)) {
644 $output_mode = $GLOBALS['output_mode'];
651 // Setter for 'output_mode' value
652 function setOutputMode ($newOutputMode) {
653 $GLOBALS['output_mode'] = (int) $newOutputMode;
656 // Checks wether output_mode is set and optionally aborts on miss
657 function isOutputModeSet ($strict = false) {
659 $isset = (isset($GLOBALS['output_mode']));
661 // Should we abort here?
662 if (($strict === true) && ($isset === false)) {
664 debug_report_bug(__FUNCTION__, __LINE__, 'Output_mode is empty.');
671 // Enables block-mode
672 function enableBlockMode ($enabled = true) {
673 $GLOBALS['block_mode'] = $enabled;
676 // Checks wether block-mode is enabled
677 function isBlockModeEnabled () {
679 if (!isset($GLOBALS['block_mode'])) {
681 debug_report_bug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
685 return $GLOBALS['block_mode'];
688 // Wrapper function for addPointsThroughReferalSystem()
689 function addPointsDirectly ($subject, $userid, $points) {
691 unset($GLOBALS['ref_level']);
693 // Call more complicated method (due to more parameters)
694 return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, false, 'direct');
697 // Wrapper for redirectToUrl but URL comes from a configuration entry
698 function redirectToConfiguredUrl ($configEntry) {
700 redirectToUrl(getConfig($configEntry));
703 // Wrapper function to redirect from member-only modules to index
704 function redirectToIndexMemberOnlyModule () {
705 // Do the redirect here
706 redirectToUrl('modules.php?module=index&code=' . getCode('MODULE_MEMBER_ONLY') . '&mod=' . getModule());
709 // Wrapper function to redirect to current URL
710 function redirectToRequestUri () {
711 redirectToUrl(basename(detectRequestUri()));
714 // Wrapper function to redirect to de-refered URL
715 function redirectToDereferedUrl ($URL) {
717 redirectToUrl(generateDerefererUrl($URL));
720 // Wrapper function for checking if extension is installed and newer or same version
721 function isExtensionInstalledAndNewer ($ext_name, $version) {
722 // Is an cache entry found?
723 if (!isset($GLOBALS['ext_installed_newer'][$ext_name][$version])) {
724 $GLOBALS['ext_installed_newer'][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
726 // Cache hits should be incremented twice
727 incrementStatsEntry('cache_hits', 2);
731 //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'=>'.$version.':'.intval($GLOBALS['ext_installed_newer'][$ext_name][$version]));
732 return $GLOBALS['ext_installed_newer'][$ext_name][$version];
735 // Wrapper function for checking if extension is installed and older than given version
736 function isExtensionInstalledAndOlder ($ext_name, $version) {
737 // Is an cache entry found?
738 if (!isset($GLOBALS['ext_installed_older'][$ext_name][$version])) {
739 $GLOBALS['ext_installed_older'][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
741 // Cache hits should be incremented twice
742 incrementStatsEntry('cache_hits', 2);
746 //* DEBUG: */ debugOutput(__FUNCTION__.':'.$ext_name.'<'.$version.':'.intval($GLOBALS['ext_installed_older'][$ext_name][$version]));
747 return $GLOBALS['ext_installed_older'][$ext_name][$version];
751 function setUsername ($userName) {
752 $GLOBALS['username'] = (string) $userName;
756 function getUsername () {
758 if (!isset($GLOBALS['username'])) {
759 // No, so it has to be a guest
760 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
764 return $GLOBALS['username'];
767 // Wrapper function for installation phase
768 function isInstallationPhase () {
770 if (!isset($GLOBALS['installation_phase'])) {
772 $GLOBALS['installation_phase'] = ((!isInstalled()) || (isInstalling()));
776 return $GLOBALS['installation_phase'];
779 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
780 function isDemoModeActive () {
782 if (!isset($GLOBALS['demo_mode_active'])) {
784 $GLOBALS['demo_mode_active'] = ((isExtensionActive('demo')) && (getAdminLogin(getSession('admin_id')) == 'demo'));
788 return $GLOBALS['demo_mode_active'];
791 // Getter for PHP caching value
792 function getPhpCaching () {
793 return $GLOBALS['php_caching'];
796 // Checks wether the admin hash is set
797 function isAdminHashSet ($adminId) {
798 // Is the array there?
799 if (!isset($GLOBALS['cache_array']['admin'])) {
800 // Missing array should be reported
801 debug_report_bug(__FUNCTION__, __LINE__, 'Cache not set.');
804 // Check for admin hash
805 return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
808 // Setter for admin hash
809 function setAdminHash ($adminId, $hash) {
810 $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
813 // Init user data array
814 function initUserData () {
815 // User id should not be zero
816 if (getCurrentUserId() < 1) debug_report_bug(__FUNCTION__.': User id is zero.');
819 $GLOBALS['user_data'][getCurrentUserId()] = array();
822 // Getter for user data
823 function getUserData ($column) {
824 // User id should not be zero
825 if (getCurrentUserId() < 1) debug_report_bug(__FUNCTION__.': User id is zero.');
828 return $GLOBALS['user_data'][getCurrentUserId()][$column];
831 // Geter for whole user data array
832 function getUserDataArray () {
834 $uid = getCurrentUserId();
836 // User id should not be zero
837 if ($uid < 1) debug_report_bug(__FUNCTION__.': User id is zero.');
839 // Get the whole array if found
840 if (isset($GLOBALS['user_data'][$uid])) {
841 // Found, so return it
842 return $GLOBALS['user_data'][$uid];
844 // Return empty array
849 // Checks if the user data is valid, this may indicate that the user has logged
850 // in, but you should use isMember() if you want to find that out.
851 function isUserDataValid () {
852 // User id should not be zero so abort here
853 if (!isCurrentUserIdSet()) return false;
856 if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
858 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
862 return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
865 // Setter for current userid
866 function setCurrentUserId ($userid) {
868 $GLOBALS['current_userid'] = bigintval($userid);
870 // Unset it to re-determine the actual state
871 unset($GLOBALS['is_userdata_valid'][$userid]);
874 // Getter for current userid
875 function getCurrentUserId () {
876 // Userid must be set before it can be used
877 if (!isCurrentUserIdSet()) {
879 debug_report_bug(__FUNCTION__, __LINE__, 'User id is not set.');
883 return $GLOBALS['current_userid'];
886 // Checks if current userid is set
887 function isCurrentUserIdSet () {
888 return ((isset($GLOBALS['current_userid'])) && ($GLOBALS['current_userid'] > 0));
891 // Checks wether we are debugging template cache
892 function isDebuggingTemplateCache () {
893 return (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
896 // Wrapper for fetchUserData() and getUserData() calls
897 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
899 if (!isset($GLOBALS['user_data_cache'][$userid][$keyColumn][$valueColumn])) {
900 // Default is 'guest'
901 $data = '{--USERNAME_GUEST--}';
903 // Can we fetch the user data?
904 if (($userid > 0) && (fetchUserData($userid, $keyColumn))) {
905 // Now get the data back
906 $data = getUserData($valueColumn);
910 $GLOBALS['user_data_cache'][$userid][$keyColumn][$valueColumn] = $data;
914 return $GLOBALS['user_data_cache'][$userid][$keyColumn][$valueColumn];
917 // Wrapper for strpos() to ease porting from deprecated ereg() function
918 function isInString ($needle, $haystack) {
919 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
920 return (strpos($haystack, $needle) !== false);
923 // Wrapper for strpos() to ease porting from deprecated eregi() function
924 // This function is case-insensitive
925 function isInStringIgnoreCase ($needle, $haystack) {
926 return (isInString(strtolower($needle), strtolower($haystack)));
929 // Wrapper to check for if fatal errors where detected
930 function ifFatalErrorsDetected () {
931 // Just call the inner function
932 return (getTotalFatalErrors() > 0);
935 // Setter for HTTP status
936 function setHttpStatus ($status) {
937 $GLOBALS['http_status'] = (string) $status;
940 // Getter for HTTP status
941 function getHttpStatus () {
942 return $GLOBALS['http_status'];
946 * Send a HTTP redirect to the browser. This function was taken from DokuWiki
947 * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
949 * ----------------------------------------------------------------------------
950 * If you want to redirect, please use redirectToUrl(); instead
951 * ----------------------------------------------------------------------------
953 * Works arround Microsoft IIS cookie sending bug. Does exit the script.
955 * @link http://support.microsoft.com/kb/q176113/
956 * @author Andreas Gohr <andi@splitbrain.org>
959 function sendRawRedirect ($url) {
960 // always close the session
961 session_write_close();
963 // Revert entity &
964 $url = str_replace('&', '&', $url);
966 // check if running on IIS < 6 with CGI-PHP
967 if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
968 (strpos($_SERVER['GATEWAY_INTERFACE'],'CGI') !== false) &&
969 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
971 // Send the IIS header
972 sendHeader('Refresh: 0;url=' . $url);
974 // Send generic header
975 sendHeader('Location: ' . $url);
982 // Determines the country of the given user id
983 function determineCountry ($userid) {
984 // Default is 'invalid'
985 $country = 'invalid';
987 // Is extension country active?
988 if (isExtensionActive('country')) {
989 // Determine the right country code through the country id
990 $id = getUserData('country_code');
992 // Then handle it over
993 $country = generateCountryInfo($id);
995 // Get raw code from user data
996 $country = getUserData('country');
1003 // "Getter" for total confirmed user accounts
1004 function getTotalConfirmedUser () {
1006 if (!isset($GLOBALS['total_confirmed_users'])) {
1008 $GLOBALS['total_confirmed_users'] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
1011 // Return cached value
1012 return $GLOBALS['total_confirmed_users'];
1015 // Is given userid valid?
1016 function isValidUserId ($userid) {
1017 // Do we have cache?
1018 if (!isset($GLOBALS['is_valid_userid'][$userid])) {
1020 $GLOBALS['is_valid_userid'][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
1024 return $GLOBALS['is_valid_userid'][$userid];
1028 function encodeEntities ($str) {
1030 $str = secureString($str);
1032 // Encode dollar sign as well
1033 $str = str_replace('$', '$', $str);
1039 // "Getter" for date from patch_ctime
1040 function getDateFromPatchTime () {
1042 if (!isset($GLOBALS[__FUNCTION__])) {
1044 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('patch_ctime'), '5');
1048 return $GLOBALS[__FUNCTION__];
1051 // Getter for current year (default)
1052 function getYear ($timestamp = null) {
1054 if (!isset($GLOBALS['year'][$timestamp])) {
1056 if (is_null($timestamp)) $timestamp = time();
1059 $GLOBALS['year'][$timestamp] = date('Y', $timestamp);
1063 return $GLOBALS['year'][$timestamp];
1066 // Getter for current month (default)
1067 function getMonth ($timestamp = null) {
1069 if (!isset($GLOBALS['month'][$timestamp])) {
1071 if (is_null($timestamp)) $timestamp = time();
1074 $GLOBALS['month'][$timestamp] = date('m', $timestamp);
1078 return $GLOBALS['month'][$timestamp];
1081 // Getter for current day (default)
1082 function getDay ($timestamp = null) {
1084 if (!isset($GLOBALS['day'][$timestamp])) {
1086 if (is_null($timestamp)) $timestamp = time();
1089 $GLOBALS['day'][$timestamp] = date('d', $timestamp);
1093 return $GLOBALS['day'][$timestamp];
1096 // Getter for current week (default)
1097 function getWeek ($timestamp = null) {
1099 if (!isset($GLOBALS['week'][$timestamp])) {
1101 if (is_null($timestamp)) $timestamp = time();
1104 $GLOBALS['week'][$timestamp] = date('W', $timestamp);
1108 return $GLOBALS['week'][$timestamp];
1111 // Getter for current short_hour (default)
1112 function getShortHour ($timestamp = null) {
1114 if (!isset($GLOBALS['short_hour'][$timestamp])) {
1116 if (is_null($timestamp)) $timestamp = time();
1119 $GLOBALS['short_hour'][$timestamp] = date('G', $timestamp);
1123 return $GLOBALS['short_hour'][$timestamp];
1126 // Getter for current long_hour (default)
1127 function getLongHour ($timestamp = null) {
1129 if (!isset($GLOBALS['long_hour'][$timestamp])) {
1131 if (is_null($timestamp)) $timestamp = time();
1134 $GLOBALS['long_hour'][$timestamp] = date('H', $timestamp);
1138 return $GLOBALS['long_hour'][$timestamp];
1141 // Getter for current second (default)
1142 function getSecond ($timestamp = null) {
1144 if (!isset($GLOBALS['second'][$timestamp])) {
1146 if (is_null($timestamp)) $timestamp = time();
1149 $GLOBALS['second'][$timestamp] = date('s', $timestamp);
1153 return $GLOBALS['second'][$timestamp];
1156 // Getter for current minute (default)
1157 function getMinute ($timestamp = null) {
1159 if (!isset($GLOBALS['minute'][$timestamp])) {
1161 if (is_null($timestamp)) $timestamp = time();
1164 $GLOBALS['minute'][$timestamp] = date('i', $timestamp);
1168 return $GLOBALS['minute'][$timestamp];