Subversion Repositories Applications.papyrus

Rev

Rev 323 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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