Fixing typo
[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 $_elementTemplateType='default';
14 var $_canUseHtmlEditor;
5ce73257 15 var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0, 'course'=>0);
7f40a229 16 function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
17 parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
5ae70385 18 // set the options, do not bother setting bogus ones
19 if (is_array($options)) {
20 foreach ($options as $name => $value) {
21 if (isset($this->_options[$name])) {
22 if (is_array($value) && is_array($this->_options[$name])) {
23 $this->_options[$name] = @array_merge($this->_options[$name], $value);
24 } else {
25 $this->_options[$name] = $value;
26 }
27 }
28 }
29 }
30 if ($this->_options['canUseHtmlEditor']=='detect'){
31 $this->_options['canUseHtmlEditor']=can_use_html_editor();
32 }
33 if ($this->_options['canUseHtmlEditor']){
80f962df 34 $this->_type='htmleditor';
35 //$this->_elementTemplateType='wide';
da6f8763 36 }else{
80f962df 37 $this->_type='textarea';
da6f8763 38 }
5ce73257 39 $this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
40 }
41 /**
42 * set html for help button
43 *
44 * @access public
45 * @param array $help array of arguments to make a help button
46 * @param string $function function name to call to get html
47 */
48 function setHelpButton($helpbuttonargs, $function='helpbutton'){
49 if (!$this->_canUseHtmlEditor){
50 if ('editorhelpbutton' == $function){
51 $key = array_search('richtext', $helpbuttonargs);
52 if ($key !== FALSE){
53 $helpbuttonargs[$key]='emoticons';
54 }
55 }
56 }
57 return parent::setHelpButton($helpbuttonargs, $function);
da6f8763 58 }
59 function getElementTemplateType(){
60 return $this->_elementTemplateType;
61 }
62 function toHtml(){
5ce73257 63 if ($this->_canUseHtmlEditor && !$this->_flagFrozen){
80f962df 64 ob_start();
7850588a 65 use_html_editor($this->getName(), '', $this->getAttribute('id'));
80f962df 66 $script=ob_get_clean();
67 } else {
68 $script='';
69 }
da6f8763 70 if ($this->_flagFrozen) {
71 return $this->getFrozenHtml();
72 } else {
73 return $this->_getTabs() .
5ce73257 74 print_textarea($this->_canUseHtmlEditor,
5ae70385 75 $this->_options['rows'],
76 $this->_options['cols'],
77 $this->_options['width'],
78 $this->_options['height'],
da6f8763 79 $this->getName(),
80 preg_replace("/(\r\n|\n|\r)/", '&#010;',$this->getValue()),
81 $this->_options['course'],
7850588a 82 true,
83 $this->getAttribute('id')).$script;
da6f8763 84 }
85 } //end func toHtml
86
87}
88?>