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