forked from gjb2048/moodle-block_jmail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
80 lines (65 loc) · 2.51 KB
/
Copy pathlib.php
File metadata and controls
80 lines (65 loc) · 2.51 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Lib functions for the block.
*
* @package blocks
* @subpackage jmail
* @copyright 2011 Juan Leyva <juanleyvadelgado@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot.'/blocks/jmail/block_jmail_mailbox.class.php');
/**
* Serves the message attachments. Implements needed access control ;-)
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @return bool false if file not found, does not return if found - justsend the file
*/
function block_jmail_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $SCRIPT;
if ($context->contextlevel != CONTEXT_BLOCK) {
//send_file_not_found();
}
require_course_login($course);
$coursecontext = block_jmail_get_context(CONTEXT_COURSE, $course->id, MUST_EXIST);
// The mailbox constructor does the permission validation
if (!$mailbox = new block_jmail_mailbox($course, $coursecontext, $context)) {
return;
}
$messageid = (int)array_shift($args);
$message = block_jmail_message::get_from_id($messageid);
// We check if we are the senders or the receivers
if (!$message) {
send_file_not_found();
}
$pendingaprobal = !$message->approved and has_capability('block/jmail:approvemessages', $context);
if (!$message->is_mine() and !$pendingaprobal) {
send_file_not_found();
}
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/$context->id/block_jmail/$filearea/$messageid/$relativepath";
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
send_file_not_found();
}
$forcedownload = true;
send_stored_file($file, 60*60, 0, $forcedownload);
}