@@ -15,125 +15,125 @@ |
||
15 | 15 | |
16 | 16 | class IFramePage extends Page |
17 | 17 | { |
18 | - private static $db = array( |
|
19 | - 'IFrameURL' => 'Text', |
|
20 | - 'AutoHeight' => 'Boolean(1)', |
|
21 | - 'AutoWidth' => 'Boolean(1)', |
|
22 | - 'FixedHeight' => 'Int(500)', |
|
23 | - 'FixedWidth' => 'Int(0)', |
|
24 | - 'AlternateContent' => 'HTMLText', |
|
25 | - 'BottomContent' => 'HTMLText', |
|
26 | - 'ForceProtocol' => 'Varchar', |
|
27 | - ); |
|
28 | - |
|
29 | - private static $defaults = array( |
|
30 | - 'AutoHeight' => '1', |
|
31 | - 'AutoWidth' => '1', |
|
32 | - 'FixedHeight' => '500', |
|
33 | - 'FixedWidth' => '0' |
|
34 | - ); |
|
35 | - |
|
36 | - private static $description = 'Embeds an iframe into the body of the page.'; |
|
37 | - |
|
38 | - private static $singular_name = 'IFrame Page'; |
|
39 | - |
|
40 | - public function getCMSFields() |
|
41 | - { |
|
42 | - $fields = parent::getCMSFields(); |
|
43 | - |
|
44 | - $fields->removeFieldFromTab('Root.Main', 'Content'); |
|
45 | - $fields->addFieldToTab('Root.Main', $url = new TextField('IFrameURL', 'Iframe URL')); |
|
46 | - $url->setRightTitle( |
|
47 | - 'Can be absolute (<em>http://silverstripe.com</em>) or relative to this site (<em>about-us</em>).' |
|
48 | - ); |
|
49 | - $fields->addFieldToTab( |
|
50 | - 'Root.Main', |
|
51 | - DropdownField::create('ForceProtocol', 'Force protocol?') |
|
52 | - ->setSource(array('http://' => 'http://', 'https://' => 'https://')) |
|
53 | - ->setEmptyString('') |
|
54 | - ->setDescription( |
|
55 | - 'Avoids mixed content warnings when iframe content is just available under a specific protocol' |
|
56 | - ), |
|
57 | - 'Metadata' |
|
58 | - ); |
|
59 | - $fields->addFieldsToTab('Root.Main', [ |
|
60 | - CheckboxField::create('AutoHeight', 'Auto height (only works with same domain URLs)'), |
|
61 | - CheckboxField::create('AutoWidth', 'Auto width (100% of the available space)'), |
|
62 | - NumericField::create('FixedHeight', 'Fixed height (in pixels)'), |
|
63 | - NumericField::create('FixedWidth', 'Fixed width (in pixels)'), |
|
64 | - HtmlEditorField::create('Content', 'Content (appears above iframe)'), |
|
65 | - HtmlEditorField::create('BottomContent', 'Content (appears below iframe)'), |
|
66 | - HtmlEditorField::create('AlternateContent', 'Alternate Content (appears when user has iframes disabled)') |
|
67 | - ]); |
|
68 | - |
|
69 | - // Move the Metadata field to last position, but make a check for it's |
|
70 | - // existence first. |
|
71 | - // |
|
72 | - // See https://github.com/silverstripe-labs/silverstripe-iframe/issues/18 |
|
73 | - $mainTab = $fields->findOrMakeTab('Root.Main'); |
|
74 | - $mainTabFields = $mainTab->FieldList(); |
|
75 | - $metaDataField = $mainTabFields->fieldByName('Metadata'); |
|
76 | - if ($metaDataField) { |
|
77 | - $mainTabFields->removeByName('Metadata'); |
|
78 | - $mainTabFields->push($metaDataField); |
|
79 | - } |
|
80 | - return $fields; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Compute class from the size parameters. |
|
85 | - */ |
|
86 | - public function getClass() |
|
87 | - { |
|
88 | - $class = ''; |
|
89 | - if ($this->AutoHeight) { |
|
90 | - $class .= 'iframepage-height-auto'; |
|
91 | - } |
|
92 | - |
|
93 | - return $class; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Compute style from the size parameters. |
|
98 | - */ |
|
99 | - public function getStyle() |
|
100 | - { |
|
101 | - $style = ''; |
|
102 | - |
|
103 | - // Always add fixed height as a fallback if autosetting or JS fails. |
|
104 | - $height = $this->FixedHeight; |
|
105 | - if (!$height) { |
|
106 | - $height = 800; |
|
107 | - } |
|
108 | - $style .= "height: {$height}px; "; |
|
109 | - |
|
110 | - if ($this->AutoWidth) { |
|
111 | - $style .= "width: 100%; "; |
|
112 | - } elseif ($this->FixedWidth) { |
|
113 | - $style .= "width: {$this->FixedWidth}px; "; |
|
114 | - } |
|
115 | - |
|
116 | - return $style; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Ensure that the IFrameURL is a valid url and prevents XSS |
|
121 | - * |
|
122 | - * @throws ValidationException |
|
123 | - * @return ValidationResult |
|
124 | - */ |
|
125 | - public function validate() |
|
126 | - { |
|
127 | - $result = parent::validate(); |
|
128 | - |
|
129 | - //whitelist allowed URL schemes |
|
130 | - $allowed_schemes = array('http', 'https'); |
|
131 | - if ($matches = parse_url($this->IFrameURL)) { |
|
132 | - if (isset($matches['scheme']) && !in_array($matches['scheme'], $allowed_schemes)) { |
|
133 | - $result->addError(_t(__CLASS__ . '.VALIDATION_BANNEDURLSCHEME', "This URL scheme is not allowed.")); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - return $result; |
|
138 | - } |
|
18 | + private static $db = array( |
|
19 | + 'IFrameURL' => 'Text', |
|
20 | + 'AutoHeight' => 'Boolean(1)', |
|
21 | + 'AutoWidth' => 'Boolean(1)', |
|
22 | + 'FixedHeight' => 'Int(500)', |
|
23 | + 'FixedWidth' => 'Int(0)', |
|
24 | + 'AlternateContent' => 'HTMLText', |
|
25 | + 'BottomContent' => 'HTMLText', |
|
26 | + 'ForceProtocol' => 'Varchar', |
|
27 | + ); |
|
28 | + |
|
29 | + private static $defaults = array( |
|
30 | + 'AutoHeight' => '1', |
|
31 | + 'AutoWidth' => '1', |
|
32 | + 'FixedHeight' => '500', |
|
33 | + 'FixedWidth' => '0' |
|
34 | + ); |
|
35 | + |
|
36 | + private static $description = 'Embeds an iframe into the body of the page.'; |
|
37 | + |
|
38 | + private static $singular_name = 'IFrame Page'; |
|
39 | + |
|
40 | + public function getCMSFields() |
|
41 | + { |
|
42 | + $fields = parent::getCMSFields(); |
|
43 | + |
|
44 | + $fields->removeFieldFromTab('Root.Main', 'Content'); |
|
45 | + $fields->addFieldToTab('Root.Main', $url = new TextField('IFrameURL', 'Iframe URL')); |
|
46 | + $url->setRightTitle( |
|
47 | + 'Can be absolute (<em>http://silverstripe.com</em>) or relative to this site (<em>about-us</em>).' |
|
48 | + ); |
|
49 | + $fields->addFieldToTab( |
|
50 | + 'Root.Main', |
|
51 | + DropdownField::create('ForceProtocol', 'Force protocol?') |
|
52 | + ->setSource(array('http://' => 'http://', 'https://' => 'https://')) |
|
53 | + ->setEmptyString('') |
|
54 | + ->setDescription( |
|
55 | + 'Avoids mixed content warnings when iframe content is just available under a specific protocol' |
|
56 | + ), |
|
57 | + 'Metadata' |
|
58 | + ); |
|
59 | + $fields->addFieldsToTab('Root.Main', [ |
|
60 | + CheckboxField::create('AutoHeight', 'Auto height (only works with same domain URLs)'), |
|
61 | + CheckboxField::create('AutoWidth', 'Auto width (100% of the available space)'), |
|
62 | + NumericField::create('FixedHeight', 'Fixed height (in pixels)'), |
|
63 | + NumericField::create('FixedWidth', 'Fixed width (in pixels)'), |
|
64 | + HtmlEditorField::create('Content', 'Content (appears above iframe)'), |
|
65 | + HtmlEditorField::create('BottomContent', 'Content (appears below iframe)'), |
|
66 | + HtmlEditorField::create('AlternateContent', 'Alternate Content (appears when user has iframes disabled)') |
|
67 | + ]); |
|
68 | + |
|
69 | + // Move the Metadata field to last position, but make a check for it's |
|
70 | + // existence first. |
|
71 | + // |
|
72 | + // See https://github.com/silverstripe-labs/silverstripe-iframe/issues/18 |
|
73 | + $mainTab = $fields->findOrMakeTab('Root.Main'); |
|
74 | + $mainTabFields = $mainTab->FieldList(); |
|
75 | + $metaDataField = $mainTabFields->fieldByName('Metadata'); |
|
76 | + if ($metaDataField) { |
|
77 | + $mainTabFields->removeByName('Metadata'); |
|
78 | + $mainTabFields->push($metaDataField); |
|
79 | + } |
|
80 | + return $fields; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Compute class from the size parameters. |
|
85 | + */ |
|
86 | + public function getClass() |
|
87 | + { |
|
88 | + $class = ''; |
|
89 | + if ($this->AutoHeight) { |
|
90 | + $class .= 'iframepage-height-auto'; |
|
91 | + } |
|
92 | + |
|
93 | + return $class; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Compute style from the size parameters. |
|
98 | + */ |
|
99 | + public function getStyle() |
|
100 | + { |
|
101 | + $style = ''; |
|
102 | + |
|
103 | + // Always add fixed height as a fallback if autosetting or JS fails. |
|
104 | + $height = $this->FixedHeight; |
|
105 | + if (!$height) { |
|
106 | + $height = 800; |
|
107 | + } |
|
108 | + $style .= "height: {$height}px; "; |
|
109 | + |
|
110 | + if ($this->AutoWidth) { |
|
111 | + $style .= "width: 100%; "; |
|
112 | + } elseif ($this->FixedWidth) { |
|
113 | + $style .= "width: {$this->FixedWidth}px; "; |
|
114 | + } |
|
115 | + |
|
116 | + return $style; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Ensure that the IFrameURL is a valid url and prevents XSS |
|
121 | + * |
|
122 | + * @throws ValidationException |
|
123 | + * @return ValidationResult |
|
124 | + */ |
|
125 | + public function validate() |
|
126 | + { |
|
127 | + $result = parent::validate(); |
|
128 | + |
|
129 | + //whitelist allowed URL schemes |
|
130 | + $allowed_schemes = array('http', 'https'); |
|
131 | + if ($matches = parse_url($this->IFrameURL)) { |
|
132 | + if (isset($matches['scheme']) && !in_array($matches['scheme'], $allowed_schemes)) { |
|
133 | + $result->addError(_t(__CLASS__ . '.VALIDATION_BANNEDURLSCHEME', "This URL scheme is not allowed.")); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + return $result; |
|
138 | + } |
|
139 | 139 | } |
@@ -130,7 +130,7 @@ |
||
130 | 130 | $allowed_schemes = array('http', 'https'); |
131 | 131 | if ($matches = parse_url($this->IFrameURL)) { |
132 | 132 | if (isset($matches['scheme']) && !in_array($matches['scheme'], $allowed_schemes)) { |
133 | - $result->addError(_t(__CLASS__ . '.VALIDATION_BANNEDURLSCHEME', "This URL scheme is not allowed.")); |
|
133 | + $result->addError(_t(__CLASS__.'.VALIDATION_BANNEDURLSCHEME', "This URL scheme is not allowed.")); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 |