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;
|
3983 |
julien |
168 |
$widget['donnees']['del_url'] = sprintf($this->config['chemins']['baseURLServicesDelTpl'], '');
|
3985 |
julien |
169 |
$widget['donnees']['new_cel_url'] = sprintf($this->config['chemins']['baseURLServicesNewCelTpl'], '');
|
3958 |
julien |
170 |
|
|
|
171 |
if ($this->user){
|
|
|
172 |
$widget['donnees']['userId'] = $this->user['id'];
|
|
|
173 |
$widget['donnees']['token'] = $this->user['token'];
|
|
|
174 |
}
|
3630 |
idir |
175 |
|
3041 |
killian |
176 |
$widget['squelette'] = 'popup' . $this->suffixeLangue;
|
3958 |
julien |
177 |
|
1480 |
aurelien |
178 |
return $widget;
|
|
|
179 |
}
|
3630 |
idir |
180 |
|
1495 |
aurelien |
181 |
private function executerContact() {
|
|
|
182 |
session_start();
|
3630 |
idir |
183 |
|
3829 |
idir |
184 |
$widget['donnees']['url_widget'] = $this->url_widget;
|
1495 |
aurelien |
185 |
$widget['donnees']['id_image'] = $_GET['id_image'];
|
|
|
186 |
$widget['donnees']['nom_sci'] = $_GET['nom_sci'];
|
|
|
187 |
$widget['donnees']['nn'] = $_GET['nn'];
|
|
|
188 |
$widget['donnees']['date'] = $_GET['date'];
|
3630 |
idir |
189 |
$widget['donnees']['auteur'] = $_GET['auteur'];
|
|
|
190 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null;
|
|
|
191 |
|
3074 |
killian |
192 |
if (isset($_GET['lang']) && 'nl' === $_GET['lang']) {
|
3043 |
killian |
193 |
$widget['donnees']['sujet'] = "Afbeelding #".$_GET['id_image']." op ".$_GET['nom_sci'];
|
|
|
194 |
$widget['donnees']['message'] = "\n\n\n\n\n\n\n\n--\nBetreft de foto \"".$_GET['nom_sci'].'" van "'.$_GET['date'];
|
3630 |
idir |
195 |
|
3043 |
killian |
196 |
} else {
|
|
|
197 |
$widget['donnees']['sujet'] = "Image #".$_GET['id_image']." de ".$_GET['nom_sci'];
|
|
|
198 |
$widget['donnees']['message'] = "\n\n\n\n\n\n\n\n--\nConcerne l'image de \"".$_GET['nom_sci'].'" du "'.$_GET['date'];
|
3630 |
idir |
199 |
|
3043 |
killian |
200 |
}
|
3630 |
idir |
201 |
|
1495 |
aurelien |
202 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
203 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/js/');
|
3044 |
mathias |
204 |
$widget['squelette'] = 'contact';
|
3630 |
idir |
205 |
|
1495 |
aurelien |
206 |
return $widget;
|
|
|
207 |
}
|
3961 |
julien |
208 |
|
580 |
jpm |
209 |
private function executerPhoto() {
|
|
|
210 |
$widget = null;
|
3630 |
idir |
211 |
|
3829 |
idir |
212 |
$this->parametres['start'] = $this->parametres['start'] ?? self::START_DEFAUT;
|
|
|
213 |
$this->parametres['limit'] = $this->parametres['limit'] ?? self::LIMIT_DEFAUT;
|
|
|
214 |
|
583 |
jpm |
215 |
extract($this->parametres);
|
3961 |
julien |
216 |
|
3823 |
idir |
217 |
$hasTriedValueInConfig = false;
|
|
|
218 |
while (!isset($vignette) || !preg_match('/^[0-9]+,[0-9]+$/', $vignette)) {
|
|
|
219 |
$vignette = (!$hasTriedValueInConfig) ? $this->config['photo']['vignette'] : self::VIGNETTE_DEFAULT;
|
|
|
220 |
$hasTriedValueInConfig = true;
|
|
|
221 |
}
|
3961 |
julien |
222 |
|
879 |
jpm |
223 |
$id = '-'.(isset($id) ? $id : '1');
|
1480 |
aurelien |
224 |
$titre = isset($titre) ? htmlentities(rawurldecode($titre)) : '';
|
3823 |
idir |
225 |
|
1480 |
aurelien |
226 |
$icone_rss = (isset($_GET['rss']) && $_GET['rss'] != 1) ? false : true;
|
|
|
227 |
$utilise_fancybox = (isset($_GET['mode_zoom']) && $_GET['mode_zoom'] != 'fancybox') ? false : true;
|
3961 |
julien |
228 |
|
3829 |
idir |
229 |
$champ_recherche = $champ_recherche ? $this->obtenirBooleen($champ_recherche) : ($this->config['photo']['champRecherche'] ? $this->obtenirBooleen($this->config['photo']['champRecherche']) : false) ;
|
3961 |
julien |
230 |
|
3970 |
julien |
231 |
// Affichage mode e-flore avec le paramètre mode_eflore
|
|
|
232 |
if ($_GET['mode_eflore']) {
|
|
|
233 |
$champ_recherche = false;
|
3961 |
julien |
234 |
$vignette ='5,2';
|
|
|
235 |
|
|
|
236 |
$tags = [
|
|
|
237 |
'fleur',
|
|
|
238 |
'feuille',
|
|
|
239 |
'fruit',
|
|
|
240 |
'ecorce',
|
|
|
241 |
'port',
|
|
|
242 |
'rameau',
|
|
|
243 |
];
|
|
|
244 |
foreach ($tags as $tag) {
|
|
|
245 |
$widget = $this->getImages($vignette, $extra, $limit, $id, $titre, $icone_rss, $utilise_fancybox,
|
|
|
246 |
true, $tag, $widget,$champ_recherche);
|
3829 |
idir |
247 |
$widget['donnees']['champ_recherche'] = $champ_recherche;
|
580 |
jpm |
248 |
}
|
3961 |
julien |
249 |
$widget['donnees']['tagToDisplay'] = 'fleur';
|
|
|
250 |
} else {
|
|
|
251 |
$widget = $this->getImages($vignette, $extra, $limit, $id, $titre, $icone_rss, $utilise_fancybox,false, 'non_eflore', $widget,$champ_recherche);
|
|
|
252 |
$widget['donnees']['champ_recherche'] = $champ_recherche;
|
580 |
jpm |
253 |
}
|
3961 |
julien |
254 |
|
580 |
jpm |
255 |
return $widget;
|
|
|
256 |
}
|
3630 |
idir |
257 |
|
711 |
delphine |
258 |
private function traiterParametres() {
|
|
|
259 |
$parametres_flux = '?';
|
3829 |
idir |
260 |
$criteres = [
|
|
|
261 |
'taxon',
|
|
|
262 |
'referentiel',
|
|
|
263 |
'date_deb',
|
|
|
264 |
'date_fin',
|
|
|
265 |
'commune',
|
|
|
266 |
'dept',
|
|
|
267 |
'pays',
|
|
|
268 |
'auteur',
|
|
|
269 |
'programme',
|
|
|
270 |
'tag',
|
3981 |
julien |
271 |
'standard',
|
3829 |
idir |
272 |
'recherche',
|
|
|
273 |
'date',
|
|
|
274 |
'motcle',
|
|
|
275 |
'projet',
|
|
|
276 |
'num_taxon',
|
|
|
277 |
'num_nom',
|
|
|
278 |
'start',
|
3970 |
julien |
279 |
'limit',
|
3981 |
julien |
280 |
'mode_eflore',
|
|
|
281 |
'famille'
|
3829 |
idir |
282 |
];
|
3630 |
idir |
283 |
|
711 |
delphine |
284 |
foreach($this->parametres as $nom_critere => $valeur_critere) {
|
741 |
delphine |
285 |
if (in_array($nom_critere, $criteres)) {
|
|
|
286 |
$valeur_critere = str_replace(' ', '%20', $valeur_critere);
|
|
|
287 |
$parametres_flux .= $nom_critere.'='.$valeur_critere.'&';
|
3630 |
idir |
288 |
|
711 |
delphine |
289 |
}
|
|
|
290 |
}
|
3630 |
idir |
291 |
if ($parametres_flux === '?') {
|
711 |
delphine |
292 |
$parametres_flux = '';
|
3630 |
idir |
293 |
|
711 |
delphine |
294 |
} else {
|
|
|
295 |
$parametres_flux = rtrim($parametres_flux, '&');
|
3630 |
idir |
296 |
|
711 |
delphine |
297 |
}
|
3630 |
idir |
298 |
|
711 |
delphine |
299 |
return $parametres_flux;
|
|
|
300 |
}
|
3829 |
idir |
301 |
|
|
|
302 |
private function obtenirBooleen($var) {
|
|
|
303 |
switch ($var) {
|
|
|
304 |
case 'false' :
|
|
|
305 |
case 'null' :
|
|
|
306 |
case 'non' :
|
|
|
307 |
case 'no' :
|
|
|
308 |
return false;
|
|
|
309 |
default:
|
|
|
310 |
return boolval($var);
|
|
|
311 |
}
|
|
|
312 |
}
|
3958 |
julien |
313 |
|
|
|
314 |
private function getProtocoles(){
|
|
|
315 |
$protocoles = [];
|
|
|
316 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
|
|
317 |
$url = sprintf($this->service_del_url, 'protocoles');
|
|
|
318 |
$json = $this->getDao()->consulter($url);
|
|
|
319 |
|
|
|
320 |
if (empty($json)) {
|
|
|
321 |
$this->messages[] = "L'URI suivante est invalide : $url";
|
|
|
322 |
} else {
|
|
|
323 |
$protocoles= json_decode($json, true);
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
return $protocoles['resultats'];
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
private function getVotes($image){
|
|
|
330 |
$votes = [];
|
|
|
331 |
|
|
|
332 |
$id = $image['id_photo'];
|
|
|
333 |
|
|
|
334 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
|
|
335 |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes');
|
|
|
336 |
|
|
|
337 |
$json = $this->getDao()->consulter($url);
|
|
|
338 |
|
|
|
339 |
if (empty($json)) {
|
|
|
340 |
$this->messages[] = "L'URI suivante est invalide : $url";
|
|
|
341 |
} else {
|
|
|
342 |
foreach (json_decode($json, true)['resultats'] as $vote){
|
|
|
343 |
$votes[] = $vote;
|
|
|
344 |
}
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
return $votes;
|
3979 |
julien |
348 |
}
|
3958 |
julien |
349 |
|
|
|
350 |
public function sendVote(){
|
|
|
351 |
$data = json_decode(file_get_contents('php://input'), true);
|
|
|
352 |
|
|
|
353 |
$id = $data['idImage'];
|
|
|
354 |
$mode = $data['mode'];
|
|
|
355 |
$contenu = [
|
|
|
356 |
'utilisateur' => $data['user'],
|
|
|
357 |
'protocole' => $data['protocole'],
|
|
|
358 |
'valeur' => $data['vote']
|
|
|
359 |
];
|
|
|
360 |
|
|
|
361 |
switch ($mode){
|
|
|
362 |
case 'PUT':
|
|
|
363 |
case 'POST':
|
|
|
364 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
|
|
365 |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes/');
|
|
|
366 |
$this->send($url, $mode, $contenu);
|
|
|
367 |
break;
|
|
|
368 |
case 'DELETE':
|
|
|
369 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
|
|
370 |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes/'.$data['voteId']);
|
|
|
371 |
$this->send($url, $mode, $contenu);
|
|
|
372 |
break;
|
|
|
373 |
}
|
|
|
374 |
}
|
|
|
375 |
|
|
|
376 |
public function send($url, $mode, Array $donnees = array()){
|
|
|
377 |
$contenu = false;
|
3968 |
julien |
378 |
$this->user = $this->getUserFromCookie();
|
3958 |
julien |
379 |
$authorizationToken = $this->user['token'];
|
|
|
380 |
|
|
|
381 |
$json = json_encode($donnees);
|
|
|
382 |
$contexte = stream_context_create([
|
|
|
383 |
'http' => [
|
|
|
384 |
'method' => $mode,
|
|
|
385 |
'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
|
|
|
386 |
"Authorization: $authorizationToken\r\n",
|
|
|
387 |
'content' => http_build_query($donnees, null, '&')]
|
|
|
388 |
]);
|
|
|
389 |
$flux = fopen($url, 'r', false, $contexte);
|
|
|
390 |
if (!$flux) {
|
|
|
391 |
$e = "L'ouverture de l'url '{$url}' par la méthode HTTP {$mode} a échoué! avec les données {$json} et le token {$authorizationToken}";
|
|
|
392 |
trigger_error($e, E_USER_WARNING);
|
|
|
393 |
} else {
|
|
|
394 |
// Contenu actuel de $url
|
|
|
395 |
$contenu = stream_get_contents($flux);
|
|
|
396 |
|
|
|
397 |
fclose($flux);
|
|
|
398 |
}
|
|
|
399 |
return $contenu;
|
|
|
400 |
}
|
3961 |
julien |
401 |
|
|
|
402 |
public function formaterDate($item, $image){
|
|
|
403 |
$item['date_photo'] = $image['date_photo'] ?? $image['obs']['date_obs'];
|
|
|
404 |
$item['date_redige'] = strftime('%A %d %B %Y', strtotime($item['date_photo']));
|
|
|
405 |
$item['date'] = date_format(date_create($item['date_photo']),"d/m/Y");
|
|
|
406 |
$item['lien'] = sprintf($this->eflore_url_tpl, $image['obs']['nom_referentiel'], $image['obs']['nom_sel_nn']);
|
|
|
407 |
$image['url_photo'] = preg_replace('/,/', "", $image['url_photo']);
|
|
|
408 |
$item['url_tpl'] = preg_replace('/(O|XS|[SML]|X(?:[23]|)L|CR(?:|X2)S|C(?:|X)S)$/', '%s.jpg',$image['url_photo']);
|
|
|
409 |
return $item;
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
public function formaterTitre($item, $image, $auteur){
|
|
|
413 |
$item['titre'] = $image['obs']['nom_sel'].' [nn'.$image['obs']['nom_sel_nn'].'] par '.$auteur.' le '
|
|
|
414 |
.date_format(date_create($image['obs']['date_obs']),"d/m/Y").' - '.$image['obs']['localisation'];
|
|
|
415 |
|
|
|
416 |
$item['id_photo_formate'] = sprintf('%09d', $image['id_photo']);
|
|
|
417 |
$item['urlProfil'] = sprintf($this->config['photo']['tbProfilUrlTpl'], $image['utilisateur']['id_utilisateur'] );
|
|
|
418 |
return $item;
|
|
|
419 |
}
|
|
|
420 |
|
|
|
421 |
private function getImages($vignette, $extra, $limit, $id, $titre, $icone_rss, $utilise_fancybox, $fromEflore,
|
|
|
422 |
$tag, $widget, $champ_recherche){
|
|
|
423 |
if ($fromEflore){
|
|
|
424 |
$this->parametres['tag'] = $tag;
|
|
|
425 |
}
|
|
|
426 |
list($colonne, $ligne) = explode(',', $vignette);
|
|
|
427 |
$extra = (isset($extra) && $extra == 0) ? false : (!$this->config['photo']['extraActif'] ? false : ($colonne == 1 || $ligne == 1 ? false : true));
|
|
|
428 |
|
|
|
429 |
$max_photo = $colonne * $ligne;
|
|
|
430 |
if ( $extra && 2 == $colonne ) {
|
|
|
431 |
$max_photo = $max_photo - 1;
|
|
|
432 |
} elseif ( $extra && 2 < $colonne ) {
|
|
|
433 |
$max_photo = $max_photo - 3;
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
$limit = $limit < $max_photo ? $limit : $max_photo;
|
|
|
437 |
$this->parametres['limit'] = $limit;
|
|
|
438 |
$parametresTraites = $this->traiterParametres();
|
|
|
439 |
$this->flux_rss_url .= $parametresTraites;
|
|
|
440 |
$url = $this->service_images_url.(!empty($parametresTraites) ? $parametresTraites.'&' : '?');
|
|
|
441 |
$json = $this->getDao()->consulter($url);
|
|
|
442 |
if ($fromEflore) {
|
|
|
443 |
unset($this->parametres['tag']);
|
|
|
444 |
}
|
|
|
445 |
if (empty($json) || !strpos($json,'images') ) {
|
|
|
446 |
$this->messages[] = "L'URI suivante est invalide : $this->service_images_url.\n".
|
|
|
447 |
"Veuillez vérifier les paramêtres indiqués et la présence d'images associées.";
|
|
|
448 |
|
|
|
449 |
} else {
|
|
|
450 |
$tableau = json_decode($json, true);
|
3990 |
julien |
451 |
|
3961 |
julien |
452 |
if (empty($tableau['total']) || empty($tableau['images'])) {
|
|
|
453 |
$this->messages[] = 'Aucune photo ne correspond à vos critères';
|
|
|
454 |
} else {
|
3983 |
julien |
455 |
|
3961 |
julien |
456 |
$parametres_photo_suivante = $parametres_photo_precedente = $this->parametres;
|
3982 |
julien |
457 |
$start = $this->parametres['start'] ? : 0;
|
3961 |
julien |
458 |
$parametres_photo_suivante['start'] = $start + $limit;
|
|
|
459 |
$parametres_photo_precedente['start'] = 0 < $start - $limit ? $start - $limit : 0;
|
|
|
460 |
|
|
|
461 |
$widget['donnees']['total'] = $tableau['total'];
|
|
|
462 |
$widget['donnees']['id'] = $id;
|
|
|
463 |
$widget['donnees']['titre'] = $titre;
|
|
|
464 |
$widget['donnees']['flux_rss_url'] = $this->flux_rss_url;
|
|
|
465 |
$widget['donnees']['url_widget'] = $this->url_widget;
|
|
|
466 |
$widget['donnees']['url_widget_photos_suivantes'] = $this->url_widget.'?'.http_build_query($parametres_photo_suivante);
|
|
|
467 |
$widget['donnees']['url_widget_photos_precedente'] = $this->url_widget.'?'.http_build_query($parametres_photo_precedente);
|
|
|
468 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/css/');
|
|
|
469 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/photo/squelettes/js/');
|
|
|
470 |
$widget['donnees']['colonne'] = $colonne;
|
|
|
471 |
$widget['donnees']['ligne'] = $ligne;
|
|
|
472 |
$widget['donnees']['extra_actif'] = $extra;
|
|
|
473 |
$widget['donnees']['icone_rss'] = $icone_rss;
|
|
|
474 |
$widget['donnees']['champ_recherche'] = $champ_recherche;
|
|
|
475 |
$widget['donnees']['start'] = $start;
|
|
|
476 |
$widget['donnees']['limit'] = $limit;
|
|
|
477 |
$widget['donnees']['utilise_fancybox'] = $utilise_fancybox;
|
|
|
478 |
$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] === 'prod');
|
|
|
479 |
$widget['donnees']['filtres'] = $this->parametres;
|
|
|
480 |
|
|
|
481 |
$num = 0;
|
|
|
482 |
$galerie_id = md5(http_build_query($_GET));
|
|
|
483 |
$widget['donnees']['galerie_id'] = $galerie_id;
|
|
|
484 |
|
|
|
485 |
session_start();
|
|
|
486 |
$_SESSION[$galerie_id]['max_photo'] = $max_photo;
|
|
|
487 |
$_SESSION[$galerie_id]['start'] = $start;
|
|
|
488 |
|
|
|
489 |
foreach ($tableau['images'] as $key => $image) {
|
|
|
490 |
if ($key == $max_photo) {
|
|
|
491 |
break;
|
|
|
492 |
}
|
3990 |
julien |
493 |
// On vérifie si l'auteur de la photo est un utilisateur tela
|
|
|
494 |
$courriel = [$image['utilisateur']['mail_utilisateur']];
|
|
|
495 |
$auteurId = $this->recupererUtilisateursIdentite($courriel)[$courriel[0]]['id'];
|
|
|
496 |
$auteurId ? $isTelaUser = true : $isTelaUser = false;
|
3961 |
julien |
497 |
$auteurTruncatedEmail = $this->tronquerCourriel($image['utilisateur']['mail_utilisateur']);
|
3990 |
julien |
498 |
|
3961 |
julien |
499 |
$auteur = trim($image['utilisateur']['nom_utilisateur']) ? $image['utilisateur']['nom_utilisateur'] : $auteurTruncatedEmail;
|
|
|
500 |
|
|
|
501 |
$item = $image;
|
3970 |
julien |
502 |
|
3961 |
julien |
503 |
$item = $this->formaterDate($item, $image);
|
|
|
504 |
|
|
|
505 |
$item = $this->formaterTitre($item, $image, $auteur);
|
|
|
506 |
|
|
|
507 |
$item['tag_eflore'] = $tag;
|
3990 |
julien |
508 |
|
|
|
509 |
$item['is_auteur_tela'] = $isTelaUser;
|
3961 |
julien |
510 |
// Ajout aux items et si première photo à extra
|
|
|
511 |
if ($key == 0) {
|
|
|
512 |
$widget['donnees']['extra'] = $item;
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
$widget['donnees']['items'][$tag][$num++] = $item;
|
|
|
516 |
$url_galerie_popup = sprintf($item['url_tpl'],'O');
|
|
|
517 |
$image_size = getimagesize($url_galerie_popup);
|
|
|
518 |
$item['width'] = $image_size[0];
|
|
|
519 |
$item['height'] = $image_size[1];
|
3990 |
julien |
520 |
|
3961 |
julien |
521 |
// Récupération des votes pictoflora
|
|
|
522 |
$item['votes'] = $this->getVotes($item);
|
|
|
523 |
|
3983 |
julien |
524 |
// Récupération des tags pictoflora
|
|
|
525 |
$item['tags_pf'] = $this->getPfTags($item);
|
|
|
526 |
|
3961 |
julien |
527 |
$_SESSION[$galerie_id]['infos_images'][$url_galerie_popup] = $item;
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
$widget['squelette'] = 'photo';
|
|
|
531 |
}
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
return $widget;
|
|
|
535 |
}
|
3983 |
julien |
536 |
|
|
|
537 |
private function getPfTags($image){
|
|
|
538 |
$tags = [];
|
|
|
539 |
|
|
|
540 |
$id = $image['id_photo'];
|
|
|
541 |
|
|
|
542 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
|
|
543 |
$url = sprintf($this->service_del_url, 'mots-cles?image='.$id);
|
|
|
544 |
|
|
|
545 |
$json = $this->getDao()->consulter($url);
|
|
|
546 |
|
|
|
547 |
if (empty($json)) {
|
|
|
548 |
$this->messages[] = "L'URI suivante est invalide : $url";
|
|
|
549 |
} else {
|
|
|
550 |
foreach (json_decode($json, true)['resultats'] as $tag){
|
|
|
551 |
$tags[] = [
|
|
|
552 |
'id_mot_cle' => $tag['id_mot_cle'],
|
|
|
553 |
'mot_cle' => $tag['mot_cle']
|
|
|
554 |
];
|
|
|
555 |
}
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
return $tags;
|
|
|
559 |
}
|
3958 |
julien |
560 |
}
|
3839 |
idir |
561 |
?>
|