MDL-23901 copy/paste style migration of glossary to export via pluginfile.php

This commit is contained in:
Petr Skoda 2010-08-23 14:42:31 +00:00
parent e243c8c448
commit 1ca1c8f820
3 changed files with 24 additions and 57 deletions

View File

@ -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);
?>
<form action="exportfile.php" method="post">
<form action="<?php echo $exporturl->out(); ?>" method="post">
<table border="0" cellpadding="6" cellspacing="6" width="100%">
<tr><td align="center">
<input type="submit" value="<?php p($strexportfile)?>" />
</td></tr></table>
<div>
<input type="hidden" name="id" value="<?php p($id)?>" />
<input type="hidden" name="cat" value="<?php p($cat)?>" />
</div>
</form>
<?php

View File

@ -1,45 +0,0 @@
<?php
// disable moodle specific debug messages and any errors in output
define('NO_DEBUG_DISPLAY', true);
require_once("../../config.php");
require_once("$CFG->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);

View File

@ -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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";