Merge branch 'MDL-70917-39' of git://github.com/paulholden/moodle into MOODLE_39_STABLE
[moodle.git] / lib / form / htmleditor.php
blob1d6d4b1f66bd7b8077773377b62a3791016343a1
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * htmleditor type form element
21 * Contains HTML class for htmleditor type element
23 * @deprecated since 3.6
24 * @package core_form
25 * @copyright 2006 Jamie Pratt <me@jamiep.org>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 global $CFG;
30 require_once("$CFG->libdir/form/textarea.php");
32 /**
33 * htmleditor type form element
35 * HTML class for htmleditor type element
37 * @package core_form
38 * @category form
39 * @copyright 2006 Jamie Pratt <me@jamiep.org>
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
43 /** @var string defines the type of editor */
44 var $_type;
46 /** @var array default options for html editor, which can be overridden */
47 var $_options=array('rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0);
49 /**
50 * Constructor
52 * @param string $elementName (optional) name of the html editor
53 * @param string $elementLabel (optional) editor label
54 * @param array $options set of options to create html editor
55 * @param array $attributes (optional) Either a typical HTML attribute string
56 * or an associative array
58 public function __construct($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
59 debugging("The form element 'htmleditor' has been deprecated. Please use the 'editor' element instead.", DEBUG_DEVELOPER);
61 parent::__construct($elementName, $elementLabel, $attributes);
62 // set the options, do not bother setting bogus ones
63 if (is_array($options)) {
64 foreach ($options as $name => $value) {
65 if (array_key_exists($name, $this->_options)) {
66 if (is_array($value) && is_array($this->_options[$name])) {
67 $this->_options[$name] = @array_merge($this->_options[$name], $value);
68 } else {
69 $this->_options[$name] = $value;
74 $this->_type='htmleditor';
76 editors_head_setup();
79 /**
80 * Old syntax of class constructor. Deprecated in PHP7.
82 * @deprecated since Moodle 3.1
84 public function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
85 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
86 self::__construct($elementName, $elementLabel, $options, $attributes);
89 /**
90 * Returns the input field in HTML
92 * @return string
94 public function toHtml() {
95 global $OUTPUT;
97 if ($this->_flagFrozen) {
98 return $this->getFrozenHtml();
99 } else {
100 $value = preg_replace("/(\r\n|\n|\r)/", '&#010;', $this->getValue());
102 return $this->_getTabs() .
103 $OUTPUT->print_textarea($this->getName(), $this->getAttribute('id'), $value, $this->_options['rows'],
104 $this->_options['cols']);
109 * What to display when element is frozen.
111 * @return string
113 function getFrozenHtml()
115 $html = format_text($this->getValue());
116 return $html . $this->_getPersistantData();