Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 1100 → Rev 1089

/trunk/api/text/wiki_papyrus/Render/Xhtml/Inclure.php
New file
0,0 → 1,69
<?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);
$tab_matches='';
preg_match($this->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', $this->conf['encodage']) && preg_match('/utf-8/i', $tab_encodage[1])) {
$output = utf8_decode($tab_matches[1]);
} else {
$output = $tab_matches[1];
}
return $output;
}
}
?>
/trunk/api/text/wiki_papyrus/Parse/Inclure.php
New file
0,0 → 1,52
<?php
// $Id: Inclure.php,v 1.1 2004-11-26 12:13:28 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Parse_Inclure extends Text_Wiki_Parse {
var $regex = '/\{\{inclure page="([A-Za-z0-9_]+)"(?: interwiki="([A-Za-z0-9_]+)"|)\}\}/';
/**
*
* Generates a replacement for the matched standalone interwiki text.
* Token options are:
*
* 'site' => The key name for the Text_Wiki interwiki array map,
* usually the name of the interwiki site.
*
* 'page' => The page on the target interwiki to link to.
*
* 'text' => The text to display as the link.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
$options = array(
'page' => $matches[1],
'site' => $matches[2],
'text' => $matches[0]
);
return $this->wiki->addToken($this->rule, $options);
}
}
?>