2 // vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Created: Tue Jul 22 18:16:09 2003 |
17 // | Author: Leandro Lucarella <llucar@mecon.gov.ar> |
18 // +----------------------------------------------------------------------+
24 require_once 'HTML/Common.php';
27 // +X2C Class 214 :HTML_Link
29 * HTML Link representation.
30 When adding GET variables, if the value is an object, it looks for a toString() method, if it doesn't exists or if is an array, it serializes the object/array to get a string value.
31 This is done in toHtml() method. Object are stored as references.
36 class HTML_Link extends HTML_Common {
38 * Variables to send via GET HTTP method.
43 var $_getVars = array();
48 * @var array $contents
51 var $_contents = array();
61 return $this->_getVars;
66 * @param array $getVars GetVars.
71 function setGetVars($getVars)
73 $this->_getVars = $getVars;
82 * @param string $href Hypertext reference.
83 * @param mixed &$contents Link contents.
84 * @param array $getVars Array (as key => value pairs) of GET variables to pass to the link.
85 * @param array $attrs Other links (A tag) attributes.
90 function HTML_Link($href = '', &$contents = '', $getVars = array(), $attrs = array()) // ~X2C
92 if (is_array($attrs)) {
93 $attrs['href'] = $href;
95 $attrs .= " href=$href";
97 parent::HTML_Common($attrs);
98 $this->_getVars = $getVars;
99 $this->addContents($contents);
103 // +X2C Operation 216
105 * Converts to HTML output.
110 function toHtml() // ~X2C
113 foreach ($this->getAttributes() as $key => $val) {
114 if ($key == 'href') {
116 foreach ($this->_getVars() as $var => $v) {
117 if (is_object($v) and method_exists($v, 'tostring')) {
119 } elseif (is_object($v) or is_array($v)) {
122 $vars[] = urlencode($var) . '=' . urlencode($v);
124 $val = '?' . join('&', $vars);
126 $attrs .= ' ' . $key . '="' . htmlentities($val) . '"';
128 return "<A$attrs>" . htmlentities($this->getContents) . '</A>';
132 // +X2C Operation 217
134 * Gets hypertext reference.
139 function getHref() // ~X2C
141 return $this->getAttribute('href');
145 // +X2C Operation 218
147 * Sets hypertext reference.
149 * @param string $href Hypertext reference.
154 function setHref($href) // ~X2C
156 $this->updateAttributes(array('href' => $href));
160 // +X2C Operation 225
162 * Set a GET variable.
164 * @param string $key Key for the GET variable.
165 * @param mixed &$value Value for the variable.
170 function setGetVar($key, &$value) // ~X2C
172 if (is_object($value)) {
173 $this->attrs[$key] =& $value;
175 $this->attrs[$key] = $value;
180 // +X2C Operation 226
182 * Updates GET variables.
184 * @param array $vars Array (as key => value pairs) of GET variables to update.
185 If they doesn't exists, they are added, if they exists, they are updated.
190 function updateGetVars($vars) // ~X2C
192 $this->_getVars += $vars;
196 // +X2C Operation 227
198 * Unsets (removes) GET variables. This method supports variable arguments.
200 * @param string $key Key of the GET variable to remove.
205 function unsetGetVars($key) // ~X2C
207 $keys = func_get_args();
208 foreach ($keys as $key) {
209 unset($this->_getVars($key));
214 // +X2C Operation 230
216 * Adds contents to the link.
218 * @param mixed &$contents Contents to add. Can be an object with a toHtml() method.
223 function addContents(&$contents) // ~X2C
225 if (is_object($contents)) {
226 $this->_contents[] =& $contents;
228 $this->_contents[] = $contents;
233 // +X2C Operation 231
238 function getContents() // ~X2C
241 foreach ($this->_contents as $c) {
242 if (is_object($c) and method_exists($c, 'tohtml')) {
243 $html .= $c->toHtml();
252 // +X2C Operation 232
254 * @param mixed $contents New link contents.
259 function setContents($contents) // ~X2C
261 $this->_contents = $contents;
265 } // -X2C Class :HTML_Link