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

Documentation generated on Mon, 13 Jan 2020 04:23:40 +0100 by phpDocumentor 1.4.3