2207 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
class Telechargement extends WidgetCommun {
|
2478 |
jpm |
4 |
|
|
|
5 |
private $description_url = null;
|
2207 |
aurelien |
6 |
private $infos_images_url = null;
|
|
|
7 |
private $telechargement_url = null;
|
2478 |
jpm |
8 |
|
2207 |
aurelien |
9 |
private $id_image = null;
|
2478 |
jpm |
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Méthode appelée par défaut pour charger ce widget.
|
|
|
13 |
*/
|
2207 |
aurelien |
14 |
public function executer() {
|
2478 |
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'];
|
2478 |
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']);
|
2478 |
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');
|
2478 |
jpm |
35 |
$donnees['base_url_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat').'/'.$this->id_image.'?methode=telecharger&format=%s';
|
2207 |
aurelien |
36 |
$contenu = $this->traiterSquelettePhp($squelette, $donnees);
|
|
|
37 |
}
|
2478 |
jpm |
38 |
$this->envoyer($contenu);
|
2207 |
aurelien |
39 |
}
|
2478 |
jpm |
40 |
|
2233 |
aurelien |
41 |
private function formaterNomOriginal($infos_images) {
|
2478 |
jpm |
42 |
$nom_original = 'Inconnu.jpg';
|
2233 |
aurelien |
43 |
if(isset($infos_images['nom_original'])) {
|
|
|
44 |
$nom_original = $infos_images['nom_original'].' ';
|
|
|
45 |
}
|
|
|
46 |
return $nom_original;
|
|
|
47 |
}
|
2478 |
jpm |
48 |
|
2207 |
aurelien |
49 |
private function formaterAttribution($infos_images) {
|
2478 |
jpm |
50 |
$attr = $this->formaterAuteur($infos_images).' [CC BY-SA], via Tela Botanica';
|
2207 |
aurelien |
51 |
return $attr;
|
|
|
52 |
}
|
2478 |
jpm |
53 |
|
2207 |
aurelien |
54 |
private function formaterAuteur($infos_images) {
|
2478 |
jpm |
55 |
$auteur_fmt = '';
|
|
|
56 |
if (isset($infos_images['prenom_utilisateur'])) {
|
2207 |
aurelien |
57 |
$auteur_fmt .= $infos_images['prenom_utilisateur'].' ';
|
|
|
58 |
}
|
2478 |
jpm |
59 |
|
|
|
60 |
if (isset($infos_images['nom_utilisateur'])) {
|
|
|
61 |
$auteur_fmt .= $infos_images['nom_utilisateur'];
|
2207 |
aurelien |
62 |
}
|
2478 |
jpm |
63 |
|
|
|
64 |
if (trim($auteur_fmt) == '') {
|
2207 |
aurelien |
65 |
$auteur_fmt = 'Auteur inconnu';
|
|
|
66 |
}
|
2478 |
jpm |
67 |
|
2207 |
aurelien |
68 |
return trim($auteur_fmt);
|
|
|
69 |
}
|
2478 |
jpm |
70 |
|
2207 |
aurelien |
71 |
private function formaterResolutionOriginale($infos_image) {
|
2478 |
jpm |
72 |
$res_fmt = '';
|
|
|
73 |
if (isset($infos_image['hauteur']) && isset($infos_image['largeur'])) {
|
|
|
74 |
$res_fmt = $infos_image['hauteur'].' x '.$infos_image['largeur'].' px';
|
|
|
75 |
} else {
|
|
|
76 |
$res_fmt = 'Taille inconnue';
|
|
|
77 |
}
|
2207 |
aurelien |
78 |
return $res_fmt;
|
|
|
79 |
}
|
2478 |
jpm |
80 |
|
2216 |
aurelien |
81 |
private function formaterDateTeleversement($infos_image) {
|
2478 |
jpm |
82 |
$date = 'Date inconnue';
|
|
|
83 |
if (isset($infos_image['date_creation'])) {
|
|
|
84 |
$date = date('d/m/Y', strtotime($infos_image['date_creation']));
|
2216 |
aurelien |
85 |
}
|
|
|
86 |
return $date;
|
|
|
87 |
}
|
2478 |
jpm |
88 |
|
2207 |
aurelien |
89 |
private function obtenirDescriptionFormats() {
|
|
|
90 |
$this->description_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat');
|
|
|
91 |
$description = json_decode(file_get_contents($this->description_url), true);
|
2478 |
jpm |
92 |
|
2207 |
aurelien |
93 |
return $description;
|
|
|
94 |
}
|
2478 |
jpm |
95 |
|
2207 |
aurelien |
96 |
private function obtenirInformationsImages() {
|
2478 |
jpm |
97 |
$this->infos_images_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImage');
|
|
|
98 |
$infos = json_decode(file_get_contents($this->infos_images_url."/image?imgId=".$this->id_image), true);
|
2207 |
aurelien |
99 |
return $infos;
|
|
|
100 |
}
|
2478 |
jpm |
101 |
|
2207 |
aurelien |
102 |
public static function obtenirLegendeFormatSimplifiee($format) {
|
2478 |
jpm |
103 |
$legende = '';
|
|
|
104 |
if (strpos($format, 'CR') !== false) {
|
|
|
105 |
$legende = '(Carrée, rognée)';
|
2207 |
aurelien |
106 |
}
|
2478 |
jpm |
107 |
if (strpos($format, 'C') !== false && strpos($format, 'R') === false) {
|
|
|
108 |
$legende = '(Carrée)';
|
2207 |
aurelien |
109 |
}
|
|
|
110 |
return $legende;
|
|
|
111 |
}
|
2478 |
jpm |
112 |
}
|