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;
|
3995 |
julien |
58 |
private $userCache = [];
|
|
|
59 |
|
580 |
jpm |
60 |
/**
|
|
|
61 |
* Méthode appelée par défaut pour charger ce widget.
|
|
|
62 |
*/
|
|
|
63 |
public function executer() {
|
|
|
64 |
$retour = null;
|
588 |
jpm |
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']);
|
580 |
jpm |
67 |
extract($this->parametres);
|
3958 |
julien |
68 |
|
580 |
jpm |
69 |
if (!isset($mode)) {
|
|
|
70 |
$mode = self::SERVICE_DEFAUT;
|
|
|
71 |
}
|
3829 |
idir |
72 |
$this->url_widget = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'photo');
|
583 |
jpm |
73 |
$this->eflore_url_tpl = $this->config['photo']['efloreUrlTpl'];
|
3823 |
idir |
74 |
$this->service_images_url = $this->config['photo']['celUrlImages'];
|
583 |
jpm |
75 |
$this->flux_rss_url = $this->config['photo']['fluxRssUrl'];
|
3630 |
idir |
76 |
|
580 |
jpm |
77 |
$cache_activation = $this->config['photo.cache']['activation'];
|
|
|
78 |
$cache_stockage = $this->config['photo.cache']['stockageDossier'];
|
3995 |
julien |
79 |
if (!is_dir($cache_stockage)) {
|
|
|
80 |
mkdir($cache_stockage, 0777, true);
|
|
|
81 |
}
|
580 |
jpm |
82 |
$ddv = $this->config['photo.cache']['dureeDeVie'];
|
|
|
83 |
$cache = new Cache($cache_stockage, $ddv, $cache_activation);
|
588 |
jpm |
84 |
$id_cache = 'photo-'.hash('adler32', print_r($this->parametres, true));
|
3630 |
idir |
85 |
$contenu = $cache->charger($id_cache);
|
3958 |
julien |
86 |
|
|
|
87 |
$this->user = $this->getUserFromCookie();
|
|
|
88 |
|
3630 |
idir |
89 |
if (!$contenu) {
|
580 |
jpm |
90 |
$methode = $this->traiterNomMethodeExecuter($mode);
|
3630 |
idir |
91 |
|
580 |
jpm |
92 |
if (method_exists($this, $methode)) {
|
|
|
93 |
$retour = $this->$methode();
|
3630 |
idir |
94 |
|
580 |
jpm |
95 |
} else {
|
|
|
96 |
$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
|
3630 |
idir |
97 |
|
580 |
jpm |
98 |
}
|
3630 |
idir |
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'];
|
3041 |
killian |
102 |
|
|
|
103 |
}
|
|
|
104 |
|
913 |
jpm |
105 |
$contenu = '';
|
3630 |
idir |
106 |
|
580 |
jpm |
107 |
if (is_null($retour)) {
|
3004 |
mathias |
108 |
$this->messages[] = 'Aucune image';
|
3630 |
idir |
109 |
|
580 |
jpm |
110 |
} else {
|
3630 |
idir |
111 |
|
913 |
jpm |
112 |
if (isset($retour['donnees'])) {
|
3630 |
idir |
113 |
$squelette = dirname(__FILE__) .self::DS. 'squelettes' .self::DS. $retour['squelette'].$this->suffixeLangue.'.tpl.html';
|
913 |
jpm |
114 |
$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
|
|
|
115 |
$cache->sauver($id_cache, $contenu);
|
3630 |
idir |
116 |
|
913 |
jpm |
117 |
} else {
|
|
|
118 |
$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
|
|
|
119 |
}
|
580 |
jpm |
120 |
}
|
|
|
121 |
}
|
588 |
jpm |
122 |
if (isset($_GET['callback'])) {
|
3829 |
idir |
123 |
$this->envoyerJsonp(['contenu' => $contenu]);
|
3630 |
idir |
124 |
|
587 |
jpm |
125 |
} else {
|
|
|
126 |
$this->envoyer($contenu);
|
|
|
127 |
}
|
3958 |
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 |
}
|
580 |
jpm |
135 |
}
|
3630 |
idir |
136 |
|
3829 |
idir |
137 |
// maintenir la retrocompatibilité avec l'ancien mode ajax
|
587 |
jpm |
138 |
private function executerAjax() {
|
3829 |
idir |
139 |
unset($this->parametres['mode']);
|
3630 |
idir |
140 |
|
3829 |
idir |
141 |
$chaineRequete = http_build_query($this->parametres);
|
|
|
142 |
$chaineRequete = $chaineRequete ? '?'.$chaineRequete : '';
|
|
|
143 |
$widget['donnees']['url_widget'] = $this->url_widget.$chaineRequete;
|
3630 |
idir |
144 |
|
3829 |
idir |
145 |
$id = '-'.(isset($this->parametres['id']) ? $this->parametres['id'] : '1');
|
|
|
146 |
$widget['donnees']['id'] = $id;
|
|
|
147 |
|
|
|
148 |
$widget['squelette'] = 'photo_retrocompatibilite_ajax';
|
|
|
149 |
|
587 |
jpm |
150 |
return $widget;
|
|
|
151 |
}
|
3630 |
idir |
152 |
|
1480 |
aurelien |
153 |
private function executerPopup() {
|
|
|
154 |
session_start();
|
3630 |
idir |
155 |
|
3958 |
julien |
156 |
$protocoles = $this->getProtocoles();
|
|
|
157 |
|
1495 |
aurelien |
158 |
$galerie_id = $_GET['galerie_id'];
|
1480 |
aurelien |
159 |
$widget['donnees']['url_image'] = $_GET['url_image'];
|
1495 |
aurelien |
160 |
$widget['donnees']['infos_images'] = $_SESSION[$galerie_id]['infos_images'];
|
3829 |
idir |
161 |
$widget['donnees']['url_widget'] = $this->url_widget;
|
1480 |
aurelien |
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/');
|
3630 |
idir |
164 |
$widget['donnees']['max_photo'] = $_SESSION[$galerie_id]['max_photo'];
|
3829 |
idir |
165 |
$widget['donnees']['start'] = $_SESSION[$galerie_id]['start'];
|
3823 |
idir |
166 |
$widget['donnees']['url_ws_regenerer_img'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_IMG_LIST) . '/regenerer-miniatures?ids-img=';
|
3630 |
idir |
167 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null;
|
3823 |
idir |
168 |
$widget['donnees']['url_base_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat/');
|
|
|
169 |
$widget['donnees']['formats_description'] = self::IMAGE_FORMATS;
|
3958 |
julien |
170 |
$widget['donnees']['protocoles'] = $protocoles;
|
3983 |
julien |
171 |
$widget['donnees']['del_url'] = sprintf($this->config['chemins']['baseURLServicesDelTpl'], '');
|
3985 |
julien |
172 |
$widget['donnees']['new_cel_url'] = sprintf($this->config['chemins']['baseURLServicesNewCelTpl'], '');
|
3958 |
julien |
173 |
|
|
|
174 |
if ($this->user){
|
|
|
175 |
$widget['donnees']['userId'] = $this->user['id'];
|
|
|
176 |
$widget['donnees']['token'] = $this->user['token'];
|
|
|
177 |
}
|
3630 |
idir |
178 |
|
3041 |
killian |
179 |
$widget['squelette'] = 'popup' . $this->suffixeLangue;
|
3958 |
julien |
180 |
|
1480 |
aurelien |
181 |
return $widget;
|
|
|
182 |
}
|
3630 |
idir |
183 |
|
1495 |
aurelien |
184 |
private function executerContact() {
|
|
|
185 |
session_start();
|
3630 |
idir |
186 |
|
3829 |
idir |
187 |
$widget['donnees']['url_widget'] = $this->url_widget;
|
1495 |
aurelien |
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'];
|
3630 |
idir |
192 |
$widget['donnees']['auteur'] = $_GET['auteur'];
|
|
|
193 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null;
|
|
|
194 |
|
3074 |
killian |
195 |
if (isset($_GET['lang']) && 'nl' === $_GET['lang']) {
|
3043 |
killian |
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'];
|
3630 |
idir |
198 |
|
3043 |
killian |
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'];
|
3630 |
idir |
202 |
|
3043 |
killian |
203 |
}
|
3630 |
idir |
204 |
|
1495 |
aurelien |
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/');
|
3044 |
mathias |
207 |
$widget['squelette'] = 'contact';
|
3630 |
idir |
208 |
|
1495 |
aurelien |
209 |
return $widget;
|
|
|
210 |
}
|
3961 |
julien |
211 |
|
580 |
jpm |
212 |
private function executerPhoto() {
|
|
|
213 |
$widget = null;
|
3995 |
julien |
214 |
session_start();
|
3630 |
idir |
215 |
|
3829 |
idir |
216 |
$this->parametres['start'] = $this->parametres['start'] ?? self::START_DEFAUT;
|
|
|
217 |
$this->parametres['limit'] = $this->parametres['limit'] ?? self::LIMIT_DEFAUT;
|
3995 |
julien |
218 |
$limit = $this->parametres['limit'];
|
3829 |
idir |
219 |
|
3823 |
idir |
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;
|
|
|
224 |
}
|
3961 |
julien |
225 |
|
879 |
jpm |
226 |
$id = '-'.(isset($id) ? $id : '1');
|
1480 |
aurelien |
227 |
$titre = isset($titre) ? htmlentities(rawurldecode($titre)) : '';
|
3823 |
idir |
228 |
|
1480 |
aurelien |
229 |
$icone_rss = (isset($_GET['rss']) && $_GET['rss'] != 1) ? false : true;
|
|
|
230 |
$utilise_fancybox = (isset($_GET['mode_zoom']) && $_GET['mode_zoom'] != 'fancybox') ? false : true;
|
3995 |
julien |
231 |
|
|
|
232 |
$champ_recherche = $champ_recherche ?? null;
|
3829 |
idir |
233 |
$champ_recherche = $champ_recherche ? $this->obtenirBooleen($champ_recherche) : ($this->config['photo']['champRecherche'] ? $this->obtenirBooleen($this->config['photo']['champRecherche']) : false) ;
|
3995 |
julien |
234 |
$extra = $extra ?? null;
|
|
|
235 |
|
3970 |
julien |
236 |
// Affichage mode e-flore avec le paramètre mode_eflore
|
|
|
237 |
if ($_GET['mode_eflore']) {
|
|
|
238 |
$champ_recherche = false;
|
3995 |
julien |
239 |
$vignette = '5,2';
|
|
|
240 |
|
3961 |
julien |
241 |
$tags = [
|
|
|
242 |
'fleur',
|
|
|
243 |
'feuille',
|
|
|
244 |
'fruit',
|
|
|
245 |
'ecorce',
|
|
|
246 |
'port',
|
|
|
247 |
'rameau',
|
|
|
248 |
];
|
3995 |
julien |
249 |
|
3961 |
julien |
250 |
foreach ($tags as $tag) {
|
3995 |
julien |
251 |
$widget = $this->getImages($vignette, $extra, $limit, $id, $titre, $icone_rss, $utilise_fancybox,true, $tag, $widget, false);
|
|
|
252 |
$widget['donnees']['champ_recherche'] = false;
|
580 |
jpm |
253 |
}
|
3961 |
julien |
254 |
$widget['donnees']['tagToDisplay'] = 'fleur';
|
|
|
255 |
} else {
|
3995 |
julien |
256 |
$widget = $this->getImages($vignette, $extra, $limit, $id, $titre, $icone_rss, $utilise_fancybox, false, 'non_eflore', $widget, $champ_recherche);
|
|
|
257 |
|
3961 |
julien |
258 |
$widget['donnees']['champ_recherche'] = $champ_recherche;
|
3995 |
julien |
259 |
|
580 |
jpm |
260 |
}
|
3961 |
julien |
261 |
|
580 |
jpm |
262 |
return $widget;
|
|
|
263 |
}
|
3630 |
idir |
264 |
|
711 |
delphine |
265 |
private function traiterParametres() {
|
|
|
266 |
$parametres_flux = '?';
|
3829 |
idir |
267 |
$criteres = [
|
|
|
268 |
'taxon',
|
|
|
269 |
'referentiel',
|
|
|
270 |
'date_deb',
|
|
|
271 |
'date_fin',
|
|
|
272 |
'commune',
|
|
|
273 |
'dept',
|
|
|
274 |
'pays',
|
|
|
275 |
'auteur',
|
|
|
276 |
'programme',
|
|
|
277 |
'tag',
|
3981 |
julien |
278 |
'standard',
|
3829 |
idir |
279 |
'recherche',
|
|
|
280 |
'date',
|
|
|
281 |
'motcle',
|
|
|
282 |
'projet',
|
|
|
283 |
'num_taxon',
|
|
|
284 |
'num_nom',
|
|
|
285 |
'start',
|
3970 |
julien |
286 |
'limit',
|
3981 |
julien |
287 |
'mode_eflore',
|
|
|
288 |
'famille'
|
3829 |
idir |
289 |
];
|
3630 |
idir |
290 |
|
711 |
delphine |
291 |
foreach($this->parametres as $nom_critere => $valeur_critere) {
|
741 |
delphine |
292 |
if (in_array($nom_critere, $criteres)) {
|
|
|
293 |
$valeur_critere = str_replace(' ', '%20', $valeur_critere);
|
|
|
294 |
$parametres_flux .= $nom_critere.'='.$valeur_critere.'&';
|
3630 |
idir |
295 |
|
711 |
delphine |
296 |
}
|
|
|
297 |
}
|
3630 |
idir |
298 |
if ($parametres_flux === '?') {
|
711 |
delphine |
299 |
$parametres_flux = '';
|
3630 |
idir |
300 |
|
711 |
delphine |
301 |
} else {
|
|
|
302 |
$parametres_flux = rtrim($parametres_flux, '&');
|
3630 |
idir |
303 |
|
711 |
delphine |
304 |
}
|
3630 |
idir |
305 |
|
711 |
delphine |
306 |
return $parametres_flux;
|
|
|
307 |
}
|
3829 |
idir |
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 |
}
|
3958 |
julien |
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;
|
3979 |
julien |
355 |
}
|
3958 |
julien |
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;
|
3968 |
julien |
385 |
$this->user = $this->getUserFromCookie();
|
3958 |
julien |
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 |
}
|
3961 |
julien |
408 |
|
3995 |
julien |
409 |
public function formaterDates($item, $image){
|
3961 |
julien |
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);
|
3995 |
julien |
434 |
|
|
|
435 |
$extra = !($extra === 0) && (($this->config['photo']['extraActif'] && (($colonne == 1 || $ligne == 1 ? false : true))));
|
|
|
436 |
|
3961 |
julien |
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 |
}
|
3995 |
julien |
443 |
|
3961 |
julien |
444 |
$limit = $limit < $max_photo ? $limit : $max_photo;
|
|
|
445 |
$this->parametres['limit'] = $limit;
|
3995 |
julien |
446 |
|
3961 |
julien |
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);
|
3995 |
julien |
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;
|
3961 |
julien |
457 |
}
|
3990 |
julien |
458 |
|
3995 |
julien |
459 |
$tableau = json_decode($json, true);
|
3983 |
julien |
460 |
|
3995 |
julien |
461 |
if (empty($tableau['total']) || empty($tableau['images'])) {
|
|
|
462 |
$this->logError('Aucune photo ne correspond à vos critères');
|
|
|
463 |
return $widget;
|
|
|
464 |
}
|
3990 |
julien |
465 |
|
3995 |
julien |
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;
|
3990 |
julien |
470 |
|
3995 |
julien |
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;
|
3990 |
julien |
490 |
|
3995 |
julien |
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;
|
3961 |
julien |
504 |
}
|
3995 |
julien |
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;
|
3961 |
julien |
545 |
}
|
3995 |
julien |
546 |
|
|
|
547 |
if ($fromEflore) {
|
|
|
548 |
unset($this->parametres['tag']);
|
|
|
549 |
}
|
|
|
550 |
$widget['squelette'] = 'photo';
|
3961 |
julien |
551 |
|
|
|
552 |
return $widget;
|
|
|
553 |
}
|
3983 |
julien |
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 |
}
|
3958 |
julien |
578 |
}
|
3839 |
idir |
579 |
?>
|