Mercurial > SimpleWebPresenter
view CacheTimeCheck.inc @ 41:2a3ff56697db
Don't set values if they are empty in URL.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Fri, 05 Oct 2012 00:48:33 +0200 |
| parents | fbbb82ced6de |
| children | 66382989353f |
line wrap: on
line source
<?php class CacheTimeCheck { private $newest; private $files = array(); private static $myInstance = 0; private function __construct($filename = False) { if ($filename) $this->cache_time($filename); $this->cache_time(__FILE__); } function instance($filename = False) { if (! self::$myInstance) self::$myInstance = new self($filename); elseif ($filename) self::$myInstance->cache_time($filename); return self::$myInstance; } function CheckHttpModified() { if (DEBUG_LEVEL >= VERBOSITY_DEBUG) var_dump($_SERVER); $gmdate_mod = gmdate('D, d M Y H:i:s', $this->newest) . ' GMT'; if(array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) { $HTTP_IF_MODIFIED_SINCE = $_SERVER['HTTP_IF_MODIFIED_SINCE']; $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE); if (strtotime($if_modified_since) >= $this->newest) { header("HTTP/1.0 304 Not Modified"); exit; } } header("Last-Modified: $gmdate_mod"); } function cache_time($path, $basedir = False) { if (!file_exists($path)) { if (DEBUG_LEVEL >= VERBOSITY_WARNING) print "${path} does not exist"; var_dump($_SERVER); errorPage("Resource not available"); } array_push($this->files, $path); $mtime = filemtime($path); if ($mtime > $this->newest) { $this->newest = $mtime; } } function includeOnce($path, $basedir = false) { if ($basedir) $path = $basedir . "/" . $path; $this->cache_time($path); include_once($path); } function loadFile($path) { $this->cache_time($path); return loadFile($path); } } ?>
