mirror of
https://github.com/silverstripe/silverstripe-iframe
synced 2024-10-22 11:05:51 +02:00
Merge pull request #26 from creative-commoners/pulls/2.0/vendorise-miframe
Pulls/2.0/vendorise miframe
This commit is contained in:
commit
df6bd2107e
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -4,3 +4,4 @@
|
||||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/.scrutinizer.yml export-ignore
|
||||
/codecov.yml
|
||||
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.DS_Store
|
@ -1,5 +1,11 @@
|
||||
inherit: true
|
||||
|
||||
build:
|
||||
nodes:
|
||||
analysis:
|
||||
tests:
|
||||
override: [php-scrutinizer-run]
|
||||
|
||||
checks:
|
||||
php:
|
||||
code_rating: true
|
||||
|
35
.travis.yml
35
.travis.yml
@ -1,34 +1,35 @@
|
||||
# See https://github.com/silverstripe/silverstripe-travis-support for setup details
|
||||
language: php
|
||||
|
||||
sudo: false
|
||||
|
||||
env:
|
||||
global:
|
||||
- COMPOSER_ROOT_VERSION=1.0.x-dev
|
||||
- CORE_RELEASE=4
|
||||
# The path of the module when installed by composer
|
||||
- MODULE_PATH=iframe
|
||||
- COMPOSER_ROOT_VERSION=2.0.x-dev
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- php: 5.6
|
||||
env: DB=MYSQL
|
||||
env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1
|
||||
- php: 7.0
|
||||
env: DB=MYSQL
|
||||
env: DB=MYSQL PHPUNIT_TEST=1
|
||||
- php: 7.1
|
||||
env: DB=MYSQL
|
||||
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
|
||||
- php: 7.2
|
||||
env: DB=MYSQL PHPUNIT_TEST=1
|
||||
|
||||
before_script:
|
||||
- composer self-update || true
|
||||
# Init PHP
|
||||
- phpenv rehash
|
||||
- phpenv config-rm xdebug.ini
|
||||
- echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
|
||||
|
||||
# Install composer dependencies
|
||||
- composer validate
|
||||
- git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support
|
||||
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
|
||||
- cd ~/builds/ss
|
||||
- composer install --prefer-dist
|
||||
- composer require --no-update silverstripe/recipe-cms:1.0.x-dev
|
||||
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit $MODULE_PATH/tests
|
||||
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
|
||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
|
||||
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs code/ tests/ *.php; fi
|
||||
|
||||
after_success:
|
||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
|
||||
|
@ -1,2 +1 @@
|
||||
<?php
|
||||
|
||||
|
@ -7,6 +7,7 @@ use SilverStripe\Forms\DropdownField;
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\NumericField;
|
||||
use SilverStripe\Forms\HTMLEditor\HtmlEditorField;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -40,22 +41,28 @@ class IFramePage extends Page
|
||||
|
||||
$fields->removeFieldFromTab('Root.Main', 'Content');
|
||||
$fields->addFieldToTab('Root.Main', $url = new TextField('IFrameURL', 'Iframe URL'));
|
||||
$url->setRightTitle('Can be absolute (<em>http://silverstripe.com</em>) or relative to this site (<em>about-us</em>).');
|
||||
$url->setRightTitle(
|
||||
'Can be absolute (<em>http://silverstripe.com</em>) or relative to this site (<em>about-us</em>).'
|
||||
);
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
DropdownField::create('ForceProtocol', 'Force protocol?')
|
||||
->setSource(array('http://' => 'http://', 'https://' => 'https://'))
|
||||
->setEmptyString('')
|
||||
->setDescription('Avoids mixed content warnings when iframe content is just available under a specific protocol'),
|
||||
->setDescription(
|
||||
'Avoids mixed content warnings when iframe content is just available under a specific protocol'
|
||||
),
|
||||
'Metadata'
|
||||
);
|
||||
$fields->addFieldToTab('Root.Main', new CheckboxField('AutoHeight', 'Auto height (only works with same domain URLs)'));
|
||||
$fields->addFieldToTab('Root.Main', new CheckboxField('AutoWidth', 'Auto width (100% of the available space)'));
|
||||
$fields->addFieldToTab('Root.Main', new NumericField('FixedHeight', 'Fixed height (in pixels)'));
|
||||
$fields->addFieldToTab('Root.Main', new NumericField('FixedWidth', 'Fixed width (in pixels)'));
|
||||
$fields->addFieldToTab('Root.Main', new HtmlEditorField('Content', 'Content (appears above iframe)'));
|
||||
$fields->addFieldToTab('Root.Main', new HtmlEditorField('BottomContent', 'Content (appears below iframe)'));
|
||||
$fields->addFieldToTab('Root.Main', new HtmlEditorField('AlternateContent', 'Alternate Content (appears when user has iframes disabled)'));
|
||||
$fields->addFieldsToTab('Root.Main', [
|
||||
CheckboxField::create('AutoHeight', 'Auto height (only works with same domain URLs)'),
|
||||
CheckboxField::create('AutoWidth', 'Auto width (100% of the available space)'),
|
||||
NumericField::create('FixedHeight', 'Fixed height (in pixels)'),
|
||||
NumericField::create('FixedWidth', 'Fixed width (in pixels)'),
|
||||
HtmlEditorField::create('Content', 'Content (appears above iframe)'),
|
||||
HtmlEditorField::create('BottomContent', 'Content (appears below iframe)'),
|
||||
HtmlEditorField::create('AlternateContent', 'Alternate Content (appears when user has iframes disabled)')
|
||||
]);
|
||||
|
||||
// Move the Metadata field to last position, but make a check for it's
|
||||
// existence first.
|
||||
|
@ -11,17 +11,19 @@ class IFramePageController extends ContentController
|
||||
protected function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
if ($this->ForceProtocol) {
|
||||
if ($this->ForceProtocol == 'http://' && Director::protocol() != 'http://') {
|
||||
return $this->redirect(preg_replace('#https://#', 'http://', $this->AbsoluteLink()));
|
||||
} elseif ($this->ForceProtocol == 'https://' && Director::protocol() != 'https://') {
|
||||
return $this->redirect(preg_replace('#http://#', 'https://', $this->AbsoluteLink()));
|
||||
}
|
||||
$currentProtocol = Director::protocol();
|
||||
$desiredProtocol = $this->ForceProtocol;
|
||||
if ($desiredProtocol && $currentProtocol !== $desiredProtocol) {
|
||||
$enforcedLocation = preg_replace(
|
||||
"#^${currentProtocol}#",
|
||||
$desiredProtocol,
|
||||
$this->AbsoluteLink()
|
||||
);
|
||||
return $this->redirect($enforcedLocation);
|
||||
}
|
||||
|
||||
if ($this->IFrameURL) {
|
||||
Requirements::javascript('iframe/javascript/iframe_page.js');
|
||||
Requirements::javascript('silverstripe/iframe: javascript/iframe_page.js');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
codecov.yml
Normal file
1
codecov.yml
Normal file
@ -0,0 +1 @@
|
||||
comment: false
|
@ -1,33 +1,36 @@
|
||||
{
|
||||
"name": "silverstripe/iframe",
|
||||
"description": "Add an iFrame pagetype to SilverStripe, to show content from another website",
|
||||
"type": "silverstripe-module",
|
||||
"keywords": ["silverstripe"],
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mateusz Uzdowski",
|
||||
"email": "mateusz@silverstripe.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": "^4@dev",
|
||||
"silverstripe/cms": "^4@dev"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/PHPUnit": "^5.7"
|
||||
},
|
||||
"autoload": {
|
||||
"name": "silverstripe/iframe",
|
||||
"description": "Add an iFrame pagetype to SilverStripe, to show content from another website",
|
||||
"type": "silverstripe-vendormodule",
|
||||
"keywords": ["silverstripe"],
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mateusz Uzdowski",
|
||||
"email": "mateusz@silverstripe.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/cms": "^4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"squizlabs/php_codesniffer": "^3.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"SilverStripe\\IFrame\\": "code/",
|
||||
"SilverStripe\\IFrame\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
"extra": {
|
||||
"expose": [
|
||||
"javascript"
|
||||
],
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
Copyright (c) 2016, SilverStripe Limited
|
||||
Copyright (c) 2017, SilverStripe Limited
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
9
phpcs.xml.dist
Normal file
9
phpcs.xml.dist
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset name="SilverStripe">
|
||||
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
|
||||
|
||||
<rule ref="PSR2" >
|
||||
<!-- Current exclusions -->
|
||||
<exclude name="PSR1.Methods.CamelCapsMethodName" />
|
||||
</rule>
|
||||
</ruleset>
|
13
phpunit.xml.dist
Normal file
13
phpunit.xml.dist
Normal file
@ -0,0 +1,13 @@
|
||||
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
|
||||
<testsuite name="Default">
|
||||
<directory>tests/</directory>
|
||||
</testsuite>
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">code/</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">tests/</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@ -12,18 +12,6 @@ class IFramePageTest extends SapphireTest
|
||||
{
|
||||
protected $usesDatabase = true;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Config::nest();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Config::unnest();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testGetClass()
|
||||
{
|
||||
$iframe = new IFramePage();
|
||||
@ -109,40 +97,40 @@ class IFramePageTest extends SapphireTest
|
||||
$page->URLSegment = 'iframe';
|
||||
$page->IFrameURL = 'http://target.com';
|
||||
|
||||
Config::inst()->update(Director::class, 'alternate_protocol', 'http');
|
||||
Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com');
|
||||
Config::modify()->set(Director::class, 'alternate_protocol', 'http');
|
||||
Config::modify()->set(Director::class, 'alternate_base_url', 'http://host.com');
|
||||
$page->ForceProtocol = '';
|
||||
$controller = new IFramePageController($page);
|
||||
$controller->doInit();
|
||||
$response = $controller->getResponse();
|
||||
$this->assertNull($response->getHeader('Location'));
|
||||
|
||||
Config::inst()->update(Director::class, 'alternate_protocol', 'https');
|
||||
Config::inst()->update(Director::class, 'alternate_base_url', 'https://host.com');
|
||||
Config::modify()->set(Director::class, 'alternate_protocol', 'https');
|
||||
Config::modify()->set(Director::class, 'alternate_base_url', 'https://host.com');
|
||||
$page->ForceProtocol = '';
|
||||
$controller = new IFramePageController($page);
|
||||
$controller->doInit();
|
||||
$response = $controller->getResponse();
|
||||
$this->assertNull($response->getHeader('Location'));
|
||||
|
||||
Config::inst()->update(Director::class, 'alternate_protocol', 'http');
|
||||
Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com');
|
||||
Config::modify()->set(Director::class, 'alternate_protocol', 'http');
|
||||
Config::modify()->set(Director::class, 'alternate_base_url', 'http://host.com');
|
||||
$page->ForceProtocol = 'http://';
|
||||
$controller = new IFramePageController($page);
|
||||
$controller->doInit();
|
||||
$response = $controller->getResponse();
|
||||
$this->assertNull($response->getHeader('Location'));
|
||||
|
||||
Config::inst()->update(Director::class, 'alternate_protocol', 'http');
|
||||
Config::inst()->update(Director::class, 'alternate_base_url', 'http://host.com');
|
||||
Config::modify()->set(Director::class, 'alternate_protocol', 'http');
|
||||
Config::modify()->set(Director::class, 'alternate_base_url', 'http://host.com');
|
||||
$page->ForceProtocol = 'https://';
|
||||
$controller = new IFramePageController($page);
|
||||
$controller->doInit();
|
||||
$response = $controller->getResponse();
|
||||
$this->assertEquals($response->getHeader('Location'), 'https://host.com/iframe/');
|
||||
|
||||
Config::inst()->update(Director::class, 'alternate_protocol', 'https');
|
||||
Config::inst()->update(Director::class, 'alternate_base_url', 'https://host.com');
|
||||
Config::modify()->set(Director::class, 'alternate_protocol', 'https');
|
||||
Config::modify()->set(Director::class, 'alternate_base_url', 'https://host.com');
|
||||
$page->ForceProtocol = 'http://';
|
||||
$controller = new IFramePageController($page);
|
||||
$controller->doInit();
|
||||
|
Loading…
Reference in New Issue
Block a user