Subversion Repositories Sites.tela-botanica.org

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 david 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.2 2005/05/26 08:51:55 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.2 $ $Date: 2005/05/26 08:51:55 $
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
$raccourci = $tab_raccourci[1];
88
$parametres = '';
89
if (isset($tab_raccourci[2])) {
90
    $parametres = $tab_raccourci[2];
91
}
92
// Nous cherchons à savoir si le raccourci est entièrement numérique ou pas.
93
if (preg_match('/^[0-9]+$/', $raccourci)) {
94
    // Nous vérifions si nous utilisons les codes numériques ou alphanumérique dans les url
95
    if (GEN_URL_ID_TYPE_MENU != 'int') {
96
        $code = GEN_retournerMenuCodeAlpha($bdd, $raccourci);
97
    } else {
98
        $code = $raccourci;
99
    }
100
} else {
101
    // Nous vérifions si nous utilisons les codes numériques ou alphanumérique dans les url
102
    if (GEN_URL_ID_TYPE_MENU != 'int') {
103
        $code = $raccourci;
104
    } else {
105
        $code = GEN_retournerMenuCodeNum($bdd, $raccourci);
106
    }
107
}
108
if ($code != '') {
109
    // Nous effectuons la redirection:
110
    if (!empty($parametres)) {
111
        header ('Location: '.sprintf(PAP_URL_REDIRECTION, $code).'&'.$parametres);
112
    } else {
113
        header ('Location: '.sprintf(PAP_URL_REDIRECTION, $code));
114
    }
115
    header('Status: 303');
116
    exit(0);
117
} else {
118
    gererErreur404();
119
}
120
 
121
// +------------------------------------------------------------------------------------------------------+
122
// |                                           LISTE de FONCTIONS                                         |
123
// +------------------------------------------------------------------------------------------------------+
124
function gererErreur404() {
125
    // Utilisation de la fonction statique de Pear HTTP pour négocier l'i18n.
126
    $aso_i18n_possible = array(GEN_I18N_ID_DEFAUT => true);
127
    $i18n = HTTP::negotiateLanguage($aso_i18n_possible, GEN_I18N_ID_DEFAUT);
128
    if (file_exists(sprintf(PAP_FICHIER_ERREUR_404, $i18n))) {
129
        header ('Location: /'.sprintf(PAP_URL_ERREUR_404, $i18n, $_SERVER['REQUEST_URI']));
130
    } else {
131
        header('Location: /');
132
    }
133
    exit(0);
134
}
135
 
136
/* +--Fin du code ----------------------------------------------------------------------------------------+
137
*
138
* $Log: erreur_404.php,v $
139
* Revision 1.2  2005/05/26 08:51:55  jpm
140
* Correction bogue du à la gestion des paramêtres.
141
*
142
* Revision 1.1  2005/03/30 08:58:32  jpm
143
* Ajout du fichier gérant les erreurs 404 et les redirections.
144
*
145
*
146
* +-- Fin du code ----------------------------------------------------------------------------------------+
147
*/
148
?>