|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* THyperLink class file. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Qiang Xue <[email protected]> |
|
6
|
|
|
* @link http://www.xisc.com/ |
|
7
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
8
|
|
|
* @package Prado\Web\UI\WebControls |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Prado\Web\UI\WebControls; |
|
12
|
|
|
|
|
13
|
|
|
use Prado\Prado; |
|
14
|
|
|
use Prado\Web\THttpUtility; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* THyperLink class |
|
18
|
|
|
* |
|
19
|
|
|
* THyperLink displays a hyperlink on a page. The hyperlink URL is specified |
|
20
|
|
|
* via the {@link setNavigateUrl NavigateUrl} property, and link text is via |
|
21
|
|
|
* the {@link setText Text} property. It is also possible to display an image |
|
22
|
|
|
* by setting the {@link setImageUrl ImageUrl} property. In this case, |
|
23
|
|
|
* the style of the image displayed can be set using the |
|
24
|
|
|
* {@link setImageStyle ImageStyle} property and {@link getText Text} is |
|
25
|
|
|
* displayed as the alternate text of the image. |
|
26
|
|
|
* |
|
27
|
|
|
* The link target is specified via the {@link setTarget Target} property. |
|
28
|
|
|
* If both {@link getImageUrl ImageUrl} and {@link getText Text} are empty, |
|
29
|
|
|
* the content enclosed within the control tag will be rendered. |
|
30
|
|
|
* |
|
31
|
|
|
* @author Qiang Xue <[email protected]> |
|
32
|
|
|
* @package Prado\Web\UI\WebControls |
|
33
|
|
|
* @since 3.0 |
|
34
|
|
|
*/ |
|
35
|
|
|
class THyperLink extends \Prado\Web\UI\WebControls\TWebControl implements \Prado\IDataRenderer |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @return string tag name of the hyperlink |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function getTagName() |
|
41
|
|
|
{ |
|
42
|
|
|
return 'a'; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Adds attributes related to a hyperlink element to renderer. |
|
47
|
|
|
* @param THtmlWriter $writer the writer used for the rendering purpose |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
protected function addAttributesToRender($writer) |
|
50
|
|
|
{ |
|
51
|
|
|
$isEnabled = $this->getEnabled(true); |
|
52
|
|
|
if ($this->getEnabled() && !$isEnabled) { |
|
53
|
|
|
$writer->addAttribute('disabled', 'disabled'); |
|
54
|
|
|
} |
|
55
|
|
|
parent::addAttributesToRender($writer); |
|
56
|
|
|
if (($url = $this->getNavigateUrl()) !== '' && $isEnabled) { |
|
57
|
|
|
$writer->addAttribute('href', $url); |
|
58
|
|
|
} |
|
59
|
|
|
if (($target = $this->getTarget()) !== '') { |
|
60
|
|
|
$writer->addAttribute('target', $target); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Renders the body content of the hyperlink. |
|
66
|
|
|
* @param THtmlWriter $writer the writer for rendering |
|
67
|
|
|
*/ |
|
68
|
|
|
public function renderContents($writer) |
|
69
|
|
|
{ |
|
70
|
|
|
if (($imageUrl = $this->getImageUrl()) === '') { |
|
71
|
|
|
if (($text = $this->getText()) !== '') { |
|
72
|
|
|
$writer->write(THttpUtility::htmlEncode($text)); |
|
73
|
|
|
} elseif ($this->getHasControls()) { |
|
74
|
|
|
parent::renderContents($writer); |
|
75
|
|
|
} else { |
|
76
|
|
|
$writer->write(THttpUtility::htmlEncode($this->getNavigateUrl())); |
|
77
|
|
|
} |
|
78
|
|
|
} else { |
|
79
|
|
|
$this->createImage($imageUrl)->renderControl($writer); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Gets the TImage for rendering the ImageUrl property. This is not for |
|
85
|
|
|
* creating dynamic images. |
|
86
|
|
|
* @param string $imageUrl image url. |
|
87
|
|
|
* @return TImage image control for rendering. |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function createImage($imageUrl) |
|
90
|
|
|
{ |
|
91
|
|
|
$image = new TImage; |
|
92
|
|
|
$image->setImageUrl($imageUrl); |
|
93
|
|
|
if (($toolTip = $this->getToolTip()) !== '') { |
|
94
|
|
|
$image->setToolTip($toolTip); |
|
95
|
|
|
} |
|
96
|
|
|
if (($text = $this->getText()) !== '') { |
|
97
|
|
|
$image->setAlternateText($text); |
|
98
|
|
|
} |
|
99
|
|
|
if (($style = $this->getViewState('ImageStyle', null)) !== null) { |
|
100
|
|
|
$image->getStyle()->copyFrom($style); |
|
101
|
|
|
} |
|
102
|
|
|
return $image; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return string the text caption of the THyperLink |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getText() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->getViewState('Text', ''); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Sets the text caption of the THyperLink. |
|
115
|
|
|
* @param string $value the text caption to be set |
|
116
|
|
|
*/ |
|
117
|
|
|
public function setText($value) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->setViewState('Text', $value, ''); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return string the alignment of the image with respective to other elements on the page, defaults to empty. |
|
124
|
|
|
* @deprecated use the ImageStyle property to get the float and/or vertical-align CSS properties instead |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getImageAlign() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->getImageStyle()->getImageAlign(); |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Sets the alignment of the image with respective to other elements on the page. |
|
133
|
|
|
* Possible values include: absbottom, absmiddle, baseline, bottom, left, |
|
134
|
|
|
* middle, right, texttop, and top. If an empty string is passed in, |
|
135
|
|
|
* imagealign attribute will not be rendered. |
|
136
|
|
|
* @param string $value the alignment of the image |
|
137
|
|
|
* @deprecated use the ImageStyle property to set the float and/or vertical-align CSS properties instead |
|
138
|
|
|
*/ |
|
139
|
|
|
public function setImageAlign($value) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->getImageStyle()->setImageAlign($value); |
|
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @return string height of the image in the THyperLink |
|
146
|
|
|
* @deprecated use the ImageStyle.Height property to get the height instead |
|
147
|
|
|
*/ |
|
148
|
|
|
public function getImageHeight() |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->getImageStyle()->getHeight(); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Sets the height of the image in the THyperLink |
|
155
|
|
|
* @param string $value height of the image in the THyperLink |
|
156
|
|
|
* @deprecated use the ImageStyle property to set the height CSS property instead |
|
157
|
|
|
*/ |
|
158
|
|
|
public function setImageHeight($value) |
|
159
|
|
|
{ |
|
160
|
|
|
$this->getImageStyle()->setHeight($value); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @return string the location of the image file for the THyperLink |
|
165
|
|
|
*/ |
|
166
|
|
|
public function getImageUrl() |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->getViewState('ImageUrl', ''); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Sets the location of image file of the THyperLink. |
|
173
|
|
|
* @param string $value the image file location |
|
174
|
|
|
*/ |
|
175
|
|
|
public function setImageUrl($value) |
|
176
|
|
|
{ |
|
177
|
|
|
$this->setViewState('ImageUrl', $value, ''); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @return string width of the image in the THyperLink |
|
182
|
|
|
* @deprecated use the ImageStyle.Width property to get the width property instead |
|
183
|
|
|
*/ |
|
184
|
|
|
public function getImageWidth() |
|
185
|
|
|
{ |
|
186
|
|
|
return $this->getImageStyle()->getWidth(); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Sets the width of the image in the THyperLink |
|
191
|
|
|
* @param string $value width of the image |
|
192
|
|
|
* @deprecated use the ImageStyle property to set the width CSS property instead |
|
193
|
|
|
*/ |
|
194
|
|
|
public function setImageWidth($value) |
|
195
|
|
|
{ |
|
196
|
|
|
$this->getImageStyle()->setWidth($value); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @return TStyle the style for the inner image |
|
201
|
|
|
*/ |
|
202
|
|
|
public function getImageStyle() |
|
203
|
|
|
{ |
|
204
|
|
|
if (($style = $this->getViewState('ImageStyle', null)) === null) { |
|
205
|
|
|
$style = new TStyle; |
|
206
|
|
|
$this->setViewState('ImageStyle', $style, null); |
|
207
|
|
|
} |
|
208
|
|
|
return $style; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @return string the URL to link to when the THyperLink component is clicked. |
|
213
|
|
|
*/ |
|
214
|
|
|
public function getNavigateUrl() |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->getViewState('NavigateUrl', ''); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Sets the URL to link to when the THyperLink component is clicked. |
|
221
|
|
|
* @param string $value the URL |
|
222
|
|
|
*/ |
|
223
|
|
|
public function setNavigateUrl($value) |
|
224
|
|
|
{ |
|
225
|
|
|
$this->setViewState('NavigateUrl', $value, ''); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Returns the URL to link to when the THyperLink component is clicked. |
|
230
|
|
|
* This method is required by {@link \Prado\IDataRenderer}. |
|
231
|
|
|
* It is the same as {@link getText()}. |
|
232
|
|
|
* @return string the text caption |
|
233
|
|
|
* @see getText |
|
234
|
|
|
* @since 3.1.0 |
|
235
|
|
|
*/ |
|
236
|
|
|
public function getData() |
|
237
|
|
|
{ |
|
238
|
|
|
return $this->getText(); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Sets the URL to link to when the THyperLink component is clicked. |
|
243
|
|
|
* This method is required by {@link \Prado\IDataRenderer}. |
|
244
|
|
|
* It is the same as {@link setText()}. |
|
245
|
|
|
* @param string $value the text caption to be set |
|
246
|
|
|
* @see setText |
|
247
|
|
|
* @since 3.1.0 |
|
248
|
|
|
*/ |
|
249
|
|
|
public function setData($value) |
|
250
|
|
|
{ |
|
251
|
|
|
$this->setText($value); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* @return string the target window or frame to display the Web page content linked to when the THyperLink component is clicked. |
|
256
|
|
|
*/ |
|
257
|
|
|
public function getTarget() |
|
258
|
|
|
{ |
|
259
|
|
|
return $this->getViewState('Target', ''); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked. |
|
264
|
|
|
* @param string $value the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string. |
|
265
|
|
|
*/ |
|
266
|
|
|
public function setTarget($value) |
|
267
|
|
|
{ |
|
268
|
|
|
$this->setViewState('Target', $value, ''); |
|
269
|
|
|
} |
|
270
|
|
|
} |
|
271
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths