One can only "prepend" something before some other thing, not "append".
[squirrelmail.git] / src / style.php
index 41923c9d454c8c90fadbbad7c7773861f4a8159c..1e2334a700a27e5f2a80afcca9c613256710768f 100644 (file)
@@ -1,11 +1,12 @@
 <?php
 /**
  * Style sheet script
- * 
+ *
  * Script processes GET arguments and generates CSS output from stylesheet.tpl.
  * 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','../');
-
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/strings.php');
-require_once(SM_PATH . 'config/config.php');
-
-/* temp setting containing list of font styles. Should go to config.php */
-$fontsets=array();
-$fontsets['sans']['NAME']='Sans';
-$fontsets['sans']['STYLE']='helvetica,arial,sans-serif';
-$fontsets['serif']['NAME']='Serif';
-$fontsets['serif']['STYLE']='serif';
-$fontsets['comicsans']['NAME']='Comic Sans';
-$fontsets['comicsans']['STYLE']='comic sans ms,sans-serif';
-$fontsets['vera']['NAME']='Vera';
-$fontsets['vera']['STYLE']='bitstream vera sans,verdana,sans-serif';
-$fontsets['tahoma']['NAME']='Tahoma';
-$fontsets['tahoma']['STYLE']='tahoma,sans-serif';
-
-/* template init */
-/** start block copy from right_main.php */
-include_once(SM_PATH . 'class/template/template.class.php');
-$sTplDir = SM_PATH . 'templates/default/';
+/**
+ * Set the location in order to skip unneeded validation and other includes
+ * in the SquirrelMail initialisation file.
+ */
+$sInitLocation = 'style';
+
+/**
+ * Include the SquirrelMail initialization file.
+ */
+require('../include/init.php');
+
+/* safety check for older config.php */
+if (!isset($fontsets) || !is_array($fontsets)) {
+    $fontsets=array();
+}
+
+/**
+ *  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 */
 
@@ -71,12 +75,22 @@ if (sqgetGlobalVar('themeid',$themeid,SQ_GET) &&
     include_once($theme[$theme_default]['PATH']);
 }
 
+/**
+ * Get text direction
+ */
+if (sqgetGlobalVar('dir',$text_direction,SQ_GET) &&
+    $text_direction == 'rtl') {
+    $align = array('left' => 'right', 'right' => 'left');
+} else {
+    $align = array('left' => 'left', 'right' => 'right');
+}
+
 /**/
 $oTemplate->assign('color', $color);
 
 /**
  * set color constants in order to use simple names instead of color array
- * 0 - SQM_TEXT_DISABLED, SQM_TITLE_BACKGROUND, SQM_BUTTON_BACKGROUND_DISABLED, 
+ * 0 - SQM_TEXT_DISABLED, SQM_TITLE_BACKGROUND, SQM_BUTTON_BACKGROUND_DISABLED,
  *     SQM_ROW_BACKGROUND_1
  * 1 -
  * 2 - SQM_ERROR_TEXT
@@ -85,8 +99,8 @@ $oTemplate->assign('color', $color);
  * 5 - SQM_ROW_BACKGROUND_HIGHLIGHT, SQM_COLUMN_HEADER_BACKGROUND
  * 6 - SQM_TEXT_STANDARD_LEFT
  * 7 - SQM_TITLE_TEXT, SQM_BLOCK_TITLE_TEXT
- * 8 - SQM_TEXT_STANDARD, SQM_BUTTON_TEXT, SQM_BLOCK_TEXT, SQM_ROW_TEXT_1, 
- *     SQM_ROW_TEXT_2, SQM_ROW_TEXT_HIGHLIGHT, SQM_ROW_TEXT_SELECTED, 
+ * 8 - SQM_TEXT_STANDARD, SQM_BUTTON_TEXT, SQM_BLOCK_TEXT, SQM_ROW_TEXT_1,
+ *     SQM_ROW_TEXT_2, SQM_ROW_TEXT_HIGHLIGHT, SQM_ROW_TEXT_SELECTED,
  *     SQM_COLUMN_HEADER_TEXT
  * 9 - SQM_BUTTON_BACKGROUND
  * 10 - SQM_BLOCK_TITLE
@@ -139,9 +153,12 @@ define('SQM_MESSAGE_QUOTE_2',$color[14]);
 
 define('SQM_ERROR_TEXT',$color[2]);
 
+define('SQM_ALIGN_LEFT', $align['left']);
+define('SQM_ALIGN_RIGHT', $align['right']);
+
 if (sqgetGlobalVar('fontset',$fontset,SQ_GET) &&
     isset($fontsets[$fontset])) {
-    $fontfamily=$fontsets[$fontset]['STYLE'];
+    $fontfamily=$fontsets[$fontset];
 } else {
     $fontfamily='';
 }
@@ -155,7 +172,17 @@ if (! sqgetGlobalVar('fontsize',$fontsize,SQ_GET)) {
 $oTemplate->assign('fontsize', $fontsize);
 
 header('Content-Type: text/css');
-
+// output a last-modified header if we can
+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');
 
-?>
\ No newline at end of file
+/**
+ * Include any additional stylesheets provided by the template
+ */
+$template_css = $oTemplate->getAdditionalStyleSheets();
+foreach ($template_css as $stylesheet) {
+    $oTemplate->display($stylesheet);
+}