﻿
<?php
include ('securite.php');
//appeler cette page depuis un fichier au dessus dans la hiérarchie des dossiers avec une include.

echo'<div class="gallerie">';
function head_location()
{
$head_location='<div class="head_location"><a href="?act=photos"><img src="gallerie/logo/logo.png" alt="Gallerie" title="retourner à la racine de la gallerie"/></a>';
if(isset($_GET['dir']) AND $_GET['dir']!=NULL){
$head_location.= ' <div class="top"> <a href="?act=photos&dir=' . $_GET['dir'] .'">' . $_GET['dir'] .'</a></div>';
}
if(isset($_GET['img']) AND $_GET['img']!=NULL){
$head_location.=  '<div class="top"> > ' .  $_GET['img'] .'</div>';
}
$head_location.=  '</div>';
echo $head_location;
}



function liste_thumbs($dossier){ //visionner avec lien vers les grands
$imgs = scandir('gallerie/img/'.$dossier);
$compte = count($imgs) -4;
echo"<fieldset class='liste'> Dossier $dossier ($compte images)<br/>";
foreach ($imgs AS $k => $v){
if($v !='.' AND $v !='..' AND $v !='Thumbs.db' AND $v !='thumbs'){
echo"
<a href='?act=photos&dir=$dossier&img=$v'>
<img src='gallerie/img/$dossier/thumbs/$v' alt='gallerie/img/$dossier/$v'/>
</a> 
";}
}
echo"</fieldset>";
}


function random_thumb($dossier)
{
$random='<fieldset class="random">';
$liste = scandir('gallerie/img/'.$dossier);
$maximum = count($liste);
$num_image = rand(0, $maximum);

while( $num_image >$maximum OR  $liste[$num_image]=="." OR $liste[$num_image]==".." OR $liste[$num_image]=="thumbs" OR $liste[$num_image]=="Thumbs.db" OR !isset($liste[$num_image]))
{$num_image = rand(0, count($liste));}

$random.=
"<img src='gallerie/img/$dossier/
$liste[$num_image]'/>";
$random.='</fieldset>';

echo $random;


}





function liste_edit($dossier){
$liste=scandir('gallerie/img/'.$dossier);
echo"<fieldset>Dossiers disponibles:<br />";
foreach ($liste AS $k => $v){
if(!preg_match("#\.#",$v)){
echo"( <a href='?act=photos&thumbs_dir=$v'>créer thumbs</a> , <a href='?act=photos&voir=$v'>voir</a> , <a href='?act=photos&watch=$v'>watch</a> ) : $v<br/>";}
}
echo"</fieldset>";
}

function liste_normale($dossier){
$liste=scandir('gallerie/img/'.$dossier);
echo"<fieldset>Dossiers disponibles:<br />";
foreach ($liste AS $k => $v){
if(!preg_match("#\.#",$v)){
echo"<a href='?act=photos&dir=$v'>- $v</a> <br/>";}
}

echo"</fieldset>";
random_thumb("afrikaans-worstelen");
}






function thumb_maker($dossier){
$liste=scandir('gallerie/img/'.$dossier);
print_r($liste);
echo"<fieldset>Redimensionnage des images du dossier $dossier:<br />";
foreach ($liste AS $k => $v){
if(!preg_match("#\.$#",$v)){
echo'
<img src="redi.php?act=photos&url=img/'.$dossier.'/'.$v.'&dossier='.$dossier.'" alt="redi.php?act=photos&url=img/'.$dossier.'/'.$v.'" /><br/>';
}
}

echo"dossier des thumbs";
liste_thumbs($dossier);
echo"</fieldset>";

}








function grande_image($dir,$img){
$image_suivante = $image_precedente = '';
$grande_image ='<div class="grande_image">';
//trouver la clé qui a pour valeur $_GET['grand']
$a_dir = scandir('gallerie/img/'.$dir);

$num_img_courante = array_search($img, $a_dir);
$nb_img = count($a_dir) -4;
$courante_affichee = $num_img_courante+1; //pour ne pas afficher 0 à la première image
$grande_image .=" image n° $courante_affichee / $nb_img <br/>";

//précédent
$precedente = $num_img_courante-1;
if (!isset($a_dir[$precedente])){$grande_image .=" <del>precedente</del> ";}
else {

$image_precedente = $a_dir[$precedente];
$grande_image .=" <a href='?act=photos&dir=$dir&img=$image_precedente'> precedente < </a>";
}


//$grande_image .=" <a href='?act=photos&dir=$dir&img=$image_suivante'> </a> ";
$suiv = $num_img_courante +1;
//suivant
if (isset($a_dir[$suiv])  && ( $a_dir[$suiv] != "." && $a_dir[$suiv] !=".." && $a_dir[$suiv] !="thumbs" && $a_dir[$suiv] !="thumbs.db")){
$image_suivante =$a_dir[$suiv];
$grande_image .=" <a href='?act=photos&dir=$dir&img=$image_suivante'>
<img src='gallerie/img/$dir/$img' alt='img/$dir/$img'/>
</a>
<a href='?act=photos&dir=$dir&img=$image_suivante'>
> suivante
</a>";
}
else{$grande_image .=" <a href='?act=photos&dir=$dir&img=$image_suivante'> <img src='gallerie/img/$dir/$img' alt='gallerie/img/$dir/$img'/> $dir </a>";}
echo $grande_image;

}


function video_list()
{
$video_stuff ='<div class="videos"> Vidéos Disponibles';
$avid = scandir('gallerie/v') or die('video_list scandir fail ');
$video_stuff .=' <fieldset class="liste">';

foreach ($avid AS $k => $v){
if(!preg_match("#\.$|\.db$|thumbs#",$v)){
$video_stuff .=' - <a href="?act=videos&v='.$v.'">'.$v.'</a><br/>';
}
}
$video_stuff .='</fieldset></div>';

echo$video_stuff;}


function video_look()
{
$video_stuff ='<div class="videos"> Vidéos Disponibles';
$avid = scandir('gallerie/v') or die('video_look scandir fail ');
$video_stuff .=' <fieldset class="liste_video"> <a href="?act=videos">Vidéos</a>:';

foreach ($avid AS $k => $v){
if(!preg_match("#\.$|\.db$|thumbs#",$v)){
$video_stuff .=' - <a href="?act=videos&v='.$v.'">'.$v.'</a><br/>';
}
}
$video_stuff .='</fieldset><fieldset class="video">


<object id="video1" width=340 height=272 classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/
mplayer/en/nsmp2inf.cab#Version=6,4,5,715"
standby="Chargement..."
type="application/x-oleobject">
<param name="FileName" value="gallerie/v/'.$_GET['v'].'">
<param name="AutoStart" value="true">
<embed type="application/x-mplayer2"
pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/"
src="gallerie/v/'.$_GET['v'].'"
name="video1" width=340 height=272 AutoStart=true>
</embed>
</object> 
<a href="gallerie/v/'.$_GET['v'].'">Télécharger la vidéo</a>


</fieldset>













</div>';
//  <EMBED SRC="gallerie/v/'.$_GET['v'].'" WIDTH=340 HEIGHT=272 AUTOSTART="TRUE" LOOP=0> 
echo $video_stuff;}










function watch($dossier){ //thumbs liés aux grands
$liste=scandir('gallerie/img/'.$dossier);
echo"<fieldset>Watch it:<br />";
foreach ($liste AS $k => $v){
if(!preg_match("#\.$#",$v)){
echo" <a href='?act=photos&dir=$dossier&img=$v'>
<img src='img/$dossier/thumbs/$v' alt='img/$dossier/thumbs/$v'/>
</a> ";}
}

if(isset($_GET['grand']) AND $_GET['grand']!=NULL){ echo'<br/>  <img src="mini.php?act=photos&url=img/'.$dossier.'/'.$_GET['grand'].'" alt="'.$_GET['grand'].'" title="'.$_GET['grand'].'"/>  ';}
echo"</fieldset>";
}



$fermdiv='';

if(isset($_GET['act']) AND $_GET['act']=='videos'){
	if(isset($_GET['v']) AND $_GET['v']!=''){video_look();}
	else{ video_list();}}
else{
head_location('');
if(isset($_GET['dir']) AND $_GET['dir']!=NULL){ 
if(isset($_GET['img']) AND $_GET['img']!=NULL){ grande_image($_GET['dir'] ,$_GET['img']);  $fermdiv='</div>';}
else{liste_thumbs($_GET['dir']);}
}
else {liste_normale('');}
if(isset($_GET['watch']) AND $_GET['watch']!=NULL){ watch($_GET['watch']);}
elseif(isset($_GET['thumbs_dir']) AND $_GET['thumbs_dir']!=NULL){ thumb_maker($_GET['thumbs_dir']);}
elseif(isset($_GET['voir']) AND $_GET['voir']!=NULL){ liste_thumbs($_GET['voir']);}
}


//Créer un dossier dans img/ pour pouvoir l'afficher.
echo"
$fermdiv
</div>
<div class='droits'>
Script de gallerie (c) <a href='http://artlemoine.com' title='portfolio de B.Lemoine, illustrateur et graphiste'>B.Lemoine</a> depuis 2009. Tous droits réservés.
</div>

";
?>

