summaryrefslogtreecommitdiff
path: root/itjs.class
diff options
context:
space:
mode:
Diffstat (limited to 'itjs.class')
-rw-r--r--itjs.class32
1 files changed, 27 insertions, 5 deletions
diff --git a/itjs.class b/itjs.class
index 6ef1c8f..c54abd3 100644
--- a/itjs.class
+++ b/itjs.class
@@ -160,7 +160,8 @@ static function filecontents($filenames, $execphp = true)
list($filename, $paramstr) = explode("?", $filename);
if ($paramstr && $execphp)
parse_str($paramstr, $_GET);
- $result .= it::replace(array('^1$' => ""), $execphp ? @include($filename) : @file_get_contents($filename), array('utf8' => false));
+ if (file_exists($filename))
+ $result .= it::replace(array('^1$' => ""), $execphp ? include($filename) : file_get_contents($filename), array('utf8' => false));
$_GET = $origget;
}
$result .= ob_get_clean();
@@ -206,14 +207,35 @@ static function checksum($fnlist, $p = array())
return it_cache::get($key) ?: it_cache::put($key, substr(md5(self::filecontents($filenames, false)), 0, 10), array('ttl' => 60));
}
-function crcurl($url)
+function crcurl($url, $p = array())
{
if (it::match('^http', $url)) # remote url, must fetch to crc
- $fn = it_url::get_cache(array('url' => $url, 'maxage' => 3600));
+ list($fn, $short_expire) = array(it_url::get_cache(array('url' => $url, 'maxage' => 3600) + $p), false);
else
- $fn = ($m = it::match("^//(\w+)(/.*)", $url)) ? "/www/$m[0].search.ch" . $m[1] : $GLOBALS['ULTRAHOME'] . $url;
+ list($fn, $short_expire) = array(($m = it::match("^//(\w+)(/.*)", $url)) ? "/www/$m[0].search.ch" . $m[1] : $GLOBALS['ULTRAHOME'] . $url, true);;
- return it::match('#', $url) ? U(trim($url, "#")) : U($url, array('c' => self::checksum(array($fn))));
+ return it::match('#', $url) ? U(trim($url, "#")) : U($url, array('c' => self::checksum(array($fn), array('short_expire' => $short_expire))));
+}
+
+# $p['nocrc'] means no $_REQUEST['c'] is needed for far future expire
+static function far_future_headers($p = array())
+{
+ $crc = $_REQUEST['c'] ?: $_REQUEST['s'];
+ if ($crc != "-" && !$_SERVER['HTTP_CACHE_CONTROL'] && $_SERVER['HTTP_IF_NONE_MATCH'] && !it::is_devel() && !$_REQUEST['retry'])
+ {
+ header("HTTP/1.0 304 Not Modified"); # client should always keep the component that fits the page it has
+ exit;
+ }
+
+ if ($crc != "-")
+ @header("Etag: alwaysvalid"); # we have checksums in the url. client should always keep the version he downloaded along with the html
+
+ if (it::is_live() && !$_REQUEST['retry'])
+ {
+ $keeptime = $crc == "-" ? 0 : ($crc || $p['nocrc'] ? 30*86400 : 900); # long expire if checksum present
+ header("Cache-Control: max-age=$keeptime, private"); # proxies should not cache since contents of same url can differ between browsers
+ header("Expires: " . gmdate("D, d M Y H:i:s", time() + $keeptime). " GMT");
+ }
}
}