From 4042788347c75e1e04b7a69210f92804bc2e0164 Mon Sep 17 00:00:00 2001
From: moodler <moodler>
Date: Wed, 29 Jul 2009 08:12:48 +0000
Subject: [PATCH] theme/styles MDL-19953 $THEME->csslifetime lets themers
 adjust the cacheability of their theme in seconds.

Also:

 1) In dev mode, caching is 60 seconds all the time.
 2) Standard theme always has a long 2 days
---
 lib/outputlib.php |  7 +++++++
 theme/styles.php  | 26 ++++++++++++++++----------
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/lib/outputlib.php b/lib/outputlib.php
index 563d4bc4c5..1fb57e9d19 100644
--- a/lib/outputlib.php
+++ b/lib/outputlib.php
@@ -318,6 +318,13 @@ class theme_config {
      */
     public $layouts = array();
 
+    /* 
+     * Time in seconds to cache the CSS style sheets for the chosen theme
+     * 
+     * @var integer
+     */
+    public $csslifetime = 1800;
+
     /**
      * With this you can control the colours of the big MP3 player
      * that is used for MP3 resources.
diff --git a/theme/styles.php b/theme/styles.php
index 980ab69dac..d94dcfcdde 100644
--- a/theme/styles.php
+++ b/theme/styles.php
@@ -57,7 +57,9 @@ require_once(dirname(__FILE__) . '/../config.php');
 $fortheme = required_param('for', PARAM_FILE);
 $pluginsheets = optional_param('pluginsheets', '', PARAM_BOOL);
 
-$CACHE_LIFETIME = 1800; // Cache stylesheets for half an hour.
+// Load the configuration of the selected theme. (See comment at the top of the file.)
+$PAGE->force_theme($fortheme);
+
 $DEFAULT_SHEET_LIST = array('styles_layout', 'styles_fonts', 'styles_color');
 
 // Fix for IE6 caching - we don't want the filemtime('styles.php'), instead use now.
@@ -65,13 +67,19 @@ $lastmodified = time();
 
 // Set the correct content type. (Should we also be specifying charset here?)
 header('Content-type: text/css'); 
-if (!debugging('', DEBUG_DEVELOPER)) {
-    // Do not send caching headers for developer. (This makes it easy to edit themes.
-    // You don't have to keep clearing the browser cache.)
-    header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastmodified) . ' GMT');
-    header('Expires: ' . gmdate("D, d M Y H:i:s", $lastmodified + $CACHE_LIFETIME) . ' GMT');
-    header('Cache-Control: max-age=' . $lifetime);
-    header('Pragma: ');
+header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastmodified) . ' GMT');
+header('Pragma: ');
+
+// Set the caching for these style sheets
+if (debugging('', DEBUG_DEVELOPER)) {        // Use very short caching time
+    header('Cache-Control: max-age=60');     // One minute
+    header('Expires: ' . gmdate("D, d M Y H:i:s", $lastmodified + 60) . ' GMT');
+} else if ($themename == 'standard') {       // Give this one extra long caching MDL-19953
+    header('Cache-Control: max-age=172801'); // Two days plus one second
+    header('Expires: ' . gmdate("D, d M Y H:i:s", $lastmodified + 172801) . ' GMT');
+} else {                                     // Use whatever time the theme has set
+    header('Cache-Control: max-age='.$THEME->csslifetime);
+    header('Expires: ' . gmdate("D, d M Y H:i:s", $lastmodified + $THEME->csslifetime) . ' GMT');
 }
 
 if (!empty($showdeprecatedstylesheetsetupwarning)) {
@@ -100,8 +108,6 @@ END;
 echo '/*';
 
 
-// Load the configuration of the selected theme. (See comment at the top of the file.)
-$PAGE->force_theme($fortheme);
 
 // We will build up a list of CSS file path names, then concatenate them all.
 $files = array();
-- 
2.39.5