Provide View Unsafe Images link on viewing a text/html attachment.
[squirrelmail.git] / src / style.php
index 58c2ad6411fa01aba808d9d1dcec9b96f8bd6643..83744aadcd2ba50f3742c80a751ea6332a4a7240 100644 (file)
@@ -9,6 +9,7 @@
  *   <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
+ *   <li>dir - string, sets text direction variables. Possible values 'rtl' or 'ltr'
  * </ul>
  * @copyright &copy; 2005-2006 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @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');
-require_once(SM_PATH . 'functions/i18n.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 */
-if (sqgetGlobalVar('templateid',$templateid,SQ_GET) &&
-    file_exists(SM_PATH.'templates/'.basename($templateid).'/stylesheet.tpl')) {
+/**
+ *  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/';
@@ -75,18 +77,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');
 }
 
 /**/
@@ -175,12 +172,34 @@ if (! sqgetGlobalVar('fontsize',$fontsize,SQ_GET)) {
 }
 $oTemplate->assign('fontsize', $fontsize);
 
+/**
+ * GOTCHA #1: When sending the headers for caching, we must send Expires,
+ *            Last-Modified, Pragma, and Cache-Control headers.  If we don't PHP 
+ *            weill makeup values that will break the cacheing.
+ * 
+ * GOTCHA #2: If the current template does not contain a template named
+ *            stylesheet.tpl, this cacheing will break because filemtime() won't
+ *            work.  This is a problem e.g. with the default_advanced template
+ *            that inherits CSS properties from the default template but
+ *            doesn't contain stylesheet.tpl itself.
+ * 
+ * TODO: Fix this. :)
+ **/
 header('Content-Type: text/css');
-// output a last-modified header if we can
-if ( $lastmod = @filemtime($oTemplate->template_dir . 'stylesheet.tpl') ) {
+if ( $lastmod = @filemtime(getcwd() .'/'. $oTemplate->template_dir . 'stylesheet.tpl') ) {
     $gmlastmod = gmdate('D, d M Y H:i:s', $lastmod) . ' GMT';
+    $expires = gmdate('D, d M Y H:i:s', strtotime('+1 week')) . ' GMT';
     header('Last-Modified: ' . $gmlastmod);
+    header('Expires: '. $expires);
+    header('Pragma: ');
+    header('Cache-Control: public, must-revalidate');
 }
 $oTemplate->display('stylesheet.tpl');
 
-?>
+/**
+ * Include any additional stylesheets provided by the template
+ */
+$template_css = $oTemplate->getAdditionalStyleSheets();
+foreach ($template_css as $stylesheet) {
+    $oTemplate->display($stylesheet);
+}