51,7 → 51,10 |
|
// Suffixe de template pour la langue (vide par défaut, correspond à "fr" au français) |
private $suffixeLangue = ''; |
|
|
private $user = null; |
|
private $service_del_url = null; |
/** |
* Méthode appelée par défaut pour charger ce widget. |
*/ |
60,7 → 63,7 |
// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback |
unset($this->parametres['callback']); |
extract($this->parametres); |
|
|
if (!isset($mode)) { |
$mode = self::SERVICE_DEFAUT; |
} |
75,7 → 78,9 |
$cache = new Cache($cache_stockage, $ddv, $cache_activation); |
$id_cache = 'photo-'.hash('adler32', print_r($this->parametres, true)); |
$contenu = $cache->charger($id_cache); |
|
|
$this->user = $this->getUserFromCookie(); |
|
if (!$contenu) { |
$methode = $this->traiterNomMethodeExecuter($mode); |
|
117,6 → 122,13 |
$this->envoyer($contenu); |
|
} |
|
// POur l'envoi du vote vers PF |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
if (isset($_GET['action']) && $_GET['action'] === 'send_pf_vote') { |
$this->sendVote(); |
} |
} |
} |
|
// maintenir la retrocompatibilité avec l'ancien mode ajax |
138,6 → 150,8 |
private function executerPopup() { |
session_start(); |
|
$protocoles = $this->getProtocoles(); |
|
$galerie_id = $_GET['galerie_id']; |
$widget['donnees']['url_image'] = $_GET['url_image']; |
$widget['donnees']['infos_images'] = $_SESSION[$galerie_id]['infos_images']; |
150,9 → 164,15 |
$widget['donnees']['popup_url'] = isset( $_GET['popup_url'] ) ? $_GET['popup_url'] : null; |
$widget['donnees']['url_base_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat/'); |
$widget['donnees']['formats_description'] = self::IMAGE_FORMATS; |
$widget['donnees']['protocoles'] = $protocoles; |
|
if ($this->user){ |
$widget['donnees']['userId'] = $this->user['id']; |
$widget['donnees']['token'] = $this->user['token']; |
} |
|
$widget['squelette'] = 'popup' . $this->suffixeLangue; |
|
|
return $widget; |
} |
|
268,16 → 288,22 |
if ($key == $max_photo) { |
break; |
} |
$auteurTruncatedEmail = $this->tronquerCourriel($image['utilisateur']['mail_utilisateur']); |
$auteur = trim($image['utilisateur']['nom_utilisateur']) ? $image['utilisateur']['nom_utilisateur'] : $auteurTruncatedEmail; |
|
$item = $image; |
// Formatage date |
$item['date_photo'] = $image['date_photo'] ?? $image['obs']['date_obs']; |
$item['date_redige'] = strftime('%A %d %B %Y', $item['date_photo']); |
$item['date_redige'] = strftime('%A %d %B %Y', strtotime($item['date_photo'])); |
$item['date'] = date_format(date_create($item['date_photo']),"d/m/Y"); |
$item['lien'] = sprintf($this->eflore_url_tpl, $image['obs']['nom_referentiel'], $image['obs']['nom_sel_nn']); |
$image['url_photo'] = preg_replace('/,/', "", $image['url_photo']); |
$item['url_tpl'] = preg_replace('/(O|XS|[SML]|X(?:[23]|)L|CR(?:|X2)S|C(?:|X)S)$/', '%s.jpg',$image['url_photo']); |
// Formatage titre |
$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']; |
|
$item['titre'] = $image['obs']['nom_sel'].' [nn'.$image['obs']['nom_sel_nn'].'] par '.$auteur.' le ' |
.date_format(date_create($image['obs']['date_obs']),"d/m/Y").' - '.$image['obs']['localisation']; |
|
$item['id_photo_formate'] = sprintf('%09d', $image['id_photo']); |
$item['urlProfil'] = sprintf($this->config['photo']['tbProfilUrlTpl'], $image['utilisateur']['id_utilisateur'] ); |
// Ajout aux items et si première photo à extra |
291,6 → 317,9 |
$image_size = getimagesize($url_galerie_popup); |
$item['width'] = $image_size[0]; |
$item['height'] = $image_size[1]; |
|
// Récupération des votes pictoflora |
$item['votes'] = $this->getVotes($item); |
|
$_SESSION[$galerie_id]['infos_images'][$url_galerie_popup] = $item; |
} |
357,5 → 386,93 |
return boolval($var); |
} |
} |
|
private function getProtocoles(){ |
$protocoles = []; |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl']; |
$url = sprintf($this->service_del_url, 'protocoles'); |
$json = $this->getDao()->consulter($url); |
|
if (empty($json)) { |
$this->messages[] = "L'URI suivante est invalide : $url"; |
} else { |
$protocoles= json_decode($json, true); |
} |
|
return $protocoles['resultats']; |
} |
|
private function getVotes($image){ |
$votes = []; |
|
$id = $image['id_photo']; |
|
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl']; |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes'); |
|
$json = $this->getDao()->consulter($url); |
|
if (empty($json)) { |
$this->messages[] = "L'URI suivante est invalide : $url"; |
} else { |
foreach (json_decode($json, true)['resultats'] as $vote){ |
$votes[] = $vote; |
} |
} |
|
return $votes; |
} |
|
public function sendVote(){ |
$data = json_decode(file_get_contents('php://input'), true); |
|
$id = $data['idImage']; |
$mode = $data['mode']; |
$contenu = [ |
'utilisateur' => $data['user'], |
'protocole' => $data['protocole'], |
'valeur' => $data['vote'] |
]; |
|
switch ($mode){ |
case 'PUT': |
case 'POST': |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl']; |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes/'); |
$this->send($url, $mode, $contenu); |
break; |
case 'DELETE': |
$this->service_del_url = $this->config['chemins']['baseURLServicesDelTpl']; |
$url = sprintf($this->service_del_url, 'images/'.$id.'/votes/'.$data['voteId']); |
$this->send($url, $mode, $contenu); |
break; |
} |
} |
|
public function send($url, $mode, Array $donnees = array()){ |
$contenu = false; |
$authorizationToken = $this->user['token']; |
|
$json = json_encode($donnees); |
$contexte = stream_context_create([ |
'http' => [ |
'method' => $mode, |
'header' => "Content-type: application/x-www-form-urlencoded\r\n" . |
"Authorization: $authorizationToken\r\n", |
'content' => http_build_query($donnees, null, '&')] |
]); |
|
$flux = fopen($url, 'r', false, $contexte); |
if (!$flux) { |
$e = "L'ouverture de l'url '{$url}' par la méthode HTTP {$mode} a échoué! avec les données {$json} et le token {$authorizationToken}"; |
trigger_error($e, E_USER_WARNING); |
} else { |
// Contenu actuel de $url |
$contenu = stream_get_contents($flux); |
|
fclose($flux); |
} |
return $contenu; |
} |
} |
?> |