Location: PHPKode > scripts > rollover2 > rollover2/class_rollover3.php
<?php
/*
 * Filename.....: class_rollover3.php
 * Aufgabe......: Rollover Effekt mit Buttons
 * Parameter....: none
 * Erstellt am..: 18. März 2003 from rollover2.php (from knito, too)
 *       _  __      _ _
 *  ||| | |/ /     (_) |        Wirtschaftsinformatiker IHK
 * \. ./| ' / _ __  _| |_ ___   www.ingoknito.de
 * - ^ -|  < | '_ \| | __/ _ \  
 * / - \| . \| | | | | || (_) | Peter Klauer
 *  ||| |_|\_\_| |_|_|\__\___/  06131-651236
 * mailto.......: hide@address.com
 *
 * The successor of rollover2 omits the preload() function and the external 
 * javascript file which is no more needed. Page code size and load time 
 * are reduced compared to rollover2.php.
 * Easy output of every button with function putall($between) where $between
 * is any html tag that will be repeated between the rollover button images.
 * Works with javascript enabled browsers IE4+, Mozilla, Opera5+.
 *
 * Changes:
 * 2005-03-04: Killed the never used "layer" parameter
 * 2005-03-02: added events array to have additional mouseover and mouseout events
 *             for example to have the infobox class working with rollover3
 */
if( !isset( $rollover3_class_loaded))
{
  $rollover3_class_loaded = 1; 

  class rollover3 
  {
    var $images = array(); // Array for all image informations
    
    /**
    * array containing entries like $events['img01']['mouseover']="tip('balloon01')"
    */
    var $events = array(); // Array for additional event handlings
    var $imagedir = './images/'; // path to image files
    var $window_defaultstatus = ''; // default status for status bar message
    
    
    /**
    * add an image to the "images" array
    *
    * @param string $imgname = Internal image name, never shown
    * @param string $baseimg = path to base image (unselected mouse not over it)
    * @param string $selimg = path to selected image (mouse hovering over it)
    * @param string $downimg = path to image in "down" position (clicked upon)
    * @param string $alt = alternate text (mousetip in ie) will appear in status bar
    * @param string $link = url where to go to when clicked upon
    * @param string $target = target window for $link
    * @param string $map = client image map name <map name="my_name"><area ... /area></map>
    * @return void 
    **/
    function addimage( $imgname, $baseimg, $selimg, $downimg='', $alt='', $link='#', $target='', $map='' )
    {
    	
      $this->images[$imgname] = 
      array( 
             'baseimg' => $baseimg, // unselected image file
             'selimg' => $selimg,   // selected image file
             'downimg' => $downimg, // if $PHP_SELF is the link, show this image
             'alt' => $alt,         // mouseover hint text
             'link' => $link,       // url to document
             'target' => $target,   // target window for new document
             'map' => $map );       // client image map name <map name="my_name"><area ... /area></map>
             
    }
    
    
    /**
    * Not needed anymore, just here in case you upgrade from rollover2
    *
    * @return void 
    **/
    function preload()
    {
    	
     // Not needed anymore to preload images or include a javascript file
     // Empty function for compatibility purposes with rollover2.
     
    }      
    
    
    /**
    * determines if $url is the url of the active page.
    *
    * @param string $url = url to compare to active page url $REQUEST_URI
    * @return boolean true when yes
    **/
    function i_am_this_url( $url )
    {
    	
      global $REQUEST_URI;

      $shortest = strlen( $url );
      $shortest = strlen( $REQUEST_URI ) < $shortest ? strlen( $REQUEST_URI ) : $shortest;
      return( substr($url, -$shortest) == substr( $REQUEST_URI, -$shortest ) );
    }

    
    /**
    * Output an img tag with attributes to the page.
    * Can handle additional mousover and mouseout effects like for infobox.
    * Displays downimage when url for it corresponds with the actual page url.
    *
    * @param string $imgname = internal image name used for handling the images
    * @return void 
    **/
    function image( $imgname )
    {
    	$over = $this->more_events($imgname, 'mouseover');
			$out =  $this->more_events($imgname, 'mouseout');    	
    	
      $size = GetImageSize($this->imagedir . $this->images[$imgname]['baseimg'] ); 
      
      $t = $this->images[$imgname]['target'] == '' ? ' ' : ' target="'.$this->images[$imgname]['target'].'" ';
      $map = $this->images[$imgname]['map'] == '' ? '' : ' ISMAP USEMAP="#'.$this->images[$imgname]['map'].'" ';
  
      if( ($this->images[$imgname]['downimg'] > '') && 
          ($this->i_am_this_url( $this->images[$imgname]['link'] ) ) )
      {
        # show state 3: downimage ($this->link == reached)
        $mover = strlen( $over ) > 1 ? " onMouseOver=\"$over\"":'';
        $mout = strlen( $out ) > 1 ? " onMouseOut=\"$out\"":'';
        	        
        echo "<img$mover$mout name='". 
        $imgname . "' border=0 width=" . $size[0] . 
        " height=" . $size[1] .$map. " src='" . $this->imagedir .  
        $this->images[$imgname]['downimg'] . 
        "' alt='" . $this->images[$imgname]['alt'] . 
        "'>" ;
      }
      else
      {
        # show normal rollover image 
        echo '<a href="' . $this->images[$imgname]['link'].'"'.$t. ' '.$map.' '. 
        "onMouseOver=\"$over;window.status='".
        $this->images[$imgname]['alt']."';return true;\" ".
        "onMouseOut=\"$out;window.status='".
        $this->window_defaultstatus."';return true;\">".
        
        "<img name='" . 
        $imgname . "' border=0 width=" . $size[0] . 
        " height=" . $size[1] . $map. " src='" . $this->imagedir .  
        $this->images[$imgname]['baseimg'] .
        "' onmouseover=\"$over;this.src='".$this->imagedir.$this->images[$imgname]['selimg'] .
        "'\" onmouseout=\"$out;this.src='".$this->imagedir.$this->images[$imgname]['baseimg'] . 
        "'\" alt='" . $this->images[$imgname]['alt'] . 
        "'></a>" ;
        
      } // normal rollover image
    } // end function image()
    
    
    /**
    * simplify your life: Output all images in one action
    *
    * @param string $between = gap between images
    * @return void 
    **/
    function putall( $between = '' )
    {
       $first = true;
       reset( $this->images );
       while( list( $image,  ) = each( $this->images ) ) 
       {
         if( !$first ) echo $between;         
         $this->image( $image );
         $first = false;
       } // while
    } // end function putall()
    
    
    /**
    * Get them additional events if they exist.
    * At the moment, only 'mouseover' and 'mouseout' are accepted as values for $what
    *
    * @param string $imgname = internal name of the image
    * @param string $what = 'mouseover' or 'mouseout'
    * @return string containing the event demanded
    **/
    function more_events( $imgname, $what )
    {
    	
    	$result = isset( $this->events[$imgname][$what] )  ? $this->events[$imgname][$what] : '';
    	return $result;
    	
    } // eof more_events
    
  } // end class rollover3
  
} // if( !isset( $rollover3_class_loaded))
?>
Return current item: rollover2