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 -----------------------------------------------------------------------------*/
27 require_once 'HTML/Common.php';
30 * HTML Link representation.
31 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.
32 This is done in toHtml() method. Object are stored as references.
37 class MECON_HTML_Link extends HTML_Common {
39 * Variables to send via GET HTTP method.
44 var $_getVars = array();
49 * @var array $contents
52 var $_contents = array();
62 return $this->_getVars;
68 * @param array $getVars GetVars.
73 function setGetVars($getVars)
75 $this->_getVars = $getVars;
81 * @param string $href Hypertext reference.
82 * @param mixed $contents Link contents.
83 * @param array $getVars Array (as key => value pairs) of GET variables to pass to the link.
84 * @param array $attrs Other links (A tag) attributes.
89 function MECON_HTML_Link($href = '', $contents = '', $getVars = array(), $attrs = array())
91 if (is_array($attrs)) {
92 $attrs['href'] = $href;
93 if (!isset($attrs['class'])){
94 $attrs['class'] = 'mecon_html_link';
97 $attrs .= " href=$href";
99 parent::HTML_Common($attrs);
100 $this->_getVars = $getVars;
101 $this->addContents($contents);
105 * Converts to HTML output.
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)) {
124 $vars[] = urlencode($var) . '[]=' . urlencode($i);
127 $vars[] = urlencode($var) . '=' . urlencode($v);
131 $val .= '?' . join('&', $vars);
134 $val = htmlentities($val);
136 $attrs .= ' ' . $key . '="' . $val . '"';
138 return "<A$attrs>" . $this->getContents() . '</A>';
142 * Gets hypertext reference.
149 return $this->getAttribute('href');
153 * Sets hypertext reference.
155 * @param string $href Hypertext reference.
160 function setHref($href)
162 $this->updateAttributes(array('href' => $href));
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)
176 $this->_getVars[$key] = $value;
180 * Updates GET variables.
182 * @param array $vars Array (as key => value pairs) of GET variables to update.
183 If they doesn't exists, they are added, if they exists, they are updated.
188 function updateGetVars($vars)
190 $this->_getVars += $vars;
194 * Unsets (removes) GET variables. This method supports variable arguments.
196 * @param string $key Key of the GET variable to remove.
201 function unsetGetVars($key)
203 $keys = func_get_args();
204 foreach ($keys as $key) {
205 unset($this->_getVars[$key]);
210 * Adds contents to the link.
212 * @param mixed &$contents Contents to add. Can be an object with a toHtml() method.
217 function addContents($contents)
219 $this->_contents[] = $contents;
226 function getContents()
229 foreach ($this->_contents as $c) {
230 if (is_object($c) and method_exists($c, 'tohtml')) {
231 $html .= $c->toHtml();
233 $html .= htmlentities($c);
240 * @param mixed $contents New link contents.
245 function setContents($contents)
247 $this->_contents = array($contents);
251 * @param mixed $contents New link contents.
258 return '/MECON/css/html/link';