Source for file HTMLImage.class.php
Documentation is available at HTMLImage.class.php
* For including this file you have to define the constant "CLASSPATH".
* Because every include in the framework depends on the CLASSPATH definition.
* The CLASSPATH means the relative path to the folder that contains the
echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
* Including the basic class of all HTML-tags.
require_once( CLASSPATH. "html/ABSTSourceObject.class.php" );
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (c) 2004 Daniel Plücken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* The alt-attribute of the image-tag.
* The title-attribute of the image-tag.
* The path of the source to the image on mouseover.
* @var boolean $over_src_set
* Stores the value of the border-attribute of this image.
* Stores whether the image should be a gallery image.
* @var boolean $gallery_img
* Note: you can set the value of $validate_path for last parameter; you
* don't need to give values of $width, $height or $border if they have
* @author Daniel Plücken <daniel@debakel.net>
* @param string $src Source of the image.
* @param boolean $validate_path
$src, $width = 0, $height = 0,
$border = 0, $validate_path = true
// Get the value of $validate_path. Do not check the first parameter!
$this->setSRC( $src, $validate_path );
* Sets the source of this image.
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $validate_path
function setSRC( $string, $validate_path = true )
|| preg_match( "!\.(?:gif|jpg|jpeg|png)$!i", $string )
parent::setSRC( $string, $validate_path );
echo "<b>The value \"". $string. "\" is not valid for the source of an "
. "The value has to be a path to an image!</b><br>\r\n";
* Sets the source of this image on mouseover.
* @author Daniel Plücken <daniel@debakel.net>
echo "<b>The over state of this image is already set.</b><br>\r\n";
"!^(?:[-._A-Za-z0-9]+/)*"
. "(?:gif|jpg|jpeg|png)$!", $string
$this->mouseover = "swapImage( this, '". $string. "' )"
$this->mouseout = "swapImage( this, '". $this->src. "' )"
echo "<b>The value \"". $string. "\" is not valid for the source of an "
. "The value has to be a path to an image!</b><br>\r\n";
* Sets the border of this image.
* @author Daniel Plücken <daniel@debakel.net>
"The value \"". $int. "\" is not valid for the border of an "
. "The value has to be a number!"
* Sets the alt-attribute of this image.
* @author Daniel Plücken <daniel@debakel.net>
function setAlt( $string = "" )
* Sets the title-attribute of this image.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $invoke_from_alt
function setTitle( $string = "", $invoke_from_alt = false )
* Returns a javascript-function to swap a given image to given source.
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $withJSdeclaration
function getJS2swapImages( $withJSdeclaration = false )
if( !$withJSdeclaration )
$out = JavaScript::getInArray();
# Put this function in the onMouseup-attribute of the img-tag!
# Use this function never before using the function swapImage,
# this will cause no changing-effect.
$js1 = " stateIMG = undefined;\r\n"
. " imgObj = new Array();\r\n"
. " function swapImage( which, path )\r\n"
. " if( !in_array( which, imgObj ) )\r\n"
. " imgObj[imgObj.length] = new Array();\r\n"
. " imgObj[imgObj.length - 1][0] = which;\r\n"
. " imgObj[imgObj.length - 1][1] = which.src;\r\n"
. " if( !stateIMG || which != stateIMG )\r\n"
. " which.src = path;\r\n"
$js2 = " function stateImage( which )\r\n"
. " for( i = 0; i < imgObj.length; i++ )\r\n"
. " if( imgObj[i][0] == stateIMG )\r\n"
. " imgObj[i][0].src = imgObj[i][1];\r\n"
. " stateIMG = which;\r\n"
# Put this function in the onMouseout-attribute of the img-tag!
$js3 = " function restoreImage( which )\r\n"
. " for( i = 0; i < imgObj.length; i++ )\r\n"
. " if( which != stateIMG "
. "&& imgObj[i][0] == which )\r\n"
. " imgObj[i][0].src = imgObj[i][1];\r\n"
if( !$withJSdeclaration )
* Returns a generated string based on the attributes of this HTML-Object.
* @author Daniel Plücken <daniel@debakel.net>
static $overJSoutput = false;
&& preg_match ( "!swapImage\(!", $this->mouseover )
if ( class_exists( "HTMLDocument" ) )
$GLOBALS["javascript_content"][] = HTMLImage::getJS2swapImages();
$out .= HTMLImage::getJS2swapImages( true );
$out .= "<img alt=\"". $this->alt. "\" "
. ( !empty( $this->title )
? "title=\"". $this->title. "\" "
? "src=\"". $this->src. "\" "
? "width=\"". $this->width. "\" "
? "height=\"". $this->height. "\" "
? "name=\"". $this->name. "\" "
? "id=\"". $this->id. "\" "
. ( !empty( $this->click )
? "onClick=\"". $this->click. "\" "
? "onMouseup=\"". $this->mouseup. "\" "
? "border=\"". $this->border. "\" "
} // End of class HTMLImages
|