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