]> git.mxchange.org Git - mailer.git/blobdiff - inc/language-functions.php
Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[mailer.git] / inc / language-functions.php
index 8aa635052922ac45c81be76e16e77ee7fa94d94e..5a339f4fade08abe79dfb04892a2ae373f3ba9e7 100644 (file)
@@ -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 *
  * 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.
@@ -48,24 +48,39 @@ function getMessage ($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 () {
        // Set default return value to default language from config
@@ -75,12 +90,12 @@ function getLanguage () {
        $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 (isIncludeReadable('inc/language/' . $lang . '.php')) {
@@ -96,7 +111,7 @@ function getLanguage () {
        }
 
        // Cache entry
-       $GLOBALS['cache_array']['language'] = $ret;
+       $GLOBALS['language'] = $ret;
 
        // Return value
        return $ret;
@@ -105,58 +120,98 @@ 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)).'<br />';
+       } // 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",
+                       $ext_name,
+                       getLanguage()
                ));
        }
 
        // 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]
 ?>