Changeset:
        34a7b75dc8c7
        
https://sourceforge.net/p/mrbs/hg-code/ci/34a7b75dc8c7e49fe316c67cd243fb15e1ebdf67
Author:
        Campbell Morrison <cimorri...@hg.code.sf.net>
Date:
        Wed Mar 01 18:07:03 2017 +0000
Log message:

Restructured code so that when the HTTP headers are sent caching is disabled by
default.  For files that can be cached then the expiry date has to be set
explicitly in http_headers().   This is to avoid problems with files being
cached when they shouldn't be.

diffstat:

 web/Themes/default/header.inc |   7 ++++++-
 web/check_slot_ajax.php       |   4 ++--
 web/css/mrbs-ielte7.css.php   |   5 ++---
 web/css/mrbs-print.css.php    |   5 ++---
 web/css/mrbs-rtl.css.php      |   5 ++---
 web/css/mrbs.css.php          |   4 ++--
 web/edit_entry_handler.php    |   2 +-
 web/edit_users.php            |   3 +--
 web/functions.inc             |  17 ++++++++++-------
 web/js/admin.js.php           |   4 ++--
 web/js/cell_click.js.php      |   4 ++--
 web/js/datatables.js.php      |   4 ++--
 web/js/datepicker.js.php      |   4 ++--
 web/js/edit_area_room.js.php  |   4 ++--
 web/js/edit_entry.js.php      |   4 ++--
 web/js/edit_users.js.php      |   4 ++--
 web/js/functions.js.php       |   4 ++--
 web/js/general.js.php         |   4 ++--
 web/js/multiple.js.php        |   4 ++--
 web/js/pending.js.php         |   4 ++--
 web/js/refresh.js.php         |   4 ++--
 web/js/report.js.php          |   4 ++--
 web/js/resizable.js.php       |   4 ++--
 web/js/search.js.php          |   4 ++--
 web/report.php                |  11 ++++-------
 web/search.php                |   3 +--
 web/view_entry.php            |   8 +++++---
 27 files changed, 68 insertions(+), 66 deletions(-)

diffs (truncated from 418 to 300 lines):

diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/Themes/default/header.inc
--- a/web/Themes/default/header.inc     Wed Mar 01 16:12:00 2017 +0000
+++ b/web/Themes/default/header.inc     Wed Mar 01 18:07:03 2017 +0000
@@ -243,7 +243,12 @@
     $year  = date("Y");
   }
 
-  http_headers();
+  // We want to prevent IE8 offering "Compatibility View" as that really
+  // messes up MRBS, especially on the Report page
+  $headers = array("Content-Type: text/html; charset=" . get_charset(),
+                   "X-UA-Compatible: IE=Edge");
+  http_headers($headers);
+  
   echo DOCTYPE;
 
   echo "<html>\n";
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/check_slot_ajax.php
--- a/web/check_slot_ajax.php   Wed Mar 01 16:12:00 2017 +0000
+++ b/web/check_slot_ajax.php   Wed Mar 01 18:07:03 2017 +0000
@@ -35,7 +35,7 @@
   }
 }
 
-header("Content-Type: application/json");
-expires_header(0);  // no caching
+http_headers(array("Content-Type: application/json"));
+
 echo json_encode($result);
 
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/css/mrbs-ielte7.css.php
--- a/web/css/mrbs-ielte7.css.php       Wed Mar 01 16:12:00 2017 +0000
+++ b/web/css/mrbs-ielte7.css.php       Wed Mar 01 18:07:03 2017 +0000
@@ -6,9 +6,8 @@
 require_once "../functions.inc";
 require_once "../theme.inc"; 
 
-header("Content-type: text/css");
-expires_header(60*30); // 30 minute expiry
-
+http_headers(array("Content-type: text/css"),
+             60*30);  // 30 minute cache expiry
 ?>
 
 /* Fixes for Internet Explorer 7 and less */
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/css/mrbs-print.css.php
--- a/web/css/mrbs-print.css.php        Wed Mar 01 16:12:00 2017 +0000
+++ b/web/css/mrbs-print.css.php        Wed Mar 01 18:07:03 2017 +0000
@@ -6,9 +6,8 @@
 require_once "../functions.inc";
 require_once "../theme.inc"; 
 
-header("Content-type: text/css");
-expires_header(60*30); // 30 minute expiry
-
+http_headers(array("Content-type: text/css"),
+             60*30);  // 30 minute cache expiry
 ?>
 
 .screenonly, .banner, nav {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/css/mrbs-rtl.css.php
--- a/web/css/mrbs-rtl.css.php  Wed Mar 01 16:12:00 2017 +0000
+++ b/web/css/mrbs-rtl.css.php  Wed Mar 01 18:07:03 2017 +0000
@@ -8,9 +8,8 @@
 require_once "../functions.inc";
 require_once "../theme.inc";
 
-header("Content-type: text/css"); 
-expires_header(60*30); // 30 minute expiry
-
+http_headers(array("Content-type: text/css"),
+             60*30);  // 30 minute cache expiry
 ?>
 
 
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/css/mrbs.css.php
--- a/web/css/mrbs.css.php      Wed Mar 01 16:12:00 2017 +0000
+++ b/web/css/mrbs.css.php      Wed Mar 01 18:07:03 2017 +0000
@@ -6,8 +6,8 @@
 require_once "../functions.inc";
 require_once "../theme.inc";
 
-header("Content-type: text/css"); 
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: text/css"),
+             60*30);  // 30 minute cache expiry
                                 
 // IMPORTANT 
*************************************************************************************************
 // In order to avoid problems in locales where the decimal point is 
represented as a comma, it is important to
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/edit_entry_handler.php
--- a/web/edit_entry_handler.php        Wed Mar 01 16:12:00 2017 +0000
+++ b/web/edit_entry_handler.php        Wed Mar 01 18:07:03 2017 +0000
@@ -747,7 +747,7 @@
       $result['table_innerhtml'] = week_table_innerhtml($day, $month, $year, 
$room, $area, $timetohighlight);
     }
   }
-  header("Content-Type: application/json");
+  http_headers(array("Content-Type: application/json"));
   echo json_encode($result);
   exit;
 }
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/edit_users.php
--- a/web/edit_users.php        Wed Mar 01 16:12:00 2017 +0000
+++ b/web/edit_users.php        Wed Mar 01 18:07:03 2017 +0000
@@ -903,8 +903,7 @@
 
 if ($ajax)
 {
-  header("Content-Type: application/json");
-  expires_header(0);  // no caching
+  http_headers(array("Content-Type: application/json"));
   echo json_encode($json_data);
 }
 else
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/functions.inc
--- a/web/functions.inc Wed Mar 01 16:12:00 2017 +0000
+++ b/web/functions.inc Wed Mar 01 18:07:03 2017 +0000
@@ -151,14 +151,17 @@
 }
 
 
-// Outputs the HTTP headers
-function http_headers()
+// Outputs the HTTP headers, passed in the array $headers, followed by
+// a set of headers to set the cache expiry date.  If $expiry_seconds <= 0
+// then caching is disabled.
+function http_headers(array $headers, $expiry_seconds=0)
 {
-  header("Content-Type: text/html; charset=" . get_charset());
-  // We want to prevent IE8 offering "Compatability View" as that really
-  // messes up MRBS, especially on the Report page
-  header("X-UA-Compatible: IE=Edge");
-  expires_header(0);  // no caching
+  foreach ($headers as $header)
+  {
+    header($header);
+  }
+
+  expires_header($expiry_seconds);
 }
 
 
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/admin.js.php
--- a/web/js/admin.js.php       Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/admin.js.php       Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/cell_click.js.php
--- a/web/js/cell_click.js.php  Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/cell_click.js.php  Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/datatables.js.php
--- a/web/js/datatables.js.php  Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/datatables.js.php  Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/datepicker.js.php
--- a/web/js/datepicker.js.php  Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/datepicker.js.php  Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/edit_area_room.js.php
--- a/web/js/edit_area_room.js.php      Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/edit_area_room.js.php      Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/edit_entry.js.php
--- a/web/js/edit_entry.js.php  Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/edit_entry.js.php  Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/edit_users.js.php
--- a/web/js/edit_users.js.php  Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/edit_users.js.php  Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(0); // Cannot cache file because it depends on $HTTP_REFERER
+http_headers(array("Content-type: application/x-javascript"),
+             0);  // Cannot cache file because it depends on $HTTP_REFERER
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/functions.js.php
--- a/web/js/functions.js.php   Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/functions.js.php   Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/general.js.php
--- a/web/js/general.js.php     Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/general.js.php     Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/multiple.js.php
--- a/web/js/multiple.js.php    Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/multiple.js.php    Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/pending.js.php
--- a/web/js/pending.js.php     Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/pending.js.php     Wed Mar 01 18:07:03 2017 +0000
@@ -3,8 +3,8 @@
 
 require "../defaultincludes.inc";
 
-header("Content-type: application/x-javascript");
-expires_header(60*30); // 30 minute expiry
+http_headers(array("Content-type: application/x-javascript"),
+             60*30);  // 30 minute expiry
 
 if ($use_strict)
 {
diff -r 9e1f7e31c5f5 -r 34a7b75dc8c7 web/js/refresh.js.php
--- a/web/js/refresh.js.php     Wed Mar 01 16:12:00 2017 +0000
+++ b/web/js/refresh.js.php     Wed Mar 01 18:07:03 2017 +0000
@@ -6,8 +6,8 @@

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Mrbs-commits mailing list
Mrbs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to