]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18910 full support for module intro editor with embedded images
authorskodak <skodak>
Wed, 22 Apr 2009 05:10:08 +0000 (05:10 +0000)
committerskodak <skodak>
Wed, 22 Apr 2009 05:10:08 +0000 (05:10 +0000)
19 files changed:
lib/weblib.php
mod/resource/index.php
mod/resource/mod_form.php
mod/resource/type/directory/resource.class.php
mod/resource/type/file/resource.class.php
mod/resource/type/html/resource.class.php
mod/resource/type/ims/resource.class.php
mod/resource/type/repository/resource.class.php
mod/resource/type/text/resource.class.php
mod/scorm/index.php
mod/scorm/lib.php
mod/scorm/locallib.php
mod/scorm/mod_form.php
mod/scorm/view.php
mod/survey/mod_form.php
mod/survey/view.php
mod/wiki/index.php
mod/wiki/mod_form.php
mod/wiki/view.php

index af987dbe918b79485960473889810b63b7a8aad9..540b4646bc2729945e5af95b25c29be1ac555d11 100644 (file)
@@ -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));
 }
 
 /**
index 15d85d9e4e88455dd401a98047d40744afce8a9d..63e968f6ef5c585908d3af0f978b7928378d693c 100644 (file)
@@ -47,8 +47,6 @@
     }
 
     $currentsection = "";
-    $options->para = false;
-    $options->noclean = true;
     foreach ($resources as $resource) {
         if ($course->format == "weeks" or $course->format == "topics") {
             $printsection = "";
         if (!$resource->visible) {      // Show dimmed if the mod is hidden
             $table->data[] = array ($printsection, 
                     "<a class=\"dimmed\" $extra href=\"view.php?id=$resource->coursemodule\">".format_string($resource->name,true)."</a>",
-                    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, 
                     "<a $extra href=\"view.php?id=$resource->coursemodule\">".format_string($resource->name,true)."</a>",
-                    format_text($resource->intro, $resource->introformat, $options) );
+                    format_module_intro('resource', $resource, $resource->coursemodule));
         }
     }
 
index 243ee602d954bf793ef19abf7d2470768749b171..f1860c8b25dfdd5b828ba1f30eeb4b8322b7db26 100644 (file)
@@ -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);
index f6a2eda765b9dd1d31bf9db440d0e621b361f9a4..3a3657c2b528bac22ce76f56cc549416bd074101 100644 (file)
@@ -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, <p> 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);
     }
 
index 3a63b422487721a652790bf5db52bdb69eba9d2f..d2af53306bd970515a1ff6b154a262c5c1d7d931 100644 (file)
@@ -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 '</script>';
 
             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 = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;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 "</body></html>";
                 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 '<div class="summary">'.format_text($resource->intro, $resource->introformat, $options).'</div>';
+            echo '<div class="summary">'.format_module_intro('resource', $resource, $cm->id).'</div>';
             if (!empty($localpath)) {  // Show some help
                 echo '<div class="mdl-right helplink">';
                 link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'),
@@ -706,7 +700,7 @@ class resource_file extends resource_base {
             }
 
             if (trim($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");
             }
 
             if ($inpopup) {
index 20097e0fffa18d2e21798bb5f939e690bcefb342..cadf8dfca8c660ea57e18db7a830879c97e452d6 100644 (file)
@@ -103,7 +103,7 @@ function display() {
                 echo '</script>';
 
                 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 = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
index 0a31abb64993b4f1b15cead0e850ac591fda7cf9..a62f96dd4eb5ce9ffd77f671244f795c611d3632 100644 (file)
@@ -340,9 +340,6 @@ class resource_ims extends resource_base {
         $mimetype = mimeinfo("type", $resource->reference);
         $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
 
-        $formatoptions = new object();
-        $formatoptions->noclean = true;
-
     /// Cache this per request
         static $items;
 
@@ -435,7 +432,7 @@ class resource_ims extends resource_base {
             echo '</script>';
 
             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 = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
index f610d336c6bb2c26f07dc75b605b18f49007af0c..697f0993a06f7c2ece2dbc24b0e04725dfaad291 100644 (file)
@@ -212,9 +212,6 @@ function display() {
     $mimetype = mimeinfo("type", $resource->reference);
     $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
 
-    $formatoptions = new object();
-    $formatoptions->noclean = true;
-
     if ($resource->options != "frame") {
         if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) {  // It's an image
             $resourcetype = "image";
@@ -314,8 +311,7 @@ function display() {
         echo '</script>';
 
         if (trim(strip_tags($resource->intro))) {
-            $formatoptions->noclean = true;
-            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 = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
@@ -365,7 +361,7 @@ function display() {
         print_header($pagetitle, $course->fullname, $navigation, "", "", true,
                 update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent"));
 
-        echo '<div class="summary">'.format_text($resource->intro, $resource->introformat, $formatoptions).'</div>';
+        echo '<div class="summary">'.format_module_intro('resource', $resource, $cm->id).'</div>';
         if (!empty($localpath)) {  // Show some help
             echo '<div class="mdl-right helplink">';
             link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
@@ -467,9 +463,8 @@ function display() {
             echo "</p></center>";
         }
 
-        if (trim($resource->summary)) {
-            $formatoptions->noclean = true;
-            print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
+        if (trim($resource->intro)) {
+            print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
         }
 
         if ($inpopup) {
index 01aa639eb07f21d17676e9767af7f41d9418802b..1cad6758e239d77cc2e25045b66d7aac9f5f8691 100644 (file)
@@ -101,7 +101,7 @@ function display() {
                 echo '</script>';
 
                 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 = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
index 7afbf08557e296195300265aff9ed8ab149eaa5a..3661af88e8448641159aa2d8cf582a8f5fbea140 100755 (executable)
         if (!$scorm->visible) {
            //Show dimmed if the mod is hidden
            $table->data[] = array ($tt, "<a class=\"dimmed\" href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name)."</a>",
-                                   format_text($scorm->intro, $scorm->introformat, $options), $reportshow);
+                                   format_module_intro('scorm', $scorm, $scorm->coursemodule), $reportshow);
         } else {
            //Show normal if the mod is visible
            $table->data[] = array ($tt, "<a href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name)."</a>",
-                                   format_text($scorm->intro, $scorm->introformat, $options), $reportshow);
+                                   format_module_intro('scorm', $scorm, $scorm->coursemodule), $reportshow);
         }
     }
 
index 4076547a7275c7b433241b47de01cf75825fcea4..0d308a588bcf94b027d055ac2473e90f876de2db 100755 (executable)
@@ -774,17 +774,7 @@ function scorm_pluginfile($course, $cminfo, $context, $filearea, $args) {
 
     $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400;
 
-    if ($filearea === 'scorm_intro') {
-        // all users may access it
-        $relativepath = '/'.implode('/', $args);
-        $fullpath = $context->id.'scorm_intro0'.$relativepath;
-
-        $fs = get_file_storage();
-        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
-            return false;
-        }
-
-    } else if ($filearea === 'scorm_content') {
+    if ($filearea === 'scorm_content') {
         $revision = (int)array_shift($args); // prevents caching problems - ignored here
         $relativepath = '/'.implode('/', $args);
         $fullpath = $context->id.'scorm_content0'.$relativepath;
index 35ead245d0bbdea3e064916be292ef410ab0044e..2d071bac23c5be43b1d6e862c0d7db7bb1c82904 100755 (executable)
@@ -701,7 +701,7 @@ function scorm_course_format_display($user,$course) {
             $colspan = ' colspan="2"';
         }
         $options = (object)array('noclean'=>true);
-        $headertext .= '</td></tr><tr><td'.$colspan.'>'.get_string('summary').':<br />'.format_text($scorm->intro, $scorm->introformat, $options).'</td></tr></table>';
+        $headertext .= '</td></tr><tr><td'.$colspan.'>'.get_string('summary').':<br />'.format_module_intro('scorm', $scorm, $scorm->coursemodule).'</td></tr></table>';
         print_simple_box($headertext,'','100%');
         scorm_view_display($user, $scorm, 'view.php?id='.$course->id, $cm, '100%');
     } else {
index 5bb3a6cb0922a071c726929d16964bec4caba74e..cf508824338bb4eab7ffc9ec2cbc55ef91f1c67f 100644 (file)
@@ -30,10 +30,7 @@ class mod_scorm_mod_form extends moodleform_mod {
         $mform->addRule('name', null, 'required', null, 'client');
 
 // Summary
-        $mform->addElement('htmleditor', 'intro', get_string('summary'));
-        $mform->setType('intro', PARAM_RAW);
-        $mform->addRule('intro', get_string('required'), 'required', null, 'client');
-        $mform->setHelpButton('intro', array('writing', 'questions', 'richtext2'), false, 'editorhelpbutton');
+        $this->add_intro_editor(true);
 
 // Scorm types
         $options = array(SCORM_TYPE_LOCAL => get_string('typelocal', 'scorm'));
index 29011a4055da95ee8886d18b7c2f07e6a5d40f65..134f0967a2c90770a4c02fe73e3d60019203d63a 100755 (executable)
     // Print the main part of the page
     print_heading(format_string($scorm->name));
     $attemptstatus = '';
-    if($scorm->displayattemptstatus == 1) {
+    if ($scorm->displayattemptstatus == 1) {
         $attemptstatus = scorm_get_attempt_status($USER,$scorm);
     }
-    $options = (object)array('noclean'=>true);
-    print_simple_box(format_text($scorm->intro, $scorm->introformat, $options).$attemptstatus, 'center', '70%', '', 5, 'generalbox', 'intro');
+    print_simple_box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'center', '70%', '', 5, 'generalbox', 'intro');
     
     $scormopen = true;
     $timenow = time();
index 68fe5e0a8051c92276d7bb338937d9b0f3274bed..79925e98c79c51a2320bcbf1dd5c6a8c7879494f 100644 (file)
@@ -4,8 +4,8 @@ require_once ($CFG->dirroot.'/course/moodleform_mod.php');
 class mod_survey_mod_form extends moodleform_mod {
 
     function definition() {
-
         global $CFG, $DB;
+
         $mform =& $this->_form;
 
         $strrequired = get_string('required');
@@ -33,9 +33,7 @@ class mod_survey_mod_form extends moodleform_mod {
         $mform->addRule('template', $strrequired, 'required', null, 'client');
         $mform->setHelpButton('template', array('surveys', get_string('helpsurveys', 'survey')));
 
-
-        $mform->addElement('textarea', 'intro', get_string('customintro', 'survey'), 'wrap="virtual" rows="20" cols="75"');
-        $mform->setType('intro', PARAM_RAW);
+        $this->add_intro_editor(false, get_string('customintro', 'survey'));
 
         $this->standard_coursemodule_elements();
 
index e0f4558588b82627c924140d47d43252d274fa44..84c38d10a30081927c56c0abf4f6ad5c285bfc5e 100644 (file)
@@ -80,8 +80,7 @@
 
         } else {
 
-            $options = (object)array('noclean'=>true);
-            print_box(format_text($survey->intro, $survey->introformat, $options), 'generalbox', 'intro');
+            print_box(format_module_intro('survey', $survey, $cm->id), 'generalbox', 'intro');
             print_spacer(30);
 
             $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
     echo '<div>';
     echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
 
-    print_simple_box(format_text($survey->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
+    print_simple_box(format_module_intro('survey', $survey, $cm->id), 'center', '70%', '', 5, 'generalbox', 'intro');
 
 // Get all the major questions and their proper order
     if (! $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions))) {
index 35e1888b5421d0ffbe908eb8b8f979c70ad2e7b6..bbd5890e57ea8bd10a636f4164400d15bdbc78fd 100644 (file)
@@ -69,7 +69,7 @@
 
         $timmod = '<span class="smallinfo">'.userdate($wiki->timemodified).'</span>';
         $options = (object)array('noclean'=>true);
-        $summary = '<div class="smallinfo">'.format_text($wiki->intro, $wiki->introformat, $options).'</div>';
+        $summary = '<div class="smallinfo">'.format_module_intro('wiki', $wiki, $wiki->coursemodule).'</div>';
 
         $site = get_site();
         switch ($wiki->wtype) {
index d288f2b258f22a0bd60b0351fbb2d51ec9dd788e..2127778ced50bde60e0ac31a0a23cbfb28443690 100644 (file)
@@ -21,10 +21,7 @@ class mod_wiki_mod_form extends moodleform_mod {
         $mform->setType('name', PARAM_NOTAGS);
         $mform->addRule('name', null, 'required', null, 'client');
 
-        $mform->addElement('htmleditor', 'intro', get_string('summary'));
-        $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);
 
         if (!$wikihasentries){
             asort($WIKI_TYPES);
index 33dccfafedb0c7fabd63467a11a2adafccb461bc..7ca02b7478fb3953781eb3a115ab83224ad1a56e 100644 (file)
 
     if($wiki_entry && $ewiki_title==$wiki_entry->pagename && !empty($wiki->intro)) {
       if (trim(strip_tags($wiki->intro))) {
-          $options = (object)array('noclean'=>true);
-          print_box(format_text($wiki->intro, $wiki->introformat, $options), 'generalbox', 'intro');
+          print_box(format_module_intro('wiki', $wiki, $cm->id), 'generalbox', 'intro');
       }
     }