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 |
];
|
3829 |
idir |
45 |
const START_DEFAUT = 0;
|
|
|
46 |
const LIMIT_DEFAUT = 100;
|
|
|
47 |
private $url_widget = null;
|
|
|
48 |
private $eflore_url_tpl = null;
|
|
|
49 |
private $service_images_url = null;
|
583 |
jpm |
50 |
private $flux_rss_url = null;
|
3041 |
killian |
51 |
|
|
|
52 |
// Suffixe de template pour la langue (vide par défaut, correspond à "fr" au français)
|
|
|
53 |
private $suffixeLangue = '';
|
3958 |
julien |
54 |
|
|
|
55 |
private $user = null;
|
|
|
56 |
|
|
|
57 |
private $service_del_url = null;
|
580 |
jpm |
58 |
/**
|
|
|
59 |
* Méthode appelée par défaut pour charger ce widget.
|
|
|
60 |
*/
|
|
|
61 |
public function executer() {
|
|
|
62 |
$retour = null;
|
588 |
jpm |
63 |
// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
|
|
|
64 |
unset($this->parametres['callback']);
|
580 |
jpm |
65 |
extract($this->parametres);
|
3958 |
julien |
66 |
|
580 |
jpm |
67 |
if (!isset($mode)) {
|
|
|
68 |
$mode = self::SERVICE_DEFAUT;
|
|
|
69 |
}
|
3829 |
idir |
70 |
$this->url_widget = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'photo');
|
583 |
jpm |
71 |
$this->eflore_url_tpl = $this->config['photo']['efloreUrlTpl'];
|
3823 |
idir |
72 |
$this->service_images_url = $this->config['photo']['celUrlImages'];
|
583 |
jpm |
73 |
$this->flux_rss_url = $this->config['photo']['fluxRssUrl'];
|
3630 |
idir |
74 |
|
580 |
jpm |
75 |
$cache_activation = $this->config['photo.cache']['activation'];
|
|
|
76 |
$cache_stockage = $this->config['photo.cache']['stockageDossier'];
|
|
|
77 |
$ddv = $this->config['photo.cache']['dureeDeVie'];
|
|
|
78 |
$cache = new Cache($cache_stockage, $ddv, $cache_activation);
|
588 |
jpm |
79 |
$id_cache = 'photo-'.hash('adler32', print_r($this->parametres, true));
|
3630 |
idir |
80 |
$contenu = $cache->charger($id_cache);
|
3958 |
julien |
81 |
|
|
|
82 |
$this->user = $this->getUserFromCookie();
|
|
|
83 |
|
3630 |
idir |
84 |
if (!$contenu) {
|
580 |
jpm |
85 |
$methode = $this->traiterNomMethodeExecuter($mode);
|
3630 |
idir |
86 |
|
580 |
jpm |
87 |
if (method_exists($this, $methode)) {
|
|
|
88 |
$retour = $this->$methode();
|
3630 |
idir |
89 |
|
580 |
jpm |
90 |
} else {
|
|
|
91 |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
|
3630 |
idir |
92 |
|
580 |
jpm |
93 |
}
|
3630 |
idir |
94 |
// Suffixe de template pour la langue - fr par défaut @TODO configurer ça un jour
|
|
|
95 |
if (isset($this->parametres['lang']) && $this->parametres['lang'] !== 'fr') {
|
|
|
96 |
$this->suffixeLangue = '_' . $this->parametres['lang'];
|
3041 |
killian |
97 |
|
|
|
98 |
}
|
|
|
99 |
|
913 |
jpm |
100 |
$contenu = '';
|
3630 |
idir |
101 |
|
580 |
jpm |
102 |
if (is_null($retour)) {
|
3004 |
mathias |
103 |
$this->messages[] = 'Aucune image';
|
3630 |
idir |
104 |
|
580 |
jpm |
105 |
} else {
|
3630 |
idir |
106 |
|
913 |
jpm |
107 |
if (isset($retour['donnees'])) {
|
3630 |
idir |
108 |
$squelette = dirname(__FILE__) .self::DS. 'squelettes' .self::DS. $retour['squelette'].$this->suffixeLangue.'.tpl.html';
|
913 |
jpm |
109 |
$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
|
|
|
110 |
$cache->sauver($id_cache, $contenu);
|
3630 |
idir |
111 |
|
913 |
jpm |
112 |
} else {
|
|
|
113 |
$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
|
3630 |
idir |
114 |
|
913 |
jpm |
115 |
}
|
580 |
jpm |
116 |
}
|
|
|
117 |
}
|
588 |
jpm |
118 |
if (isset($_GET['callback'])) {
|
3829 |
idir |
119 |
$this->envoyerJsonp(['contenu' => $contenu]);
|
3630 |
idir |
120 |
|
587 |
jpm |
121 |
} else {
|
|
|
122 |
$this->envoyer($contenu);
|
3630 |
idir |
123 |
|
587 |
jpm |
124 |
}
|
3958 |
julien |
125 |
|
|
|
126 |
// POur l'envoi du vote vers PF
|
|
|
127 |
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
128 |
if (isset($_GET['action']) && $_GET['action'] === 'send_pf_vote') {
|
|
|
129 |
$this->sendVote();
|
|
|
130 |
}
|
|
|
131 |
}
|
580 |
jpm |
132 |
}
|
3630 |
idir |
133 |
|
3829 |
idir |
134 |
// maintenir la retrocompatibilité avec l'ancien mode ajax
|
587 |
jpm |
135 |
private function executerAjax() {
|
3829 |
idir |
136 |
unset($this->parametres['mode']);
|
3630 |
idir |
137 |
|
3829 |
idir |
138 |
$chaineRequete = http_build_query($this->parametres);
|
|
|
139 |
$chaineRequete = $chaineRequete ? '?'.$chaineRequete : '';
|
|
|
140 |
$widget['donnees']['url_widget'] = $this->url_widget.$chaineRequete;
|
3630 |
idir |
141 |
|
3829 |
idir |
142 |
$id = '-'.(isset($this->parametres['id']) ? $this->parametres['id'] : '1');
|
|
|
143 |
$widget['donnees']['id'] = $id;
|
|
|
144 |
|
|
|
145 |
$widget['squelette'] = 'photo_retrocompatibilite_ajax';
|
|
|
146 |
|
587 |
jpm |
147 |
return $widget;
|
|
|
148 |
}
|
3630 |
idir |
149 |
|
1480 |
aurelien |
150 |
private function executerPopup() {
|
|
|
151 |
session_start();
|
3630 |
idir |
152 |
|
3958 |
julien |
153 |
$protocoles = $this->getProtocoles();
|
|
|
154 |
|
1495 |
aurelien |
155 |
$galerie_id = $_GET['galerie_id'];
|
1480 |
aurelien |
156 |
$widget['donnees']['url_image'] = $_GET['url_image'];
|
1495 |
aurelien |
157 |
$widget['donnees']['infos_images'] = $_SESSION[$galerie_id]['infos_images'];
|
3829 |
idir |
158 |
$widget['donnees']['url_widget'] = $this->url_widget;
|
1480 |
aurelien |
159 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
160 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/js/');
|
3630 |
idir |
161 |
$widget['donnees']['max_photo'] = $_SESSION[$galerie_id]['max_photo'];
|
3829 |
idir |
162 |
$widget['donnees']['start'] = $_SESSION[$galerie_id]['start'];
|
3823 |
idir |
163 |
$widget['donnees']['url_ws_regenerer_img'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_IMG_LIST) . '/regenerer-miniatures?ids-img=';
|
3630 |
idir |
164 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null;
|
3823 |
idir |
165 |
$widget['donnees']['url_base_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat/');
|
|
|
166 |
$widget['donnees']['formats_description'] = self::IMAGE_FORMATS;
|
3958 |
julien |
167 |
$widget['donnees']['protocoles'] = $protocoles;
|
|
|
168 |
|
|
|
169 |
if ($this->user){
|
|
|
170 |
$widget['donnees']['userId'] = $this->user['id'];
|
|
|
171 |
$widget['donnees']['token'] = $this->user['token'];
|
|
|
172 |
}
|
3630 |
idir |
173 |
|
3041 |
killian |
174 |
$widget['squelette'] = 'popup' . $this->suffixeLangue;
|
3958 |
julien |
175 |
|
1480 |
aurelien |
176 |
return $widget;
|
|
|
177 |
}
|
3630 |
idir |
178 |
|
1495 |
aurelien |
179 |
private function executerContact() {
|
|
|
180 |
session_start();
|
3630 |
idir |
181 |
|
3829 |
idir |
182 |
$widget['donnees']['url_widget'] = $this->url_widget;
|
1495 |
aurelien |
183 |
$widget['donnees']['id_image'] = $_GET['id_image'];
|
|
|
184 |
$widget['donnees']['nom_sci'] = $_GET['nom_sci'];
|
|
|
185 |
$widget['donnees']['nn'] = $_GET['nn'];
|
|
|
186 |
$widget['donnees']['date'] = $_GET['date'];
|
3630 |
idir |
187 |
$widget['donnees']['auteur'] = $_GET['auteur'];
|
|
|
188 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null;
|
|
|
189 |
|
3074 |
killian |
190 |
if (isset($_GET['lang']) && 'nl' === $_GET['lang']) {
|
3043 |
killian |
191 |
$widget['donnees']['sujet'] = "Afbeelding #".$_GET['id_image']." op ".$_GET['nom_sci'];
|
|
|
192 |
$widget['donnees']['message'] = "\n\n\n\n\n\n\n\n--\nBetreft de foto \"".$_GET['nom_sci'].'" van "'.$_GET['date'];
|
3630 |
idir |
193 |
|
3043 |
killian |
194 |
} else {
|
|
|
195 |
$widget['donnees']['sujet'] = "Image #".$_GET['id_image']." de ".$_GET['nom_sci'];
|
|
|
196 |
$widget['donnees']['message'] = "\n\n\n\n\n\n\n\n--\nConcerne l'image de \"".$_GET['nom_sci'].'" du "'.$_GET['date'];
|
3630 |
idir |
197 |
|
3043 |
killian |
198 |
}
|
3630 |
idir |
199 |
|
1495 |
aurelien |
200 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
201 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/js/');
|
3044 |
mathias |
202 |
$widget['squelette'] = 'contact';
|
3630 |
idir |
203 |
|
1495 |
aurelien |
204 |
return $widget;
|
|
|
205 |
}
|
3961 |
julien |
206 |
|
580 |
jpm |
207 |
private function executerPhoto() {
|
|
|
208 |
$widget = null;
|
3630 |
idir |
209 |
|
3829 |
idir |
210 |
$this->parametres['start'] = $this->parametres['start'] ?? self::START_DEFAUT;
|
|
|
211 |
$this->parametres['limit'] = $this->parametres['limit'] ?? self::LIMIT_DEFAUT;
|
|
|
212 |
|
583 |
jpm |
213 |
extract($this->parametres);
|
3961 |
julien |
214 |
|
3823 |
idir |
215 |
$hasTriedValueInConfig = false;
|
|
|
216 |
while (!isset($vignette) || !preg_match('/^[0-9]+,[0-9]+$/', $vignette)) {
|
|
|
217 |
$vignette = (!$hasTriedValueInConfig) ? $this->config['photo']['vignette'] : self::VIGNETTE_DEFAULT;
|
|
|
218 |
$hasTriedValueInConfig = true;
|
|
|
219 |
}
|
3961 |
julien |
220 |
|
879 |
jpm |
221 |
$id = '-'.(isset($id) ? $id : '1');
|
1480 |
aurelien |
222 |
$titre = isset($titre) ? htmlentities(rawurldecode($titre)) : '';
|
3823 |
idir |
223 |
|
1480 |
aurelien |
224 |
$icone_rss = (isset($_GET['rss']) && $_GET['rss'] != 1) ? false : true;
|
|
|
225 |
$utilise_fancybox = (isset($_GET['mode_zoom']) && $_GET['mode_zoom'] != 'fancybox') ? false : true;
|
3961 |
julien |
226 |
|
3829 |
idir |
227 |
$champ_recherche = $champ_recherche ? $this->obtenirBooleen($champ_recherche) : ($this->config['photo']['champRecherche'] ? $this->obtenirBooleen($this->config['photo']['champRecherche']) : false) ;
|
3961 |
julien |
228 |
|
3970 |
julien |
229 |
// Affichage mode e-flore avec le paramètre mode_eflore
|
|
|
230 |
if ($_GET['mode_eflore']) {
|
|
|
231 |
$champ_recherche = false;
|
3961 |
julien |
232 |
$vignette ='5,2';
|
|
|
233 |
|
|
|
234 |
$tags = [
|
|
|
235 |
'fleur',
|
|
|
236 |
'feuille',
|
|
|
237 |
'fruit',
|
|
|
238 |
'ecorce',
|
|
|
239 |
'port',
|
|
|
240 |
'rameau',
|
|
|
241 |
];
|
|
|
242 |
foreach ($tags as $tag) {
|
|
|
243 |
$widget = $this->getImages($vignette, $extra, $limit, $id, $titre, $icone_rss, $utilise_fancybox,
|
|
|
244 |
true, $tag, $widget,$champ_recherche);
|
3829 |
idir |
245 |
$widget['donnees']['champ_recherche'] = $champ_recherche;
|
580 |
jpm |
246 |
}
|
3961 |
julien |
247 |
$widget['donnees']['tagToDisplay'] = 'fleur';
|
|
|
248 |
} else {
|
|
|
249 |
$widget = $this->getImages($vignette, $extra, $limit, $id, $titre, $icone_rss, $utilise_fancybox,false, 'non_eflore', $widget,$champ_recherche);
|
|
|
250 |
$widget['donnees']['champ_recherche'] = $champ_recherche;
|
580 |
jpm |
251 |
}
|
3961 |
julien |
252 |
|
580 |
jpm |
253 |
return $widget;
|
|
|
254 |
}
|
3630 |
idir |
255 |
|
711 |
delphine |
256 |
private function traiterParametres() {
|
|
|
257 |
$parametres_flux = '?';
|
3829 |
idir |
258 |
$criteres = [
|
|
|
259 |
'taxon',
|
|
|
260 |
'referentiel',
|
|
|
261 |
'date_deb',
|
|
|
262 |
'date_fin',
|
|
|
263 |
'commune',
|
|
|
264 |
'dept',
|
|
|
265 |
'pays',
|
|
|
266 |
'auteur',
|
|
|
267 |
'programme',
|
|
|
268 |
'tag',
|
3981 |
julien |
269 |
'standard',
|
3829 |
idir |
270 |
'recherche',
|
|
|
271 |
'date',
|
|
|
272 |
'motcle',
|
|
|
273 |
'projet',
|
|
|
274 |
'num_taxon',
|
|
|
275 |
'num_nom',
|
|
|
276 |
'start',
|
3970 |
julien |
277 |
'limit',
|
3981 |
julien |
278 |
'mode_eflore',
|
|
|
279 |
'famille'
|
3829 |
idir |
280 |
];
|
3630 |
idir |
281 |
|
711 |
delphine |
282 |
foreach($this->parametres as $nom_critere => $valeur_critere) {
|
741 |
delphine |
283 |
if (in_array($nom_critere, $criteres)) {
|
|
|
284 |
$valeur_critere = str_replace(' ', '%20', $valeur_critere);
|
|
|
285 |
$parametres_flux .= $nom_critere.'='.$valeur_critere.'&';
|
3630 |
idir |
286 |
|
711 |
delphine |
287 |
}
|
|
|
288 |
}
|
3630 |
idir |
289 |
if ($parametres_flux === '?') {
|
711 |
delphine |
290 |
$parametres_flux = '';
|
3630 |
idir |
291 |
|
711 |
delphine |
292 |
} else {
|
|
|
293 |
$parametres_flux = rtrim($parametres_flux, '&');
|
3630 |
idir |
294 |
|
711 |
delphine |
295 |
}
|
3630 |
idir |
296 |
|
711 |
delphine |
297 |
return $parametres_flux;
|
|
|
298 |
}
|
3829 |
idir |
299 |
|
|
|
300 |
private function obtenirBooleen($var) {
|
|
|
301 |
switch ($var) {
|
|
|
302 |
case 'false' :
|
|
|
303 |
case 'null' :
|
|
|
304 |
case 'non' :
|
|
|
305 |
case 'no' :
|
|
|
306 |
return false;
|
|
|
307 |
default:
|
|
|
308 |
return boolval($var);
|
|
|
309 |
}
|
|
|
310 |
}
|
3958 |
julien |
311 |
|
|
|
312 |
private function getProtocoles(){
|
|
|
313 |
$protocoles = [];
|
|
|
314 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
|
|
315 |
$url = sprintf($this->service_del_url, 'protocoles');
|
|
|
316 |
$json = $this->getDao()->consulter($url);
|
|
|
317 |
|
|
|
318 |
if (empty($json)) {
|
|
|
319 |
$this->messages[] = "L'URI suivante est invalide : $url";
|
|
|
320 |
} else {
|
|
|
321 |
$protocoles= json_decode($json, true);
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
return $protocoles['resultats'];
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
private function getVotes($image){
|
|
|
328 |
$votes = [];
|
|
|
329 |
|
|
|
330 |
$id = $image['id_photo'];
|
|
|
331 |
|
|
|
332 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
|
|
333 |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes');
|
|
|
334 |
|
|
|
335 |
$json = $this->getDao()->consulter($url);
|
|
|
336 |
|
|
|
337 |
if (empty($json)) {
|
|
|
338 |
$this->messages[] = "L'URI suivante est invalide : $url";
|
|
|
339 |
} else {
|
|
|
340 |
foreach (json_decode($json, true)['resultats'] as $vote){
|
|
|
341 |
$votes[] = $vote;
|
|
|
342 |
}
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
return $votes;
|
3979 |
julien |
346 |
}
|
3958 |
julien |
347 |
|
|
|
348 |
public function sendVote(){
|
|
|
349 |
$data = json_decode(file_get_contents('php://input'), true);
|
|
|
350 |
|
|
|
351 |
$id = $data['idImage'];
|
|
|
352 |
$mode = $data['mode'];
|
|
|
353 |
$contenu = [
|
|
|
354 |
'utilisateur' => $data['user'],
|
|
|
355 |
'protocole' => $data['protocole'],
|
|
|
356 |
'valeur' => $data['vote']
|
|
|
357 |
];
|
|
|
358 |
|
|
|
359 |
switch ($mode){
|
|
|
360 |
case 'PUT':
|
|
|
361 |
case 'POST':
|
|
|
362 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
|
|
363 |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes/');
|
|
|
364 |
$this->send($url, $mode, $contenu);
|
|
|
365 |
break;
|
|
|
366 |
case 'DELETE':
|
|
|
367 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
|
|
368 |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes/'.$data['voteId']);
|
|
|
369 |
$this->send($url, $mode, $contenu);
|
|
|
370 |
break;
|
|
|
371 |
}
|
|
|
372 |
}
|
|
|
373 |
|
|
|
374 |
public function send($url, $mode, Array $donnees = array()){
|
|
|
375 |
$contenu = false;
|
3968 |
julien |
376 |
$this->user = $this->getUserFromCookie();
|
3958 |
julien |
377 |
$authorizationToken = $this->user['token'];
|
|
|
378 |
|
|
|
379 |
$json = json_encode($donnees);
|
|
|
380 |
$contexte = stream_context_create([
|
|
|
381 |
'http' => [
|
|
|
382 |
'method' => $mode,
|
|
|
383 |
'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
|
|
|
384 |
"Authorization: $authorizationToken\r\n",
|
|
|
385 |
'content' => http_build_query($donnees, null, '&')]
|
|
|
386 |
]);
|
|
|
387 |
$flux = fopen($url, 'r', false, $contexte);
|
|
|
388 |
if (!$flux) {
|
|
|
389 |
$e = "L'ouverture de l'url '{$url}' par la méthode HTTP {$mode} a échoué! avec les données {$json} et le token {$authorizationToken}";
|
|
|
390 |
trigger_error($e, E_USER_WARNING);
|
|
|
391 |
} else {
|
|
|
392 |
// Contenu actuel de $url
|
|
|
393 |
$contenu = stream_get_contents($flux);
|
|
|
394 |
|
|
|
395 |
fclose($flux);
|
|
|
396 |
}
|
|
|
397 |
return $contenu;
|
|
|
398 |
}
|
3961 |
julien |
399 |
|
|
|
400 |
public function formaterDate($item, $image){
|
|
|
401 |
$item['date_photo'] = $image['date_photo'] ?? $image['obs']['date_obs'];
|
|
|
402 |
$item['date_redige'] = strftime('%A %d %B %Y', strtotime($item['date_photo']));
|
|
|
403 |
$item['date'] = date_format(date_create($item['date_photo']),"d/m/Y");
|
|
|
404 |
$item['lien'] = sprintf($this->eflore_url_tpl, $image['obs']['nom_referentiel'], $image['obs']['nom_sel_nn']);
|
|
|
405 |
$image['url_photo'] = preg_replace('/,/', "", $image['url_photo']);
|
|
|
406 |
$item['url_tpl'] = preg_replace('/(O|XS|[SML]|X(?:[23]|)L|CR(?:|X2)S|C(?:|X)S)$/', '%s.jpg',$image['url_photo']);
|
|
|
407 |
return $item;
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
public function formaterTitre($item, $image, $auteur){
|
|
|
411 |
$item['titre'] = $image['obs']['nom_sel'].' [nn'.$image['obs']['nom_sel_nn'].'] par '.$auteur.' le '
|
|
|
412 |
.date_format(date_create($image['obs']['date_obs']),"d/m/Y").' - '.$image['obs']['localisation'];
|
|
|
413 |
|
|
|
414 |
$item['id_photo_formate'] = sprintf('%09d', $image['id_photo']);
|
|
|
415 |
$item['urlProfil'] = sprintf($this->config['photo']['tbProfilUrlTpl'], $image['utilisateur']['id_utilisateur'] );
|
|
|
416 |
return $item;
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
private function getImages($vignette, $extra, $limit, $id, $titre, $icone_rss, $utilise_fancybox, $fromEflore,
|
|
|
420 |
$tag, $widget, $champ_recherche){
|
|
|
421 |
if ($fromEflore){
|
|
|
422 |
$this->parametres['tag'] = $tag;
|
|
|
423 |
}
|
|
|
424 |
list($colonne, $ligne) = explode(',', $vignette);
|
|
|
425 |
$extra = (isset($extra) && $extra == 0) ? false : (!$this->config['photo']['extraActif'] ? false : ($colonne == 1 || $ligne == 1 ? false : true));
|
|
|
426 |
|
|
|
427 |
$max_photo = $colonne * $ligne;
|
|
|
428 |
if ( $extra && 2 == $colonne ) {
|
|
|
429 |
$max_photo = $max_photo - 1;
|
|
|
430 |
} elseif ( $extra && 2 < $colonne ) {
|
|
|
431 |
$max_photo = $max_photo - 3;
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
$limit = $limit < $max_photo ? $limit : $max_photo;
|
|
|
435 |
$this->parametres['limit'] = $limit;
|
|
|
436 |
$parametresTraites = $this->traiterParametres();
|
|
|
437 |
$this->flux_rss_url .= $parametresTraites;
|
|
|
438 |
$url = $this->service_images_url.(!empty($parametresTraites) ? $parametresTraites.'&' : '?');
|
|
|
439 |
$json = $this->getDao()->consulter($url);
|
|
|
440 |
if ($fromEflore) {
|
|
|
441 |
unset($this->parametres['tag']);
|
|
|
442 |
}
|
|
|
443 |
if (empty($json) || !strpos($json,'images') ) {
|
|
|
444 |
$this->messages[] = "L'URI suivante est invalide : $this->service_images_url.\n".
|
|
|
445 |
"Veuillez vérifier les paramêtres indiqués et la présence d'images associées.";
|
|
|
446 |
|
|
|
447 |
} else {
|
|
|
448 |
$tableau = json_decode($json, true);
|
|
|
449 |
|
|
|
450 |
if (empty($tableau['total']) || empty($tableau['images'])) {
|
|
|
451 |
$this->messages[] = 'Aucune photo ne correspond à vos critères';
|
|
|
452 |
} else {
|
|
|
453 |
|
|
|
454 |
$parametres_photo_suivante = $parametres_photo_precedente = $this->parametres;
|
3982 |
julien |
455 |
$start = $this->parametres['start'] ? : 0;
|
3961 |
julien |
456 |
$parametres_photo_suivante['start'] = $start + $limit;
|
|
|
457 |
$parametres_photo_precedente['start'] = 0 < $start - $limit ? $start - $limit : 0;
|
|
|
458 |
|
|
|
459 |
$widget['donnees']['total'] = $tableau['total'];
|
|
|
460 |
$widget['donnees']['id'] = $id;
|
|
|
461 |
$widget['donnees']['titre'] = $titre;
|
|
|
462 |
$widget['donnees']['flux_rss_url'] = $this->flux_rss_url;
|
|
|
463 |
$widget['donnees']['url_widget'] = $this->url_widget;
|
|
|
464 |
$widget['donnees']['url_widget_photos_suivantes'] = $this->url_widget.'?'.http_build_query($parametres_photo_suivante);
|
|
|
465 |
$widget['donnees']['url_widget_photos_precedente'] = $this->url_widget.'?'.http_build_query($parametres_photo_precedente);
|
|
|
466 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
467 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/js/');
|
|
|
468 |
$widget['donnees']['colonne'] = $colonne;
|
|
|
469 |
$widget['donnees']['ligne'] = $ligne;
|
|
|
470 |
$widget['donnees']['extra_actif'] = $extra;
|
|
|
471 |
$widget['donnees']['icone_rss'] = $icone_rss;
|
|
|
472 |
$widget['donnees']['champ_recherche'] = $champ_recherche;
|
|
|
473 |
$widget['donnees']['start'] = $start;
|
|
|
474 |
$widget['donnees']['limit'] = $limit;
|
|
|
475 |
$widget['donnees']['utilise_fancybox'] = $utilise_fancybox;
|
|
|
476 |
$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] === 'prod');
|
|
|
477 |
$widget['donnees']['filtres'] = $this->parametres;
|
|
|
478 |
|
|
|
479 |
$num = 0;
|
|
|
480 |
$galerie_id = md5(http_build_query($_GET));
|
|
|
481 |
$widget['donnees']['galerie_id'] = $galerie_id;
|
|
|
482 |
|
|
|
483 |
session_start();
|
|
|
484 |
$_SESSION[$galerie_id]['max_photo'] = $max_photo;
|
|
|
485 |
$_SESSION[$galerie_id]['start'] = $start;
|
|
|
486 |
|
|
|
487 |
foreach ($tableau['images'] as $key => $image) {
|
|
|
488 |
if ($key == $max_photo) {
|
|
|
489 |
break;
|
|
|
490 |
}
|
|
|
491 |
$auteurTruncatedEmail = $this->tronquerCourriel($image['utilisateur']['mail_utilisateur']);
|
|
|
492 |
$auteur = trim($image['utilisateur']['nom_utilisateur']) ? $image['utilisateur']['nom_utilisateur'] : $auteurTruncatedEmail;
|
|
|
493 |
|
|
|
494 |
$item = $image;
|
3970 |
julien |
495 |
|
3961 |
julien |
496 |
$item = $this->formaterDate($item, $image);
|
|
|
497 |
|
|
|
498 |
$item = $this->formaterTitre($item, $image, $auteur);
|
|
|
499 |
|
|
|
500 |
$item['tag_eflore'] = $tag;
|
|
|
501 |
|
|
|
502 |
// Ajout aux items et si première photo à extra
|
|
|
503 |
if ($key == 0) {
|
|
|
504 |
$widget['donnees']['extra'] = $item;
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
$widget['donnees']['items'][$tag][$num++] = $item;
|
|
|
508 |
$url_galerie_popup = sprintf($item['url_tpl'],'O');
|
|
|
509 |
$image_size = getimagesize($url_galerie_popup);
|
|
|
510 |
$item['width'] = $image_size[0];
|
|
|
511 |
$item['height'] = $image_size[1];
|
|
|
512 |
|
|
|
513 |
// Récupération des votes pictoflora
|
|
|
514 |
$item['votes'] = $this->getVotes($item);
|
|
|
515 |
|
|
|
516 |
$_SESSION[$galerie_id]['infos_images'][$url_galerie_popup] = $item;
|
|
|
517 |
}
|
|
|
518 |
|
|
|
519 |
$widget['squelette'] = 'photo';
|
|
|
520 |
}
|
|
|
521 |
}
|
|
|
522 |
|
|
|
523 |
return $widget;
|
|
|
524 |
}
|
3958 |
julien |
525 |
}
|
3839 |
idir |
526 |
?>
|