1<?php
2/**
3 * This parser parses Horde Registry links, which allow calling Horde
4 * API "*"/show methods from within the page. Basic syntax is
5 * [[link link title | link-app/link-method argname1=value1 argname2=value2 ...]].
6 *
7 * @package Wicked
8 */
9class Text_Wiki_Parse_Registrylink extends Text_Wiki_Parse
10{
11    /**
12     * The regular expression used to find registry links.
13     *
14     * @access public
15     *
16     * @var string
17     */
18    public $regex = "/\[\[link (.*)\]\]/sU";
19
20    /**
21     * Generates a token entry for the matched text. Token options are:
22     *
23     * 'app'  => The application to link to.
24     * 'args' => The parameters passed to the app/show method.
25     *
26     * @access public
27     *
28     * @param array &$matches  The array of matches from parse().
29     *
30     * @return  A delimited token number to be used as a placeholder in
31     *          the source text.
32     */
33    public function process(&$matches)
34    {
35        @list($title, $call) = explode('|', $matches[1], 2);
36        $opts = explode(' ', trim($call));
37        $method = trim(array_shift($opts));
38        parse_str(implode('&', $opts), $args);
39
40        return $this->wiki->addToken($this->rule, array('title' => trim($title),
41                                                        'method' => $method,
42                                                        'args' => $args));
43    }
44}
45