Skip to content

Commit

Permalink
MDL-16075 adding missing lang strings
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 7, 2008
1 parent a060b74 commit aa9bcfc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
1 change: 1 addition & 0 deletions lang/en_utf8/glossary.php
Expand Up @@ -15,6 +15,7 @@
$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';
Expand Down
87 changes: 57 additions & 30 deletions mod/glossary/lib.php
Expand Up @@ -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() {
Expand Down

0 comments on commit aa9bcfc

Please sign in to comment.