Subversion Repositories eFlore/Applications.cel

Rev

Rev 3151 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
// declare(encoding='UTF-8');
class Telechargement extends WidgetCommun {

        private $description_url = null;
        private $infos_images_url = null;
        private $telechargement_url = null;

        private $id_image = null;

        /**
         * Méthode appelée par défaut pour charger ce widget.
         */
        public function executer() {
                if (!isset($_GET['id_image']) || !is_numeric($_GET['id_image'])) {
                        $this->messages[] = "Ce widget nécéssite un identifiant d'image.";
                } else {
                        $this->id_image = $_GET['id_image'];
                }

                if (!empty($this->messages)) {
                        $contenu = 'Un problème est survenu : '.print_r($this->messages, true);
                } else {
                        $donnees = $this->obtenirDescriptionFormats();
                        $squelette = dirname(__FILE__).'/squelettes'.'/telechargement.tpl.html';
                        $donnees['informations_image'] = $this->obtenirInformationsImages();
                        $donnees['nom_original_fmt'] = $this->formaterNomOriginal($donnees['informations_image']);
                        $donnees['resolution_originale'] = $this->formaterResolutionOriginale($donnees['informations_image']);
                        $donnees['auteur_fmt'] = $this->formaterAuteur($donnees['informations_image']);
                        $donnees['attribution'] = $this->formaterAttribution($donnees['informations_image']);
                        $donnees['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
                        $donnees['date_televersement'] = $this->formaterDateTeleversement($donnees['informations_image']);
                        $donnees['url_image_exemple'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat').'/'.$this->id_image.'?methode=afficher&format=CS';
                        $donnees['url_image_originale'] = sprintf($this->config['chemins']['celImgUrlTpl'], str_pad($this->id_image, 9, "0", STR_PAD_LEFT).'O');
                        $donnees['base_url_telechargement'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat').'/'.$this->id_image.'?methode=telecharger&format=%s';
                        $donnees['prod'] = ($this->config['parametres']['modeServeur'] == "prod");

                        $contenu = $this->traiterSquelettePhp($squelette, $donnees);
                }
                $this->envoyer($contenu);
        }

        private function formaterNomOriginal($infos_images) {
                $nom_original = 'Inconnu.jpg';
                if(isset($infos_images['nom_original'])) {
                        $nom_original = $infos_images['nom_original'].' ';
                }
                return $nom_original;
        }

        private function formaterAttribution($infos_images) {
                $attr = $this->formaterAuteur($infos_images).' [CC BY-SA 2.0 FR], via Tela Botanica';
                return $attr;
        }

        private function formaterAuteur($infos_images) {
                $auteur_fmt = '';
                if (isset($infos_images['pseudo_utilisateur'])) {
                        $auteur_fmt .= $infos_images['pseudo_utilisateur'].' ';
                }

                
                if (trim($auteur_fmt) == '') {
                        $auteur_fmt = 'Auteur inconnu';
                }

                return trim($auteur_fmt);
        }

        private function formaterResolutionOriginale($infos_image) {
                $res_fmt = '';
                if (isset($infos_image['hauteur']) && isset($infos_image['largeur'])) {
                        $res_fmt = $infos_image['hauteur'].' x '.$infos_image['largeur'].' px';
                } else {
                        $res_fmt = 'Taille inconnue';
                }
                return $res_fmt;
        }

        private function formaterDateTeleversement($infos_image) {
                $date = 'Date inconnue';
                if (isset($infos_image['date_creation'])) {
                        $date = date('d/m/Y', strtotime($infos_image['date_creation']));
                }
                return $date;
        }

        private function obtenirDescriptionFormats() {
                $this->description_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImageFormat');
                $description = json_decode(file_get_contents($this->description_url), true);

                return $description;
        }

        private function obtenirInformationsImages() {
                $this->infos_images_url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], 'CelImage');
                $infos = json_decode(file_get_contents($this->infos_images_url."/image?imgId=".$this->id_image), true);
                return $infos;
        }

        public static function obtenirLegendeFormatSimplifiee($format) {
                $legende = '';
                if (strpos($format, 'CR') !== false) {
                        $legende = '(Carrée, rognée)';
                }
                if (strpos($format, 'C') !== false && strpos($format, 'R') === false) {
                        $legende = '(Carrée)';
                }
                return $legende;
        }
}