MDL-23911 login as session can be only terminated by logout, this should improve...
[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) {
27
28 if ($context->contextlevel != CONTEXT_BLOCK) {
29 send_file_not_found();
30 }
31
32 require_course_login($course);
33
34 if ($filearea !== 'content') {
35 send_file_not_found();
36 }
37
38 $fs = get_file_storage();
39
40 $filename = array_pop($args);
d85ab705 41 $filepath = $args ? '/'.implode('/', $args).'/' : '/';
64f93798
PS
42
43 if (!$file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename) or $file->is_directory()) {
44 send_file_not_found();
45 }
46
47 session_get_instance()->write_close();
48 send_stored_file($file, 60*60, 0, $forcedownload);
49}