mirror of
https://github.com/silverstripe/silverstripe-iframe
synced 2024-10-22 11:05:51 +02:00
Converted to PSR-2
This commit is contained in:
parent
91f9c9cb5b
commit
15ec879c70
@ -4,8 +4,9 @@
|
||||
* CMS editor can choose width, height, or set it to attempt automatic size configuration.
|
||||
*/
|
||||
|
||||
class IFramePage extends Page {
|
||||
static $db = array(
|
||||
class IFramePage extends Page
|
||||
{
|
||||
public static $db = array(
|
||||
'IFrameURL' => 'Text',
|
||||
'AutoHeight' => 'Boolean(1)',
|
||||
'AutoWidth' => 'Boolean(1)',
|
||||
@ -16,16 +17,17 @@ class IFramePage extends Page {
|
||||
'ForceProtocol' => 'Varchar',
|
||||
);
|
||||
|
||||
static $defaults = array(
|
||||
public static $defaults = array(
|
||||
'AutoHeight' => '1',
|
||||
'AutoWidth' => '1',
|
||||
'FixedHeight' => '500',
|
||||
'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->removeFieldFromTab('Root.Main', 'Content');
|
||||
@ -53,7 +55,8 @@ class IFramePage extends Page {
|
||||
/**
|
||||
* Compute class from the size parameters.
|
||||
*/
|
||||
function getClass() {
|
||||
public function getClass()
|
||||
{
|
||||
$class = '';
|
||||
if ($this->AutoHeight) {
|
||||
$class .= 'iframepage-height-auto';
|
||||
@ -65,18 +68,20 @@ class IFramePage extends Page {
|
||||
/**
|
||||
* Compute style from the size parameters.
|
||||
*/
|
||||
function getStyle() {
|
||||
public function getStyle()
|
||||
{
|
||||
$style = '';
|
||||
|
||||
// Always add fixed height as a fallback if autosetting or JS fails.
|
||||
$height = $this->FixedHeight;
|
||||
if (!$height) $height = 800;
|
||||
if (!$height) {
|
||||
$height = 800;
|
||||
}
|
||||
$style .= "height: {$height}px; ";
|
||||
|
||||
if ($this->AutoWidth) {
|
||||
$style .= "width: 100%; ";
|
||||
}
|
||||
else if ($this->FixedWidth) {
|
||||
} elseif ($this->FixedWidth) {
|
||||
$style .= "width: {$this->FixedWidth}px; ";
|
||||
}
|
||||
|
||||
@ -89,13 +94,14 @@ class IFramePage extends Page {
|
||||
* @throws ValidationException
|
||||
* @return ValidationResult
|
||||
*/
|
||||
public function validate() {
|
||||
public function validate()
|
||||
{
|
||||
$result = parent::validate();
|
||||
|
||||
//whitelist allowed URL schemes
|
||||
$allowed_schemes = array('http', 'https');
|
||||
if($matches = parse_url($this->IFrameURL)) {
|
||||
if(isset($matches['scheme']) && !in_array($matches['scheme'], $allowed_schemes)) {
|
||||
if ($matches = parse_url($this->IFrameURL)) {
|
||||
if (isset($matches['scheme']) && !in_array($matches['scheme'], $allowed_schemes)) {
|
||||
$result->error(_t('IFramePage.VALIDATION.BANNEDURLSCHEME', "This URL scheme is not allowed."));
|
||||
}
|
||||
}
|
||||
@ -104,14 +110,16 @@ class IFramePage extends Page {
|
||||
}
|
||||
}
|
||||
|
||||
class IFramePage_Controller extends Page_Controller {
|
||||
function init() {
|
||||
class IFramePage_Controller extends Page_Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
if($this->ForceProtocol) {
|
||||
if($this->ForceProtocol == 'http://' && Director::protocol() != 'http://') {
|
||||
if ($this->ForceProtocol) {
|
||||
if ($this->ForceProtocol == 'http://' && Director::protocol() != 'http://') {
|
||||
return $this->redirect(preg_replace('#https://#', 'http://', $this->AbsoluteLink()));
|
||||
} else if($this->ForceProtocol == 'https://' && Director::protocol() != 'https://') {
|
||||
} elseif ($this->ForceProtocol == 'https://' && Director::protocol() != 'https://') {
|
||||
return $this->redirect(preg_replace('#http://#', 'https://', $this->AbsoluteLink()));
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
<?php
|
||||
|
||||
class IFramePageTest extends SapphireTest {
|
||||
|
||||
public function setUp() {
|
||||
class IFramePageTest extends SapphireTest
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Config::nest();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
public function tearDown()
|
||||
{
|
||||
Config::unnest();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
function testGetClass() {
|
||||
public function testGetClass()
|
||||
{
|
||||
$iframe = new IFramePage();
|
||||
$iframe->AutoHeight = 1;
|
||||
$iframe->getClass();
|
||||
@ -25,7 +28,8 @@ class IFramePageTest extends SapphireTest {
|
||||
$this->assertNotContains('iframepage-height-auto', $iframe->getClass());
|
||||
}
|
||||
|
||||
function testGetStyle() {
|
||||
public function testGetStyle()
|
||||
{
|
||||
$iframe = new IFramePage();
|
||||
|
||||
$iframe->FixedHeight = 0;
|
||||
@ -45,7 +49,8 @@ class IFramePageTest extends SapphireTest {
|
||||
$this->assertContains('width: 200px', $iframe->getStyle(), 'Fixed width is settable');
|
||||
}
|
||||
|
||||
function testAllowedUrls() {
|
||||
public function testAllowedUrls()
|
||||
{
|
||||
$iframe = new IFramePage();
|
||||
|
||||
$tests = array(
|
||||
@ -73,20 +78,21 @@ class IFramePageTest extends SapphireTest {
|
||||
)
|
||||
);
|
||||
|
||||
foreach($tests['allowed'] as $url) {
|
||||
foreach ($tests['allowed'] as $url) {
|
||||
$iframe->IFrameURL = $url;
|
||||
$iframe->write();
|
||||
$this->assertContains($iframe->IFrameURL, $url);
|
||||
}
|
||||
|
||||
foreach($tests['banned'] as $url) {
|
||||
foreach ($tests['banned'] as $url) {
|
||||
$iframe->IFrameURL = $url;
|
||||
$this->setExpectedException('ValidationException');
|
||||
$iframe->write();
|
||||
}
|
||||
}
|
||||
|
||||
public function testForceProtocol() {
|
||||
public function testForceProtocol()
|
||||
{
|
||||
$origServer = $_SERVER;
|
||||
|
||||
$page = new IFramePage();
|
||||
|
Loading…
Reference in New Issue
Block a user