Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Link   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

Link.php


Vis: Sample code, tutorial

Link, Sample code, tutorial

Sådan benyttes komponenten Link klassen

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

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

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

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

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

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

Skjul: Sådan vises komponenten

Link, Sådan vises komponenten

Sådan vises komponenten Link klassen

Finn-Rasmusssen.com

Vis: PHP source code

Link, PHP source code

Den fulde PHP kildekode for Link klassen

<?php
/**
 * @package base
 * @see HTML_BASE_UTIL_PATH.'/Link.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.'/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:
 *    $text      = "text to show";
 *    $href      = "where2go.html";
 *    $class     = "cssClassName";
 *    $title     = "title to show"
 *    $aux       = LINK_LAYOUT_LI; // Or INK_LAYOUT_BR or "" (empty)
 *    $target    = "blank"; // Opens in a new window
 *    $name      = "TheNameOfLocalHrefs#";
 *    $tabindex  = "3";
 *    $onclick   = "alert('Hello')";
 *    $accesskey = "A";
 *    
 *   $link = new Link($text, $href, $class, $title, $aux, $target, $name, $tabindex, $onclick, $accesskey);
 *   print $link->getHtml();
 * Or
 *   $link = new Link('','','','','','', $name);
 *   print $link->getHtml(); // Target name
 * Or
 *   Link::display($text, $href, $class, $title, $aux, $target, $name, $tabindex, $onclick, $accesskey);
 * Or
 *   Link::display('','','','','','', $name); // Target name
 * </code>
 *
 * @package base
 */

class Link extends Element {
    
/**
     * @var String $text The text to use for the link
     */
    
protected $text   '';

    
/**
     * @var String $href The url to jump to
     */
    
protected $href   '';

    
/**
     * @var String $aux The additional html to add
     */
    
protected $aux    '';

    
/**
     * @var String $target The open in new window
     */
    
protected $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
     * @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($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.')' '';
        
parent::__construct($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);
                
$urlencode true;
                
$file      __FILE__;
                
$line      __LINE__;
                
$params .= Params::get($paramsArray$urlencode$file$line);
            } 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, expected aux= LINK_LAYOUT_LI or LINK_LAYOUT_BR, found aux=".$this->aux);
                }
            } else {
                
// Ok
            
}
            if (
defined('DEBUG_LEVEL') && 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","&#013;"$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('onclick');
                
$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 .= '&nbsp;'// <a href="" ...><img ... />&nbsp;Text</a>
                    
}
                }
            }
            
$text  $this->text;
            
// 2008-03-13 removed
            //$text  = str_replace('-',"&#187;", $this->text); // In order to avoid line breaks
            /**
             * Only replace ' ' with &nbsp; when smal text size
             */
            
if (strlen($text) < 20 ) {
                
$html .= str_replace(' ',"&nbsp;"$text);       // In order to avoid line breaks
            
} else {
                
$html .= $text;
            }
            
$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, $tabindex, $onclick, $accesskey);
     * </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
     * @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($text=''$href=''$class=''$title=''$aux=''$target=''$name=''$tabindex=''$onclick=''$accesskey='') {
        
$html = new Link($text$href$class$title$aux$target$name$tabindex$onclick$accesskey);
        
$html->addHtml();
    }
}
?>

Vis: HTML source code

Link, HTML source code

Den fulde HTML kildekode for Link klassen

<?
<!-- DEBUGLink -->
<!-- 
Finn-Rasmusssen.com --><class="baseLinkColor" href="http://finn-rasmusssen.com" title="Finn-Rasmusssen.com">Finn-Rasmusssen.com</a>
?>

Vis: Class methods

Link, Class methods

Her er 'klasse metoderne' for Link klassen:

  • __construct
  • getParams
  • getHtml
  • display
  • 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

Link, Object vars

Her er 'objekt variable' for Link 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