--- /dev/null
+<?php
+include('fonc_images.php');
+
+define('NOM_FICHIER_INFO', 'infos.txt');
+define('SUFFIXE_VIGNETTE','micro_');
+define('SUFFIXE_PHOTO_REDUITE','mini_');
+
+#retourne les arguments à repasser à la page
+function arguments_page()
+{
+ global $vars_repasse;
+ $args = '';
+ foreach($vars_repasse as $var)
+ if(isset($_GET[$var])) $args .= $var.'='.$_GET[$var].'&';
+ return $args;
+}
+
+class Galerie
+{
+ var $repertoire_galerie;
+
+ var $section_courante = null;
+ var $taille_vignette = TAILLE_VIGNETTE;
+ var $nombre_vignette_par_page = NOMBRE_VIGNETTE_PAR_PAGE;
+ var $nombre_colonne = NOMBRE_COLONNE;
+
+ #contient un tableau ayant pour indice le nom des section
+ #et pour valeur un tableau contenants en 'infos' un tableau contenant le nom est la date de la section
+ #et en 'images' un tableau des images de la section
+ var $sections = array();
+
+ function repertoire_courant() { return $this->repertoire_galerie.'/'.$this->section_courante.'/'; }
+
+ #constructeur
+ function Galerie($rep='.')
+ {
+ $this->repertoire_galerie = $rep;
+
+ #ouvre le repertoire de la galerie
+ $rep_galerie = dir($this->repertoire_galerie);
+ #pour chaque repertoire (section)
+ while ($section = $rep_galerie->read())
+ {
+ if ($section != '..' and $section != '.')
+ {
+ if (is_null($this->section_courante)) $this->section_courante = $section;
+
+ #ouvre le repertoire des images de la section en cours
+ $rep_section = dir($this->repertoire_galerie.'/'.$section);
+
+ #essais d'inclure le fichier d'info
+ if (!@include($this->repertoire_galerie.'/'.$section.'/'.NOM_FICHIER_INFO))
+ {$auteur = 'auteur inconnu'; $date = 'date inconnue';}
+
+ #enregistre les infos
+ $this->sections[$section]['infos']['auteur'] = $auteur;
+ $this->sections[$section]['infos']['date'] = $date;
+
+ #pour chaque images
+ while ($photo = $rep_section->read())
+ {
+ if (ereg('('.SUFFIXE_VIGNETTE.'|'.SUFFIXE_PHOTO_REDUITE.').*', $photo)) continue;
+ if (ereg('.*\.[jJ][pP][gG]', $photo)) #si l'extension est .jpg alors mémorise l'image
+ $this->sections[$section]['images'][] = $photo;
+ }
+ $rep_section->close();
+ }
+ }
+ $rep_galerie->close();
+
+ foreach($this->sections as $nom_section => $null)
+ sort($this->sections[$nom_section]['images']);
+ }
+
+ #affiche la liste des pages
+ function liste_pages()
+ {
+ for($i=1; $i<=ceil(count($this->sections[$this->section_courante]['images'])/NOMBRE_VIGNETTE_PAR_PAGE); $i++)
+ echo ($i==1?'':' | ') ,($i==$_GET['__page_section']?'<b>':''),'<a href="',NOM_FICHIER,'?',arguments_page(),'__section=',$this->section_courante,'&__page_section=',$i,'&__page_galerie=section">',$i,'</a>',($i==$_GET['__page_section']?'</b>':'');
+ }
+
+ #affiche les vignettes de la section courante
+ function afficher_vignettes($page)
+ {
+ $num_image = 0;
+
+ echo '<table width="100%" cellpading="0" cellspacing="0" border="0">';
+ echo '<tr><td><div style="font-size : ',TAILLE_SECTION,'pt; font-weight : bold; ">',$this->section_courante,'</div></td>';
+ echo '<td align="right">Pages : ',$this->liste_pages(),'</td></tr>';
+ echo '<tr><td colspan="2">Auteur : ', $this->get_auteur(), ' - Date : ', $this->get_date(), '</td></tr></table>';
+
+ #pour chaque image de la section courante
+ echo '<br/><table width="100%" cellpading="0" cellspacing="0" border="0"><tr>';
+ foreach ($this->sections[$this->section_courante]['images'] as $image)
+ {
+ $num_image++;
+
+ if ($num_image <= $page*NOMBRE_VIGNETTE_PAR_PAGE-NOMBRE_VIGNETTE_PAR_PAGE or $num_image > $page*NOMBRE_VIGNETTE_PAR_PAGE)
+ continue;
+
+ $vignette = $this->repertoire_courant().SUFFIXE_VIGNETTE.$image;
+ image_redim ($this->repertoire_courant().$image, TAILLE_VIGNETTE, $vignette, 60, 1);
+
+ if (($num_image - $page*NOMBRE_VIGNETTE_PAR_PAGE-1) % NOMBRE_COLONNE == 0) echo '</tr><tr>';
+ echo '<td align="center" valign="middle">
+ <a href="',NOM_FICHIER,'?',arguments_page(),'__section=',$this->section_courante,'&__photo=',$image,'&__page_galerie=photo">
+ <img alt="', $vignette ,'" src="', $vignette ,'"/>
+ </a></td>';
+ }
+ echo '</tr></table>';
+ }
+
+ #pour afficher une seule photo
+ function afficher_photo($photo)
+ {
+ $photo_reduite = $this->repertoire_courant().SUFFIXE_PHOTO_REDUITE.$photo;
+ $pas_redim = false;
+ if (!image_redim ($this->repertoire_courant().$photo, TAILLE_PHOTO_REDUITE, $photo_reduite, 70, 1))
+ $pas_redim = true;
+
+ $lien_retour = NOM_FICHIER.'?'.arguments_page().'__section='.$this->section_courante.'&__page_section='.$this->num_page_photo($photo).'&__page_galerie=section';
+
+ if ($photo_suivant = $this->photo_suivante($photo))
+ $lien_suivant = NOM_FICHIER.'?'.arguments_page().'__section='.$this->section_courante.'&__photo='.$photo_suivant.'&__page_galerie=photo';
+
+ if ($photo_precedante = $this->photo_precedante($photo))
+ $lien_precedant = NOM_FICHIER.'?'.arguments_page().'__section='.$this->section_courante.'&__photo='.$photo_precedante.'&__page_galerie=photo';
+
+
+ echo '<table width="100%" cellpading="0" cellspacing="0" border="0">';
+
+ #la barre de navigation : suivant / précédant
+ $nav = '<tr><td>'.(isset($lien_precedant)?'<a href="'.$lien_precedant.'">Photo précédente</a>':'').'</td>'.
+ '<td align="center"><a href="'.$lien_retour.'">Retour</a></td>'.
+ '<td align="right">'.(isset($lien_suivant)?'<a href="'.$lien_suivant.'">Photo suivante</a>':'').'</td></tr>';
+
+ echo $nav;
+ echo '<tr><td colspan="3" align="center">'.($pas_redim ? '' : '<a target="_blank" href="'.$this->repertoire_courant().'">0').'<img alt="'. ($pas_redim ? $photo : $photo_reduite) .'" src="'. ($pas_redim ? $this->repertoire_courant().$photo : $photo_reduite) .'"/>'.($pas_redim ?'':'</a>').'</td></tr>';
+ echo '<tr><td colspan="3" align="center"><div style="font-size : ',TAILLE_TAILLE_NOM_IMAGE,'pt; font-weight : bold; ">',$photo,'</div></td></tr>';
+ echo $nav;
+ echo '</table>';
+ }
+
+ #renvois le numéros de la page ou se trouve une photo
+ function num_page_photo($photo)
+ {
+ $num_image = 0;
+ foreach($this->sections[$this->section_courante]['images'] as $nom_image)
+ {
+ $num_image++;
+ if ($photo == $nom_image) return ceil($num_image/NOMBRE_VIGNETTE_PAR_PAGE);
+ }
+ return 1;
+ }
+
+ #renvois la photo suivant, si elle n'existe pas alors renvois 0
+ function photo_suivante($photo)
+ {
+ $num_photo = array_search($photo, $this->sections[$this->section_courante]['images']);
+ if (isset($this->sections[$this->section_courante]['images'][$num_photo+1]))
+ return $this->sections[$this->section_courante]['images'][$num_photo+1];
+ else
+ return 0;
+ }
+
+ #renvois la photo precedante, si elle n'existe pas alors renvois 0
+ function photo_precedante($photo)
+ {
+ $num_photo = array_search($photo, $this->sections[$this->section_courante]['images']);
+ if (isset($this->sections[$this->section_courante]['images'][$num_photo-1]))
+ return $this->sections[$this->section_courante]['images'][$num_photo-1];
+ else
+ return 0;
+ }
+
+ #renvois un tableau des sections
+ function sections()
+ {
+ $sections = array();
+ foreach ($this->sections as $nom_section => $section)
+ array_push($sections, $nom_section);
+
+ return $sections;
+ }
+
+ function set_section_courante($section)
+ {
+ $this->section_courante = $section;
+ }
+
+ #renvois l'auteur d'une section
+ function get_auteur($section=null)
+ {
+ if (is_null($section)) $section = $this->section_courante;
+ return $this->sections[$section]['infos']['auteur'];
+ }
+
+ #renvois la date de la section
+ function get_date($section=null)
+ {
+ if (is_null($section)) $section = $this->section_courante;
+ return $this->sections[$section]['infos']['date'];
+ }
+}
+?>
\ No newline at end of file