Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
182 jpm 1
<?php
2
 
3
class Text_Wiki_Render_Xhtml_Inclure extends Text_Wiki_Render {
4
 
5
    var $conf = array(
6
        'sites' => array(
7
            'Wikipedia' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://fr.wikipedia.org/wiki/%s'),
8
            'Wikipedia_fr' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://fr.wikipedia.org/wiki/%s'),
9
            'Wikipedia_en' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://en.wikipedia.org/wiki/%s'),
10
            'Wikini_eFlore' => array('preg' => '/<div class="page">(.*)<\/div>.*<div class="commentsheader">/Umsi', 'url' => 'http://wiki.tela-botanica.org/eflore/wakka.php?wiki=%s')
11
            ),
12
        'css' => null,
13
        'encodage' => 'iso-8859-15'
14
    );
15
 
16
 
17
    /**
18
    *
19
    * Renders a token into text matching the requested format.
20
    *
21
    * @access public
22
    *
23
    * @param array $options The "options" portion of the token (second
24
    * element).
25
    *
26
    * @return string The text rendered from the token options.
27
    *
28
    */
29
 
30
    function token($options)
31
    {
32
        $site = $options['site'];
33
        $page = $options['page'];
34
        $text = $options['text'];
35
        $css = $this->formatConf(' class="%s"', 'css');
36
 
37
        if (isset($this->conf['sites'][$site])) {
38
            $href = $this->conf['sites'][$site]['url'];
39
        } else {
40
            return $text;
41
        }
42
 
43
        // old form where page is at end,
44
        // or new form with %s placeholder for sprintf()?
45
        if (strpos($href, '%s') === false) {
46
            // use the old form
47
            $href = $href . $page;
48
        } else {
49
            // use the new form
50
            $href = sprintf($href, $page);
51
        }
52
 
53
        $output = '';
54
 
55
        $contenu = file_get_contents($href);
56
        preg_match($this->conf['sites'][$site]['preg'], $contenu, $tab_matches);
57
        preg_match('/<meta +http-equiv="Content-Type" +content="text\/html; *charset=(.+)"\/>/Ui', $contenu, $tab_encodage);
58
        if (preg_match('/^(?:iso-8859-1|iso-8859-15)$/i', $this->conf['encodage']) && preg_match('/utf-8/i', $tab_encodage[1])) {
59
            $output = utf8_decode($tab_matches[1]);
60
        } else {
61
            $output = $tab_matches[1];
62
        }
63
 
64
        return $output;
65
    }
66
}
67
?>