BUGFIX fix for #5076

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98957 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Tom Rix 2010-02-15 01:58:05 +00:00 committed by Sam Minnee
parent ec5f472139
commit 9b7d030eda
2 changed files with 39 additions and 4 deletions

View File

@ -170,6 +170,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
*/
public static $breadcrumbs_delimiter = " » ";
/**
* Whether or not to write the homepage map for static publisher
*/
public static $write_homepage_map = true;
static $searchable_fields = array(
'Title',
'Content',
@ -1948,13 +1953,34 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
}
}
// Check to write CMS homepage map.
$usingStaticPublishing = false;
foreach(ClassInfo::subclassesFor('StaticPublisher') as $class) if ($this->hasExtension($class)) $usingStaticPublishing = true;
// NOTE: if you change the path here, you must also change it in sapphire/static-main.php
if (self::$write_homepage_map) {
if ($usingStaticPublishing && $map = self::generate_homemage_domain_map()) {
@file_put_contents(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php', "<?php\n\$homepageMap = ".var_export($map, true)."; ?>");
} else { if (file_exists(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php')) unlink(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php'); }
}
// Handle activities undertaken by decorators
$this->extend('onAfterPublish', $original);
return true;
}
static function generate_homepage_domain_map() {
$domainSpecificHomepages = Versioned::get_by_stage('Page', 'Live', "HomepageForDomain != ''", 'URLSegment ASC');
if (!$domainSpecificHomepages) return false;
$map = array();
foreach($domainSpecificHomepages->map('URLSegment', 'HomepageForDomain') as $url => $domains) {
foreach(explode(',', $domains) as $domain) $map[$domain] = $url;
}
return $map;
}
/**
* Unpublish this page - remove it from the live site
*

View File

@ -16,13 +16,14 @@
$cacheOn = true;
$cacheDebug = false;
$hostmapLocation = '../subsites/host-map.php';
$homepageMapLocation = '../assets/_homepage-map.php';
date_default_timezone_set('Pacific/Auckland');
if ($cacheOn && empty($_COOKIE['bypassStaticCache'])) {
if (file_exists($hostmapLocation)) {
include_once $hostmapLocation;
$subsiteHostmap['default'] = isset($subsiteHostmap['default']) ? $subsiteHostmap['default'] : '';
// Look for the host, and find the cache dir
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$cacheDir = (isset($subsiteHostmap[$host]) ? $subsiteHostmap[$host] : $subsiteHostmap['default']) . '/';
@ -31,16 +32,24 @@ if ($cacheOn && empty($_COOKIE['bypassStaticCache'])) {
}
// Look for the file in the cachedir
$file = preg_replace('/[^a-zA-Z0-9]/si', '_', trim($_SERVER['REQUEST_URI'], '/'));
$file = trim($_SERVER['REQUEST_URI'], '/');
$file = $file ? $file : 'index';
// Route to the 'correct' index file (if applicable)
if ($file == 'index' && file_exists($homepageMapLocation)) {
include_once $homepageMapLocation;
$file = isset($homepageMap[$_SERVER['HTTP_HOST']]) ? $homepageMap[$_SERVER['HTTP_HOST']] : $file;
}
$file = preg_replace('/[^a-zA-Z0-9]/si', '_', $file);
if (file_exists('../cache/'.$cacheDir.$file.'.html')) {
header('X-cache: hit at '.@date('r'));
echo file_get_contents('../cache/'.$cacheDir.$file.'.html');
} elseif (file_exists('../cache/'.$cacheDir.$file.'.php')) {
header('X-cache: hit at '.@date('r'));
include_once '../cache/'.$cacheDir.$file.'.php';
if ($cacheDebug) echo "<h1>File was cached</h1>";
if ($cacheDebug) echo "<h1>File was cached</h1>";
} else {
header('X-cache: miss at '.@date('r') . ' on ' . $cacheDir . $file);
// No cache hit... fallback!!!