index       article       [code]       qcm       citation       glossary public.pub.graz.network
  droit       JS       meteo       nivologie       NTIC       orientation       SUBCATEGORY        


  picture.lib.php

Slide Show. Slide over all pictures files present in a directory.

<?
// ZARG-31.08.00 09:22:16
// Pictures select object
// This code will give you the possibility to insert
// dynamic images in your document and to view them
// one by one, with the possibility to navigate
// through the directory structure below.
//
// This will take all standard img in a directory
// This will let you navigate in child directories
// This will return you random img

//Start
class picture {

// configuration parameters
var $root
var 
$no_img_url '';
var 
$refresh_epoch '5';
var 
$stop='stop';
var 
$last='last';
var 
$next='next';
var 
$start='start';

// insides air variables
var $path;
var 
$head_url;
var 
$nbr_img;
var 
$images;
var 
$img_url;
var 
$img_url_rand;
var 
$img_src_random_smallSize;
var 
$img_src_random_normSize;
var 
$img_src_normSize;
var 
$img_src_smallSize;
var 
$img_src;
var 
$href_next_open;
var 
$href_back_open;
var 
$href_normalSize_open;
var 
$href_motion_open;
var 
$nav_bar;
var 
$locator;
var 
$metatag_refresh;
var 
$size;
var 
$size_rand;
var 
$href_base;
var 
$state;
var 
$state_motion;
var 
$state_normal;
//var $images;

     
function picture ($path,$smallSize,$animate) {
         global 
$include_path$SE$PHP_SELF $picture,$normal,$motion;
        if (isset(
$_REQUEST['picture'])) $picture=$_REQUEST['picture'];
        if (isset(
$_REQUEST['normal'])) $normal=$_REQUEST['normal'];
        if (isset(
$_REQUEST['motion'])) $motion=$_REQUEST['motion'];
        
$images=array();
        
$this->path $path;
        
$this->root '.';
        
$SCRIPT_NAMEgetenv('SCRIPT_NAME');
        
$this->head_url '?picture=';
        
        
// Establish actual path for directory's images
        
if (isset($picture)){
            
$picture ereg_replace("^/(.*)""1"$picture);
            if (
is_dir($this->root.'/'.$picture)){
                
$this->path $picture;
            }
            if (
is_file($this->root.'/'.$picture)){
                
$this->path dirname($picture);
            }
        }
        
        
// Get images list, Get child directories list
        
$handle opendir($this->root.'/'.$this->path);
        
$i 0;$j 0;
        while (
$file readdir($handle)) { 
            if (
ereg(".*.(jpg|gif|jpeg)$"$file) ) {
                
$images[$i++] = $file;
            } else if (
is_dir($this->root.'/'.$this->path.'/'.$file)) {
                
$this->dir[$j++] = $file;
            } 
        }
        
closedir($handle);
        
        
// Find last viewed image
        
$this->nbr_img sizeof($images)-1;

        
$ctl '0';
        for (
$i 0$i <= $this->nbr_img$i++){
            
            
$mystring $picture;
            
$findme  $images[$i];
            
$pos strpos($mystring$findme);
            if (
$pos===false){}
            else{
                
$index $i;
                
$ctl '1';
                break;
                 } 
            
        }
        
// Establish actual index num for image reference in directory's array
        
if ($ctl == '0'){ $index '0';}
        
$index_rand rand(0,$this->nbr_img);
        
$index_next $index 1;
        
$index_back $index -1;
        if (
$index_back 0){ $index_back $this->nbr_img;}
        if (
$index_next $this->nbr_img){ $index_next '0';}
        
        
// Get the URL of the picture
        
if (isset($images[$index])){
            
$this->size GetImageSize($this->root.'/'.$this->path.'/'.$images[$index]);
            
$this->size_rand GetImageSize($this->root.'/'.$this->path.'/'.$images[$index_rand]);
            
$this->img_url $this->path.'/'.$images[$index];
            
$this->img_url_rand $this->path.'/'.$images[$index_rand];
        } 
        
        
// Create all images tags
        
$this->img_src_random_smallSize '<img src="'.$this->img_url_rand.'" height='.$smallSize.' border=0>';
        
$this->img_src_random_normSize '<img src="'.$this->img_url_rand.'" '.$this->size_rand.' border=0>';
        
$this->img_src_normSize '<img src="'.$this->img_url.'" '.$this->size.' border=0>';
        
$this->img_src_smallSize '<img src="'.$this->img_url.'" height='.$smallSize.' border=0>';
        
        
// Establish the parameters string
        
if ($normal == "on"){
            
$this->state '&normal=on';
            
$this->state_normal '&normal='.$normal;
            
$this->img_src $this->img_src_normSize;
        } else {
            
$this->state '&normal=off';
            
$this->img_src $this->img_src_smallSize;
        }
        if (
$motion == "on"){
            
$this->state .= '&motion=on';
            
$this->state_motion '&motion='.$motion;
        } else {
            
$this->state .= '&motion=off';
        } 
        
        
// Create Locator/Navigator elements
        
$this->locator '<br/>';
        for (
$i=0;$i<=sizeof($this->dir)-1;$i++){
            if (
$this->dir[$i] == '..'){
                
$string ereg_replace("(.*)/(.*)?$""1"$path);
                
$this->locator .= "<a href="$PHP_SELF".$this->head_url.$string.'">else</a> | '; 
            } else if ($this->dir[$i] == '
.'){
                //next;
            } else {
                $this->locator .= "<a href="$PHP_SELF".$this->head_url.$this->path.'
/'.$this->dir[$i].'">'.$this->dir[$i].'</a> | '; 
            }
        }
        
$this->locator .= '<br/>';
        
        // Create Ahref Links elements
        
$this->href_base = "<a href="$PHP_SELF".$this->head_url.$this->path.'/';
        
$this->href_next_open $this->href_base.$images[$index_next].$this->state.'">';
        
$this->href_back_open $this->href_base.$images[$index_back].$this->state.'">';
        
$this->href_normalSize_open $this->href_base.$images[$index].$this->state_motion.'&normal=on">';
        
$this->href_smallSize_open $this->href_base.$images[$index].$this->state_motion.'">';
        
$this->href_motionOn_open $this->href_base.$images[$index_next].$this->state_normal.'&motion=on">';
        
$this->href_motionOff_open $this->href_base.$images[$index].$this->state_normal.'">';
        
        
// Create Navigation/Tools/Services elements
        
$this->nav_bar $this->href_back_open.$this->last.'</a> | ';
        if(
$motion == 'on') { $this->nav_bar .= $this->href_motionOff_open.$this->stop.'</a> | '; }
        else { 
$this->nav_bar .= $this->href_motionOn_open.$this->start.'</a> | '; }
        
$this->nav_bar .= $this->href_next_open.$this->next.'</a>';
        
//if($normal == 'on') { $this->nav_bar .= $this->href_smallSize_open.'small</a>'; }
        //else { $this->nav_bar .= $this->href_normalSize_open.'original</a>'; }
        
        // Create Metatags/Automatic refresh elements
        
if ($motion == 'on'){
            
$this->metatag_refresh '<meta http-equiv="refresh" content="'.$this->refresh_epoch.'; url=';
            
$this->metatag_refresh .= $PHP_SELF.$this->head_url.$this->path.'/'.$images[$index_next].$this->state.'">';
        } else {
            
$this->metatag_refresh '';
        }
     }
// END
}
?>
1