Merge branch 'MDL-62969_master' of git://github.com/markn86/moodle
[moodle.git] / lib / form / htmleditor.php
blob32353d673768c984c492a169d0f4bc39840a94da
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 * @package core_form
24 * @copyright 2006 Jamie Pratt <me@jamiep.org>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 global $CFG;
29 require_once("$CFG->libdir/form/textarea.php");
31 /**
32 * htmleditor type form element
34 * HTML class for htmleditor type element
36 * @package core_form
37 * @category form
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 */
43 var $_type;
45 /** @var array default options for html editor, which can be overridden */
46 var $_options=array('rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0);
48 /**
49 * Constructor
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 public function __construct($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
58 parent::__construct($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);
65 } else {
66 $this->_options[$name] = $value;
71 $this->_type='htmleditor';
73 editors_head_setup();
76 /**
77 * Old syntax of class constructor. Deprecated in PHP7.
79 * @deprecated since Moodle 3.1
81 public function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
82 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
83 self::__construct($elementName, $elementLabel, $options, $attributes);
86 /**
87 * Returns the input field in HTML
89 * @return string
91 function toHtml(){
92 if ($this->_flagFrozen) {
93 return $this->getFrozenHtml();
94 } else {
95 return $this->_getTabs() .
96 print_textarea(true,
97 $this->_options['rows'],
98 $this->_options['cols'],
99 $this->_options['width'],
100 $this->_options['height'],
101 $this->getName(),
102 preg_replace("/(\r\n|\n|\r)/", '&#010;',$this->getValue()),
103 0, // unused anymore
104 true,
105 $this->getAttribute('id'));
110 * What to display when element is frozen.
112 * @return string
114 function getFrozenHtml()
116 $html = format_text($this->getValue());
117 return $html . $this->_getPersistantData();