29,7 → 29,7 |
// | Le fait que vous puissiez accéder à cet en-tête signifie que vous avez pris connaissance de la | |
// | licence CeCILL, et que vous en avez accepté les termes. | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: inclure.php,v 1.1 2006-12-01 17:36:28 florian Exp $ |
// CVS : $Id: inclure.php,v 1.2 2006-12-08 15:57:30 jp_milcent Exp $ |
/** |
* Applette : Inclure |
* |
42,7 → 42,7 |
//Autres auteurs : |
*@author Aucun |
*@copyright Tela-Botanica 2000-2006 |
*@version $Revision: 1.1 $ $Date: 2006-12-01 17:36:28 $ |
*@version $Revision: 1.2 $ $Date: 2006-12-08 15:57:30 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
|
50,7 → 50,7 |
// | ENTÊTE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherInclure'; |
$GLOBALS['_GEN_commun']['info_applette_balise'] = '\{\{[Ii]nclure(?: (?:(page="[^"]+")|(interwiki="[^"]+")))+\}\}'; |
$GLOBALS['_GEN_commun']['info_applette_balise'] = '\{\{[Ii]nclure(?:\s*(?:(page="[^"]+")|(interwiki="[^"]+")|))+\s*\}\}'; |
|
// -------------------------------------------------------------------------------------------------------- |
//Utilisation de la bibliothèque Papyrus pap_meta.fonct.php inclue par Papyrus |
80,95 → 80,89 |
*/ |
function afficherInclure($tab_applette_arguments, $_GEN_commun) |
{ |
$conf = array( |
'sites' => array( |
'Wikipedia' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://fr.wikipedia.org/wiki/%s'), |
'Wikipedia_fr' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://fr.wikipedia.org/wiki/%s'), |
'Wikipedia_en' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://en.wikipedia.org/wiki/%s'), |
'Wikini_eFlore' => array('preg' => '/<div class="page">(.*)<\/div>.*<div class="commentsheader">/Umsi', 'url' => 'http://wiki.tela-botanica.org/eflore/wakka.php?wiki=%s') |
), |
'css' => null, |
'encodage' => 'iso-8859-15' |
); |
//echo '<pre>'.print_r($tab_applette_arguments, true).'</pre>'. |
// Initialisation des variables |
$sortie = ''; |
$GLOBALS['_INCLURE_']['informations'] = array(); |
$GLOBALS['_INCLURE_']['erreurs'] = array(); |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Gestion des arguments |
$tab_arguments = $tab_applette_arguments; |
unset($tab_arguments[0]); |
foreach($tab_arguments as $argument) { |
foreach($tab_arguments as $argument) { |
$tab_parametres = explode('=', $argument); |
$options[$tab_parametres[0]] = trim($tab_parametres[1], '"'); |
if ($tab_parametres[0] != '' && $tab_parametres[1] != '') { |
$options[$tab_parametres[0]] = trim($tab_parametres[1], '"'); |
} |
} |
|
$site = $options['interwiki']; |
$page = $options['page']; |
$text = $tab_applette_arguments[0]; |
$css = _formatConf(' class="%s"', 'css'); |
|
if (isset($conf['sites'][$site])) { |
$href = $conf['sites'][$site]['url']; |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Gestion des erreurs de paramètrage |
$ok = true; |
if (!isset($options['interwiki'])) { |
$GLOBALS['_INCLURE_']['erreurs'][] = sprintf(CATEG_LG_ERREUR_INTERWIKI, $tab_applette_arguments[0]); |
$ok = false; |
} else { |
return $text; |
if (!isset($GLOBALS['_INCLURE_']['site'][$options['interwiki']])) { |
$GLOBALS['_INCLURE_']['erreurs'][] = sprintf(CATEG_LG_ERREUR_SITE, $options['interwiki']); |
$ok = false; |
} |
} |
|
// old form where page is at end, |
// or new form with %s placeholder for sprintf()? |
if (strpos($href, '%s') === false) { |
// use the old form |
$href = $href . $page; |
} else { |
// use the new form |
$href = sprintf($href, $page); |
if (!isset($options['page'])) { |
$GLOBALS['_INCLURE_']['erreurs'][] = sprintf(CATEG_LG_ERREUR_PAGE, $tab_applette_arguments[0]); |
$ok = false; |
} |
|
$contenu = file_get_contents($href); |
if ($contenu != false) { |
$tab_matches = ''; |
preg_match($conf['sites'][$site]['preg'], $contenu, $tab_matches); |
$tab_encodage = ''; |
preg_match('/<meta +http-equiv="Content-Type" +content="text\/html; *charset=(.+)"\/>/Ui', $contenu, $tab_encodage); |
if (preg_match('/^(?:iso-8859-1|iso-8859-15)$/i', $conf['encodage']) && preg_match('/utf-8/i', $tab_encodage[1])) { |
$sortie = utf8_decode($tab_matches[1]); |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Récupération des données |
$GLOBALS['_INCLURE_']['sortie'] = ''; |
if ($ok) { |
$href = $GLOBALS['_INCLURE_']['site'][$options['interwiki']]['url']; |
$href = sprintf($href, $options['page']); |
|
|
$contenu = file_get_contents($href); |
if ($contenu != false) { |
$tab_matches = ''; |
preg_match($GLOBALS['_INCLURE_']['site'][$options['interwiki']]['preg'], $contenu, $tab_matches); |
$tab_encodage = ''; |
preg_match('/<meta +http-equiv="Content-Type" +content="text\/html; *charset=(.+)"\/>/Ui', $contenu, $tab_encodage); |
if (preg_match('/^(?:iso-8859-1|iso-8859-15)$/i', $GLOBALS['_INCLURE_']['encodage']) && preg_match('/utf-8/i', $tab_encodage[1])) { |
$GLOBALS['_INCLURE_']['sortie'] = utf8_decode($tab_matches[1]); |
} else { |
$GLOBALS['_INCLURE_']['sortie'] = $tab_matches[1]; |
} |
} else { |
$sortie = $tab_matches[1]; |
$GLOBALS['_INCLURE_']['informations'][] = sprintf(CATEG_LG_ERREUR_INCLUSION, $href); |
} |
} else { |
$sortie = '<p class="pap_erreur">'."Un problème a été rencontré lors de la tentative d'inclusion de la page : ". |
'<a href="'.$href.'">'.$href.'</a></p>'; |
} |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Extrait les variables et les ajoutes à l'espace de noms local |
// Gestion des squelettes |
extract($GLOBALS['_INCLURE_']); |
// Démarre le buffer |
ob_start(); |
// Inclusion du fichier |
include(INCL_CHEMIN_SQUELETTE.INCL_SQUELETTE_LISTE); |
// Récupérer le contenu du buffer |
$sortie = ob_get_contents(); |
// Arrête et détruit le buffer |
ob_end_clean(); |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Sortie |
return $sortie; |
} |
|
// +------------------------------------------------------------------------------------------------------+ |
// | LISTE DES FONCTIONS | |
// +------------------------------------------------------------------------------------------------------+ |
|
/** |
* |
* Simple method to wrap a configuration in an sprintf() format. |
* |
* @access public |
* |
* @param string $key The configuration key. |
* |
* @param string $format The sprintf() format string. |
* |
* @return mixed The formatted configuration key value (if it exists) |
* or null (if it does not). |
* |
*/ |
function _formatConf($format, $key) |
{ |
if (isset($this->conf[$key])) { |
return sprintf($format, $this->conf[$key]); |
} else { |
return null; |
} |
} |
/* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log: not supported by cvs2svn $ |
* Revision 1.1 2006/12/01 17:36:28 florian |
* Ajout de l'apllette Inclure, provenant de l'action Inclure. |
* |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |
?> |