public function __construct(stdClass $options) { global $CFG, $USER, $PAGE; require_once $CFG->dirroot . '/repository/lib.php'; $defaults = array('accepted_types' => '*', 'return_types' => FILE_INTERNAL, 'env' => 'filepicker', 'client_id' => uniqid(), 'itemid' => 0, 'maxbytes' => -1, 'maxfiles' => 1, 'buttonname' => false); foreach ($defaults as $key => $value) { if (empty($options->{$key})) { $options->{$key} = $value; } } $options->currentfile = ''; if (!empty($options->itemid)) { $fs = get_file_storage(); $usercontext = get_context_instance(CONTEXT_USER, $USER->id); if (empty($options->filename)) { if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id DESC', false)) { $file = reset($files); } } else { $file = $fs->get_file($usercontext->id, 'user', 'draft', $options->itemid, $options->filepath, $options->filename); } if (!empty($file)) { $options->currentfile = html_writer::link(moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename()), $file->get_filename()); } } // initilise options, getting files in root path $this->options = initialise_filepicker($options); // copying other options foreach ($options as $name => $value) { if (!isset($this->options->{$name})) { $this->options->{$name} = $value; } } }
public function test_initialise_filepicker() { global $PAGE, $SITE; $this->resetAfterTest(true); $PAGE->set_url('/'); $PAGE->set_course($SITE); $this->setUser(2); $args = new stdClass(); $args->accepted_types = '*'; $args->return_types = array(FILE_EXTERNAL); $info = initialise_filepicker($args); $this->assertInstanceOf('stdClass', $info); $this->assertObjectHasAttribute('defaultlicense', $info); $this->assertObjectHasAttribute('licenses', $info); $this->assertObjectHasAttribute('author', $info); $this->assertObjectHasAttribute('externallink', $info); $this->assertObjectHasAttribute('accepted_types', $info); $this->assertObjectHasAttribute('return_types', $info); }
function display_add_field($recordid=0) { global $CFG, $DB, $OUTPUT, $PAGE; $text = ''; $format = 0; $str = '<div title="'.$this->field->description.'">'; editors_head_setup(); $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))){ $format = $content->content1; $text = clean_text($content->content, $format); $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text); } else { $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('web_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); $strformats = format_text_menu(); $formats = $editor->get_supported_formats(); foreach ($formats as $fid) { $formats[$fid] = $strformats[$fid]; } $editor->use_editor($field, $options, $fpoptions); $str .= '<input type="hidden" name="'.$field.'_itemid" value="'.$draftitemid.'" />'; $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="'.$this->field->param3.'" cols="'.$this->field->param2.'">'.s($text).'</textarea></div>'; $str .= '<div><select name="'.$field.'_content1">'; foreach ($formats as $key=>$desc) { $selected = ($format == $key) ? 'selected="selected"' : ''; $str .= '<option value="'.s($key).'" '.$selected.'>'.$desc.'</option>'; } $str .= '</select>'; $str .= '</div>'; $str .= '</div>'; return $str; }
/** * Get the options required to configure the filepicker for one of the editor * toolbar buttons. * @param mixed $acceptedtypes array of types of '*'. * @param int $draftitemid the draft area item id. * @param object $context the context. * @return object the required options. */ protected function specific_filepicker_options($acceptedtypes, $draftitemid, $context) { $filepickeroptions = new stdClass(); $filepickeroptions->accepted_types = $acceptedtypes; $filepickeroptions->return_types = FILE_INTERNAL | FILE_EXTERNAL; $filepickeroptions->context = $context; $filepickeroptions->env = 'filepicker'; $options = initialise_filepicker($filepickeroptions); $options->context = $context; $options->client_id = uniqid(); $options->env = 'editor'; $options->itemid = $draftitemid; return $options; }
/** * Constructor * * @param stdClass $options options for filemanager * default options are: * maxbytes=>-1, * maxfiles=>-1, * itemid=>0, * subdirs=>false, * client_id=>uniqid(), * acepted_types=>'*', * return_types=>FILE_INTERNAL, * context=>$PAGE->context, * author=>fullname($USER), * licenses=>array build from $CFG->licenses, * defaultlicense=>$CFG->sitedefaultlicense */ public function __construct(stdClass $options) { global $CFG, $USER, $PAGE; require_once $CFG->dirroot . '/repository/lib.php'; $defaults = array('maxbytes' => -1, 'maxfiles' => -1, 'itemid' => 0, 'subdirs' => 0, 'client_id' => uniqid(), 'accepted_types' => '*', 'return_types' => FILE_INTERNAL, 'context' => $PAGE->context, 'author' => fullname($USER), 'licenses' => array()); if (!empty($CFG->licenses)) { $array = explode(',', $CFG->licenses); foreach ($array as $license) { $l = new stdClass(); $l->shortname = $license; $l->fullname = get_string($license, 'license'); $defaults['licenses'][] = $l; } } if (!empty($CFG->sitedefaultlicense)) { $defaults['defaultlicense'] = $CFG->sitedefaultlicense; } foreach ($defaults as $key => $value) { if (empty($options->{$key})) { $options->{$key} = $value; } } $fs = get_file_storage(); // initilise options, getting files in root path $this->options = file_get_drafarea_files($options->itemid, '/'); // calculate file count $usercontext = context_user::instance($USER->id); $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id', false); $filecount = count($files); $this->options->filecount = $filecount; // copying other options foreach ($options as $name => $value) { $this->options->{$name} = $value; } // calculate the maximum file size as minimum from what is specified in filepicker options, // course options, global configuration and php settings $coursebytes = $maxbytes = 0; list($context, $course, $cm) = get_context_info_array($this->options->context->id); if (is_object($course)) { $coursebytes = $course->maxbytes; } if (!empty($this->options->maxbytes) && $this->options->maxbytes > 0) { $maxbytes = $this->options->maxbytes; } $this->options->maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursebytes, $maxbytes); // building file picker options $params = new stdClass(); $params->accepted_types = $options->accepted_types; $params->return_types = $options->return_types; $params->context = $options->context; $params->env = 'filemanager'; $params->disable_types = !empty($options->disable_types) ? $options->disable_types : array(); $filepicker_options = initialise_filepicker($params); $this->options->filepicker = $filepicker_options; }
/** * Returns HTML for editor form element. * * @return string */ function toHtml() { global $CFG, $PAGE, $OUTPUT; require_once($CFG->dirroot.'/repository/lib.php'); if ($this->_flagFrozen) { return $this->getFrozenHtml(); } $ctx = $this->_options['context']; $id = $this->_attributes['id']; $elname = $this->_attributes['name']; $subdirs = $this->_options['subdirs']; $maxbytes = $this->_options['maxbytes']; $areamaxbytes = $this->_options['areamaxbytes']; $maxfiles = $this->_options['maxfiles']; $changeformat = $this->_options['changeformat']; // TO DO: implement as ajax calls $text = $this->_values['text']; $format = $this->_values['format']; $draftitemid = $this->_values['itemid']; // security - never ever allow guest/not logged in user to upload anything if (isguestuser() or !isloggedin()) { $maxfiles = 0; } $str = $this->_getTabs(); $str .= '<div>'; $editor = editors_get_preferred_editor($format); $strformats = format_text_menu(); $formats = $editor->get_supported_formats(); foreach ($formats as $fid) { $formats[$fid] = $strformats[$fid]; } // get filepicker info // $fpoptions = array(); if ($maxfiles != 0 ) { if (empty($draftitemid)) { // no existing area info provided - let's use fresh new draft area require_once("$CFG->libdir/filelib.php"); $this->setValue(array('itemid'=>file_get_unused_draft_itemid())); $draftitemid = $this->_values['itemid']; } $args = new stdClass(); // need these three to filter repositories list $args->accepted_types = array('web_image'); $args->return_types = $this->_options['return_types']; $args->context = $ctx; $args->env = 'filepicker'; // advimage plugin $image_options = initialise_filepicker($args); $image_options->context = $ctx; $image_options->client_id = uniqid(); $image_options->maxbytes = $this->_options['maxbytes']; $image_options->areamaxbytes = $this->_options['areamaxbytes']; $image_options->env = 'editor'; $image_options->itemid = $draftitemid; // moodlemedia plugin $args->accepted_types = array('video', 'audio'); $media_options = initialise_filepicker($args); $media_options->context = $ctx; $media_options->client_id = uniqid(); $media_options->maxbytes = $this->_options['maxbytes']; $media_options->areamaxbytes = $this->_options['areamaxbytes']; $media_options->env = 'editor'; $media_options->itemid = $draftitemid; // advlink plugin $args->accepted_types = '*'; $link_options = initialise_filepicker($args); $link_options->context = $ctx; $link_options->client_id = uniqid(); $link_options->maxbytes = $this->_options['maxbytes']; $link_options->areamaxbytes = $this->_options['areamaxbytes']; $link_options->env = 'editor'; $link_options->itemid = $draftitemid; $args->accepted_types = array('.vtt'); $subtitle_options = initialise_filepicker($args); $subtitle_options->context = $ctx; $subtitle_options->client_id = uniqid(); $subtitle_options->maxbytes = $this->_options['maxbytes']; $subtitle_options->areamaxbytes = $this->_options['areamaxbytes']; $subtitle_options->env = 'editor'; $subtitle_options->itemid = $draftitemid; $fpoptions['image'] = $image_options; $fpoptions['media'] = $media_options; $fpoptions['link'] = $link_options; $fpoptions['subtitle'] = $subtitle_options; } //If editor is required and tinymce, then set required_tinymce option to initalize tinymce validation. if (($editor instanceof tinymce_texteditor) && !is_null($this->getAttribute('onchange'))) { $this->_options['required'] = true; } // print text area - TODO: add on-the-fly switching, size configuration, etc. $editor->set_text($text); $editor->use_editor($id, $this->_options, $fpoptions); $rows = empty($this->_attributes['rows']) ? 15 : $this->_attributes['rows']; $cols = empty($this->_attributes['cols']) ? 80 : $this->_attributes['cols']; //Apply editor validation if required field $context = []; $context['rows'] = $rows; $context['cols'] = $cols; $context['frozen'] = $this->_flagFrozen; foreach ($this->getAttributes() as $name => $value) { $context[$name] = $value; } $context['hasformats'] = count($formats) > 1; $context['formats'] = []; if (($format === '' || $format === null) && count($formats)) { $format = key($formats); } foreach ($formats as $formatvalue => $formattext) { $context['formats'][] = ['value' => $formatvalue, 'text' => $formattext, 'selected' => ($formatvalue == $format)]; } $context['id'] = $id; $context['value'] = $text; $context['format'] = $format; if (!is_null($this->getAttribute('onblur')) && !is_null($this->getAttribute('onchange'))) { $context['changelistener'] = true; } $str .= $OUTPUT->render_from_template('core_form/editor_textarea', $context); // during moodle installation, user area doesn't exist // so we need to disable filepicker here. if (!during_initial_install() && empty($CFG->adminsetuppending)) { // 0 means no files, -1 unlimited if ($maxfiles != 0 ) { $str .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $elname.'[itemid]', 'value' => $draftitemid)); // used by non js editor only $editorurl = new moodle_url("$CFG->wwwroot/repository/draftfiles_manager.php", array( 'action'=>'browse', 'env'=>'editor', 'itemid'=>$draftitemid, 'subdirs'=>$subdirs, 'maxbytes'=>$maxbytes, 'areamaxbytes' => $areamaxbytes, 'maxfiles'=>$maxfiles, 'ctx_id'=>$ctx->id, 'course'=>$PAGE->course->id, 'sesskey'=>sesskey(), )); $str .= '<noscript>'; $str .= "<div><object type='text/html' data='$editorurl' height='160' width='600' style='border:1px solid #000'></object></div>"; $str .= '</noscript>'; } } $str .= '</div>'; return $str; }
/** * Constructor * * @param stdClass $options options for filemanager */ public function __construct(stdClass $options) { global $CFG, $USER, $PAGE; require_once $CFG->dirroot . '/repository/lib.php'; $defaults = array('maxbytes' => -1, 'maxfiles' => -1, 'itemid' => 0, 'subdirs' => 0, 'client_id' => uniqid(), 'accepted_types' => '*', 'return_types' => FILE_INTERNAL, 'context' => $PAGE->context); foreach ($defaults as $key => $value) { if (empty($options->{$key})) { $options->{$key} = $value; } } $fs = get_file_storage(); // initilise options, getting files in root path $this->options = file_get_drafarea_files($options->itemid, '/'); // calculate file count $usercontext = get_context_instance(CONTEXT_USER, $USER->id); $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id', false); $filecount = count($files); $this->options->filecount = $filecount; // copying other options foreach ($options as $name => $value) { $this->options->{$name} = $value; } // building file picker options $params = new stdClass(); $params->accepted_types = $options->accepted_types; $params->return_types = $options->return_types; $params->context = $options->context; $params->env = 'filemanager'; $params->disable_types = !empty($options->disable_types) ? $options->disable_types : array(); $filepicker_options = initialise_filepicker($params); $this->options->filepicker = $filepicker_options; }
function toHtml() { global $CFG, $PAGE; require_once $CFG->dirroot . '/repository/lib.php'; if ($this->_flagFrozen) { return $this->getFrozenHtml(); } $ctx = $this->_options['context']; $id = $this->_attributes['id']; $elname = $this->_attributes['name']; $subdirs = $this->_options['subdirs']; $maxbytes = $this->_options['maxbytes']; $maxfiles = $this->_options['maxfiles']; $changeformat = $this->_options['changeformat']; // TO DO: implement as ajax calls $text = $this->_values['text']; $format = $this->_values['format']; $draftitemid = $this->_values['itemid']; // security - never ever allow guest/not logged in user to upload anything if (isguestuser() or !isloggedin()) { $maxfiles = 0; } $str = $this->_getTabs(); $str .= '<div>'; $editor = editors_get_preferred_editor($format); $strformats = format_text_menu(); $formats = $editor->get_supported_formats(); foreach ($formats as $fid) { $formats[$fid] = $strformats[$fid]; } // get filepicker info // $fpoptions = array(); if ($maxfiles != 0) { if (empty($draftitemid)) { // no existing area info provided - let's use fresh new draft area require_once "{$CFG->libdir}/filelib.php"; $this->setValue(array('itemid' => file_get_unused_draft_itemid())); $draftitemid = $this->_values['itemid']; } $args = new stdClass(); // need these three to filter repositories list $args->accepted_types = array('image'); $args->return_types = FILE_INTERNAL | FILE_EXTERNAL; $args->context = $ctx; $args->env = 'filepicker'; // advimage plugin $image_options = initialise_filepicker($args); $image_options->context = $ctx; $image_options->client_id = uniqid(); $image_options->maxbytes = $this->_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 = $ctx; $media_options->client_id = uniqid(); $media_options->maxbytes = $this->_options['maxbytes']; $media_options->env = 'editor'; $media_options->itemid = $draftitemid; // advlink plugin $args->accepted_types = '*'; $link_options = initialise_filepicker($args); $link_options->context = $ctx; $link_options->client_id = uniqid(); $link_options->maxbytes = $this->_options['maxbytes']; $link_options->env = 'editor'; $link_options->itemid = $draftitemid; $fpoptions['image'] = $image_options; $fpoptions['media'] = $media_options; $fpoptions['link'] = $link_options; } //If editor is required and tinymce, then set required_tinymce option to initalize tinymce validation. if ($editor instanceof tinymce_texteditor && !is_null($this->getAttribute('onchange'))) { $this->_options['required'] = true; } /// print text area - TODO: add on-the-fly switching, size configuration, etc. $editor->use_editor($id, $this->_options, $fpoptions); $rows = empty($this->_attributes['rows']) ? 15 : $this->_attributes['rows']; $cols = empty($this->_attributes['cols']) ? 80 : $this->_attributes['cols']; //Apply editor validation if required field $editorrules = ''; if (!is_null($this->getAttribute('onblur')) && !is_null($this->getAttribute('onchange'))) { $editorrules = 'onblur="' . htmlspecialchars($this->getAttribute('onblur')) . '" onchange="' . htmlspecialchars($this->getAttribute('onchange')) . '"'; } $str .= '<div><textarea id="' . $id . '" name="' . $elname . '[text]" rows="' . $rows . '" cols="' . $cols . '"' . $editorrules . '>'; $str .= s($text); $str .= '</textarea></div>'; $str .= '<div>'; if (count($formats) > 1) { $str .= html_writer::select($formats, $elname . '[format]', $format, false); } else { $str .= html_writer::empty_tag('input', array('name' => $elname . '[format]', 'type' => 'hidden', 'value' => array_pop(array_keys($formats)))); } $str .= '</div>'; // during moodle installation, user area doesn't exist // so we need to disable filepicker here. if (!during_initial_install() && empty($CFG->adminsetuppending)) { // 0 means no files, -1 unlimited if ($maxfiles != 0) { $str .= '<input type="hidden" name="' . $elname . '[itemid]" value="' . $draftitemid . '" />'; // used by non js editor only $editorurl = new moodle_url("{$CFG->wwwroot}/repository/draftfiles_manager.php", array('action' => 'browse', 'env' => 'editor', 'itemid' => $draftitemid, 'subdirs' => $subdirs, 'maxbytes' => $maxbytes, 'maxfiles' => $maxfiles, 'ctx_id' => $ctx->id, 'course' => $PAGE->course->id, 'sesskey' => sesskey())); $str .= '<noscript>'; $str .= "<div><object type='text/html' data='{$editorurl}' height='160' width='600' style='border:1px solid #000'></object></div>"; $str .= '</noscript>'; } } $str .= '</div>'; return $str; }
/** * Returns an XHTML string for the editor * * @param string $data * @param string $query * @return string XHTML string for the editor */ public function output_html($data, $query='') { global $USER; $default = $this->get_defaultsetting(); $defaultinfo = $default; if (!is_null($default) and $default !== '') { $defaultinfo = "\n".$default; } $ctx = context_user::instance($USER->id); $editor = editors_get_preferred_editor(FORMAT_HTML); $options = $this->get_options(); $draftitemid = file_get_unused_draft_itemid(); $component = is_null($this->plugin) ? 'core' : $this->plugin; $data = file_prepare_draft_area($draftitemid, $options['context']->id, $component, $this->get_full_name().'_draftitemid', $draftitemid, $options, $data); $fpoptions = array(); $args = new stdClass(); // Need these three to filter repositories list. $args->accepted_types = array('web_image'); $args->return_types = $options['return_types']; $args->context = $ctx; $args->env = 'filepicker'; // Advimage plugin. $imageoptions = initialise_filepicker($args); $imageoptions->context = $ctx; $imageoptions->client_id = uniqid(); $imageoptions->maxbytes = $options['maxbytes']; $imageoptions->areamaxbytes = $options['areamaxbytes']; $imageoptions->env = 'editor'; $imageoptions->itemid = $draftitemid; // Moodlemedia plugin. $args->accepted_types = array('video', 'audio'); $mediaoptions = initialise_filepicker($args); $mediaoptions->context = $ctx; $mediaoptions->client_id = uniqid(); $mediaoptions->maxbytes = $options['maxbytes']; $mediaoptions->areamaxbytes = $options['areamaxbytes']; $mediaoptions->env = 'editor'; $mediaoptions->itemid = $draftitemid; // Advlink plugin. $args->accepted_types = '*'; $linkoptions = initialise_filepicker($args); $linkoptions->context = $ctx; $linkoptions->client_id = uniqid(); $linkoptions->maxbytes = $options['maxbytes']; $linkoptions->areamaxbytes = $options['areamaxbytes']; $linkoptions->env = 'editor'; $linkoptions->itemid = $draftitemid; $fpoptions['image'] = $imageoptions; $fpoptions['media'] = $mediaoptions; $fpoptions['link'] = $linkoptions; $editor->use_editor($this->get_id(), $options, $fpoptions); return format_admin_setting($this, $this->visiblename, '<div class="form-textarea"> <textarea rows="'. $this->rows .'" cols="'. $this->cols .'" id="'. $this->get_id() .'" name="'.$this->get_full_name() .'"spellcheck="true">'. s($data) .' </textarea> </div> <input value="'.$draftitemid.'" name="'.$this->get_full_name().'_draftitemid" type="hidden" />', $this->description, true, '', $defaultinfo, $query); }
public static function get_filepicker_options($context, $draftitemid, $maxbytes) { // common filepicker arguments $args = (object) array('return_types' => FILE_INTERNAL | FILE_EXTERNAL, 'context' => $context, 'env' => 'filepicker'); // advimage plugin $args->accepted_types = array('web_image'); $image_options = initialise_filepicker($args); $image_options->context = $context; $image_options->client_id = uniqid(); $image_options->maxbytes = $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 = $context; $media_options->client_id = uniqid(); $media_options->maxbytes = $maxbytes; $media_options->env = 'editor'; $media_options->itemid = $draftitemid; // advlink plugin $args->accepted_types = '*'; $link_options = initialise_filepicker($args); $link_options->context = $context; $link_options->client_id = uniqid(); $link_options->maxbytes = $maxbytes; $link_options->env = 'editor'; $link_options->itemid = $draftitemid; return array('image' => $image_options, 'media' => $media_options, 'link' => $link_options); }
function display_add_field($recordid = 0, $formdata = null) { global $CFG, $DB, $OUTPUT, $PAGE; $text = ''; $format = 0; $str = '<div title="' . s($this->field->description) . '">'; $str .= '<label for="field_' . $this->field->id . '" class="accesshide">'; $str .= html_writer::span($this->field->name); if ($this->field->required) { $image = html_writer::img($OUTPUT->pix_url('req'), get_string('requiredelement', 'form'), array('class' => 'req', 'title' => get_string('requiredelement', 'form'))); $str .= html_writer::div($image, 'inline-req'); } $str .= '</label>'; editors_head_setup(); $options = $this->get_options(); $itemid = $this->field->id; $field = 'field_'.$itemid; if ($formdata) { $fieldname = 'field_' . $this->field->id . '_content1'; if (isset($formdata->$fieldname)) { $format = $formdata->$fieldname; } else { $format = file_get_unused_draft_itemid(); } $fieldname = 'field_' . $this->field->id . '_itemid'; if (isset($formdata->$fieldname)) { $draftitemid = clean_param($formdata->$fieldname, PARAM_INT); } else { $draftitemid = file_get_unused_draft_itemid(); } $fieldname = 'field_' . $this->field->id; if (isset($formdata->$fieldname)) { $text = $formdata->$fieldname; } } else if ($recordid && $content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) { $format = $content->content1; $text = clean_text($content->content, $format); $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text); } else { $draftitemid = file_get_unused_draft_itemid(); $format = FORMAT_HTML; } // get filepicker info // $fpoptions = array(); if ($options['maxfiles'] != 0 ) { $args = new stdClass(); // need these three to filter repositories list $args->accepted_types = array('web_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); $strformats = format_text_menu(); $formats = $editor->get_supported_formats(); foreach ($formats as $fid) { $formats[$fid] = $strformats[$fid]; } $editor->set_text($text); $editor->use_editor($field, $options, $fpoptions); $str .= '<input type="hidden" name="'.$field.'_itemid" value="'.s($draftitemid).'" />'; $str .= '<div class="mod-data-input">'; $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="'.$this->field->param3.'" cols="'.$this->field->param2.'" spellcheck="true">'.s($text).'</textarea></div>'; $str .= '<div><label class="accesshide" for="' . $field . '_content1">' . get_string('format') . '</label>'; $str .= '<select id="' . $field . '_content1" name="'.$field.'_content1">'; foreach ($formats as $key=>$desc) { $selected = ($format == $key) ? 'selected="selected"' : ''; $str .= '<option value="'.s($key).'" '.$selected.'>'.$desc.'</option>'; } $str .= '</select>'; $str .= '</div>'; $str .= '</div>'; $str .= '</div>'; return $str; }