xref: /plugin/struct/types/LongText.php (revision b193f1ee28c5fa11f136bc19373095ca8f6d073d)
1<?php
2namespace dokuwiki\plugin\struct\types;
3
4use dokuwiki\plugin\struct\meta\QueryBuilder;
5use dokuwiki\plugin\struct\meta\QueryBuilderWhere;
6
7class LongText extends AbstractMultiBaseType {
8    use TraitFilterPrefix;
9
10    protected $config = array(
11        'prefix' => '',
12        'postfix' => '',
13        'rows' => '5',
14        'cols' => '50'
15    );
16
17
18    /**
19     * Output the stored data
20     *
21     * @param string|int $value the value stored in the database
22     * @param \Doku_Renderer $R the renderer currently used to render the data
23     * @param string $mode The mode the output is rendered in (eg. XHTML)
24     * @return bool true if $mode could be satisfied
25     */
26    public function renderValue($value, \Doku_Renderer $R, $mode) {
27        $R->cdata($this->config['prefix'] . $value . $this->config['postfix']);
28        return true;
29    }
30
31    /**
32     * Clean line endings
33     *
34     * @param int|string $rawvalue
35     * @return int|string
36     */
37    public function validate($rawvalue) {
38        $rawvalue = rtrim($rawvalue);
39        $rawvalue = cleanText($rawvalue);
40        return $rawvalue;
41    }
42
43    /**
44     * Use a text area for input
45     *
46     * @param string $name
47     * @param string $rawvalue
48     * @param string $htmlID
49     *
50     * @return string
51     */
52    public function valueEditor($name, $rawvalue, $htmlID) {
53        $rawvalue = formText($rawvalue);
54        $params = array(
55            'name' => $name,
56            'class' => 'struct_'.strtolower($this->getClass()),
57            'id' => $htmlID,
58            'rows' => $this->config['rows'],
59            'cols' => $this->config['cols']
60        );
61        $attributes = buildAttributes($params, true);
62
63        return "<textarea $attributes>$rawvalue</textarea>";
64    }
65}
66