-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.php
80 lines (67 loc) · 2.76 KB
/
preview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
// This file is part of Moodle - http://moodle.org/
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Fetches object preview from repository
*
* @package atto_edusharing
* @copyright metaVentis GmbH — http://metaventis.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Create preview link with signature.
require_once(__DIR__ . '/../../../../../config.php');
require_once($CFG->dirroot . '/lib/setup.php');
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->dirroot . '/mod/edusharing/lib.php');
require_login();
global $DB, $USER;
$resourceid = optional_param('resourceId', 0, PARAM_INT);
if (!$edusharing = $DB->get_record('edusharing', array('id' => $resourceid))) {
trigger_error(get_string('error_loading_instance', 'editor_edusharing'), E_USER_WARNING);
}
$previewservice = get_config('edusharing', 'application_cc_gui_url') . '/' . 'preview';
$time = round(microtime(true) * 1000);
$url = $previewservice;
$url .= '?appId=' . get_config('edusharing', 'application_appid');
$url .= '&courseId=' . $edusharing->course;
$url .= '&repoId=' . edusharing_get_repository_id_from_url($edusharing->object_url);
$url .= '&proxyRepId=' . get_config('edusharing', 'application_homerepid');
$url .= '&nodeId=' . edusharing_get_object_id_from_url($edusharing->object_url);
$url .= '&resourceId=' . $resourceid;
$url .= '&version=' . $edusharing->object_version;
$sigdata = get_config('edusharing', 'application_appid') . $time . edusharing_get_object_id_from_url($edusharing->object_url);
$sig = urlencode(edusharing_get_signature($sigdata));
$url .= '&sig=' . $sig;
$url .= '&signed=' . $sigdata;
$url .= '&ts=' . $time;
$curl = new curl();
$curl->setopt( array(
'CURLOPT_SSL_VERIFYPEER' => false,
'CURLOPT_SSL_VERIFYHOST' => false,
'CURLOPT_FOLLOWLOCATION' => 1,
'CURLOPT_HEADER' => 0,
'CURLOPT_RETURNTRANSFER' => 1,
'CURLOPT_USERAGENT' => $_SERVER['HTTP_USER_AGENT'],
));
$output = $curl->get($url);
if ($curl->error) {
debugging('cURL Error: '.$curl->error);
echo 'cURL Error: '.$curl->error;
exit();
}
$curlinfo = $curl->get_info();
header('Content-type: ' . $curlinfo['content_type']);
echo $output;
exit();