Subversion Repositories Applications.papyrus

Rev

Rev 1087 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
248 jpm 1
<?php
2
 
3
 
4
class Text_Wiki_Render_Xhtml_Url extends Text_Wiki_Render {
5
 
6
 
7
    var $conf = array(
8
        'target' => '_blank',
9
        'images' => true,
10
        'img_ext' => array('jpg', 'jpeg', 'gif', 'png'),
11
        'css_inline' => null,
12
        'css_footnote' => null,
13
        'css_descr' => null,
14
        'css_img' => null
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
        // create local variables from the options array (text,
33
        // href, type)
34
        extract($options);
35
 
36
        // find the rightmost dot and determine the filename
37
        // extension.
38
        $pos = strrpos($href, '.');
39
        $ext = strtolower(substr($href, $pos + 1));
40
        $href = htmlspecialchars($href);
41
 
42
        // does the filename extension indicate an image file?
43
        if ($this->getConf('images') &&
44
            in_array($ext, $this->getConf('img_ext', array()))) {
45
 
46
            // create alt text for the image
47
            if (! isset($text) || $text == '') {
48
                $text = basename($href);
49
                $text = htmlspecialchars($text);
50
            }
51
 
52
            // generate an image tag
53
            $css = $this->formatConf(' class="%s"', 'css_img');
54
            $output = "<img$css src=\"$href\" alt=\"$text\" />";
55
 
56
        } else {
57
 
58
            // allow for alternative targets on non-anchor HREFs
59
            if ($href{0} == '#') {
60
                $target = '';
61
            } else {
62
                $target = $this->getConf('target');
63
            }
64
 
65
            // generate a regular link (not an image)
66
            $text = htmlspecialchars($text);
67
            $css = $this->formatConf(' class="%s"', "css_$type");
68
            $output = "<a$css href=\"$href\"";
69
 
70
            if ($target) {
71
                // use a "popup" window.  this is XHTML compliant, suggested by
72
                // Aaron Kalin.  uses the $target as the new window name.
73
                $target = htmlspecialchars($target);
74
                $output .= " onclick=\"window.open(this.href, '$target');";
75
                $output .= " return false;\"";
76
            }
77
 
78
            // finish up output
79
            $output .= ">$text</a>";
80
 
81
            // make numbered references look like footnotes when no
82
            // CSS class specified, make them superscript by default
83
            if ($type == 'footnote' && ! $css) {
84
                $output = '<sup>' . $output . '</sup>';
85
            }
86
        }
87
 
88
        return $output;
89
    }
90
}
91
?>