blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Img   Login nu   Login
blank.gif
 ««« Se kilde koden
blank.gif
triangle.gif Basic Base  Component Db Dto Form Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table Template Util
blank.gif
blank.gif
 
arrow-headline.gif Index
 
  Tilbage

Navn : Img.php


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();
    ?>

Parent html

Sådan vises komponenten Img klassen

Sample demo

PHP source code

Den fulde PHP kildekode for Img klassen

<?
/**
* @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.10
* @since 22-feb-2007
*/

/**
* The required files
*/
require_once(HTML_BASE_COMMON_PATH.'/Html.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
     */
    
var $src = '';
    
    
/**
     * @var String $width The width of the image
     */
    
var $width = '';
    
    
/**
     * @var String $height The height of the image
     */
    
var $height = '';
    
    
/**
     * @var String $alt The alt text for the image
     */
    
var $alt = '';
    
    
/**
     * @var String $class The css class name for the image
     */
    
var $class = '';
    
    
/**
     * @var String $border The border for the image
     */
    
var $border = '';
    
    
/**
     * @var String $aux The aux attributes for the complete image
     */
    
var $aux = '';

    
/**
     * @var String $name The name for the image
     */
    
var $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 Img($src='',$width='',$height='',$alt='',$class='',$border='',$aux='') {
        
$this->Html();
        
$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 {
/** 2008-03-29 removed
            $path = PROJECT_DOCUMENT_ROOT.$this->src;
            if (file_exists($path)) {
                $size = GetImageSize($path);
                if ($this->width=='' && is_array($size)) {
                    $this->width = $size[0]; // Width
                }
                if ($this->height=='' && is_array($size)) {
                    $this->height = $size[1]; // Height
                }
            } else {
                $msg = $this->getClassName().'(), Unable to find image, src='.$path."<br />\r\n";
                if (defined('HTML_LOG_UTIL_PATH')) {
                    //Log::info(__FILE__,__LINE__,$msg);
                } else {
                }
                Message::add($msg, __FILE__, __LINE__);
            }
Message::add("DEBUG $this->src w=$this->width h=$this->height", __FILE__, __LINE__);
**/
        
}
    }
    
    
/**
     * Get the complete html for an image
     * @return String the html
     */
    
function getHtml() {
        
$html  = $this->html;
        
$this->calculateWidthHeight();
        if (
$this->src!='') {
            if (
$this->alt=='') {
                
$this->alt = basename($this->src); // xhtml 1.0 strict compliant
            
}
            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 {
                    die(
$this->getClassName()." Illegal aux=".$this->aux);
                }
            } 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)
     */
    
function display($src='',$width='',$height='',$alt='',$class='',$border='',$aux='') {
        
$html = new Img($src,$width,$height,$alt,$class,$border,$aux);
        
$html->addHtml();
    }
}
?>

HTML source code

Den fulde HTML kildekode for Img klassen

<?
<img src="/aniBee.gif" width="20" height="20" alt="Sample demo" />
?>

Class methods

Her er 'klasse metoderne' for Img klassen:

  • object
  • getclassname
  • getmsg
  • addhtml
  • gethtml
  • tostring
  • getcachefilename
  • save
  • content
  • html
  • setobject
  • set
  • get
  • getattribute
  • gettag
  • add
  • getsizeof
  • getelement
  • getelements
  • gettoogle
  • getmaximize
  • getminimize
  • newtriangle
  • display
  • showsource
  • img
  • calculatewidthheight

Object vars

Her er 'objekt variable' for Img klassen:

  • html =>
  • sql =>
  • elements => Array
  • sizeof => 0
  • src => /aniBee.gif
  • width => 20
  • height => 20
  • alt => Sample demo
  • class =>
  • border =>
  • aux =>
  • name =>

 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif