xref: /plugin/struct/types/Wiki.php (revision 48801f6d7d7ad3c56a635066943b271f49b9264e)
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     * @param string $htmlID
45     *
46     * @return string
47     */
48    public function valueEditor($name, $rawvalue, $htmlID) {
49        $rawvalue = formText($rawvalue);
50        $params = array(
51            'name' => $name,
52            'class' => 'struct_'.strtolower($this->getClass()),
53            'id' => $htmlID
54        );
55        $attributes = buildAttributes($params, true);
56
57        return "<textarea $attributes>$rawvalue</textarea>";
58    }
59}
60