X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Flanguage-functions.php;h=cb1f925dbcb9a016f1cbd89d9f164312573bef82;hp=693fed1674d032e6002c7ac86c05b98d01d45d89;hb=79cab07c8937729e73bfacd4977bd5a203a7d950;hpb=fe1e1d3b8291b1ca991e3d2e639cb28097c53d74 diff --git a/inc/language-functions.php b/inc/language-functions.php index 693fed1674..cb1f925dbc 100644 --- a/inc/language-functions.php +++ b/inc/language-functions.php @@ -17,7 +17,7 @@ * Needs to be in all Files and every File needs "svn propset * * svn:keywords Date Revision" (autoprobset!) at least!!!!!! * * -------------------------------------------------------------------- * - * Copyright (c) 2003 - 2008 by Roland Haeder * + * Copyright (c) 2003 - 2009 by Roland Haeder * * For more information visit: http://www.mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -35,55 +35,73 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * * MA 02110-1301 USA * ************************************************************************/ + // Some security stuff... if (!defined('__SECURITY')) { - $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php'; - require($INC); -} + die(); +} // END - if // "Getter" for language strings // @TODO Rewrite all language constants to this function. function getMessage ($messageId) { // Default is not found! - $return = '!'.$messageId.'!'; + $return = '!' . $messageId . '!'; // Is the language string found? - if (isset($GLOBALS['msg'][strtolower($messageId)])) { + if (isMessageIdValid($messageId)) { // Language array element found in small_letters - $return = $GLOBALS['msg'][$messageId]; - } elseif (isset($GLOBALS['msg'][strtoupper($messageId)])) { - // @DEPRECATED Language array element found in BIG_LETTERS - $return = $GLOBALS['msg'][$messageId]; - } elseif (defined($messageId)) { - // @DEPRECATED Deprecated constant found - $return = constant($messageId); + $return = $GLOBALS['messages'][$messageId]; } else { // Missing language constant - DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Missing message string %s detected.", $messageId)); + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Missing message string %s detected.", $messageId)); } // Return the string return $return; } +// Init messages +function initMessages () { + $GLOBALS['messages'] = array(); +} + +// Add message +function addMessages ($messages) { + // Merge both + $GLOBALS['messages'] = merge_array($GLOBALS['messages'], $messages); +} + +// Checks wether given message id is valid +function isMessageIdValid ($messageId) { + return (isset($GLOBALS['messages'][$messageId])); +} + +// "Getter for current language +function getCurrentLanguage () { + return $GLOBALS['language']; +} + // "Getter" for language function getLanguage () { + // Default is 'de'. DO NOT CHANGE THIS!!! + $ret = 'de'; + // Set default return value to default language from config - $ret = getConfig('DEFAULT_LANG'); + if (isConfigEntrySet('DEFAULT_LANG')) $ret = getConfig('DEFAULT_LANG'); // Init variable $lang = ''; // Is the variable set - if (REQUEST_ISSET_GET('mx_lang')) { + if (isGetRequestElementSet('mx_lang')) { // Accept only first 2 chars - $lang = substr(REQUEST_GET('mx_lang'), 0, 2); - } elseif (isset($GLOBALS['cache_array']['language'])) { + $lang = substr(getRequestElement('mx_lang'), 0, 2); + } elseif (isset($GLOBALS['language'])) { // Use cached - $ret = $GLOBALS['cache_array']['language']; + $ret = getCurrentLanguage(); } elseif (!empty($lang)) { // Check if main language file does exist - if (isFileReadable(constant('PATH') . 'inc/language/' . $lang . '.php')) { + if (isIncludeReadable('inc/language/' . $lang . '.php')) { // Okay found, so let's update cookies setLanguage($lang); } // END - if @@ -96,7 +114,7 @@ function getLanguage () { } // Cache entry - $GLOBALS['cache_array']['language'] = $ret; + $GLOBALS['language'] = $ret; // Return value return $ret; @@ -105,58 +123,99 @@ function getLanguage () { // "Setter" for language function setLanguage ($lang) { // Accept only first 2 chars! - $lang = substr(SQL_ESCAPE(strip_tags($lang)), 0, 2); + $lang = substr(SQL_ESCAPE(secureString($lang)), 0, 2); // Set cookie setSession('mx_lang', $lang); } +// Checks wether a language file is there for optional extension +function isLanguageIncludeReadable ($ext_name = 'none') { + // Do we have array element? + if (!isset($GLOBALS['lang_inc'][$ext_name])) { + // Generate filename + if ($ext_name == 'none') { + // Generic + $languageInclude = sprintf("inc/language/%s.php", getLanguage()); + } else { + // Extension's language file + $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage()); + } + + // Look for file if no extension name is provided + $GLOBALS['lang_inc'][$ext_name] = isIncludeReadable($languageInclude); + //* DEBUG: */ print __FUNCTION__.':'.$ext_name.'='.$languageInclude.'='.intval(isIncludeReadable($languageInclude)).'
'; + } // END - if + + // Return it + return $GLOBALS['lang_inc'][$ext_name]; +} + // Load the current language file or fixes it to 'de' -// If ext_name is empty, load general language support, else load extension's -// language file. -function loadLanguageFile ($ext_name = '') { +// If ext_name is 'none', load general language support, else load extension's +// language file. In installation phase load the install language file. +function loadLanguageFile ($ext_name = 'none') { // Try to get language from session - $mx_lang = getSession('mx_lang'); + $currLanguage = getLanguage(); // Set default language if it is not (yet) set - if (is_null($mx_lang)) $mx_lang = getConfig('DEFAULT_LANG'); + if (is_null($currLanguage)) { + // Get it from config + $currLanguage = getConfig('DEFAULT_LANG'); - // Generate filename - if (empty($ext_name)) { - // Generic - $languageInclude = sprintf("inc/language/%s.php", SQL_ESCAPE($mx_lang)); - } else { - // Extension's language file - $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage()); - } + // And save it in session + setLanguage($currLanguage); + } // END - if - // Look for file if no extension name is provided - if ((empty($ext_name)) && (isIncludeReadable($languageInclude) === false)) { + // Do we have the language file NOT? + if (!isLanguageIncludeReadable($ext_name)) { // Switch to default (DO NOT CHANGE!!!) setLanguage('de'); - $languageInclude = 'inc/language/de.php'; // And set it temporarily setConfigEntry('DEFAULT_LANG', 'de'); } // END - if // Is the file there? - if (isIncludeReadable($languageInclude)) { + if (isLanguageIncludeReadable($ext_name)) { // Load language file - loadIncludeOnce($languageInclude); - } elseif ((isDebugModeEnabled()) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme')) { + loadLanguageInclude($ext_name); + } elseif ((isDebugModeEnabled()) && (getOutputMode() == '0') && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme')) { // No language file is not so good... - DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no language file or we cannot read from it. lang=%s", - $ext_name, getLanguage() + logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no language file or we cannot read from it. lang=%s, mode=%s", + $ext_name, + getLanguage(), + getExtensionMode() )); } // Check for installation mode - if ((isInstalling()) || (!isInstalled()) || (!isAdminRegistered())) { - // Load matching language file - loadInclude('inc/language/install_' . getSession('mx_lang') . '.php'); + if ((isInstallationPhase()) || (!isAdminRegistered())) { + // Load language file + loadLanguageInclude('install'); } // END - if } +// Loads the language file +function loadLanguageInclude ($ext_name = 'none') { + // Generate filename + if ($ext_name == 'none') { + // Generic + $languageInclude = sprintf("inc/language/%s.php", getLanguage()); + } else { + // Extension's language file + $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage()); + } + + // Check it before loading + if (isLanguageIncludeReadable($ext_name)) { + // Load it + loadIncludeOnce($languageInclude); + } else { + // Not readable! + DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Language file %s not found or readable.", $languageInclude)); + } +} + // [EOF] ?>