2009-07-13 06:42:48 +02:00
|
|
|
<?php
|
|
|
|
|
2009-07-13 22:28:31 +02:00
|
|
|
/**
|
|
|
|
* This file is designed to be the new 'server' of sites using StaticPublisher.
|
|
|
|
* to use this, you need to modify your .htaccess to point all requests to
|
|
|
|
* static-main.php, rather than main.php. This file also allows for using
|
|
|
|
* static publisher with the subsites module.
|
|
|
|
*
|
|
|
|
* If you are using StaticPublisher+Subsites, set the following in _config.php:
|
|
|
|
* FilesystemPublisher::$domain_based_caching = true;
|
2009-07-14 03:21:04 +02:00
|
|
|
* If you are not using subsites, the host-map.php file will not exist (it is
|
|
|
|
* automatically generated by the Subsites module) and the cache will default
|
|
|
|
* to no subdirectory.
|
2009-07-13 22:28:31 +02:00
|
|
|
*/
|
2009-07-13 06:42:48 +02:00
|
|
|
|
2009-08-03 23:53:30 +02:00
|
|
|
$cacheOn = true;
|
2009-10-15 23:46:36 +02:00
|
|
|
$cacheDebug = false;
|
2009-08-03 23:53:30 +02:00
|
|
|
$hostmapLocation = '../subsites/host-map.php';
|
2009-10-15 23:53:15 +02:00
|
|
|
date_default_timezone_set('Pacific/Auckland');
|
|
|
|
|
2010-01-13 00:19:53 +01:00
|
|
|
if ($cacheOn && empty($_COOKIE['bypassStaticCache'])) {
|
2009-08-03 23:53:30 +02:00
|
|
|
if (file_exists($hostmapLocation)) {
|
|
|
|
include_once $hostmapLocation;
|
|
|
|
$subsiteHostmap['default'] = isset($subsiteHostmap['default']) ? $subsiteHostmap['default'] : '';
|
2009-07-13 06:42:48 +02:00
|
|
|
|
2009-08-03 23:53:30 +02:00
|
|
|
// Look for the host, and find the cache dir
|
|
|
|
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
|
|
|
|
$cacheDir = (isset($subsiteHostmap[$host]) ? $subsiteHostmap[$host] : $subsiteHostmap['default']) . '/';
|
|
|
|
} else {
|
|
|
|
$cacheDir = '';
|
|
|
|
}
|
2009-07-13 06:42:48 +02:00
|
|
|
|
2009-08-03 23:53:30 +02:00
|
|
|
// Look for the file in the cachedir
|
|
|
|
$file = preg_replace('/[^a-zA-Z0-9]/si', '_', trim($_SERVER['REQUEST_URI'], '/'));
|
|
|
|
$file = $file ? $file : 'index';
|
2009-07-13 06:42:48 +02:00
|
|
|
|
2009-08-03 23:53:30 +02:00
|
|
|
if (file_exists('../cache/'.$cacheDir.$file.'.html')) {
|
2009-10-15 23:53:15 +02:00
|
|
|
header('X-cache: hit at '.@date('r'));
|
2009-08-03 23:53:30 +02:00
|
|
|
echo file_get_contents('../cache/'.$cacheDir.$file.'.html');
|
|
|
|
} elseif (file_exists('../cache/'.$cacheDir.$file.'.php')) {
|
2009-10-15 23:53:15 +02:00
|
|
|
header('X-cache: hit at '.@date('r'));
|
2009-08-03 23:53:30 +02:00
|
|
|
include_once '../cache/'.$cacheDir.$file.'.php';
|
2009-10-15 23:46:36 +02:00
|
|
|
if ($cacheDebug) echo "<h1>File was cached</h1>";
|
2009-08-03 23:53:30 +02:00
|
|
|
} else {
|
2009-10-15 23:53:15 +02:00
|
|
|
header('X-cache: miss at '.@date('r') . ' on ' . $cacheDir . $file);
|
2009-08-03 23:53:30 +02:00
|
|
|
// No cache hit... fallback!!!
|
|
|
|
include 'main.php';
|
2009-10-15 23:46:36 +02:00
|
|
|
if ($cacheDebug) echo "<h1>File was !NOT! cached</h1>";
|
2009-08-03 23:53:30 +02:00
|
|
|
}
|
2009-07-13 06:42:48 +02:00
|
|
|
} else {
|
|
|
|
include 'main.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|