MDL-14741: use the default html editor, as chosen in the admin settings
[moodle.git] / lib / form / htmleditor.php
CommitLineData
da6f8763 1<?php
2global $CFG;
3require_once("$CFG->libdir/form/textarea.php");
4
5/**
6 * HTML class for htmleditor type element
5ce73257 7 *
da6f8763 8 * @author Jamie Pratt
9 * @access public
10 */
7f40a229 11class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
80f962df 12 var $_type;
da6f8763 13 var $_canUseHtmlEditor;
5ce73257 14 var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0, 'course'=>0);
7f40a229 15 function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
16 parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
5ae70385 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);
23 } else {
24 $this->_options[$name] = $value;
25 }
26 }
27 }
28 }
29 if ($this->_options['canUseHtmlEditor']=='detect'){
30 $this->_options['canUseHtmlEditor']=can_use_html_editor();
31 }
32 if ($this->_options['canUseHtmlEditor']){
80f962df 33 $this->_type='htmleditor';
34 //$this->_elementTemplateType='wide';
da6f8763 35 }else{
80f962df 36 $this->_type='textarea';
da6f8763 37 }
5ce73257 38 $this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
39 }
40 /**
41 * set html for help button
42 *
43 * @access public
44 * @param array $help array of arguments to make a help button
45 * @param string $function function name to call to get html
46 */
47 function setHelpButton($helpbuttonargs, $function='helpbutton'){
48 if (!$this->_canUseHtmlEditor){
49 if ('editorhelpbutton' == $function){
50 $key = array_search('richtext', $helpbuttonargs);
51 if ($key !== FALSE){
18a77361 52 array_splice($helpbuttonargs, $key, 1, array('text', 'emoticons'));
5ce73257 53 }
18a77361 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');
5ce73257 57 }
58 }
59 return parent::setHelpButton($helpbuttonargs, $function);
da6f8763 60 }
64360ee7 61
da6f8763 62 function toHtml(){
5ce73257 63 if ($this->_canUseHtmlEditor && !$this->_flagFrozen){
b26be9a9 64 global $htmlEditorObject;
65 $script = $htmlEditorObject->activateEditor($this->getName(), $this->getAttribute('id'));
80f962df 66 } else {
67 $script='';
68 }
da6f8763 69 if ($this->_flagFrozen) {
70 return $this->getFrozenHtml();
71 } else {
72 return $this->_getTabs() .
5ce73257 73 print_textarea($this->_canUseHtmlEditor,
5ae70385 74 $this->_options['rows'],
75 $this->_options['cols'],
76 $this->_options['width'],
77 $this->_options['height'],
da6f8763 78 $this->getName(),
79 preg_replace("/(\r\n|\n|\r)/", '&#010;',$this->getValue()),
80 $this->_options['course'],
7850588a 81 true,
82 $this->getAttribute('id')).$script;
da6f8763 83 }
84 } //end func toHtml
85
bb90bf3f 86 /**
87 * What to display when element is frozen.
88 *
89 * @access public
90 * @return string
91 */
92 function getFrozenHtml()
93 {
94 $html = format_text($this->getValue());
95 return $html . $this->_getPersistantData();
96 } //end func getFrozenHtml
da6f8763 97}
b26be9a9 98?>