diff --git a/mod/data/field/textarea/field.class.php b/mod/data/field/textarea/field.class.php
index 6f2db0c2045..a15dfb2e3ee 100644
--- a/mod/data/field/textarea/field.class.php
+++ b/mod/data/field/textarea/field.class.php
@@ -28,6 +28,27 @@ class data_field_textarea extends data_field_base {
var $type = 'textarea';
+ /**
+ * Returns options for embedded files
+ *
+ * @return array
+ */
+ private function get_options() {
+ if (!isset($this->field->param5)) {
+ $this->field->param5 = 0;
+ }
+ $options = array();
+ $options['trusttext'] = false;
+ $options['forcehttps'] = false;
+ $options['subdirs'] = false;
+ $options['maxfiles'] = -1;
+ $options['context'] = $this->context;
+ $options['maxbytes'] = $this->field->param5;
+ $options['changeformat'] = 0;
+ $options['noclean'] = false;
+ return $options;
+ }
+
function display_add_field($recordid=0) {
global $CFG, $DB, $OUTPUT, $PAGE;
@@ -37,27 +58,63 @@ class data_field_textarea extends data_field_base {
$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;
+ $options = $this->get_options();
$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;
- $text = clean_text($text, $format);
- } else if (can_use_html_editor()) {
- $format = FORMAT_HTML;
+ $text = clean_text($content->content, $format);
+ $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text);
} else {
- $format = FORMAT_PLAIN;
+ $draftitemid = file_get_unused_draft_itemid();
+ if (can_use_html_editor()) {
+ $format = FORMAT_HTML;
+ } else {
+ $format = FORMAT_PLAIN;
+ }
+ }
+
+ // get filepicker info
+ //
+ $fpoptions = array();
+ if ($options['maxfiles'] != 0 ) {
+ $args = new stdClass();
+ // need these three to filter repositories list
+ $args->accepted_types = array('image');
+ $args->return_types = (FILE_INTERNAL | FILE_EXTERNAL);
+ $args->context = $this->context;
+ $args->env = 'filepicker';
+ // advimage plugin
+ $image_options = initialise_filepicker($args);
+ $image_options->context = $this->context;
+ $image_options->client_id = uniqid();
+ $image_options->maxbytes = $options['maxbytes'];
+ $image_options->env = 'editor';
+ $image_options->itemid = $draftitemid;
+
+ // moodlemedia plugin
+ $args->accepted_types = array('video', 'audio');
+ $media_options = initialise_filepicker($args);
+ $media_options->context = $this->context;
+ $media_options->client_id = uniqid();
+ $media_options->maxbytes = $options['maxbytes'];
+ $media_options->env = 'editor';
+ $media_options->itemid = $draftitemid;
+
+ // advlink plugin
+ $args->accepted_types = '*';
+ $link_options = initialise_filepicker($args);
+ $link_options->context = $this->context;
+ $link_options->client_id = uniqid();
+ $link_options->maxbytes = $options['maxbytes'];
+ $link_options->env = 'editor';
+ $link_options->itemid = $draftitemid;
+
+ $fpoptions['image'] = $image_options;
+ $fpoptions['media'] = $media_options;
+ $fpoptions['link'] = $link_options;
}
$editor = editors_get_preferred_editor($format);
@@ -66,7 +123,8 @@ class data_field_textarea extends data_field_base {
foreach ($formats as $fid) {
$formats[$fid] = $strformats[$fid];
}
- $editor->use_editor($field, $options);
+ $editor->use_editor($field, $options, $fpoptions);
+ $str .= '
';
$str .= '
';
$str .= '