2009-02-27 03:41:21 +01:00
|
|
|
<?php
|
2012-06-05 01:30:13 +02:00
|
|
|
/**
|
|
|
|
* Iframe page type embeds an iframe of URL of choice into the page.
|
|
|
|
* CMS editor can choose width, height, or set it to attempt automatic size configuration.
|
|
|
|
*/
|
2009-02-27 03:41:21 +01:00
|
|
|
|
|
|
|
class IFramePage extends Page {
|
|
|
|
static $db = array(
|
2012-06-05 01:30:13 +02:00
|
|
|
'IFrameURL' => 'Text',
|
|
|
|
'AutoHeight' => 'Boolean(1)',
|
|
|
|
'AutoWidth' => 'Boolean(1)',
|
|
|
|
'FixedHeight' => 'Int(500)',
|
|
|
|
'FixedWidth' => 'Int(0)',
|
2009-06-04 04:35:03 +02:00
|
|
|
'AlternateContent' => 'HTMLText',
|
|
|
|
'BottomContent' => 'HTMLText'
|
2009-02-27 03:41:21 +01:00
|
|
|
);
|
2012-06-05 01:30:13 +02:00
|
|
|
|
|
|
|
static $defaults = array(
|
|
|
|
'AutoHeight' => '1',
|
|
|
|
'AutoWidth' => '1',
|
|
|
|
'FixedHeight' => '500',
|
|
|
|
'FixedWidth' => '0'
|
|
|
|
);
|
|
|
|
|
|
|
|
static $description = 'Embeds an iframe into the body of the page.';
|
2009-02-27 03:41:21 +01:00
|
|
|
|
|
|
|
function getCMSFields() {
|
|
|
|
$fields = parent::getCMSFields();
|
2012-06-01 07:21:05 +02:00
|
|
|
|
|
|
|
$fields->removeFieldFromTab('Root.Main', 'Content');
|
2013-02-27 04:37:48 +01:00
|
|
|
$fields->addFieldToTab('Root.Main', $url = new TextField('IFrameURL', 'Iframe URL'), 'Metadata');
|
2012-06-05 01:30:13 +02:00
|
|
|
$url->setRightTitle('Can be absolute (<em>http://silverstripe.com</em>) or relative to this site (<em>about-us</em>).');
|
2013-02-27 04:37:48 +01:00
|
|
|
$fields->addFieldToTab('Root.Main', new CheckboxField('AutoHeight', 'Auto height (only works with same domain URLs)'), 'Metadata');
|
|
|
|
$fields->addFieldToTab('Root.Main', new CheckboxField('AutoWidth', 'Auto width (100% of the available space)'), 'Metadata');
|
|
|
|
$fields->addFieldToTab('Root.Main', new NumericField('FixedHeight', 'Fixed height (in pixels)'), 'Metadata');
|
|
|
|
$fields->addFieldToTab('Root.Main', new NumericField('FixedWidth', 'Fixed width (in pixels)'), 'Metadata');
|
|
|
|
$fields->addFieldToTab('Root.Main', new HtmlEditorField('Content', 'Content (appears above iframe)'), 'Metadata');
|
|
|
|
$fields->addFieldToTab('Root.Main', new HtmlEditorField('BottomContent', 'Content (appears below iframe)'), 'Metadata');
|
|
|
|
$fields->addFieldToTab('Root.Main', new HtmlEditorField('AlternateContent', 'Alternate Content (appears when user has iframes disabled)'), 'Metadata');
|
2012-06-01 07:21:05 +02:00
|
|
|
|
2009-02-27 03:41:21 +01:00
|
|
|
return $fields;
|
2012-06-01 07:21:05 +02:00
|
|
|
}
|
2012-06-05 01:30:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute class from the size parameters.
|
|
|
|
*/
|
|
|
|
function getClass() {
|
|
|
|
$class = '';
|
|
|
|
if ($this->AutoHeight) {
|
|
|
|
$class .= 'iframepage-height-auto';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute style from the size parameters.
|
|
|
|
*/
|
|
|
|
function getStyle() {
|
|
|
|
$style = '';
|
|
|
|
|
|
|
|
// Always add fixed height as a fallback if autosetting or JS fails.
|
|
|
|
$height = $this->FixedHeight;
|
|
|
|
if (!$height) $height = 800;
|
|
|
|
$style .= "height: {$height}px; ";
|
|
|
|
|
|
|
|
if ($this->AutoWidth) {
|
|
|
|
$style .= "width: 100%; ";
|
|
|
|
}
|
|
|
|
else if ($this->FixedWidth) {
|
|
|
|
$style .= "width: {$this->FixedWidth}px; ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $style;
|
|
|
|
}
|
2009-02-27 03:41:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class IFramePage_Controller extends Page_Controller {
|
2012-06-01 07:21:05 +02:00
|
|
|
function init() {
|
|
|
|
parent::init();
|
|
|
|
|
2012-06-05 01:30:13 +02:00
|
|
|
if ($this->IFrameURL) {
|
|
|
|
Requirements::javascript('iframe/javascript/iframe_page.js');
|
2012-06-01 07:21:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|