Subversion Repositories Applications.papyrus

Rev

Rev 754 | Rev 1125 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 754 Rev 1029
Line 19... Line 19...
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: pap_url.class.php,v 1.3 2006-03-02 10:49:49 ddelon Exp $
24
// CVS : $Id: pap_url.class.php,v 1.4 2006-10-11 18:04:11 jp_milcent Exp $
25
/**
25
/**
26
* Classe de gestion des url de Papyrus
26
* Classe de gestion des url de Papyrus
27
*
27
*
28
* Permet de gérer la réecriture des url.
28
* Permet de gérer la réecriture des url.
29
*
29
*
Line 32... Line 32...
32
//Auteur original :
32
//Auteur original :
33
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
33
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
34
//Autres auteurs :
34
//Autres auteurs :
35
*@author        Aucun
35
*@author        Aucun
36
*@copyright     Tela-Botanica 2000-2004
36
*@copyright     Tela-Botanica 2000-2004
37
*@version       $Revision: 1.3 $ $Date: 2006-03-02 10:49:49 $
37
*@version       $Revision: 1.4 $ $Date: 2006-10-11 18:04:11 $
38
// +------------------------------------------------------------------------------------------------------+
38
// +------------------------------------------------------------------------------------------------------+
39
*/
39
*/
Line 40... Line 40...
40
 
40
 
41
// +------------------------------------------------------------------------------------------------------+
41
// +------------------------------------------------------------------------------------------------------+
Line 51... Line 51...
51
    /** Identifiant du menu
51
    /** Identifiant du menu
52
    *
52
    *
53
    * @var integer
53
    * @var integer
54
    */
54
    */
55
    var $id;
55
    var $id;
-
 
56
    /** Chaine contenant le permalien.
-
 
57
    *
-
 
58
    * @var string
-
 
59
    */
-
 
60
    var $permalien = '';
56
    /** Booléen indiquant si on affiche ou pas un permalien.
61
    /** Booléen indiquant si on affiche ou pas un permalien.
57
    *
62
    *
58
    * @var boolean
63
    * @var boolean
59
    */
64
    */
60
    var $permalien;
65
    var $permalien_bool;
-
 
66
    /** Chaine indiquant le type d'url.
-
 
67
    *
-
 
68
    * @var string
-
 
69
    */
-
 
70
    var $url_type = 'MENU';
61
    /** Code numérique du menu courant
71
    /** Code numérique du menu courant
62
    *
72
    *
63
    * @var integer
73
    * @var integer
64
    */
74
    */
65
    var $code_num;
75
    var $code_num;
Line 74... Line 84...
74
    * @see __construct()
84
    * @see __construct()
75
    */
85
    */
76
    function Pap_URL($url = null, $useBrackets = true)
86
    function Pap_URL($url = null, $useBrackets = true)
77
    {
87
    {
78
        $this->__construct($url, $useBrackets);
88
        $this->__construct($url, $useBrackets);
-
 
89
		// Gestion de la réecriture d'url
-
 
90
		if (defined('PAP_URL_REECRITURE') AND PAP_URL_REECRITURE == '1') {
-
 
91
			$this->setPermalienBool(true);
-
 
92
		}
79
    }
93
    }
80
    /** Méthode setId() - Définit l'id du menu courant
94
    /** Méthode setId() - Définit l'id du menu courant
81
    * 
95
    * 
82
    * @param integer l'identifiant du menu courant.
96
    * @param integer l'identifiant du menu courant.
83
    * @return mixed false en cas d'erreur 
97
    * @return mixed false en cas d'erreur 
Line 101... Line 115...
101
    */
115
    */
102
    function getId()
116
    function getId()
103
    {
117
    {
104
        return $this->id;
118
        return $this->id;
105
    }
119
    }
-
 
120
    /** Méthode setPermalien() - Définit le permaliens
-
 
121
    * 
-
 
122
    * @param string valeur
-
 
123
    * @return mixed false en cas d'erreur 
-
 
124
    * @access public
-
 
125
    */
-
 
126
    function setPermalien($chaine = '')
-
 
127
    {
-
 
128
        // Nous vérifions que l'identifiant est bien un entier
-
 
129
        if (is_string($chaine) && $chaine != '') {
-
 
130
            if ($this->permalien != '') {
-
 
131
            	$this->permalien .= PAP_URL_REECRITURE_SEP;
-
 
132
            } else {
-
 
133
            	$this->permalien = constant('PAP_URL_REECRITURE_'.$this->getUrlType()).PAP_URL_REECRITURE_SEP;
-
 
134
            }
-
 
135
            $this->permalien .= $chaine;
-
 
136
        } else if ($chaine == '') {
-
 
137
        	$this->permalien = '';
-
 
138
        } else {
-
 
139
            return false;
-
 
140
        }
-
 
141
    }
-
 
142
    /** Méthode getPermalien() - Retourne le permalien
-
 
143
    * 
-
 
144
    * @return string le permalien
-
 
145
    * @access public
-
 
146
    */
-
 
147
    function getPermalien()
-
 
148
    {
-
 
149
        return $this->permalien;
-
 
150
    }
-
 
151
    /** Méthode setUrlType() - Définit le type d'URL
-
 
152
    * 
-
 
153
    * @param string type d'URL (SITE ou MENU)
-
 
154
    * @return mixed false en cas d'erreur 
-
 
155
    * @access public
-
 
156
    */
-
 
157
    function setUrlType($type)
-
 
158
    {
-
 
159
        // Nous vérifions que l'identifiant est bien un entier
-
 
160
        if (is_string($type) && ($type == 'MENU' || $type == 'SITE')) {
-
 
161
            $this->url_type = $type;
-
 
162
        } else {
-
 
163
            return false;
-
 
164
        }
-
 
165
    }
-
 
166
    /** Méthode getUrlType() - Retourne le type de l'URL
-
 
167
    * 
-
 
168
    * @return string le type d'URL
-
 
169
    * @access public
-
 
170
    */
-
 
171
    function getUrlType()
-
 
172
    {
-
 
173
        return $this->url_type;
-
 
174
    }
106
    /** Méthode setPermalien() - Définit le type d'utilisation des permaliens
175
    /** Méthode setPermalienBool() - Définit le type d'utilisation des permaliens
107
    * 
176
    * 
108
    * @param boolean true ou false
177
    * @param boolean true ou false
109
    * @return mixed false en cas d'erreur 
178
    * @return mixed false en cas d'erreur 
110
    * @access public
179
    * @access public
111
    */
180
    */
112
    function setPermalien($bool)
181
    function setPermalienBool($bool)
113
    {
182
    {
114
        // Nous vérifions que l'identifiant est bien un entier
183
        // Nous vérifions que l'identifiant est bien un entier
115
        if (is_bool($bool)) {
184
        if (is_bool($bool)) {
116
            $this->permalien = $bool;
185
            $this->permalien_bool = $bool;
117
        } else {
186
        } else {
118
            return false;
187
            return false;
119
        }
188
        }
120
    }
189
    }
121
    /** Méthode getPermalien() - Retourne booléen indiquant si on utilise ou pas les permaliens
190
    /** Méthode getPermalienBool() - Retourne booléen indiquant si on utilise ou pas les permaliens
122
    * 
191
    * 
123
    * @return boolean true ou false
192
    * @return boolean true ou false
124
    * @access public
193
    * @access public
125
    */
194
    */
126
    function getPermalien()
195
    function getPermalienBool()
127
    {
196
    {
128
        return $this->permalien;
197
        return $this->permalien_bool;
129
    }
198
    }
130
    /** Méthode setCodeAlpha() - Définit le code alphanumérique de l'url
199
    /** Méthode setCodeAlpha() - Définit le code alphanumérique de l'url
131
    * 
200
    * 
132
    * @param string le code alphanumérique pour l'url du menu
201
    * @param string le code alphanumérique pour l'url du menu
133
    * @return mixed false en cas d'erreur 
202
    * @return mixed false en cas d'erreur 
Line 180... Line 249...
180
    * @return string l'url complète.
249
    * @return string l'url complète.
181
    * @access public
250
    * @access public
182
    */
251
    */
183
    function getURL()
252
    function getURL()
184
    {
253
    {
185
    	
-
 
186
            
-
 
187
        // identifiant de la langue choisie
254
        // Identifiant de la langue choisie
188
        if ( (isset($GLOBALS['_GEN_commun']['i18n'])) && (!empty($GLOBALS['_GEN_commun']['i18n'])) ) {
255
        if ( (isset($GLOBALS['_GEN_commun']['i18n'])) && (!empty($GLOBALS['_GEN_commun']['i18n'])) ) {
189
        	if ($GLOBALS['_GEN_commun']['i18n']!=GEN_I18N_ID_DEFAUT) {
256
        	if ($GLOBALS['_GEN_commun']['i18n'] != GEN_I18N_ID_DEFAUT) {
190
            	$this->addQueryString(GEN_URL_CLE_I18N, $GLOBALS['_GEN_commun']['i18n']);
257
            	$this->addQueryString(GEN_URL_CLE_I18N, $GLOBALS['_GEN_commun']['i18n']);
191
        	}
258
        	}
192
        }
259
        }
Line 193... Line 260...
193
            
260
            
194
        // Nous regardons si un id de menu existe
261
        // Nous regardons si un id de menu existe
195
        if ($this->getId() != '') {
262
        if ($this->getId() != '') {
196
            // Préparation des noms des champs des codes pour le site et le menu
263
            // Préparation des noms des champs des codes pour le site et le menu
197
            $champs_code_site = (GEN_URL_ID_TYPE_SITE == 'int') ? 'gs_code_num' : 'gs_code_alpha';
264
            $champs_code_site = (GEN_URL_ID_TYPE_SITE == 'int') ? 'gs_code_num' : 'gs_code_alpha';
198
            $champs_code_menu = (GEN_URL_ID_TYPE_MENU == 'int') ? 'gm_code_num' : 'gm_code_alpha';
-
 
-
 
265
            $champs_code_menu = (GEN_URL_ID_TYPE_MENU == 'int') ? 'gm_code_num' : 'gm_code_alpha';
199
            
266
            if ($this->getUrlType() == 'MENU') {
200
            // Récupération du nom de l'entrée du menu à afficher
267
	            // Récupération du nom de l'entrée du menu à afficher
201
            $requete =  'SELECT gm_code_alpha, gm_code_num, gm_ce_i18n, gm_ce_site '.
268
	            $requete =  'SELECT gm_code_alpha, gm_code_num, gm_ce_i18n, gm_ce_site '.
202
                        'FROM gen_menu '.
269
	                        'FROM gen_menu '.
203
                        'WHERE gm_id_menu = '.$this->id.' ';
270
	                        'WHERE gm_id_menu = '.$this->id.' ';
204
            
271
	            
205
            $resultat = $GLOBALS['_GEN_commun']['pear_db']->query($requete);
272
	            $resultat = $GLOBALS['_GEN_commun']['pear_db']->query($requete);
206
            (DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
273
	            (DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
207
            
274
	            
208
            $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
275
	            $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
209
            $resultat->free();
276
	            $resultat->free();
210
            // Nous vérifions si nous avons à faire à un menu commun ou pas
277
	            // Nous vérifions si nous avons à faire à un menu commun ou pas
211
            if ($ligne['gm_ce_site'] != 0) {
278
	            if ($ligne['gm_ce_site'] != 0) {
212
                // Récupération des infos sur le site
279
	                // Récupération des infos sur le site
213
                $bln_url_site = false;
280
	                $bln_url_site = false;
-
 
281
	                $requete_site = 'SELECT gs_code_alpha, gs_code_num '.
-
 
282
	                                'FROM gen_site '.
-
 
283
	                                'WHERE gs_id_site = '.$ligne['gm_ce_site'].' ';
-
 
284
	                
-
 
285
	                $resultat_site = $GLOBALS['_GEN_commun']['pear_db']->query($requete_site);
-
 
286
	                (DB::isError($resultat_site)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_site->getMessage(), $requete_site)) : '';
-
 
287
	                
-
 
288
	                $ligne_site = $resultat_site->fetchRow(DB_FETCHMODE_ASSOC);
-
 
289
	                $resultat_site->free();
-
 
290
	            } else {
-
 
291
	                // Menu commun
-
 
292
	                $bln_url_site = true;
-
 
293
	                $ligne_site[$champs_code_site] = $GLOBALS['_GEN_commun']['info_site']->$champs_code_site;
-
 
294
	            }
-
 
295
	            $this->addQueryString(GEN_URL_CLE_MENU, $ligne[$champs_code_menu]);
-
 
296
            	$this->setCodeAlpha($ligne['gm_code_alpha']);
-
 
297
            	$this->setCodeNum($ligne['gm_code_num']);
-
 
298
            } else if ($this->getUrlType() == 'SITE') {
-
 
299
            	$bln_url_site = true;
214
                $requete_site = 'SELECT gs_code_alpha, gs_code_num '.
300
            	$requete_site = 'SELECT gs_code_alpha, gs_code_num '.
215
                                'FROM gen_site '.
301
                                'FROM gen_site '.
Line 216... Line 302...
216
                                'WHERE gs_id_site = '.$ligne['gm_ce_site'].' ';
302
                                'WHERE gs_id_site = '.$this->getId().' ';
217
                
303
                
Line 218... Line 304...
218
                $resultat_site = $GLOBALS['_GEN_commun']['pear_db']->query($requete_site);
304
                $resultat_site = $GLOBALS['_GEN_commun']['pear_db']->query($requete_site);
219
                (DB::isError($resultat_site)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_site->getMessage(), $requete_site)) : '';
305
                (DB::isError($resultat_site)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_site->getMessage(), $requete_site)) : '';
220
                
-
 
221
                $ligne_site = $resultat_site->fetchRow(DB_FETCHMODE_ASSOC);
-
 
222
                $resultat_site->free();
306
                
223
            } else {
307
                $ligne_site = $resultat_site->fetchRow(DB_FETCHMODE_ASSOC);
224
                // Menu commun
308
                $resultat_site->free();
-
 
309
            	$this->setCodeAlpha($ligne_site['gs_code_alpha']);
225
                $bln_url_site = true;
310
            	$this->setCodeNum($ligne_site['gs_code_num']);
226
                $ligne_site[$champs_code_site] = $GLOBALS['_GEN_commun']['info_site']->$champs_code_site;
311
            }
227
            }
312
            
228
            // Préparation de l'url de l'entrée
313
            // Préparation de l'url de l'entrée
-
 
314
            if ($bln_url_site) {
229
            if ($bln_url_site) {
315
                $this->addQueryString(GEN_URL_CLE_SITE, $ligne_site[$champs_code_site]);
230
                $this->addQueryString(GEN_URL_CLE_SITE, $ligne_site[$champs_code_site]);
316
            }
231
            }
317
            
Line 232... Line 318...
232
            $this->addQueryString(GEN_URL_CLE_MENU, $ligne[$champs_code_menu]);
318
            if ( (isset($GLOBALS['_GEN_commun']['url_i18n'])) && (!empty($GLOBALS['_GEN_commun']['url_i18n'])) ) {
233
            $this->setCodeAlpha($ligne['gm_code_alpha']);
319
                $this->addQueryString(GEN_URL_CLE_I18N, $GLOBALS['_GEN_commun']['url_i18n']);
234
            $this->setCodeNum($ligne['gm_code_num']);
320
            }
Line 235... Line 321...
235
            
321
            
236
            if ( (isset($GLOBALS['_GEN_commun']['url_date'])) && (!empty($GLOBALS['_GEN_commun']['url_date'])) ) {
322
            if ( (isset($GLOBALS['_GEN_commun']['url_date'])) && (!empty($GLOBALS['_GEN_commun']['url_date'])) ) {
237
                $this->addQueryString(GEN_URL_CLE_DATE, $GLOBALS['_GEN_commun']['url_date']);
323
                $this->addQueryString(GEN_URL_CLE_DATE, $GLOBALS['_GEN_commun']['url_date']);
238
            }
324
            }
Line 239... Line -...
239
            
-
 
240
            if ( (isset($GLOBALS['_GEN_commun']['url_format'])) && (!empty($GLOBALS['_GEN_commun']['url_format'])) ) {
-
 
241
                $this->addQueryString(GEN_URL_CLE_FORMAT, $GLOBALS['_GEN_commun']['url_format']);
-
 
242
            }
-
 
243
        }
-
 
244
        
-
 
245
        // Gestion temporéraire de la réecriture
-
 
246
        if (defined('PAP_URL_REECRITURE') AND PAP_URL_REECRITURE == 1) {
-
 
247
            $this->setPermalien(true);
-
 
248
        }
-
 
249
        /*A FAIRE : gestion des urls permanente et réecrite compléte avec format, date...
-
 
250
            
-
 
251
            // Ajout des composant de l'url absolu du document courant
-
 
252
            if ($site = $this->retournerUnParametre(GEN_URL_CLE_SITE)) {
-
 
253
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_SITE.'_'.$site;
-
 
254
                $this->removeQueryString(GEN_URL_CLE_SITE);
-
 
255
            }
-
 
256
            if ($menu = $this->retournerUnParametre(GEN_URL_CLE_MENU)) {
-
 
257
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_MENU.'_'.$menu;
-
 
258
                $this->removeQueryString(GEN_URL_CLE_MENU);
-
 
259
            }
-
 
260
            if ($i18n = $this->retournerUnParametre(GEN_URL_CLE_I18N)) {
-
 
261
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_I18N.'_'.$i18n;
-
 
262
                $this->removeQueryString(GEN_URL_CLE_I18N);
-
 
263
            }
-
 
264
            if ($date = $this->retournerUnParametre(GEN_URL_CLE_DATE)) {
-
 
265
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_DATE.'_'.$date;
-
 
266
                $this->removeQueryString(GEN_URL_CLE_DATE);
-
 
267
            }
-
 
268
            if ($format = $this->retournerUnParametre(GEN_URL_CLE_FORMAT)) {
-
 
269
                $this->path .= DIRECTORY_SEPARATOR.GEN_URL_CLE_FORMAT.'_'.$format;
-
 
270
                $this->removeQueryString(GEN_URL_CLE_FORMAT);
325
            
271
            }
326
            if ( (isset($GLOBALS['_GEN_commun']['url_format'])) && (!empty($GLOBALS['_GEN_commun']['url_format'])) ) {
272
            echo $this->path.'<br>';
327
                $this->addQueryString(GEN_URL_CLE_FORMAT, $GLOBALS['_GEN_commun']['url_format']);
273
        }
328
            }
-
 
329
        }
-
 
330
        
274
        */
331
		// Construction du permalien ou pas
275
        
332
        if ($this->getPermalienBool()) {
276
        // Construction du permalien ou pas
333
            // Récupération du chemin jusqu'au fichier principal de Papyrus
277
        if ($this->getPermalien()) {
334
            $this->path = (dirname($this->path) == DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : dirname($this->path).DIRECTORY_SEPARATOR;
278
            // Récupération du chemin jusqu'au fichier principal de Papyrus
335
            // On vide le permalien construite par les appels à getUrl() avant de le remplir
-
 
336
            $this->setPermalien();
-
 
337
            if (constant('GEN_URL_RACCOURCI_ID_TYPE_'.$this->getUrlType()) == 'int') {
279
            $this->path = (dirname($this->path) == DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : dirname($this->path);
338
                $this->setPermalien($this->getCodeNum());
280
            if (GEN_URL_RACCOURCI_ID_TYPE_MENU == 'int') {
339
            } else {
281
                $this->path .= $this->getCodeNum();
340
                $this->setPermalien($this->getCodeAlpha());
282
            } else {
341
            }
Line 283... Line 342...
283
                $this->path .= $this->getCodeAlpha();
342
			$this->removeQueryString(GEN_URL_CLE_SITE);
284
            }
343
            $this->removeQueryString(GEN_URL_CLE_MENU);
285
            $querystring = '';
344
            $querystring = $this->getQueryString();
286
        } else {
345
        } else {
287
            $querystring = $this->getQueryString();
346
            $querystring = $this->getQueryString();
288
        }
347
        }
-
 
348
        
289
        
349
        // Construction de l'url
290
        // Construction de l'url
350
        $this->url = $this->protocol . '://'
Line 291... Line 351...
291
        $this->url = $this->protocol . '://'
351
                   . $this->user . (!empty($this->pass) ? ':' : '')
292
                   . $this->user . (!empty($this->pass) ? ':' : '')
352
                   . $this->pass . (!empty($this->user) ? '@' : '')
Line 312... Line 372...
312
            }
372
            }
313
        }
373
        }
Line 314... Line 374...
314
        
374
        
315
        return FALSE;
375
        return FALSE;
-
 
376
    }
316
    }
377
 
Line 317... Line 378...
317
}
378
}
318
 
379
 
319
// +------------------------------------------------------------------------------------------------------+
380
// +------------------------------------------------------------------------------------------------------+
Line 323... Line 384...
323
 
384
 
324
 
385
 
325
/* +--Fin du code ----------------------------------------------------------------------------------------+
386
/* +--Fin du code ----------------------------------------------------------------------------------------+
-
 
387
*
-
 
388
* $Log: not supported by cvs2svn $
-
 
389
* Revision 1.3  2006/03/02 10:49:49  ddelon
326
*
390
* Fusion branche multilinguisme dans branche principale
327
* $Log: not supported by cvs2svn $
391
*
328
* Revision 1.2.2.1  2005/12/27 15:56:00  ddelon
392
* Revision 1.2.2.1  2005/12/27 15:56:00  ddelon
329
* Fusion Head vers multilinguisme (wikini double clic)
393
* Fusion Head vers multilinguisme (wikini double clic)
330
*
394
*
Line 335... Line 399...
335
* Ajout de la classe URL de Papyrus.
399
* Ajout de la classe URL de Papyrus.
336
*
400
*
337
*
401
*
338
* +-- Fin du code ----------------------------------------------------------------------------------------+
402
* +-- Fin du code ----------------------------------------------------------------------------------------+
339
*/
403
*/
340
?>
-
 
341
404
?>
-
 
405