1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
3 Ministerio de EconomÃa
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 -----------------------------------------------------------------------------*/
29 // +X2C Class 892 :MECON_HTML_Link
31 * HTML Link representation.
32 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.
33 This is done in toHtml() method. Object are stored as references.
38 class MECON_HTML_Link extends HTML_Common {
40 * Variables to send via GET HTTP method.
45 var $_getVars = array();
50 * @var array $contents
53 var $_contents = array();
63 return $this->_getVars;
68 * @param array $getVars GetVars.
73 function setGetVars($getVars)
75 $this->_getVars = $getVars;
84 * @param string $href Hypertext reference.
85 * @param mixed $contents Link contents.
86 * @param array $getVars Array (as key => value pairs) of GET variables to pass to the link.
87 * @param array $attrs Other links (A tag) attributes.
92 function MECON_HTML_Link($href = '', $contents = '', $getVars = array(), $attrs = array()) // ~X2C
94 if (is_array($attrs)) {
95 $attrs['href'] = $href;
97 $attrs .= " href=$href";
99 parent::HTML_Common($attrs);
100 $this->_getVars = $getVars;
101 $this->addContents($contents);
105 // +X2C Operation 179
107 * Converts to HTML output.
112 function toHtml() // ~X2C
115 foreach ($this->getAttributes() as $key => $val) {
116 if ($key == 'href') {
118 foreach ($this->_getVars as $var => $v) {
119 if (is_object($v) and method_exists($v, 'tostring')) {
121 } elseif (is_object($v) or is_array($v)) {
124 $vars[] = urlencode($var) . '=' . urlencode($v);
127 $val = '?' . join('&', $vars);
130 $attrs .= ' ' . $key . '="' . htmlentities($val) . '"';
132 return "<A$attrs>" . $this->getContents() . '</A>';
136 // +X2C Operation 180
138 * Gets hypertext reference.
143 function getHref() // ~X2C
145 return $this->getAttribute('href');
149 // +X2C Operation 181
151 * Sets hypertext reference.
153 * @param string $href Hypertext reference.
158 function setHref($href) // ~X2C
160 $this->updateAttributes(array('href' => $href));
164 // +X2C Operation 182
166 * Set a GET variable.
168 * @param string $key Key for the GET variable.
169 * @param mixed &$value Value for the variable.
174 function setGetVar($key, &$value) // ~X2C
176 if (is_object($value)) {
177 $this->attrs[$key] =& $value;
179 $this->attrs[$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 if (is_object($contents)) {
230 $this->_contents[] =& $contents;
232 $this->_contents[] = $contents;
237 // +X2C Operation 186
242 function getContents() // ~X2C
245 foreach ($this->_contents as $c) {
246 if (is_object($c) and method_exists($c, 'tohtml')) {
247 $html .= $c->toHtml();
249 $html .= htmlentities($c);
256 // +X2C Operation 187
258 * @param mixed $contents New link contents.
263 function setContents($contents) // ~X2C
265 $this->_contents = $contents;
269 } // -X2C Class :MECON_HTML_Link