1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
5 -------------------------------------------------------------------------------
6 This file is part of meconlib.
8 meconlib is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option)
13 meconlib is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License; if not,
18 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 Boston, MA 02111-1307 USA
20 -------------------------------------------------------------------------------
21 Creado: Thu Aug 21 15:09:10 2003
22 Autor: @@author <@@email>
23 -------------------------------------------------------------------------------
25 -----------------------------------------------------------------------------*/
28 require_once 'HTML/Common.php';
31 // +X2C Class 892 :MECON_HTML_Link
33 * HTML Link representation.
34 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.
35 This is done in toHtml() method. Object are stored as references.
40 class MECON_HTML_Link extends HTML_Common {
42 * Variables to send via GET HTTP method.
47 var $_getVars = array();
52 * @var array $contents
55 var $_contents = array();
65 return $this->_getVars;
70 * @param array $getVars GetVars.
75 function setGetVars($getVars)
77 $this->_getVars = $getVars;
86 * @param string $href Hypertext reference.
87 * @param mixed $contents Link contents.
88 * @param array $getVars Array (as key => value pairs) of GET variables to pass to the link.
89 * @param array $attrs Other links (A tag) attributes.
94 function MECON_HTML_Link($href = '', $contents = '', $getVars = array(), $attrs = array()) // ~X2C
96 if (is_array($attrs)) {
97 $attrs['href'] = $href;
99 $attrs .= " href=$href";
101 parent::HTML_Common($attrs);
102 $this->_getVars = $getVars;
103 $this->addContents($contents);
107 // +X2C Operation 179
109 * Converts to HTML output.
114 function toHtml() // ~X2C
117 foreach ($this->getAttributes() as $key => $val) {
118 if ($key == 'href') {
120 foreach ($this->_getVars as $var => $v) {
121 if (is_object($v) and method_exists($v, 'tostring')) {
123 } elseif (is_object($v) or is_array($v)) {
126 $vars[] = urlencode($var) . '=' . urlencode($v);
129 $val .= '?' . join('&', $vars);
132 $val = htmlentities($val);
134 $attrs .= ' ' . $key . '="' . $val . '"';
136 return "<A$attrs>" . $this->getContents() . '</A>';
140 // +X2C Operation 180
142 * Gets hypertext reference.
147 function getHref() // ~X2C
149 return $this->getAttribute('href');
153 // +X2C Operation 181
155 * Sets hypertext reference.
157 * @param string $href Hypertext reference.
162 function setHref($href) // ~X2C
164 $this->updateAttributes(array('href' => $href));
168 // +X2C Operation 182
170 * Set a GET variable.
172 * @param string $key Key for the GET variable.
173 * @param mixed $value Value for the variable.
178 function setGetVar($key, $value) // ~X2C
180 $this->_getVars[$key] = $value;
184 // +X2C Operation 183
186 * Updates GET variables.
188 * @param array $vars Array (as key => value pairs) of GET variables to update.
189 If they doesn't exists, they are added, if they exists, they are updated.
194 function updateGetVars($vars) // ~X2C
196 $this->_getVars += $vars;
200 // +X2C Operation 184
202 * Unsets (removes) GET variables. This method supports variable arguments.
204 * @param string $key Key of the GET variable to remove.
209 function unsetGetVars($key) // ~X2C
211 $keys = func_get_args();
212 foreach ($keys as $key) {
213 unset($this->_getVars[$key]);
218 // +X2C Operation 185
220 * Adds contents to the link.
222 * @param mixed &$contents Contents to add. Can be an object with a toHtml() method.
227 function addContents($contents) // ~X2C
229 $this->_contents[] = $contents;
233 // +X2C Operation 186
238 function getContents() // ~X2C
241 foreach ($this->_contents as $c) {
242 if (is_object($c) and method_exists($c, 'tohtml')) {
243 $html .= $c->toHtml();
245 $html .= htmlentities($c);
252 // +X2C Operation 187
254 * @param mixed $contents New link contents.
259 function setContents($contents) // ~X2C
261 $this->_contents = array($contents);
265 } // -X2C Class :MECON_HTML_Link