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