Subversion Repositories Applications.papyrus

Rev

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

Rev 1101 Rev 1118
Line 27... Line 27...
27
// | de sécurité.                                                                                         |
27
// | de sécurité.                                                                                         |
28
// |                                                                                                      |
28
// |                                                                                                      |
29
// | Le fait que vous puissiez accéder à cet en-tête signifie que vous avez pris connaissance de la       |
29
// | Le fait que vous puissiez accéder à cet en-tête signifie que vous avez pris connaissance de la       |
30
// | licence CeCILL, et que vous en avez accepté les termes.                                              |
30
// | licence CeCILL, et que vous en avez accepté les termes.                                              |
31
// +------------------------------------------------------------------------------------------------------+
31
// +------------------------------------------------------------------------------------------------------+
32
// CVS : $Id: inclure.php,v 1.1 2006-12-01 17:36:28 florian Exp $
32
// CVS : $Id: inclure.php,v 1.2 2006-12-08 15:57:30 jp_milcent Exp $
33
/**
33
/**
34
* Applette : Inclure
34
* Applette : Inclure
35
*
35
*
36
* Retourne toutes les pages Papyrus appartenant à une catégorie donnée.
36
* Retourne toutes les pages Papyrus appartenant à une catégorie donnée.
37
*
37
*
Line 40... Line 40...
40
//Auteur original :
40
//Auteur original :
41
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
41
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
42
//Autres auteurs :
42
//Autres auteurs :
43
*@author        Aucun
43
*@author        Aucun
44
*@copyright     Tela-Botanica 2000-2006
44
*@copyright     Tela-Botanica 2000-2006
45
*@version       $Revision: 1.1 $ $Date: 2006-12-01 17:36:28 $
45
*@version       $Revision: 1.2 $ $Date: 2006-12-08 15:57:30 $
46
// +------------------------------------------------------------------------------------------------------+
46
// +------------------------------------------------------------------------------------------------------+
47
*/
47
*/
Line 48... Line 48...
48
 
48
 
49
// +------------------------------------------------------------------------------------------------------+
49
// +------------------------------------------------------------------------------------------------------+
50
// |                                            ENTÊTE du PROGRAMME                                       |
50
// |                                            ENTÊTE du PROGRAMME                                       |
51
// +------------------------------------------------------------------------------------------------------+
51
// +------------------------------------------------------------------------------------------------------+
52
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherInclure';
52
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherInclure';
Line 53... Line 53...
53
$GLOBALS['_GEN_commun']['info_applette_balise'] = '\{\{[Ii]nclure(?: (?:(page="[^"]+")|(interwiki="[^"]+")))+\}\}';
53
$GLOBALS['_GEN_commun']['info_applette_balise'] = '\{\{[Ii]nclure(?:\s*(?:(page="[^"]+")|(interwiki="[^"]+")|))+\s*\}\}';
54
 
54
 
55
// --------------------------------------------------------------------------------------------------------
55
// --------------------------------------------------------------------------------------------------------
56
//Utilisation de la bibliothèque Papyrus pap_meta.fonct.php inclue par Papyrus
56
//Utilisation de la bibliothèque Papyrus pap_meta.fonct.php inclue par Papyrus
Line 78... Line 78...
78
* @param  array  tableau global de Papyrus.
78
* @param  array  tableau global de Papyrus.
79
* @return string HTML la liste des listes de menus.
79
* @return string HTML la liste des listes de menus.
80
*/
80
*/
81
function afficherInclure($tab_applette_arguments, $_GEN_commun)
81
function afficherInclure($tab_applette_arguments, $_GEN_commun)
82
{
82
{
83
	$conf = array(
-
 
84
	    'sites' => array(
-
 
85
	        'Wikipedia' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://fr.wikipedia.org/wiki/%s'),
-
 
86
	        'Wikipedia_fr' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://fr.wikipedia.org/wiki/%s'),
-
 
87
	        'Wikipedia_en' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://en.wikipedia.org/wiki/%s'),
-
 
88
	        'Wikini_eFlore' => array('preg' => '/<div class="page">(.*)<\/div>.*<div class="commentsheader">/Umsi', 'url' => 'http://wiki.tela-botanica.org/eflore/wakka.php?wiki=%s')
-
 
89
	        ),
-
 
90
	    'css' => null,
-
 
91
	    'encodage' => 'iso-8859-15'
-
 
92
	);
-
 
93
	//echo '<pre>'.print_r($tab_applette_arguments, true).'</pre>'.
-
 
94
	// Initialisation des variables
83
	// Initialisation des variables
95
    $sortie = '';
84
    $sortie = '';
-
 
85
	$GLOBALS['_INCLURE_']['informations'] = array();
-
 
86
	$GLOBALS['_INCLURE_']['erreurs'] = array();
-
 
87
	
-
 
88
    //+----------------------------------------------------------------------------------------------------------------+
-
 
89
	// Gestion des arguments
96
	$tab_arguments = $tab_applette_arguments;
90
	$tab_arguments = $tab_applette_arguments;
97
	unset($tab_arguments[0]);
91
	unset($tab_arguments[0]);
98
    foreach($tab_arguments as $argument) {
92
	foreach($tab_arguments as $argument) {
99
	    $tab_parametres = explode('=', $argument);
93
	    $tab_parametres = explode('=', $argument);
-
 
94
	    if ($tab_parametres[0] != '' && $tab_parametres[1] != '') {
100
	    $options[$tab_parametres[0]] = trim($tab_parametres[1], '"'); 
95
	    	$options[$tab_parametres[0]] = trim($tab_parametres[1], '"');
-
 
96
	    } 
101
    }
97
    }
102
    
98
 
-
 
99
	//+----------------------------------------------------------------------------------------------------------------+
103
    $site = $options['interwiki'];
100
    // Gestion des erreurs de paramètrage
104
    $page = $options['page'];
101
    $ok = true;
105
    $text = $tab_applette_arguments[0];
-
 
106
    $css = _formatConf(' class="%s"', 'css');
-
 
107
    
-
 
108
    if (isset($conf['sites'][$site])) {
102
    if (!isset($options['interwiki'])) {
-
 
103
        $GLOBALS['_INCLURE_']['erreurs'][] = sprintf(CATEG_LG_ERREUR_INTERWIKI, $tab_applette_arguments[0]);
109
        $href = $conf['sites'][$site]['url'];
104
        $ok = false;
110
    } else {
105
    } else {
-
 
106
    	if (!isset($GLOBALS['_INCLURE_']['site'][$options['interwiki']])) {
-
 
107
    	    $GLOBALS['_INCLURE_']['erreurs'][] = sprintf(CATEG_LG_ERREUR_SITE, $options['interwiki']);
111
        return $text;
108
        	$ok = false;
-
 
109
	    }
112
    }
110
    }
113
    
-
 
114
    // old form where page is at end,
111
    if (!isset($options['page'])) {
115
    // or new form with %s placeholder for sprintf()?
112
        $GLOBALS['_INCLURE_']['erreurs'][] = sprintf(CATEG_LG_ERREUR_PAGE, $tab_applette_arguments[0]);
116
    if (strpos($href, '%s') === false) {
-
 
117
        // use the old form
-
 
118
        $href = $href . $page;
113
        $ok = false;
119
    } else {
-
 
120
        // use the new form
-
 
121
        $href = sprintf($href, $page);
-
 
122
    }
114
    }
Line -... Line 115...
-
 
115
    
-
 
116
    
-
 
117
	//+----------------------------------------------------------------------------------------------------------------+
-
 
118
	// Récupération des données
-
 
119
    $GLOBALS['_INCLURE_']['sortie'] = '';
-
 
120
    if ($ok) {
-
 
121
		$href = $GLOBALS['_INCLURE_']['site'][$options['interwiki']]['url'];
-
 
122
		$href = sprintf($href, $options['page']);
-
 
123
	    
123
    
124
	
124
    $contenu = file_get_contents($href);
125
	    $contenu = file_get_contents($href);
125
    if ($contenu != false) {
126
	    if ($contenu != false) {
126
	    $tab_matches = '';
127
		    $tab_matches = '';
127
	    preg_match($conf['sites'][$site]['preg'], $contenu, $tab_matches);
128
		    preg_match($GLOBALS['_INCLURE_']['site'][$options['interwiki']]['preg'], $contenu, $tab_matches);
128
	    $tab_encodage = '';
129
		    $tab_encodage = '';
129
	    preg_match('/<meta +http-equiv="Content-Type" +content="text\/html; *charset=(.+)"\/>/Ui', $contenu, $tab_encodage);
130
		    preg_match('/<meta +http-equiv="Content-Type" +content="text\/html; *charset=(.+)"\/>/Ui', $contenu, $tab_encodage);
130
	    if (preg_match('/^(?:iso-8859-1|iso-8859-15)$/i', $conf['encodage']) && preg_match('/utf-8/i', $tab_encodage[1])) {
131
		    if (preg_match('/^(?:iso-8859-1|iso-8859-15)$/i', $GLOBALS['_INCLURE_']['encodage']) && preg_match('/utf-8/i', $tab_encodage[1])) {
-
 
132
		        $GLOBALS['_INCLURE_']['sortie'] = utf8_decode($tab_matches[1]);
-
 
133
		    } else {
-
 
134
		        $GLOBALS['_INCLURE_']['sortie'] = $tab_matches[1];
131
	        $sortie = utf8_decode($tab_matches[1]);
135
		    }
132
	    } else {
136
	    } else {
133
	        $sortie = $tab_matches[1];
137
	    	$GLOBALS['_INCLURE_']['informations'][] = sprintf(CATEG_LG_ERREUR_INCLUSION, $href);
134
	    }
-
 
135
    } else {
-
 
136
    	$sortie = '<p class="pap_erreur">'."Un problème a été rencontré lors de la tentative d'inclusion de la page : ".
-
 
137
    	'<a href="'.$href.'">'.$href.'</a></p>';
138
	    }
-
 
139
    }
-
 
140
        
-
 
141
	//+----------------------------------------------------------------------------------------------------------------+
-
 
142
    // Extrait les variables et les ajoutes à l'espace de noms local
-
 
143
	// Gestion des squelettes
-
 
144
	extract($GLOBALS['_INCLURE_']);
-
 
145
	// Démarre le buffer
-
 
146
	ob_start();
-
 
147
	// Inclusion du fichier
-
 
148
	include(INCL_CHEMIN_SQUELETTE.INCL_SQUELETTE_LISTE);
-
 
149
	// Récupérer le  contenu du buffer
-
 
150
	$sortie = ob_get_contents();
-
 
151
	// Arrête et détruit le buffer
-
 
152
	ob_end_clean();
-
 
153
	
-
 
154
	//+----------------------------------------------------------------------------------------------------------------+
138
    }
155
	// Sortie
139
    return $sortie;
156
    return $sortie;
Line 140... Line -...
140
}
-
 
141
 
-
 
142
// +------------------------------------------------------------------------------------------------------+
-
 
143
// |                                            LISTE DES FONCTIONS                                       |
-
 
144
// +------------------------------------------------------------------------------------------------------+
-
 
145
 
-
 
146
/**
-
 
147
* 
-
 
148
* Simple method to wrap a configuration in an sprintf() format.
-
 
149
* 
-
 
150
* @access public
-
 
151
* 
-
 
152
* @param string $key The configuration key.
-
 
153
* 
-
 
154
* @param string $format The sprintf() format string.
-
 
155
* 
-
 
156
* @return mixed The formatted configuration key value (if it exists) 
-
 
157
* or null (if it does not).
-
 
158
* 
-
 
159
*/
-
 
160
function _formatConf($format, $key)
-
 
161
{
-
 
162
    if (isset($this->conf[$key])) {
-
 
163
        return sprintf($format, $this->conf[$key]);
-
 
164
    } else {
-
 
165
        return null;
-
 
166
    }
157
}
167
}
158
 
168
/* +--Fin du code ----------------------------------------------------------------------------------------+
159
/* +--Fin du code ----------------------------------------------------------------------------------------+
-
 
160
*
-
 
161
* $Log: not supported by cvs2svn $
-
 
162
* Revision 1.1  2006/12/01 17:36:28  florian
169
*
163
* Ajout de l'apllette Inclure, provenant de l'action Inclure.
170
* $Log: not supported by cvs2svn $
164
*
171
*
165
*
172
* +-- Fin du code ----------------------------------------------------------------------------------------+
166
* +-- Fin du code ----------------------------------------------------------------------------------------+
173
*/
167
*/