/
download.php
51 lines (44 loc) · 1.42 KB
/
download.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
*
* @package mahara
* @subpackage core
* @author Richard Mansfield
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('PUBLIC', 1);
require('init.php');
require_once('file.php');
$type = param_alpha('type', null);
if ($type == 'sitemap') {
if (!get_config('generatesitemap')) {
throw new NotFoundException(get_string('filenotfound'));
}
if ($name = param_alphanumext('name', null)) {
if (!preg_match('/^sitemap_[a-z0-9_]+\.xml(\.gz)?$/', $name, $m)) {
throw new NotFoundException(get_string('filenotfound'));
}
$mimetype = empty($m[1]) ? 'text/xml' : 'application/gzip';
}
else {
$name = 'sitemap_index.xml';
$mimetype = 'text/xml';
}
$path = get_config('dataroot') . 'sitemaps/' . $name;
}
else {
$data = $SESSION->get('downloadfile');
if (!$USER->is_logged_in() || empty($data) || empty($data['file'])) {
throw new NotFoundException(get_string('filenotfound'));
}
$path = get_config('dataroot') . 'export/' . $USER->get('id') . '/' . $data['file'];
$name = $data['name'];
$mimetype = $data['mimetype'];
}
if (!file_exists($path)) {
throw new NotFoundException(get_string('filenotfound'));
}
serve_file($path, $name, $mimetype);