templateset_default and templateset_fallback are IDs now, not unpredictable index...
[squirrelmail.git] / class / template / Template.class.php
index 20e82bffece6579452518f05cee4f01cfa7f3187..70705ae20835f4f4e3543f314512ae99b1424656 100644 (file)
@@ -232,10 +232,26 @@ class Template
         $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) 
                          ? array() : $aTemplateSet);
         $templateset_fallback = (!isset($templateset_fallback) 
-                                 ? 0 : $templateset_fallback);
+                                 ? $default : $templateset_fallback);
 
-        return (!empty($aTemplateSet[$templateset_fallback]['ID'])
-                ? $aTemplateSet[$templateset_fallback]['ID'] : $default);
+        // iterate through all template sets, is this a valid skin ID?
+        //
+        $found_it = FALSE;
+        foreach ($aTemplateSet as $aTemplate) {
+            if ($aTemplate['ID'] == $templateset_fallback) {
+                $found_it = TRUE;
+                break;
+            }
+        }
+
+        if ($found_it)
+            return $templateset_fallback;
+
+        // FIXME: note that it is possible for $default to
+        // point to an invalid (nonexistent) template set
+        // and that error will not be caught here
+        //
+        return $default;
 
     }
 
@@ -267,10 +283,26 @@ class Template
         $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet)
                          ? array() : $aTemplateSet);
         $templateset_default = (!isset($templateset_default) 
-                                 ? 0 : $templateset_default);
+                                 ? $default : $templateset_default);
 
-        return (!empty($aTemplateSet[$templateset_default]['ID'])
-                ? $aTemplateSet[$templateset_default]['ID'] : $default);
+        // iterate through all template sets, is this a valid skin ID?
+        //
+        $found_it = FALSE;
+        foreach ($aTemplateSet as $aTemplate) {
+            if ($aTemplate['ID'] == $templateset_default) {
+                $found_it = TRUE;
+                break;
+            }
+        }
+
+        if ($found_it)
+            return $templateset_default;
+
+        // FIXME: note that it is possible for $default to
+        // point to an invalid (nonexistent) template set
+        // and that error will not be caught here
+        //
+        return $default;
 
     }
 
@@ -741,9 +773,9 @@ class Template
             $engine = $this->get_template_config($template_set_id, 
                                                  'template_engine', SQ_PHP_TEMPLATE);
             $file_list = array('plugins/' . $plugin . '/' . $file => array(
-                                                      'PATH'   => $file_path,
-                                                      'SET_ID' => $template_set_id,
-                                                      'ENGINE' => $engine,
+                                         'PATH'   => substr($file_path, strlen(SM_PATH)),
+                                         'SET_ID' => $template_set_id,
+                                         'ENGINE' => $engine,
                                                                           )
                               );
             $this->template_file_cache