mirror of
https://github.com/silverstripe/silverstripe-iframe
synced 2024-10-22 11:05:51 +02:00
Merge pull request #9 from helpfulrobot/convert-to-psr-2
Converted to PSR-2
This commit is contained in:
commit
7c541975a8
@ -4,8 +4,9 @@
|
|||||||
* CMS editor can choose width, height, or set it to attempt automatic size configuration.
|
* CMS editor can choose width, height, or set it to attempt automatic size configuration.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class IFramePage extends Page {
|
class IFramePage extends Page
|
||||||
static $db = array(
|
{
|
||||||
|
public static $db = array(
|
||||||
'IFrameURL' => 'Text',
|
'IFrameURL' => 'Text',
|
||||||
'AutoHeight' => 'Boolean(1)',
|
'AutoHeight' => 'Boolean(1)',
|
||||||
'AutoWidth' => 'Boolean(1)',
|
'AutoWidth' => 'Boolean(1)',
|
||||||
@ -16,16 +17,17 @@ class IFramePage extends Page {
|
|||||||
'ForceProtocol' => 'Varchar',
|
'ForceProtocol' => 'Varchar',
|
||||||
);
|
);
|
||||||
|
|
||||||
static $defaults = array(
|
public static $defaults = array(
|
||||||
'AutoHeight' => '1',
|
'AutoHeight' => '1',
|
||||||
'AutoWidth' => '1',
|
'AutoWidth' => '1',
|
||||||
'FixedHeight' => '500',
|
'FixedHeight' => '500',
|
||||||
'FixedWidth' => '0'
|
'FixedWidth' => '0'
|
||||||
);
|
);
|
||||||
|
|
||||||
static $description = 'Embeds an iframe into the body of the page.';
|
public static $description = 'Embeds an iframe into the body of the page.';
|
||||||
|
|
||||||
function getCMSFields() {
|
public function getCMSFields()
|
||||||
|
{
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
$fields->removeFieldFromTab('Root.Main', 'Content');
|
$fields->removeFieldFromTab('Root.Main', 'Content');
|
||||||
@ -53,7 +55,8 @@ class IFramePage extends Page {
|
|||||||
/**
|
/**
|
||||||
* Compute class from the size parameters.
|
* Compute class from the size parameters.
|
||||||
*/
|
*/
|
||||||
function getClass() {
|
public function getClass()
|
||||||
|
{
|
||||||
$class = '';
|
$class = '';
|
||||||
if ($this->AutoHeight) {
|
if ($this->AutoHeight) {
|
||||||
$class .= 'iframepage-height-auto';
|
$class .= 'iframepage-height-auto';
|
||||||
@ -65,18 +68,20 @@ class IFramePage extends Page {
|
|||||||
/**
|
/**
|
||||||
* Compute style from the size parameters.
|
* Compute style from the size parameters.
|
||||||
*/
|
*/
|
||||||
function getStyle() {
|
public function getStyle()
|
||||||
|
{
|
||||||
$style = '';
|
$style = '';
|
||||||
|
|
||||||
// Always add fixed height as a fallback if autosetting or JS fails.
|
// Always add fixed height as a fallback if autosetting or JS fails.
|
||||||
$height = $this->FixedHeight;
|
$height = $this->FixedHeight;
|
||||||
if (!$height) $height = 800;
|
if (!$height) {
|
||||||
|
$height = 800;
|
||||||
|
}
|
||||||
$style .= "height: {$height}px; ";
|
$style .= "height: {$height}px; ";
|
||||||
|
|
||||||
if ($this->AutoWidth) {
|
if ($this->AutoWidth) {
|
||||||
$style .= "width: 100%; ";
|
$style .= "width: 100%; ";
|
||||||
}
|
} elseif ($this->FixedWidth) {
|
||||||
else if ($this->FixedWidth) {
|
|
||||||
$style .= "width: {$this->FixedWidth}px; ";
|
$style .= "width: {$this->FixedWidth}px; ";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +94,8 @@ class IFramePage extends Page {
|
|||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
* @return ValidationResult
|
* @return ValidationResult
|
||||||
*/
|
*/
|
||||||
public function validate() {
|
public function validate()
|
||||||
|
{
|
||||||
$result = parent::validate();
|
$result = parent::validate();
|
||||||
|
|
||||||
//whitelist allowed URL schemes
|
//whitelist allowed URL schemes
|
||||||
@ -104,8 +110,10 @@ class IFramePage extends Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IFramePage_Controller extends Page_Controller {
|
class IFramePage_Controller extends Page_Controller
|
||||||
function init() {
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
if ($this->ForceProtocol) {
|
if ($this->ForceProtocol) {
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class IFramePageTest extends SapphireTest {
|
class IFramePageTest extends SapphireTest
|
||||||
|
{
|
||||||
public function setUp() {
|
public function setUp()
|
||||||
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
Config::nest();
|
Config::nest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown() {
|
public function tearDown()
|
||||||
|
{
|
||||||
Config::unnest();
|
Config::unnest();
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetClass() {
|
public function testGetClass()
|
||||||
|
{
|
||||||
$iframe = new IFramePage();
|
$iframe = new IFramePage();
|
||||||
$iframe->AutoHeight = 1;
|
$iframe->AutoHeight = 1;
|
||||||
$iframe->getClass();
|
$iframe->getClass();
|
||||||
@ -25,7 +28,8 @@ class IFramePageTest extends SapphireTest {
|
|||||||
$this->assertNotContains('iframepage-height-auto', $iframe->getClass());
|
$this->assertNotContains('iframepage-height-auto', $iframe->getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetStyle() {
|
public function testGetStyle()
|
||||||
|
{
|
||||||
$iframe = new IFramePage();
|
$iframe = new IFramePage();
|
||||||
|
|
||||||
$iframe->FixedHeight = 0;
|
$iframe->FixedHeight = 0;
|
||||||
@ -45,7 +49,8 @@ class IFramePageTest extends SapphireTest {
|
|||||||
$this->assertContains('width: 200px', $iframe->getStyle(), 'Fixed width is settable');
|
$this->assertContains('width: 200px', $iframe->getStyle(), 'Fixed width is settable');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testAllowedUrls() {
|
public function testAllowedUrls()
|
||||||
|
{
|
||||||
$iframe = new IFramePage();
|
$iframe = new IFramePage();
|
||||||
|
|
||||||
$tests = array(
|
$tests = array(
|
||||||
@ -86,7 +91,8 @@ class IFramePageTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForceProtocol() {
|
public function testForceProtocol()
|
||||||
|
{
|
||||||
$origServer = $_SERVER;
|
$origServer = $_SERVER;
|
||||||
|
|
||||||
$page = new IFramePage();
|
$page = new IFramePage();
|
||||||
|
Loading…
Reference in New Issue
Block a user