diff --git a/mod/data/field/textarea/field.class.php b/mod/data/field/textarea/field.class.php index e07e7a7a46e..a6d3eaa44bd 100755 --- a/mod/data/field/textarea/field.class.php +++ b/mod/data/field/textarea/field.class.php @@ -21,44 +21,61 @@ // // /////////////////////////////////////////////////////////////////////////// +require_once($CFG->dirroot.'/lib/filelib.php'); +require_once($CFG->dirroot.'/repository/lib.php'); + class data_field_textarea extends data_field_base { var $type = 'textarea'; function display_add_field($recordid=0) { - global $CFG, $DB, $OUTPUT; + global $CFG, $DB, $OUTPUT, $PAGE; $text = ''; $format = 0; - if ($recordid){ - if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { - $text = $content->content; - $format = $content->content1; - } - } - $str = '
'; - if (can_use_html_editor()) { - // Show a rich text html editor. - $str .= $this->gen_textarea(true, $text); - $str .= $OUTPUT->help_icon(moodle_help_icon::make("richtext2", get_string("helprichtext"), 'moodle', true)); - $str .= ''; + editors_head_setup(); + $options = array(); + $options['trusttext'] = false; + $options['forcehttps'] = false; + $options['subdirs'] = false; + $options['maxfiles'] = 0; + $options['maxbytes'] = 0; + $options['changeformat'] = 0; + $options['noclean'] = false; + + $itemid = $this->field->id; + $field = 'field_'.$itemid; + + if ($recordid && $content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))){ + $text = $content->content; + $format = $content->content1; + } else if (can_use_html_editor()) { + $format = FORMAT_HTML; } else { - // Show a normal textarea. Also let the user specify the format to be used. - $str .= $this->gen_textarea(false, $text); - - // Get the available text formats for this field. - $formatsForField = format_text_menu(); - $str .= '
'; - $select = html_select( $formatsForField, 'field_' . $this->field->id . '_content1', $format); - $select->nothingvalue = ''; - $str .= $OUTPUT->select($select); - - $str .= $OUTPUT->help_icon(moodle_help_icon::make('textformat', get_string('helpformatting'), 'moodle')); + $format = FORMAT_PLAIN; } + + $editor = get_preferred_texteditor($format); + $strformats = format_text_menu(); + $formats = $editor->get_supported_formats(); + foreach ($formats as $fid) { + $formats[$fid] = $strformats[$fid]; + } + $editor->use_editor($field, $options); + $str .= '
'; + $str .= '
'; + $str .= $OUTPUT->help_icon(moodle_help_icon::make('textformat', get_string('helpformatting'), 'moodle')); + $str .= '
'; + $str .= '
'; return $str; } @@ -83,12 +100,6 @@ class data_field_textarea extends data_field_base { return array(" ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content $ILIKE :$name) ", array($name=>"%$value%")); } - function gen_textarea($usehtmleditor, $text='') { - return print_textarea($usehtmleditor, $this->field->param3, $this->field->param2, - '', '', 'field_'.$this->field->id, $text, '', true, 'field_' . $this->field->id); - } - - function print_after_form() { } diff --git a/mod/data/field/textarea/mod.html b/mod/data/field/textarea/mod.html index abe706dbce7..c53a69a5eaf 100755 --- a/mod/data/field/textarea/mod.html +++ b/mod/data/field/textarea/mod.html @@ -39,3 +39,4 @@ + diff --git a/mod/data/templates.php b/mod/data/templates.php index 21214c43d78..b486af70a3f 100755 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -151,6 +151,22 @@ if (empty($data->addtemplate) and empty($data->singletemplate) and data_generate_default_template($data, 'rsstemplate'); } +editors_head_setup(); +$format = FORMAT_HTML; +$editor = get_preferred_texteditor($format); +$strformats = format_text_menu(); +$formats = $editor->get_supported_formats(); +foreach ($formats as $fid) { + $formats[$fid] = $strformats[$fid]; +} +$options = array(); +$options['trusttext'] = false; +$options['forcehttps'] = false; +$options['subdirs'] = false; +$options['maxfiles'] = 0; +$options['maxbytes'] = 0; +$options['changeformat'] = 0; +$options['noclean'] = false; echo '
'; echo '
'; @@ -172,7 +188,11 @@ if ($mode == 'listtemplate'){ echo ' '; echo ''; echo '
'; - print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplateheader', $data->listtemplateheader); + + $field = 'listtemplateheader'; + $editor->use_editor($field, $options); + echo '
'; + echo ''; echo ''; } @@ -263,7 +283,9 @@ if ($mode == 'listtemplate'){ echo '
'; } -print_textarea($usehtmleditor, 20, 72, 0, 0, 'template', $data->{$mode}); +$field = 'template'; +$editor->use_editor($field, $options); +echo '
'; echo ''; echo ''; @@ -272,7 +294,10 @@ if ($mode == 'listtemplate'){ echo ' '; echo ''; echo '
'; - print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplatefooter', $data->listtemplatefooter); + + $field = 'listtemplatefooter'; + $editor->use_editor($field, $options); + echo '
'; echo ''; echo ''; } else if ($mode == 'rsstemplate') { @@ -280,7 +305,10 @@ if ($mode == 'listtemplate'){ echo ' '; echo ''; echo '
'; - print_textarea($usehtmleditor, 10, 72, 0, 0, 'rsstitletemplate', $data->rsstitletemplate); + + $field = 'rsstitletemplate'; + $editor->use_editor($field, $options); + echo '
'; echo ''; echo ''; }