From ac3668bfaedc5fe535f7b7d56d04163696777f48 Mon Sep 17 00:00:00 2001 From: skodak Date: Wed, 22 Apr 2009 05:10:08 +0000 Subject: [PATCH] MDL-18910 full support for module intro editor with embedded images --- lib/weblib.php | 6 ++++-- mod/resource/index.php | 6 ++---- mod/resource/mod_form.php | 8 +------- mod/resource/type/directory/resource.class.php | 6 +----- mod/resource/type/file/resource.class.php | 14 ++++---------- mod/resource/type/html/resource.class.php | 2 +- mod/resource/type/ims/resource.class.php | 5 +---- mod/resource/type/repository/resource.class.php | 13 ++++--------- mod/resource/type/text/resource.class.php | 2 +- mod/scorm/index.php | 4 ++-- mod/scorm/lib.php | 12 +----------- mod/scorm/locallib.php | 2 +- mod/scorm/mod_form.php | 5 +---- mod/scorm/view.php | 5 ++--- mod/survey/mod_form.php | 6 ++---- mod/survey/view.php | 5 ++--- mod/wiki/index.php | 2 +- mod/wiki/mod_form.php | 5 +---- mod/wiki/view.php | 3 +-- 19 files changed, 33 insertions(+), 78 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index af987dbe91..540b4646bc 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1558,10 +1558,12 @@ function filter_text($text, $courseid=NULL) { * @return text */ function format_module_intro($module, $activity, $cmid) { - $options = (object)array('noclean'=>true); + global $CFG; + require_once("$CFG->libdir/filelib.php"); + $options = (object)array('noclean'=>true, 'para'=>false); $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); + return trim(format_text($intro, $activity->introformat, $options)); } /** diff --git a/mod/resource/index.php b/mod/resource/index.php index 15d85d9e4e..63e968f6ef 100644 --- a/mod/resource/index.php +++ b/mod/resource/index.php @@ -47,8 +47,6 @@ } $currentsection = ""; - $options->para = false; - $options->noclean = true; foreach ($resources as $resource) { if ($course->format == "weeks" or $course->format == "topics") { $printsection = ""; @@ -72,12 +70,12 @@ if (!$resource->visible) { // Show dimmed if the mod is hidden $table->data[] = array ($printsection, "coursemodule\">".format_string($resource->name,true)."", - format_text($resource->intro, $resource->introformat, $options) ); + format_module_intro('resource', $resource, $resource->coursemodule)); } else { //Show normal if the mod is visible $table->data[] = array ($printsection, "coursemodule\">".format_string($resource->name,true)."", - format_text($resource->intro, $resource->introformat, $options) ); + format_module_intro('resource', $resource, $resource->coursemodule)); } } diff --git a/mod/resource/mod_form.php b/mod/resource/mod_form.php index 243ee602d9..f1860c8b25 100644 --- a/mod/resource/mod_form.php +++ b/mod/resource/mod_form.php @@ -28,8 +28,6 @@ class mod_resource_mod_form extends moodleform_mod { //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); -// $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment')); - $mform->addElement('text', 'name', get_string('name'), array('size'=>'48')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); @@ -38,11 +36,7 @@ class mod_resource_mod_form extends moodleform_mod { } $mform->addRule('name', null, 'required', null, 'client'); - $mform->addElement('htmleditor', 'intro', get_string('summary')); - $mform->setType('intro', PARAM_RAW); - $mform->setHelpButton('intro', array('summary', get_string('summary'), 'resource')); - // summary should be optional again MDL-9485 - //$mform->addRule('summary', get_string('required'), 'required', null, 'client'); + $this->add_intro_editor(false); $mform->addElement('header', 'typedesc', resource_get_name($type)); $this->_resinstance->setup_elements($mform); diff --git a/mod/resource/type/directory/resource.class.php b/mod/resource/type/directory/resource.class.php index f6a2eda765..3a3657c2b5 100644 --- a/mod/resource/type/directory/resource.class.php +++ b/mod/resource/type/directory/resource.class.php @@ -40,10 +40,6 @@ function display() { $subdir = optional_param('subdir','', PARAM_PATH); $resource->reference = clean_param($resource->reference, PARAM_PATH); - $formatoptions = new object(); - $formatoptions->noclean = true; - $formatoptions->para = false; // MDL-12061,

in html editor breaks xhtml strict - add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id); if ($resource->reference) { @@ -91,7 +87,7 @@ function display() { if (trim(strip_tags($resource->intro))) { - print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center"); + print_simple_box(format_module_intro('resource', $resource, $cm->id), "center"); print_spacer(10,10); } diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php index 3a63b42248..d2af53306b 100644 --- a/mod/resource/type/file/resource.class.php +++ b/mod/resource/type/file/resource.class.php @@ -223,9 +223,6 @@ class resource_file extends resource_base { $mimetype = mimeinfo("type", $resource->reference); $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name)); - $formatoptions = new object(); - $formatoptions->noclean = true; - if ($resource->options != "forcedownload") { // TODO nicolasconnault 14-03-07: This option should be renamed "embed" if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image $resourcetype = "image"; @@ -365,7 +362,7 @@ class resource_file extends resource_base { echo ''; if (trim(strip_tags($resource->intro))) { - print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center"); + print_simple_box(format_module_intro('resource', $resource, $cm->id), "center"); } $link = "wwwroot/mod/resource/view.php?inpopup=true&id={$cm->id}\" " @@ -451,7 +448,7 @@ class resource_file extends resource_base { ///print the intro if (!empty($resource->intro)) { - print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center"); + print_simple_box(format_module_intro('resource', $resource, $cm->id), "center"); } echo ""; exit; @@ -489,10 +486,7 @@ class resource_file extends resource_base { print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent")); - $options = new object(); - $options->para = false; - $options->noclean = true; - echo '

'.format_text($resource->intro, $resource->introformat, $options).'
'; + echo '
'.format_module_intro('resource', $resource, $cm->id).'
'; if (!empty($localpath)) { // Show some help echo '