From aa9bcfcd508cea109dee2af0359bf65b3c701301 Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 7 Sep 2008 23:20:51 +0000 Subject: [PATCH] MDL-16075 adding missing lang strings --- lang/en_utf8/glossary.php | 1 + mod/glossary/lib.php | 87 +++++++++++++++++++++++++-------------- 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/lang/en_utf8/glossary.php b/lang/en_utf8/glossary.php index 01d7526c36..01b7e3fc56 100644 --- a/lang/en_utf8/glossary.php +++ b/lang/en_utf8/glossary.php @@ -15,6 +15,7 @@ $string['allowprintview'] = 'Allow print view'; $string['allowratings'] = 'Allow entries to be rated?'; $string['answer'] = 'Answer'; $string['approve'] = 'Approve'; +$string['areaintro'] = 'Glossary introduction'; $string['areyousuredelete'] = 'Are you sure you want to delete this entry?'; $string['areyousuredeletecomment'] = 'Are you sure you want to delete this comment?'; $string['areyousureexport'] = 'Are you sure you want to export this entry to'; diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 60ae1a86de..c3ffbcb0eb 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -1179,56 +1179,83 @@ function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") { } } +/** + * Lists all browsable file areas + */ +function glossary_get_file_areas($course, $cm, $context) { + $areas = array(); + if (has_capability('moodle/course:managefiles', $context)) { + $areas['glossary_intro'] = get_string('areaintro', 'glossary'); + } + return $areas; +} + /** * Serves the glossary attachments. Implements needed access control ;-) */ function glossary_pluginfile($course, $cminfo, $context, $filearea, $args) { global $CFG, $DB; - if ($filearea !== 'glossary_attachment') { - return false; - } - if (!$cminfo->uservisible) { return false; } - $entryid = (int)array_shift($args); + if ($filearea === 'glossary_intro') { + // all users may access it + $relativepath = '/'.implode('/', $args); + $fullpath = $context->id.'glossary_intro0'.$relativepath; - if (!$entry = $DB->get_record('glossary_entries', array('id'=>$entryid))) { - return false; - } + $fs = get_file_storage(); + if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { + return false; + } - if (!$glossary = $DB->get_record('glossary', array('id'=>$cminfo->instance))) { - return false; - } + $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400; - if ($glossary->defaultapproval and !$entry->approved and !has_capability('mod/glossary:approve', $context)) { - return false; - } + // finally send the file + send_stored_file($file, $lifetime, 0); - if ($entry->glossaryid == $cminfo->instance) { - $filecontext = $context; + } else if ($filearea === 'glossary_attachment') { + $entryid = (int)array_shift($args); - } else if ($entry->sourceglossaryid == $cminfo->instance) { - if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) { - print_error('invalidcoursemodule'); + if (!$entry = $DB->get_record('glossary_entries', array('id'=>$entryid))) { + return false; } - $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id); - } else { - return false; - } + if (!$glossary = $DB->get_record('glossary', array('id'=>$cminfo->instance))) { + return false; + } - $fs = get_file_storage(); - $relativepath = '/'.implode('/', $args); - $fullpath = $filecontext->id.$filearea.$entryid.$relativepath; - if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { - return false; + if ($glossary->defaultapproval and !$entry->approved and !has_capability('mod/glossary:approve', $context)) { + return false; + } + + if ($entry->glossaryid == $cminfo->instance) { + $filecontext = $context; + + } else if ($entry->sourceglossaryid == $cminfo->instance) { + if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) { + print_error('invalidcoursemodule'); + } + $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id); + + } else { + return false; + } + + $relativepath = '/'.implode('/', $args); + $fullpath = $filecontext->id.$filearea.$entryid.$relativepath; + + $fs = get_file_storage(); + if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { + return false; + } + + // finally send the file + send_stored_file($file, 0, 0, true); // download MUST be forced - security! } - // finally send the file - send_stored_file($file, 0, 0, true); // download MUST be forced - security! + return false; } function glossary_print_tabbed_table_end() { -- 2.39.5