|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 global $CFG; 00003 require_once("$CFG->libdir/form/textarea.php"); 00004 00011 class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{ 00012 var $_type; 00013 var $_canUseHtmlEditor; 00014 var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0); 00015 function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){ 00016 parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes); 00017 // set the options, do not bother setting bogus ones 00018 if (is_array($options)) { 00019 foreach ($options as $name => $value) { 00020 if (array_key_exists($name, $this->_options)) { 00021 if (is_array($value) && is_array($this->_options[$name])) { 00022 $this->_options[$name] = @array_merge($this->_options[$name], $value); 00023 } else { 00024 $this->_options[$name] = $value; 00025 } 00026 } 00027 } 00028 } 00029 if ($this->_options['canUseHtmlEditor']=='detect'){ 00030 $this->_options['canUseHtmlEditor']=can_use_html_editor(); 00031 } 00032 if ($this->_options['canUseHtmlEditor']){ 00033 $this->_type='htmleditor'; 00034 //$this->_elementTemplateType='wide'; 00035 }else{ 00036 $this->_type='textarea'; 00037 } 00038 $this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor']; 00039 00040 editors_head_setup(); 00041 } 00049 function setHelpButton($helpbuttonargs, $function='helpbutton'){ 00050 debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead'); 00051 } 00052 00053 function toHtml(){ 00054 //if ($this->_canUseHtmlEditor && !$this->_flagFrozen){ 00055 // $script = ''; 00056 //} else { 00057 // $script=''; 00058 //} 00059 if ($this->_flagFrozen) { 00060 return $this->getFrozenHtml(); 00061 } else { 00062 return $this->_getTabs() . 00063 print_textarea($this->_canUseHtmlEditor, 00064 $this->_options['rows'], 00065 $this->_options['cols'], 00066 $this->_options['width'], 00067 $this->_options['height'], 00068 $this->getName(), 00069 preg_replace("/(\r\n|\n|\r)/", '
',$this->getValue()), 00070 0, // unused anymore 00071 true, 00072 $this->getAttribute('id')); 00073 } 00074 } //end func toHtml 00075 00082 function getFrozenHtml() 00083 { 00084 $html = format_text($this->getValue()); 00085 return $html . $this->_getPersistantData(); 00086 } //end func getFrozenHtml 00087 }