One can only "prepend" something before some other thing, not "append".
[squirrelmail.git] / src / style.php
index 2114787306921aefee0dd3d6b7c851e7e736003d..1e2334a700a27e5f2a80afcca9c613256710768f 100644 (file)
@@ -6,6 +6,7 @@
  * Used GET arguments:
  * <ul>
  *   <li>themeid - string, sets theme file from themes/*.php
+ *   <li>templateid - string, sets template directory from templates/
  *   <li>fontset - string, sets selected set of fonts from $fontsets array.
  *   <li>fontsize - integer, sets selected font size
  * </ul>
  * @package squirrelmail
  */
 
-/** @ignore */
-define('SM_PATH','../');
+/**
+ * Set the location in order to skip unneeded validation and other includes
+ * in the SquirrelMail initialisation file.
+ */
+$sInitLocation = 'style';
 
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/strings.php');
-require_once(SM_PATH . 'config/config.php');
-# FIXME: remove it after template setting moved to get request
-require_once(SM_PATH . 'include/load_prefs.php');
+/**
+ * Include the SquirrelMail initialization file.
+ */
+require('../include/init.php');
 
 /* safety check for older config.php */
 if (!isset($fontsets) || !is_array($fontsets)) {
     $fontsets=array();
 }
 
-/* template init */
-/** start block copy from right_main.php */
-include_once(SM_PATH . 'class/template/template.class.php');
+/**
+ *  get template name and set used template directory
+ *
+ *  Existing file check has been moved into the template object, so it is
+ *  not neccesary to do file_exists() here.
+ * */
+if (sqgetGlobalVar('templateid',$templateid,SQ_GET)) {
+    $sTplDir = SM_PATH.'templates/'.basename($templateid).'/';
+} else {
+    $sTplDir = SM_PATH.'templates/default/';
+}
 
 $oTemplate = new Template($sTplDir);
 /** end block copy */
@@ -66,18 +76,13 @@ if (sqgetGlobalVar('themeid',$themeid,SQ_GET) &&
 }
 
 /**
- * TODO: tokul. $languages are not loaded here.
- * get alignment variable from language settings...
- * MOVE THIS to a central init section !!!!
+ * Get text direction
  */
-if (!sqgetGlobalVar('align',$align,SQ_SESSION)) {
-    $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ? $languages[$squirrelmail_language]['DIR'] : 'ltr';
-    if ( $dir == 'ltr' ) {
-        $align = array('left' => 'left', 'right' => 'right');
-    } else {
-        $align = array('left' => 'right', 'right' => 'left');
-    }
-    sqsession_register($align, 'align');
+if (sqgetGlobalVar('dir',$text_direction,SQ_GET) &&
+    $text_direction == 'rtl') {
+    $align = array('left' => 'right', 'right' => 'left');
+} else {
+    $align = array('left' => 'left', 'right' => 'right');
 }
 
 /**/
@@ -153,7 +158,7 @@ define('SQM_ALIGN_RIGHT', $align['right']);
 
 if (sqgetGlobalVar('fontset',$fontset,SQ_GET) &&
     isset($fontsets[$fontset])) {
-    $fontfamily=$fontsets[$fontset]['STYLE'];
+    $fontfamily=$fontsets[$fontset];
 } else {
     $fontfamily='';
 }
@@ -172,7 +177,12 @@ if ( $lastmod = @filemtime($oTemplate->template_dir . 'stylesheet.tpl') ) {
     $gmlastmod = gmdate('D, d M Y H:i:s', $lastmod) . ' GMT';
     header('Last-Modified: ' . $gmlastmod);
 }
-
 $oTemplate->display('stylesheet.tpl');
 
-?>
+/**
+ * Include any additional stylesheets provided by the template
+ */
+$template_css = $oTemplate->getAdditionalStyleSheets();
+foreach ($template_css as $stylesheet) {
+    $oTemplate->display($stylesheet);
+}