file.php 2.1 KB

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