summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/bureaucracy/helper/fieldwiki.php
blob: dada855ad4c98803c4987d631c3ed5689dab4381 (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
70
<?php
/**
 * Class helper_plugin_bureaucracy_fieldwiki
 *
 * Adds some static text to the form, but parses the input as Wiki syntax (computationally expensive)
 */
class helper_plugin_bureaucracy_fieldwiki extends helper_plugin_bureaucracy_field {

    protected $tpl = '<p>@@LABEL@@</p>';

    /**
     * Arguments:
     *  - cmd
     *  - wiki text
     *
     * @param array $args The tokenized definition, only split at spaces
     */
    public function initialize($args) {
        parent::initialize($args);
        // make always optional to prevent being marked as required
        $this->opt['optional'] = true;
    }

    /**
     * Handle a post to the field
     *
     * @param null $value empty
     * @param helper_plugin_bureaucracy_field[] $fields (reference) form fields (POST handled upto $this field)
     * @param int    $index  index number of field in form
     * @param int    $formid unique identifier of the form which contains this field
     * @return bool Whether the passed value is valid
     */
    public function handle_post($value, &$fields, $index, $formid) {
        return true;
    }

    /**
     * Get an arbitrary parameter
     *
     * @param string $name
     * @return mixed|null
     */
    public function getParam($name) {
        return ($name === 'value') ? null : parent::getParam($name);
    }

    /**
     * Returns parsed wiki instructions
     *
     * @param string|array $tpl    The template as string
     * @param array        $params A hash mapping parameters to values
     *
     * @return string The parsed template
     */
    protected function _parse_tpl($tpl, $params) {
        $ins = p_get_instructions($params['display']);
        // remove document and p instructions (opening and closing)
        $start = 2;
        $end = 2;
        // check if struct instructions have to be removed as well from the beginning or end
        if (isset($ins[1][1][0]) && $ins[1][1][0] === 'struct_output') {
            $start = 3;
        } elseif (isset($ins[count($ins) - 2][1][0]) && $ins[count($ins) - 2][1][0] === 'struct_output') {
            $end = 3;
        }
        $ins = array_slice($ins, $start, -$end);
        $tpl = p_render('xhtml', $ins, $byref_ignore);
        return '<p>'.$tpl.'</p>';
    }
}