2012-03-25 18:35:01 +02:00
|
|
|
<?php
|
|
|
|
|
2014-07-14 07:17:44 +02:00
|
|
|
/**
|
|
|
|
* @property text Domain domain name of this subsite. Do not include the URL scheme here
|
|
|
|
* @property bool IsPrimary Is this the primary subdomain?
|
|
|
|
*/
|
2015-11-23 04:53:45 +01:00
|
|
|
class SubsiteDomain extends DataObject
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $db = array(
|
|
|
|
"Domain" => "Varchar(255)",
|
|
|
|
"IsPrimary" => "Boolean",
|
|
|
|
);
|
2013-05-06 12:21:09 +02:00
|
|
|
|
2015-11-23 04:53:45 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $has_one = array(
|
|
|
|
"Subsite" => "Subsite",
|
|
|
|
);
|
2013-05-06 12:21:09 +02:00
|
|
|
|
2015-11-23 04:53:45 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $summary_fields=array(
|
|
|
|
'Domain',
|
|
|
|
'IsPrimary',
|
|
|
|
);
|
2013-05-06 12:21:09 +02:00
|
|
|
|
2015-11-23 04:53:45 +01:00
|
|
|
/**
|
|
|
|
* Whenever a Subsite Domain is written, rewrite the hostmap
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function onAfterWrite()
|
|
|
|
{
|
|
|
|
Subsite::writeHostMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return \FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = new FieldList(
|
|
|
|
new TextField('Domain', $this->fieldLabel('Domain'), null, 255),
|
|
|
|
new CheckboxField('IsPrimary', $this->fieldLabel('IsPrimary'))
|
|
|
|
);
|
2013-05-06 12:21:09 +02:00
|
|
|
|
2015-11-23 04:53:45 +01:00
|
|
|
$this->extend('updateCMSFields', $fields);
|
|
|
|
return $fields;
|
|
|
|
}
|
2014-07-14 07:17:44 +02:00
|
|
|
|
2015-11-23 04:53:45 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param bool $includerelations
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function fieldLabels($includerelations = true)
|
|
|
|
{
|
|
|
|
$labels = parent::fieldLabels($includerelations);
|
|
|
|
$labels['Domain'] = _t('SubsiteDomain.DOMAIN', 'Domain');
|
|
|
|
$labels['IsPrimary'] = _t('SubsiteDomain.IS_PRIMARY', 'Is Primary Domain');
|
2013-10-30 13:43:59 +01:00
|
|
|
|
2015-11-23 04:53:45 +01:00
|
|
|
return $labels;
|
|
|
|
}
|
2013-10-30 13:43:59 +01:00
|
|
|
|
2015-11-23 04:53:45 +01:00
|
|
|
/**
|
|
|
|
* Before writing the Subsite Domain, strip out any HTML the user has entered.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function onBeforeWrite()
|
|
|
|
{
|
|
|
|
parent::onBeforeWrite();
|
2014-07-14 07:17:44 +02:00
|
|
|
|
2015-11-23 04:53:45 +01:00
|
|
|
//strip out any HTML to avoid XSS attacks
|
|
|
|
$this->Domain = Convert::html2raw($this->Domain);
|
|
|
|
}
|
2013-04-30 07:53:09 +02:00
|
|
|
}
|