mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Compare commits
1 Commits
5267cd4619
...
53548d6c0d
Author | SHA1 | Date | |
---|---|---|---|
|
53548d6c0d |
@ -7,6 +7,7 @@ use SilverStripe\Assets\File;
|
|||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\HeaderField;
|
use SilverStripe\Forms\HeaderField;
|
||||||
use SilverStripe\Forms\OptionsetField;
|
use SilverStripe\Forms\OptionsetField;
|
||||||
|
use SilverStripe\Forms\UrlField;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,6 +48,9 @@ class RedirectorPage extends Page
|
|||||||
'RedirectionType',
|
'RedirectionType',
|
||||||
'Content',
|
'Content',
|
||||||
],
|
],
|
||||||
|
'fieldClasses' => [
|
||||||
|
'ExternalURL' => UrlField::class,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
private static $table_name = 'RedirectorPage';
|
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()
|
public function getCMSFields()
|
||||||
{
|
{
|
||||||
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
||||||
// Remove all metadata fields, does not apply for redirector pages
|
// Remove all metadata fields, does not apply for redirector pages
|
||||||
$fields->removeByName('Metadata');
|
$fields->removeByName('Metadata');
|
||||||
|
$fields->dataFieldByName('ExternalURL')?->setAllowRelativeProtocol(true);
|
||||||
|
|
||||||
$fields->addFieldsToTab(
|
$fields->addFieldsToTab(
|
||||||
'Root.Main',
|
'Root.Main',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user