1<?php
2/**
3 * Task Plugin, task form component: show new task form (only)
4 *
5 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author   LarsDW223
7 */
8
9class syntax_plugin_task_taskform extends DokuWiki_Syntax_Plugin {
10    protected $helper = NULL;
11
12    /**
13     * Constructor. Loads helper plugin.
14     */
15    public function __construct() {
16        $this->helper = plugin_load('helper', 'task');
17    }
18
19    function getType() { return 'substition'; }
20    function getPType() { return 'block'; }
21    function getSort() { return 306; }
22
23    function connectTo($mode) {
24        $this->Lexer->addSpecialPattern('\{\{task>form>.+?\}\}', $mode, 'plugin_task_taskform');
25    }
26
27    function handle($match, $state, $pos, Doku_Handler $handler) {
28        global $ID;
29
30        // strip {{task>form> from start and }} from end
31        $match = substr($match, 12, -2);
32        list($ns, $flags) = explode('&', $match, 2);
33        $flags = explode('&', $flags);
34
35        if (($ns == '*') || ($ns == ':')) $ns = '';
36        elseif ($ns == '.') $ns = getNS($ID);
37        else $ns = cleanID($ns);
38
39        $selectUserGroup = NULL;
40        foreach ($flags as $flag) {
41            if (substr($flag, 0, 16) == 'selectUserGroup=') {
42                $selectUserGroup = substr($flag, 16);
43                $selectUserGroup = trim($selectUserGroup, '"');
44            }
45        }
46        return array($ns, $flags, $selectUserGroup);
47    }
48
49    function render($mode, Doku_Renderer $renderer, $data) {
50        if ($mode != 'xhtml') {
51            false;
52        }
53
54        list($ns, $flags, $selectUserGroup) = $data;
55
56        $selectUser = in_array('selectUser', $flags);
57        if ($this->helper) $renderer->doc .= $this->helper->_newTaskForm($ns, $selectUser, $selectUserGroup);
58        return true;
59    }
60}
61// vim:et:ts=4:sw=4:enc=utf-8:
62