202bcbcc |
1 | <?php |
2 | |
3 | /** |
4 | * init.php -- initialisation file |
5 | * |
6 | * File should be loaded in every file in src/ or plugins that occupate an entire frame |
7 | * |
8 | * @copyright © 2006 The SquirrelMail Project Team |
9 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
10 | * @version $Id$ |
11 | * @package squirrelmail |
12 | */ |
13 | |
202bcbcc |
14 | /** |
15 | * This is a development version so in order to track programmer mistakes we |
16 | * set the error reporting to E_ALL |
17 | */ |
202bcbcc |
18 | error_reporting(E_ALL); |
19 | |
20 | |
6a2a6e44 |
21 | /** |
22 | * If register_globals are on, unregister globals. |
a3b99374 |
23 | * Second test covers boolean set as string (php_value register_globals off). |
6a2a6e44 |
24 | */ |
55dd9abf |
25 | if ((bool) ini_get('register_globals') && |
a3b99374 |
26 | strtolower(ini_get('register_globals'))!='off') { |
6a2a6e44 |
27 | /** |
55dd9abf |
28 | * Remove all globals that are not reserved by PHP |
29 | * 'value' and 'key' are used by foreach. Don't unset them inside foreach. |
6a2a6e44 |
30 | */ |
55dd9abf |
31 | foreach ($GLOBALS as $key => $value) { |
32 | switch($key) { |
33 | case 'HTTP_POST_VARS': |
34 | case '_POST': |
35 | case 'HTTP_GET_VARS': |
36 | case '_GET': |
37 | case 'HTTP_COOKIE_VARS': |
38 | case '_COOKIE': |
39 | case 'HTTP_SERVER_VARS': |
40 | case '_SERVER': |
41 | case 'HTTP_ENV_VARS': |
42 | case '_ENV': |
43 | case 'HTTP_POST_FILES': |
44 | case '_FILES': |
45 | case '_REQUEST': |
46 | case 'HTTP_SESSION_VARS': |
47 | case '_SESSION': |
48 | case 'GLOBALS': |
49 | case 'key': |
50 | case 'value': |
51 | break; |
55dd9abf |
52 | default: |
53 | unset($GLOBALS[$key]); |
54 | } |
6a2a6e44 |
55 | } |
55dd9abf |
56 | // Unset variables used in foreach |
57 | unset($GLOBALS['key']); |
58 | unset($GLOBALS['value']); |
6a2a6e44 |
59 | } |
60 | |
d849b570 |
61 | /** |
62 | * Used as a dummy value, e.g., for passing as an empty |
e39d00e9 |
63 | * hook argument (where the value is passed by reference, |
64 | * and therefore NULL itself is not acceptable). |
d849b570 |
65 | */ |
086ad092 |
66 | global $null; |
d849b570 |
67 | $null = NULL; |
68 | |
71efd1ed |
69 | /** |
70 | * [#1518885] session.use_cookies = off breaks SquirrelMail |
71 | * |
086ad092 |
72 | * When session cookies are not used, all http redirects, meta refreshes, |
73 | * src/download.php and javascript URLs are broken. Setting must be set |
71efd1ed |
74 | * before session is started. |
75 | */ |
76 | if (!(bool)ini_get('session.use_cookies') || |
77 | ini_get('session.use_cookies') == 'off') { |
78 | ini_set('session.use_cookies','1'); |
79 | } |
6a2a6e44 |
80 | |
202bcbcc |
81 | /** |
82 | * calculate SM_PATH and calculate the base_uri |
83 | * assumptions made: init.php is only called from plugins or from the src dir. |
84 | * files in the plugin directory may not be part of a subdirectory called "src" |
85 | * |
86 | */ |
87 | if (isset($_SERVER['SCRIPT_NAME'])) { |
88 | $a = explode('/',$_SERVER['SCRIPT_NAME']); |
89 | } elseif (isset($HTTP_SERVER_VARS['SCRIPT_NAME'])) { |
b0829edf |
90 | $a = explode('/',$HTTP_SERVER_VARS['SCRIPT_NAME']); |
91 | } else { |
92 | $error = 'Unable to detect script environment. ' |
93 | .'Please test your PHP settings and send PHP core config, $_SERVER ' |
94 | .'and $HTTP_SERVER_VARS to SquirrelMail developers.'; |
95 | die($error); |
202bcbcc |
96 | } |
97 | $sSM_PATH = ''; |
98 | for($i = count($a) -2;$i > -1; --$i) { |
99 | $sSM_PATH .= '../'; |
100 | if ($a[$i] === 'src' || $a[$i] === 'plugins') { |
101 | break; |
102 | } |
103 | } |
104 | |
105 | $base_uri = implode('/',array_slice($a,0,$i)). '/'; |
106 | |
202bcbcc |
107 | define('SM_PATH',$sSM_PATH); |
6a2a6e44 |
108 | define('SM_BASE_URI', $base_uri); |
202bcbcc |
109 | /** |
110 | * global var $bInit is used to check if initialisation took place. |
111 | * At this moment it's a workarounf for the include of addrbook_search_html |
112 | * inside compose.php. If we found a better way then remove this. Do only use |
113 | * this var if you know for sure a page can be called stand alone and be included |
114 | * in another file. |
115 | */ |
116 | $bInit = true; |
117 | |
8e1e2794 |
118 | /** |
119 | * This theme as a failsafe if no themes were found, or if we error |
120 | * out before anything could be initialised. |
121 | */ |
122 | $color = array(); |
123 | $color[0] = '#DCDCDC'; /* light gray TitleBar */ |
124 | $color[1] = '#800000'; /* red */ |
125 | $color[2] = '#CC0000'; /* light red Warning/Error Messages */ |
126 | $color[3] = '#A0B8C8'; /* green-blue Left Bar Background */ |
127 | $color[4] = '#FFFFFF'; /* white Normal Background */ |
128 | $color[5] = '#FFFFCC'; /* light yellow Table Headers */ |
129 | $color[6] = '#000000'; /* black Text on left bar */ |
130 | $color[7] = '#0000CC'; /* blue Links */ |
131 | $color[8] = '#000000'; /* black Normal text */ |
132 | $color[9] = '#ABABAB'; /* mid-gray Darker version of #0 */ |
133 | $color[10] = '#666666'; /* dark gray Darker version of #9 */ |
134 | $color[11] = '#770000'; /* dark red Special Folders color */ |
135 | $color[12] = '#EDEDED'; |
136 | $color[13] = '#800000'; /* (dark red) Color for quoted text -- > 1 quote */ |
137 | $color[14] = '#ff0000'; /* (red) Color for quoted text -- >> 2 or more */ |
138 | $color[15] = '#002266'; /* (dark blue) Unselectable folders */ |
139 | $color[16] = '#ff9933'; /* (orange) Highlight color */ |
140 | |
202bcbcc |
141 | require(SM_PATH . 'functions/global.php'); |
918fcc1d |
142 | require(SM_PATH . 'functions/arrays.php'); |
5e68a08e |
143 | |
144 | /* load default configuration */ |
145 | require(SM_PATH . 'config/config_default.php'); |
146 | /* reset arrays in default configuration */ |
147 | $ldap_server = array(); |
148 | $plugins = array(); |
149 | $fontsets = array(); |
5e68a08e |
150 | $aTemplateSet = array(); |
28294310 |
151 | $aTemplateSet[0]['ID'] = 'default'; |
152 | $aTemplateSet[0]['NAME'] = 'Default'; |
01fd1d1a |
153 | |
5e68a08e |
154 | /* load site configuration */ |
202bcbcc |
155 | require(SM_PATH . 'config/config.php'); |
5e68a08e |
156 | /* load local configuration overrides */ |
157 | if (file_exists(SM_PATH . 'config/config_local.php')) { |
158 | require(SM_PATH . 'config/config_local.php'); |
159 | } |
160 | |
202bcbcc |
161 | require(SM_PATH . 'functions/plugin.php'); |
162 | require(SM_PATH . 'include/constants.php'); |
163 | require(SM_PATH . 'include/languages.php'); |
42b5e8aa |
164 | require(SM_PATH . 'class/template/Template.class.php'); |
5ab684a5 |
165 | require(SM_PATH . 'class/error.class.php'); |
202bcbcc |
166 | |
167 | /** |
168 | * If magic_quotes_runtime is on, SquirrelMail breaks in new and creative ways. |
169 | * Force magic_quotes_runtime off. |
170 | * tassium@squirrelmail.org - I put it here in the hopes that all SM code includes this. |
171 | * If there's a better place, please let me know. |
172 | */ |
173 | ini_set('magic_quotes_runtime','0'); |
174 | |
175 | |
176 | /* if running with magic_quotes_gpc then strip the slashes |
177 | from POST and GET global arrays */ |
178 | if (get_magic_quotes_gpc()) { |
179 | sqstripslashes($_GET); |
180 | sqstripslashes($_POST); |
181 | } |
182 | |
202bcbcc |
183 | |
184 | /* strip any tags added to the url from PHP_SELF. |
185 | This fixes hand crafted url XXS expoits for any |
186 | page that uses PHP_SELF as the FORM action */ |
187 | $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']); |
188 | |
189 | $PHP_SELF = php_self(); |
190 | |
191 | /** |
192 | * Initialize the session |
193 | */ |
194 | |
e8c4e350 |
195 | /** set the name of the session cookie */ |
196 | if (!isset($session_name) || !$session_name) { |
197 | $session_name = 'SQMSESSID'; |
198 | } |
199 | |
200 | /** |
201 | * if session.auto_start is On then close the session |
1d537493 |
202 | */ |
203 | $sSessionAutostartName = session_name(); |
bf6140e3 |
204 | $sCookiePath = null; |
1d537493 |
205 | if ((isset($sSessionAutostartName) || $sSessionAutostartName == '') && |
206 | $sSessionAutostartName !== $session_name) { |
207 | $sCookiePath = ini_get('session.cookie_path'); |
208 | $sCookieDomain = ini_get('session.cookie_domain'); |
e8c4e350 |
209 | // reset the cookie |
1d537493 |
210 | setcookie($sSessionAutostartName,'',time() - 604800,$sCookiePath,$sCookieDomain); |
e8c4e350 |
211 | @session_destroy(); |
212 | session_write_close(); |
1d537493 |
213 | } |
e8c4e350 |
214 | |
202bcbcc |
215 | /** |
216 | * includes from classes stored in the session |
217 | */ |
218 | require(SM_PATH . 'class/mime.class.php'); |
219 | |
202bcbcc |
220 | ini_set('session.name' , $session_name); |
221 | session_set_cookie_params (0, $base_uri); |
222 | sqsession_is_active(); |
223 | |
5aed95be |
224 | /** |
225 | * SquirrelMail internal version number -- DO NOT CHANGE |
226 | * $sm_internal_version = array (release, major, minor) |
227 | */ |
a895042a |
228 | $SQM_INTERNAL_VERSION = explode('.', SM_VERSION, 3); |
b37e457f |
229 | $SQM_INTERNAL_VERSION[2] = intval($SQM_INTERNAL_VERSION[2]); |
5aed95be |
230 | |
93d67e0d |
231 | |
086ad092 |
232 | /* if plugins are disabled only for one user and |
93d67e0d |
233 | * the current user is NOT that user, turn them |
234 | * back on |
235 | */ |
236 | sqgetGlobalVar('username',$username,SQ_SESSION); |
237 | if ($disable_plugins && !empty($disable_plugins_user) |
238 | && $username != $disable_plugins_user) { |
239 | $disable_plugins = false; |
240 | } |
241 | |
242 | /* remove all plugins if they are disabled */ |
243 | if ($disable_plugins) { |
244 | $plugins = array(); |
245 | } |
246 | |
247 | |
5aed95be |
248 | /** |
249 | * Include Compatibility plugin if available. |
250 | */ |
93d67e0d |
251 | if (!$disable_plugins && file_exists(SM_PATH . 'plugins/compatibility/functions.php')) |
5aed95be |
252 | include_once(SM_PATH . 'plugins/compatibility/functions.php'); |
253 | |
254 | /** |
255 | * MAIN PLUGIN LOADING CODE HERE |
086ad092 |
256 | * On init, we no longer need to load all plugin setup files. |
5aed95be |
257 | * Now, we load the statically generated hook registrations here |
258 | * and let the hook calls include only the plugins needed. |
259 | */ |
260 | $squirrelmail_plugin_hooks = array(); |
93d67e0d |
261 | if (!$disable_plugins && file_exists(SM_PATH . 'config/plugin_hooks.php')) { |
5aed95be |
262 | require(SM_PATH . 'config/plugin_hooks.php'); |
263 | } |
264 | |
265 | /** |
266 | * allow plugins to override main configuration; hook is placed |
267 | * here to allow plugins to use session information to do their work |
268 | */ |
d849b570 |
269 | do_hook('config_override', $null); |
5aed95be |
270 | |
202bcbcc |
271 | /** |
3464e1f4 |
272 | * DISABLED. |
202bcbcc |
273 | * Remove globalized session data in rg=on setups |
086ad092 |
274 | * |
3464e1f4 |
275 | * Code can be utilized when session is started, but data is not loaded. |
086ad092 |
276 | * We have already loaded configuration and other important vars. Can't |
3464e1f4 |
277 | * clean session globals here. |
278 | if ((bool) @ini_get('register_globals') && |
279 | strtolower(ini_get('register_globals'))!='off') { |
202bcbcc |
280 | foreach ($_SESSION as $key => $value) { |
281 | unset($GLOBALS[$key]); |
282 | } |
283 | } |
3464e1f4 |
284 | */ |
6a2a6e44 |
285 | |
826ddd72 |
286 | sqsession_register(SM_BASE_URI,'base_uri'); |
6a2a6e44 |
287 | |
202bcbcc |
288 | /** |
289 | * Retrieve the language cookie |
290 | */ |
291 | if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE)) { |
292 | $squirrelmail_language = ''; |
293 | } |
294 | |
202bcbcc |
295 | /** |
9e06a3ea |
296 | * Do something special for some pages. This is based on the PAGE_NAME constand |
297 | * set at the top of every page. |
202bcbcc |
298 | */ |
9e06a3ea |
299 | if ( !defined('PAGE_NAME') ) define('PAGE_NAME', NULL); |
300 | switch (PAGE_NAME) { |
086ad092 |
301 | case 'style': |
c4e5f61f |
302 | |
2b26084f |
303 | // need to get the right template set up |
28294310 |
304 | // |
305 | sqGetGlobalVar('templateid', $templateid, SQ_GET); |
c4e5f61f |
306 | |
2b26084f |
307 | // sanitize just in case... |
28294310 |
308 | // |
309 | $templateid = preg_replace('/(\.\.\/){1,}/', '', $templateid); |
310 | |
311 | // make sure given template actually is available |
312 | // |
28294310 |
313 | $found_templateset = false; |
314 | for ($i = 0; $i < count($aTemplateSet); ++$i) { |
315 | if ($aTemplateSet[$i]['ID'] == $templateid) { |
316 | $found_templateset = true; |
317 | break; |
318 | } |
319 | } |
c4e5f61f |
320 | |
be155e14 |
321 | // FIXME: do we need/want to check here for actual (physical) presence of template sets? |
28294310 |
322 | // selected template not available, fall back to default template |
323 | // |
324 | if (!$found_templateset) { |
42b5e8aa |
325 | $sTemplateID = Template::get_default_template_set(); |
28294310 |
326 | } else { |
327 | $sTemplateID = $templateid; |
c4e5f61f |
328 | } |
329 | |
2b26084f |
330 | session_write_close(); |
c4e5f61f |
331 | break; |
332 | |
202bcbcc |
333 | case 'redirect': |
4d2f7565 |
334 | /** |
826ddd72 |
335 | * directory hashing functions are needed for all setups in case |
4d2f7565 |
336 | * plugins use own pref files. |
337 | */ |
338 | require(SM_PATH . 'functions/prefs.php'); |
2e616fa4 |
339 | require(SM_PATH . 'functions/auth.php'); |
4d2f7565 |
340 | /* hook loads custom prefs backend plugins */ |
d849b570 |
341 | $prefs_backend = do_hook('prefs_backend', $null); |
202bcbcc |
342 | if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) { |
343 | require(SM_PATH . $prefs_backend); |
344 | } elseif (isset($prefs_dsn) && !empty($prefs_dsn)) { |
345 | require(SM_PATH . 'functions/db_prefs.php'); |
346 | } else { |
202bcbcc |
347 | require(SM_PATH . 'functions/file_prefs.php'); |
348 | } |
349 | //nobreak; |
350 | case 'login': |
351 | require(SM_PATH . 'functions/display_messages.php' ); |
352 | require(SM_PATH . 'functions/page_header.php'); |
353 | require(SM_PATH . 'functions/html.php'); |
42b5e8aa |
354 | |
355 | // reset template file cache |
356 | // |
357 | $sTemplateID = Template::get_default_template_set(); |
358 | Template::cache_template_file_hierarchy(TRUE); |
359 | |
01fd1d1a |
360 | /** |
361 | * Make sure icon variables are setup for the login page. |
362 | */ |
363 | $icon_theme = $icon_themes[$icon_theme_def]['PATH']; |
364 | /* |
365 | * NOTE: The $icon_theme_path var should contain the path to the icon |
366 | * theme to use. If the admin has disabled icons, or the user has |
367 | * set the icon theme to "None," no icons will be used. |
368 | */ |
369 | $icon_theme_path = (!$use_icons || $icon_theme=='none') ? NULL : ($icon_theme == 'template' ? SM_PATH . Template::calculate_template_images_directory($sTemplateID) : $icon_theme); |
370 | |
1d537493 |
371 | /** |
372 | * cleanup old cookies with a cookie path the same as the standard php.ini |
373 | * cookie path. All previous SquirrelMail version used the standard php.ini |
374 | * cookie path for storing the session name. That behaviour changed. |
375 | */ |
376 | if ($sCookiePath !== SM_BASE_URI) { |
377 | /** |
378 | * do not delete the standard sessions with session.name is i.e. PHPSESSID |
379 | * because they probably belong to other php apps |
380 | */ |
381 | if (ini_get('session.name') !== $sSessionAutostartName) { |
30a428c6 |
382 | // This does not work. Sometimes the cookie with SQSESSID=deleted and path / |
383 | // is picked up in webmail.php => login will fail |
384 | //sqsetcookie(ini_get('session.name'),'',0,$sCookiePath); |
1d537493 |
385 | } |
386 | } |
202bcbcc |
387 | break; |
388 | default: |
389 | require(SM_PATH . 'functions/display_messages.php' ); |
390 | require(SM_PATH . 'functions/page_header.php'); |
391 | require(SM_PATH . 'functions/html.php'); |
392 | require(SM_PATH . 'functions/strings.php'); |
393 | |
394 | |
395 | /** |
396 | * Check if we are logged in |
397 | */ |
398 | require(SM_PATH . 'functions/auth.php'); |
399 | |
400 | if ( !sqsession_is_registered('user_is_logged_in') ) { |
401 | // First we store some information in the new session to prevent |
402 | // information-loss. |
403 | // |
404 | $session_expired_post = $_POST; |
405 | $session_expired_location = $PHP_SELF; |
406 | if (!sqsession_is_registered('session_expired_post')) { |
407 | sqsession_register($session_expired_post,'session_expired_post'); |
408 | } |
409 | if (!sqsession_is_registered('session_expired_location')) { |
410 | sqsession_register($session_expired_location,'session_expired_location'); |
411 | } |
412 | // signout page will deal with users who aren't logged |
413 | // in on its own; don't show error here |
414 | // |
9e06a3ea |
415 | if ( PAGE_NAME == 'signout' ) { |
a140422a |
416 | return; |
202bcbcc |
417 | } |
418 | |
8efadc6b |
419 | /** |
420 | * Initialize the template object (logout_error uses it) |
421 | */ |
8efadc6b |
422 | /* |
086ad092 |
423 | * $sTemplateID is not initialized when a user is not logged in, so we |
424 | * will use the config file defaults here. If the neccesary variables |
28294310 |
425 | * are net set, force a default value. |
8efadc6b |
426 | */ |
42b5e8aa |
427 | $sTemplateID = Template::get_default_template_set(); |
28294310 |
428 | $oTemplate = Template::construct_template($sTemplateID); |
8efadc6b |
429 | |
202bcbcc |
430 | set_up_language($squirrelmail_language, true); |
431 | logout_error( _("You must be logged in to access this page.") ); |
432 | exit; |
433 | } |
434 | |
93d67e0d |
435 | //FIXME: remove next line if the placement of the copy of this line above does not prove to be problematic |
202bcbcc |
436 | sqgetGlobalVar('username',$username,SQ_SESSION); |
79524620 |
437 | sqgetGlobalVar('authz',$authz,SQ_SESSION); |
202bcbcc |
438 | |
439 | /** |
440 | * Setting the prefs backend |
441 | */ |
442 | sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION ); |
443 | sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION ); |
444 | |
445 | if ( !sqsession_is_registered('prefs_are_cached') || |
446 | !isset( $prefs_cache) || |
447 | !is_array( $prefs_cache)) { |
448 | $prefs_are_cached = false; |
449 | $prefs_cache = false; //array(); |
450 | } |
451 | |
c4e5f61f |
452 | /* see 'redirect' case */ |
4d2f7565 |
453 | require(SM_PATH . 'functions/prefs.php'); |
454 | |
d849b570 |
455 | $prefs_backend = do_hook('prefs_backend', $null); |
202bcbcc |
456 | if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) { |
457 | require(SM_PATH . $prefs_backend); |
458 | } elseif (isset($prefs_dsn) && !empty($prefs_dsn)) { |
459 | require(SM_PATH . 'functions/db_prefs.php'); |
460 | } else { |
202bcbcc |
461 | require(SM_PATH . 'functions/file_prefs.php'); |
462 | } |
463 | |
464 | /** |
465 | * initializing user settings |
466 | */ |
467 | require(SM_PATH . 'include/load_prefs.php'); |
468 | |
202bcbcc |
469 | // i do not understand the frames language cookie story |
470 | /** |
471 | * We'll need this to later have a noframes version |
472 | * |
473 | * Check if the user has a language preference, but no cookie. |
474 | * Send him a cookie with his language preference, if there is |
475 | * such discrepancy. |
476 | */ |
477 | $my_language = getPref($data_dir, $username, 'language'); |
478 | if ($my_language != $squirrelmail_language) { |
479 | sqsetcookie('squirrelmail_language', $my_language, time()+2592000, $base_uri); |
480 | } |
481 | // /dont understand |
482 | |
483 | /** |
484 | * Set up the language. |
485 | */ |
486 | $err=set_up_language(getPref($data_dir, $username, 'language')); |
202bcbcc |
487 | |
488 | // Japanese translation used without mbstring support |
489 | if ($err==2) { |
490 | $sError = |
491 | "<p>You need to have PHP installed with the multibyte string function \n". |
492 | "enabled (using configure option --enable-mbstring).</p>\n". |
493 | "<p>System assumed that you accidently switched to Japanese translation \n". |
494 | "and reverted your language preference to English.</p>\n". |
495 | "<p>Please refresh this page in order to use webmail.</p>\n"; |
496 | error_box($sError); |
497 | } |
498 | |
499 | $timeZone = getPref($data_dir, $username, 'timezone'); |
500 | |
501 | /* Check to see if we are allowed to set the TZ environment variable. |
502 | * We are able to do this if ... |
503 | * safe_mode is disabled OR |
504 | * safe_mode_allowed_env_vars is empty (you are allowed to set any) OR |
505 | * safe_mode_allowed_env_vars contains TZ |
506 | */ |
507 | $tzChangeAllowed = (!ini_get('safe_mode')) || |
508 | !strcmp(ini_get('safe_mode_allowed_env_vars'),'') || |
509 | preg_match('/^([\w_]+,)*TZ/', ini_get('safe_mode_allowed_env_vars')); |
510 | |
511 | if ( $timeZone != SMPREF_NONE && ($timeZone != "") |
512 | && $tzChangeAllowed ) { |
513 | |
514 | // get time zone key, if strict or custom strict timezones are used |
515 | if (isset($time_zone_type) && |
516 | ($time_zone_type == 1 || $time_zone_type == 3)) { |
517 | /* load time zone functions */ |
518 | require(SM_PATH . 'include/timezones.php'); |
519 | $realTimeZone = sq_get_tz_key($timeZone); |
520 | } else { |
521 | $realTimeZone = $timeZone; |
522 | } |
523 | |
524 | // set time zone |
525 | if ($realTimeZone) { |
526 | putenv("TZ=".$realTimeZone); |
527 | } |
528 | } |
867fed37 |
529 | |
530 | /** |
531 | * php 5.1.0 added time zone functions. Set time zone with them in order |
532 | * to prevent E_STRICT notices and allow time zone modifications in safe_mode. |
533 | */ |
534 | if (function_exists('date_default_timezone_set')) { |
535 | if ($timeZone != SMPREF_NONE && $timeZone != "") { |
536 | date_default_timezone_set($timeZone); |
537 | } else { |
538 | // interface runs on server's time zone. Remove php E_STRICT complains |
539 | $default_timezone = @date_default_timezone_get(); |
086ad092 |
540 | date_default_timezone_set($default_timezone); |
867fed37 |
541 | } |
542 | } |
202bcbcc |
543 | break; |
544 | } |
545 | |
202bcbcc |
546 | /* |
086ad092 |
547 | * $sTemplateID is not initialized when a user is not logged in, so we |
548 | * will use the config file defaults here. If the neccesary variables |
28294310 |
549 | * are not set, force a default value. |
086ad092 |
550 | * |
551 | * If the user is logged in, $sTemplateID will be set in load_prefs.php, |
28294310 |
552 | * so we shouldn't change it here. |
202bcbcc |
553 | */ |
28294310 |
554 | if (!isset($sTemplateID)) { |
42b5e8aa |
555 | $sTemplateID = Template::get_default_template_set(); |
28294310 |
556 | $icon_theme_path = !$use_icons ? NULL : Template::calculate_template_images_directory($sTemplateID); |
3aa46abc |
557 | } |
be155e14 |
558 | |
559 | // template object may have already been constructed in load_prefs.php |
560 | // |
561 | if (empty($oTemplate)) { |
562 | $oTemplate = Template::construct_template($sTemplateID); |
563 | } |
202bcbcc |
564 | |
7aae649d |
565 | // We want some variables to always be available to the template |
e39d00e9 |
566 | $oTemplate->assign('javascript_on', |
567 | (sqGetGlobalVar('user_is_logged_in', $user_is_logged_in, SQ_SESSION) |
568 | ? checkForJavascript() : 0)); |
fe8103c2 |
569 | $oTemplate->assign('base_uri', sqm_baseuri()); |
457e8593 |
570 | $always_include = array('sTemplateID', 'icon_theme_path'); |
7aae649d |
571 | foreach ($always_include as $var) { |
572 | $oTemplate->assign($var, (isset($$var) ? $$var : NULL)); |
573 | } |
574 | |
202bcbcc |
575 | /** |
576 | * Initialize our custom error handler object |
577 | */ |
202bcbcc |
578 | $oErrorHandler = new ErrorHandler($oTemplate,'error_message.tpl'); |
579 | |
580 | /** |
581 | * Activate custom error handling |
582 | */ |
583 | if (version_compare(PHP_VERSION, "4.3.0", ">=")) { |
584 | $oldErrorHandler = set_error_handler(array($oErrorHandler, 'SquirrelMailErrorhandler')); |
585 | } else { |
586 | $oldErrorHandler = set_error_handler('SquirrelMailErrorhandler'); |
587 | } |
588 | |
589 | /** |
590 | * Javascript support detection function |
591 | * @param boolean $reset recheck javascript support if set to true. |
867fed37 |
592 | * @return integer SMPREF_JS_ON or SMPREF_JS_OFF ({@see include/constants.php}) |
202bcbcc |
593 | * @since 1.5.1 |
594 | */ |
202bcbcc |
595 | function checkForJavascript($reset = FALSE) { |
596 | global $data_dir, $username, $javascript_on, $javascript_setting; |
597 | |
598 | if ( !$reset && sqGetGlobalVar('javascript_on', $javascript_on, SQ_SESSION) ) |
599 | return $javascript_on; |
600 | |
e39d00e9 |
601 | $user_is_logged_in = FALSE; |
457e8593 |
602 | if ( ( $reset || !isset($javascript_setting) ) |
086ad092 |
603 | // getPref() not defined (nor is it meaningful) when user not |
457e8593 |
604 | // logged in, but that begs the question if $javascript_on is |
086ad092 |
605 | // not in the session in that case, where do we get it from? |
457e8593 |
606 | && ( sqGetGlobalVar('user_is_logged_in', $user_is_logged_in, SQ_SESSION) |
607 | && $user_is_logged_in) ) |
202bcbcc |
608 | $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT); |
609 | |
610 | if ( !sqGetGlobalVar('new_js_autodetect_results', $js_autodetect_results) && |
611 | !sqGetGlobalVar('js_autodetect_results', $js_autodetect_results) ) |
612 | $js_autodetect_results = SMPREF_JS_OFF; |
613 | |
614 | if ( $javascript_setting == SMPREF_JS_AUTODETECT ) |
615 | $javascript_on = $js_autodetect_results; |
616 | else |
617 | $javascript_on = $javascript_setting; |
618 | |
619 | sqsession_register($javascript_on, 'javascript_on'); |
620 | return $javascript_on; |
621 | } |
622 | |
623 | function sqm_baseuri() { |
624 | global $base_uri; |
625 | return $base_uri; |
8e1e2794 |
626 | } |