2207 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
class Telechargement extends WidgetCommun {
|
2487 |
jpm |
4 |
|
|
|
5 |
private $description_url = null;
|
2207 |
aurelien |
6 |
private $infos_images_url = null;
|
|
|
7 |
private $telechargement_url = null;
|
2487 |
jpm |
8 |
|
2207 |
aurelien |
9 |
private $id_image = null;
|
2487 |
jpm |
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Méthode appelée par défaut pour charger ce widget.
|
|
|
13 |
*/
|
2207 |
aurelien |
14 |
public function executer() {
|
2487 |
jpm |
15 |
if (!isset($_GET['id_image']) || !is_numeric($_GET['id_image'])) {
|
|
|
16 |
$this->messages[] = "Ce widget nécéssite un identifiant d'image.";
|
2207 |
aurelien |
17 |
} else {
|
|
|
18 |
$this->id_image = $_GET['id_image'];
|
2487 |
jpm |
19 |
}
|
|
|
20 |
|
|
|
21 |
if (!empty($this->messages)) {
|
|
|
22 |
$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
|
|
|
23 |
} else {
|
2207 |
aurelien |
24 |
$donnees = $this->obtenirDescriptionFormats();
|
|
|
25 |
$squelette = dirname(__FILE__).'/squelettes'.'/telechargement.tpl.html';
|
|
|
26 |
$donnees['informations_image'] = $this->obtenirInformationsImages();
|
2233 |
aurelien |
27 |
$donnees['nom_original_fmt'] = $this->formaterNomOriginal($donnees['informations_image']);
|
2207 |
aurelien |
28 |
$donnees['resolution_originale'] = $this->formaterResolutionOriginale($donnees['informations_image']);
|
|
|
29 |
$donnees['auteur_fmt'] = $this->formaterAuteur($donnees['informations_image']);
|
|
|
30 |
$donnees['attribution'] = $this->formaterAttribution($donnees['informations_image']);
|
|
|
31 |
$donnees['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
|
2216 |
aurelien |
32 |
$donnees['date_televersement'] = $this->formaterDateTeleversement($donnees['informations_image']);
|
2487 |
jpm |
33 |
$donnees['url_image_exemple'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat').'/'.$this->id_image.'?methode=afficher&format=CS';
|
2207 |
aurelien |
34 |
$donnees['url_image_originale'] = sprintf($this->config['chemins']['celImgUrlTpl'], str_pad($this->id_image, 9, "0", STR_PAD_LEFT).'O');
|
2487 |
jpm |
35 |
$donnees['base_url_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat').'/'.$this->id_image.'?methode=telecharger&format=%s';
|
2848 |
mathias |
36 |
$donnees['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
|
|
|
37 |
|
2207 |
aurelien |
38 |
$contenu = $this->traiterSquelettePhp($squelette, $donnees);
|
|
|
39 |
}
|
2487 |
jpm |
40 |
$this->envoyer($contenu);
|
2207 |
aurelien |
41 |
}
|
2487 |
jpm |
42 |
|
2233 |
aurelien |
43 |
private function formaterNomOriginal($infos_images) {
|
2487 |
jpm |
44 |
$nom_original = 'Inconnu.jpg';
|
2233 |
aurelien |
45 |
if(isset($infos_images['nom_original'])) {
|
|
|
46 |
$nom_original = $infos_images['nom_original'].' ';
|
|
|
47 |
}
|
|
|
48 |
return $nom_original;
|
|
|
49 |
}
|
2487 |
jpm |
50 |
|
2207 |
aurelien |
51 |
private function formaterAttribution($infos_images) {
|
3151 |
delphine |
52 |
$attr = $this->formaterAuteur($infos_images).' [CC BY-SA 2.0 FR], via Tela Botanica';
|
2207 |
aurelien |
53 |
return $attr;
|
|
|
54 |
}
|
2487 |
jpm |
55 |
|
2207 |
aurelien |
56 |
private function formaterAuteur($infos_images) {
|
2487 |
jpm |
57 |
$auteur_fmt = '';
|
3806 |
delphine |
58 |
if (isset($infos_images['pseudo_utilisateur'])) {
|
|
|
59 |
$auteur_fmt .= $infos_images['pseudo_utilisateur'].' ';
|
2207 |
aurelien |
60 |
}
|
2487 |
jpm |
61 |
|
3806 |
delphine |
62 |
|
2487 |
jpm |
63 |
if (trim($auteur_fmt) == '') {
|
2207 |
aurelien |
64 |
$auteur_fmt = 'Auteur inconnu';
|
|
|
65 |
}
|
2487 |
jpm |
66 |
|
2207 |
aurelien |
67 |
return trim($auteur_fmt);
|
|
|
68 |
}
|
2487 |
jpm |
69 |
|
2207 |
aurelien |
70 |
private function formaterResolutionOriginale($infos_image) {
|
2487 |
jpm |
71 |
$res_fmt = '';
|
|
|
72 |
if (isset($infos_image['hauteur']) && isset($infos_image['largeur'])) {
|
|
|
73 |
$res_fmt = $infos_image['hauteur'].' x '.$infos_image['largeur'].' px';
|
|
|
74 |
} else {
|
|
|
75 |
$res_fmt = 'Taille inconnue';
|
|
|
76 |
}
|
2207 |
aurelien |
77 |
return $res_fmt;
|
|
|
78 |
}
|
2487 |
jpm |
79 |
|
2216 |
aurelien |
80 |
private function formaterDateTeleversement($infos_image) {
|
2487 |
jpm |
81 |
$date = 'Date inconnue';
|
|
|
82 |
if (isset($infos_image['date_creation'])) {
|
|
|
83 |
$date = date('d/m/Y', strtotime($infos_image['date_creation']));
|
2216 |
aurelien |
84 |
}
|
|
|
85 |
return $date;
|
|
|
86 |
}
|
2487 |
jpm |
87 |
|
2207 |
aurelien |
88 |
private function obtenirDescriptionFormats() {
|
|
|
89 |
$this->description_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat');
|
|
|
90 |
$description = json_decode(file_get_contents($this->description_url), true);
|
2487 |
jpm |
91 |
|
2207 |
aurelien |
92 |
return $description;
|
|
|
93 |
}
|
2487 |
jpm |
94 |
|
2207 |
aurelien |
95 |
private function obtenirInformationsImages() {
|
2487 |
jpm |
96 |
$this->infos_images_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImage');
|
|
|
97 |
$infos = json_decode(file_get_contents($this->infos_images_url."/image?imgId=".$this->id_image), true);
|
2207 |
aurelien |
98 |
return $infos;
|
|
|
99 |
}
|
2487 |
jpm |
100 |
|
2207 |
aurelien |
101 |
public static function obtenirLegendeFormatSimplifiee($format) {
|
2487 |
jpm |
102 |
$legende = '';
|
|
|
103 |
if (strpos($format, 'CR') !== false) {
|
|
|
104 |
$legende = '(Carrée, rognée)';
|
2207 |
aurelien |
105 |
}
|
2487 |
jpm |
106 |
if (strpos($format, 'C') !== false && strpos($format, 'R') === false) {
|
|
|
107 |
$legende = '(Carrée)';
|
2207 |
aurelien |
108 |
}
|
|
|
109 |
return $legende;
|
|
|
110 |
}
|
2487 |
jpm |
111 |
}
|