portfolio - MDL-20850 - updates to use $PAGE better
[moodle.git] / portfolio / file.php
CommitLineData
d96a1acc 1<?php
4c7a4ef9 2/**
3 * Moodle - Modular Object-Oriented Dynamic Learning Environment
4 * http://moodle.org
5 * Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * @package moodle
21 * @subpackage portfolio
22 * @author Penny Leach <penny@catalyst.net.nz>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
24 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
25 *
26 * For portfolio plugins that are 'pull' - ie, send the request and then wait
27 * for the remote system to request the file for moodle,
28 * this is the script that serves up the export file to them.
29 */
d96a1acc 30require_once(dirname(dirname(__FILE__)) . '/config.php');
98335b2d 31
32if (empty($CFG->enableportfolios)) {
33 print_error('disabled', 'portfolio');
34}
35
d96a1acc 36require_once($CFG->libdir . '/portfoliolib.php');
37require_once($CFG->libdir . '/file/stored_file.php');
38require_once($CFG->libdir . '/filelib.php');
39
4c7a4ef9 40// exporter id
d96a1acc 41$id = required_param('id', PARAM_INT);
42
98335b2d 43require_login();
44
d96a1acc 45$exporter = portfolio_exporter::rewaken_object($id);
6b6f1c05 46$exporter->verify_rewaken();
d96a1acc 47
4c7a4ef9 48// push plugins don't need to access this script.
d96a1acc 49if ($exporter->get('instance')->is_push()) {
34035201 50 throw new portfolio_export_exception($exporter, 'filedenied', 'portfolio');
d96a1acc 51}
52
4c7a4ef9 53// it's up to the plugin to verify the request parameters, like a token or whatever
d96a1acc 54if (!$exporter->get('instance')->verify_file_request_params(array_merge($_GET, $_POST))) {
34035201 55 throw new portfolio_export_exception($exporter, 'filedenied', 'portfolio');
d96a1acc 56}
57
4c7a4ef9 58// ok, we're good, send the file and finish the export.
2eb07e79 59$exporter->get('instance')->send_file();
d96a1acc 60$exporter->process_stage_cleanup(true);
2eb07e79 61exit;
4317f92f 62