1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* unilabel type grid.
|
|
|
19 |
*
|
|
|
20 |
* @package unilabeltype_grid
|
|
|
21 |
* @author Andreas Grabs <info@grabs-edv.de>
|
|
|
22 |
* @copyright 2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
* @param mixed $course
|
|
|
25 |
* @param mixed $cm
|
|
|
26 |
* @param mixed $context
|
|
|
27 |
* @param mixed $filearea
|
|
|
28 |
* @param mixed $args
|
|
|
29 |
* @param mixed $forcedownload
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Send files provided by this plugin.
|
|
|
34 |
*
|
|
|
35 |
* @param \stdClass $course
|
|
|
36 |
* @param \stdClass $cm
|
|
|
37 |
* @param \context $context
|
|
|
38 |
* @param string $filearea
|
|
|
39 |
* @param array $args
|
|
|
40 |
* @param bool $forcedownload
|
|
|
41 |
* @return bool
|
|
|
42 |
*/
|
|
|
43 |
function unilabeltype_grid_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
|
|
|
44 |
if ($context->contextlevel != CONTEXT_MODULE) {
|
|
|
45 |
return false;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
require_course_login($course, true, $cm);
|
|
|
49 |
if (!has_capability('mod/unilabel:view', $context)) {
|
|
|
50 |
return false;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
if (($filearea !== 'image') && ($filearea !== 'image_mobile') && ($filearea !== 'content')) {
|
|
|
54 |
return false;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
$relativepath = implode('/', $args);
|
|
|
58 |
$fullpath = '/' . $context->id . '/unilabeltype_grid/' . $filearea . '/' . $relativepath;
|
|
|
59 |
|
|
|
60 |
$fs = get_file_storage();
|
|
|
61 |
if ($file = $fs->get_file_by_hash(sha1($fullpath))) {
|
|
|
62 |
if (!$file->is_directory()) {
|
|
|
63 |
send_stored_file($file, 0, 0, true); // Download MUST be forced - security!
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
return false;
|
|
|
68 |
}
|