xref: /plugin/struct/types/Wiki.php (revision 127d6bacbaa5831b9606d5ae91b03cfbe9108473)
1<?php
2namespace dokuwiki\plugin\struct\types;
3
4use dokuwiki\plugin\struct\meta\QueryBuilderWhere;
5
6class Wiki extends AbstractBaseType {
7    use TraitFilterPrefix;
8
9    protected $config = array(
10        'prefix' => '',
11        'postfix' => '',
12    );
13
14    /**
15     * @param int|string $value
16     * @param \Doku_Renderer $R
17     * @param string $mode
18     * @return bool
19     */
20    public function renderValue($value, \Doku_Renderer $R, $mode) {
21        $value = $this->config['prefix'] . $value . $this->config['postfix'];
22        $doc = p_render($mode, p_get_instructions($value), $info);
23        $R->doc .= $doc; // FIXME this probably does not work for all renderers
24        return true;
25    }
26
27    /**
28     * Clean line endings
29     *
30     * @param int|string $rawvalue
31     * @return int|string
32     */
33    public function validate($rawvalue) {
34        $rawvalue = rtrim($rawvalue);
35        $rawvalue = cleanText($rawvalue);
36        return $rawvalue;
37    }
38
39    /**
40     * Use a text area for input
41     *
42     * @param string $name
43     * @param string $rawvalue
44     * @return string
45     */
46    public function valueEditor($name, $rawvalue) {
47        $class = 'struct_'.strtolower($this->getClass());
48        $name = hsc($name);
49        $rawvalue = formText($rawvalue);
50
51        $html = "<textarea name=\"$name\" class=\"$class\">$rawvalue</textarea>";
52        return "$html";
53    }
54}
55