Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MINOR smarter static-main.php, now detects automatically if you are u…
…sing domain based cacheing

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@81712 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
rixth committed Jul 13, 2009
1 parent 3a4518c commit a81f387
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions static-main.php
@@ -1,18 +1,22 @@
<?php

$domainBasedCaching = true;
/**
* 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;
*/

if ($domainBasedCaching) {
// Host -> cache dir mapping
if (file_exists('../subsites/host-map.php')) {
include_once '../subsites/host-map.php';
} else {
$subsiteHostmap = array();
}
if (file_exists('../subsites/host-map.php')) {
include_once '../subsites/host-map.php';
$siteHostmap['default'] = isset($siteHostmap['default']) ? $siteHostmap['default'] : '';

// Look for the host, and find the cache dir
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$cacheDir = isset($siteHostmap[$host]) ? $siteHostmap[$host] : $siteHostmap['default'];
$cacheDir = (isset($siteHostmap[$host]) ? $siteHostmap[$host] : $siteHostmap['default']) . '/';
} else {
$cacheDir = '';
}
Expand All @@ -21,10 +25,10 @@
$file = preg_replace('/[^a-zA-Z0-9]/si', '_', trim($_SERVER['REQUEST_URI'], '/'));
$file = $file ? $file : 'index';

if (file_exists('../cache/'.$cacheDir.'/'.$file.'.html')) {
echo file_get_contents('../cache/'.$cacheDir.'/'.$file.'.html');
} elseif (file_exists('../cache/'.$cacheDir.'/'.$file.'.php')) {
include_once '../cache/'.$cacheDir.'/'.$file.'.php';
if (file_exists('../cache/'.$cacheDir.$file.'.html')) {
echo file_get_contents('../cache/'.$cacheDir.$file.'.html');
} elseif (file_exists('../cache/'.$cacheDir.$file.'.php')) {
include_once '../cache/'.$cacheDir.$file.'.php';
} else {
// No cache hit... fallback!!!
include 'main.php';
Expand Down

0 comments on commit a81f387

Please sign in to comment.