From 6535be85516a1a822166ffb18429ce68079a60a6 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 12 Aug 2003 07:52:19 +0000 Subject: [PATCH] New, shorter intro to styles files that calls a function. This function sets header information to improve caching (default 5 minutes) Cookies are also prevented to improve cacheability. --- lib/weblib.php | 18 ++++++++++++++++++ theme/brightretro/styles.php | 10 ++-------- theme/cordoroyblue/styles.php | 11 +++-------- theme/garden/styles.php | 12 +++--------- theme/oceanblue/styles.php | 12 +++--------- theme/poweraid/styles.php | 10 +++------- theme/standard/styles.php | 10 ++-------- theme/standardblue/styles.php | 12 +++--------- theme/standardgreen/styles.php | 12 +++--------- theme/standardlogo/styles.php | 12 +++--------- theme/standardred/styles.php | 12 +++--------- theme/standardwhite/styles.php | 12 +++--------- 12 files changed, 49 insertions(+), 94 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index a9a53d1c3e..5985c26c2d 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -780,6 +780,24 @@ function print_footer ($course=NULL) { include ("$CFG->dirroot/theme/$CFG->theme/footer.html"); } +function style_sheet_setup($lastmodified, $lifetime, $themename="") { + + global $CFG; + + header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT"); + header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT"); + header("Cache-control: max_age = $lifetime"); + header("Pragma: "); + header("Content-type: text/css"); // Correct MIME type + + if (!empty($themename)) { + $CFG->theme = $themename; + } + + return "$CFG->wwwroot/theme/$CFG->theme"; + +} + function user_login_string($course, $user=NULL) { global $USER, $CFG; diff --git a/theme/brightretro/styles.php b/theme/brightretro/styles.php index 9f41f51e74..d7e8d26ebe 100644 --- a/theme/brightretro/styles.php +++ b/theme/brightretro/styles.php @@ -2,15 +2,9 @@ /// We use PHP so we can do value substitutions into the styles + $nomoodlecookie = true; require_once("../../config.php"); - - header("Content-type: text/css"); /// Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /// From here on it's nearly a normal stylesheet. diff --git a/theme/cordoroyblue/styles.php b/theme/cordoroyblue/styles.php index 59bb199596..5bd43b9314 100644 --- a/theme/cordoroyblue/styles.php +++ b/theme/cordoroyblue/styles.php @@ -2,15 +2,10 @@ /// We use PHP so we can do value substitutions into the styles - require_once("../../config.php"); + $nomoodlecookie = true; + require_once("../../config.php"); + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); - header("Content-type: text/css"); /// Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; /// From here on it's nearly a normal stylesheet. /// First are some CSS definitions for normal tags, diff --git a/theme/garden/styles.php b/theme/garden/styles.php index 169bdc6e22..5719fef320 100755 --- a/theme/garden/styles.php +++ b/theme/garden/styles.php @@ -2,15 +2,9 @@ /// We use PHP so we can do value substitutions into the styles - require_once("../../config.php"); - - header("Content-type: text/css"); // Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $nomoodlecookie = true; + require_once("../../config.php"); + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /// From here on it's nearly a normal stylesheet. /// First are some CSS definitions for normal tags, diff --git a/theme/oceanblue/styles.php b/theme/oceanblue/styles.php index 07e4e559dc..dd861fde7b 100644 --- a/theme/oceanblue/styles.php +++ b/theme/oceanblue/styles.php @@ -2,15 +2,9 @@ /// We use PHP so we can do value substitutions into the styles - require_once("../../config.php"); - - header("Content-type: text/css"); // Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $nomoodlecookie = true; + require_once("../../config.php"); + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /// From here on it's nearly a normal stylesheet. /// First are some CSS definitions for normal tags, diff --git a/theme/poweraid/styles.php b/theme/poweraid/styles.php index 0a1e9794e0..8970299c09 100644 --- a/theme/poweraid/styles.php +++ b/theme/poweraid/styles.php @@ -26,13 +26,9 @@ /* We use PHP so we can do value substitutions into the styles */ - require_once("../../config.php"); - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $nomoodlecookie = true; + require_once("../../config.php"); + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /* From here on it's nearly a normal stylesheet. diff --git a/theme/standard/styles.php b/theme/standard/styles.php index b89b8aba50..731de21220 100644 --- a/theme/standard/styles.php +++ b/theme/standard/styles.php @@ -2,15 +2,9 @@ /// We use PHP so we can do value substitutions into the styles + $nomoodlecookie = true; require_once("../../config.php"); - - header("Content-type: text/css"); // Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /// From here on it's nearly a normal stylesheet. /// First are some CSS definitions for normal tags, diff --git a/theme/standardblue/styles.php b/theme/standardblue/styles.php index b89b8aba50..3025f069e5 100644 --- a/theme/standardblue/styles.php +++ b/theme/standardblue/styles.php @@ -2,15 +2,9 @@ /// We use PHP so we can do value substitutions into the styles - require_once("../../config.php"); - - header("Content-type: text/css"); // Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $nomoodlecookie = true; + require_once("../../config.php"); + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /// From here on it's nearly a normal stylesheet. /// First are some CSS definitions for normal tags, diff --git a/theme/standardgreen/styles.php b/theme/standardgreen/styles.php index b89b8aba50..3025f069e5 100644 --- a/theme/standardgreen/styles.php +++ b/theme/standardgreen/styles.php @@ -2,15 +2,9 @@ /// We use PHP so we can do value substitutions into the styles - require_once("../../config.php"); - - header("Content-type: text/css"); // Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $nomoodlecookie = true; + require_once("../../config.php"); + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /// From here on it's nearly a normal stylesheet. /// First are some CSS definitions for normal tags, diff --git a/theme/standardlogo/styles.php b/theme/standardlogo/styles.php index b89b8aba50..3025f069e5 100644 --- a/theme/standardlogo/styles.php +++ b/theme/standardlogo/styles.php @@ -2,15 +2,9 @@ /// We use PHP so we can do value substitutions into the styles - require_once("../../config.php"); - - header("Content-type: text/css"); // Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $nomoodlecookie = true; + require_once("../../config.php"); + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /// From here on it's nearly a normal stylesheet. /// First are some CSS definitions for normal tags, diff --git a/theme/standardred/styles.php b/theme/standardred/styles.php index b89b8aba50..3025f069e5 100644 --- a/theme/standardred/styles.php +++ b/theme/standardred/styles.php @@ -2,15 +2,9 @@ /// We use PHP so we can do value substitutions into the styles - require_once("../../config.php"); - - header("Content-type: text/css"); // Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $nomoodlecookie = true; + require_once("../../config.php"); + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /// From here on it's nearly a normal stylesheet. /// First are some CSS definitions for normal tags, diff --git a/theme/standardwhite/styles.php b/theme/standardwhite/styles.php index b89b8aba50..3025f069e5 100644 --- a/theme/standardwhite/styles.php +++ b/theme/standardwhite/styles.php @@ -2,15 +2,9 @@ /// We use PHP so we can do value substitutions into the styles - require_once("../../config.php"); - - header("Content-type: text/css"); // Correct MIME type - - if (isset($themename)) { - $CFG->theme = $themename; - } - - $themeurl = "$CFG->wwwroot/theme/$CFG->theme"; + $nomoodlecookie = true; + require_once("../../config.php"); + $themeurl = style_sheet_setup(filemtime("styles.php"), 300, $themename); /// From here on it's nearly a normal stylesheet. /// First are some CSS definitions for normal tags, -- 2.39.5