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