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