/**
* 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=='') {
// xhtml 1.0 strict compliant
if (!empty($GLOBALS['pageKeyword'])) {
$this->alt = $GLOBALS['pageKeyword'];
} 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",'
',$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();
}
}
?>