]> git.mxchange.org Git - mailer.git/blob - inc/language-functions.php
Login form for guests in surfbar added, some trigger_error() added, misc rewrites
[mailer.git] / inc / language-functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 08/25/2003 *
4  * ===============                              Last change: 11/29/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : language-functions.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Language functions                               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Sprachfunktionen                                 *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
41         require($INC);
42 }
43
44 // "Getter" for language strings
45 // @TODO Rewrite all language constants to this function.
46 function getMessage ($messageId) {
47         // Default is not found!
48         $return = '!'.$messageId.'!';
49
50         // Is the language string found?
51         if (isset($GLOBALS['msg'][strtolower($messageId)])) {
52                 // Language array element found in small_letters
53                 $return = $GLOBALS['msg'][$messageId];
54         } elseif (isset($GLOBALS['msg'][strtoupper($messageId)])) {
55                 // @DEPRECATED Language array element found in BIG_LETTERS
56                 $return = $GLOBALS['msg'][$messageId];
57         } elseif (defined($messageId)) {
58                 // @DEPRECATED Deprecated constant found
59                 $return = constant($messageId);
60         } else {
61                 // Missing language constant
62                 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Missing message string %s detected.", $messageId));
63         }
64
65         // Return the string
66         return $return;
67 }
68
69 // "Getter" for language
70 function getLanguage () {
71         // Set default return value to default language from config
72         $ret = getConfig('DEFAULT_LANG');
73
74         // Init variable
75         $lang = '';
76
77         // Is the variable set
78         if (REQUEST_ISSET_GET('mx_lang')) {
79                 // Accept only first 2 chars
80                 $lang = substr(REQUEST_GET('mx_lang'), 0, 2);
81         } elseif (isset($GLOBALS['cache_array']['language'])) {
82                 // Use cached
83                 $ret = $GLOBALS['cache_array']['language'];
84         } elseif (!empty($lang)) {
85                 // Check if main language file does exist
86                 if (isFileReadable(constant('PATH') . 'inc/language/' . $lang . '.php')) {
87                         // Okay found, so let's update cookies
88                         setLanguage($lang);
89                 } // END - if
90         } elseif (isSessionVariableSet('mx_lang')) {
91                 // Return stored value from cookie
92                 $ret = getSession('mx_lang');
93
94                 // Fixes a warning before the session has the mx_lang constant
95                 if (empty($ret)) $ret = getConfig('DEFAULT_LANG');
96         }
97
98         // Cache entry
99         $GLOBALS['cache_array']['language'] = $ret;
100
101         // Return value
102         return $ret;
103 }
104
105 // "Setter" for language
106 function setLanguage ($lang) {
107         // Accept only first 2 chars!
108         $lang = substr(SQL_ESCAPE(strip_tags($lang)), 0, 2);
109
110         // Set cookie
111         setSession('mx_lang', $lang);
112 }
113
114 // Load the current language file or fixes it to 'de'
115 // If ext_name is empty, load general language support, else load extension's
116 // language file.
117 function loadLanguageFile ($ext_name = '') {
118         // Try to get language from session
119         $mx_lang = getSession('mx_lang');
120
121         // Set default language if it is not (yet) set
122         if (is_null($mx_lang)) $mx_lang = getConfig('DEFAULT_LANG');
123
124         // Generate filename
125         if (empty($ext_name)) {
126                 // Generic
127                 $languageInclude = sprintf("inc/language/%s.php", SQL_ESCAPE($mx_lang));
128         } else {
129                 // Extension's language file
130                 $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage());
131         }
132
133         // Look for file if no extension name is provided
134         if ((empty($ext_name)) && (isIncludeReadable($languageInclude) === false)) {
135                 // Switch to default (DO NOT CHANGE!!!)
136                 setLanguage('de');
137                 $languageInclude = 'inc/language/de.php';
138
139                 // And set it temporarily
140                 setConfigEntry('DEFAULT_LANG', 'de');
141         } // END - if
142
143         // Is the file there?
144         if (isIncludeReadable($languageInclude)) {
145                 // Load language file
146                 loadIncludeOnce($languageInclude);
147         } elseif ((isDebugModeEnabled()) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme')) {
148                 // No language file is not so good...
149                 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no language file or we cannot read from it. lang=%s",
150                         $ext_name, getLanguage()
151                 ));
152         }
153
154         // Check for installation mode
155         if ((isInstalling()) || (!isInstalled()) || (!isAdminRegistered())) {
156                 // Load matching language file
157                 loadInclude('inc/language/install_' . getSession('mx_lang') . '.php');
158         } // END - if
159 }
160
161 // [EOF]
162 ?>