3 require_once("$CFG->libdir/form/textarea.php");
6 * HTML class for htmleditor type element
11 class MoodleQuickForm_htmleditor
extends MoodleQuickForm_textarea
{
13 var $_canUseHtmlEditor;
14 var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0, 'course'=>0);
15 function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
16 parent
::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
17 // set the options, do not bother setting bogus ones
18 if (is_array($options)) {
19 foreach ($options as $name => $value) {
20 if (isset($this->_options
[$name])) {
21 if (is_array($value) && is_array($this->_options
[$name])) {
22 $this->_options
[$name] = @array_merge
($this->_options
[$name], $value);
24 $this->_options
[$name] = $value;
29 if ($this->_options
['canUseHtmlEditor']=='detect'){
30 $this->_options
['canUseHtmlEditor']=can_use_html_editor();
32 if ($this->_options
['canUseHtmlEditor']){
33 $this->_type
='htmleditor';
34 //$this->_elementTemplateType='wide';
36 $this->_type
='textarea';
38 $this->_canUseHtmlEditor
= $this->_options
['canUseHtmlEditor'];
41 * set html for help button
44 * @param array $help array of arguments to make a help button
45 * @param string $function function name to call to get html
47 function setHelpButton($helpbuttonargs, $function='helpbutton'){
48 if (!$this->_canUseHtmlEditor
){
49 if ('editorhelpbutton' == $function){
50 $key = array_search('richtext', $helpbuttonargs);
52 array_splice($helpbuttonargs, $key, 1, array('text', 'emoticons'));
54 } elseif ('helpbutton' == $function && $helpbuttonargs[0] == 'richtext' && ((!isset($helpbuttonargs[2])) ||
$helpbuttonargs[2] == 'moodle')){
55 //replace single 'richtext' help button with text and emoticon button when htmleditor off.
56 return $this->setHelpButton(array('text', 'emoticons'), 'editorhelpbutton');
59 return parent
::setHelpButton($helpbuttonargs, $function);
63 if ($this->_canUseHtmlEditor
&& !$this->_flagFrozen
){
65 use_html_editor($this->getName(), '', $this->getAttribute('id'));
66 $script=ob_get_clean();
70 if ($this->_flagFrozen
) {
71 return $this->getFrozenHtml();
73 return $this->_getTabs() .
74 print_textarea($this->_canUseHtmlEditor
,
75 $this->_options
['rows'],
76 $this->_options
['cols'],
77 $this->_options
['width'],
78 $this->_options
['height'],
80 preg_replace("/(\r\n|\n|\r)/", '
',$this->getValue()),
81 $this->_options
['course'],
83 $this->getAttribute('id')).$script;
88 * What to display when element is frozen.
93 function getFrozenHtml()
95 $html = format_text($this->getValue());
96 return $html . $this->_getPersistantData();
97 } //end func getFrozenHtml