MDL-61242 repository_equella: Add source key when sending the source.
[moodle.git] / repository / equella / callback.php
CommitLineData
27bb724f
DC
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/**
74ea1b95 18 * Callback for equella repository.
27bb724f 19 *
5bcfd504 20 * @since Moodle 2.3
74ea1b95 21 * @package repository_equella
27bb724f
DC
22 * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
1fcf0ca8 25require(__DIR__.'/../../config.php');
27bb724f
DC
26$json = required_param('tlelinks', PARAM_RAW);
27
2e47347c
DP
28require_login();
29
130b3f8c
DP
30$decodedinfo = json_decode($json);
31$info = array_pop($decodedinfo);
27bb724f 32
2e47347c
DP
33$url = '';
34if (isset($info->url)) {
35 $url = s(clean_param($info->url, PARAM_URL));
36}
37
38$filename = '';
0e1cd769
DC
39// Use $info->filename if exists, $info->name is a display name,
40// it may not have extension
41if (isset($info->filename)) {
42 $filename = s(clean_param($info->filename, PARAM_FILE));
43} else if (isset($info->name)) {
2e47347c
DP
44 $filename = s(clean_param($info->name, PARAM_FILE));
45}
46
47$thumbnail = '';
48if (isset($info->thumbnail)) {
49 $thumbnail = s(clean_param($info->thumbnail, PARAM_URL));
50}
51
52$author = '';
e3e4ca5a 53if (isset($info->owner)) {
54 $author = s(clean_param($info->owner, PARAM_NOTAGS));
2e47347c
DP
55}
56
57$license = '';
58if (isset($info->license)) {
59 $license = s(clean_param($info->license, PARAM_ALPHAEXT));
60}
da1f4aee 61
56964b79 62$source = base64_encode(json_encode(array('url'=>$url,'filename'=>$filename)));
d05c2ac7 63$sourcekey = sha1($source . repository::get_secret_key() . sesskey());
c01f7628 64
27bb724f
DC
65$js =<<<EOD
66<html>
67<head>
2e47347c 68 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
27bb724f
DC
69 <script type="text/javascript">
70 window.onload = function() {
71 var resource = {};
72 resource.title = "$filename";
c01f7628 73 resource.source = "$source";
d05c2ac7 74 resource.sourcekey = "$sourcekey";
27bb724f 75 resource.thumbnail = '$thumbnail';
2e47347c
DP
76 resource.author = "$author";
77 resource.license = "$license";
27bb724f
DC
78 parent.M.core_filepicker.select_file(resource);
79 }
80 </script>
81</head>
82<body><noscript></noscript></body>
83</html>
84EOD;
85
2e47347c 86header('Content-Type: text/html; charset=utf-8');
27bb724f 87die($js);