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 -----------------------------------------------------------------------------*/
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 $attrs .= ' ' . $key . '="' . htmlentities($val) . '"';
134 return "<A$attrs>" . $this->getContents() . '</A>';
138 // +X2C Operation 180
140 * Gets hypertext reference.
145 function getHref() // ~X2C
147 return $this->getAttribute('href');
151 // +X2C Operation 181
153 * Sets hypertext reference.
155 * @param string $href Hypertext reference.
160 function setHref($href) // ~X2C
162 $this->updateAttributes(array('href' => $href));
166 // +X2C Operation 182
168 * Set a GET variable.
170 * @param string $key Key for the GET variable.
171 * @param mixed &$value Value for the variable.
176 function setGetVar($key, &$value) // ~X2C
178 if (is_object($value)) {
179 $this->attrs[$key] =& $value;
181 $this->attrs[$key] = $value;
186 // +X2C Operation 183
188 * Updates GET variables.
190 * @param array $vars Array (as key => value pairs) of GET variables to update.
191 If they doesn't exists, they are added, if they exists, they are updated.
196 function updateGetVars($vars) // ~X2C
198 $this->_getVars += $vars;
202 // +X2C Operation 184
204 * Unsets (removes) GET variables. This method supports variable arguments.
206 * @param string $key Key of the GET variable to remove.
211 function unsetGetVars($key) // ~X2C
213 $keys = func_get_args();
214 foreach ($keys as $key) {
215 unset($this->_getVars[$key]);
220 // +X2C Operation 185
222 * Adds contents to the link.
224 * @param mixed &$contents Contents to add. Can be an object with a toHtml() method.
229 function addContents($contents) // ~X2C
231 $this->_contents[] = $contents;
235 // +X2C Operation 186
240 function getContents() // ~X2C
243 foreach ($this->_contents as $c) {
244 if (is_object($c) and method_exists($c, 'tohtml')) {
245 $html .= $c->toHtml();
247 $html .= htmlentities($c);
254 // +X2C Operation 187
256 * @param mixed $contents New link contents.
261 function setContents($contents) // ~X2C
263 $this->_contents = array($contents);
267 } // -X2C Class :MECON_HTML_Link