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 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 $rawvalue = rtrim($rawvalue); 44 $rawvalue = cleanText($rawvalue); 45 return $rawvalue; 46 } 47 48 /** 49 * Use a text area for input 50 * 51 * @param string $name 52 * @param string $rawvalue 53 * @param string $htmlID 54 * 55 * @return string 56 */ 57 public function valueEditor($name, $rawvalue, $htmlID) { 58 $rawvalue = formText($rawvalue); 59 $params = array( 60 'name' => $name, 61 'class' => 'struct_'.strtolower($this->getClass()), 62 'id' => $htmlID, 63 'rows' => $this->config['rows'], 64 'cols' => $this->config['cols'] 65 ); 66 $attributes = buildAttributes($params, true); 67 68 return "<textarea $attributes>$rawvalue</textarea>"; 69 } 70} 71