Subversion Repositories Applications.papyrus

Rev

Rev 377 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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