caches.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2006 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.
  7. */
  8. ## Browser cache-control. If this is a cacheable action (e.g., browse,
  9. ## diff), then set the Last-Modified header to the time the site was
  10. ## last modified. If the browser has provided us with a matching
  11. ## If-Modified-Since request header, we can return 304 Not Modified.
  12. SDV($LastModFile,"$WorkDir/.lastmod");
  13. if (!$LastModFile) return;
  14. $LastModTime = @filemtime($LastModFile);
  15. foreach(get_included_files() as $f)
  16. { $v = @filemtime($f); if ($v > $LastModTime) $LastModTime = $v; }
  17. if (@$EnableIMSCaching) {
  18. SDV($IMSCookie, $CookiePrefix.'imstime');
  19. SDV($IMSCookieExpires, $Now + 60*60*24*30);
  20. SDV($IMSInvalidators, array('authpw', 'author'));
  21. $LogoutCookies[] = $IMSCookie;
  22. if ($IMSCookie) {
  23. $IMSTime = @$_COOKIE[$IMSCookie];
  24. if ($IMSTime < $LastModTime
  25. || array_intersect($IMSInvalidators, array_keys($_POST))) {
  26. $IMSTime = $Now;
  27. setcookie($IMSCookie, $IMSTime, $IMSCookieExpires, '/');
  28. }
  29. } else $IMSTime = $LastModTime;
  30. if (in_array($action, (array)$CacheActions)) {
  31. $HTTPLastMod = gmdate('D, d M Y H:i:s \G\M\T',$IMSTime);
  32. $HTTPHeaders[] = "Cache-Control: no-cache";
  33. $HTTPHeaders[] = "Last-Modified: $HTTPLastMod";
  34. if (@$_SERVER['HTTP_IF_MODIFIED_SINCE']==$HTTPLastMod)
  35. { header("HTTP/1.0 304 Not Modified"); exit(); }
  36. }
  37. }
  38. if ($NoHTMLCache
  39. || !@$PageCacheDir
  40. || count($_POST) > 0
  41. || count($_GET) > 2
  42. || (count($_GET) == 1 && !$_GET['n'])) { $NoHTMLCache |= 1; return; }
  43. mkdirp($PageCacheDir);
  44. if (!file_exists("$PageCacheDir/.htaccess")
  45. && $fp = @fopen("$PageCacheDir/.htaccess", "w"))
  46. { fwrite($fp, "Order Deny,Allow\nDeny from all\n"); fclose($fp); }
  47. $PageCacheFile = "$PageCacheDir/$pagename,cache";
  48. if (file_exists($PageCacheFile) && @filemtime($PageCacheFile) < $LastModTime)
  49. @unlink($PageCacheFile);