X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/0f0e41a6f47093189c050a7beeac79144ed8c0d6..cf283b8f59060371d0a82fc349d265218215fcb2:/lib/MECON/HTML/Link.php
diff --git a/lib/MECON/HTML/Link.php b/lib/MECON/HTML/Link.php
index b1835c1..1252dff 100644
--- a/lib/MECON/HTML/Link.php
+++ b/lib/MECON/HTML/Link.php
@@ -24,11 +24,8 @@ Autor: @@author <@@email>
$Id$
-----------------------------------------------------------------------------*/
-// +X2C includes
require_once 'HTML/Common.php';
-// ~X2C
-// +X2C Class 892 :MECON_HTML_Link
/**
* HTML Link representation.
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.
@@ -64,6 +61,7 @@ class MECON_HTML_Link extends HTML_Common {
{
return $this->_getVars;
}
+
/**
* Sets GetVars.
*
@@ -77,9 +75,6 @@ class MECON_HTML_Link extends HTML_Common {
$this->_getVars = $getVars;
}
- // ~X2C
-
- // +X2C Operation 178
/**
* Constructor.
*
@@ -91,10 +86,13 @@ class MECON_HTML_Link extends HTML_Common {
* @return void
* @access public
*/
- function MECON_HTML_Link($href = '', $contents = '', $getVars = array(), $attrs = array()) // ~X2C
+ function MECON_HTML_Link($href = '', $contents = '', $getVars = array(), $attrs = array())
{
if (is_array($attrs)) {
$attrs['href'] = $href;
+ if (!isset($attrs['class'])){
+ $attrs['class'] = 'mecon_html_link';
+ }
} else {
$attrs .= " href=$href";
}
@@ -102,55 +100,38 @@ class MECON_HTML_Link extends HTML_Common {
$this->_getVars = $getVars;
$this->addContents($contents);
}
- // -X2C
- // +X2C Operation 179
/**
* Converts to HTML output.
*
* @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() . '';
}
- // -X2C
- // +X2C Operation 180
/**
* Gets hypertext reference.
*
* @return string
* @access public
*/
- function getHref() // ~X2C
+ function getHref()
{
return $this->getAttribute('href');
}
- // -X2C
- // +X2C Operation 181
/**
* Sets hypertext reference.
*
@@ -159,13 +140,11 @@ class MECON_HTML_Link extends HTML_Common {
* @return void
* @access public
*/
- function setHref($href) // ~X2C
+ function setHref($href)
{
$this->updateAttributes(array('href' => $href));
}
- // -X2C
- // +X2C Operation 182
/**
* Set a GET variable.
*
@@ -175,13 +154,11 @@ class MECON_HTML_Link extends HTML_Common {
* @return void
* @access public
*/
- function setGetVar($key, $value) // ~X2C
+ function setGetVar($key, $value)
{
$this->_getVars[$key] = $value;
}
- // -X2C
- // +X2C Operation 183
/**
* Updates GET variables.
*
@@ -191,13 +168,11 @@ 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;
}
- // -X2C
- // +X2C Operation 184
/**
* Unsets (removes) GET variables. This method supports variable arguments.
*
@@ -206,16 +181,14 @@ 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) {
unset($this->_getVars[$key]);
}
}
- // -X2C
- // +X2C Operation 185
/**
* Adds contents to the link.
*
@@ -224,18 +197,16 @@ If they doesn't exists, they are added, if they exists, they are updated.
* @return void
* @access public
*/
- function addContents($contents) // ~X2C
+ function addContents($contents)
{
$this->_contents[] = $contents;
}
- // -X2C
- // +X2C Operation 186
/**
* @return string
* @access public
*/
- function getContents() // ~X2C
+ function getContents()
{
$html = '';
foreach ($this->_contents as $c) {
@@ -247,21 +218,65 @@ If they doesn't exists, they are added, if they exists, they are updated.
}
return $html;
}
- // -X2C
- // +X2C Operation 187
/**
* @param mixed $contents New link contents.
*
* @return void
* @access public
*/
- function setContents($contents) // ~X2C
+ function setContents($contents)
{
$this->_contents = array($contents);
}
- // -X2C
-} // -X2C Class :MECON_HTML_Link
+ /**
+ * @param mixed $contents New link contents.
+ *
+ * @return void
+ * @access public
+ */
+ function getCSS()
+ {
+ 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