/**
* The required files
*/
require_once(HTML_BASE_UTIL_PATH.'/Link.php');
require_once(HTML_BASIC_UTIL_PATH.'/Message.php');
if (defined('HTML_UTIL_COMPONENT_PATH')) {
require_once(HTML_UTIL_COMPONENT_PATH.'/Request.php');
require_once(HTML_UTIL_COMPONENT_PATH.'/Params.php');
}
if (defined('HTML_LOG_UTIL_PATH')) {
require_once(HTML_LOG_UTIL_PATH.'/Log.php');
}
/**
* Returns a complete predefined Link as HTML.
* The link is found by the $name
* <code>
* Usage:
* $name = LINK_CLOSE; // Or one of the following
* // LINK_DENMARK, LINK_CLOSE, LINK_START, LINK_RETURNX, LINK_BACK, LINK_FIND,
* // LINK_UPDATE, LINK_CMS_HEAD, LINK_CMS_CONTENT, LINK_MAIL, LINK_LOGIN,
* // LINK_LOGOFF, LINK_RETURN, LINK_PRINT
* $html = new Links($name,$text,$class,$title,$aux,$target);
* print $html->getHtml();
* Or
* Links::display($name,$text,$class,$title,$aux,$target);
* </code>
* @package base
*/
class Links extends Link {
/**
* Constructor
* @param String $name The name of an image i.e. 'logo'
* @param String $text The text 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
*/
function Links($name='',$text='',$class='',$title='',$aux='',$target='') {
$href = ''; // TODO overrule ?
$theHref = $this->getUrl($href,$name); // Update href
$theText = $this->getText($text,$name);
$theClass = $this->getClass($class,$name);
$theTitle = $this->getTitle($title,$name);
$this->Link($theText,$theHref,$theClass,$theTitle,$aux,$target);
}
/**
* Get the complete url for a Link icluding the request parameters
* @param String $name The name of a link i.e. LINK_PRINT
* @param String $href The name of an external link i.e. 'design/'
* @return String the html
*/
function getUrl($href,$name) {
$url = $this->getHref($href,$name);
$params = "";
switch ($name) {
case LINK_DENMARK:
case LINK_GERMANY:
case LINK_ENGLAND:
case LINK_FRANCE:
case LINK_ITALY:
case LINK_NORWAY:
case LINK_SWEDEN:
case LINK_USA:
$url .= $this->nextLanguage($href,$name);
break;
case LINK_START:
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(@REQUEST_CMS_USERNAME=>''));
}
$url .= $params;
break;
case LINK_FIND:
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get();
}
$url = @LINK_HREF_SEARCH.$params;
break;
case LINK_UPDATE:
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get();
}
$url .= $params;
break;
case LINK_CMS_HEAD:
if (defined('VIEW_CMS_HEAD_LANGUAGE')) {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(REQUEST_COMMAND=>VIEW_CMS_HEAD_LANGUAGE));
}
$url .= $params;
}
break;
case LINK_CMS_NEWS:
if (defined('VIEW_CMS_NEWS_LANGUAGE')) {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(REQUEST_COMMAND=>VIEW_CMS_NEWS_LANGUAGE));
}
$url .= $params;
}
break;
case LINK_CMS_CONTENT:
if (defined('VIEW_CMS_CONTENT_LANGUAGE')) {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(REQUEST_COMMAND=>VIEW_CMS_CONTENT_LANGUAGE));
}
$url .= $params;
}
break;
case LINK_CMS_TOP:
if (defined('VIEW_CMS_TOP_LANGUAGE')) {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(REQUEST_COMMAND=>VIEW_CMS_TOP_LANGUAGE));
}
$url .= $params;
}
break;
case LINK_CMS_LEFT:
if (defined('VIEW_CMS_LEFT_LANGUAGE')) {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(REQUEST_COMMAND=>VIEW_CMS_LEFT_LANGUAGE));
}
$url .= $params;
}
break;
case LINK_CMS_RIGHT:
if (defined('VIEW_CMS_RIGHT_LANGUAGE')) {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(REQUEST_COMMAND=>VIEW_CMS_RIGHT_LANGUAGE));
}
$url .= $params;
}
break;
case LINK_CMS_BOTTOM:
if (defined('VIEW_CMS_BOTTOM_LANGUAGE')) {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(REQUEST_COMMAND=>VIEW_CMS_BOTTOM_LANGUAGE));
}
$url .= $params;
}
break;
case LINK_MAIL:
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get();
}
$url .= LINK_HREF_EMAIL.$params;
break;
case LINK_LOGIN:
if (defined('VIEW_LOGIN_FORM')) {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(REQUEST_COMMAND=>VIEW_LOGIN_FORM));
}
$url .= LINK_HREF_LOGIN.$params;
}
break;
case LINK_LOGOFF:
if (defined('VIEW_LOGOFF_FORM')) {
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get(array(REQUEST_COMMAND=>VIEW_LOGOFF_FORM));
}
$url .= LINK_HREF_LOGIN.$params;
}
break;
case LINK_RETURN:
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get();
}
$url .= '/'.$params;
break;
case LINK_BACK:
// Ignore, because of javascript::back();
break;
case LINK_PRINT:
$params = $this->getPrinterParams();
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$url .= Params::get($params);
}
break;
default:
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get();
}
$url .= $params;
break;
}
return $url;
}
/**
* Get the parameters for the print link for the supported packages
* @return array The array of supported packages
*/
function getPrinterParams() {
$params = array();
if (defined('REQUEST_COMMAND') && defined('VIEW_PRINTER')) {
$params[REQUEST_COMMAND] = VIEW_PRINTER;
}
if (defined('REQUEST_COMPONENT_SHOW') && defined('COMPONENT_SHOW_PRINTER')) {
$params[REQUEST_COMPONENT_SHOW] = COMPONENT_SHOW_PRINTER;
}
if (defined('REQUEST_LAYOUT_SHOW') && defined('LAYOUT_SHOW_PRINTER')) {
$params[REQUEST_LAYOUT_SHOW] = LAYOUT_SHOW_PRINTER;
}
if (defined('REQUEST_LINK_SHOW') && defined('LINK_SHOW_PRINTER')) {
$params[REQUEST_LINK_SHOW] = LINK_SHOW_PRINTER;
}
if (defined('REQUEST_TAB_SHOW') && defined('TAB_SHOW_PRINTER')) {
$params[REQUEST_TAB_SHOW] = TAB_SHOW_PRINTER;
}
if (defined('REQUEST_CMS_SHOW') && defined('CMS_SHOW_PRINTER')) {
$params[REQUEST_CMS_SHOW] = CMS_SHOW_PRINTER;
}
if (defined('REQUEST_SKELETON_SHOW') && defined('SKELETON_SHOW_PRINTER')) {
$params[REQUEST_SKELETON_SHOW] = SKELETON_SHOW_PRINTER;
}
if (defined('REQUEST_GOOGLE_ADS_SHOW') && defined('GOOGLE_ADS_SHOW_PRINTER')) {
$params[REQUEST_GOOGLE_ADS_SHOW] = GOOGLE_ADS_SHOW_PRINTER;
}
if (defined('REQUEST_GOOGLE_MAPS_SHOW') && defined('GOOGLE_MAPS_SHOW_PRINTER')) {
$params[REQUEST_GOOGLE_MAPS_SHOW] = GOOGLE_MAPS_SHOW_PRINTER;
}
if (defined('REQUEST_GOOGLE_TRANSLATE_SHOW') && defined('GOOGLE_TRANSLATE_SHOW_PRINTER')) {
$params[REQUEST_GOOGLE_TRANSLATE_SHOW] = GOOGLE_TRANSLATE_SHOW_PRINTER;
}
if (defined('REQUEST_MENU_FISHEYE_SHOW') && defined('MENU_FISHEYE_SHOW_PRINTER')) {
$params[REQUEST_MENU_FISHEYE_SHOW] = MENU_FISHEYE_SHOW_PRINTER;
}
return $params;
}
/**
* Get the link attribute or use the default
* <code>
* Usage:
* $attribute = '';
* $text = $this->getLinkName($attribute,LINK_PRINT,LINK_NAME_TEXT);
* </code>
* @param String $attribute The attribute to use, if supplied
* @param String $linkId The link ID to use
* @param String $linkname The link name to use
* @return String The value of the link attribute
*/
function getLinkName($attribute, $linkId, $name) {
$value = $attribute;
// 2008-05-19 removed
// if ($value == '') {
$linkname = $GLOBALS[$name];
if (is_array($linkname)) {
if (array_key_exists($linkId,$linkname)) {
$value = $GLOBALS[$name][$linkId];
} else {
// TODO what
}
} else {
// TODO what
}
// } else {
// TODO what
// }
return $value;
}
/**
* Get the link attribute for the href or use the link ID
* @param String $href The href to use, if supplied
* @param String $linkId The link ID to use
* @return String The value of the link href attribute
*/
function getHref($href, $linkId) {
return $this->getLinkName($href,$linkId,LINK_NAME_HREF);
}
/**
* Get the link attribute for the text or use the link ID
* @param String $text The text to use, if supplied
* @param String $linkId The link ID to use
* @return String The value of the link text attribute
*/
function getText($text, $linkId) {
return $this->getLinkName($text,$linkId,LINK_NAME_TEXT);
}
/**
* Get the link attribute for the class or use the link ID
* @param String $class The class to use, if supplied
* @param String $linkId The link ID to use
* @return String The value of the link class attribute
*/
function getClass($class, $linkId) {
return $this->getLinkName($class,$linkId,LINK_NAME_CLASS);
}
/**
* Get the link attribute for the title or use the link ID
* @param String $title The title to use, if supplied
* @param String $linkId The link ID to use
* @return String The value of the link title attribute
*/
function getTitle($title, $linkId) {
return $this->getLinkName($title,$linkId,LINK_NAME_TITLE);
}
/**
* Get the new language from the Link name
* @param String $name The name of the link
* @return String $language The next language to use
*/
function getLanguage($name) {
$language = LANGUAGE;
switch ($name) {
case LINK_DENMARK:
$language = LANGUAGE_DA;
break;
case LINK_GERMANY:
$language = LANGUAGE_DE;
break;
case LINK_ENGLAND:
$language = LANGUAGE_EN;
break;
case LINK_FRANCE:
$language = LANGUAGE_FR;
break;
case LINK_ITALY:
$language = LANGUAGE_IT;
break;
case LINK_NORWAY:
$language = LANGUAGE_NO;
break;
case LINK_SWEDEN:
$language = LANGUAGE_SE;
break;
case LINK_USA:
$language = LANGUAGE_US;
break;
default:
break;
}
return $language;
}
/**
* Change to the next language
* @param String $href The href of the link
* @param String $name The name of the link
* @return String The href to use
*/
function nextLanguage($href,$name) {
$param = array();
$language = $this->getLanguage($name);
if (defined('REQUEST_LANGUAGE')) {
$param[REQUEST_LANGUAGE] = $language;
}
if (defined('REQUEST_TAB')) {
$tab = "";
if (defined('HTML_UTIL_COMPONENT_PATH') ) {
$tab = Request::get(REQUEST_TAB);
}
if ($tab != '') {
$param[REQUEST_TAB] = $tab;
}
}
$params = "";
if (defined('HTML_UTIL_COMPONENT_PATH')) {
$params = Params::get($param);
}
// Substitute the original language with the new language in question
if (LANGUAGE!='' && LANGUAGE!==$language && array_key_exists($language,$GLOBALS[DEFINE_LANGUAGE])) {
$params = str_replace(REQUEST_LANGUAGE.'='.LANGUAGE,REQUEST_LANGUAGE.'='.$GLOBALS[DEFINE_LANGUAGE][$language],$params);
}
return $href.$params;
}
/**
* Get a new Links object from the specified Link name
* <code>
* Usage:
* $link = Links::newLink($name,$text,$class,$title,$aux,$target);
* </code>
* @static
* @param String $name The name of a link i.e. 'logo'
* @param String $text The text 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
* @return Links Return a new instance of the Links object
*/
function newLink($name='',$text='',$class='',$title='',$aux='',$target='') {
return new Links($name,$text,$class,$title,$aux,$target);
}
/**
* Display a predefined link, when the LINK_name is supplied
* <code>
* Usage:
* Links::display($name,$text,$class,$title,$aux,$target);
* </code>
* @static
* @param String $name The name of an image i.e. 'logo'
* @param String $text The text 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
*/
function display($name='',$text='',$class='',$title='',$aux='',$target='') {
$html = new Links($name,$text,$class,$title,$aux,$target);
$html->addHtml();
}
}
?>