Double->single converted and fixed a display bug when theme is already installed
[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 // [EOF]
115 ?>