Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 181 → Rev 182

/trunk/api/text/wiki_papyrus/Render/Xhtml/Inclure.php
New file
0,0 → 1,67
<?php
 
class Text_Wiki_Render_Xhtml_Inclure extends Text_Wiki_Render {
var $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'
);
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
$site = $options['site'];
$page = $options['page'];
$text = $options['text'];
$css = $this->formatConf(' class="%s"', 'css');
if (isset($this->conf['sites'][$site])) {
$href = $this->conf['sites'][$site]['url'];
} else {
return $text;
}
// 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);
}
$output = '';
$contenu = file_get_contents($href);
preg_match($this->conf['sites'][$site]['preg'], $contenu, $tab_matches);
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', $this->conf['encodage']) && preg_match('/utf-8/i', $tab_encodage[1])) {
$output = utf8_decode($tab_matches[1]);
} else {
$output = $tab_matches[1];
}
return $output;
}
}
?>