* @author Delphine CAUQUIL * @copyright 2011 Tela-Botanica * @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3 * @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2 * @version $Id$ */ class Fiche extends aControleur { private $onglet = 'synthese'; private $parametres = array(); private $conteneur = null; private $num_nom = 0; private $nom_retenu = ''; private $nom_selectionne = null; private $nom_appele_html = null; // le nom et l'auteur par lesquels on est arrivés sur la fiche, en cas de synonymie private $url; public function initialiser() { $this->capturerParametres(); $this->conteneur = new Conteneur($this->parametres); $nom_courant = $this->conteneur->getNomCourant(); $this->nom_selectionne = $nom_courant->getNomSelectionne(); $this->url = $this->conteneur->getAppUrls(); $this->nom_retenu = $nom_courant->getNomRetenu(); if ($this->nom_retenu->get('id') != $this->nom_selectionne->get('id')) { $this->nom_appele_html = $this->nom_selectionne->get('nom_sci_html').' '.$this->nom_selectionne->get('auteur'); } spl_autoload_register(array($this, 'chargerClassesOnglets')); } private function capturerParametres() { if (isset($_GET['num_nom'])) { $this->parametres['num_nom'] = $_GET['num_nom']; } if (isset($_GET['nom'])) { $this->parametres['nom'] = $_GET['nom']; } if (isset($_GET['type_nom'])) { $this->parametres['type_nom'] = $_GET['type_nom']; } if (isset($_GET['referentiel'])) { $this->parametres['referentiel'] = $_GET['referentiel']; Registre::set('parametres.referentiel', $_GET['referentiel']); } if (isset($_GET['niveau'])) { Registre::set('parametres.niveau', $_GET['niveau']); } if (isset($_GET['onglet'])) { $this->onglet = $_GET['onglet']; } } private function chargerClassesOnglets($classe) { $base = dirname(__FILE__).DS; $cheminFormateurs = $base.'formateurs'.DS; $dossiers = array($base, $cheminFormateurs); foreach ($dossiers as $chemin) { $fichierATester = $chemin.$classe.'.php'; if (file_exists($fichierATester)) { include_once $fichierATester; return null; } } } public function executerActionParDefaut() { $this->executerFiche(); } public function executerFiche(){ $squelette = 'fiche_'.$this->onglet; //Gestion du niveau $niveau = isset($_GET['niveau']) ? $_GET['niveau'] : 2; if ($this->onglet == 'synthese' && $niveau != null) { $squelette .= '_niveau'.$niveau; } // Récupération parametres et données $donnees = array_merge($this->obtenirDonnees(), $this->parametres); $donnees['i18n'] = I18n::get('Fiche'); $verna = isset($donnees['ethnobotanique']['nomsVerna']) && count($donnees['ethnobotanique']['nomsVerna']) ? $donnees['ethnobotanique']['nomsVerna'][0]['nom_vernaculaire'] : ""; // titre, description et tag de la page $this->setSortie('titre', $this->nom_retenu->get('nom_sci')); // ( ) $this->setSortie('description', sprintf("Fiche descriptive de %s %s (%s)", $this->nom_retenu->get('nom_sci'), $verna ? ('/ ' . $verna) : '', $donnees['description']['titre'])); $this->setSortie('tags', $this->nom_retenu->get('nom_sci').",".$verna. ",botanique,plante,description,ecologie,reconnaitre,fiche espece"); $nom_sci_html = $this->nom_retenu->get('nom_sci_html'); // la recherche avancée à partir du clic sur le nom ne fonctionne pas sur les hybrides $nom_sci_html = strpos($nom_sci_html, 'class="hyb"') === false ? $this->formaterLiensNomsHtml($nom_sci_html) : $nom_sci_html; // titre de la fiche $donnees['nom_retenu_html'] = $nom_sci_html.' '.$this->nom_retenu->get('auteur'); $donnees['nom_retenu'] = $this->nom_retenu->get('nom_sci'); $donnees['num_tax'] = $this->nom_selectionne->get('num_taxonomique'); $donnees['nom_appele_html'] = $this->nom_appele_html; $famille = $this->nom_retenu->getTaxonSupRang('180'); $donnees['lien_recherche_famille'] = html_entity_decode($this->url->obtenirUrlRechercheAvancee(array("fam" => $famille))); $donnees['famille'] = $famille; $donnees['referentiel'] = $this->parametres['referentiel']; $donnees['nom_fr_norm'] = $this->nom_selectionne->get('nom_fr_norm'); $donnees['nom_vernaculaire'] = $verna; // moteur de recherche $this->executerAction('Recherche', 'executerAccueil', $this->parametres); // page synthese $blocs_niveaux = $this->conteneur->getParametreTableau('blocs_fiche_defaut'); $donnees['blocs'] = '"'.str_replace('|', '","', $blocs_niveaux[Registre::get('parametres.niveau')]).'"'; // onglet $donnees['onglet'] = $this->onglet; $donnees['niveau'] = $niveau; $donnees['base_url_onglets'] = Config::get('base_url_application_onglets'); $taxons = new Taxons(); $referentiel = $this->conteneur->getParametre('referentiel'); $donnees['prod'] = Config::get('info.prod'); $donnees['permalien_num_nom'] = $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns()); $donnees['entete'] = $this->getVue('fiche_entete', $donnees); $donnees['contenu_onglet'] = $this->getVue($squelette, $donnees); $this->setSortie(self::RENDU_CORPS, $this->getVue('fiche_accueil_niveau'.$niveau, $donnees), true); $this->ajouterPiedDePage(); } public function executerTemplateAjax() { $classe = ucfirst($this->onglet); $onglet = new $classe($this->conteneur); $action = 'obtenir'.ucfirst($_GET['sous_action']); $html_ajax = $onglet->$action(); header('Content-type : text/html'); echo $html_ajax; exit; } private function formaterLiensNomsHtml($nom_sci_html) { $app_urls = new AppUrls(); $params = array(); $classes_recherche = array("fam" => "fam", "gen" => "gen", "sp" => "sp", "infra-sp" => "ssp"); $doc = new DOMDocument(); $doc->loadHTML($nom_sci_html); $spans = $doc->getElementsByTagName('span'); $abbrs = $doc->getElementsByTagName('abbr'); $params_subsp = array(); $i18n = I18n::get('Fiche'); //TODO: c'est un peu moche, la fonction est surement factorisable if ($spans->length > 0) { foreach($spans as $span) { $classe = $span->getAttribute('class'); if(in_array($classe, array_keys($classes_recherche))) { $params[$classes_recherche[$classe]] = $span->nodeValue; if($classe == "sp") { $params_subsp = $params; } $lien_tpl = html_entity_decode($this->url->obtenirUrlRechercheAvancee($params)); $texte_lien = $span->nodeValue; $span->nodeValue = ""; $text = $doc->createElement('a', $texte_lien); $text->setAttribute('href', $lien_tpl); $text->setAttribute('title', $i18n["lien-recherche-hier-".$classe]); $text->setAttribute('class', 'lien_recherche_hier'); $span->appendChild($text); } } } if ($abbrs->length > 0) { foreach($abbrs as $abbr) { $classe = $abbr->getAttribute('class'); $params_subsp["type"] = $abbr->nodeValue; $lien_tpl = html_entity_decode($this->url->obtenirUrlRechercheAvancee($params_subsp)); $texte_lien = $abbr->nodeValue; $abbr->nodeValue = ""; $text = $doc->createElement('a', $texte_lien); $text->setAttribute('href', $lien_tpl); $text->setAttribute('title', $i18n["lien-recherche-hier-ssp"]); $text->setAttribute('class', 'lien_recherche_hier'); $abbr->appendChild($text); } } return $doc->SaveXml(); } private function formaterLienRechercheSurPartieNomSci(&$noeud, &$params) { } public function ajouterLienModuleExport() { $donnees['lien'] = $this->url->obtenirUrlPdfExport($this->parametres['num_nom']); $export = $this->getVue('fiche_pdf_lien', $donnees); return $export; } public function ajouterPiedDePage() { $description = new Description($this->conteneur); $taxons = new Taxons(); $referentiel = $this->conteneur->getParametre('referentiel'); $urlMobile = $this->url->obtenirUrlMobile($this->parametres['num_nom']); $donnees = array('wikipedia' => $description->getUrlWikipedia(), 'export_pdf' => $this->ajouterLienModuleExport(), 'permalien_num_nom' => $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns()), 'permalien_taxon' => $taxons->getUrlPermalienTaxon($referentiel, 1, $this->conteneur->getNomCourant()->getNt()), 'nn' => $this->conteneur->getNomCourant()->getNns(), 'nt' => $this->conteneur->getNomCourant()->getNt(), 'nnr' => $this->conteneur->getNomCourant()->getNnr(), 'inpn' => $this->conteneur->getNomCourant()->getInpn(), 'wiki' => $description->getLienWikini(), 'nom_retenu' => $this->nom_retenu->get('nom_sci'), 'mobile' => $urlMobile, 'qr_code_png' => $this->obtenirUrlQrCode($urlMobile) ); $this->setSortie(self::RENDU_CORPS, $this->getVue('fiche_pied_page', $donnees), true); } private function obtenirUrlQrCode($urlMobile) { $qr = $this->conteneur->getQrCode(); $qr->setUrl(htmlspecialchars_decode($urlMobile)); $idQrCode = $this->conteneur->getParametre('referentiel') . '-' .$this->conteneur->getNomCourant()->getNns(); $urlQrCode = $qr->dessiner($idQrCode); return $urlQrCode; } public function executerOnglet(){ $this->viderSorties(); $donnees = $this->obtenirDonnees(); $squelette_onglet = $this->onglet; // onglet $donnees['i18n'] = I18n::get('Fiche'); $donnees['onglet'] = $this->onglet; $taxons = new Taxons(); $referentiel = $this->conteneur->getParametre('referentiel'); $donnees['permalien_num_nom'] = $taxons->getUrlPermalienNumNom($referentiel, 1, $this->conteneur->getNomCourant()->getNns()); $donnees['prod'] = Config::get('info.prod'); // cas particulier de l'onglet synthese qui possède 3 niveaux // et dont le nom n'est donc pas directement celui de son squelette if($this->onglet == "synthese") { $niveau = isset($_GET['niveau']) ? $_GET['niveau'] : 2; $squelette_onglet .= '_niveau'.$niveau; $entete = $this->getVue('fiche_entete', $donnees); $vue = $entete.$this->getVue('fiche_'.$squelette_onglet, $donnees); } else { $vue = $this->getVue('fiche_'.$squelette_onglet, $donnees); } header('Content-type: text/html'); $this->setSortie(self::RENDU_CORPS, $vue); } private function obtenirDonnees() { $classe = ucfirst($this->onglet); $onglet = new $classe($this->conteneur); // grep-friendly: new Synthese() return $onglet->obtenirDonnees(); } } ?>