mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Compare commits
2 Commits
c366f1e076
...
bfe6d0964f
Author | SHA1 | Date | |
---|---|---|---|
|
bfe6d0964f | ||
|
53548d6c0d |
@ -7,6 +7,7 @@ use SilverStripe\Assets\File;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\HeaderField;
|
||||
use SilverStripe\Forms\OptionsetField;
|
||||
use SilverStripe\Forms\UrlField;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
/**
|
||||
@ -47,6 +48,9 @@ class RedirectorPage extends Page
|
||||
'RedirectionType',
|
||||
'Content',
|
||||
],
|
||||
'fieldClasses' => [
|
||||
'ExternalURL' => UrlField::class,
|
||||
],
|
||||
];
|
||||
|
||||
private static $table_name = 'RedirectorPage';
|
||||
@ -171,35 +175,12 @@ class RedirectorPage extends Page
|
||||
}
|
||||
}
|
||||
|
||||
protected function onBeforeWrite()
|
||||
{
|
||||
parent::onBeforeWrite();
|
||||
|
||||
if ($this->ExternalURL && substr($this->ExternalURL ?? '', 0, 2) !== '//') {
|
||||
$urlParts = parse_url($this->ExternalURL ?? '');
|
||||
if ($urlParts) {
|
||||
if (empty($urlParts['scheme'])) {
|
||||
// no scheme, assume http
|
||||
$this->ExternalURL = 'http://' . $this->ExternalURL;
|
||||
} elseif (!in_array($urlParts['scheme'], [
|
||||
'http',
|
||||
'https',
|
||||
])) {
|
||||
// we only allow http(s) urls
|
||||
$this->ExternalURL = '';
|
||||
}
|
||||
} else {
|
||||
// malformed URL to reject
|
||||
$this->ExternalURL = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getCMSFields()
|
||||
{
|
||||
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
||||
// Remove all metadata fields, does not apply for redirector pages
|
||||
$fields->removeByName('Metadata');
|
||||
$fields->dataFieldByName('ExternalURL')?->setAllowRelativeProtocol(true);
|
||||
|
||||
$fields->addFieldsToTab(
|
||||
'Root.Main',
|
||||
|
Loading…
Reference in New Issue
Block a user