1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Fetches object preview from repository
|
|
|
19 |
*
|
|
|
20 |
* @package mod_edusharing
|
|
|
21 |
* @copyright metaVentis GmbH — http://metaventis.com
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
use EduSharingApiClient\Usage;
|
|
|
26 |
use mod_edusharing\EduSharingService;
|
|
|
27 |
use mod_edusharing\UtilityFunctions;
|
|
|
28 |
|
|
|
29 |
require_once(dirname(__FILE__) . '/../../config.php');
|
|
|
30 |
|
|
|
31 |
global $DB;
|
|
|
32 |
|
|
|
33 |
try {
|
|
|
34 |
require_login();
|
|
|
35 |
$resourceid = optional_param('resourceId', 0, PARAM_INT);
|
|
|
36 |
$edusharing = $DB->get_record('edusharing', ['id' => $resourceid], '*', MUST_EXIST);
|
|
|
37 |
$utils = new UtilityFunctions();
|
|
|
38 |
$service = new EduSharingService();
|
|
|
39 |
$usage = new Usage(
|
|
|
40 |
$utils->get_object_id_from_url($edusharing->object_url),
|
|
|
41 |
$edusharing->object_version,
|
|
|
42 |
(string)$edusharing->course,
|
|
|
43 |
(string)$edusharing->id,
|
|
|
44 |
(string)$edusharing->usage_id
|
|
|
45 |
);
|
|
|
46 |
$curlresult = $service->get_preview_image($usage);
|
|
|
47 |
} catch (Exception $exception) {
|
|
|
48 |
echo 'Error occurred: ' . $exception->getMessage();
|
|
|
49 |
exit();
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
header('Content-type: ' . $curlresult->info['content_type']);
|
|
|
53 |
echo $curlresult->content;
|
|
|
54 |
exit();
|