X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/9ea00a51d80e94e95ff5525f3c63301c86b50d12..7eddd945e06d40240c52993be71ad52b9212f79e:/lib/MECON/HTML/Link.php
diff --git a/lib/MECON/HTML/Link.php b/lib/MECON/HTML/Link.php
index d50e261..d013131 100644
--- a/lib/MECON/HTML/Link.php
+++ b/lib/MECON/HTML/Link.php
@@ -107,29 +107,18 @@ class MECON_HTML_Link extends HTML_Common {
* @return string
* @access public
*/
- function toHtml() // ~X2C
+ function toHtml()
{
$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) or is_array($v)) {
- $v = serialize($v);
- }
- $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() . '';
}
/**
@@ -138,7 +127,7 @@ class MECON_HTML_Link extends HTML_Common {
* @return string
* @access public
*/
- function getHref() // ~X2C
+ function getHref()
{
return $this->getAttribute('href');
}
@@ -151,7 +140,7 @@ class MECON_HTML_Link extends HTML_Common {
* @return void
* @access public
*/
- function setHref($href) // ~X2C
+ function setHref($href)
{
$this->updateAttributes(array('href' => $href));
}
@@ -165,7 +154,7 @@ class MECON_HTML_Link extends HTML_Common {
* @return void
* @access public
*/
- function setGetVar($key, $value) // ~X2C
+ function setGetVar($key, $value)
{
$this->_getVars[$key] = $value;
}
@@ -179,7 +168,7 @@ If they doesn't exists, they are added, if they exists, they are updated.
* @return void
* @access public
*/
- function updateGetVars($vars) // ~X2C
+ function updateGetVars($vars)
{
$this->_getVars += $vars;
}
@@ -192,7 +181,7 @@ If they doesn't exists, they are added, if they exists, they are updated.
* @return void
* @access public
*/
- function unsetGetVars($key) // ~X2C
+ function unsetGetVars($key)
{
$keys = func_get_args();
foreach ($keys as $key) {
@@ -204,20 +193,26 @@ 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) // ~X2C
+ function addContents($contents, $front = false)
{
- $this->_contents[] = $contents;
+ if ($front) {
+ array_unshift($this->_contents, $contents);
+ }
+ else {
+ $this->_contents[] = $contents;
+ }
}
/**
* @return string
* @access public
*/
- function getContents() // ~X2C
+ function getContents()
{
$html = '';
foreach ($this->_contents as $c) {
@@ -236,7 +231,7 @@ If they doesn't exists, they are added, if they exists, they are updated.
* @return void
* @access public
*/
- function setContents($contents) // ~X2C
+ function setContents($contents)
{
$this->_contents = array($contents);
}
@@ -249,7 +244,43 @@ If they doesn't exists, they are added, if they exists, they are updated.
*/
function getCSS()
{
- return '/MECON/css/html/link.css';
+ 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" : '');
}
}