$attrs = '';
foreach ($this->getAttributes() as $key => $val) {
if ($key == 'href') {
- $vars = array();
- foreach ($this->_getVars as $var => $v) {
- if (is_object($v) and method_exists($v, 'tostring')) {
- $v = $v->tostring();
- } elseif (is_object($v)) {
- $v = serialize($v);
- }
- if (is_array($v)) {
- foreach ($v as $i) {
- $vars[] = urlencode($var) . '[]=' . urlencode($i);
- }
- } else {
- $vars[] = urlencode($var) . '=' . urlencode($v);
- }
- }
- if ($vars) {
- $val .= '?' . join('&', $vars);
- }
+ $val = $this->getURI();
} else {
$val = htmlentities($val);
}
$attrs .= ' ' . $key . '="' . $val . '"';
}
- return "<A$attrs>" . $this->getContents() . '</A>';
+ return "<a$attrs>" . $this->getContents() . '</a>';
}
/**
* Adds contents to the link.
*
* @param mixed &$contents Contents to add. Can be an object with a toHtml() method.
+ * @param bool $front Tells where to put the new content.
*
* @return void
* @access public
*/
- function addContents($contents)
+ function addContents($contents, $front = false)
{
- $this->_contents[] = $contents;
+ if ($front) {
+ array_unshift($this->_contents, $contents);
+ }
+ else {
+ $this->_contents[] = $contents;
+ }
}
/**
return '/MECON/css/html/link';
}
+ /**
+ * Gets the query string generated with the GET vars.
+ *
+ * @return GET query string.
+ */
+ function getQueryString()
+ {
+ $vars = array();
+ foreach ($this->_getVars as $var => $v) {
+ if (is_object($v) and method_exists($v, 'tostring')) {
+ $v = $v->tostring();
+ } elseif (is_object($v)) {
+ $v = serialize($v);
+ }
+ if (is_array($v)) {
+ foreach ($v as $i) {
+ $vars[] = urlencode($var) . '[]=' . urlencode($i);
+ }
+ } else {
+ $vars[] = urlencode($var) . '=' . urlencode($v);
+ }
+ }
+ return join('&', $vars);
+ }
+
+ /**
+ * Gets the URI (base page with the query string).
+ *
+ * @return URI string.
+ */
+ function getURI()
+ {
+ $query = $this->getQueryString();
+ return $this->getAttribute('href') . ($query ? "?$query" : '');
+ }
+
}
?>
\ No newline at end of file