Automatic installer lang files (20110214)
[moodle.git] / lib / form / htmleditor.php
blob0dbc0b737a2d5532653f2e068be42a4448414f0e
1 <?php
2 global $CFG;
3 require_once("$CFG->libdir/form/textarea.php");
5 /**
6 * HTML class for htmleditor type element
8 * @author Jamie Pratt
9 * @access public
11 class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
12 var $_type;
13 var $_canUseHtmlEditor;
14 var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>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 (array_key_exists($name, $this->_options)) {
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;
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';
35 }else{
36 $this->_type='textarea';
38 $this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
40 editors_head_setup();
42 /**
43 * set html for help button
45 * @access public
46 * @param array $help array of arguments to make a help button
47 * @param string $function function name to call to get html
49 function setHelpButton($helpbuttonargs, $function='helpbutton'){
50 debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
53 function toHtml(){
54 //if ($this->_canUseHtmlEditor && !$this->_flagFrozen){
55 // $script = '';
56 //} else {
57 // $script='';
58 //}
59 if ($this->_flagFrozen) {
60 return $this->getFrozenHtml();
61 } else {
62 return $this->_getTabs() .
63 print_textarea($this->_canUseHtmlEditor,
64 $this->_options['rows'],
65 $this->_options['cols'],
66 $this->_options['width'],
67 $this->_options['height'],
68 $this->getName(),
69 preg_replace("/(\r\n|\n|\r)/", '&#010;',$this->getValue()),
70 0, // unused anymore
71 true,
72 $this->getAttribute('id'));
74 } //end func toHtml
76 /**
77 * What to display when element is frozen.
79 * @access public
80 * @return string
82 function getFrozenHtml()
84 $html = format_text($this->getValue());
85 return $html . $this->_getPersistantData();
86 } //end func getFrozenHtml