Some improvements to style_sheet_setup based on this from John Dell
authormoodler <moodler>
Mon, 22 Dec 2003 02:43:51 +0000 (02:43 +0000)
committermoodler <moodler>
Mon, 22 Dec 2003 02:43:51 +0000 (02:43 +0000)
  http://moodle.org/mod/forum/discuss.php?d=4171

lib/weblib.php

index 406e99fea892674077bf88cf0c1a6017213121b0..c548b1cc0f731f4fc257069526e17cdb9aff20b7 100644 (file)
@@ -899,6 +899,19 @@ function style_sheet_setup($lastmodified=0, $lifetime=300, $themename="") {
 /// approriately as well as the current path
 
     global $CFG;
+    
+    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {   // May not need to send stylesheet
+        // Following lines from Wolfram Kriesing and John Dell
+        $months = array_flip(array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'));
+        preg_match('~[^,]*,\s(\d+)\s(\w+)\s(\d+)\s(\d+):(\d+):(\d+).*~',
+                   $_SERVER['HTTP_IF_MODIFIED_SINCE'], $splitDate);
+        $timestamp = gmmktime($splitDate[4], $splitDate[5], $splitDate[6], $months[$splitDate[2]]+1, 
+                              $splitDate[1], $splitDate[3]);
+        if ($lastmodified <= $timestamp) {
+            header('HTTP/1.x 304 Not Modified');
+            exit;
+        }
+    }
 
     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");