580 |
jpm |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.
|
|
|
5 |
* Encodage en entrée : utf8
|
|
|
6 |
* Encodage en sortie : utf8
|
|
|
7 |
*
|
|
|
8 |
* Cas d'utilisation et documentation :
|
|
|
9 |
* @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
|
|
|
10 |
*
|
|
|
11 |
* Paramètres :
|
583 |
jpm |
12 |
* ===> extra = booléen (1 ou 0) [par défaut : 1]
|
|
|
13 |
* Affiche / Cache la vignette en taille plus importante au bas du widget.
|
|
|
14 |
* ===> vignette = [0-9]+,[0-9]+ [par défaut : 4,3]
|
|
|
15 |
* Indique le nombre de vignette par ligne et le nombre de ligne.
|
580 |
jpm |
16 |
*
|
3823 |
idir |
17 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
18 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
19 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
20 |
* @version $Id$
|
|
|
21 |
* @copyright Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
|
580 |
jpm |
22 |
*/
|
|
|
23 |
class Photo extends WidgetCommun {
|
3630 |
idir |
24 |
|
580 |
jpm |
25 |
const DS = DIRECTORY_SEPARATOR;
|
|
|
26 |
const SERVICE_DEFAUT = 'photo';
|
3823 |
idir |
27 |
const VIGNETTE_DEFAULT = '4,3';
|
|
|
28 |
const WS_IMG_LIST = 'celImage';
|
|
|
29 |
const IMAGE_FORMATS = [
|
|
|
30 |
'CRX2S' => '63px (Carrée, rognée)',
|
|
|
31 |
'CRXS' => '100px (Carrée, rognée)',
|
|
|
32 |
'CXS' => '100px (Carrée)',
|
|
|
33 |
'CS' => '300px (Carrée)',
|
|
|
34 |
'CRS' => '300px (Carrée, rognée)',
|
|
|
35 |
'XS' => '150px',
|
|
|
36 |
'S' => '400px',
|
|
|
37 |
'M' => '600px',
|
|
|
38 |
'L' => '800px',
|
|
|
39 |
'CRL' => '600px (Carrée, rognée)',
|
|
|
40 |
'XL' => '1024px',
|
|
|
41 |
'X2L' => '1280px',
|
|
|
42 |
'X3L' => '1600px',
|
|
|
43 |
'O' => 'Format original (Taille inconnue)'
|
|
|
44 |
];
|
583 |
jpm |
45 |
private $flux_rss_url = null;
|
|
|
46 |
private $eflore_url_tpl = null;
|
3041 |
killian |
47 |
|
|
|
48 |
// Suffixe de template pour la langue (vide par défaut, correspond à "fr" au français)
|
|
|
49 |
private $suffixeLangue = '';
|
|
|
50 |
|
580 |
jpm |
51 |
/**
|
|
|
52 |
* Méthode appelée par défaut pour charger ce widget.
|
|
|
53 |
*/
|
|
|
54 |
public function executer() {
|
|
|
55 |
$retour = null;
|
588 |
jpm |
56 |
// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
|
|
|
57 |
unset($this->parametres['callback']);
|
580 |
jpm |
58 |
extract($this->parametres);
|
|
|
59 |
|
|
|
60 |
if (!isset($mode)) {
|
|
|
61 |
$mode = self::SERVICE_DEFAUT;
|
|
|
62 |
}
|
3630 |
idir |
63 |
|
583 |
jpm |
64 |
$this->eflore_url_tpl = $this->config['photo']['efloreUrlTpl'];
|
3823 |
idir |
65 |
$this->service_images_url = $this->config['photo']['celUrlImages'];
|
583 |
jpm |
66 |
$this->flux_rss_url = $this->config['photo']['fluxRssUrl'];
|
3630 |
idir |
67 |
|
580 |
jpm |
68 |
$cache_activation = $this->config['photo.cache']['activation'];
|
|
|
69 |
$cache_stockage = $this->config['photo.cache']['stockageDossier'];
|
|
|
70 |
$ddv = $this->config['photo.cache']['dureeDeVie'];
|
|
|
71 |
$cache = new Cache($cache_stockage, $ddv, $cache_activation);
|
588 |
jpm |
72 |
$id_cache = 'photo-'.hash('adler32', print_r($this->parametres, true));
|
3630 |
idir |
73 |
$contenu = $cache->charger($id_cache);
|
|
|
74 |
|
|
|
75 |
if (!$contenu) {
|
580 |
jpm |
76 |
$methode = $this->traiterNomMethodeExecuter($mode);
|
3630 |
idir |
77 |
|
580 |
jpm |
78 |
if (method_exists($this, $methode)) {
|
|
|
79 |
$retour = $this->$methode();
|
3630 |
idir |
80 |
|
580 |
jpm |
81 |
} else {
|
|
|
82 |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
|
3630 |
idir |
83 |
|
580 |
jpm |
84 |
}
|
3630 |
idir |
85 |
// Suffixe de template pour la langue - fr par défaut @TODO configurer ça un jour
|
|
|
86 |
if (isset($this->parametres['lang']) && $this->parametres['lang'] !== 'fr') {
|
|
|
87 |
$this->suffixeLangue = '_' . $this->parametres['lang'];
|
3041 |
killian |
88 |
|
|
|
89 |
}
|
|
|
90 |
|
913 |
jpm |
91 |
$contenu = '';
|
3630 |
idir |
92 |
|
580 |
jpm |
93 |
if (is_null($retour)) {
|
3004 |
mathias |
94 |
$this->messages[] = 'Aucune image';
|
3630 |
idir |
95 |
|
580 |
jpm |
96 |
} else {
|
3630 |
idir |
97 |
|
913 |
jpm |
98 |
if (isset($retour['donnees'])) {
|
3630 |
idir |
99 |
$squelette = dirname(__FILE__) .self::DS. 'squelettes' .self::DS. $retour['squelette'].$this->suffixeLangue.'.tpl.html';
|
913 |
jpm |
100 |
$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
|
|
|
101 |
$cache->sauver($id_cache, $contenu);
|
3630 |
idir |
102 |
|
913 |
jpm |
103 |
} else {
|
|
|
104 |
$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
|
3630 |
idir |
105 |
|
913 |
jpm |
106 |
}
|
580 |
jpm |
107 |
}
|
|
|
108 |
}
|
588 |
jpm |
109 |
if (isset($_GET['callback'])) {
|
587 |
jpm |
110 |
$this->envoyerJsonp(array('contenu' => $contenu));
|
3630 |
idir |
111 |
|
587 |
jpm |
112 |
} else {
|
|
|
113 |
$this->envoyer($contenu);
|
3630 |
idir |
114 |
|
587 |
jpm |
115 |
}
|
580 |
jpm |
116 |
}
|
3630 |
idir |
117 |
|
587 |
jpm |
118 |
private function executerAjax() {
|
|
|
119 |
$widget = $this->executerPhoto();
|
3630 |
idir |
120 |
|
587 |
jpm |
121 |
$widget['squelette'] = 'photo_ajax';
|
3630 |
idir |
122 |
|
587 |
jpm |
123 |
return $widget;
|
|
|
124 |
}
|
3630 |
idir |
125 |
|
1480 |
aurelien |
126 |
private function executerPopup() {
|
|
|
127 |
session_start();
|
3630 |
idir |
128 |
|
1495 |
aurelien |
129 |
$galerie_id = $_GET['galerie_id'];
|
3630 |
idir |
130 |
|
1480 |
aurelien |
131 |
$widget['donnees']['url_image'] = $_GET['url_image'];
|
1495 |
aurelien |
132 |
$widget['donnees']['infos_images'] = $_SESSION[$galerie_id]['infos_images'];
|
|
|
133 |
$widget['donnees']['urls'] = $_SESSION[$galerie_id]['urls'];
|
|
|
134 |
$widget['donnees']['url_widget'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'photo');
|
1480 |
aurelien |
135 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
136 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/js/');
|
3630 |
idir |
137 |
$widget['donnees']['max_photo'] = $_SESSION[$galerie_id]['max_photo'];
|
3823 |
idir |
138 |
$widget['donnees']['url_ws_regenerer_img'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_IMG_LIST) . '/regenerer-miniatures?ids-img=';
|
3630 |
idir |
139 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null;
|
3823 |
idir |
140 |
$widget['donnees']['url_base_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat/');
|
|
|
141 |
$widget['donnees']['formats_description'] = self::IMAGE_FORMATS;
|
3630 |
idir |
142 |
|
3041 |
killian |
143 |
$widget['squelette'] = 'popup' . $this->suffixeLangue;
|
3630 |
idir |
144 |
|
1480 |
aurelien |
145 |
return $widget;
|
|
|
146 |
}
|
3630 |
idir |
147 |
|
1495 |
aurelien |
148 |
private function executerContact() {
|
|
|
149 |
session_start();
|
3630 |
idir |
150 |
|
|
|
151 |
$widget['donnees']['url_widget'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'photo');
|
1495 |
aurelien |
152 |
$widget['donnees']['id_image'] = $_GET['id_image'];
|
|
|
153 |
$widget['donnees']['nom_sci'] = $_GET['nom_sci'];
|
|
|
154 |
$widget['donnees']['nn'] = $_GET['nn'];
|
|
|
155 |
$widget['donnees']['date'] = $_GET['date'];
|
3630 |
idir |
156 |
$widget['donnees']['auteur'] = $_GET['auteur'];
|
|
|
157 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null;
|
|
|
158 |
|
3074 |
killian |
159 |
if (isset($_GET['lang']) && 'nl' === $_GET['lang']) {
|
3043 |
killian |
160 |
$widget['donnees']['sujet'] = "Afbeelding #".$_GET['id_image']." op ".$_GET['nom_sci'];
|
|
|
161 |
$widget['donnees']['message'] = "\n\n\n\n\n\n\n\n--\nBetreft de foto \"".$_GET['nom_sci'].'" van "'.$_GET['date'];
|
3630 |
idir |
162 |
|
3043 |
killian |
163 |
} else {
|
|
|
164 |
$widget['donnees']['sujet'] = "Image #".$_GET['id_image']." de ".$_GET['nom_sci'];
|
|
|
165 |
$widget['donnees']['message'] = "\n\n\n\n\n\n\n\n--\nConcerne l'image de \"".$_GET['nom_sci'].'" du "'.$_GET['date'];
|
3630 |
idir |
166 |
|
3043 |
killian |
167 |
}
|
3630 |
idir |
168 |
|
1495 |
aurelien |
169 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
170 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/js/');
|
3044 |
mathias |
171 |
$widget['squelette'] = 'contact';
|
3630 |
idir |
172 |
|
1495 |
aurelien |
173 |
return $widget;
|
|
|
174 |
}
|
3630 |
idir |
175 |
|
|
|
176 |
|
580 |
jpm |
177 |
private function executerPhoto() {
|
1480 |
aurelien |
178 |
session_start();
|
3630 |
idir |
179 |
|
580 |
jpm |
180 |
$widget = null;
|
3630 |
idir |
181 |
|
583 |
jpm |
182 |
extract($this->parametres);
|
3630 |
idir |
183 |
|
3823 |
idir |
184 |
$hasTriedValueInConfig = false;
|
|
|
185 |
while (!isset($vignette) || !preg_match('/^[0-9]+,[0-9]+$/', $vignette)) {
|
|
|
186 |
$vignette = (!$hasTriedValueInConfig) ? $this->config['photo']['vignette'] : self::VIGNETTE_DEFAULT;
|
|
|
187 |
$hasTriedValueInConfig = true;
|
|
|
188 |
}
|
879 |
jpm |
189 |
$id = '-'.(isset($id) ? $id : '1');
|
1480 |
aurelien |
190 |
$titre = isset($titre) ? htmlentities(rawurldecode($titre)) : '';
|
3823 |
idir |
191 |
|
1480 |
aurelien |
192 |
$icone_rss = (isset($_GET['rss']) && $_GET['rss'] != 1) ? false : true;
|
|
|
193 |
$utilise_fancybox = (isset($_GET['mode_zoom']) && $_GET['mode_zoom'] != 'fancybox') ? false : true;
|
3630 |
idir |
194 |
|
583 |
jpm |
195 |
list($colonne, $ligne) = explode(',', $vignette);
|
3823 |
idir |
196 |
$extra = (isset($extra) && $extra == 0) ? false : (!$this->config['photo']['extraActif'] ? false : ($colonne == 1 || $ligne == 1 ? false : true));
|
|
|
197 |
$parametresTraites = $this->traiterParametres();
|
|
|
198 |
$this->flux_rss_url .= $parametresTraites;
|
|
|
199 |
$url = $this->service_images_url.(!empty($parametresTraites) ? $parametresTraites : '*');
|
|
|
200 |
$json = $this->getDao()->consulter($url);
|
2776 |
mathias |
201 |
|
3630 |
idir |
202 |
|
3823 |
idir |
203 |
if (empty($json) || !strpos($json,'images') ) {
|
|
|
204 |
$this->messages[] = "L'URI suivante est invalide : $this->service_images_url.\n".
|
|
|
205 |
"Veuillez vérifier les paramêtres indiqués et la présence d'images associées.";
|
2848 |
mathias |
206 |
|
3823 |
idir |
207 |
} else {
|
|
|
208 |
$tableau = json_decode($json, true);
|
3630 |
idir |
209 |
|
3823 |
idir |
210 |
if (empty($tableau['total']) || empty($tableau['images'])) {
|
|
|
211 |
$this->messages[] = 'Aucune photo ne correspond à vos critères';
|
|
|
212 |
} else {
|
|
|
213 |
$widget['donnees']['id'] = $id;
|
|
|
214 |
$widget['donnees']['titre'] = $titre;
|
|
|
215 |
// $widget['donnees']['service_images_url'] = $this->service_images_url;
|
|
|
216 |
$widget['donnees']['flux_rss_url'] = $this->flux_rss_url;
|
|
|
217 |
$widget['donnees']['url_widget'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'photo');
|
|
|
218 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
219 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/js/');
|
|
|
220 |
$widget['donnees']['colonne'] = $colonne;
|
|
|
221 |
$widget['donnees']['extra_actif'] = $extra;
|
|
|
222 |
$widget['donnees']['icone_rss'] = $icone_rss;
|
|
|
223 |
$widget['donnees']['utilise_fancybox'] = $utilise_fancybox;
|
|
|
224 |
$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] === 'prod');
|
3630 |
idir |
225 |
|
3823 |
idir |
226 |
$max_photo = $colonne * $ligne;
|
|
|
227 |
if ( $extra && 2 == $colonne ) {
|
|
|
228 |
$max_photo = $max_photo - 1;
|
|
|
229 |
} elseif ( $extra && 2 < $colonne ) {
|
|
|
230 |
$max_photo = $max_photo - 3;
|
|
|
231 |
}
|
|
|
232 |
$num = 0;
|
|
|
233 |
$galerie_id = md5(http_build_query($_GET));
|
|
|
234 |
$widget['donnees']['galerie_id'] = $galerie_id;
|
3630 |
idir |
235 |
|
3823 |
idir |
236 |
foreach ($tableau['images'] as $image) {
|
|
|
237 |
if ($num == $max_photo) {
|
|
|
238 |
break;
|
|
|
239 |
}
|
|
|
240 |
$item = $image;
|
|
|
241 |
// Formatage date
|
|
|
242 |
$item['date_photo'] = $image['date_photo'] ?? $image['obs']['date_obs'];
|
|
|
243 |
$item['date_redige'] = strftime('%A %d %B %Y', $item['date_photo']);
|
|
|
244 |
$item['date'] = date_format(date_create($item['date_photo']),"d/m/Y");
|
|
|
245 |
$item['lien'] = sprintf($this->eflore_url_tpl, $image['obs']['nom_referentiel'], $image['obs']['nom_sel_nn']);
|
|
|
246 |
$item['eflore_url'] = isset($item['nn']) ? $item['lien'] : '#';
|
|
|
247 |
$item['url_tpl'] = preg_replace('/(O|XS|[SML]|X(?:[23]|)L|CR(?:|X2)S|C(?:|X)S)$/', '%s.jpg', $image['url_photo']);
|
|
|
248 |
// Formatage titre
|
|
|
249 |
$item['titre'] = $image['obs']['nom_sel'].' [nn'.$image['obs']['nom_sel_nn'].'] par '.$image['utilisateur']['nom_utilisateur'].' le '.date_format(date_create($image['obs']['date_obs']),"d/m/Y").' - '.$image['obs']['localisation'];
|
|
|
250 |
$item['id_photo_formate'] = sprintf('%09d', $image['id_photo']);
|
|
|
251 |
// Ajout aux items et si première photo à extra
|
|
|
252 |
if ($num == 0) {
|
|
|
253 |
$widget['donnees']['extra'] = $item;
|
3630 |
idir |
254 |
|
583 |
jpm |
255 |
}
|
3630 |
idir |
256 |
|
3823 |
idir |
257 |
$widget['donnees']['items'][$num++] = $item;
|
|
|
258 |
$url_galerie_popup = sprintf($item['url_tpl'],'O');
|
|
|
259 |
$image_size = getimagesize($url_galerie_popup);
|
|
|
260 |
$item['width'] = $image_size[0];
|
|
|
261 |
$item['height'] = $image_size[1];
|
|
|
262 |
$_SESSION[$galerie_id]['urls'][] = $url_galerie_popup;
|
|
|
263 |
$_SESSION[$galerie_id]['max_photo'] = $max_photo;
|
|
|
264 |
$_SESSION[$galerie_id]['infos_images'][$url_galerie_popup] = $item;
|
583 |
jpm |
265 |
}
|
3630 |
idir |
266 |
|
3823 |
idir |
267 |
$widget['squelette'] = 'photo';
|
580 |
jpm |
268 |
}
|
|
|
269 |
}
|
3630 |
idir |
270 |
|
580 |
jpm |
271 |
return $widget;
|
|
|
272 |
}
|
3630 |
idir |
273 |
|
711 |
delphine |
274 |
private function traiterParametres() {
|
|
|
275 |
$parametres_flux = '?';
|
2776 |
mathias |
276 |
$criteres = array('utilisateur', 'commune', 'dept', 'taxon', 'commentaire', 'date', 'tag', 'motcle', 'projet', 'num_taxon', 'num_nom', 'referentiel', 'groupe_zones_geo');
|
3630 |
idir |
277 |
|
711 |
delphine |
278 |
foreach($this->parametres as $nom_critere => $valeur_critere) {
|
741 |
delphine |
279 |
if (in_array($nom_critere, $criteres)) {
|
|
|
280 |
$valeur_critere = str_replace(' ', '%20', $valeur_critere);
|
|
|
281 |
$parametres_flux .= $nom_critere.'='.$valeur_critere.'&';
|
3630 |
idir |
282 |
|
711 |
delphine |
283 |
}
|
|
|
284 |
}
|
3630 |
idir |
285 |
if ($parametres_flux === '?') {
|
711 |
delphine |
286 |
$parametres_flux = '';
|
3630 |
idir |
287 |
|
711 |
delphine |
288 |
} else {
|
|
|
289 |
$parametres_flux = rtrim($parametres_flux, '&');
|
3630 |
idir |
290 |
|
711 |
delphine |
291 |
}
|
3630 |
idir |
292 |
|
711 |
delphine |
293 |
return $parametres_flux;
|
|
|
294 |
}
|
580 |
jpm |
295 |
}
|
3823 |
idir |
296 |
?>
|