Subversion Repositories Applications.papyrus

Rev

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

Rev Author Line No. Line
333 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: pap_url.class.php,v 1.1 2005-04-14 13:56:25 jpm Exp $
25
/**
26
* Classe de gestion des url de Papyrus
27
*
28
* Permet de gérer la réecriture des url.
29
*
30
*@package Papyrus
31
*@subpackage Classes
32
//Auteur original :
33
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
34
//Autres auteurs :
35
*@author        Aucun
36
*@copyright     Tela-Botanica 2000-2004
37
*@version       $Revision: 1.1 $ $Date: 2005-04-14 13:56:25 $
38
// +------------------------------------------------------------------------------------------------------+
39
*/
40
 
41
// +------------------------------------------------------------------------------------------------------+
42
// |                                            ENTETE du PROGRAMME                                       |
43
// +------------------------------------------------------------------------------------------------------+
44
 
45
 
46
 
47
// +------------------------------------------------------------------------------------------------------+
48
// |                                            CORPS du PROGRAMME                                        |
49
// +------------------------------------------------------------------------------------------------------+
50
class Pap_URL extends Net_URL {
51
    /** Identifiant du menu
52
    *
53
    * @var integer
54
    */
55
    var $id;
56
    /**
57
    * PHP4 Constructeur
58
    *
59
    * @see __construct()
60
    */
61
    function Pap_URL($url = null, $useBrackets = true)
62
    {
63
        $this->__construct($url, $useBrackets);
64
    }
65
    /** Méthode setId() - Définit l'id du menu courant
66
    *
67
    * @param integer l'identifiant du menu courant.
68
    * @return mixed false en cas d'erreur
69
    * @access public
70
    */
71
    function setId($id)
72
    {
73
        // Nous transformons en entier l'identifiant
74
        settype($id, "integer");
75
        // Nous vérifions que l'identifiant est bien un entier
76
        if (is_integer($id)) {
77
            $this->id = $id;
78
        } else {
79
            return false;
80
        }
81
    }
82
    /** Méthode getId() - Retourne l'id du menu courant
83
    *
84
    * @return integer l'identifiant du menu courant.
85
    * @access public
86
    */
87
    function getId()
88
    {
89
        return $this->id;
90
    }
91
    /**
92
    * Méthode getURL() - Retourne l'url
93
    *
94
    * @return string l'url complète.
95
    * @access public
96
    */
97
    function getURL()
98
    {
99
        if ($this->getId() != '') {
100
            // Préparation des noms des champs des codes pour le site et le menu
101
            $champs_code_site = (GEN_URL_ID_TYPE_SITE == 'int') ? 'gs_code_num' : 'gs_code_alpha';
102
            $champs_code_menu = (GEN_URL_ID_TYPE_MENU == 'int') ? 'gm_code_num' : 'gm_code_alpha';
103
 
104
            // Récupération du nom de l'entrée du menu à afficher
105
            $requete =  'SELECT '.$champs_code_menu.', gm_ce_i18n, gm_ce_site '.
106
                        'FROM gen_menu '.
107
                        'WHERE gm_id_menu = '.$this->id.' ';
108
 
109
            $resultat = $GLOBALS['_GEN_commun']['pear_db']->query($requete);
110
            (DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
111
 
112
            $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
113
            $resultat->free();
114
            // Nous vérifions si nous avons à faire à un menu commun ou pas
115
            if ($ligne['gm_ce_site'] != 0) {
116
                // Récupération des infos sur le site
117
                $bln_url_site = false;
118
                $requete_site = 'SELECT '.$champs_code_site.' '.
119
                                'FROM gen_site '.
120
                                'WHERE gs_id_site = '.$ligne['gm_ce_site'].' ';
121
 
122
                $resultat_site = $GLOBALS['_GEN_commun']['pear_db']->query($requete_site);
123
                (DB::isError($resultat_site)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_site->getMessage(), $requete_site)) : '';
124
 
125
                $ligne_site = $resultat_site->fetchRow(DB_FETCHMODE_ASSOC);
126
                $resultat_site->free();
127
            } else {
128
                // Menu commun
129
                $bln_url_site = true;
130
                $ligne_site[$champs_code_site] = $GLOBALS['_GEN_commun']['info_site']->$champs_code_site;
131
            }
132
            // Préparation de l'url de l'entrée
133
            if ($bln_url_site) {
134
                $this->addQueryString(GEN_URL_CLE_SITE, $ligne_site[$champs_code_site]);
135
            }
136
            $this->addQueryString(GEN_URL_CLE_MENU, $ligne[$champs_code_menu]);
137
 
138
            if ( (isset($GLOBALS['_GEN_commun']['url_i18n'])) && (!empty($GLOBALS['_GEN_commun']['url_i18n'])) ) {
139
                $this->addQueryString(GEN_URL_CLE_I18N, $GLOBALS['_GEN_commun']['url_i18n']);
140
            }
141
 
142
            if ( (isset($GLOBALS['_GEN_commun']['url_date'])) && (!empty($GLOBALS['_GEN_commun']['url_date'])) ) {
143
                $this->addQueryString(GEN_URL_CLE_DATE, $GLOBALS['_GEN_commun']['url_date']);
144
            }
145
 
146
            if ( (isset($GLOBALS['_GEN_commun']['url_format'])) && (!empty($GLOBALS['_GEN_commun']['url_format'])) ) {
147
                $this->addQueryString(GEN_URL_CLE_FORMAT, $GLOBALS['_GEN_commun']['url_format']);
148
            }
149
        }
150
        /* A FAIRE : gestion des urls permanente et réecrite
151
        if (defined('PAP_URL_REECRITURE') AND PAP_URL_REECRITURE == 1) {
152
            // Récupération du chemin jusqu'au fichier principal de Papyrus
153
            $this->path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
154
 
155
            // Ajout des composant de l'url absolu du document courant
156
            if ($site = $this->retournerUnParametre(GEN_URL_CLE_SITE)) {
157
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_SITE.'_'.$site;
158
                $this->removeQueryString(GEN_URL_CLE_SITE);
159
            }
160
            if ($menu = $this->retournerUnParametre(GEN_URL_CLE_MENU)) {
161
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_MENU.'_'.$menu;
162
                $this->removeQueryString(GEN_URL_CLE_MENU);
163
            }
164
            if ($i18n = $this->retournerUnParametre(GEN_URL_CLE_I18N)) {
165
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_I18N.'_'.$i18n;
166
                $this->removeQueryString(GEN_URL_CLE_I18N);
167
            }
168
            if ($date = $this->retournerUnParametre(GEN_URL_CLE_DATE)) {
169
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_DATE.'_'.$date;
170
                $this->removeQueryString(GEN_URL_CLE_DATE);
171
            }
172
            if ($format = $this->retournerUnParametre(GEN_URL_CLE_FORMAT)) {
173
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_FORMAT.'_'.$format;
174
                $this->removeQueryString(GEN_URL_CLE_FORMAT);
175
            }
176
            echo $this->path.'<br>';
177
        }
178
        */
179
        $querystring = $this->getQueryString();
180
        $this->url = $this->protocol . '://'
181
                   . $this->user . (!empty($this->pass) ? ':' : '')
182
                   . $this->pass . (!empty($this->user) ? '@' : '')
183
                   . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
184
                   . $this->path
185
                   . (!empty($querystring) ? '?' . $querystring : '')
186
                   . (!empty($this->anchor) ? '#' . $this->anchor : '');
187
 
188
        return $this->url;
189
    }
190
 
191
    /** Méthode retournant la valeur d'un paramêtre de l'URL.
192
    *
193
    * @return mixed la valeur du paramêtre demandé ou false
194
    * @access public
195
    */
196
    function retournerUnParametre($parametre)
197
    {
198
        if (!empty($this->querystring)) {
199
            if (isset($this->querystring[$parametre])) {
200
                return $this->querystring[$parametre];
201
            }
202
        }
203
 
204
        return FALSE;
205
    }
206
}
207
 
208
// +------------------------------------------------------------------------------------------------------+
209
// |                                            PIED du PROGRAMME                                         |
210
// +------------------------------------------------------------------------------------------------------+
211
 
212
 
213
 
214
/* +--Fin du code ----------------------------------------------------------------------------------------+
215
*
216
* $Log: not supported by cvs2svn $
217
*
218
* +-- Fin du code ----------------------------------------------------------------------------------------+
219
*/
220
?>