| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TImage class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TImage.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Web.UI.WebControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* TImage class
|
|
|
15 |
*
|
|
|
16 |
* TImage displays an image on a page. The image is specified via the
|
|
|
17 |
* {@link setImageUrl ImageUrl} property which takes a relative or absolute
|
|
|
18 |
* URL to the image file. The alignment of the image displayed is set by
|
|
|
19 |
* the {@link setImageAlign ImageAlign} property. To set alternative texts
|
|
|
20 |
* or long description of the image, use {@link setAlternateText AlternateText}
|
|
|
21 |
* or {@link setDescriptionUrl DescriptionUrl} property, respectively.
|
|
|
22 |
*
|
|
|
23 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
24 |
* @version $Id: TImage.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
25 |
* @package System.Web.UI.WebControls
|
|
|
26 |
* @since 3.0
|
|
|
27 |
*/
|
|
|
28 |
class TImage extends TWebControl implements IDataRenderer
|
|
|
29 |
{
|
|
|
30 |
/**
|
|
|
31 |
* @return string tag name of image control
|
|
|
32 |
*/
|
|
|
33 |
protected function getTagName()
|
|
|
34 |
{
|
|
|
35 |
return 'img';
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Adds attributes related to an HTML image element to renderer.
|
|
|
40 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
41 |
*/
|
|
|
42 |
protected function addAttributesToRender($writer)
|
|
|
43 |
{
|
|
|
44 |
$writer->addAttribute('src',$this->getImageUrl());
|
|
|
45 |
$writer->addAttribute('alt',$this->getAlternateText());
|
|
|
46 |
if(($desc=$this->getDescriptionUrl())!=='')
|
|
|
47 |
$writer->addAttribute('longdesc',$desc);
|
|
|
48 |
if(($align=$this->getImageAlign())!=='')
|
|
|
49 |
$writer->addAttribute('align',$align);
|
|
|
50 |
parent::addAttributesToRender($writer);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Renders the body content of the image.
|
|
|
55 |
* Nothing to be rendered within image tags.
|
|
|
56 |
* @param THtmlWriter the writer for rendering
|
|
|
57 |
*/
|
|
|
58 |
public function renderContents($writer)
|
|
|
59 |
{
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* @return string the alternative text displayed in the TImage component when the image is unavailable.
|
|
|
64 |
*/
|
|
|
65 |
public function getAlternateText()
|
|
|
66 |
{
|
|
|
67 |
return $this->getViewState('AlternateText','');
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Sets the alternative text to be displayed in the TImage when the image is unavailable.
|
|
|
72 |
* @param string the alternative text
|
|
|
73 |
*/
|
|
|
74 |
public function setAlternateText($value)
|
|
|
75 |
{
|
|
|
76 |
$this->setViewState('AlternateText',$value,'');
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* @return string the alignment of the image with respective to other elements on the page, defaults to empty.
|
|
|
81 |
*/
|
|
|
82 |
public function getImageAlign()
|
|
|
83 |
{
|
|
|
84 |
return $this->getViewState('ImageAlign','');
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Sets the alignment of the image with respective to other elements on the page.
|
|
|
89 |
* Possible values include: absbottom, absmiddle, baseline, bottom, left,
|
|
|
90 |
* middle, right, texttop, and top. If an empty string is passed in,
|
|
|
91 |
* imagealign attribute will not be rendered.
|
|
|
92 |
* @param string the alignment of the image
|
|
|
93 |
*/
|
|
|
94 |
public function setImageAlign($value)
|
|
|
95 |
{
|
|
|
96 |
$this->setViewState('ImageAlign',$value,'');
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* @return string the URL of the image file
|
|
|
101 |
*/
|
|
|
102 |
public function getImageUrl()
|
|
|
103 |
{
|
|
|
104 |
return $this->getViewState('ImageUrl','');
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* @param string the URL of the image file
|
|
|
109 |
*/
|
|
|
110 |
public function setImageUrl($value)
|
|
|
111 |
{
|
|
|
112 |
$this->setViewState('ImageUrl',$value,'');
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
/**
|
|
|
116 |
* Returns the URL of the image file.
|
|
|
117 |
* This method is required by {@link IDataRenderer}.
|
|
|
118 |
* It is the same as {@link getImageUrl()}.
|
|
|
119 |
* @return string the URL of the image file.
|
|
|
120 |
* @see getImageUrl
|
|
|
121 |
* @since 3.1.0
|
|
|
122 |
*/
|
|
|
123 |
public function getData()
|
|
|
124 |
{
|
|
|
125 |
return $this->getImageUrl();
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* Sets the URL of the image.
|
|
|
130 |
* This method is required by {@link IDataRenderer}.
|
|
|
131 |
* It is the same as {@link setImageUrl()}.
|
|
|
132 |
* @param string the URL of the image file.
|
|
|
133 |
* @see setImageUrl
|
|
|
134 |
* @since 3.1.0
|
|
|
135 |
*/
|
|
|
136 |
public function setData($value)
|
|
|
137 |
{
|
|
|
138 |
$this->setImageUrl($value);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
/**
|
|
|
142 |
* @return string the URL to long description
|
|
|
143 |
*/
|
|
|
144 |
public function getDescriptionUrl()
|
|
|
145 |
{
|
|
|
146 |
return $this->getViewState('DescriptionUrl','');
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* @param string the URL to the long description of the image.
|
|
|
151 |
*/
|
|
|
152 |
public function setDescriptionUrl($value)
|
|
|
153 |
{
|
|
|
154 |
$this->setViewState('DescriptionUrl',$value,'');
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
|