2009-10-05 23:01:01 +02:00
|
|
|
<?php
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2017-05-24 12:32:05 +02:00
|
|
|
namespace SilverStripe\Subsites\Extensions;
|
|
|
|
|
|
|
|
|
2016-09-22 16:38:29 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
use SilverStripe\ORM\DataExtension;
|
2017-05-24 12:32:05 +02:00
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
|
|
|
|
2012-03-25 18:35:01 +02:00
|
|
|
class ErrorPageSubsite extends DataExtension {
|
2017-05-24 12:32:05 +02:00
|
|
|
|
2009-10-05 23:01:01 +02:00
|
|
|
/**
|
2017-05-24 12:32:05 +02:00
|
|
|
* Alter file path to generated a static (static) error page file to handle error page template on different sub-sites
|
2009-10-05 23:01:01 +02:00
|
|
|
*
|
2015-11-20 03:32:52 +01:00
|
|
|
* {@see Error::get_error_filename()}
|
2009-10-05 23:01:01 +02:00
|
|
|
*
|
2017-05-24 12:32:05 +02:00
|
|
|
* FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including main site) between
|
2015-11-20 03:32:52 +01:00
|
|
|
* opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly.
|
|
|
|
*
|
|
|
|
* @param string $name Filename to write to
|
|
|
|
* @param int $statusCode Integer error code
|
2009-10-05 23:01:01 +02:00
|
|
|
*/
|
2015-11-20 03:32:52 +01:00
|
|
|
public function updateErrorFilename(&$name, $statusCode) {
|
2017-05-24 12:32:05 +02:00
|
|
|
|
2010-09-22 03:43:57 +02:00
|
|
|
// Try to get current subsite from session
|
|
|
|
$subsite = Subsite::currentSubsite(false);
|
2017-05-24 12:32:05 +02:00
|
|
|
|
2009-10-06 04:53:32 +02:00
|
|
|
// since this function is called from Page class before the controller is created, we have to get subsite from domain instead
|
2010-09-22 03:43:57 +02:00
|
|
|
if(!$subsite) {
|
2009-10-06 04:53:32 +02:00
|
|
|
$subsiteID = Subsite::getSubsiteIDForDomain();
|
2015-11-20 03:32:52 +01:00
|
|
|
if($subsiteID != 0) {
|
|
|
|
$subsite = DataObject::get_by_id("Subsite", $subsiteID);
|
|
|
|
}
|
2009-10-06 04:53:32 +02:00
|
|
|
}
|
2015-11-20 03:32:52 +01:00
|
|
|
|
|
|
|
// Without subsite, don't rewrite
|
|
|
|
if($subsite) {
|
|
|
|
// Add subdomain to end of filename, just before .html
|
|
|
|
// This should preserve translatable locale in the filename as well
|
2010-03-31 00:50:37 +02:00
|
|
|
$subdomain = $subsite->domain();
|
2015-11-20 03:32:52 +01:00
|
|
|
$name = substr($name, 0, -5) . "-{$subdomain}.html";
|
2009-10-05 23:01:01 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-24 12:32:05 +02:00
|
|
|
|
|
|
|
}
|