New file |
0,0 → 1,148 |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 4.1 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This file is part of Papyrus. | |
// | | |
// | Foobar is free software; you can redistribute it and/or modify | |
// | it under the terms of the GNU General Public License as published by | |
// | the Free Software Foundation; either version 2 of the License, or | |
// | (at your option) any later version. | |
// | | |
// | Foobar is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// | GNU General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU General Public License | |
// | along with Foobar; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: erreur_404.php,v 1.2 2005/05/26 08:51:55 jpm Exp $ |
/** |
* Redirection de page |
* |
* Permet d'utiliser la redirection de page. |
* |
*@package Papyrus |
//Auteur original : |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
//Autres auteurs : |
*@author Aucun |
*@copyright Tela-Botanica 2000-2005 |
*@version $Revision: 1.2 $ $Date: 2005/05/26 08:51:55 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
|
// +------------------------------------------------------------------------------------------------------+ |
// | ENTETE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
// Définission de constantes |
/** Chemin et nom du fichier de configuration principal de Papyrus.*/ |
define('PAP_FICHIER_CONFIG', 'papyrus/configuration/pap_config.inc.php'); |
/** Chemin et nom du fichier de configuration avancée de Papyrus.*/ |
define('PAP_FICHIER_CONFIG_AVANCEE', 'papyrus/configuration/pap_config_avancee.inc.php'); |
/** Chemin et nom du fichier des fonctions manipulant les menus de Papyrus.*/ |
define('PAP_FICHIER_FONCTION_MENU', 'papyrus/bibliotheque/fonctions/pap_menu.fonct.php'); |
/** Chemin et nom du fichier Pear DB.*/ |
define('PAP_FICHIER_PEAR_DB', 'api/pear/DB.php'); |
/** Chemin et nom du fichier Pear HTTP.*/ |
define('PAP_FICHIER_PEAR_HTTP', 'api/pear/HTTP.php'); |
/** Chemin et nom du fichier affichant une erreur 404.*/ |
define('PAP_FICHIER_ERREUR_404', 'sites/commun/%s/http_erreurs/erreur404.php'); |
/** Chemin et nom du fichier affichant une erreur 404.*/ |
define('PAP_URL_ERREUR_404', 'sites/commun/%s/http_erreurs/erreur404.php?url=%s'); |
/** Url où rediriger une page.*/ |
define('PAP_URL_REDIRECTION', '/papyrus.php?menu=%s'); |
|
if (file_exists(PAP_FICHIER_CONFIG) && file_exists(PAP_FICHIER_FONCTION_MENU) && file_exists(PAP_FICHIER_CONFIG_AVANCEE) && |
file_exists(PAP_FICHIER_PEAR_DB) && file_exists(PAP_FICHIER_PEAR_HTTP)) { |
/** Inclusion du fichier de configuration de Papyrus permettant de se conecter à la base de données. */ |
require_once PAP_FICHIER_CONFIG; |
/** Inclusion du fichier de configuration de Papyrus permettant d'avoir des infos sur la structure de l'url. */ |
require_once PAP_FICHIER_CONFIG_AVANCEE; |
/** Inclusion du fichier de contenant les fonctions de manipulation des informations sur les menus de Papyrus. */ |
require_once PAP_FICHIER_FONCTION_MENU; |
/** Inclusion de la classe PEAR d'abstraction de base de donnée. */ |
require_once PAP_FICHIER_PEAR_DB; |
/** Inclusion de l'objet PEAR servant à négocier le language avec le navigateur client. */ |
require_once PAP_FICHIER_PEAR_HTTP; |
} else { |
gererErreur404(); |
} |
|
// +------------------------------------------------------------------------------------------------------+ |
// | CORPS du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
// +------------------------------------------------------------------------------------------------------+ |
// Tentative de Connexion à la base de données et de récupération de l'URI demandée. |
$bdd = DB::connect(PAP_DSN); |
if (DB::isError($bdd) || empty($_SERVER['REQUEST_URI'])) { |
gererErreur404(); |
} |
preg_match('/^\/(.*?)(?:\?(.*)|)$/', $_SERVER['REQUEST_URI'], $tab_raccourci); |
$raccourci = $tab_raccourci[1]; |
$parametres = ''; |
if (isset($tab_raccourci[2])) { |
$parametres = $tab_raccourci[2]; |
} |
// Nous cherchons à savoir si le raccourci est entièrement numérique ou pas. |
if (preg_match('/^[0-9]+$/', $raccourci)) { |
// Nous vérifions si nous utilisons les codes numériques ou alphanumérique dans les url |
if (GEN_URL_ID_TYPE_MENU != 'int') { |
$code = GEN_retournerMenuCodeAlpha($bdd, $raccourci); |
} else { |
$code = $raccourci; |
} |
} else { |
// Nous vérifions si nous utilisons les codes numériques ou alphanumérique dans les url |
if (GEN_URL_ID_TYPE_MENU != 'int') { |
$code = $raccourci; |
} else { |
$code = GEN_retournerMenuCodeNum($bdd, $raccourci); |
} |
} |
if ($code != '') { |
// Nous effectuons la redirection: |
if (!empty($parametres)) { |
header ('Location: '.sprintf(PAP_URL_REDIRECTION, $code).'&'.$parametres); |
} else { |
header ('Location: '.sprintf(PAP_URL_REDIRECTION, $code)); |
} |
header('Status: 303'); |
exit(0); |
} else { |
gererErreur404(); |
} |
|
// +------------------------------------------------------------------------------------------------------+ |
// | LISTE de FONCTIONS | |
// +------------------------------------------------------------------------------------------------------+ |
function gererErreur404() { |
// Utilisation de la fonction statique de Pear HTTP pour négocier l'i18n. |
$aso_i18n_possible = array(GEN_I18N_ID_DEFAUT => true); |
$i18n = HTTP::negotiateLanguage($aso_i18n_possible, GEN_I18N_ID_DEFAUT); |
if (file_exists(sprintf(PAP_FICHIER_ERREUR_404, $i18n))) { |
header ('Location: /'.sprintf(PAP_URL_ERREUR_404, $i18n, $_SERVER['REQUEST_URI'])); |
} else { |
header('Location: /'); |
} |
exit(0); |
} |
|
/* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log: erreur_404.php,v $ |
* Revision 1.2 2005/05/26 08:51:55 jpm |
* Correction bogue du à la gestion des paramêtres. |
* |
* Revision 1.1 2005/03/30 08:58:32 jpm |
* Ajout du fichier gérant les erreurs 404 et les redirections. |
* |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |
?> |