Merge branch 'MDL-68912' of https://github.com/rlorenzo/moodle
[moodle.git] / portfolio / file.php
CommitLineData
d96a1acc 1<?php
93dd2725
RW
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
4c7a4ef9 17/**
4c7a4ef9 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.
93dd2725
RW
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
4c7a4ef9 26 */
1fcf0ca8 27require_once(__DIR__ . '/../config.php');
98335b2d 28
29if (empty($CFG->enableportfolios)) {
30 print_error('disabled', 'portfolio');
31}
32
d96a1acc 33require_once($CFG->libdir . '/portfoliolib.php');
24ba58ee 34require_once($CFG->libdir . '/portfolio/exporter.php');
d96a1acc 35require_once($CFG->libdir . '/filelib.php');
36
4c7a4ef9 37// exporter id
d96a1acc 38$id = required_param('id', PARAM_INT);
39
98335b2d 40require_login();
aa379865 41$PAGE->set_url('/portfolio/add.php', array('id' => $id));
98335b2d 42
d96a1acc 43$exporter = portfolio_exporter::rewaken_object($id);
6b6f1c05 44$exporter->verify_rewaken();
d96a1acc 45
4c7a4ef9 46// push plugins don't need to access this script.
d96a1acc 47if ($exporter->get('instance')->is_push()) {
34035201 48 throw new portfolio_export_exception($exporter, 'filedenied', 'portfolio');
d96a1acc 49}
50
4c7a4ef9 51// it's up to the plugin to verify the request parameters, like a token or whatever
d96a1acc 52if (!$exporter->get('instance')->verify_file_request_params(array_merge($_GET, $_POST))) {
34035201 53 throw new portfolio_export_exception($exporter, 'filedenied', 'portfolio');
d96a1acc 54}
55
4c7a4ef9 56// ok, we're good, send the file and finish the export.
2eb07e79 57$exporter->get('instance')->send_file();
d96a1acc 58$exporter->process_stage_cleanup(true);
2eb07e79 59exit;
4317f92f 60