summaryrefslogtreecommitdiff
path: root/includes/pear/Text/Wiki/Parse/Creole/Image.php
blob: 09ddb8b08026c08a2f2865a1c05d658a37e52ba6 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php

/**
 *
 * Parse for images in the source text.
 *
 * @category Text
 *
 * @package Text_Wiki
 *
 * @author Tomaiuolo Michele <tomamic@yahoo.it>
 *
 * @license LGPL
 *
 * @version $Id: Image.php 243106 2007-09-28 22:02:50Z mic $
 *
 */


class Text_Wiki_Parse_Image extends Text_Wiki_Parse {

    /**
     *
     * Constructor.  Overrides the Text_Wiki_Parse constructor so that we
     * can set the $regex property dynamically (we need to include the
     * Text_Wiki $delim character).
     *
     * @param object &$obj The calling "parent" Text_Wiki object.
     *
     * @param string $name The token name to use for this rule.
     *
     */

    function Text_Wiki_Parse_Image(&$obj)
    {
        parent::Text_Wiki_Parse($obj);
        $this->regex = '/{{([^' . $this->wiki->delim . ']*)(\|([^' . $this->wiki->delim . ']*))?}}/U';
    }


    /**
     *
     * Generates a replacement token for the matched text.
     *
     * @access public
     *
     * @param array &$matches The array of matches from parse().
     *
     * @return string A token marking the horizontal rule.
     *
     */

    function process(&$matches)
    {
        $src = trim($matches[1]);
		$src = ltrim($src, '/');
        $alt = isset($matches[3]) ? trim($matches[3]) : $src;

        return $this->wiki->addToken(
            $this->rule,
            array(
                'src' => $src,
                'attr' => array('alt' => $alt, 'title' => $alt)
            )
        );
    }

}
?>