Subversion Repositories Applications.papyrus

Rev

Rev 182 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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