weekly release 4.0dev
[moodle.git] / lib / form / htmleditor.php
CommitLineData
da6f8763 1<?php
6c1fd304
RT
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.
13//
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/>.
16
17
18/**
19 * htmleditor type form element
20 *
21 * Contains HTML class for htmleditor type element
22 *
f8d15c66 23 * @deprecated since 3.6
6c1fd304
RT
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
27 */
28
da6f8763 29global $CFG;
30require_once("$CFG->libdir/form/textarea.php");
31
32/**
6c1fd304
RT
33 * htmleditor type form element
34 *
da6f8763 35 * HTML class for htmleditor type element
5ce73257 36 *
6c1fd304
RT
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
da6f8763 41 */
7f40a229 42class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
6c1fd304 43 /** @var string defines the type of editor */
80f962df 44 var $_type;
6c1fd304 45
6c1fd304 46 /** @var array default options for html editor, which can be overridden */
3d27180e 47 var $_options=array('rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0);
6c1fd304
RT
48
49 /**
50 * Constructor
51 *
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
57 */
1a0df553 58 public function __construct($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
f8d15c66
MN
59 debugging("The form element 'htmleditor' has been deprecated. Please use the 'editor' element instead.", DEBUG_DEVELOPER);
60
1a0df553 61 parent::__construct($elementName, $elementLabel, $attributes);
5ae70385 62 // set the options, do not bother setting bogus ones
63 if (is_array($options)) {
64 foreach ($options as $name => $value) {
d3919c25 65 if (array_key_exists($name, $this->_options)) {
5ae70385 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;
70 }
71 }
72 }
73 }
3d27180e 74 $this->_type='htmleditor';
ff5fe311 75
76 editors_head_setup();
5ce73257 77 }
6c1fd304 78
1a0df553
MG
79 /**
80 * Old syntax of class constructor. Deprecated in PHP7.
81 *
82 * @deprecated since Moodle 3.1
83 */
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);
87 }
88
6c1fd304
RT
89 /**
90 * Returns the input field in HTML
91 *
92 * @return string
93 */
4d67fe61
MN
94 public function toHtml() {
95 global $OUTPUT;
96
da6f8763 97 if ($this->_flagFrozen) {
98 return $this->getFrozenHtml();
99 } else {
4d67fe61
MN
100 $value = preg_replace("/(\r\n|\n|\r)/", '&#010;', $this->getValue());
101
da6f8763 102 return $this->_getTabs() .
4d67fe61
MN
103 $OUTPUT->print_textarea($this->getName(), $this->getAttribute('id'), $value, $this->_options['rows'],
104 $this->_options['cols']);
da6f8763 105 }
6c1fd304 106 }
da6f8763 107
bb90bf3f 108 /**
109 * What to display when element is frozen.
110 *
6c1fd304 111 * @return string
bb90bf3f 112 */
113 function getFrozenHtml()
114 {
115 $html = format_text($this->getValue());
116 return $html . $this->_getPersistantData();
6c1fd304 117 }
da6f8763 118}