Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Blame | Last modification | View Log | RSS feed

<?php
// declare(encoding='UTF-8');
/**
 * Classe mère du module Liste.
 *
 * @category    PHP 5.2
 * @package             eflore-consultation
 * @author              Jean-Pascal MILCENT <jpm@tela-botanica.org>
 * @author              Delphine CAUQUIL <delphine@tela-botanica.org>
 * @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 Wp extends aControleur {

        private $parametres = null;
        private $donneesTpl = array();

        public function initialiser() {
                spl_autoload_register(array($this, 'chargerClassesWp'));
                $this->parametres = new ParametresWp();
                $this->capturerParametres();
        }

        private function chargerClassesWp($classe) {
                $base = dirname(__FILE__).DS;
                $robots = Config::get('chemin_modeles').DS.'robots'.DS;
                $dossiers = array($base, $robots);
                foreach ($dossiers as $chemin) {
                        $fichierATester = $chemin.$classe.'.php';
                        if (file_exists($fichierATester)) {
                                include_once $fichierATester;
                                return null;
                        }
                }
        }

        private function capturerParametres() {
                if (isset($_GET['article'])) {
                        $this->parametres->article = $_GET['article'];
                }
        }

        public function executerActionParDefaut() {
                $this->executerArticleWp();
        }

        public function executerArticleWp() {
                $this->donneesTpl['article']['recherche'] = $this->parametres->article;
                $this->chargerArticle();
                $this->setSortie(self::RENDU_CORPS, $this->getVue('article', $this->donneesTpl));
        }

        private function chargerArticle() {
                $wp = new WikipediaBot('fr');
                $wp->chargerPage($this->parametres->article);
                $this->donneesTpl['article']['titre'] = $wp->getPageTitre();
                $this->donneesTpl['article']['taxobox'] = $wp->rendre($wp->extraireTaxobox());
                $this->donneesTpl['article']['intro'] = $wp->rendre($wp->getSectionParNumero(0));
                $this->donneesTpl['article']['caracteristiques'] = $wp->rendre($wp->getSectionParTitre('Caractéristiques'));
                $this->donneesTpl['article']['contenu'] = $wp->rendre($wp->getPageTxt());
        }

        private function creerPageUrl() {
                $page = $this->creerPageNom();
                $url = "http://fr.wikipedia.org/wiki/$page";
                return $url;
        }

        private function creerPageNom() {
                $page = str_replace(' ', '_', $this->parametres->article);
                $page = urlencode($page);
                return $page;
        }
}
?>