Added rest of translation pairs of systran.otenet.gr, besides greek pairs.
[squirrelmail.git] / functions / global.php
1 <?php
2
3 /**
4 * global.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This includes code to update < 4.1.0 globals to the newer format
10 * It also has some session register functions that work across various
11 * php versions.
12 *
13 * $Id$
14 */
15
16 require_once(SM_PATH . 'config/config.php');
17
18 /* set the name of the session cookie */
19 if(isset($session_name) && $session_name) {
20 ini_set('session.name' , $session_name);
21 } else {
22 ini_set('session.name' , 'SQMSESSID');
23 }
24
25 /* If magic_quotes_runtime is on, SquirrelMail breaks in new and creative ways.
26 * Force magic_quotes_runtime off.
27 * tassium@squirrelmail.org - I put it here in the hopes that all SM code includes this.
28 * If there's a better place, please let me know.
29 */
30 ini_set('magic_quotes_runtime','0');
31
32 /* Since we decided all IMAP servers must implement the UID command as defined in
33 * the IMAP RFC, we force $uid_support to be on.
34 */
35
36 global $uid_support;
37 $uid_support = true;
38
39 sqsession_is_active();
40
41 /* convert old-style superglobals to current method
42 * this is executed if you are running PHP 4.0.x.
43 * it is run via a require_once directive in validate.php
44 * and redirect.php. Patch submitted by Ray Black.
45 */
46
47 if ( !check_php_version(4,1) ) {
48 global $_COOKIE, $_ENV, $_FILES, $_GET, $_POST, $_SERVER, $_SESSION;
49 global $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_GET_VARS,
50 $HTTP_POST_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS, $PHP_SELF;
51 $_COOKIE =& $HTTP_COOKIE_VARS;
52 $_ENV =& $HTTP_ENV_VARS;
53 $_FILES =& $HTTP_POST_FILES;
54 $_GET =& $HTTP_GET_VARS;
55 $_POST =& $HTTP_POST_VARS;
56 $_SERVER =& $HTTP_SERVER_VARS;
57 $_SESSION =& $HTTP_SESSION_VARS;
58 if (!isset($PHP_SELF) || empty($PHP_SELF)) {
59 $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
60 }
61 }
62
63 /* if running with magic_quotes_gpc then strip the slashes
64 from POST and GET global arrays */
65
66 if (get_magic_quotes_gpc()) {
67 sqstripslashes($_GET);
68 sqstripslashes($_POST);
69 }
70
71 /* strip any tags added to the url from PHP_SELF.
72 This fixes hand crafted url XXS expoits for any
73 page that uses PHP_SELF as the FORM action */
74
75 $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
76
77 /**
78 * returns true if current php version is at mimimum a.b.c
79 *
80 * Called: check_php_version(4,1)
81 */
82 function check_php_version ($a = '0', $b = '0', $c = '0')
83 {
84 global $SQ_PHP_VERSION;
85
86 if(!isset($SQ_PHP_VERSION))
87 $SQ_PHP_VERSION = substr( str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'), 0, 3);
88
89 return $SQ_PHP_VERSION >= ($a.$b.$c);
90 }
91
92 /**
93 * returns true if the current internal SM version is at minimum a.b.c
94 * These are plain integer comparisons, as our internal version is
95 * constructed by us, as an array of 3 ints.
96 *
97 * Called: check_sm_version(1,3,3)
98 */
99 function check_sm_version($a = 0, $b = 0, $c = 0)
100 {
101 global $SQM_INTERNAL_VERSION;
102 if ( !isset($SQM_INTERNAL_VERSION) ||
103 $SQM_INTERNAL_VERSION[0] < $a ||
104 $SQM_INTERNAL_VERSION[1] < $b ||
105 ( $SQM_INTERNAL_VERSION[1] == $b &&
106 $SQM_INTERNAL_VERSION[2] < $c ) ) {
107 return FALSE;
108 }
109 return TRUE;
110 }
111
112
113 /* recursively strip slashes from the values of an array */
114 function sqstripslashes(&$array) {
115 if(count($array) > 0) {
116 foreach ($array as $index=>$value) {
117 if (is_array($array[$index])) {
118 sqstripslashes($array[$index]);
119 }
120 else {
121 $array[$index] = stripslashes($value);
122 }
123 }
124 }
125 }
126
127 function sqsession_register ($var, $name) {
128
129 sqsession_is_active();
130
131 if ( !check_php_version(4,1) ) {
132 global $HTTP_SESSION_VARS;
133 $HTTP_SESSION_VARS[$name] = $var;
134 }
135 else {
136 $_SESSION["$name"] = $var;
137 }
138 session_register("$name");
139 }
140
141 function sqsession_unregister ($name) {
142
143 sqsession_is_active();
144
145 if ( !check_php_version(4,1) ) {
146 global $HTTP_SESSION_VARS;
147 unset($HTTP_SESSION_VARS[$name]);
148 }
149 else {
150 unset($_SESSION[$name]);
151 }
152 session_unregister("$name");
153 }
154
155 function sqsession_is_registered ($name) {
156 $test_name = &$name;
157 $result = false;
158 if ( !check_php_version(4,1) ) {
159 global $HTTP_SESSION_VARS;
160 if (isset($HTTP_SESSION_VARS[$test_name])) {
161 $result = true;
162 }
163 }
164 else {
165 if (isset($_SESSION[$test_name])) {
166 $result = true;
167 }
168 }
169 return $result;
170 }
171
172
173 define('SQ_INORDER',0);
174 define('SQ_GET',1);
175 define('SQ_POST',2);
176 define('SQ_SESSION',3);
177 define('SQ_COOKIE',4);
178 define('SQ_SERVER',5);
179 define('SQ_FORM',6);
180
181 /**
182 * Search for the var $name in $_SESSION, $_POST, $_GET,
183 * $_COOKIE, or $_SERVER and set it in provided var.
184 *
185 * If $search is not provided, or == SQ_INORDER, it will search
186 * $_SESSION, then $_POST, then $_GET. Otherwise,
187 * use one of the defined constants to look for
188 * a var in one place specifically.
189 *
190 * Note: $search is an int value equal to one of the
191 * constants defined above.
192 *
193 * example:
194 * sqgetGlobalVar('username',$username,SQ_SESSION);
195 * -- no quotes around last param!
196 *
197 * Returns FALSE if variable is not found.
198 * Returns TRUE if it is.
199 */
200 function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) {
201
202 if ( !check_php_version(4,1) ) {
203 global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS,
204 $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;
205
206 $_COOKIE =& $HTTP_COOKIE_VARS;
207 $_GET =& $HTTP_GET_VARS;
208 $_POST =& $HTTP_POST_VARS;
209 $_SERVER =& $HTTP_SERVER_VARS;
210 $_SESSION =& $HTTP_SESSION_VARS;
211 }
212
213 /* NOTE: DO NOT enclose the constants in the switch
214 statement with quotes. They are constant values,
215 enclosing them in quotes will cause them to evaluate
216 as strings. */
217 switch ($search) {
218 /* we want the default case to be first here,
219 so that if a valid value isn't specified,
220 all three arrays will be searched. */
221 default:
222 case SQ_INORDER: // check session, post, get
223 case SQ_SESSION:
224 if( isset($_SESSION[$name]) ) {
225 $value = $_SESSION[$name];
226 return TRUE;
227 } elseif ( $search == SQ_SESSION ) {
228 break;
229 }
230 case SQ_FORM: // check post, get
231 case SQ_POST:
232 if( isset($_POST[$name]) ) {
233 $value = $_POST[$name];
234 return TRUE;
235 } elseif ( $search == SQ_POST ) {
236 break;
237 }
238 case SQ_GET:
239 if ( isset($_GET[$name]) ) {
240 $value = $_GET[$name];
241 return TRUE;
242 }
243 /* NO IF HERE. FOR SQ_INORDER CASE, EXIT after GET */
244 break;
245 case SQ_COOKIE:
246 if ( isset($_COOKIE[$name]) ) {
247 $value = $_COOKIE[$name];
248 return TRUE;
249 }
250 break;
251 case SQ_SERVER:
252 if ( isset($_SERVER[$name]) ) {
253 $value = $_SERVER[$name];
254 return TRUE;
255 }
256 break;
257 }
258 return FALSE;
259 }
260
261 function sqsession_destroy() {
262
263 /*
264 * php.net says we can kill the cookie by setting just the name:
265 * http://www.php.net/manual/en/function.setcookie.php
266 * maybe this will help fix the session merging again.
267 *
268 * Changed the theory on this to kill the cookies first starting
269 * a new session will provide a new session for all instances of
270 * the browser, we don't want that, as that is what is causing the
271 * merging of sessions.
272 */
273
274 global $base_uri;
275
276 if (isset($_COOKIE[session_name()])) setcookie(session_name(), '', time() - 5, $base_uri);
277 if (isset($_COOKIE['username'])) setcookie('username','',time() - 5,$base_uri);
278 if (isset($_COOKIE['key'])) setcookie('key','',time() - 5,$base_uri);
279
280 $sessid = session_id();
281 if (!empty( $sessid )) {
282 if ( !check_php_version(4,1) ) {
283 global $HTTP_SESSION_VARS;
284 $HTTP_SESSION_VARS = array();
285 } else {
286 $_SESSION = array();
287 }
288 @session_destroy();
289 }
290
291 }
292
293 /*
294 * Function to verify a session has been started. If it hasn't
295 * start a session up. php.net doesn't tell you that $_SESSION
296 * (even though autoglobal), is not created unless a session is
297 * started, unlike $_POST, $_GET and such
298 */
299
300 function sqsession_is_active() {
301
302 $sessid = session_id();
303 if ( empty( $sessid ) ) {
304 session_start();
305 }
306 }
307
308
309 ?>