Blob


1 <?php if (!defined('PmWiki')) exit();
2 /* Copyright 2006-2020 Patrick R. Michaud (pmichaud@pobox.com)
3 This file is part of PmWiki; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published
5 by the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version. See pmwiki.php for full details.
8 Script maintained by Petko YOTOV www.pmwiki.org/petko
9 */
11 ## Browser cache-control. If this is a cacheable action (e.g., browse,
12 ## diff), then set the Last-Modified header to the time the site was
13 ## last modified. If the browser has provided us with a matching
14 ## If-Modified-Since request header, we can return 304 Not Modified.
15 SDV($LastModFile,"$WorkDir/.lastmod");
16 if (!$LastModFile) return;
18 $LastModTime = @filemtime($LastModFile);
19 foreach(get_included_files() as $f)
20 { $v = @filemtime($f); if ($v > $LastModTime) $LastModTime = $v; }
22 if (@$EnableIMSCaching) {
23 SDV($IMSCookie, $CookiePrefix.'imstime');
24 SDV($IMSCookieExpires, $Now + 60*60*24*30);
25 SDV($IMSInvalidators, array('authpw', 'author'));
26 $LogoutCookies[] = $IMSCookie;
28 if ($IMSCookie) {
29 $IMSTime = @$_COOKIE[$IMSCookie];
30 if ($IMSTime < $LastModTime
31 || array_intersect($IMSInvalidators, array_keys($_POST))) {
32 $IMSTime = $Now;
33 pmsetcookie($IMSCookie, $IMSTime, $IMSCookieExpires, '/');
34 }
35 } else $IMSTime = $LastModTime;
37 if (in_array($action, (array)$CacheActions)) {
38 $HTTPLastMod = gmdate('D, d M Y H:i:s \G\M\T',$IMSTime);
39 $HTTPHeaders[] = "Cache-Control: no-cache";
40 $HTTPHeaders[] = "Last-Modified: $HTTPLastMod";
41 if (@$_SERVER['HTTP_IF_MODIFIED_SINCE']==$HTTPLastMod) {
42 header("HTTP/1.0 304 Not Modified");
43 header("Cache-Control: no-cache");
44 header("Expires: ");
45 header("Last-Modified: $HTTPLastMod");
46 exit();
47 }
48 }
49 }
51 if ($NoHTMLCache
52 || !@$PageCacheDir
53 || count($_POST) > 0
54 || count($_GET) > 1
55 || (count($_GET) == 1 && !@$_GET['n'])) { $NoHTMLCache |= 1; return; }
57 mkdirp($PageCacheDir);
58 if (!file_exists("$PageCacheDir/.htaccess")
59 && $fp = @fopen("$PageCacheDir/.htaccess", "w"))
60 { fwrite($fp, $DenyHtaccessContent); fclose($fp); }
62 SDV($PageCacheFileFmt, "%s/%s,cache");
63 SDV($PageCacheFile, sprintf($PageCacheFileFmt, $PageCacheDir, $pagename));
65 if (file_exists($PageCacheFile) && @filemtime($PageCacheFile) < $LastModTime)
66 @unlink($PageCacheFile);