Merge branch 'wip-MDL-42020-master' of git://github.com/marinaglancy/moodle
[moodle.git] / repository / equella / callback.php
blob01fc27dc7f3f790a21c131d3a5b4ecab7ddb476b
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.
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/>.
17 /**
18 * Callback for equella repository.
20 * @since 2.3
21 * @package repository_equella
22 * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
26 $json = required_param('tlelinks', PARAM_RAW);
28 require_login();
30 $decodedinfo = json_decode($json);
31 $info = array_pop($decodedinfo);
33 $url = '';
34 if (isset($info->url)) {
35 $url = s(clean_param($info->url, PARAM_URL));
38 $filename = '';
39 if (isset($info->name)) {
40 $filename = s(clean_param($info->name, PARAM_FILE));
43 $thumbnail = '';
44 if (isset($info->thumbnail)) {
45 $thumbnail = s(clean_param($info->thumbnail, PARAM_URL));
48 $author = '';
49 if (isset($info->owner)) {
50 $author = s(clean_param($info->owner, PARAM_NOTAGS));
53 $license = '';
54 if (isset($info->license)) {
55 $license = s(clean_param($info->license, PARAM_ALPHAEXT));
58 $source = base64_encode(serialize((object)array('url'=>$url,'filename'=>$filename)));
60 $js =<<<EOD
61 <html>
62 <head>
63 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
64 <script type="text/javascript">
65 window.onload = function() {
66 var resource = {};
67 resource.title = "$filename";
68 resource.source = "$source";
69 resource.thumbnail = '$thumbnail';
70 resource.author = "$author";
71 resource.license = "$license";
72 parent.M.core_filepicker.select_file(resource);
74 </script>
75 </head>
76 <body><noscript></noscript></body>
77 </html>
78 EOD;
80 header('Content-Type: text/html; charset=utf-8');
81 die($js);