mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-14589: copying the current htmleditor element to editor, prior to filepicker removal from the old one.
This commit is contained in:
parent
97844c1dda
commit
0b94f32019
98
lib/form/editor.php
Normal file
98
lib/form/editor.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
global $CFG;
|
||||
require_once("$CFG->libdir/form/textarea.php");
|
||||
|
||||
/**
|
||||
* HTML class for htmleditor type element
|
||||
*
|
||||
* @author Jamie Pratt
|
||||
* @access public
|
||||
*/
|
||||
class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
|
||||
var $_type;
|
||||
var $_canUseHtmlEditor;
|
||||
var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0, 'filearea'=>'');
|
||||
function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
|
||||
parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
|
||||
// set the options, do not bother setting bogus ones
|
||||
if (is_array($options)) {
|
||||
foreach ($options as $name => $value) {
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
if (is_array($value) && is_array($this->_options[$name])) {
|
||||
$this->_options[$name] = @array_merge($this->_options[$name], $value);
|
||||
} else {
|
||||
$this->_options[$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->_options['canUseHtmlEditor']=='detect'){
|
||||
$this->_options['canUseHtmlEditor']=can_use_html_editor();
|
||||
}
|
||||
if ($this->_options['canUseHtmlEditor']){
|
||||
$this->_type='htmleditor';
|
||||
//$this->_elementTemplateType='wide';
|
||||
}else{
|
||||
$this->_type='textarea';
|
||||
}
|
||||
$this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
|
||||
}
|
||||
/**
|
||||
* set html for help button
|
||||
*
|
||||
* @access public
|
||||
* @param array $help array of arguments to make a help button
|
||||
* @param string $function function name to call to get html
|
||||
*/
|
||||
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
||||
if (!$this->_canUseHtmlEditor){
|
||||
if ('editorhelpbutton' == $function){
|
||||
$key = array_search('richtext2', $helpbuttonargs);
|
||||
if ($key !== FALSE){
|
||||
array_splice($helpbuttonargs, $key, 1, array('text2', 'emoticons2'));
|
||||
}
|
||||
} elseif ('helpbutton' == $function && $helpbuttonargs[0] == 'richtext2' && ((!isset($helpbuttonargs[2])) || $helpbuttonargs[2] == 'moodle')){
|
||||
//replace single 'richtext' help button with text and emoticon button when htmleditor off.
|
||||
return $this->setHelpButton(array('text2', 'emoticons2'), 'editorhelpbutton');
|
||||
}
|
||||
}
|
||||
return parent::setHelpButton($helpbuttonargs, $function);
|
||||
}
|
||||
|
||||
function toHtml(){
|
||||
//if ($this->_canUseHtmlEditor && !$this->_flagFrozen){
|
||||
// $script = '';
|
||||
//} else {
|
||||
// $script='';
|
||||
//}
|
||||
if ($this->_flagFrozen) {
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->_getTabs() .
|
||||
'<input type="hidden" name="filearea" value="'. $this->_options['filearea'] .'" />'."\n".
|
||||
print_textarea($this->_canUseHtmlEditor,
|
||||
$this->_options['rows'],
|
||||
$this->_options['cols'],
|
||||
$this->_options['width'],
|
||||
$this->_options['height'],
|
||||
$this->getName(),
|
||||
preg_replace("/(\r\n|\n|\r)/", '
',$this->getValue()),
|
||||
0, // unused anymore
|
||||
true,
|
||||
$this->getAttribute('id'));
|
||||
}
|
||||
} //end func toHtml
|
||||
|
||||
/**
|
||||
* What to display when element is frozen.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getFrozenHtml()
|
||||
{
|
||||
$html = format_text($this->getValue());
|
||||
return $html . $this->_getPersistantData();
|
||||
} //end func getFrozenHtml
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user