/**
* The required files
*/
require_once(HTML_BASE_UTIL_PATH.'/Element.php');
require_once(HTML_BASE_UTIL_PATH.'/Tabindex.php');
require_once(HTML_BASE_UTIL_PATH.'/Accesskey.php');
if (defined('HTML_UTIL_COMPONENT_PATH')) {
require_once(HTML_UTIL_COMPONENT_PATH.'/Params.php');
}
/**
* Returns a complete Link as HTML
* <a class="$class" href="$href" title="$title" name="$name" target="_BLANK">$text</a>
* The link may be terminated by a <br /> or surronded by <li> tags
* as specified by the $aux parameter.
* Note: If you specify "\r\n" in the title tag, then a break is automatically added
* <code>
* Usage:
* $link = new Link($text,$href,$class,$title,$aux,$target,$name);
* print $link->getHtml();
* Or
* $link = new Link('','','','','','',$name);
* print $link->getHtml(); // Target name
* Or
* Link::display($text,$href,$class,$title,$aux,$target,$name);
* Or
* Link::display('','','','','','',$name); // Target name
* </code>
*
* @package base
*/
class Link extends Element {
/**
* @var String $text The text to use for the link
*/
var $text = '';
/**
* @var String $href The url to jump to
*/
var $href = '';
/**
* @var String $aux The additional html to add
*/
var $aux = '';
/**
* @var String $target The open in new window
*/
var $target = '';
/**
* Constructor
* @param String $text The text for the link
* @param String $href The url for the link
* @param String $class The css class of the link
* @param String $title The tool tip of the link
* @param String $aux Add 'br' or 'li' html tags, if required
* @param String $target The target for the link I.e. _BLANK
* @param String $name The name for the link
*/
function Link($text='',$href='',$class='',$title='',$aux='',$target='',$name='',$tabindex='',$onclick='',$accesskey='') {
// Must be a link attribute <a name="name">text</a>
$aName = ($name!='' && $text!='')?$name:'';
$value = '';
$aClass = $class!=''?$class:CSS_LINK_COLOR;
//$tabindex = Tabindex::next();
//$onclick = '';
//$accesskey = Accesskey::next($text);
$aTitle = $title!=''?$title:$text; // xhtml 1.0 strict
$aTitle .= $accesskey!=''?' (Alt + '.$accesskey.')':'';
$this->Element($aName,$value,$aClass,$aTitle,$tabindex,$onclick,$accesskey);
$this->text = $text;
$this->aux = $aux;
$this->target = $target;
$linkpath = '';
$strHttp = 'http:/'.'/';
$strHttps = 'https:/'.'/';
if (strpos($href,$strHttp) !==false ||
strpos($href,$strHttps)!==false ||
//strpos($href,'..')!==false ||
strpos($href,'#')!==false ||
strpos($href,'mailto:')!==false ||
strpos($href,'javascript:')!==false) {
// Skip params check
$this->href = $href;
} else {
$this->href = $href!=''?LINK_PATH.$href:$_SERVER['PHP_SELF'];
$params = $this->getParams();
// Strip off all parameters and add them again
$theHref = explode('?',$this->href);
$this->href = $theHref[0].$params;
}
}
/**
* Get the complete html for a link
* @return String the html
*/
function getParams() {
// Do not work with the 'j' as in 'javascript:' or 'mailto:'
// Because the first position IS '0'
$params = '';
$strHttp = 'http:/'.'/';
if (strpos($this->href,$strHttp)!==false ||
//strpos($this->href,'?') !==false ||
strpos($this->href,'javascript:')!==false ||
strpos($this->href,'mailto:')!==false) {
// Ignore
} else {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$paramsArray = Params::getArray($this->href);
$params .= Params::get($paramsArray);
} else {
$querystring = explode('?',$this->href);
if (count($querystring)==2) {
$params = '?'.$querystring[1];
}
}
}
return $params;
}
/**
* Get the complete html for a link
* An image object may be added
* @return String the html
*/
function getHtml() {
$html = $this->html;
if ($this->href!='' || $this->name!='') {
if ($this->aux != '') {
if ($this->aux & (LINK_LAYOUT_LI | LINK_LAYOUT_BR)) {
// Ok
} else {
die($this->getClassName()." Illegal aux=".$this->aux);
}
} else {
// Ok
}
if (DEBUG_LEVEL & DEBUG_LEVEL_SHOW_LI && $this->text!='') {
$html .= "<!-- $this->text -->";
}
if ($this->aux & LINK_LAYOUT_LI) {
$html .= " <li";
$class = "$this->class";
if ($class!='') {
$html .= ' class="'.$class.'"';
}
$html .= '>';
}
if (strpos($this->title,"\r\n")!==false) {
/**
* @todo Does only work in IE, not FireFox
*/
$this->title = str_replace("\r\n","
",$this->title); // <br>
}
$html .= '<a';
if ($this->name!='') {
$html .= $this->getAttribute('name');
} else {
$html .= $this->getAttribute('id');
$html .= $this->getAttribute('class');
$html .= $this->getAttribute('href');
$html .= $this->getAttribute('title');
$html .= $this->getAttribute('target');
$html .= $this->getAttribute('onblur');
$html .= $this->getAttribute('onfocus');
$html .= $this->getAttribute('accesskey');
$html .= $this->getAttribute('tabindex');
}
$html .= '>';
$image = $this->getElements(); // Image as html
if ($image!='') {
$html .= $image;
if ($this->text!='') {
if ($this->aux & LINK_LAYOUT_BR) {
$html .= "<br />"; // <a href="" ...><img ... /><br />Text</a>
} else {
$html .= ' '; // <a href="" ...><img ... /> Text</a>
}
}
}
$text = $this->text;
// 2008-03-13 removed
//$text = str_replace('-',"»",$this->text); // In order to avoid line breaks
$html .= str_replace(' '," ",$text); // In order to avoid line breaks
$html .= "</a>";
if ($this->aux & LINK_LAYOUT_LI) {
$html .= "</li>\r\n";
}
if ($this->aux & LINK_LAYOUT_BR) {
$html .= "<br />\r\n";
}
} else {
$html .= '<!-- '.$this->getClassName()."->getHtml(), both href and name are empty -->\r\n";
}
return $html;
}
/**
* Display html
* <code>
* Usage:
* Link::display($text,$href,$class,$title,$aux,$target,$name);
* </code>
* @static
* @param String $text The text for the link
* @param String $href The url for the link
* @param String $class The css class of the link
* @param String $title The tool tip of the link
* @param String $aux Add 'br' or 'li' html tags, if required
* @param String $target The target for the link. I.e. _BLANK
* @param String $name The name for the link
*/
function display($text='',$href='',$class='',$title='',$aux='',$target='',$name='') {
$html = new Link($text,$href,$class,$title,$aux,$target,$name);
$html->addHtml();
}
}
?>