Skip to content

Commit

Permalink
MDL-22731, fixed category description images
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Jun 11, 2010
1 parent 94788de commit 214a81b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
5 changes: 3 additions & 2 deletions course/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
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);
Expand Down Expand Up @@ -200,7 +200,8 @@
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();
}

Expand Down
48 changes: 32 additions & 16 deletions pluginfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
$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)) {
Expand Down Expand Up @@ -254,25 +254,41 @@


} 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))) {
Expand Down Expand Up @@ -424,11 +440,11 @@

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();
}
Expand Down

0 comments on commit 214a81b

Please sign in to comment.