From dc5c2bd9eb3ac4998b65cdf0374f32628388406e Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 21 Apr 2009 21:17:21 +0000 Subject: [PATCH] MDL-18910 full support for module intro editor with embedded images --- course/modedit.php | 39 +++++++++++++++++++++++++++++++++--- course/moodleform_mod.php | 20 +++++++++++++++++-- lang/en_utf8/moodle.php | 1 + lib/moodlelib.php | 2 +- lib/weblib.php | 13 ++++++++++++ mod/assignment/lib.php | 15 +++++++------- mod/assignment/mod_form.php | 5 +---- mod/chat/lib.php | 2 +- mod/choice/lib.php | 2 +- mod/data/lib.php | 2 +- mod/feedback/lib.php | 2 +- mod/forum/lib.php | 18 +---------------- mod/forum/post_form.php | 3 +-- mod/glossary/edit_form.php | 3 +-- mod/glossary/lib.php | 19 ++---------------- mod/label/lib.php | 2 +- mod/lesson/lib.php | 2 +- mod/quiz/lib.php | 2 +- mod/resource/lib.php | 2 +- mod/scorm/lib.php | 2 +- mod/survey/lib.php | 2 +- mod/wiki/lib.php | 2 +- pluginfile.php | 40 +++++++++++++++++++++++++++++-------- 23 files changed, 125 insertions(+), 75 deletions(-) diff --git a/course/modedit.php b/course/modedit.php index 304d66bd6d..54a5141174 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -53,6 +53,12 @@ $form->add = $add; $form->return = 0; //must be false if this is an add, go back to course view on cancel + if (plugin_supports('mod', $form->modulename, FEATURE_MOD_INTRO, true)) { + $draftid_editor = file_get_submitted_draft_itemid('introeditor'); + file_prepare_draft_area($draftid_editor, null, null, null); + $form->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default + } + // Turn off default grouping for modules that don't provide group mode if ($add=='resource' || $add=='glossary' || $add=='label') { $form->groupingid = 0; @@ -130,6 +136,12 @@ $form->showavailability = $cm->showavailability; } + if (plugin_supports('mod', $form->modulename, FEATURE_MOD_INTRO, true)) { + $draftid_editor = file_get_submitted_draft_itemid('introeditor'); + $currentintro = file_prepare_draft_area($draftid_editor, $context->id, $form->modulename.'_intro', 0, true, $form->intro); + $form->introeditor = array('text'=>$currentintro, 'format'=>$form->introformat, 'itemid'=>$draftid_editor); + } + if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$form->modulename, 'iteminstance'=>$form->instance, 'courseid'=>$course->id))) { // add existing outcomes @@ -306,6 +318,17 @@ $DB->update_record('course_modules', $cm); + $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); + + // update embedded links and save files + if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) { + $fromform->intro = file_save_draft_area_files($fromform->introeditor['itemid'], $modcontext->id, + $fromform->modulename.'_intro', 0, + true, $fromform->introeditor['text']); + $fromform->introformat = $fromform->introeditor['format']; + unset($fromform->introeditor); + } + if (!$updateinstancefunction($fromform, $mform)) { print_error('cannotupdatemod', '', 'view.php?id=$course->id', $fromform->modulename); } @@ -367,6 +390,17 @@ print_error('cannotaddcoursemodule'); } + $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); + + // update embedded links and save files + if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) { + $fromform->intro = file_save_draft_area_files($fromform->introeditor['itemid'], $modcontext->id, + $fromform->modulename.'_intro', 0, + true, $fromform->introeditor['text']); + $fromform->introformat = $fromform->introeditor['format']; + unset($fromform->introeditor); + } + $returnfromfunc = $addinstancefunction($fromform, $mform); if (!$returnfromfunc or !is_number($returnfromfunc)) { @@ -409,9 +443,8 @@ } // Set up conditions - if($CFG->enableavailability) { - condition_info::update_cm_from_form( - (object)array('id'=>$fromform->coursemodule),$fromform,false); + if ($CFG->enableavailability) { + condition_info::update_cm_from_form((object)array('id'=>$fromform->coursemodule), $fromform, false); } add_to_log($course->id, "course", "add mod", diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index 7c275bd23e..bb763864d6 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -70,7 +70,7 @@ class moodleform_mod extends moodleform { $this->_features->outcomes = (!empty($CFG->enableoutcomes) and plugin_supports('mod', $this->_modname, FEATURE_GRADE_OUTCOMES, true)); $this->_features->hasgrades = plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false); $this->_features->idnumber = plugin_supports('mod', $this->_modname, FEATURE_IDNUMBER, true); - $this->_features->introeditor = plugin_supports('mod', $this->_modname, FEATURE_MODEDIT_INTRO_EDITOR, true); + $this->_features->introeditor = plugin_supports('mod', $this->_modname, FEATURE_MOD_INTRO, true); $this->_features->defaultcompletion = plugin_supports('mod', $this->_modname, FEATURE_MODEDIT_DEFAULT_COMPLETION, true); $this->_features->gradecat = ($this->_features->outcomes or $this->_features->hasgrades); @@ -572,6 +572,22 @@ class moodleform_mod extends moodleform { $mform->setType('return', PARAM_BOOL); } + function add_intro_editor($required=false, $customlabel=null) { + if (!$this->_features->introeditor) { + // intro editor not supported in this module + return; + } + + $mform = $this->_form; + $label = is_null($customlabel) ? get_string('moduleintro') : $customlabel; + + $mform->addElement('editor', 'introeditor', $label, array('maxfiles'=>EDITOR_UNLIMITED_FILES)); + $mform->setType('introeditor', PARAM_RAW); // no XSS prevention here, users must be trusted + if ($required) { + $mform->addRule('introeditor', get_string('required'), 'required', null, 'client'); + } + } + /** * Overriding formslib's add_action_buttons() method, to add an extra submit "save changes and return" button. * @@ -589,7 +605,7 @@ class moodleform_mod extends moodleform { $submit2label = get_string('savechangesandreturntocourse'); } - $mform =& $this->_form; + $mform = $this->_form; // elements in a row need a group $buttonarray = array(); diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 817f6513ee..928e3a0eac 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -1010,6 +1010,7 @@ $string['missingusername'] = 'Missing username'; $string['modified'] = 'Modified'; $string['moduledeleteconfirm'] = 'You are about to completely delete the module \'$a\'. This will completely delete everything in the database associated with this activity module. Are you SURE you want to continue?'; $string['moduledeletefiles'] = 'All data associated with the module \'$a->module\' has been deleted from the database. To complete the deletion (and prevent the module re-installing itself), you should now delete this directory from your server: $a->directory'; +$string['moduleintro'] = 'Description'; $string['modulesetup'] = 'Setting up module tables'; $string['modulesuccess'] = '$a tables have been set up correctly'; $string['moodledocs'] = 'Moodle Docs'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 7076044063..948a2765ee 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -318,7 +318,7 @@ define('FEATURE_GROUPINGS', 'groupings'); define('FEATURE_GROUPMEMBERSONLY', 'groupmembersonly'); /** True if module supports intro editor */ -define('FEATURE_MODEDIT_INTRO_EDITOR', 'modedit_intro_editor'); +define('FEATURE_MOD_INTRO', 'mod_intro'); /** True if module has default completion */ define('FEATURE_MODEDIT_DEFAULT_COMPLETION', 'modedit_default_completion'); diff --git a/lib/weblib.php b/lib/weblib.php index 9ad99356f3..af987dbe91 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1550,6 +1550,19 @@ function filter_text($text, $courseid=NULL) { return filter_manager::instance()->filter_text($text, $context, $courseid); } +/** + * Formats activity intro text + * @param string $module name of module + * @param object $activity instance of activity + * @param int $cmid course module id + * @return text + */ +function format_module_intro($module, $activity, $cmid) { + $options = (object)array('noclean'=>true); + $context = get_context_instance(CONTEXT_MODULE, $cmid); + $intro = file_rewrite_pluginfile_urls($activity->intro, 'pluginfile.php', $context->id, $module.'_intro', 0); + return format_text($intro, $activity->introformat, $options); +} /** * Legacy function, used for cleaning of old forum and glossary text only. diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index bc9c50191a..548794be70 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -160,9 +160,7 @@ class assignment_base { */ function view_intro() { print_simple_box_start('center', '', '', 0, 'generalbox', 'intro'); - $formatoptions = new stdClass; - $formatoptions->noclean = true; - echo format_text($this->assignment->intro, $this->assignment->introformat, $formatoptions); + echo format_module_intro('assignment', $this->assignment, $this->cm->id); print_simple_box_end(); } @@ -358,7 +356,7 @@ class assignment_base { if ($assignment->timedue) { $event = new object(); $event->name = $assignment->name; - $event->description = $assignment->intro; + $event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule); $event->courseid = $assignment->course; $event->groupid = 0; $event->userid = 0; @@ -447,14 +445,14 @@ class assignment_base { if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'assignment', 'instance'=>$assignment->id))) { $event->name = $assignment->name; - $event->description = $assignment->intro; + $event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule); $event->timestart = $assignment->timedue; update_event($event); } else { $event = new object(); $event->name = $assignment->name; - $event->description = $assignment->intro; + $event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule); $event->courseid = $assignment->course; $event->groupid = 0; $event->userid = 0; @@ -2429,9 +2427,10 @@ function assignment_refresh_events($courseid = 0) { $moduleid = $DB->get_field('modules', 'id', array('name'=>'assignment')); foreach ($assignments as $assignment) { + $cm = get_coursemodule_from_id('assignment', $assignment->id); $event = NULL; $event->name = $assignment->name; - $event->description = $assignment->intro; + $event->description = format_module_intro('assignment', $assignment, $cm->id); $event->timestart = $assignment->timedue; if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'assignment', 'instance'=>$assignment->id))) { @@ -3241,7 +3240,7 @@ function assignment_supports($feature) { case FEATURE_GROUPS: return true; case FEATURE_GROUPINGS: return true; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return true; case FEATURE_GRADE_OUTCOMES: return true; diff --git a/mod/assignment/mod_form.php b/mod/assignment/mod_form.php index 7802a6102a..8ed8b2db43 100644 --- a/mod/assignment/mod_form.php +++ b/mod/assignment/mod_form.php @@ -39,10 +39,7 @@ class mod_assignment_mod_form extends moodleform_mod { } $mform->addRule('name', null, 'required', null, 'client'); - $mform->addElement('htmleditor', 'intro', get_string('description', 'assignment')); - $mform->setType('intro', PARAM_RAW); - $mform->setHelpButton('intro', array('writing', 'questions', 'richtext2'), false, 'editorhelpbutton'); - $mform->addRule('intro', get_string('required'), 'required', null, 'client'); + $this->add_intro_editor(true, get_string('description', 'assignment')); $mform->addElement('modgrade', 'grade', get_string('grade')); $mform->setDefault('grade', 100); diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 9dd173dcf4..7476b683de 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -980,7 +980,7 @@ function chat_supports($feature) { case FEATURE_GROUPS: return true; case FEATURE_GROUPINGS: return true; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return false; case FEATURE_GRADE_HAS_GRADE: return false; case FEATURE_GRADE_OUTCOMES: return true; diff --git a/mod/choice/lib.php b/mod/choice/lib.php index 3cc1325a6d..889c0aa10f 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -765,7 +765,7 @@ function choice_supports($feature) { case FEATURE_GROUPS: return true; case FEATURE_GROUPINGS: return true; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return false; case FEATURE_GRADE_OUTCOMES: return false; diff --git a/mod/data/lib.php b/mod/data/lib.php index 273015f1a1..f05b690552 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -2328,7 +2328,7 @@ function data_supports($feature) { case FEATURE_GROUPS: return true; case FEATURE_GROUPINGS: return true; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return true; case FEATURE_GRADE_OUTCOMES: return true; diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index cf56fdceea..801c0d4dff 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -38,7 +38,7 @@ function feedback_supports($feature) { case FEATURE_GROUPS: return true; case FEATURE_GROUPINGS: return true; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return false; case FEATURE_GRADE_OUTCOMES: return false; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 04fadf769c..c241ea0e72 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -240,7 +240,7 @@ function forum_supports($feature) { case FEATURE_GROUPS: return true; case FEATURE_GROUPINGS: return true; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_COMPLETION_HAS_RULES: return true; case FEATURE_GRADE_HAS_GRADE: return true; @@ -4064,22 +4064,6 @@ function forum_pluginfile($course, $cminfo, $context, $filearea, $args) { return false; } - if ($filearea === 'forum_intro') { - // all users may access it - $relativepath = '/'.implode('/', $args); - $fullpath = $context->id.'forum_intro0'.$relativepath; - - $fs = get_file_storage(); - if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { - return false; - } - - $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400; - - // finally send the file - send_stored_file($file, $lifetime, 0); - } - $fileareas = array('forum_attachment', 'forum_post'); if (!in_array($filearea, $fileareas)) { return false; diff --git a/mod/forum/post_form.php b/mod/forum/post_form.php index a5238a2c4d..ff0a0fa585 100644 --- a/mod/forum/post_form.php +++ b/mod/forum/post_form.php @@ -23,8 +23,7 @@ class mod_forum_post_form extends moodleform { $mform->addRule('subject', get_string('required'), 'required', null, 'client'); $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); - $mform->addElement('editor', 'message', get_string('message', 'forum'), - array('maxfiles' => EDITOR_UNLIMITED_FILES, 'filearea' => 'forum_post')); + $mform->addElement('editor', 'message', get_string('message', 'forum'), array('maxfiles' => EDITOR_UNLIMITED_FILES)); $mform->setType('message', PARAM_RAW); $mform->addRule('message', get_string('required'), 'required', null, 'client'); $mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext2'), false, 'editorhelpbutton'); diff --git a/mod/glossary/edit_form.php b/mod/glossary/edit_form.php index 28f4237827..90b8257289 100644 --- a/mod/glossary/edit_form.php +++ b/mod/glossary/edit_form.php @@ -17,8 +17,7 @@ class mod_glossary_entry_form extends moodleform { $mform->setType('concept', PARAM_TEXT); $mform->addRule('concept', null, 'required', null, 'client'); - $mform->addElement('editor', 'entry', get_string('definition', 'glossary'), - array('maxfiles' => EDITOR_UNLIMITED_FILES, 'filearea' => 'glossary_entry')); + $mform->addElement('editor', 'entry', get_string('definition', 'glossary'), array('maxfiles' => EDITOR_UNLIMITED_FILES)); $mform->setType('entry', PARAM_RAW); $mform->addRule('entry', get_string('required'), 'required', null, 'client'); $mform->setHelpButton('entry', array('reading', 'writing', 'questions', 'richtext2'), false, 'editorhelpbutton'); diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index da878e71e4..0d0798a01a 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -1084,22 +1084,7 @@ function glossary_pluginfile($course, $cminfo, $context, $filearea, $args) { return false; } - if ($filearea === 'glossary_intro') { - // all users may access it - $relativepath = '/'.implode('/', $args); - $fullpath = $context->id.'glossary_intro0'.$relativepath; - - $fs = get_file_storage(); - if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { - return false; - } - - $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400; - - // finally send the file - send_stored_file($file, $lifetime, 0); - - } else if ($filearea === 'glossary_attachment' or $filearea === 'glossary_entry') { + if ($filearea === 'glossary_attachment' or $filearea === 'glossary_entry') { $entryid = (int)array_shift($args); if (!$entry = $DB->get_record('glossary_entries', array('id'=>$entryid))) { @@ -2277,7 +2262,7 @@ function glossary_supports($feature) { case FEATURE_GROUPS: return false; case FEATURE_GROUPINGS: return false; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return true; case FEATURE_GRADE_OUTCOMES: return true; diff --git a/mod/label/lib.php b/mod/label/lib.php index a8a2e2e8de..e7768349e6 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -145,7 +145,7 @@ function label_supports($feature) { case FEATURE_GROUPS: return false; case FEATURE_GROUPINGS: return false; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return false; + case FEATURE_MOD_INTRO: return false; case FEATURE_COMPLETION_TRACKS_VIEWS: return false; case FEATURE_GRADE_HAS_GRADE: return false; case FEATURE_GRADE_OUTCOMES: return false; diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index e3893b79ba..138fe5bb34 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -720,7 +720,7 @@ function lesson_supports($feature) { case FEATURE_GROUPS: return false; case FEATURE_GROUPINGS: return false; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return true; case FEATURE_GRADE_OUTCOMES: return true; diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index e03fbb62c5..c20d6cf7fe 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1255,7 +1255,7 @@ function quiz_supports($feature) { case FEATURE_GROUPS: return true; case FEATURE_GROUPINGS: return true; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return true; case FEATURE_GRADE_OUTCOMES: return true; diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 45e5bc8ca6..f892283e15 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -764,7 +764,7 @@ function resource_supports($feature) { case FEATURE_GROUPS: return false; case FEATURE_GROUPINGS: return false; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return false; case FEATURE_GRADE_OUTCOMES: return false; diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index cfcf39a5a6..4076547a72 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -820,7 +820,7 @@ function scorm_supports($feature) { case FEATURE_GROUPS: return false; case FEATURE_GROUPINGS: return false; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return true; case FEATURE_GRADE_OUTCOMES: return true; diff --git a/mod/survey/lib.php b/mod/survey/lib.php index f181b853f7..cf0bc9569a 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -597,7 +597,7 @@ function survey_supports($feature) { case FEATURE_GROUPS: return true; case FEATURE_GROUPINGS: return true; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return true; case FEATURE_GRADE_OUTCOMES: return true; diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php index 3f75c579cf..d63ea6272e 100644 --- a/mod/wiki/lib.php +++ b/mod/wiki/lib.php @@ -1777,7 +1777,7 @@ function wiki_supports($feature) { case FEATURE_GROUPS: return true; case FEATURE_GROUPINGS: return true; case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MODEDIT_INTRO_EDITOR: return true; + case FEATURE_MOD_INTRO: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_GRADE_HAS_GRADE: return false; case FEATURE_GRADE_OUTCOMES: return true; diff --git a/pluginfile.php b/pluginfile.php index 4a7f327d09..4014e345ea 100644 --- a/pluginfile.php +++ b/pluginfile.php @@ -226,16 +226,40 @@ $cminfo = $modinfo->cms[$context->instanceid]; $modname = $cminfo->modname; $libfile = "$CFG->dirroot/mod/$modname/lib.php"; - if (file_exists($libfile)) { - require_once($libfile); - $filefunction = $modname.'_pluginfile'; - if (function_exists($filefunction)) { - if ($filefunction($course, $cminfo, $context, $filearea, $args) !== false) { - die; - } + if (!file_exists($libfile)) { + send_file_not_found(); + } + + require_once($libfile); + if ($filearea === $modname.'_intro') { + if (!plugin_supports('mod', $modname, FEATURE_MOD_INTRO, true)) { + send_file_not_found(); + } + if (!$cminfo->uservisible) { + send_file_not_found(); + } + // all users may access it + $itemid = (int)array_shift($args); + $relativepath = '/'.implode('/', $args); + $fullpath = $context->id.$filearea.'0'.$relativepath; + + $fs = get_file_storage(); + if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { + send_file_not_found(); + } + + $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400; + + // finally send the file + send_stored_file($file, $lifetime, 0); + } + + $filefunction = $modname.'_pluginfile'; + if (function_exists($filefunction)) { + if ($filefunction($course, $cminfo, $context, $filearea, $args) !== false) { + die; } } - send_file_not_found(); } else if ($context->contextlevel == CONTEXT_BLOCK) { //not supported yet -- 2.39.5