| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* THyperLink class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.xisc.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
|
|
9 |
* @version $Id: THyperLink.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Web.UI.WebControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* THyperLink class
|
|
|
15 |
*
|
|
|
16 |
* THyperLink displays a hyperlink on a page. The hyperlink URL is specified
|
|
|
17 |
* via the {@link setNavigateUrl NavigateUrl} property, and link text is via
|
|
|
18 |
* the {@link setText Text} property. It is also possible to display an image
|
|
|
19 |
* by setting the {@link setImageUrl ImageUrl} property. In this case,
|
|
|
20 |
* {@link getText Text} is displayed as the alternate text of the image.
|
|
|
21 |
* The link target is specified via the {@link setTarget Target} property.
|
|
|
22 |
* If both {@link getImageUrl ImageUrl} and {@link getText Text} are empty,
|
|
|
23 |
* the content enclosed within the control tag will be rendered.
|
|
|
24 |
*
|
|
|
25 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
26 |
* @version $Id: THyperLink.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
27 |
* @package System.Web.UI.WebControls
|
|
|
28 |
* @since 3.0
|
|
|
29 |
*/
|
|
|
30 |
class THyperLink extends TWebControl implements IDataRenderer
|
|
|
31 |
{
|
|
|
32 |
/**
|
|
|
33 |
* @return string tag name of the hyperlink
|
|
|
34 |
*/
|
|
|
35 |
protected function getTagName()
|
|
|
36 |
{
|
|
|
37 |
return 'a';
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Adds attributes related to a hyperlink element to renderer.
|
|
|
42 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
43 |
*/
|
|
|
44 |
protected function addAttributesToRender($writer)
|
|
|
45 |
{
|
|
|
46 |
$isEnabled=$this->getEnabled(true);
|
|
|
47 |
if($this->getEnabled() && !$isEnabled)
|
|
|
48 |
$writer->addAttribute('disabled','disabled');
|
|
|
49 |
parent::addAttributesToRender($writer);
|
|
|
50 |
if(($url=$this->getNavigateUrl())!=='' && $isEnabled)
|
|
|
51 |
$writer->addAttribute('href',$url);
|
|
|
52 |
if(($target=$this->getTarget())!=='')
|
|
|
53 |
$writer->addAttribute('target',$target);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Renders the body content of the hyperlink.
|
|
|
58 |
* @param THtmlWriter the writer for rendering
|
|
|
59 |
*/
|
|
|
60 |
public function renderContents($writer)
|
|
|
61 |
{
|
|
|
62 |
if(($imageUrl=$this->getImageUrl())==='')
|
|
|
63 |
{
|
|
|
64 |
if(($text=$this->getText())!=='')
|
|
|
65 |
$writer->write(THttpUtility::htmlEncode($text));
|
|
|
66 |
else if($this->getHasControls())
|
|
|
67 |
parent::renderContents($writer);
|
|
|
68 |
else
|
|
|
69 |
$writer->write(THttpUtility::htmlEncode($this->getNavigateUrl()));
|
|
|
70 |
}
|
|
|
71 |
else
|
|
|
72 |
{
|
|
|
73 |
$this->createImage($imageUrl)->renderControl($writer);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Gets the TImage for rendering the ImageUrl property. This is not for
|
|
|
79 |
* creating dynamic images.
|
|
|
80 |
* @param string image url.
|
|
|
81 |
* @return TImage image control for rendering.
|
|
|
82 |
*/
|
|
|
83 |
protected function createImage($imageUrl)
|
|
|
84 |
{
|
|
|
85 |
$image=Prado::createComponent('System.Web.UI.WebControls.TImage');
|
|
|
86 |
$image->setImageUrl($imageUrl);
|
|
|
87 |
if(($toolTip=$this->getToolTip())!=='')
|
|
|
88 |
$image->setToolTip($toolTip);
|
|
|
89 |
if(($text=$this->getText())!=='')
|
|
|
90 |
$image->setAlternateText($text);
|
|
|
91 |
$image->setBorderWidth('0');
|
|
|
92 |
return $image;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* @return string the text caption of the THyperLink
|
|
|
97 |
*/
|
|
|
98 |
public function getText()
|
|
|
99 |
{
|
|
|
100 |
return $this->getViewState('Text','');
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* Sets the text caption of the THyperLink.
|
|
|
105 |
* @param string the text caption to be set
|
|
|
106 |
*/
|
|
|
107 |
public function setText($value)
|
|
|
108 |
{
|
|
|
109 |
$this->setViewState('Text',$value,'');
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* @return string the location of the image file for the THyperLink
|
|
|
114 |
*/
|
|
|
115 |
public function getImageUrl()
|
|
|
116 |
{
|
|
|
117 |
return $this->getViewState('ImageUrl','');
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* Sets the location of image file of the THyperLink.
|
|
|
122 |
* @param string the image file location
|
|
|
123 |
*/
|
|
|
124 |
public function setImageUrl($value)
|
|
|
125 |
{
|
|
|
126 |
$this->setViewState('ImageUrl',$value,'');
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
/**
|
|
|
130 |
* @return string the URL to link to when the THyperLink component is clicked.
|
|
|
131 |
*/
|
|
|
132 |
public function getNavigateUrl()
|
|
|
133 |
{
|
|
|
134 |
return $this->getViewState('NavigateUrl','');
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* Sets the URL to link to when the THyperLink component is clicked.
|
|
|
139 |
* @param string the URL
|
|
|
140 |
*/
|
|
|
141 |
public function setNavigateUrl($value)
|
|
|
142 |
{
|
|
|
143 |
$this->setViewState('NavigateUrl',$value,'');
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* Returns the URL to link to when the THyperLink component is clicked.
|
|
|
148 |
* This method is required by {@link IDataRenderer}.
|
|
|
149 |
* It is the same as {@link getText()}.
|
|
|
150 |
* @return string the text caption
|
|
|
151 |
* @see getText
|
|
|
152 |
* @since 3.1.0
|
|
|
153 |
*/
|
|
|
154 |
public function getData()
|
|
|
155 |
{
|
|
|
156 |
return $this->getText();
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
/**
|
|
|
160 |
* Sets the URL to link to when the THyperLink component is clicked.
|
|
|
161 |
* This method is required by {@link IDataRenderer}.
|
|
|
162 |
* It is the same as {@link setText()}.
|
|
|
163 |
* @param string the text caption to be set
|
|
|
164 |
* @see setText
|
|
|
165 |
* @since 3.1.0
|
|
|
166 |
*/
|
|
|
167 |
public function setData($value)
|
|
|
168 |
{
|
|
|
169 |
$this->setText($value);
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
/**
|
|
|
173 |
* @return string the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
|
|
|
174 |
*/
|
|
|
175 |
public function getTarget()
|
|
|
176 |
{
|
|
|
177 |
return $this->getViewState('Target','');
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
/**
|
|
|
181 |
* Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
|
|
|
182 |
* @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
|
|
|
183 |
*/
|
|
|
184 |
public function setTarget($value)
|
|
|
185 |
{
|
|
|
186 |
$this->setViewState('Target',$value,'');
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
|