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

Img.php


Vis: Sample code, tutorial

Img, Sample code, tutorial

Sådan benyttes komponenten Img klassen

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

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

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

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

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

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

Skjul: Sådan vises komponenten

Img, Sådan vises komponenten

Sådan vises komponenten Img klassen

Sample demo

Vis: PHP source code

Img, PHP source code

Den fulde PHP kildekode for Img klassen

<?php
/**
 * @package base
 * @see HTML_BASE_UTIL_PATH.'/Img.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_COMMON_PATH.'/Html.php');
if (
defined('HTML_BASIC_UTIL_PATH')) {
    require_once(
HTML_BASIC_UTIL_PATH.'/Message.php');
}
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
 * Returns a complete Image as HTML
 * Note: If you specify "\r\n" in the alt tag, then a break is automatically added
 * <code>
 *      <img name="$name" src="$src" width="$width" height="$height" 
 *      alt="$alt" class="$class" border="$border" />
 * Usage:
 *   $img = new Img($src, $width, $height, $alt, $class, $border, $aux);
 *   print $img->getHtml();
 * Or
 *   Img::display($src, $width, $height, $alt, $class, $border, $aux);
 * </code>
 * @package base
 */

class Img extends Html {
    
/**
     * @var String $src The path to the image 
     */
    
protected $src '';
    
    
/**
     * @var String $width The width of the image 
     */
    
protected $width '';
    
    
/**
     * @var String $height The height of the image
     */
    
protected $height '';
    
    
/**
     * @var String $alt The alt text for the image
     */
    
protected $alt '';
    
    
/**
     * @var String $class The css class name for the image
     */
    
protected $class '';
    
    
/**
     * @var String $border The border for the image
     */
    
protected $border '';
    
    
/**
     * @var String $aux The aux attributes for the complete image
     */
    
protected $aux '';

    
/**
     * @var String $name The name for the image
     */
    
protected $name '';

    
/**
     * Constructor
     * @param String $src    The source path for the image i.e. /logo.gif
     * @param String $width  The width or null or ''
     * @param String $height The height or null or ''
     * @param String $alt    The alt text
     * @param String $class  The css class for the image
     * @param String $border The border of an image
     * @param String $aux    The new line indicator (LINK_LAYOUT_BR)
     */
    
function __construct($src=''$width=''$height=''$alt=''$class=''$border=''$aux='') {
        
parent::__construct();
        
$this->src     $src;
        
$this->width   $width;
        
$this->height  $height;
        
$this->class   $class;
        
$this->border  $border;
        
$this->aux     $aux;
        
$this->alt     $alt;
    }

    
/**
     * Calculate the width and height, if not specified
     * Skip the calculation if the src contains
     * 'http://' OR does not have a '/' in the src
     * OR the height or width have already been defined 
     */
    
function calculateWidthHeight() {
        
$strHttp 'http:/'.'/';
        if (
strpos($this->src,'/')===false || 
            
strpos($this->src$strHttp)!==false || 
            
strpos($this->src,'?')!==false || // Used in Thumb.php
            
$this->width!=='' || $this->height!=='') {
            
// Skip
        
} else {
            
// Ignore
        
}
    }
    
    
/**
     * Get the complete html for an image
     * @return String the html
     */
    
function getHtml() {
        
$html  $this->html;
        
$this->calculateWidthHeight();
        if (
$this->src != '') {
            if (
$this->alt=='') {
                
// xhtml 1.0 strict compliant
                
if (!empty($GLOBALS['pageKeyword'])) {
//                    $this->alt = $GLOBALS['pageKeyword'];
                    
$this->alt basename($this->src);
                } else {
                    
$this->alt basename($this->src);
                }
            }
            if (
strpos($this->alt,"\r\n")!==false) {
                
// Does only work in IE, not FireFox
                
$this->alt str_replace("\r\n",'&#013;'$this->alt); // <br>
            
}
            
$html .= '<img';
            
$html .= $this->getAttribute('name');
            
$html .= $this->getAttribute('src');
            
$html .= $this->getAttribute('width');
            
$html .= $this->getAttribute('height');
            
$html .= $this->getAttribute('alt');
            
$html .= $this->getAttribute('class');
            
$html .= $this->getAttribute('border');
            
$html .= " />"
            if (
$this->aux != '') {
                if (
$this->aux & (LINK_LAYOUT_LI LINK_LAYOUT_BR)) {
                    
// Ok
                
} else {
                    
$msg $this->getClassName().'(), Illegal aux, expected [ LINK_LAYOUT_LI | LINK_LAYOUT_BR ], found='.$this->aux;
                    if (
defined('HTML_LOG_UTIL_PATH')) {
                        
Log::error($msg__FILE____LINE__);
                    }
                    if (
defined('HTML_BASIC_UTIL_PATH')) {
                        
Message::add($msg__FILE____LINE__);
                    }
                }
            } else {
                
// Ok
            
}
            
$html .= $this->aux LINK_LAYOUT_BR "<br />\r\n" '';
        } else {
            
$html .= "<!-- ".$this->getClassName()."->getHtml() src is empty -->\r\n";
        }
        return 
$html;
    }

    
/**
     * Display html
     * <code>
     * Usage:
     *    Img::display($src, $width, $height, $alt, $class, $border, $aux);
     * </code>
     * @static
     * @param String $src    The source path for the image
     * @param String $width  The width or null or ''
     * @param String $height The height or null or ''
     * @param String $alt    The alt text
     * @param String $class  The css class for the image
     * @param String $border The border of an image
     * @param String $aux    The new line indicator (nl)
     */
    
public static function display($src=''$width=''$height=''$alt=''$class=''$border=''$aux='') {
        
$html = new Img($src$width$height$alt$class$border$aux);
        
$html->addHtml();
    }
}
?>

Vis: HTML source code

Img, HTML source code

Den fulde HTML kildekode for Img klassen

<?
<!-- DEBUGImg -->
<
img src="http://finnrasmussen.dk/images/aniBee.gif" width="20" height="20" alt="Sample demo" />
?>

Vis: Class methods

Img, Class methods

Her er 'klasse metoderne' for Img klassen:

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

Img, Object vars

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