diff --git a/mod/glossary/export.php b/mod/glossary/export.php index 79dd0e7c3ce..11d97f06e24 100644 --- a/mod/glossary/export.php +++ b/mod/glossary/export.php @@ -16,9 +16,7 @@ if ($cat !== 0) { if ($mode !== '') { $url->param('mode', $mode); } -if ($hook !== '') { - $url->param('hook', $hook); -} + $PAGE->set_url($url); if (! $cm = get_coursemodule_from_id('glossary', $id)) { @@ -56,15 +54,15 @@ $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading($strexportentries); echo $OUTPUT->box_start('glossarydisplay generalbox'); +$exporturl = moodle_url::make_pluginfile_url($context->id, 'mod_glossary', 'export', 0, "/$cat/", 'export.xml', true); + ?> -
libdir/filelib.php"); -require_once("lib.php"); - -$id = required_param('id', PARAM_INT); // Course Module ID - -$l = optional_param('l','', PARAM_ALPHANUM); -$cat = optional_param('cat',0, PARAM_ALPHANUM); - -$url = new moodle_url('/mod/glossary/exportfile.php', array('id'=>$id)); -if ($l !== '') { - $url->param('l', $l); -} -if ($cat !== 0) { - $url->param('cat', $cat); -} -$PAGE->set_url($url); - -if (! $cm = get_coursemodule_from_id('glossary', $id)) { - print_error('invalidcoursemodule'); -} - -if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); -} - -if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidid', 'glossary'); -} - -require_login($course->id, false, $cm); - -$context = get_context_instance(CONTEXT_MODULE, $cm->id); -require_capability('mod/glossary:export', $context); - -$filename = clean_filename(strip_tags(format_string($glossary->name,true)).'.xml'); -$content = glossary_generate_export_file($glossary,$l,$cat); - -send_file($content, $filename, 0, 0, true, true); - diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 22ef1fbb0d9..c3247f0d8fb 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -1423,6 +1423,22 @@ function glossary_pluginfile($course, $cm, $context, $filearea, $args, $forcedow // finally send the file send_stored_file($file, 0, 0, true); // download MUST be forced - security! + + } else if ($filearea === 'export') { + require_login($course, false, $cm); + require_capability('mod/glossary:export', $context); + + if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) { + return false; + } + + $cat = array_shift($args); + $cat = clean_param($cat, PARAM_ALPHANUM); + + $filename = clean_filename(strip_tags(format_string($glossary->name)).'.xml'); + $content = glossary_generate_export_file($glossary, NULL, $cat); + + send_file($content, $filename, 0, 0, true, true); } return false; @@ -1911,15 +1927,13 @@ function glossary_generate_export_csv($entries, $aliases, $categories) { } /** - * @todo Check whether the third argument is valid - * @global object - * @global object + * * @param object $glossary - * @param string $hook - * @param int $hook + * @param string $ignored invalid parameter + * @param int|string $hook * @return string */ -function glossary_generate_export_file($glossary, $hook = "", $hook = 0) { +function glossary_generate_export_file($glossary, $ignored = "", $hook = 0) { global $CFG, $DB; $co = "\n";