2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * htmleditor type form element
21 * Contains HTML class for htmleditor type element
24 * @copyright 2006 Jamie Pratt <me@jamiep.org>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 require_once("$CFG->libdir/form/textarea.php");
32 * htmleditor type form element
34 * HTML class for htmleditor type element
38 * @copyright 2006 Jamie Pratt <me@jamiep.org>
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 class MoodleQuickForm_htmleditor
extends MoodleQuickForm_textarea
{
42 /** @var string defines the type of editor */
45 /** @var array default options for html editor, which can be overridden */
46 var $_options=array('rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0);
51 * @param string $elementName (optional) name of the html editor
52 * @param string $elementLabel (optional) editor label
53 * @param array $options set of options to create html editor
54 * @param array $attributes (optional) Either a typical HTML attribute string
55 * or an associative array
57 function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
58 parent
::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
59 // set the options, do not bother setting bogus ones
60 if (is_array($options)) {
61 foreach ($options as $name => $value) {
62 if (array_key_exists($name, $this->_options
)) {
63 if (is_array($value) && is_array($this->_options
[$name])) {
64 $this->_options
[$name] = @array_merge
($this->_options
[$name], $value);
66 $this->_options
[$name] = $value;
71 $this->_type
='htmleditor';
77 * Returns the input field in HTML
82 if ($this->_flagFrozen
) {
83 return $this->getFrozenHtml();
85 return $this->_getTabs() .
87 $this->_options
['rows'],
88 $this->_options
['cols'],
89 $this->_options
['width'],
90 $this->_options
['height'],
92 preg_replace("/(\r\n|\n|\r)/", '
',$this->getValue()),
95 $this->getAttribute('id'));
100 * What to display when element is frozen.
104 function getFrozenHtml()
106 $html = format_text($this->getValue());
107 return $html . $this->_getPersistantData();