MDL-22731, fixed category description images
authorDongsheng Cai <unoter@gmail.com>
Fri, 11 Jun 2010 04:11:42 +0000 (04:11 +0000)
committerDongsheng Cai <unoter@gmail.com>
Fri, 11 Jun 2010 04:11:42 +0000 (04:11 +0000)
course/category.php
pluginfile.php

index 29b7917..65db242 100644 (file)
         admin_externalpage_setup('coursemgmt', '', $urlparams, $CFG->wwwroot . '/course/category.php');
         $PAGE->set_context($context);   // Ensure that we are actually showing blocks etc for the cat context
         echo $OUTPUT->header();
-    } else {        
+    } else {
         $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
         $PAGE->navbar->add($category->name);
         $PAGE->navbar->add($strcourses);
         if (!isset($category->descriptionformat)) {
             $category->descriptionformat = FORMAT_MOODLE;
         }
-        echo format_text($category->description, $category->descriptionformat, $options);
+        $text = file_rewrite_pluginfile_urls($category->description, 'pluginfile.php', $context->id, 'category_description', $category->id);
+        echo format_text($text, $category->descriptionformat, $options);
         echo $OUTPUT->box_end();
     }
 
index 3eb2e12..9ca8950 100644 (file)
@@ -71,7 +71,7 @@ if (!empty($sendflashupgrader) && (($userplayerversion[0] <  $requiredplayervers
         $lifetime = 0;  // Do not cache
         send_file($path, $filename, $lifetime, 0, false, false, $mimetype);
 
-} else if ($context->contextlevel == CONTEXT_SYSTEM) {   
+} else if ($context->contextlevel == CONTEXT_SYSTEM) {
     if ($filearea === 'blog_attachment' || $filearea === 'blog_post') {
 
         if (empty($CFG->bloglevel)) {
@@ -254,25 +254,41 @@ if (!empty($sendflashupgrader) && (($userplayerversion[0] <  $requiredplayervers
 
 
 } else if ($context->contextlevel == CONTEXT_COURSECAT) {
-    if ($filearea !== 'coursecat_intro') {
-        send_file_not_found();
-    }
+    if ($filearea == 'coursecat_intro') {
+        if ($CFG->forcelogin) {
+            // no login necessary - unless login forced everywhere
+            require_login();
+        }
 
-    if ($CFG->forcelogin) {
-        // no login necessary - unless login forced everywhere
-        require_login();
-    }
+        $relativepath = '/'.implode('/', $args);
+        $fullpath = $context->id.'coursecat_intro0'.$relativepath;
 
-    $relativepath = '/'.implode('/', $args);
-    $fullpath = $context->id.'coursecat_intro0'.$relativepath;
+        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->get_filename() == '.') {
+            send_file_not_found();
+        }
 
-    if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->get_filename() == '.') {
+        session_get_instance()->write_close(); // unlock session during fileserving
+        send_stored_file($file, 60*60, 0, $forcedownload);
+    } else if ($filearea == 'category_description') {
+        if ($CFG->forcelogin) {
+            // no login necessary - unless login forced everywhere
+            require_login();
+        }
+        $itemid = (int)array_shift($args);
+
+        $relativepath = '/'.implode('/', $args);
+        $fullpath = $context->id.'category_description'.$itemid.$relativepath;
+
+        if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->get_filename() == '.') {
+            send_file_not_found();
+        }
+
+        session_get_instance()->write_close(); // unlock session during fileserving
+        send_stored_file($file, 60*60, 0, $forcedownload);
+    } else {
         send_file_not_found();
     }
 
-    session_get_instance()->write_close(); // unlock session during fileserving
-    send_stored_file($file, 60*60, 0, $forcedownload);
-
 
 } else if ($context->contextlevel == CONTEXT_COURSE) {
     if (!$course = $DB->get_record('course', array('id'=>$context->instanceid))) {
@@ -424,11 +440,11 @@ if (!empty($sendflashupgrader) && (($userplayerversion[0] <  $requiredplayervers
 
         session_get_instance()->write_close();
         send_stored_file($file, 60*60, 0, false);
-   
+
     } else if ($filearea === 'user_profile') {
         $userid = (int)array_shift($args);
         $usercontext = get_context_instance(CONTEXT_USER, $userid);
-        
+
         if ($CFG->forcelogin) {
             require_login();
         }