64c3df426cdfd9bae93fc750084fe7947c6506eb
[cl7.git] / class_galerie_photos.php
1 <?php
2 include('fonc_images.php');
3
4 define('NOM_FICHIER_INFO', 'infos.txt');
5 define('SUFFIXE_VIGNETTE','micro_');
6 define('SUFFIXE_PHOTO_REDUITE','mini_');
7
8 #retourne les arguments à repasser à la page
9 function arguments_page()
10 {
11 global $vars_repasse;
12 $args = '';
13 foreach($vars_repasse as $var)
14 if(isset($_GET[$var])) $args .= $var.'='.$_GET[$var].'&amp;';
15 return $args;
16 }
17
18 class Galerie
19 {
20 var $repertoire_galerie;
21
22 var $section_courante = null;
23 var $taille_vignette = TAILLE_VIGNETTE;
24 var $nombre_vignette_par_page = NOMBRE_VIGNETTE_PAR_PAGE;
25 var $nombre_colonne = NOMBRE_COLONNE;
26
27 #contient un tableau ayant pour indice le nom des section
28 #et pour valeur un tableau contenants en 'infos' un tableau contenant le nom est la date de la section
29 #et en 'images' un tableau des images de la section
30 var $sections = array();
31
32 function repertoire_courant() { return $this->repertoire_galerie.'/'.$this->section_courante.'/'; }
33
34 #constructeur
35 function Galerie($rep='.')
36 {
37 $this->repertoire_galerie = $rep;
38
39 #ouvre le repertoire de la galerie
40 $rep_galerie = dir($this->repertoire_galerie);
41 #pour chaque repertoire (section)
42 while ($section = $rep_galerie->read())
43 {
44 if ($section != '..' and $section != '.')
45 {
46 if (is_null($this->section_courante)) $this->section_courante = $section;
47
48 #ouvre le repertoire des images de la section en cours
49 $rep_section = dir($this->repertoire_galerie.'/'.$section);
50
51 #essais d'inclure le fichier d'info
52 if (!@include($this->repertoire_galerie.'/'.$section.'/'.NOM_FICHIER_INFO))
53 {$auteur = 'auteur inconnu'; $date = 'date inconnue';}
54
55 #enregistre les infos
56 $this->sections[$section]['infos']['auteur'] = $auteur;
57 $this->sections[$section]['infos']['date'] = $date;
58
59 #pour chaque images
60 while ($photo = $rep_section->read())
61 {
62 if (ereg('('.SUFFIXE_VIGNETTE.'|'.SUFFIXE_PHOTO_REDUITE.').*', $photo)) continue;
63 if (ereg('.*\.[jJ][pP][gG]', $photo)) #si l'extension est .jpg alors mémorise l'image
64 $this->sections[$section]['images'][] = $photo;
65 }
66 $rep_section->close();
67 }
68 }
69 $rep_galerie->close();
70
71 foreach($this->sections as $nom_section => $null)
72 sort($this->sections[$nom_section]['images']);
73 }
74
75 #affiche la liste des pages
76 function liste_pages()
77 {
78 for($i=1; $i<=ceil(count($this->sections[$this->section_courante]['images'])/NOMBRE_VIGNETTE_PAR_PAGE); $i++)
79 echo ($i==1?'':' | ') ,($i==$_GET['__page_section']?'<b>':''),'<a href="',NOM_FICHIER,'?',arguments_page(),'__section=',$this->section_courante,'&amp;__page_section=',$i,'&amp;__page_galerie=section">',$i,'</a>',($i==$_GET['__page_section']?'</b>':'');
80 }
81
82 #affiche les vignettes de la section courante
83 function afficher_vignettes($page)
84 {
85 $num_image = 0;
86
87 echo '<table width="100%" cellpading="0" cellspacing="0" border="0">';
88 echo '<tr><td><div style="font-size : ',TAILLE_SECTION,'pt; font-weight : bold; ">',$this->section_courante,'</div></td>';
89 echo '<td align="right">Pages : ',$this->liste_pages(),'</td></tr>';
90 echo '<tr><td colspan="2">Auteur : ', $this->get_auteur(), ' - Date : ', $this->get_date(), '</td></tr></table>';
91
92 #pour chaque image de la section courante
93 echo '<br/><table width="100%" cellpading="0" cellspacing="0" border="0"><tr>';
94 foreach ($this->sections[$this->section_courante]['images'] as $image)
95 {
96 $num_image++;
97
98 if ($num_image <= $page*NOMBRE_VIGNETTE_PAR_PAGE-NOMBRE_VIGNETTE_PAR_PAGE or $num_image > $page*NOMBRE_VIGNETTE_PAR_PAGE)
99 continue;
100
101 $vignette = $this->repertoire_courant().SUFFIXE_VIGNETTE.$image;
102 image_redim ($this->repertoire_courant().$image, TAILLE_VIGNETTE, $vignette, 60, 1);
103
104 if (($num_image - $page*NOMBRE_VIGNETTE_PAR_PAGE-1) % NOMBRE_COLONNE == 0) echo '</tr><tr>';
105 echo '<td align="center" valign="middle">
106 <a href="',NOM_FICHIER,'?',arguments_page(),'__section=',$this->section_courante,'&amp;__photo=',$image,'&amp;__page_galerie=photo">
107 <img alt="', $vignette ,'" src="', $vignette ,'"/>
108 </a></td>';
109 }
110 echo '</tr></table>';
111 }
112
113 #pour afficher une seule photo
114 function afficher_photo($photo)
115 {
116 $photo_reduite = $this->repertoire_courant().SUFFIXE_PHOTO_REDUITE.$photo;
117 $pas_redim = false;
118 if (!image_redim ($this->repertoire_courant().$photo, TAILLE_PHOTO_REDUITE, $photo_reduite, 70, 1))
119 $pas_redim = true;
120
121 $lien_retour = NOM_FICHIER.'?'.arguments_page().'__section='.$this->section_courante.'&amp;__page_section='.$this->num_page_photo($photo).'&amp;__page_galerie=section';
122
123 if ($photo_suivant = $this->photo_suivante($photo))
124 $lien_suivant = NOM_FICHIER.'?'.arguments_page().'__section='.$this->section_courante.'&amp;__photo='.$photo_suivant.'&amp;__page_galerie=photo';
125
126 if ($photo_precedante = $this->photo_precedante($photo))
127 $lien_precedant = NOM_FICHIER.'?'.arguments_page().'__section='.$this->section_courante.'&amp;__photo='.$photo_precedante.'&amp;__page_galerie=photo';
128
129
130 echo '<table width="100%" cellpading="0" cellspacing="0" border="0">';
131
132 #la barre de navigation : suivant / précédant
133 $nav = '<tr><td>'.(isset($lien_precedant)?'<a href="'.$lien_precedant.'">Photo précédente</a>':'').'</td>'.
134 '<td align="center"><a href="'.$lien_retour.'">Retour</a></td>'.
135 '<td align="right">'.(isset($lien_suivant)?'<a href="'.$lien_suivant.'">Photo suivante</a>':'').'</td></tr>';
136
137 echo $nav;
138 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>';
139 echo '<tr><td colspan="3" align="center"><div style="font-size : ',TAILLE_TAILLE_NOM_IMAGE,'pt; font-weight : bold; ">',$photo,'</div></td></tr>';
140 echo $nav;
141 echo '</table>';
142 }
143
144 #renvois le numéros de la page ou se trouve une photo
145 function num_page_photo($photo)
146 {
147 $num_image = 0;
148 foreach($this->sections[$this->section_courante]['images'] as $nom_image)
149 {
150 $num_image++;
151 if ($photo == $nom_image) return ceil($num_image/NOMBRE_VIGNETTE_PAR_PAGE);
152 }
153 return 1;
154 }
155
156 #renvois la photo suivant, si elle n'existe pas alors renvois 0
157 function photo_suivante($photo)
158 {
159 $num_photo = array_search($photo, $this->sections[$this->section_courante]['images']);
160 if (isset($this->sections[$this->section_courante]['images'][$num_photo+1]))
161 return $this->sections[$this->section_courante]['images'][$num_photo+1];
162 else
163 return 0;
164 }
165
166 #renvois la photo precedante, si elle n'existe pas alors renvois 0
167 function photo_precedante($photo)
168 {
169 $num_photo = array_search($photo, $this->sections[$this->section_courante]['images']);
170 if (isset($this->sections[$this->section_courante]['images'][$num_photo-1]))
171 return $this->sections[$this->section_courante]['images'][$num_photo-1];
172 else
173 return 0;
174 }
175
176 #renvois un tableau des sections
177 function sections()
178 {
179 $sections = array();
180 foreach ($this->sections as $nom_section => $section)
181 array_push($sections, $nom_section);
182
183 return $sections;
184 }
185
186 function set_section_courante($section)
187 {
188 $this->section_courante = $section;
189 }
190
191 #renvois l'auteur d'une section
192 function get_auteur($section=null)
193 {
194 if (is_null($section)) $section = $this->section_courante;
195 return $this->sections[$section]['infos']['auteur'];
196 }
197
198 #renvois la date de la section
199 function get_date($section=null)
200 {
201 if (is_null($section)) $section = $this->section_courante;
202 return $this->sections[$section]['infos']['date'];
203 }
204 }
205 ?>