Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Links   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tls.gif     Base  trs.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tl.gif Form tr.gif tl.gif Language tr.gif tl.gif Layout tr.gif tl.gif Menu tr.gif tl.gif Mvc tr.gif tl.gif Netbank.eksperter.dk tr.gif tl.gif Tab tr.gif tl.gif Table tr.gif tl.gif Util tr.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Links.php


Vis: Sample code, tutorial

Links, Sample code, tutorial

Sådan benyttes komponenten Links klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Links.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Links
    ::display($param1$param2$param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object 
    = new Links($param1$param2$param3, ...);
    print 
    $object->getHtml();
    ?>

Skjul: Sådan vises komponenten

Links, Sådan vises komponenten

Sådan vises komponenten Links klassen

Copyright @ 1999-2010 www.Finn-Rasmussen.com

Vis: PHP source code

Links, PHP source code

Den fulde PHP kildekode for Links klassen

<?php
/**
 * @package base
 * @see HTML_BASE_UTIL_PATH.'/Links.php'
 * @copyright (c) http://Finn-Rasmussen.com
 * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
 * @author http://Finn-Rasmussen.com
 * @version 1.11
 * @since 27-nov-2009
 */

/**
 * The required files
 */
require_once(HTML_BASE_UTIL_PATH.'/Link.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:
 *   $linkId = 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
 *   $text  = "text for link";
 *   $href  = ""; // Use build in href
 *   $class = CSS_LINK_COLOR;
 *   $title = "The title (tooltip) text";
 *   $aux   = LINK_LAYOUT_LI; // OR LINK_LAYOUT_BR or "" (empty)
 * 
 *   $html = new Links($linkId, $text, $href, $class, $title, $aux, $target, $name, $tabindex, $onclick, $accesskey);
 *   print $html->getHtml();
 * Or
 *   Links::display($linkId, $text, $href, $class, $title, $aux, $target, $name, $tabindex, $onclick, $accesskey);
 * </code>
 * @package base
 */

class Links extends Link {
    
/**
    * Constructor
    * @param String $linkId    The link Id of an image i.e. LINK_PRINT
    * @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
    * @param String $tabindex  The name of the tab index
    * @param String $onclick   The javascript onclick function name
    * @param String $accesskey The access key
    */
    
function __construct($linkId=''$text=''$href=''$class=''$title=''$aux=''$target=''$name=''$tabindex=''$onclick=''$accesskey='') {
 
//       $href = ''; // TODO overrule ?
        
$theHref  $this->getUrl($href$linkId); // Update href
        
$theText  $this->getText($text$linkId);
        
$theClass $this->getClass($class$linkId);
        
$theTitle $this->getTitle($title$linkId);
        
parent::__construct($theText$theHref$theClass$theTitle$aux$target$name$tabindex$onclick$accesskey);
    }

    
/**
     * Get the complete url for a Link icluding the request parameters
     * @param String $linkId The link Id 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$linkId) {
        
$url $this->getHref($href$linkId);
        
$urlencode true;
        
$object = new Params(); 
        
$params "";
        switch (
$linkId) {
            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$linkId);
                break;
            case 
LINK_START:
                if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                    
$params $object->get(array(@REQUEST_CMS_USERNAME=>''), $urlencode__FILE____LINE__);
                }
                
$url .= $params;
                break;
            case 
LINK_FIND:
                if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                    
$params $object->get(array(), $urlencode__FILE____LINE__);
                }
                
$url = @LINK_HREF_SEARCH.$params;
                break;
            case 
LINK_UPDATE:
                if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                    
$params $object->get(array(), $urlencode__FILE____LINE__);
                }
                
$url .= $params;
                break;
            case 
LINK_CMS_HEAD:
                if (
defined('VIEW_CMS_HEAD_LANGUAGE')) {
                    if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                        
$params $object->get(array(REQUEST_COMMAND=>VIEW_CMS_HEAD_LANGUAGE), $urlencode__FILE____LINE__);
                    }
                    
$url .= $params;
                }
                break;
            case 
LINK_CMS_NEWS:
                if (
defined('VIEW_CMS_NEWS_LANGUAGE')) {
                    if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                        
$params $object->get(array(REQUEST_COMMAND=>VIEW_CMS_NEWS_LANGUAGE), $urlencode__FILE____LINE__);
                    }
                    
$url .= $params;
                }
                break;
            case 
LINK_CMS_CONTENT:
                if (
defined('VIEW_CMS_CONTENT_LANGUAGE')) {
                    if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                        
$params $object->get(array(REQUEST_COMMAND=>VIEW_CMS_CONTENT_LANGUAGE), $urlencode__FILE____LINE__);
                    }
                    
$url .= $params;
                }
                break;
            case 
LINK_CMS_TOP:
                if (
defined('VIEW_CMS_TOP_LANGUAGE')) {
                    if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                        
$params $object->get(array(REQUEST_COMMAND=>VIEW_CMS_TOP_LANGUAGE), $urlencode__FILE____LINE__);
                    }
                    
$url .= $params;
                }
                break;
            case 
LINK_CMS_LEFT:
                if (
defined('VIEW_CMS_LEFT_LANGUAGE')) {
                    if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                        
$params $object->get(array(REQUEST_COMMAND=>VIEW_CMS_LEFT_LANGUAGE), $urlencode__FILE____LINE__);
                    }
                    
$url .= $params;
                }
                break;
            case 
LINK_CMS_RIGHT:
                if (
defined('VIEW_CMS_RIGHT_LANGUAGE')) {
                    if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                        
$params $object->get(array(REQUEST_COMMAND=>VIEW_CMS_RIGHT_LANGUAGE), $urlencode__FILE____LINE__);
                    }
                    
$url .= $params;
                }
                break;
            case 
LINK_CMS_BOTTOM:
                if (
defined('VIEW_CMS_BOTTOM_LANGUAGE')) {
                    if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                        
$params $object->get(array(REQUEST_COMMAND=>VIEW_CMS_BOTTOM_LANGUAGE), $urlencode__FILE____LINE__);
                    }
                    
$url .= $params;
                }
                break;
            case 
LINK_MAIL:
                if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                    
$params $object->get(array(), $urlencode__FILE____LINE__);
                }
                
$url .= LINK_HREF_EMAIL.$params;
                break;
            case 
LINK_LOGIN:
                if (
defined('VIEW_LOGIN_FORM')) {
                    if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                        
$params $object->get(array(REQUEST_COMMAND=>VIEW_LOGIN_FORM), $urlencode__FILE____LINE__);
                    }
                    
$url .= LINK_HREF_LOGIN.$params;
                }
                break;
            case 
LINK_LOGOFF:
                if (
defined('VIEW_LOGOFF_FORM')) {
                    if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                        
$param = array();
                        
$param[REQUEST_COMMAND] = VIEW_LOGOFF_FORM;
                        
$test  Request::get(REQUEST_BASE_PACKAGE_TEST);
                        if (
$test !== "") {
                            
$param[REQUEST_BASE_PACKAGE_TEST] = $test;
                        }
                        
$params $object->get($param$urlencode__FILE____LINE__);
                    }
                    
$url .= $params// LINK_HREF_LOGIN.
                
}
                break;
            case 
LINK_RETURN:
                if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                    
$params $object->get(array(), $urlencode__FILE____LINE__);
                }
                
$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 .= $object->get($params$urlencode__FILE____LINE__);
                }
                break;
            default:
                if (
defined('HTML_UTIL_COMPONENT_PATH')) {
                    
$params $object->get(array(), $urlencode__FILE____LINE__);
                }
                
$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')) {
            
$command Request::get(REQUEST_COMMAND);
            if (
$command !== "") {
                
$params[REQUEST_COMMAND] = $command;
            }
        }
        if (
defined('REQUEST_ID')) {
            
$id Request::get(REQUEST_ID);
            if (
$id !== "") {
                
$params[REQUEST_ID] = $id;
            }
        }
        if (
defined('REQUEST_PRINTER') && defined('VIEW_PRINTER')) {
            
$params[REQUEST_PRINTER] = 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
     * The user may overrule the default settings buy adding an $attribute value
     * <code>
     * Usage:
     *    $attribute = '';
     *    $linkId    = LINK_PRINT;
     *    $linkname  = LINK_NAME_TEXT;
     *    $text = $this->getLinkName($attribute, $linkId, $linkname);
     *    
     * Or overule, like here
     *    $attribute = 'http://finn-rasmussen.com';
     *    $linkId    = LINK_PRINT;
     *    $linkname  = LINK_NAME_HREF;
     *    $href  = $this->getLinkName($attribute, $linkId, $linkname);
     *    
     * </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$linkname) {
        
$value $attribute;
        if (
$value === "") {
            
$linkNames "NAME NOT IN GLOBALS";
            if (
array_key_exists($linkname$GLOBALS)) {
                
$linkNames $GLOBALS[$linkname];
            } else {
                
// TODO what
            
}
            if (
is_array($linkNames)) {
                if (
array_key_exists($linkId$linkNames)) {
                    
$value $GLOBALS[$linkname][$linkId];
                } 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$linkIdLINK_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$linkIdLINK_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$linkIdLINK_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$linkIdLINK_NAME_TITLE);
    }

    
/**
     * Get the new language from the Link name
     * @param  String $linkId   The link Id of the link
     * @return String $language The next language to use
     */
    
function getLanguage($linkId) {
        
$language LANGUAGE;
        switch (
$linkId) {
            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 $linkId The link Id of the link
     * @return String The href to use
     */
    
function nextLanguage($href$linkId) {
        
$param = array();
          
$language $this->getLanguage($linkId);
        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')) {
            
$urlencode true;
            
$params Params::get($param$urlencode__FILE____LINE__);
//            foreach($param as $key=>$value) {
//                print "XX : $key=>$value<br />";
//            }
        
}
        
// 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($linkId, $text, $href, $class, $title, $aux, $target, $name, $tabindex, $onclick, $accesskey);
     * </code>
     * @static
     * @param  String $linkId    The link Id of a link i.e. LINK_LOGO
     * @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
     * @param  String $tabindex  The name of the tab index
     * @param  String $onclick   The javascript onclick function name
     * @param  String $accesskey The access key
     * @return Links Return a new instance of the Links object 
     */
     
public static function newLink($linkId=''$text=''$href=''$class=''$title=''$aux=''$target=''$name=''$tabindex=''$onclick=''$accesskey='') {
        return new 
Links($linkId$text$href$class$title$aux$target$name$tabindex$onclick$accesskey);         
     }

    
/**
     * Display a predefined link, when the LINK_name is supplied
     * <code>
     * Usage:
     *    Links::display($linkId, $text, $href, $class, $title, $aux, $target, $name, $tabindex, $onclick, $accesskey);
     * </code>
     * @static
     * @param String $linkId    The link Id of an image i.e. 'logo'
     * @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
     * @param String $tabindex  The name of the tab index
     * @param String $onclick   The javascript onclick function name
     * @param String $accesskey The access key
     */
    
public static function display($linkId=''$text=''$href=''$class=''$title=''$aux=''$target=''$name=''$tabindex=''$onclick=''$accesskey='') {
        
$html = new Links($linkId$text$href$class$title$aux$target$name$tabindex$onclick$accesskey);
        
$html->addHtml();
    }
}
?>

Vis: HTML source code

Links, HTML source code

Den fulde HTML kildekode for Links klassen

<?
<!-- DEBUGLinks -->
<!-- 
Copyright 1999-2010
www
.Finn-Rasmussen.com --><class="baseLinkColor" href="http://Finn-Rasmussen.com/copyright/" title="Læs om Copyright (c) fra&#013;www.Finn-Rasmussen.com">Copyright 1999-2010
www
.Finn-Rasmussen.com</a>
?>

Vis: Class methods

Links, Class methods

Her er 'klasse metoderne' for Links klassen:

  • __construct
  • getUrl
  • getPrinterParams
  • getLinkName
  • getHref
  • getText
  • getClass
  • getTitle
  • getLanguage
  • nextLanguage
  • newLink
  • display
  • getParams
  • getHtml
  • getValue
  • setId
  • setOnfocus
  • setOnblur
  • id
  • setObject
  • set
  • get
  • getAttribute
  • getTag
  • add
  • getSizeof
  • getElement
  • getElements
  • getToogle
  • getMaximize
  • getMinimize
  • newTriangle
  • getStartHtml
  • getEndHtml
  • showsource
  • getClassName
  • getMsg
  • addHtml
  • __toString
  • getCacheFileName
  • save
  • content

Vis: Object vars

Links, Object vars

Her er 'objekt variable' for Links klassen:

  • html =>
  • sql =>

MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.2.6-1+lenny8) 1.11
blank.gif