------------------------------------------------------------------------------- $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. This is done in toHtml() method. Object are stored as references. * * @package HTML * @access public */ class MECON_HTML_Link extends HTML_Common { /** * Variables to send via GET HTTP method. * * @var array $getVars * @access protected */ var $_getVars = array(); /** * Link contents. * * @var array $contents * @access protected */ var $_contents = array(); /** * Gets GetVars. * * @return array * @access public */ function getGetVars() { return $this->_getVars; } /** * Sets GetVars. * * @param array $getVars GetVars. * * @return void * @access public */ function setGetVars($getVars) { $this->_getVars = $getVars; } // ~X2C // +X2C Operation 178 /** * Constructor. * * @param string $href Hypertext reference. * @param mixed $contents Link contents. * @param array $getVars Array (as key => value pairs) of GET variables to pass to the link. * @param array $attrs Other links (A tag) attributes. * * @return void * @access public */ function MECON_HTML_Link($href = '', $contents = '', $getVars = array(), $attrs = array()) // ~X2C { if (is_array($attrs)) { $attrs['href'] = $href; } else { $attrs .= " href=$href"; } parent::HTML_Common($attrs); $this->_getVars = $getVars; $this->addContents($contents); } // -X2C // +X2C Operation 179 /** * Converts to HTML output. * * @return string * @access public */ function toHtml() // ~X2C { $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); } } $attrs .= ' ' . $key . '="' . htmlentities($val) . '"'; } return "" . $this->getContents() . ''; } // -X2C // +X2C Operation 180 /** * Gets hypertext reference. * * @return string * @access public */ function getHref() // ~X2C { return $this->getAttribute('href'); } // -X2C // +X2C Operation 181 /** * Sets hypertext reference. * * @param string $href Hypertext reference. * * @return void * @access public */ function setHref($href) // ~X2C { $this->updateAttributes(array('href' => $href)); } // -X2C // +X2C Operation 182 /** * Set a GET variable. * * @param string $key Key for the GET variable. * @param mixed &$value Value for the variable. * * @return void * @access public */ function setGetVar($key, &$value) // ~X2C { if (is_object($value)) { $this->attrs[$key] =& $value; } else { $this->attrs[$key] = $value; } } // -X2C // +X2C Operation 183 /** * Updates GET variables. * * @param array $vars Array (as key => value pairs) of GET variables to update. If they doesn't exists, they are added, if they exists, they are updated. * * @return void * @access public */ function updateGetVars($vars) // ~X2C { $this->_getVars += $vars; } // -X2C // +X2C Operation 184 /** * Unsets (removes) GET variables. This method supports variable arguments. * * @param string $key Key of the GET variable to remove. * * @return void * @access public */ function unsetGetVars($key) // ~X2C { $keys = func_get_args(); foreach ($keys as $key) { unset($this->_getVars[$key]); } } // -X2C // +X2C Operation 185 /** * Adds contents to the link. * * @param mixed &$contents Contents to add. Can be an object with a toHtml() method. * * @return void * @access public */ function addContents(&$contents) // ~X2C { if (is_object($contents)) { $this->_contents[] =& $contents; } else { $this->_contents[] = $contents; } } // -X2C // +X2C Operation 186 /** * @return string * @access public */ function getContents() // ~X2C { $html = ''; foreach ($this->_contents as $c) { if (is_object($c) and method_exists($c, 'tohtml')) { $html .= $c->toHtml(); } else { $html .= htmlentities($c); } } return $html; } // -X2C // +X2C Operation 187 /** * @param mixed $contents New link contents. * * @return void * @access public */ function setContents($contents) // ~X2C { $this->_contents = $contents; } // -X2C } // -X2C Class :MECON_HTML_Link ?>