19503405bSRandolf Rotta<?php 2d6d97f60SAnna Dabrowska 39503405bSRandolf Rottanamespace dokuwiki\plugin\struct\types; 49503405bSRandolf Rotta 5d6d97f60SAnna Dabrowskaclass LongText extends AbstractMultiBaseType 6d6d97f60SAnna Dabrowska{ 79503405bSRandolf Rotta use TraitFilterPrefix; 89503405bSRandolf Rotta 9*7fe2cdf2SAndreas Gohr protected $config = [ 10*7fe2cdf2SAndreas Gohr 'prefix' => '', 11*7fe2cdf2SAndreas Gohr 'postfix' => '', 12*7fe2cdf2SAndreas Gohr 'rows' => '5', 13*7fe2cdf2SAndreas Gohr 'cols' => '50' 14*7fe2cdf2SAndreas Gohr ]; 159503405bSRandolf Rotta 169503405bSRandolf Rotta 179503405bSRandolf Rotta /** 189503405bSRandolf Rotta * Output the stored data 199503405bSRandolf Rotta * 209503405bSRandolf Rotta * @param string|int $value the value stored in the database 219503405bSRandolf Rotta * @param \Doku_Renderer $R the renderer currently used to render the data 229503405bSRandolf Rotta * @param string $mode The mode the output is rendered in (eg. XHTML) 239503405bSRandolf Rotta * @return bool true if $mode could be satisfied 249503405bSRandolf Rotta */ 25d6d97f60SAnna Dabrowska public function renderValue($value, \Doku_Renderer $R, $mode) 26d6d97f60SAnna Dabrowska { 27f7222085SMichael Große if ($mode === 'xhtml') { 28e79e41afSMichael Große $valueWithBR = nl2br(hsc($value)); 29f7222085SMichael Große $R->doc .= hsc($this->config['prefix']) . $valueWithBR . hsc($this->config['postfix']); 30f7222085SMichael Große } else { 319503405bSRandolf Rotta $R->cdata($this->config['prefix'] . $value . $this->config['postfix']); 32f7222085SMichael Große } 339503405bSRandolf Rotta return true; 349503405bSRandolf Rotta } 359503405bSRandolf Rotta 369503405bSRandolf Rotta /** 379503405bSRandolf Rotta * Clean line endings 389503405bSRandolf Rotta * 399503405bSRandolf Rotta * @param int|string $rawvalue 409503405bSRandolf Rotta * @return int|string 419503405bSRandolf Rotta */ 42d6d97f60SAnna Dabrowska public function validate($rawvalue) 43d6d97f60SAnna Dabrowska { 449503405bSRandolf Rotta $rawvalue = rtrim($rawvalue); 459503405bSRandolf Rotta $rawvalue = cleanText($rawvalue); 469503405bSRandolf Rotta return $rawvalue; 479503405bSRandolf Rotta } 489503405bSRandolf Rotta 499503405bSRandolf Rotta /** 509503405bSRandolf Rotta * Use a text area for input 519503405bSRandolf Rotta * 529503405bSRandolf Rotta * @param string $name 539503405bSRandolf Rotta * @param string $rawvalue 549503405bSRandolf Rotta * @param string $htmlID 559503405bSRandolf Rotta * 569503405bSRandolf Rotta * @return string 579503405bSRandolf Rotta */ 58d6d97f60SAnna Dabrowska public function valueEditor($name, $rawvalue, $htmlID) 59d6d97f60SAnna Dabrowska { 609503405bSRandolf Rotta $rawvalue = formText($rawvalue); 61*7fe2cdf2SAndreas Gohr $params = [ 62*7fe2cdf2SAndreas Gohr 'name' => $name, 63*7fe2cdf2SAndreas Gohr 'class' => 'struct_' . strtolower($this->getClass()), 64*7fe2cdf2SAndreas Gohr 'id' => $htmlID, 65*7fe2cdf2SAndreas Gohr 'rows' => $this->config['rows'], 66*7fe2cdf2SAndreas Gohr 'cols' => $this->config['cols'] 67*7fe2cdf2SAndreas Gohr ]; 689503405bSRandolf Rotta $attributes = buildAttributes($params, true); 699503405bSRandolf Rotta 709503405bSRandolf Rotta return "<textarea $attributes>$rawvalue</textarea>"; 719503405bSRandolf Rotta } 729503405bSRandolf Rotta} 73