Removing check that is no longer needed.
[squirrelmail.git] / include / init.php
index 4f5112fb181a2b38551243f956d1348ef9204507..fb0cc536ecdd5fab1ff33936ffb81449bed279c3 100644 (file)
@@ -158,6 +158,7 @@ if (file_exists(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.
@@ -306,9 +307,6 @@ switch ($sInitLocation) {
 
         // make sure given template actually is available
         //
-        $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet)
-                         ? array() : $aTemplateSet);
-        $templateset_default = (!isset($templateset_default) ? 0 : $templateset_default);
         $found_templateset = false;
         for ($i = 0; $i < count($aTemplateSet); ++$i) {
             if ($aTemplateSet[$i]['ID'] == $templateid) {
@@ -317,12 +315,11 @@ switch ($sInitLocation) {
             }
         }
 
-// FIXME: do we need/want to check here for actual presence of template sets?
+// FIXME: do we need/want to check here for actual (physical) presence of template sets?
         // selected template not available, fall back to default template
         //
         if (!$found_templateset) {
-            $sTemplateID = (!isset($aTemplateSet[$templateset_default]['ID'])
-                            ? 'default' : $aTemplateSet[$templateset_default]['ID']);
+            $sTemplateID = Template::get_default_template_set();
         } else {
             $sTemplateID = $templateid;
         }
@@ -337,6 +334,7 @@ switch ($sInitLocation) {
          * plugins use own pref files.
          */
         require(SM_PATH . 'functions/prefs.php');
+        require(SM_PATH . 'functions/auth.php');
         /* hook loads custom prefs backend plugins */
         $prefs_backend = do_hook_function('prefs_backend');
         if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) {
@@ -351,6 +349,12 @@ switch ($sInitLocation) {
         require(SM_PATH . 'functions/display_messages.php' );
         require(SM_PATH . 'functions/page_header.php');
         require(SM_PATH . 'functions/html.php');
+
+        // reset template file cache
+        //
+        $sTemplateID = Template::get_default_template_set();
+        Template::cache_template_file_hierarchy(TRUE);
+
         /**
          * 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
@@ -400,18 +404,12 @@ switch ($sInitLocation) {
             /**
              * Initialize the template object (logout_error uses it)
              */
-            require(SM_PATH . 'class/template/Template.class.php');
             /*
              * $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.
              */
-            $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) 
-                             ? array() : $aTemplateSet);
-            $templateset_default = ( !isset($templateset_default) ? 0 : $templateset_default );
-
-            $sTemplateID = ( !isset($aTemplateSet[$templateset_default]['ID']) ?
-                             'default' : $aTemplateSet[$templateset_default]['ID'] );
+            $sTemplateID = Template::get_default_template_set();
             $oTemplate = Template::construct_template($sTemplateID);
 
             set_up_language($squirrelmail_language, true);
@@ -530,11 +528,6 @@ switch ($sInitLocation) {
         break;
 }
 
-/**
- * Initialize the template object
- */
-require(SM_PATH . 'class/template/Template.class.php');
-
 /*
  * $sTemplateID is not initialized when a user is not logged in, so we 
  * will use the config file defaults here.  If the neccesary variables 
@@ -544,17 +537,18 @@ require(SM_PATH . 'class/template/Template.class.php');
  * so we shouldn't change it here.
  */
 if (!isset($sTemplateID)) {
-    $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) 
-                     ? array() : $aTemplateSet);
-    $templateset_default = ( !isset($templateset_default) ? 0 : $templateset_default );
-    
-    $sTemplateID = !isset($aTemplateSet[$templateset_default]['ID']) ? 'default' : $aTemplateSet[$templateset_default]['ID'];
+    $sTemplateID = Template::get_default_template_set();
     $icon_theme_path = !$use_icons ? NULL : Template::calculate_template_images_directory($sTemplateID);
 }
-$oTemplate = Template::construct_template($sTemplateID);
+
+// template object may have already been constructed in load_prefs.php
+//
+if (empty($oTemplate)) {
+    $oTemplate = Template::construct_template($sTemplateID);
+}
 
 // We want some variables to always be available to the template
-$always_include = array('sTemplateID', 'icon_theme_path');
+$always_include = array('sTemplateID', 'icon_theme_path', 'javascript_on');
 foreach ($always_include as $var) {
     $oTemplate->assign($var, (isset($$var) ? $$var : NULL));
 }