Subversion Repositories Applications.papyrus

Rev

Rev 2074 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1128 jp_milcent 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
2074 Jean-Pasca 4
// | PHP version 5.1																						|
1128 jp_milcent 5
// +------------------------------------------------------------------------------------------------------+
2074 Jean-Pasca 6
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org)								|
1128 jp_milcent 7
// +------------------------------------------------------------------------------------------------------+
2074 Jean-Pasca 8
// | This file is part of papyrus_bp.																	|
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							|
1128 jp_milcent 23
// +------------------------------------------------------------------------------------------------------+
24
/**
25
* papyrus_bp - lien.php
26
*
27
* Description :
28
*
29
*@package papyrus_bp
30
//Auteur original :
2074 Jean-Pasca 31
*@author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
1128 jp_milcent 32
//Autres auteurs :
2074 Jean-Pasca 33
*@author		Aucun
34
*@copyright	 Tela-Botanica 1999-2006
35
*@version	   $Id$
1128 jp_milcent 36
// +------------------------------------------------------------------------------------------------------+
37
*/
38
 
39
// +------------------------------------------------------------------------------------------------------+
2074 Jean-Pasca 40
// |											ENTÊTE du PROGRAMME									   |
1128 jp_milcent 41
// +------------------------------------------------------------------------------------------------------+
42
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherLien';
2078 Jean-Pasca 43
$GLOBALS['_GEN_commun']['info_applette_balise'] = '\{\{[Ll]ien(?:\s*(?:((?:menu|site)="[^"]+")|(titre="[^"]+")|(squelette="[^"]+")|))+\s*\}\}';
1128 jp_milcent 44
 
45
// --------------------------------------------------------------------------------------------------------
46
/** Inclusion du fichier de configuration de cette application.*/
47
require_once GEN_CHEMIN_APPLETTE.'lien'.GEN_SEP.'configuration'.GEN_SEP.'lien_configuration.inc.php';
48
 
49
// Inclusion des fichiers de traduction de l'applette LIEN de Papyrus
50
if (file_exists(LIEN_CHEMIN_LANGUE.'lien_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php')) {
2074 Jean-Pasca 51
	/** Inclusion du fichier de traduction suite à la transaction avec le navigateur.*/
52
	require_once LIEN_CHEMIN_LANGUE.'lien_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php';
1128 jp_milcent 53
} else {
2074 Jean-Pasca 54
	/** Inclusion du fichier de traduction par défaut.*/
55
	require_once LIEN_CHEMIN_LANGUE.'lien_langue_'.LIEN_I18N_DEFAUT.'.inc.php';
1128 jp_milcent 56
}
57
 
58
 
59
// +------------------------------------------------------------------------------------------------------+
2074 Jean-Pasca 60
// |											CORPS du PROGRAMME										|
1128 jp_milcent 61
// +------------------------------------------------------------------------------------------------------+
62
/** Fonction afficherLien() - Retourne le lien d'un menu ou d'un site.
63
*
64
* Cette fonction retourne un lien vers un menu ou un site. Le lien est créé dynamiquement et donc toujours à jour.
65
* Il est possible d'utiliser les code numérique ou alphanumérique.
66
*
67
* @param  array contient les arguments de la fonction.
68
* @param  array  tableau global de Papyrus.
69
* @return string XHTML le lien.
70
*/
71
function afficherLien($tab_applette_arguments, $_GEN_commun)
72
{
73
	// Initialisation des variables
2074 Jean-Pasca 74
	$sortie = '';
1968 jp_milcent 75
	$niveau = null;
1128 jp_milcent 76
	$GLOBALS['_LIEN_']['url'] = '';
77
	$GLOBALS['_LIEN_']['titre'] = LIEN_LG_ERREUR_TITRE;
2074 Jean-Pasca 78
	$GLOBALS['_LIEN_']['erreurs'] = array();
1128 jp_milcent 79
 
80
	//+----------------------------------------------------------------------------------------------------------------+
81
	// Gestion des arguments
2074 Jean-Pasca 82
	$tab_arguments = $tab_applette_arguments;
1128 jp_milcent 83
	unset($tab_arguments[0]);
2074 Jean-Pasca 84
	foreach($tab_arguments as $argument) {
85
		$tab_parametres = explode('=', $argument);
86
		$options[$tab_parametres[0]] = trim($tab_parametres[1], '"');
87
	}
1128 jp_milcent 88
 
89
	//+----------------------------------------------------------------------------------------------------------------+
2074 Jean-Pasca 90
	// Gestion des erreurs de paramètrage
91
	if (!isset($options['menu']) && !isset($options['site']) ) {
92
		$GLOBALS['_LIEN_']['erreur'] = LIEN_LG_ERREUR_SITE_MENU;
93
	} else {
94
		if (isset($options['menu'])) {
95
			$niveau = 'menu';
96
			$identifiant = $options['menu'];
97
		} else if (isset($options['site'])) {
98
			$niveau = 'site';
99
			$identifiant = $options['site'];
100
		}
101
	}
2078 Jean-Pasca 102
 
103
	$squelette = LIEN_CHEMIN_SQUELETTE.LIEN_SQUELETTE_LISTE;
104
	if (isset($options['squelette'])) {
105
		$ext = '.tpl.html';
106
		if (preg_match('/(\.tpl\..+)$/', $options['squelette'], $match)) {
107
			$ext = $match[1];
108
		}
109
 
110
		if (!file_exists(LIEN_CHEMIN_SQUELETTE.$options['squelette'].$ext)) {
111
			$GLOBALS['_LIEN_']['erreur'] = LIEN_LG_ERREUR_SQUELETTE;
112
		} else {
113
			$squelette = LIEN_CHEMIN_SQUELETTE.$options['squelette'].$ext;
114
		}
115
	}
2074 Jean-Pasca 116
	//+----------------------------------------------------------------------------------------------------------------+
117
	// Récupération des données
1128 jp_milcent 118
	$bdd =& $GLOBALS['_GEN_commun']['pear_db'];
119
	$id_langue = $GLOBALS['_GEN_commun']['i18n']; //identifiant de la langue choisie
120
	if (isset($id_langue) && ($id_langue != '')) {
121
		$langue_url = $id_langue;
122
	} else {
123
		$langue_url = GEN_I18N_ID_DEFAUT;
124
	}
125
	$une_url =& new Pap_URL();
126
	// Les sites
127
	if ($niveau == "site") {
128
		if (preg_match('/^[0-9]+$/', $identifiant)) {
129
			$aso_site = GEN_lireInfoSiteI18nCodeAlpha($bdd, GEN_retournerSiteCodeAlpha($bdd, $identifiant), $langue_url, DB_FETCHMODE_ASSOC);
130
		} else {
131
			$aso_site = GEN_lireInfoSiteI18nCodeAlpha($bdd, $identifiant, $langue_url, DB_FETCHMODE_ASSOC);
132
		}
133
 
2074 Jean-Pasca 134
		if (isset($options['titre'])) {
135
			$GLOBALS['_LIEN_']['titre'] = $options['titre'];
136
		} else {
137
			if (!empty($aso_site['gs_titre'])) {
1128 jp_milcent 138
				$GLOBALS['_LIEN_']['titre'] = $aso_site['gs_titre'];
2074 Jean-Pasca 139
			} else {
1128 jp_milcent 140
				$GLOBALS['_LIEN_']['titre'] = $aso_site['gs_nom'];
2074 Jean-Pasca 141
			}
142
		}
143
		$une_url->setUrlType('SITE');
144
		$une_url->setId($aso_site['gs_id_site']);
1128 jp_milcent 145
	}
146
	// Les menus
147
	if ($niveau == "menu") {
148
		if (preg_match('/^[0-9]+$/', $identifiant)) {
149
			$aso_menu = GEN_lireInfoMenu($bdd, GEN_retournerIdMenuParCodeNum($bdd, $identifiant), DB_FETCHMODE_ASSOC);
150
		} else {
151
			$aso_menu = GEN_lireInfoMenu($bdd, GEN_retournerIdMenuParCodeNum($bdd, GEN_retournerMenuCodeNum($bdd, $identifiant)), DB_FETCHMODE_ASSOC);
152
		}
2074 Jean-Pasca 153
		if (isset($options['titre'])) {
154
			$GLOBALS['_LIEN_']['titre'] = $options['titre'];
155
		} else {
156
			if (!empty($aso_menu['gm_titre'])) {
1128 jp_milcent 157
				$GLOBALS['_LIEN_']['titre'] = $aso_menu['gm_titre'];
2074 Jean-Pasca 158
			} elseif (!empty($aso_menu['gm_titre_alternatif'])) {
1128 jp_milcent 159
				$GLOBALS['_LIEN_']['titre'] = $aso_menu['gm_titre_alternatif'];
2074 Jean-Pasca 160
			} elseif (!empty($aso_menu['gm_nom'])) {
1128 jp_milcent 161
				$GLOBALS['_LIEN_']['titre'] = $aso_menu['gm_nom'];
2074 Jean-Pasca 162
			}
163
		}
164
		$une_url->setId($aso_menu['gm_id_menu']);
165
	}
166
 
1128 jp_milcent 167
	if ($langue_url != GEN_I18N_ID_DEFAUT) {
168
		$une_url->addQueryString(GEN_URL_CLE_I18N, $langue_url);
169
	}
170
	$GLOBALS['_LIEN_']['url'] = $une_url->getURL();
171
	$GLOBALS['_LIEN_']['titre'] = htmlentities($GLOBALS['_LIEN_']['titre']);
172
 
173
	//+----------------------------------------------------------------------------------------------------------------+
2074 Jean-Pasca 174
	// Extrait les variables et les ajoutes à l'espace de noms local
1128 jp_milcent 175
	// Gestion des squelettes
176
	extract($GLOBALS['_LIEN_']);
177
	// Démarre le buffer
178
	ob_start();
179
	// Inclusion du fichier
2078 Jean-Pasca 180
	include($squelette);
1128 jp_milcent 181
	// Récupérer le  contenu du buffer
182
	$sortie = ob_get_contents();
183
	// Arrête et détruit le buffer
184
	ob_end_clean();
185
 
186
	//+----------------------------------------------------------------------------------------------------------------+
187
	// Sortie
2074 Jean-Pasca 188
	return $sortie;
1128 jp_milcent 189
}
1968 jp_milcent 190
?>