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 = '';
|
3807 |
delphine |
58 |
if (isset($infos_images['pseudo_utilisateur'])) {
|
|
|
59 |
$auteur_fmt .= $infos_images['pseudo_utilisateur'].' ';
|
2207 |
aurelien |
60 |
}
|
2487 |
jpm |
61 |
|
|
|
62 |
if (trim($auteur_fmt) == '') {
|
2207 |
aurelien |
63 |
$auteur_fmt = 'Auteur inconnu';
|
|
|
64 |
}
|
2487 |
jpm |
65 |
|
2207 |
aurelien |
66 |
return trim($auteur_fmt);
|
|
|
67 |
}
|
2487 |
jpm |
68 |
|
2207 |
aurelien |
69 |
private function formaterResolutionOriginale($infos_image) {
|
2487 |
jpm |
70 |
$res_fmt = '';
|
|
|
71 |
if (isset($infos_image['hauteur']) && isset($infos_image['largeur'])) {
|
|
|
72 |
$res_fmt = $infos_image['hauteur'].' x '.$infos_image['largeur'].' px';
|
|
|
73 |
} else {
|
|
|
74 |
$res_fmt = 'Taille inconnue';
|
|
|
75 |
}
|
2207 |
aurelien |
76 |
return $res_fmt;
|
|
|
77 |
}
|
2487 |
jpm |
78 |
|
2216 |
aurelien |
79 |
private function formaterDateTeleversement($infos_image) {
|
2487 |
jpm |
80 |
$date = 'Date inconnue';
|
|
|
81 |
if (isset($infos_image['date_creation'])) {
|
|
|
82 |
$date = date('d/m/Y', strtotime($infos_image['date_creation']));
|
2216 |
aurelien |
83 |
}
|
|
|
84 |
return $date;
|
|
|
85 |
}
|
2487 |
jpm |
86 |
|
2207 |
aurelien |
87 |
private function obtenirDescriptionFormats() {
|
|
|
88 |
$this->description_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat');
|
|
|
89 |
$description = json_decode(file_get_contents($this->description_url), true);
|
2487 |
jpm |
90 |
|
2207 |
aurelien |
91 |
return $description;
|
|
|
92 |
}
|
2487 |
jpm |
93 |
|
2207 |
aurelien |
94 |
private function obtenirInformationsImages() {
|
2487 |
jpm |
95 |
$this->infos_images_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImage');
|
|
|
96 |
$infos = json_decode(file_get_contents($this->infos_images_url."/image?imgId=".$this->id_image), true);
|
2207 |
aurelien |
97 |
return $infos;
|
|
|
98 |
}
|
2487 |
jpm |
99 |
|
2207 |
aurelien |
100 |
public static function obtenirLegendeFormatSimplifiee($format) {
|
2487 |
jpm |
101 |
$legende = '';
|
|
|
102 |
if (strpos($format, 'CR') !== false) {
|
|
|
103 |
$legende = '(Carrée, rognée)';
|
2207 |
aurelien |
104 |
}
|
2487 |
jpm |
105 |
if (strpos($format, 'C') !== false && strpos($format, 'R') === false) {
|
|
|
106 |
$legende = '(Carrée)';
|
2207 |
aurelien |
107 |
}
|
|
|
108 |
return $legende;
|
|
|
109 |
}
|
2487 |
jpm |
110 |
}
|