MDL-23916 JS now allowed on private /my/ pages again
[moodle.git] / blocks / html / lib.php
CommitLineData
64f93798
PS
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Form for editing HTML block instances.
20 *
21 * @package block_html
22 * @copyright 2010 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload) {
d449b246 27 global $SCRIPT;
64f93798
PS
28
29 if ($context->contextlevel != CONTEXT_BLOCK) {
30 send_file_not_found();
31 }
32
33 require_course_login($course);
34
35 if ($filearea !== 'content') {
36 send_file_not_found();
37 }
38
39 $fs = get_file_storage();
40
41 $filename = array_pop($args);
d85ab705 42 $filepath = $args ? '/'.implode('/', $args).'/' : '/';
64f93798
PS
43
44 if (!$file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename) or $file->is_directory()) {
45 send_file_not_found();
46 }
47
d449b246
PS
48 if ($parentcontext = get_context_instance_by_id($birecord_or_cm->parentcontextid)) {
49 if ($parentcontext->contextlevel == CONTEXT_USER) {
50 // force download on all personal pages including /my/
51 //because we do not have reliable way to find out from where this is used
52 $forcedownload = true;
53 }
54 } else {
55 // weird, there should be parent context, better force dowload then
56 $forcedownload = true;
57 }
58
64f93798
PS
59 session_get_instance()->write_close();
60 send_stored_file($file, 60*60, 0, $forcedownload);
61}