Merge branch 'MOODLE_23_STABLE' into install_23_STABLE
[moodle.git] / portfolio / file.php
... / ...
CommitLineData
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 * For portfolio plugins that are 'pull' - ie, send the request and then wait
19 * for the remote system to request the file for moodle,
20 * this is the script that serves up the export file to them.
21 *
22 * @package core_portfolio
23 * @copyright 2008 Penny Leach <penny@catalyst.net.nz>,
24 * Martin Dougiamas <http://dougiamas.com>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
27require_once(dirname(dirname(__FILE__)) . '/config.php');
28
29if (empty($CFG->enableportfolios)) {
30 print_error('disabled', 'portfolio');
31}
32
33require_once($CFG->libdir . '/portfoliolib.php');
34require_once($CFG->libdir . '/portfolio/exporter.php');
35require_once($CFG->libdir . '/filelib.php');
36
37// exporter id
38$id = required_param('id', PARAM_INT);
39
40require_login();
41$PAGE->set_url('/portfolio/add.php', array('id' => $id));
42
43$exporter = portfolio_exporter::rewaken_object($id);
44$exporter->verify_rewaken();
45
46// push plugins don't need to access this script.
47if ($exporter->get('instance')->is_push()) {
48 throw new portfolio_export_exception($exporter, 'filedenied', 'portfolio');
49}
50
51// it's up to the plugin to verify the request parameters, like a token or whatever
52if (!$exporter->get('instance')->verify_file_request_params(array_merge($_GET, $_POST))) {
53 throw new portfolio_export_exception($exporter, 'filedenied', 'portfolio');
54}
55
56// ok, we're good, send the file and finish the export.
57$exporter->get('instance')->send_file();
58$exporter->process_stage_cleanup(true);
59exit;
60