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.
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);
125 $val .= '?' . join('&', $vars);
128 $val = htmlentities($val);
130 $attrs .= ' ' . $key . '="' . $val . '"';
132 return "<A$attrs>" . $this->getContents() . '</A>';
136 * Gets hypertext reference.
141 function getHref() // ~X2C
143 return $this->getAttribute('href');
147 * Sets hypertext reference.
149 * @param string $href Hypertext reference.
154 function setHref($href) // ~X2C
156 $this->updateAttributes(array('href' => $href));
160 * Set a GET variable.
162 * @param string $key Key for the GET variable.
163 * @param mixed $value Value for the variable.
168 function setGetVar($key, $value) // ~X2C
170 $this->_getVars[$key] = $value;
174 * Updates GET variables.
176 * @param array $vars Array (as key => value pairs) of GET variables to update.
177 If they doesn't exists, they are added, if they exists, they are updated.
182 function updateGetVars($vars) // ~X2C
184 $this->_getVars += $vars;
188 * Unsets (removes) GET variables. This method supports variable arguments.
190 * @param string $key Key of the GET variable to remove.
195 function unsetGetVars($key) // ~X2C
197 $keys = func_get_args();
198 foreach ($keys as $key) {
199 unset($this->_getVars[$key]);
204 * Adds contents to the link.
206 * @param mixed &$contents Contents to add. Can be an object with a toHtml() method.
211 function addContents($contents) // ~X2C
213 $this->_contents[] = $contents;
220 function getContents() // ~X2C
223 foreach ($this->_contents as $c) {
224 if (is_object($c) and method_exists($c, 'tohtml')) {
225 $html .= $c->toHtml();
227 $html .= htmlentities($c);
234 * @param mixed $contents New link contents.
239 function setContents($contents) // ~X2C
241 $this->_contents = array($contents);
245 * @param mixed $contents New link contents.
252 return '/MECON/css/html/link';