| 323 | jpm | 1 | <?php
 | 
        
           |  |  | 2 | /*vim: set expandtab tabstop=4 shiftwidth=4: */
 | 
        
           |  |  | 3 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 4 | // | PHP version 4.1                                                                                      |
 | 
        
           |  |  | 5 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 6 | // | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org)                                         |
 | 
        
           |  |  | 7 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 8 | // | This file is part of Papyrus.                                                                        |
 | 
        
           |  |  | 9 | // |                                                                                                      |
 | 
        
           |  |  | 10 | // | Foobar is free software; you can redistribute it and/or modify                                       |
 | 
        
           |  |  | 11 | // | it under the terms of the GNU General Public License as published by                                 |
 | 
        
           |  |  | 12 | // | the Free Software Foundation; either version 2 of the License, or                                    |
 | 
        
           |  |  | 13 | // | (at your option) any later version.                                                                  |
 | 
        
           |  |  | 14 | // |                                                                                                      |
 | 
        
           |  |  | 15 | // | Foobar is distributed in the hope that it will be useful,                                            |
 | 
        
           |  |  | 16 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
 | 
        
           |  |  | 17 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
 | 
        
           |  |  | 18 | // | GNU General Public License for more details.                                                         |
 | 
        
           |  |  | 19 | // |                                                                                                      |
 | 
        
           |  |  | 20 | // | You should have received a copy of the GNU General Public License                                    |
 | 
        
           |  |  | 21 | // | along with Foobar; if not, write to the Free Software                                                |
 | 
        
           |  |  | 22 | // | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
 | 
        
           |  |  | 23 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 24 | // CVS : $Id: erreur_404.php,v 1.1 2005-03-30 08:58:32 jpm Exp $
 | 
        
           |  |  | 25 | /**
 | 
        
           |  |  | 26 | * Redirection de page
 | 
        
           |  |  | 27 | *
 | 
        
           |  |  | 28 | * Permet d'utiliser la redirection de page.
 | 
        
           |  |  | 29 | *
 | 
        
           |  |  | 30 | *@package Papyrus
 | 
        
           |  |  | 31 | //Auteur original :
 | 
        
           |  |  | 32 | *@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
 | 
        
           |  |  | 33 | //Autres auteurs :
 | 
        
           |  |  | 34 | *@author        Aucun
 | 
        
           |  |  | 35 | *@copyright     Tela-Botanica 2000-2005
 | 
        
           |  |  | 36 | *@version       $Revision: 1.1 $ $Date: 2005-03-30 08:58:32 $
 | 
        
           |  |  | 37 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 38 | */
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 41 | // |                                            ENTETE du PROGRAMME                                       |
 | 
        
           |  |  | 42 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 43 | // Définission de constantes
 | 
        
           |  |  | 44 | /** Chemin et nom du fichier de configuration principal de Papyrus.*/
 | 
        
           |  |  | 45 | define('PAP_FICHIER_CONFIG', 'papyrus/configuration/pap_config.inc.php');
 | 
        
           |  |  | 46 | /** Chemin et nom du fichier de configuration avancée de Papyrus.*/
 | 
        
           |  |  | 47 | define('PAP_FICHIER_CONFIG_AVANCEE', 'papyrus/configuration/pap_config_avancee.inc.php');
 | 
        
           |  |  | 48 | /** Chemin et nom du fichier des fonctions manipulant les menus de Papyrus.*/
 | 
        
           |  |  | 49 | define('PAP_FICHIER_FONCTION_MENU', 'papyrus/bibliotheque/fonctions/pap_menu.fonct.php');
 | 
        
           |  |  | 50 | /** Chemin et nom du fichier Pear DB.*/
 | 
        
           |  |  | 51 | define('PAP_FICHIER_PEAR_DB', 'api/pear/DB.php');
 | 
        
           |  |  | 52 | /** Chemin et nom du fichier Pear HTTP.*/
 | 
        
           |  |  | 53 | define('PAP_FICHIER_PEAR_HTTP', 'api/pear/HTTP.php');
 | 
        
           |  |  | 54 | /** Chemin et nom du fichier affichant une erreur 404.*/
 | 
        
           |  |  | 55 | define('PAP_FICHIER_ERREUR_404', 'sites/commun/%s/http_erreurs/erreur404.php');
 | 
        
           |  |  | 56 | /** Chemin et nom du fichier affichant une erreur 404.*/
 | 
        
           |  |  | 57 | define('PAP_URL_ERREUR_404', 'sites/commun/%s/http_erreurs/erreur404.php?url=%s');
 | 
        
           |  |  | 58 | /** Url où rediriger une page.*/
 | 
        
           |  |  | 59 | define('PAP_URL_REDIRECTION', '/papyrus.php?menu=%s');
 | 
        
           |  |  | 60 |   | 
        
           |  |  | 61 | if (file_exists(PAP_FICHIER_CONFIG) && file_exists(PAP_FICHIER_FONCTION_MENU) && file_exists(PAP_FICHIER_CONFIG_AVANCEE) &&
 | 
        
           |  |  | 62 |     file_exists(PAP_FICHIER_PEAR_DB) && file_exists(PAP_FICHIER_PEAR_HTTP)) {
 | 
        
           |  |  | 63 |     /** Inclusion du fichier de configuration de Papyrus permettant de se conecter à la base de données. */
 | 
        
           |  |  | 64 |     require_once PAP_FICHIER_CONFIG;
 | 
        
           |  |  | 65 |     /** Inclusion du fichier de configuration de Papyrus permettant d'avoir des infos sur la structure de l'url. */
 | 
        
           |  |  | 66 |     require_once PAP_FICHIER_CONFIG_AVANCEE;
 | 
        
           |  |  | 67 |     /** Inclusion du fichier de contenant les fonctions de manipulation des informations sur les menus de Papyrus. */
 | 
        
           |  |  | 68 |     require_once PAP_FICHIER_FONCTION_MENU;
 | 
        
           |  |  | 69 |     /** Inclusion de la classe PEAR d'abstraction de base de donnée. */
 | 
        
           |  |  | 70 |     require_once PAP_FICHIER_PEAR_DB;
 | 
        
           |  |  | 71 |     /** Inclusion de l'objet PEAR servant à négocier le language avec le navigateur client. */
 | 
        
           |  |  | 72 |     require_once PAP_FICHIER_PEAR_HTTP;
 | 
        
           |  |  | 73 | } else {
 | 
        
           |  |  | 74 |     gererErreur404();
 | 
        
           |  |  | 75 | }
 | 
        
           |  |  | 76 |   | 
        
           |  |  | 77 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 78 | // |                                            CORPS du PROGRAMME                                        |
 | 
        
           |  |  | 79 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 80 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 81 | // Tentative de Connexion à la base de données et de récupération de l'URI demandée.
 | 
        
           |  |  | 82 | $bdd = DB::connect(PAP_DSN);
 | 
        
           |  |  | 83 | if (DB::isError($bdd) || empty($_SERVER['REQUEST_URI'])) {
 | 
        
           |  |  | 84 |     gererErreur404();
 | 
        
           |  |  | 85 | }
 | 
        
           |  |  | 86 | preg_match('/^\/(.*)$/', $_SERVER['REQUEST_URI'], $tab_raccourci);
 | 
        
           |  |  | 87 | echo $raccourci;
 | 
        
           |  |  | 88 | $raccourci = $tab_raccourci[1];
 | 
        
           |  |  | 89 | // Nous cherchons à savoir si le raccourci est entièrement numérique ou pas.
 | 
        
           |  |  | 90 | if (preg_match('/^[0-9]+$/', $raccourci)) {
 | 
        
           |  |  | 91 |     // Nous vérifions si nous utilisons les codes numériques ou alphanumérique dans les url
 | 
        
           |  |  | 92 |     if (GEN_URL_ID_TYPE_MENU != 'int') {
 | 
        
           |  |  | 93 |         $code = GEN_retournerMenuCodeAlpha($bdd, $raccourci);
 | 
        
           |  |  | 94 |     } else {
 | 
        
           |  |  | 95 |         $code = $raccourci;
 | 
        
           |  |  | 96 |     }
 | 
        
           |  |  | 97 | } else {
 | 
        
           |  |  | 98 |     // Nous vérifions si nous utilisons les codes numériques ou alphanumérique dans les url
 | 
        
           |  |  | 99 |     if (GEN_URL_ID_TYPE_MENU != 'int') {
 | 
        
           |  |  | 100 |         $code = $raccourci;
 | 
        
           |  |  | 101 |     } else {
 | 
        
           |  |  | 102 |         $code = GEN_retournerMenuCodeNum($bdd, $raccourci);
 | 
        
           |  |  | 103 |     }
 | 
        
           |  |  | 104 | }
 | 
        
           |  |  | 105 | if ($code != '') {
 | 
        
           |  |  | 106 |     // Nous effectuons la redirection:
 | 
        
           |  |  | 107 |     header ('Location: '.sprintf(PAP_URL_REDIRECTION, $code));
 | 
        
           |  |  | 108 |     exit(0);
 | 
        
           |  |  | 109 | } else {
 | 
        
           |  |  | 110 |     gererErreur404();
 | 
        
           |  |  | 111 | }
 | 
        
           |  |  | 112 |   | 
        
           |  |  | 113 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 114 | // |                                           LISTE de FONCTIONS                                         |
 | 
        
           |  |  | 115 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 116 | function gererErreur404() {
 | 
        
           |  |  | 117 |     // Utilisation de la fonction statique de Pear HTTP pour négocier l'i18n.
 | 
        
           |  |  | 118 |     $aso_i18n_possible = array(GEN_I18N_ID_DEFAUT => true);
 | 
        
           |  |  | 119 |     $i18n = HTTP::negotiateLanguage($aso_i18n_possible, GEN_I18N_ID_DEFAUT);
 | 
        
           |  |  | 120 |     if (file_exists(sprintf(PAP_FICHIER_ERREUR_404, $i18n))) {
 | 
        
           |  |  | 121 |         header ('Location: /'.sprintf(PAP_URL_ERREUR_404, $i18n, $_SERVER['REQUEST_URI']));
 | 
        
           |  |  | 122 |     } else {
 | 
        
           |  |  | 123 |         header('Location: /');
 | 
        
           |  |  | 124 |     }
 | 
        
           |  |  | 125 |     exit(0);
 | 
        
           |  |  | 126 | }
 | 
        
           |  |  | 127 |   | 
        
           |  |  | 128 | /* +--Fin du code ----------------------------------------------------------------------------------------+
 | 
        
           |  |  | 129 | *
 | 
        
           |  |  | 130 | * $Log: not supported by cvs2svn $
 | 
        
           |  |  | 131 | *
 | 
        
           |  |  | 132 | * +-- Fin du code ----------------------------------------------------------------------------------------+
 | 
        
           |  |  | 133 | */
 | 
        
           |  |  | 134 | ?>
 |