Source for file init.php
Documentation is available at init.php
-  * init.php -- initialisation file 
-  * File should be loaded in every file in src/ or plugins that occupate an entire frame 
-  * @copyright © 2006 The SquirrelMail Project Team 
-  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
-  * @version $Id: init.php,v 1.28 2006/10/05 21:59:04 stevetruckstuff Exp $ 
-  * This is a development version so in order to track programmer mistakes we 
-  * set the error reporting to E_ALL 
-  * If register_globals are on, unregister globals. 
-  * Second test covers boolean set as string (php_value register_globals off). 
- if (- (bool)  ini_get('register_globals')- && 
 
-      * Remove all globals that are not reserved by PHP 
-      * 'value' and 'key' are used by foreach. Don't unset them inside foreach. 
-     foreach ($GLOBALS as $key - =>  $value) {
 
-         case 'HTTP_SESSION_VARS'- : 
 
-             // FIXME: variable must be set only in src/login.php 
-     // Unset variables used in foreach 
-     unset ($GLOBALS['value']);
-  * [#1518885] session.use_cookies = off breaks SquirrelMail 
-  * When session cookies are not used, all http redirects, meta refreshes, 
-  * src/download.php and javascript URLs are broken. Setting must be set 
-  * before session is started. 
- if (!- (bool) ini_get('session.use_cookies')- || 
 
-     ini_get('session.use_cookies') - ==  'off') {
 
-     ini_set('session.use_cookies','1'); 
-  * calculate SM_PATH and calculate the base_uri 
-  * assumptions made: init.php is only called from plugins or from the src dir. 
-  * files in the plugin directory may not be part of a subdirectory called "src" 
- if (- isset ($_SERVER['SCRIPT_NAME'])) {
 
-     $a - =  explode('/',$_SERVER['SCRIPT_NAME']);
 
- } elseif (- isset ($HTTP_SERVER_VARS['SCRIPT_NAME'])) {
 
-     $a - =  explode('/',$HTTP_SERVER_VARS['SCRIPT_NAME']);
 
-     $error - =  'Unable to detect script environment. '
 
-     . 'Please test your PHP settings and send PHP core config, $_SERVER '
-     . 'and $HTTP_SERVER_VARS to SquirrelMail developers.';
- for($i - =  count($a)- - 2;$i- > - 1;- -- $i) {
 
-     if ($a[$i] - ===  'src'- ||  $a[$i]- ===  'plugins') {
 
- define('SM_BASE_URI', $base_uri); 
-  * global var $bInit is used to check if initialisation took place. 
-  * At this moment it's a workarounf for the include of addrbook_search_html 
-  * inside compose.php. If we found a better way then remove this. Do only use 
-  * this var if you know for sure a page can be called stand alone and be included 
-  * This theme as a failsafe if no themes were found, or if we error 
-  * out before anything could be initialised. 
- $color[0]  - =  '#DCDCDC';  /* light gray    TitleBar               */
 
- $color[1]  - =  '#800000';  /* red                                  */
 
- $color[2]  - =  '#CC0000';  /* light red     Warning/Error Messages */
 
- $color[3]  - =  '#A0B8C8';  /* green-blue    Left Bar Background    */
 
- $color[4]  - =  '#FFFFFF';  /* white         Normal Background      */
 
- $color[5]  - =  '#FFFFCC';  /* light yellow  Table Headers          */
 
- $color[6]  - =  '#000000';  /* black         Text on left bar       */
 
- $color[7]  - =  '#0000CC';  /* blue          Links                  */
 
- $color[8]  - =  '#000000';  /* black         Normal text            */
 
- $color[9]  - =  '#ABABAB';  /* mid-gray      Darker version of #0   */
 
- $color[10] - =  '#666666';  /* dark gray     Darker version of #9   */
 
- $color[11] - =  '#770000';  /* dark red      Special Folders color  */
 
- $color[13] - =  '#800000';  /* (dark red)    Color for quoted text -- > 1 quote */
 
- $color[14] - =  '#ff0000';  /* (red)         Color for quoted text -- >> 2 or more */
 
- $color[15] - =  '#002266';  /* (dark blue)   Unselectable folders */
 
- $color[16] - =  '#ff9933';  /* (orange)      Highlight color */
 
- require (SM_PATH- .  'functions/global.php');
- require (SM_PATH- .  'functions/arrays.php');
- /* load default configuration */ 
- require (SM_PATH- .  'config/config_default.php');
- /* reset arrays in default configuration */ 
- $theme[0]['PATH'] - =  SM_PATH- .  'themes/default_theme.php';
 
- $theme[0]['NAME'] - =  'Default';
 
- $aTemplateSet[0]['ID'] - =  'default';
 
- $aTemplateSet[0]['NAME'] - =  'Default';
 
- /* load site configuration */ 
- require (SM_PATH- .  'config/config.php');
- /* load local configuration overrides */ 
-     require (SM_PATH- .  'config/config_local.php');
- require (SM_PATH- .  'functions/plugin.php');
- require (SM_PATH- .  'include/constants.php');
- require (SM_PATH- .  'include/languages.php');
- require (SM_PATH- .  'class/template/Template.class.php');
-  * If magic_quotes_runtime is on, SquirrelMail breaks in new and creative ways. 
-  * Force magic_quotes_runtime off. 
-  * If there's a better place, please let me know. 
- ini_set('magic_quotes_runtime','0'); 
- /* if running with magic_quotes_gpc then strip the slashes 
-    from POST and GET global arrays */ 
- /* strip any tags added to the url from PHP_SELF. 
- This fixes hand crafted url XXS expoits for any 
-    page that uses PHP_SELF as the FORM action */ 
- $_SERVER['PHP_SELF'] - =  strip_tags($_SERVER['PHP_SELF']);
 
- /** set the name of the session cookie */ 
- if (!- isset ($session_name)- ||  !$session_name) {
 
-     $session_name - =  'SQMSESSID';
 
-  * if session.auto_start is On then close the session 
- if ((- isset ($sSessionAutostartName)- ||  $sSessionAutostartName- ==  '')- && 
 
-      $sSessionAutostartName - !==  $session_name) {
 
-     $sCookiePath - =  ini_get('session.cookie_path');
 
-     $sCookieDomain - =  ini_get('session.cookie_domain');
 
-         setcookie($sSessionAutostartName,'',time() - -  604800,$sCookiePath,$sCookieDomain);
 
-  * includes from classes stored in the session 
- require (SM_PATH- .  'class/mime.class.php');
- ini_set('session.name' , $session_name); 
-  * Remove globalized session data in rg=on setups 
-  * Code can be utilized when session is started, but data is not loaded. 
-  * We have already loaded configuration and other important vars. Can't 
-  * clean session globals here. 
- if ((bool) @ini_get('register_globals') && 
-     strtolower(ini_get('register_globals'))!='off') { 
-     foreach ($_SESSION as $key => $value) { 
-  * SquirrelMail version number -- DO NOT CHANGE 
- $version - =  '1.5.2 [CVS]';
 
-  * SquirrelMail internal version number -- DO NOT CHANGE 
-  * $sm_internal_version = array (release, major, minor) 
- $SQM_INTERNAL_VERSION - =  array(1,5,2);
 
-  * Retrieve the language cookie 
-     $squirrelmail_language - =  '';
 
-  * @var $sInitlocation From where do we include. 
- if (!- isset ($sInitLocation)) {
 
-  * MAIN PLUGIN LOADING CODE HERE 
-  * Include Compatibility plugin if available. 
-     include_once(SM_PATH - .  'plugins/compatibility/functions.php');
 
- $squirrelmail_plugin_hooks - =  array();
 
- /* On init, register all plugins configured for use. */ 
- if (- isset ($plugins)- &&  is_array($plugins)) {
 
-     // turn on output buffering in order to prevent output of new lines 
-     foreach ($plugins as $name) { 
-     // get output and remove whitespace 
-     // if plugins output more than newlines and spacing, stop script execution. 
-  * Before 1.5.2 version hook was part of functions/constants.php. 
-  * After init layout changes, hook had to be moved because include/constants.php is 
-  * loaded before plugins are initialized. 
- switch ($sInitLocation) { 
-         // need to get the right template set up 
-                 sqGetGlobalVar('templateid', $templateid, SQ_GET); 
-         // sanitize just in case... 
-                 $templateid - =  preg_replace('/(\.\.\/){1,}/', '', $templateid);
 
-         // make sure given template actually is available 
-                 $found_templateset - =  false;
 
-         for ($i - =  0; $i- <  count($aTemplateSet);- ++ $i) {
 
-             if ($aTemplateSet[$i]['ID'] - ==  $templateid) {
 
-                 $found_templateset - =  true;
 
- // FIXME: do we need/want to check here for actual presence of template sets? 
-         // selected template not available, fall back to default template 
-                 if (!$found_templateset) { 
-             $sTemplateID - =  $templateid;
 
-          * directory hashing functions are needed for all setups in case 
-          * plugins use own pref files. 
-         require (SM_PATH- .  'functions/prefs.php');
-         require (SM_PATH- .  'functions/auth.php');
-         /* hook loads custom prefs backend plugins */ 
-         if (- isset ($prefs_backend)- &&  !empty($prefs_backend)- &&  file_exists(SM_PATH- .  $prefs_backend)) {
 
-             require (SM_PATH- .  $prefs_backend);
-         } elseif (- isset ($prefs_dsn)- &&  !empty($prefs_dsn)) {
 
-             require (SM_PATH- .  'functions/db_prefs.php');
-             require (SM_PATH- .  'functions/file_prefs.php');
-         require (SM_PATH- .  'functions/display_messages.php' );
-         require (SM_PATH- .  'functions/page_header.php');
-         require (SM_PATH- .  'functions/html.php');
-         // reset template file cache 
-          * cleanup old cookies with a cookie path the same as the standard php.ini 
-          * cookie path. All previous SquirrelMail version used the standard php.ini 
-          * cookie path for storing the session name. That behaviour changed. 
-              * do not delete the standard sessions with session.name is i.e. PHPSESSID 
-              * because they probably belong to other php apps 
-             if (ini_get('session.name') - !==  $sSessionAutostartName) {
 
-         require (SM_PATH- .  'functions/display_messages.php' );
-         require (SM_PATH- .  'functions/page_header.php');
-         require (SM_PATH- .  'functions/html.php');
-         require (SM_PATH- .  'functions/strings.php');
-          * Check if we are logged in 
-         require (SM_PATH- .  'functions/auth.php');
-             //  First we store some information in the new session to prevent 
-                         $session_expired_post - =  $_POST;
 
-             $session_expired_location - =  $PHP_SELF;
 
-             // signout page will deal with users who aren't logged 
-             // in on its own; don't show error here 
-                         if (strpos($PHP_SELF, 'signout.php') - !==  FALSE) {
 
-              * Initialize the template object (logout_error uses it) 
-              * $sTemplateID is not initialized when a user is not logged in, so we  
-              * will use the config file defaults here.  If the neccesary variables  
-              * are net set, force a default value. 
-          * Setting the prefs backend 
-             $prefs_are_cached - =  false;
 
-             $prefs_cache - =  false; //array();
 
-         /* see 'redirect' case */ 
-         require (SM_PATH- .  'functions/prefs.php');
-         if (- isset ($prefs_backend)- &&  !empty($prefs_backend)- &&  file_exists(SM_PATH- .  $prefs_backend)) {
 
-             require (SM_PATH- .  $prefs_backend);
-         } elseif (- isset ($prefs_dsn)- &&  !empty($prefs_dsn)) {
 
-             require (SM_PATH- .  'functions/db_prefs.php');
-             require (SM_PATH- .  'functions/file_prefs.php');
-          * initializing user settings 
-         require (SM_PATH- .  'include/load_prefs.php');
- // i do not understand the frames language cookie story 
-          * We'll need this to later have a noframes version 
-          * Check if the user has a language preference, but no cookie. 
-          * Send him a cookie with his language preference, if there is 
-          $my_language - =  getPref($data_dir, $username, 'language');
 
-          if ($my_language - !=  $squirrelmail_language) {
 
-              sqsetcookie('squirrelmail_language', $my_language, time()- + 2592000, $base_uri);
 
-         /* this is the last cookie we set so flush it. */ 
-         // Japanese translation used without mbstring support 
-                 "<p>You need to have PHP installed with the multibyte string function \n"- . 
 
-                 "enabled (using configure option --enable-mbstring).</p>\n"- . 
 
-                 "<p>System assumed that you accidently switched to Japanese translation \n"- . 
 
-                 "and reverted your language preference to English.</p>\n"- . 
 
-                 "<p>Please refresh this page in order to use webmail.</p>\n"; 
-         $timeZone - =  getPref($data_dir, $username, 'timezone');
 
-         /* Check to see if we are allowed to set the TZ environment variable. 
-          * We are able to do this if ... 
-          *   safe_mode is disabled OR 
-          *   safe_mode_allowed_env_vars is empty (you are allowed to set any) OR 
-          *   safe_mode_allowed_env_vars contains TZ 
-         $tzChangeAllowed - =  (!ini_get('safe_mode'))- || 
 
-             // get time zone key, if strict or custom strict timezones are used 
-                         if (- isset ($time_zone_type)- && 
 
-                 ($time_zone_type - ==  1- ||  $time_zone_type- ==  3)) {
 
-                 /* load time zone functions */ 
-                 require (SM_PATH- .  'include/timezones.php');
-                 $realTimeZone - =  $timeZone;
 
-          * php 5.1.0 added time zone functions. Set time zone with them in order 
-          * to prevent E_STRICT notices and allow time zone modifications in safe_mode. 
-                 date_default_timezone_set($timeZone); 
-                 // interface runs on server's time zone. Remove php E_STRICT complains 
-                                 $default_timezone - =  @date_default_timezone_get();
 
-                 date_default_timezone_set($default_timezone);         
-  * $sTemplateID is not initialized when a user is not logged in, so we  
-  * will use the config file defaults here.  If the neccesary variables  
-  * are not set, force a default value. 
-  * If the user is logged in, $sTemplateID will be set in load_prefs.php,  
-  * so we shouldn't change it here. 
- if (!- isset ($sTemplateID)) {
 
- // We want some variables to always be available to the template 
- $always_include - =  array('sTemplateID', 'icon_theme_path', 'javascript_on');
 
- foreach ($always_include as $var) { 
-     $oTemplate->assign($var, (- isset (- $ $var)- ? $ $var- :  NULL));
 
-  * Initialize our custom error handler object 
- require (SM_PATH- .  'class/error.class.php');
- $oErrorHandler - =  new ErrorHandler($oTemplate,'error_message.tpl');
 
-  * Activate custom error handling 
-     $oldErrorHandler - =  set_error_handler(array($oErrorHandler, 'SquirrelMailErrorhandler'));
 
-  * Javascript support detection function 
-  * @param boolean $reset recheck javascript support if set to true. 
-  * @return integer SMPREF_JS_ON or SMPREF_JS_OFF ({@see include/constants.php}) 
-   global $data_dir, $username, $javascript_on, $javascript_setting; 
-   if ( !$reset - &&  sqGetGlobalVar('javascript_on', $javascript_on, SQ_SESSION) )
 
-   if ( $reset - ||  !- isset ($javascript_setting) )
 
-   if ( !sqGetGlobalVar('new_js_autodetect_results', $js_autodetect_results) - && 
 
-        !sqGetGlobalVar('js_autodetect_results', $js_autodetect_results) ) 
-     $javascript_on - =  $js_autodetect_results;
 
-     $javascript_on - =  $javascript_setting;
 
 
	
		Documentation generated on Sat, 07 Oct 2006 16:11:53 +0300 by phpDocumentor 1.3.0RC6