1<?php
2/**
3 * DokuWiki Plugin Listusergroup (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Richard Gfrerer <richard.gfrerer@gmx.net>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) {
11    die();
12}
13
14class syntax_plugin_listusergroup extends DokuWiki_Syntax_Plugin {
15    /**
16     * @return string Syntax mode type
17     */
18    public function getType() { return 'substition'; }
19
20    /**
21     * @return string Paragraph type
22     */
23    public function getPType() { return 'normal'; }
24
25    /**
26     * @return int Sort order - Low numbers go before high numbers
27     */
28    public function getSort() { return 160; }
29
30    /**
31     * Connect lookup pattern to lexer.
32     *
33     * @param string $mode Parser mode
34     */
35    public function connectTo($mode) {
36
37         $this->Lexer->addSpecialPattern('{{listusergroup>[^}]+}}',$mode,'plugin_listusergroup');
38    }
39
40    /**
41     * Handle matches of the listusergroup syntax
42     *
43     * @param string       $match   The match of the syntax
44     * @param int          $state   The state of the handler
45     * @param int          $pos     The position in the document
46     * @param Doku_Handler $handler The handler
47     *
48     * @return array Data for the renderer
49     */
50    public function handle($match, $state, $pos, Doku_Handler $handler) {
51		list($syntax, $match) = explode('>', substr( strtolower($match), 0, -2), 2); // strip markup
52
53
54		$options = [];
55		$optionParts = explode(';', $match);
56		foreach ($optionParts as $optionPart) {
57			list($key,$optiontxt) = explode('=', $optionPart,2);
58			$options[trim($key)] = explode(',', $optiontxt);
59			$options[$key] = array_map('trim', $options[$key]);
60		}
61
62		return $options;
63    }
64
65    /**
66     * Render xhtml output or metadata
67     *
68     * @param string        $mode     Renderer mode (supported modes: xhtml)
69     * @param Doku_Renderer $renderer The renderer
70     * @param array         $data     The data from the handler() function
71     *
72     * @return bool If rendering was successful.
73     */
74    public function render($mode, Doku_Renderer $renderer, $data){
75		if ($mode == 'xhtml') {
76			if ($my =& plugin_load('helper', 'listusergroup'))
77				$renderer->doc .= $my->getXHTML($data);
78			return true;
79		}
80		return false;
81    }
82}
83
84