Subversion Repositories Applications.papyrus

Rev

Rev 333 | Rev 754 | Go to most recent revision | Details | Compare with Previous | 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
// +------------------------------------------------------------------------------------------------------+
343 jpm 24
// CVS : $Id: pap_url.class.php,v 1.2 2005-04-18 16:40:50 jpm Exp $
333 jpm 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
343 jpm 37
*@version       $Revision: 1.2 $ $Date: 2005-04-18 16:40:50 $
333 jpm 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;
343 jpm 56
    /** Booléen indiquant si on affiche ou pas un permalien.
57
    *
58
    * @var boolean
59
    */
60
    var $permalien;
61
    /** Code numérique du menu courant
62
    *
63
    * @var integer
64
    */
65
    var $code_num;
66
    /** Code alphanumérique du menu courant
67
    *
68
    * @var string
69
    */
70
    var $code_alpha;
333 jpm 71
    /**
72
    * PHP4 Constructeur
73
    *
74
    * @see __construct()
75
    */
76
    function Pap_URL($url = null, $useBrackets = true)
77
    {
78
        $this->__construct($url, $useBrackets);
79
    }
80
    /** Méthode setId() - Définit l'id du menu courant
81
    *
82
    * @param integer l'identifiant du menu courant.
83
    * @return mixed false en cas d'erreur
84
    * @access public
85
    */
86
    function setId($id)
87
    {
88
        // Nous transformons en entier l'identifiant
89
        settype($id, "integer");
90
        // Nous vérifions que l'identifiant est bien un entier
91
        if (is_integer($id)) {
92
            $this->id = $id;
93
        } else {
94
            return false;
95
        }
96
    }
97
    /** Méthode getId() - Retourne l'id du menu courant
98
    *
99
    * @return integer l'identifiant du menu courant.
100
    * @access public
101
    */
102
    function getId()
103
    {
104
        return $this->id;
105
    }
343 jpm 106
    /** Méthode setPermalien() - Définit le type d'utilisation des permaliens
107
    *
108
    * @param boolean true ou false
109
    * @return mixed false en cas d'erreur
110
    * @access public
111
    */
112
    function setPermalien($bool)
113
    {
114
        // Nous vérifions que l'identifiant est bien un entier
115
        if (is_bool($bool)) {
116
            $this->permalien = $bool;
117
        } else {
118
            return false;
119
        }
120
    }
121
    /** Méthode getPermalien() - Retourne booléen indiquant si on utilise ou pas les permaliens
122
    *
123
    * @return boolean true ou false
124
    * @access public
125
    */
126
    function getPermalien()
127
    {
128
        return $this->permalien;
129
    }
130
    /** Méthode setCodeAlpha() - Définit le code alphanumérique de l'url
131
    *
132
    * @param string le code alphanumérique pour l'url du menu
133
    * @return mixed false en cas d'erreur
134
    * @access public
135
    */
136
    function setCodeAlpha($code_alpha)
137
    {
138
        if (is_string($code_alpha)) {
139
            $this->code_alpha = $code_alpha;
140
        } else {
141
            return false;
142
        }
143
    }
144
    /** Méthode getCodeNum() - Retourne le code numérique de l'url
145
    *
146
    * @return string le code numérique pour l'url du menu
147
    * @access public
148
    */
149
    function getCodeNum()
150
    {
151
        return $this->code_num;
152
    }
153
    /** Méthode setCodeNum() - Définit le code numérique de l'url
154
    *
155
    * @param string le code numérique pour l'url du menu
156
    * @return mixed false en cas d'erreur
157
    * @access public
158
    */
159
    function setCodeNum($code_num)
160
    {
161
        if (is_integer($code_num)) {
162
            $this->code_num = $code_num;
163
        } else {
164
            return false;
165
        }
166
    }
167
 
168
    /** Méthode getCodeAlpha() - Retourne le code alphanumérique de l'url
169
    *
170
    * @return string le code alphanumérique pour l'url du menu
171
    * @access public
172
    */
173
    function getCodeAlpha()
174
    {
175
        return $this->code_alpha;
176
    }
333 jpm 177
    /**
178
    * Méthode getURL() - Retourne l'url
179
    *
180
    * @return string l'url complète.
181
    * @access public
182
    */
183
    function getURL()
184
    {
343 jpm 185
        // Nous regardons si un id de menu existe
333 jpm 186
        if ($this->getId() != '') {
187
            // Préparation des noms des champs des codes pour le site et le menu
188
            $champs_code_site = (GEN_URL_ID_TYPE_SITE == 'int') ? 'gs_code_num' : 'gs_code_alpha';
189
            $champs_code_menu = (GEN_URL_ID_TYPE_MENU == 'int') ? 'gm_code_num' : 'gm_code_alpha';
190
 
191
            // Récupération du nom de l'entrée du menu à afficher
343 jpm 192
            $requete =  'SELECT gm_code_alpha, gm_code_num, gm_ce_i18n, gm_ce_site '.
333 jpm 193
                        'FROM gen_menu '.
194
                        'WHERE gm_id_menu = '.$this->id.' ';
195
 
196
            $resultat = $GLOBALS['_GEN_commun']['pear_db']->query($requete);
197
            (DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
198
 
199
            $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
200
            $resultat->free();
201
            // Nous vérifions si nous avons à faire à un menu commun ou pas
202
            if ($ligne['gm_ce_site'] != 0) {
203
                // Récupération des infos sur le site
204
                $bln_url_site = false;
343 jpm 205
                $requete_site = 'SELECT gs_code_alpha, gs_code_num '.
333 jpm 206
                                'FROM gen_site '.
207
                                'WHERE gs_id_site = '.$ligne['gm_ce_site'].' ';
208
 
209
                $resultat_site = $GLOBALS['_GEN_commun']['pear_db']->query($requete_site);
210
                (DB::isError($resultat_site)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_site->getMessage(), $requete_site)) : '';
211
 
212
                $ligne_site = $resultat_site->fetchRow(DB_FETCHMODE_ASSOC);
213
                $resultat_site->free();
214
            } else {
215
                // Menu commun
216
                $bln_url_site = true;
217
                $ligne_site[$champs_code_site] = $GLOBALS['_GEN_commun']['info_site']->$champs_code_site;
218
            }
219
            // Préparation de l'url de l'entrée
220
            if ($bln_url_site) {
221
                $this->addQueryString(GEN_URL_CLE_SITE, $ligne_site[$champs_code_site]);
222
            }
223
            $this->addQueryString(GEN_URL_CLE_MENU, $ligne[$champs_code_menu]);
343 jpm 224
            $this->setCodeAlpha($ligne['gm_code_alpha']);
225
            $this->setCodeNum($ligne['gm_code_num']);
333 jpm 226
 
227
            if ( (isset($GLOBALS['_GEN_commun']['url_i18n'])) && (!empty($GLOBALS['_GEN_commun']['url_i18n'])) ) {
228
                $this->addQueryString(GEN_URL_CLE_I18N, $GLOBALS['_GEN_commun']['url_i18n']);
229
            }
230
 
231
            if ( (isset($GLOBALS['_GEN_commun']['url_date'])) && (!empty($GLOBALS['_GEN_commun']['url_date'])) ) {
232
                $this->addQueryString(GEN_URL_CLE_DATE, $GLOBALS['_GEN_commun']['url_date']);
233
            }
234
 
235
            if ( (isset($GLOBALS['_GEN_commun']['url_format'])) && (!empty($GLOBALS['_GEN_commun']['url_format'])) ) {
236
                $this->addQueryString(GEN_URL_CLE_FORMAT, $GLOBALS['_GEN_commun']['url_format']);
237
            }
238
        }
343 jpm 239
 
240
        // Gestion temporéraire de la réecriture
333 jpm 241
        if (defined('PAP_URL_REECRITURE') AND PAP_URL_REECRITURE == 1) {
343 jpm 242
            $this->setPermalien(true);
243
        }
244
        /*A FAIRE : gestion des urls permanente et réecrite compléte avec format, date...
333 jpm 245
 
246
            // Ajout des composant de l'url absolu du document courant
247
            if ($site = $this->retournerUnParametre(GEN_URL_CLE_SITE)) {
248
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_SITE.'_'.$site;
249
                $this->removeQueryString(GEN_URL_CLE_SITE);
250
            }
251
            if ($menu = $this->retournerUnParametre(GEN_URL_CLE_MENU)) {
252
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_MENU.'_'.$menu;
253
                $this->removeQueryString(GEN_URL_CLE_MENU);
254
            }
255
            if ($i18n = $this->retournerUnParametre(GEN_URL_CLE_I18N)) {
256
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_I18N.'_'.$i18n;
257
                $this->removeQueryString(GEN_URL_CLE_I18N);
258
            }
259
            if ($date = $this->retournerUnParametre(GEN_URL_CLE_DATE)) {
260
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_DATE.'_'.$date;
261
                $this->removeQueryString(GEN_URL_CLE_DATE);
262
            }
263
            if ($format = $this->retournerUnParametre(GEN_URL_CLE_FORMAT)) {
264
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_FORMAT.'_'.$format;
265
                $this->removeQueryString(GEN_URL_CLE_FORMAT);
266
            }
267
            echo $this->path.'<br>';
268
        }
269
        */
343 jpm 270
 
271
        // Construction du permalien ou pas
272
        if ($this->getPermalien()) {
273
            // Récupération du chemin jusqu'au fichier principal de Papyrus
274
            $this->path = (dirname($this->path) == DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : dirname($this->path);
275
            if (GEN_URL_RACCOURCI_ID_TYPE_MENU == 'int') {
276
                $this->path .= $this->getCodeNum();
277
            } else {
278
                $this->path .= $this->getCodeAlpha();
279
            }
280
            $querystring = '';
281
        } else {
282
            $querystring = $this->getQueryString();
283
        }
284
 
285
        // Construction de l'url
333 jpm 286
        $this->url = $this->protocol . '://'
287
                   . $this->user . (!empty($this->pass) ? ':' : '')
288
                   . $this->pass . (!empty($this->user) ? '@' : '')
289
                   . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
290
                   . $this->path
291
                   . (!empty($querystring) ? '?' . $querystring : '')
292
                   . (!empty($this->anchor) ? '#' . $this->anchor : '');
293
 
294
        return $this->url;
295
    }
296
 
297
    /** Méthode retournant la valeur d'un paramêtre de l'URL.
298
    *
299
    * @return mixed la valeur du paramêtre demandé ou false
300
    * @access public
301
    */
302
    function retournerUnParametre($parametre)
303
    {
304
        if (!empty($this->querystring)) {
305
            if (isset($this->querystring[$parametre])) {
306
                return $this->querystring[$parametre];
307
            }
308
        }
309
 
310
        return FALSE;
311
    }
312
}
313
 
314
// +------------------------------------------------------------------------------------------------------+
315
// |                                            PIED du PROGRAMME                                         |
316
// +------------------------------------------------------------------------------------------------------+
317
 
318
 
319
 
320
/* +--Fin du code ----------------------------------------------------------------------------------------+
321
*
322
* $Log: not supported by cvs2svn $
343 jpm 323
* Revision 1.1  2005/04/14 13:56:25  jpm
324
* Ajout de la classe URL de Papyrus.
333 jpm 325
*
343 jpm 326
*
333 jpm 327
* +-- Fin du code ----------------------------------------------------------------------------------------+
328
*/
329
?>