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();
|
|
|
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'], '');
|
|
|
32 |
$donnees['date_televersement'] = date("d/m/Y",strtotime($donnees['informations_image']['date_creation']));
|
|
|
33 |
$donnees['url_image_exemple'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat').'/'.$this->id_image.'?methode=afficher&format=CS';
|
|
|
34 |
$donnees['url_image_originale'] = sprintf($this->config['chemins']['celImgUrlTpl'], str_pad($this->id_image, 9, "0", STR_PAD_LEFT).'O');
|
|
|
35 |
$donnees['base_url_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat').'/'.$this->id_image.'?methode=telecharger&format=%s';
|
|
|
36 |
$contenu = $this->traiterSquelettePhp($squelette, $donnees);
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
$this->envoyer($contenu);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
private function formaterAttribution($infos_images) {
|
|
|
43 |
$attr = $this->formaterAuteur($infos_images).' '.
|
|
|
44 |
'[CC BY-SA], via Tela Botanica';
|
|
|
45 |
|
|
|
46 |
return $attr;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
private function formaterAuteur($infos_images) {
|
|
|
50 |
$auteur_fmt = "";
|
|
|
51 |
if(isset($infos_images['prenom_utilisateur'])) {
|
|
|
52 |
$auteur_fmt .= $infos_images['prenom_utilisateur'].' ';
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
if(isset($infos_images['nom_utilisateur'])) {
|
|
|
56 |
$auteur_fmt .= $infos_images['nom_utilisateur'];
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if(trim($auteur_fmt) == "") {
|
|
|
60 |
$auteur_fmt = 'Auteur inconnu';
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
return trim($auteur_fmt);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
private function formaterResolutionOriginale($infos_image) {
|
|
|
67 |
$res_fmt = "";
|
|
|
68 |
if(isset($infos_image['hauteur']) && isset($infos_image['largeur'])) {
|
|
|
69 |
$res_fmt = $infos_image['hauteur'].' x '.$infos_image['largeur'].' px';
|
|
|
70 |
} else {
|
|
|
71 |
$res_fmt = 'Taille inconnue';
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
return $res_fmt;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
private function obtenirDescriptionFormats() {
|
|
|
78 |
$this->description_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat');
|
|
|
79 |
$description = json_decode(file_get_contents($this->description_url), true);
|
|
|
80 |
|
|
|
81 |
return $description;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
private function obtenirInformationsImages() {
|
|
|
85 |
$this->infos_images_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImage');
|
|
|
86 |
$infos = json_decode(file_get_contents($this->infos_images_url."/image?imgId=".$this->id_image), true);
|
|
|
87 |
return $infos;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
public static function obtenirLegendeFormatSimplifiee($format) {
|
|
|
91 |
$legende = "";
|
|
|
92 |
if(strpos($format, 'CR') !== false) {
|
|
|
93 |
$legende = "(Carrée, rognée)";
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
if(strpos($format, 'C') !== false && strpos($format, 'R') === false) {
|
|
|
97 |
$legende = "(Carrée)";
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
return $legende;
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
?>
|