|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* TInlineFrame class file. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Jason Ragsdale <[email protected]> |
|
6
|
|
|
* @author Harry Pottash <[email protected]> |
|
7
|
|
|
* @link https://github.com/pradosoft/prado |
|
8
|
|
|
* @copyright Copyright © 2005-2016 The PRADO Group |
|
9
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
|
10
|
|
|
* @package Prado\Web\UI\WebControls |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Prado\Web\UI\WebControls; |
|
14
|
|
|
|
|
15
|
|
|
use Prado\TPropertyValue; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* TInlineFrame class |
|
19
|
|
|
* |
|
20
|
|
|
* TInlineFrame displays an inline frame (iframe) on a Web page. |
|
21
|
|
|
* The location of the frame content is specified by {@link setFrameUrl FrameUrl}. |
|
22
|
|
|
* The frame's alignment is specified by {@link setAlign Align}. |
|
23
|
|
|
* The {@link setMarginWidth MarginWidth} and {@link setMarginHeight MarginHeight} |
|
24
|
|
|
* properties define the number of pixels to use as the left/right margins and |
|
25
|
|
|
* top/bottom margins, respectively, within the inline frame. |
|
26
|
|
|
* The {@link setScrollBars ScrollBars} property specifies whether scrollbars are |
|
27
|
|
|
* provided for the inline frame. And {@link setDescriptionUrl DescriptionUrl} |
|
28
|
|
|
* gives the URI of a long description of the frame's contents. |
|
29
|
|
|
* |
|
30
|
|
|
* Original Prado v2 IFrame Author Information |
|
31
|
|
|
* @author Jason Ragsdale <[email protected]> |
|
32
|
|
|
* @author Harry Pottash <[email protected]> |
|
33
|
|
|
* @package Prado\Web\UI\WebControls |
|
34
|
|
|
* @since 3.0 |
|
35
|
|
|
*/ |
|
36
|
|
|
class TInlineFrame extends \Prado\Web\UI\WebControls\TWebControl implements \Prado\IDataRenderer |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @return string tag name of the iframe. |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function getTagName() |
|
42
|
|
|
{ |
|
43
|
|
|
return 'iframe'; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return TInlineFrameAlign alignment of the iframe. Defaults to TInlineFrameAlign::NotSet. |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getAlign() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getViewState('Align', TInlineFrameAlign::NotSet); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param TInlineFrameAlign $value alignment of the iframe. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function setAlign($value) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->setViewState('Align', TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\WebControls\\TInlineFrameAlign'), TInlineFrameAlign::NotSet); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return string the URL to long description |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getDescriptionUrl() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getViewState('DescriptionUrl', ''); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $value the URL to the long description of the image. |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setDescriptionUrl($value) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->setViewState('DescriptionUrl', $value, ''); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return bool whether there should be a visual separator between the frames. Defaults to true. |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getShowBorder() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->getViewState('ShowBorder', true); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param bool $value whether there should be a visual separator between the frames. |
|
88
|
|
|
*/ |
|
89
|
|
|
public function setShowBorder($value) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->setViewState('ShowBorder', TPropertyValue::ensureBoolean($value), true); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string URL that this iframe will load content from. Defaults to ''. |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getFrameUrl() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->getViewState('FrameUrl', ''); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param string $value URL that this iframe will load content from. |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setFrameUrl($value) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->setViewState('FrameUrl', $value, ''); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Returns the URL that this iframe will load content from |
|
112
|
|
|
* This method is required by {@link \Prado\IDataRenderer}. |
|
113
|
|
|
* It is the same as {@link getFrameUrl()}. |
|
114
|
|
|
* @return string the URL that this iframe will load content from |
|
115
|
|
|
* @see getFrameUrl |
|
116
|
|
|
* @since 3.1.0 |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getData() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->getFrameUrl(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Sets the URL that this iframe will load content from. |
|
125
|
|
|
* This method is required by {@link \Prado\IDataRenderer}. |
|
126
|
|
|
* It is the same as {@link setFrameUrl()}. |
|
127
|
|
|
* @param string $value the URL that this iframe will load content from |
|
128
|
|
|
* @see setFrameUrl |
|
129
|
|
|
* @since 3.1.0 |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setData($value) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->setFrameUrl($value); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return TInlineFrameScrollBars the visibility and position of scroll bars in an iframe. Defaults to TInlineFrameScrollBars::Auto. |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getScrollBars() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->getViewState('ScrollBars', TInlineFrameScrollBars::Auto); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param TInlineFrameScrollBars $value the visibility and position of scroll bars in an iframe. |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setScrollBars($value) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->setViewState('ScrollBars', TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\WebControls\\TInlineFrameScrollBars'), TInlineFrameScrollBars::Auto); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return int the width of the control |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getWidth() |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->getViewState('Width', -1); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @param int $value the width of the control |
|
162
|
|
|
*/ |
|
163
|
|
View Code Duplication |
public function setWidth($value) |
|
|
|
|
|
|
164
|
|
|
{ |
|
165
|
|
|
if (($value = TPropertyValue::ensureInteger($value)) < 0) { |
|
166
|
|
|
$value = -1; |
|
167
|
|
|
} |
|
168
|
|
|
$this->setViewState('Width', $value, -1); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return int the height of the control |
|
173
|
|
|
*/ |
|
174
|
|
|
public function getHeight() |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->getViewState('Height', -1); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @param int $value the height of the control |
|
181
|
|
|
*/ |
|
182
|
|
View Code Duplication |
public function setHeight($value) |
|
|
|
|
|
|
183
|
|
|
{ |
|
184
|
|
|
if (($value = TPropertyValue::ensureInteger($value)) < 0) { |
|
185
|
|
|
$value = -1; |
|
186
|
|
|
} |
|
187
|
|
|
$this->setViewState('Height', $value, -1); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @return int the amount of space, in pixels, that should be left between |
|
192
|
|
|
* the frame's contents and the left and right margins. Defaults to -1, meaning not set. |
|
193
|
|
|
*/ |
|
194
|
|
|
public function getMarginWidth() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->getViewState('MarginWidth', -1); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @param int $value the amount of space, in pixels, that should be left between |
|
201
|
|
|
* the frame's contents and the left and right margins. |
|
202
|
|
|
*/ |
|
203
|
|
View Code Duplication |
public function setMarginWidth($value) |
|
|
|
|
|
|
204
|
|
|
{ |
|
205
|
|
|
if (($value = TPropertyValue::ensureInteger($value)) < 0) { |
|
206
|
|
|
$value = -1; |
|
207
|
|
|
} |
|
208
|
|
|
$this->setViewState('MarginWidth', $value, -1); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @return int the amount of space, in pixels, that should be left between |
|
213
|
|
|
* the frame's contents and the top and bottom margins. Defaults to -1, meaning not set. |
|
214
|
|
|
*/ |
|
215
|
|
|
public function getMarginHeight() |
|
216
|
|
|
{ |
|
217
|
|
|
return $this->getViewState('MarginHeight', -1); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @param int $value the amount of space, in pixels, that should be left between |
|
222
|
|
|
* the frame's contents and the top and bottom margins. |
|
223
|
|
|
*/ |
|
224
|
|
View Code Duplication |
public function setMarginHeight($value) |
|
|
|
|
|
|
225
|
|
|
{ |
|
226
|
|
|
if (($value = TPropertyValue::ensureInteger($value)) < 0) { |
|
227
|
|
|
$value = -1; |
|
228
|
|
|
} |
|
229
|
|
|
$this->setViewState('MarginHeight', $value, -1); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* Adds attribute name-value pairs to renderer. |
|
234
|
|
|
* This overrides the parent implementation with additional button specific attributes. |
|
235
|
|
|
* @param THtmlWriter $writer the writer used for the rendering purpose |
|
236
|
|
|
*/ |
|
237
|
|
|
protected function addAttributesToRender($writer) |
|
238
|
|
|
{ |
|
239
|
|
|
if ($this->getID() !== '') { |
|
240
|
|
|
$writer->addAttribute('name', $this->getUniqueID()); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
if (($src = $this->getFrameUrl()) !== '') { |
|
244
|
|
|
$writer->addAttribute('src', $src); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
if (($align = strtolower($this->getAlign())) !== 'notset') { |
|
248
|
|
|
$writer->addAttribute('align', $align); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
$scrollBars = $this->getScrollBars(); |
|
252
|
|
|
if ($scrollBars === TInlineFrameScrollBars::None) { |
|
253
|
|
|
$writer->addAttribute('scrolling', 'no'); |
|
254
|
|
|
} elseif ($scrollBars === TInlineFrameScrollBars::Both) { |
|
255
|
|
|
$writer->addAttribute('scrolling', 'yes'); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
if (!$this->getShowBorder()) { |
|
259
|
|
|
$writer->addAttribute('frameborder', '0'); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
if (($longdesc = $this->getDescriptionUrl()) !== '') { |
|
263
|
|
|
$writer->addAttribute('longdesc', $longdesc); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
if (($width = $this->getWidth()) !== -1) { |
|
267
|
|
|
$writer->addAttribute('width', $width); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
if (($height = $this->getHeight()) !== -1) { |
|
271
|
|
|
$writer->addAttribute('height', $height); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
if (($marginheight = $this->getMarginHeight()) !== -1) { |
|
275
|
|
|
$writer->addAttribute('marginheight', $marginheight); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
if (($marginwidth = $this->getMarginWidth()) !== -1) { |
|
279
|
|
|
$writer->addAttribute('marginwidth', $marginwidth); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
parent::addAttributesToRender($writer); |
|
283
|
|
|
} |
|
284
|
|
|
} |
|
285
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.