mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX fix for #5076 (from r98957)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102818 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
d5f21946d2
commit
45c5163c18
@ -168,6 +168,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',
|
||||
@ -1982,6 +1987,16 @@ 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);
|
||||
@ -1989,6 +2004,17 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
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
|
||||
*
|
||||
|
@ -16,6 +16,7 @@
|
||||
$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'])) {
|
||||
@ -31,9 +32,17 @@ 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');
|
||||
|
Loading…
Reference in New Issue
Block a user