From 539c7ca14834afcc3c5eae7699e69fcbb55d34b0 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Thu, 23 Feb 2012 14:30:26 +0800 Subject: [PATCH] MDL-23787 added possibility to embed images into textarea fields in database activity Conflicts: mod/data/field/textarea/lang/en/datafield_textarea.php --- mod/data/field/textarea/field.class.php | 145 +++++++++++++++--- .../textarea/lang/en/datafield_textarea.php | 29 ++++ mod/data/field/textarea/mod.html | 8 + 3 files changed, 164 insertions(+), 18 deletions(-) create mode 100644 mod/data/field/textarea/lang/en/datafield_textarea.php 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 .= '
+ + +