$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;
$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
$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);
}
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)) {
}
// 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",
$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);
$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.
*
$submit2label = get_string('savechangesandreturntocourse');
}
- $mform =& $this->_form;
+ $mform = $this->_form;
// elements in a row need a group
$buttonarray = array();
$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';
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');
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.
*/
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();
}
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;
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;
$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))) {
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;
}
$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);
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;
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;
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;
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;
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;
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;
$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');
$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');
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))) {
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;
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;
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;
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;
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;
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;
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;
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;
$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