| Line 49... |
Line 49... |
| 49 |
private $service_images_url = null;
|
49 |
private $service_images_url = null;
|
| 50 |
private $flux_rss_url = null;
|
50 |
private $flux_rss_url = null;
|
| Line 51... |
Line 51... |
| 51 |
|
51 |
|
| 52 |
// Suffixe de template pour la langue (vide par défaut, correspond à "fr" au français)
|
52 |
// Suffixe de template pour la langue (vide par défaut, correspond à "fr" au français)
|
| 53 |
private $suffixeLangue = '';
|
53 |
private $suffixeLangue = '';
|
| - |
|
54 |
|
| - |
|
55 |
private $user = null;
|
| - |
|
56 |
|
| 54 |
|
57 |
private $service_del_url = null;
|
| 55 |
/**
|
58 |
/**
|
| 56 |
* Méthode appelée par défaut pour charger ce widget.
|
59 |
* Méthode appelée par défaut pour charger ce widget.
|
| 57 |
*/
|
60 |
*/
|
| 58 |
public function executer() {
|
61 |
public function executer() {
|
| 59 |
$retour = null;
|
62 |
$retour = null;
|
| 60 |
// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
|
63 |
// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
|
| 61 |
unset($this->parametres['callback']);
|
64 |
unset($this->parametres['callback']);
|
| 62 |
extract($this->parametres);
|
65 |
extract($this->parametres);
|
| 63 |
|
66 |
|
| 64 |
if (!isset($mode)) {
|
67 |
if (!isset($mode)) {
|
| 65 |
$mode = self::SERVICE_DEFAUT;
|
68 |
$mode = self::SERVICE_DEFAUT;
|
| 66 |
}
|
69 |
}
|
| 67 |
$this->url_widget = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'photo');
|
70 |
$this->url_widget = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'photo');
|
| Line 73... |
Line 76... |
| 73 |
$cache_stockage = $this->config['photo.cache']['stockageDossier'];
|
76 |
$cache_stockage = $this->config['photo.cache']['stockageDossier'];
|
| 74 |
$ddv = $this->config['photo.cache']['dureeDeVie'];
|
77 |
$ddv = $this->config['photo.cache']['dureeDeVie'];
|
| 75 |
$cache = new Cache($cache_stockage, $ddv, $cache_activation);
|
78 |
$cache = new Cache($cache_stockage, $ddv, $cache_activation);
|
| 76 |
$id_cache = 'photo-'.hash('adler32', print_r($this->parametres, true));
|
79 |
$id_cache = 'photo-'.hash('adler32', print_r($this->parametres, true));
|
| 77 |
$contenu = $cache->charger($id_cache);
|
80 |
$contenu = $cache->charger($id_cache);
|
| 78 |
|
81 |
|
| - |
|
82 |
$this->user = $this->getUserFromCookie();
|
| - |
|
83 |
|
| 79 |
if (!$contenu) {
|
84 |
if (!$contenu) {
|
| 80 |
$methode = $this->traiterNomMethodeExecuter($mode);
|
85 |
$methode = $this->traiterNomMethodeExecuter($mode);
|
| Line 81... |
Line 86... |
| 81 |
|
86 |
|
| 82 |
if (method_exists($this, $methode)) {
|
87 |
if (method_exists($this, $methode)) {
|
| Line 115... |
Line 120... |
| 115 |
|
120 |
|
| 116 |
} else {
|
121 |
} else {
|
| Line 117... |
Line 122... |
| 117 |
$this->envoyer($contenu);
|
122 |
$this->envoyer($contenu);
|
| - |
|
123 |
|
| - |
|
124 |
}
|
| - |
|
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();
|
| 118 |
|
130 |
}
|
| Line 119... |
Line 131... |
| 119 |
}
|
131 |
}
|
| 120 |
}
|
132 |
}
|
| 121 |
|
133 |
|
| Line 136... |
Line 148... |
| 136 |
}
|
148 |
}
|
| Line 137... |
Line 149... |
| 137 |
|
149 |
|
| 138 |
private function executerPopup() {
|
150 |
private function executerPopup() {
|
| Line -... |
Line 151... |
| - |
|
151 |
session_start();
|
| - |
|
152 |
|
| 139 |
session_start();
|
153 |
$protocoles = $this->getProtocoles();
|
| 140 |
|
154 |
|
| 141 |
$galerie_id = $_GET['galerie_id'];
|
155 |
$galerie_id = $_GET['galerie_id'];
|
| 142 |
$widget['donnees']['url_image'] = $_GET['url_image'];
|
156 |
$widget['donnees']['url_image'] = $_GET['url_image'];
|
| 143 |
$widget['donnees']['infos_images'] = $_SESSION[$galerie_id]['infos_images'];
|
157 |
$widget['donnees']['infos_images'] = $_SESSION[$galerie_id]['infos_images'];
|
| Line 148... |
Line 162... |
| 148 |
$widget['donnees']['start'] = $_SESSION[$galerie_id]['start'];
|
162 |
$widget['donnees']['start'] = $_SESSION[$galerie_id]['start'];
|
| 149 |
$widget['donnees']['url_ws_regenerer_img'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_IMG_LIST) . '/regenerer-miniatures?ids-img=';
|
163 |
$widget['donnees']['url_ws_regenerer_img'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_IMG_LIST) . '/regenerer-miniatures?ids-img=';
|
| 150 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null;
|
164 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null;
|
| 151 |
$widget['donnees']['url_base_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat/');
|
165 |
$widget['donnees']['url_base_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat/');
|
| 152 |
$widget['donnees']['formats_description'] = self::IMAGE_FORMATS;
|
166 |
$widget['donnees']['formats_description'] = self::IMAGE_FORMATS;
|
| - |
|
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 |
}
|
| Line 153... |
Line 173... |
| 153 |
|
173 |
|
| 154 |
$widget['squelette'] = 'popup' . $this->suffixeLangue;
|
174 |
$widget['squelette'] = 'popup' . $this->suffixeLangue;
|
| 155 |
|
175 |
|
| 156 |
return $widget;
|
176 |
return $widget;
|
| Line 157... |
Line 177... |
| 157 |
}
|
177 |
}
|
| 158 |
|
178 |
|
| Line 266... |
Line 286... |
| 266 |
|
286 |
|
| 267 |
foreach ($tableau['images'] as $key => $image) {
|
287 |
foreach ($tableau['images'] as $key => $image) {
|
| 268 |
if ($key == $max_photo) {
|
288 |
if ($key == $max_photo) {
|
| 269 |
break;
|
289 |
break;
|
| - |
|
290 |
}
|
| - |
|
291 |
$auteurTruncatedEmail = $this->tronquerCourriel($image['utilisateur']['mail_utilisateur']);
|
| - |
|
292 |
$auteur = trim($image['utilisateur']['nom_utilisateur']) ? $image['utilisateur']['nom_utilisateur'] : $auteurTruncatedEmail;
|
| 270 |
}
|
293 |
|
| 271 |
$item = $image;
|
294 |
$item = $image;
|
| 272 |
// Formatage date
|
295 |
// Formatage date
|
| 273 |
$item['date_photo'] = $image['date_photo'] ?? $image['obs']['date_obs'];
|
296 |
$item['date_photo'] = $image['date_photo'] ?? $image['obs']['date_obs'];
|
| 274 |
$item['date_redige'] = strftime('%A %d %B %Y', $item['date_photo']);
|
297 |
$item['date_redige'] = strftime('%A %d %B %Y', strtotime($item['date_photo']));
|
| 275 |
$item['date'] = date_format(date_create($item['date_photo']),"d/m/Y");
|
298 |
$item['date'] = date_format(date_create($item['date_photo']),"d/m/Y");
|
| 276 |
$item['lien'] = sprintf($this->eflore_url_tpl, $image['obs']['nom_referentiel'], $image['obs']['nom_sel_nn']);
|
299 |
$item['lien'] = sprintf($this->eflore_url_tpl, $image['obs']['nom_referentiel'], $image['obs']['nom_sel_nn']);
|
| 277 |
$image['url_photo'] = preg_replace('/,/', "", $image['url_photo']);
|
300 |
$image['url_photo'] = preg_replace('/,/', "", $image['url_photo']);
|
| 278 |
$item['url_tpl'] = preg_replace('/(O|XS|[SML]|X(?:[23]|)L|CR(?:|X2)S|C(?:|X)S)$/', '%s.jpg',$image['url_photo']);
|
301 |
$item['url_tpl'] = preg_replace('/(O|XS|[SML]|X(?:[23]|)L|CR(?:|X2)S|C(?:|X)S)$/', '%s.jpg',$image['url_photo']);
|
| - |
|
302 |
// Formatage titre
|
| 279 |
// Formatage titre
|
303 |
|
| - |
|
304 |
$item['titre'] = $image['obs']['nom_sel'].' [nn'.$image['obs']['nom_sel_nn'].'] par '.$auteur.' le '
|
| - |
|
305 |
.date_format(date_create($image['obs']['date_obs']),"d/m/Y").' - '.$image['obs']['localisation'];
|
| 280 |
$item['titre'] = $image['obs']['nom_sel'].' [nn'.$image['obs']['nom_sel_nn'].'] par '.$image['utilisateur']['nom_utilisateur'].' le '.date_format(date_create($image['obs']['date_obs']),"d/m/Y").' - '.$image['obs']['localisation'];
|
306 |
|
| 281 |
$item['id_photo_formate'] = sprintf('%09d', $image['id_photo']);
|
307 |
$item['id_photo_formate'] = sprintf('%09d', $image['id_photo']);
|
| 282 |
$item['urlProfil'] = sprintf($this->config['photo']['tbProfilUrlTpl'], $image['utilisateur']['id_utilisateur'] );
|
308 |
$item['urlProfil'] = sprintf($this->config['photo']['tbProfilUrlTpl'], $image['utilisateur']['id_utilisateur'] );
|
| 283 |
// Ajout aux items et si première photo à extra
|
309 |
// Ajout aux items et si première photo à extra
|
| 284 |
if ($key == 0) {
|
310 |
if ($key == 0) {
|
| Line 289... |
Line 315... |
| 289 |
$widget['donnees']['items'][$num++] = $item;
|
315 |
$widget['donnees']['items'][$num++] = $item;
|
| 290 |
$url_galerie_popup = sprintf($item['url_tpl'],'O');
|
316 |
$url_galerie_popup = sprintf($item['url_tpl'],'O');
|
| 291 |
$image_size = getimagesize($url_galerie_popup);
|
317 |
$image_size = getimagesize($url_galerie_popup);
|
| 292 |
$item['width'] = $image_size[0];
|
318 |
$item['width'] = $image_size[0];
|
| 293 |
$item['height'] = $image_size[1];
|
319 |
$item['height'] = $image_size[1];
|
| - |
|
320 |
|
| - |
|
321 |
// Récupération des votes pictoflora
|
| - |
|
322 |
$item['votes'] = $this->getVotes($item);
|
| Line 294... |
Line 323... |
| 294 |
|
323 |
|
| 295 |
$_SESSION[$galerie_id]['infos_images'][$url_galerie_popup] = $item;
|
324 |
$_SESSION[$galerie_id]['infos_images'][$url_galerie_popup] = $item;
|
| Line 296... |
Line 325... |
| 296 |
}
|
325 |
}
|
| Line 355... |
Line 384... |
| 355 |
return false;
|
384 |
return false;
|
| 356 |
default:
|
385 |
default:
|
| 357 |
return boolval($var);
|
386 |
return boolval($var);
|
| 358 |
}
|
387 |
}
|
| 359 |
}
|
388 |
}
|
| - |
|
389 |
|
| - |
|
390 |
private function getProtocoles(){
|
| - |
|
391 |
$protocoles = [];
|
| - |
|
392 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
| - |
|
393 |
$url = sprintf($this->service_del_url, 'protocoles');
|
| - |
|
394 |
$json = $this->getDao()->consulter($url);
|
| - |
|
395 |
|
| - |
|
396 |
if (empty($json)) {
|
| - |
|
397 |
$this->messages[] = "L'URI suivante est invalide : $url";
|
| - |
|
398 |
} else {
|
| - |
|
399 |
$protocoles= json_decode($json, true);
|
| - |
|
400 |
}
|
| - |
|
401 |
|
| - |
|
402 |
return $protocoles['resultats'];
|
| - |
|
403 |
}
|
| - |
|
404 |
|
| - |
|
405 |
private function getVotes($image){
|
| - |
|
406 |
$votes = [];
|
| - |
|
407 |
|
| - |
|
408 |
$id = $image['id_photo'];
|
| - |
|
409 |
|
| - |
|
410 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
| - |
|
411 |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes');
|
| - |
|
412 |
|
| - |
|
413 |
$json = $this->getDao()->consulter($url);
|
| - |
|
414 |
|
| - |
|
415 |
if (empty($json)) {
|
| - |
|
416 |
$this->messages[] = "L'URI suivante est invalide : $url";
|
| - |
|
417 |
} else {
|
| - |
|
418 |
foreach (json_decode($json, true)['resultats'] as $vote){
|
| - |
|
419 |
$votes[] = $vote;
|
| - |
|
420 |
}
|
| - |
|
421 |
}
|
| - |
|
422 |
|
| - |
|
423 |
return $votes;
|
| - |
|
424 |
}
|
| - |
|
425 |
|
| - |
|
426 |
public function sendVote(){
|
| - |
|
427 |
$data = json_decode(file_get_contents('php://input'), true);
|
| - |
|
428 |
|
| - |
|
429 |
$id = $data['idImage'];
|
| - |
|
430 |
$mode = $data['mode'];
|
| - |
|
431 |
$contenu = [
|
| - |
|
432 |
'utilisateur' => $data['user'],
|
| - |
|
433 |
'protocole' => $data['protocole'],
|
| - |
|
434 |
'valeur' => $data['vote']
|
| - |
|
435 |
];
|
| - |
|
436 |
|
| - |
|
437 |
switch ($mode){
|
| - |
|
438 |
case 'PUT':
|
| - |
|
439 |
case 'POST':
|
| - |
|
440 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
| - |
|
441 |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes/');
|
| - |
|
442 |
$this->send($url, $mode, $contenu);
|
| - |
|
443 |
break;
|
| - |
|
444 |
case 'DELETE':
|
| - |
|
445 |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl'];
|
| - |
|
446 |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes/'.$data['voteId']);
|
| - |
|
447 |
$this->send($url, $mode, $contenu);
|
| - |
|
448 |
break;
|
| - |
|
449 |
}
|
| - |
|
450 |
}
|
| - |
|
451 |
|
| - |
|
452 |
public function send($url, $mode, Array $donnees = array()){
|
| - |
|
453 |
$contenu = false;
|
| - |
|
454 |
$authorizationToken = $this->user['token'];
|
| - |
|
455 |
|
| - |
|
456 |
$json = json_encode($donnees);
|
| - |
|
457 |
$contexte = stream_context_create([
|
| - |
|
458 |
'http' => [
|
| - |
|
459 |
'method' => $mode,
|
| - |
|
460 |
'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
|
| - |
|
461 |
"Authorization: $authorizationToken\r\n",
|
| - |
|
462 |
'content' => http_build_query($donnees, null, '&')]
|
| - |
|
463 |
]);
|
| - |
|
464 |
|
| - |
|
465 |
$flux = fopen($url, 'r', false, $contexte);
|
| - |
|
466 |
if (!$flux) {
|
| - |
|
467 |
$e = "L'ouverture de l'url '{$url}' par la méthode HTTP {$mode} a échoué! avec les données {$json} et le token {$authorizationToken}";
|
| - |
|
468 |
trigger_error($e, E_USER_WARNING);
|
| - |
|
469 |
} else {
|
| - |
|
470 |
// Contenu actuel de $url
|
| - |
|
471 |
$contenu = stream_get_contents($flux);
|
| - |
|
472 |
|
| - |
|
473 |
fclose($flux);
|
| - |
|
474 |
}
|
| - |
|
475 |
return $contenu;
|
| - |
|
476 |
}
|
| 360 |
}
|
477 |
}
|
| 361 |
?>
|
478 |
?>
|