1<?php
2/**
3 * Class helper_plugin_bureaucracyau_fieldwiki
4 *
5 * Adds some static text to the form, but parses the input as Wiki syntax (computationally expensive)
6 */
7class helper_plugin_bureaucracyau_fieldwiki extends helper_plugin_bureaucracyau_field {
8
9    protected $tpl = '<p>@@LABEL@@</p>';
10
11    /**
12     * Arguments:
13     *  - cmd
14     *  - wiki text
15     *
16     * @param array $args The tokenized definition, only split at spaces
17     */
18    public function initialize($args) {
19        parent::initialize($args);
20        // make always optional to prevent being marked as required
21        $this->opt['optional'] = true;
22    }
23
24    /**
25     * Handle a post to the field
26     *
27     * @param null $value empty
28     * @param helper_plugin_bureaucracyau_field[] $fields (reference) form fields (POST handled upto $this field)
29     * @param int    $index  index number of field in form
30     * @param int    $formid unique identifier of the form which contains this field
31     * @return bool Whether the passed value is valid
32     */
33    public function handle_post($value, &$fields, $index, $formid) {
34        return true;
35    }
36
37    /**
38     * Get an arbitrary parameter
39     *
40     * @param string $name
41     * @return mixed|null
42     */
43    public function getParam($name) {
44        return ($name === 'value') ? null : parent::getParam($name);
45    }
46
47    /**
48     * Returns parsed wiki instructions
49     *
50     * @param string|array $tpl    The template as string
51     * @param array        $params A hash mapping parameters to values
52     *
53     * @return string The parsed template
54     */
55    protected function _parse_tpl($tpl, $params) {
56        $ins = array_slice(p_get_instructions($params['display']), 2, -2);
57        $tpl = p_render('xhtml', $ins, $byref_ignore);
58        return '<p>'.$tpl.'</p>';
59    }
60}
61