Source for file style.php

Documentation is available at style.php

  1. <?php
  2.  
  3. /**
  4.  * Style sheet script
  5.  *
  6.  * Script processes GET arguments and generates CSS output from stylesheet.tpl,
  7.  * which is defined in each template set.
  8.  *
  9.  * Used GET arguments:
  10.  * <ul>
  11.  *   <li>themeid - string, sets theme file from themes/*.php
  12.  *   <li>templateid - string, sets template set ID
  13.  *   <li>fontset - string, sets selected set of fonts from $fontsets array.
  14.  *   <li>fontsize - integer, sets selected font size
  15.  *   <li>dir - string, sets text direction variables. Possible values 'rtl' or 'ltr'
  16.  * </ul>
  17.  * @copyright &copy; 2005-2006 The SquirrelMail Project Team
  18.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  19.  * @version $Id: style.php,v 1.18 2006/10/02 11:46:40 pdontthink Exp $
  20.  * @package squirrelmail
  21.  */
  22.  
  23. /**
  24.  * Set the location in order to skip unneeded validation and other includes
  25.  * in the SquirrelMail initialisation file.
  26.  */
  27. $sInitLocation 'style';
  28.  
  29. /**
  30.  * Include the SquirrelMail initialization file.
  31.  */
  32. require('../include/init.php');
  33.  
  34. /* safety check for older config.php */
  35. if (!isset($fontsets|| !is_array($fontsets)) {
  36.     $fontsets=array();
  37. }
  38.  
  39.  
  40. /**
  41.  * The following code should no longer be neccesary, but it will remain for the
  42.  * time being, just in case.
  43.  *
  44.  * TODO: Remove if no longer needed.
  45.  **/
  46.  
  47. /* set default colors in case color theme is not full */
  48. $color array();
  49. $color[0]   '#dcdcdc'// (light gray)     TitleBar
  50. $color[1]   '#800000'// (red)
  51. $color[2]   '#cc0000'// (light red)      Warning/Error Messages
  52. $color[3]   '#a0b8c8'// (green-blue)     Left Bar Background
  53. $color[4]   '#ffffff'// (white)          Normal Background
  54. $color[5]   '#ffffcc'// (light yellow)   Table Headers
  55. $color[6]   '#000000'// (black)          Text on left bar
  56. $color[7]   '#0000cc'// (blue)           Links
  57. $color[8]   '#000000'// (black)          Normal text
  58. $color[9]   '#ababab'// (mid-gray)       Darker version of #0
  59. $color[10]  '#666666'// (dark gray)      Darker version of #9
  60. $color[11]  '#770000'// (dark red)       Special Folders color
  61. $color[12]  '#ededed'// (light gray)     Alternate color for message list
  62. $color[13]  '#800000'// (dark red)       Color for quoted text -- > 1 quote
  63. $color[14]  '#ff0000'// (red)            Color for quoted text -- >> 2 or more
  64. $color[15]  '#002266'// (dark blue)      Unselectable folders
  65. $color[16]  '#ff9933'// (orange)         Highlight color
  66.  
  67. /**
  68.  * set color constants in order to use simple names instead of color array
  69.  * 0 - SQM_TEXT_DISABLED, SQM_TITLE_BACKGROUND, SQM_BUTTON_BACKGROUND_DISABLED,
  70.  *     SQM_ROW_BACKGROUND_1
  71.  * 1 -
  72.  * 2 - SQM_ERROR_TEXT
  73.  * 3 - SQM_BACKGROUND_LEFT
  74.  * 4 - SQM_BACKGROUND
  75.  * 5 - SQM_ROW_BACKGROUND_HIGHLIGHT, SQM_COLUMN_HEADER_BACKGROUND
  76.  * 6 - SQM_TEXT_STANDARD_LEFT
  77.  * 7 - SQM_TITLE_TEXT, SQM_BLOCK_TITLE_TEXT
  78.  * 8 - SQM_TEXT_STANDARD, SQM_BUTTON_TEXT, SQM_BLOCK_TEXT, SQM_ROW_TEXT_1,
  79.  *     SQM_ROW_TEXT_2, SQM_ROW_TEXT_HIGHLIGHT, SQM_ROW_TEXT_SELECTED,
  80.  *     SQM_COLUMN_HEADER_TEXT
  81.  * 9 - SQM_BUTTON_BACKGROUND
  82.  * 10 - SQM_BLOCK_TITLE
  83.  * 11 - SQM_TEXT_SPECIAL
  84.  * 12 - SQM_BUTTON_BACKGROUND_TEXT, SQM_BLOCK_BACKGROUND, SQM_ROW_BACKGROUND_2
  85.  * 13 - SQM_MESSAGE_QUOTE_1
  86.  * 14 - SQM_MESSAGE_QUOTE_2
  87.  * 15 - SQM_TEXT_HIGHLIGHT
  88.  * 16 - SQM_ROW_BACKGROUND_SELECTED
  89.  */
  90. define('SQM_BACKGROUND',$color[4]);
  91. define('SQM_BACKGROUND_LEFT',$color[3]);
  92.  
  93. define('SQM_TEXT_STANDARD',$color[8]);
  94. define('SQM_TEXT_STANDARD_LEFT',$color[6]);
  95. define('SQM_TEXT_HIGHLIGHT',$color[15]);
  96. define('SQM_TEXT_DISABLED',$color[0]);
  97. define('SQM_TEXT_SPECIAL',$color[11]);
  98.  
  99. define('SQM_LINK',$color[7]);
  100. define('SQM_LINK_LEFT',$color[6]);
  101.  
  102. define('SQM_TITLE_BACKGROUND',$color[0]);
  103. define('SQM_TITLE_TEXT',$color[7]);
  104.  
  105. define('SQM_BUTTON_BACKGROUND',$color[9]);
  106. define('SQM_BUTTON_TEXT',$color[8]);
  107. define('SQM_BUTTON_BACKGROUND_DISABLED',$color[0]);
  108. define('SQM_BUTTON_BACKGROUND_TEXT',$color[12]);
  109.  
  110. define('SQM_BLOCK_BACKGROUND',$color[12]);
  111. define('SQM_BLOCK_TEXT',$color[8]);
  112. define('SQM_BLOCK_TITLE',$color[10]);
  113. define('SQM_BLOCK_TITLE_TEXT',$color[7]);
  114.  
  115. define('SQM_ROW_BACKGROUND_1',$color[0]);
  116. define('SQM_ROW_BACKGROUND_2',$color[12]);
  117. define('SQM_ROW_TEXT_1',$color[8]);
  118. define('SQM_ROW_TEXT_2',$color[8]);
  119. define('SQM_ROW_BACKGROUND_HIGHLIGHT',$color[5]);
  120. define('SQM_ROW_TEXT_HIGHLIGHT',$color[8]);
  121. define('SQM_ROW_BACKGROUND_SELECTED',$color[16]);
  122. define('SQM_ROW_TEXT_SELECTED',$color[8]);
  123.  
  124. define('SQM_COLUMN_HEADER_BACKGROUND',$color[5]);
  125. define('SQM_COLUMN_HEADER_TEXT',$color[8]);
  126.  
  127. define('SQM_MESSAGE_QUOTE_1',$color[13]);
  128. define('SQM_MESSAGE_QUOTE_2',$color[14]);
  129.  
  130. define('SQM_ERROR_TEXT',$color[2]);
  131.  
  132. define('SQM_ALIGN_LEFT'$align['left']);
  133. define('SQM_ALIGN_RIGHT'$align['right']);
  134.  
  135. // END TODO
  136.  
  137. if (sqgetGlobalVar('fontset',$fontset,SQ_GET&&
  138.     isset($fontsets[$fontset])) {
  139.     $fontfamily=$fontsets[$fontset];
  140. else {
  141.     $fontfamily='';
  142. }
  143.  
  144. if (sqgetGlobalVar('fontsize',$fontsize,SQ_GET)) {
  145.     $fontsize 0;
  146. else {
  147.     $fontsize = (int) $fontsize;
  148. }
  149.  
  150. $oTemplate->header('Content-Type: text/css');
  151. /**
  152.  * GOTCHA #1: When sending the headers for caching, we must send Expires,
  153.  *            Last-Modified, Pragma, and Cache-Control headers.  If we don't PHP
  154.  *            will makeup values that will break the cacheing.
  155.  * 
  156.  * GOTCHA #2: If the current template does not contain a template named
  157.  *            stylesheet.tpl, this cacheing will break because filemtime() won't
  158.  *            work.  This is a problem e.g. with the default_advanced template
  159.  *            that inherits CSS properties from the default template but
  160.  *            doesn't contain stylesheet.tpl itself.
  161. IDEA: So ask the Template class object to return the mtime or better yet, the full file path (at least from SM_PATH) by using $oTemplate->get_template_file_path(stylesheet.tpl) but this is still a problem if the default template also does not have such a file (in which case, we fall back to SM's css/deafult css file (so in that case, go get that file's mtime!)
  162.  *            Possibly naive suggestion - template can define its own default
  163.  *            template name
  164.  * 
  165.  * GOTCHA #3: If the user changes user prefs for things like font size then
  166.  *            the mtime should be updated to the time of that change, and not
  167.  *            that of the stylesheet.tpl file.  IDEA: can this be a value kept
  168.  *            in user prefs (always compare to actual file mtime before sending
  169.  *            to the browser)
  170.  *
  171.  * Comment re gotcha #3: If we only define basic font prefs here, we really
  172.  * only need to refresh the cache if one of the font prefs changes.
  173.  * Possibly some type of "force nocache flag could be set if a font pref is
  174.  * changed?
  175.  *
  176.  * Response: Perhaps, if that can be implemented great, but I think the
  177.  * user prefs solution would definitely work: catch the font setting change
  178.  * in a custom save() routine from user prefs and away we go.
  179.  *
  180.  * TODO: Fix this. :)
  181.  */
  182.  
  183. if $lastmod @filemtime(SM_PATH $oTemplate->get_template_file_directory(
  184.                          . 'css/stylesheet.tpl') ) {
  185.     $gmlastmod gmdate('D, d M Y H:i:s'$lastmod' GMT';
  186.     $expires gmdate('D, d M Y H:i:s'strtotime('+1 week')) ' GMT';
  187.     header('Last-Modified: ' $gmlastmod);
  188.     header('Expires: '$expires);
  189.     header('Pragma: ');
  190.     header('Cache-Control: public, must-revalidate');
  191. }
  192. // Steve, why did you remove this?  Is it irrelevant now?  If so, let's 
  193. // remove the rest of the references to it here (note that it is being
  194. // used above in the filetime() statement) and elsewhere
  195. // $oTemplate->display('css/stylesheet.tpl');
  196.  
  197. /**
  198.  * Additional styles are now handled by adding stylesheets to
  199.  * templates/<template>/css/, so here, we simply define some
  200.  * basic styles based on user prefs.
  201.  */
  202. ?>
  203. /* older css template */
  204. body, td, th, dd, dt, h1, h2, h3, h4, h5, h6, p, ol, ul, li {
  205. <?php
  206. if($fontfamilyecho '  font-family: '.$fontfamily.";\n";
  207. ?>
  208. }
  209. body, small {
  210. <?php
  211. if($fontsizeecho '  font-size: '.($fontsize-2)."pt;\n";
  212. ?>
  213. }
  214. td, th {
  215. <?php
  216. if($fontsizeecho '  font-size: '.$fontsize."pt;\n";
  217. ?>
  218. }
  219. textarea, pre {
  220. font-family: monospace;
  221. <?php
  222. if($fontsizeecho '  font-size: '.($fontsize-1)."pt;\n";
  223. ?>
  224. }

Documentation generated on Sat, 07 Oct 2006 16:13:52 +0300 by phpDocumentor 1.3.0RC6