Mercurial > SimpleWebPresenter
comparison cache_check.inc @ 32:7b19be62ea94
Remove yet another global, replace by CacheTimeCheck class.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 04 Oct 2012 19:46:11 +0200 |
| parents | 1ec0738a1623 |
| children |
comparison
equal
deleted
inserted
replaced
| 30:647b72603b7d | 32:7b19be62ea94 |
|---|---|
| 1 <?php | 1 <?php |
| 2 function cache_check($mtime) | 2 class CacheTimeCheck |
| 3 { | 3 { |
| 4 if (DEBUG) | 4 private $newest; |
| 5 var_dump($_SERVER); | 5 private $files = array(); |
| 6 | 6 |
| 7 $HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE']; | 7 function __construct($minTime = 0, $filename = False) |
| 8 $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE); | 8 { |
| 9 if ($filename) | |
| 10 array_push($this->files, $filename); | |
| 11 $this->newest = $minTime; | |
| 12 $this->cache_time(__FILE__); | |
| 13 } | |
| 9 | 14 |
| 10 $gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT'; | 15 function CheckHttpModified() |
| 16 { | |
| 17 if (DEBUG) | |
| 18 var_dump($_SERVER); | |
| 11 | 19 |
| 12 if ($if_modified_since == $gmdate_mod) { | 20 $HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE']; |
| 13 header("HTTP/1.0 304 Not Modified"); | 21 $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE); |
| 14 exit; | 22 |
| 23 $gmdate_mod = gmdate('D, d M Y H:i:s', $this->newest) . ' GMT'; | |
| 24 | |
| 25 if ($if_modified_since == $gmdate_mod) { | |
| 26 header("HTTP/1.0 304 Not Modified"); | |
| 27 exit; | |
| 28 } | |
| 29 header("Last-Modified: $gmdate_mod"); | |
| 15 } | 30 } |
| 16 header("Last-Modified: $gmdate_mod"); | |
| 17 } | |
| 18 | 31 |
| 19 function cache_time($path) | 32 function cache_time($path) |
| 20 { | 33 { |
| 21 global $newest; | 34 array_push($this->files, $path); |
| 22 $mtime = filemtime($path); | 35 $mtime = filemtime($path); |
| 23 if ($mtime > $newest) { | 36 if ($mtime > $this->newest) { |
| 24 $newest = $mtime; | 37 $this->newest = $mtime; |
| 38 } | |
| 39 } | |
| 40 | |
| 41 function includeOnce($path) | |
| 42 { | |
| 43 $this->cache_time($path); | |
| 44 include_once($path); | |
| 25 } | 45 } |
| 26 } | 46 } |
| 27 | |
| 28 function include_with_mtime($path) | |
| 29 { | |
| 30 cache_time($path); | |
| 31 include_once($path); | |
| 32 } | |
| 33 | |
| 34 cache_time(__FILE__); | |
| 35 ?> | 47 ?> |
