summaryrefslogtreecommitdiff
path: root/pear/Text/Wiki/Render/Creole/Wikilink.php
blob: fe4fc37d23e799cdc2688ece733535cac604dca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

class Text_Wiki_Render_Creole_Wikilink extends Text_Wiki_Render {

    /**
    *
    * Renders a token into XHTML.
    *
    * @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)
    {
        $dup = (($options['page'] == $options['text']) || ($options['page'] == preg_replace('/\s+/', '_', $options['text'])));
        
        if ($options['type'] == 'start') {
            if ($dup) return '[[';
            else return '[['.$options['page'].
                (strlen($options['anchor']) ? $options['anchor'] : '').
                (strlen($options['text']) && (strlen($options['page']) || strlen($options['anchor'])) ? '|' : '');
        } else if ($options['type'] == 'end') {
            if ($dup && strlen($options['anchor'])) return $options['anchor'].']]';
            else return ']]';
        } else {
            if ($dup) return '[['.
                    (strlen($options['text']) ? $options['text'] : '').
                    (strlen($options['anchor']) ? $options['anchor'] : '').
                    ']]';
            else return '[['.$options['page'].
                (strlen($options['anchor']) ? $options['anchor'] : '').
                (strlen($options['text']) && strlen($options['page']) && strlen($options['anchor']) ? '|' : '').
                (strlen($options['text']) ? $options['text'] : '').
                ']]';
        }
    }
}
?>