X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/11fc033324d7f8988c422129b6e13f6e3053e05a..c6b15817758e60270fb968945fb7f3164c3f4ef9:/lib/MECON/HTML/Link.php diff --git a/lib/MECON/HTML/Link.php b/lib/MECON/HTML/Link.php index dc86a68..08e5275 100644 --- a/lib/MECON/HTML/Link.php +++ b/lib/MECON/HTML/Link.php @@ -112,30 +112,13 @@ class MECON_HTML_Link extends HTML_Common { $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 "" . $this->getContents() . ''; + return "" . $this->getContents() . ''; } /** @@ -187,7 +170,10 @@ If they doesn't exists, they are added, if they exists, they are updated. */ function updateGetVars($vars) { - $this->_getVars += $vars; + foreach ($vars as $key => $value) + { + $this->_getVars[$key] = $value; + } } /** @@ -210,13 +196,19 @@ If they doesn't exists, they are added, if they exists, they are updated. * 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; + } } /** @@ -258,6 +250,42 @@ If they doesn't exists, they are added, if they exists, they are updated. 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