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