123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- class cache
- {
-
- function http($files,$mod_ts=array())
- {
- if (empty($files) || !is_array($files)) {
- return false;
- }
-
- array_walk($files,create_function('&$v','$v = filemtime($v);'));
-
- $array_ts = array_merge($mod_ts,$files);
-
- rsort($array_ts);
- $ts = $array_ts[0];
-
- $since = NULL;
- if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
- $since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
- $since = preg_replace ('/^(.*)(Mon|Tue|Wed|Thu|Fri|Sat|Sun)(.*)(GMT)(.*)/', '$2$3 GMT', $since);
- $since = strtotime($since);
- }
-
- $status_mode = preg_match('/cgi/',php_sapi_name());
-
-
- $headers[] = 'Last-Modified: '.gmdate('D, d M Y H:i:s',$ts).' GMT';
- $headers[] = 'Cache-Control: must-revalidate, max-age=0';
- $headers[] = 'Pragma:';
-
- if ($since >= $ts)
- {
- if ($status_mode) {
- header("Status: 304 Not Modified");
- } else {
- if (version_compare(phpversion(),'4.3.0','>=')) {
- header('Not Modified', TRUE, 304);
- } else {
- header('HTTP/1.x 304 Not Modified');
- }
- }
- foreach ($headers as $v) {
- header($v);
- }
- exit;
- }
- else
- {
- header('Date: '.gmdate('D, d M Y H:i:s').' GMT');
- foreach ($headers as $v) {
- header($v);
- }
- }
- }
-
-
-
- function writeFile($file,$content)
- {
- $w = false;
- if (file_exists($file)) {
- $w = is_writable($file);
- } else {
- $w = is_writable(dirname($file));
- }
-
- if (!$w) {
- return false;
- }
-
- if (($fp = @fopen($file,'w')) !== false) {
- fwrite($fp,$content,strlen($content));
- fclose($fp);
- }
- }
-
-
- function getFile($file,$files)
- {
- if (empty($files) || !is_array($files) || !file_exists($file)) {
- return false;
- }
-
- array_walk($files,create_function('&$v','$v = filemtime($v);'));
- rsort($files);
- $ts = $files[0];
-
- $ftime = filemtime($file);
-
- if ($ts <= $ftime) {
- define('DC_CACHE_CONTENT',implode('',file($file)));
- }
- }
- }
- ?>
|