1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Subsites\Extensions; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
6
|
|
|
use SilverStripe\Core\Config\Config; |
7
|
|
|
use SilverStripe\ORM\DataExtension; |
8
|
|
|
use SilverStripe\ORM\DataObject; |
9
|
|
|
use SilverStripe\Subsites\Model\Subsite; |
10
|
|
|
|
11
|
|
|
class ErrorPageSubsite extends DataExtension |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Alter file path to generated a static (static) error page file to handle error page template |
15
|
|
|
* on different sub-sites |
16
|
|
|
* |
17
|
|
|
* @see ErrorPage::get_error_filename() |
18
|
|
|
* |
19
|
|
|
* FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including |
20
|
|
|
* main site) between opening ErrorPage in the CMS and publish ErrorPage causes static error page to get |
21
|
|
|
* generated incorrectly. |
22
|
|
|
* |
23
|
|
|
* @param string $name |
24
|
|
|
* @param int $statusCode |
25
|
|
|
*/ |
26
|
|
|
public function updateErrorFilename(&$name, &$statusCode) |
27
|
|
|
{ |
28
|
|
|
$static_filepath = Config::inst()->get($this->owner->ClassName, 'static_filepath'); |
29
|
|
|
$subdomainPart = ''; |
30
|
|
|
|
31
|
|
|
// Try to get current subsite from session |
32
|
|
|
$subsite = Subsite::currentSubsite(); |
33
|
|
|
|
34
|
|
|
// since this function is called from Page class before the controller is created, we have |
35
|
|
|
// to get subsite from domain instead |
36
|
|
|
if (!$subsite) { |
37
|
|
|
$subsiteID = Subsite::getSubsiteIDForDomain(); |
38
|
|
|
if ($subsiteID != 0) { |
39
|
|
|
$subsite = DataObject::get_by_id(Subsite::class, $subsiteID); |
40
|
|
|
} else { |
41
|
|
|
$subsite = null; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ($subsite) { |
46
|
|
|
$subdomain = $subsite->domain(); |
47
|
|
|
$subdomainPart = "-{$subdomain}"; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// @todo implement Translatable namespace |
51
|
|
|
if (singleton(SiteTree::class)->hasExtension('Translatable') |
52
|
|
|
&& $locale |
53
|
|
|
&& $locale != Translatable::default_locale() |
54
|
|
|
) { |
55
|
|
|
$filepath = $static_filepath . "/error-{$statusCode}-{$locale}{$subdomainPart}.html"; |
|
|
|
|
56
|
|
|
} else { |
57
|
|
|
$filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html"; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$name = $filepath; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.