File: Attribute.php

package info (click to toggle)
php-horde-wicked 2.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,528 kB
  • ctags: 1,236
  • sloc: php: 5,386; xml: 1,027; makefile: 10; sh: 3
file content (52 lines) | stat: -rw-r--r-- 1,514 bytes parent folder | download | duplicates (12)
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
<?php
/**
 * This parser parses "attributes," which carry meta-information about the
 * page.  These attributes are in the form [[WikiWord: value]].
 *
 * @package Wicked
 */
class Text_Wiki_Parse_Attribute extends Text_Wiki_Parse
{
    /**
     * The regular expression used to find source text matching this rule (this
     * is set in the constructor).
     *
     * @var string
     */
    public $regex;

    public function __construct(&$obj)
    {
        parent::Text_Wiki_Parse($obj);

        $this->regex = '/((?:\[\[' . Wicked::REGEXP_WIKIWORD .
                       ':\s+.*?\]\]\s*)+)/';
    }

    /**
     * Generates a token entry for the matched text. Token options are:
     *
     * 'src'  => The image source, typically a relative path name.
     * 'opts' => Any macro options following the source.
     *
     * @param array &$matches  The array of matches from parse().
     *
     * @return  A delimited token number to be used as a placeholder in
     *          the source text.
     */
    public function process(&$matches)
    {
        $options = array('attributes' => array());

        $text = $matches[1];
        while (preg_match('/^\[\[(' . Wicked::REGEXP_WIKIWORD . '):\s+(.*?)\]\]\s*(.*)$/s',
                          $text, $sub)) {

            $options['attributes'][] = array('name' => $sub[1],
                                             'value' => $sub[2]);
            $text = $sub[3];
        }

        return $this->wiki->addToken($this->rule, $options);
    }
}