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