"HTMLFragment", "UpperCase" => "HTMLFragment", ); /** * Enable shortcode parsing on this field * * @var bool */ protected $processShortcodes = false; /** * Check if shortcodes are enabled * * @return bool */ public function getProcessShortcodes() { return $this->processShortcodes; } /** * Set shortcodes on or off by default * * @param bool $process * @return $this */ public function setProcessShortcodes($process) { $this->processShortcodes = (bool)$process; return $this; } /** * @param array $options * * Options accepted in addition to those provided by Text: * * - shortcodes: If true, shortcodes will be turned into the appropriate HTML. * If false, shortcodes will not be processed. * * - whitelist: If provided, a comma-separated list of elements that will be allowed to be stored * (be careful on relying on this for XSS protection - some seemingly-safe elements allow * attributes that can be exploited, for instance ) * Text nodes outside of HTML tags are filtered out by default, but may be included by adding * the text() directive. E.g. 'link,meta,text()' will allow only and text at * the root level. * * @return $this */ public function setOptions(array $options = array()) { if(array_key_exists("shortcodes", $options)) { $this->setProcessShortcodes(!!$options["shortcodes"]); } return parent::setOptions($options); } public function forTemplate() { // Suppress XML encoding for DBHtmlText return $this->RAW(); } public function RAW() { if ($this->processShortcodes) { return ShortcodeParser::get_active()->parse($this->value); } else { return $this->value; } } /** * Safely escape for XML string * * @return string */ public function CDATA() { return sprintf( '', str_replace(']]>', ']]]]>', $this->RAW()) ); } /** * Get plain-text version. * * Note: unlike DBHTMLText, this doesn't respect line breaks / paragraphs * * @return string */ public function Plain() { // Strip out HTML $text = strip_tags($this->RAW()); // Convert back to plain text return trim(Convert::xml2raw($text)); } public function scaffoldFormField($title = null, $params = null) { return new HTMLEditorField($this->name, $title, 1); } public function scaffoldSearchField($title = null) { return new TextField($this->name, $title); } public function getSchemaValue() { // Form schema format as HTML $value = $this->RAW(); if($value) { return [ 'html' => $this->RAW() ]; } return null; } }