mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-01 15:28:02 +02:00
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:
parent
ec5f472139
commit
9b7d030eda
@ -170,6 +170,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
*/
|
*/
|
||||||
public static $breadcrumbs_delimiter = " » ";
|
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(
|
static $searchable_fields = array(
|
||||||
'Title',
|
'Title',
|
||||||
'Content',
|
'Content',
|
||||||
@ -1948,6 +1953,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
|
// Handle activities undertaken by decorators
|
||||||
$this->extend('onAfterPublish', $original);
|
$this->extend('onAfterPublish', $original);
|
||||||
@ -1955,6 +1970,17 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
return true;
|
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
|
* Unpublish this page - remove it from the live site
|
||||||
*
|
*
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
$cacheOn = true;
|
$cacheOn = true;
|
||||||
$cacheDebug = false;
|
$cacheDebug = false;
|
||||||
$hostmapLocation = '../subsites/host-map.php';
|
$hostmapLocation = '../subsites/host-map.php';
|
||||||
|
$homepageMapLocation = '../assets/_homepage-map.php';
|
||||||
date_default_timezone_set('Pacific/Auckland');
|
date_default_timezone_set('Pacific/Auckland');
|
||||||
|
|
||||||
if ($cacheOn && empty($_COOKIE['bypassStaticCache'])) {
|
if ($cacheOn && empty($_COOKIE['bypassStaticCache'])) {
|
||||||
@ -31,9 +32,17 @@ if ($cacheOn && empty($_COOKIE['bypassStaticCache'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Look for the file in the cachedir
|
// 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';
|
$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')) {
|
if (file_exists('../cache/'.$cacheDir.$file.'.html')) {
|
||||||
header('X-cache: hit at '.@date('r'));
|
header('X-cache: hit at '.@date('r'));
|
||||||
echo file_get_contents('../cache/'.$cacheDir.$file.'.html');
|
echo file_get_contents('../cache/'.$cacheDir.$file.'.html');
|
||||||
|
Loading…
Reference in New Issue
Block a user