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 /** 18 * Callback for equella repository. 19 * 20 * @since Moodle 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 24 */ 25 require(__DIR__.'/../../config.php'); 26 require_once($CFG->dirroot . '/repository/lib.php'); 27 28 $json = required_param('tlelinks', PARAM_RAW); 29 30 require_login(); 31 32 $decodedinfo = json_decode($json); 33 $info = array_pop($decodedinfo); 34 35 $url = ''; 36 if (isset($info->url)) { 37 $url = s(clean_param($info->url, PARAM_URL)); 38 } 39 40 $filename = ''; 41 // Use $info->filename if exists, $info->name is a display name, 42 // it may not have extension 43 if (isset($info->filename)) { 44 $filename = s(clean_param($info->filename, PARAM_FILE)); 45 } else if (isset($info->name)) { 46 $filename = s(clean_param($info->name, PARAM_FILE)); 47 } 48 49 $thumbnail = ''; 50 if (isset($info->thumbnail)) { 51 $thumbnail = s(clean_param($info->thumbnail, PARAM_URL)); 52 } 53 54 $author = ''; 55 if (isset($info->owner)) { 56 $author = s(clean_param($info->owner, PARAM_NOTAGS)); 57 } 58 59 $license = ''; 60 if (isset($info->license)) { 61 $license = s(clean_param($info->license, PARAM_ALPHAEXT)); 62 } 63 64 $source = base64_encode(json_encode(array('url'=>$url,'filename'=>$filename))); 65 $sourcekey = sha1($source . repository::get_secret_key() . sesskey()); 66 67 $js =<<<EOD 68 <html> 69 <head> 70 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 71 <script type="text/javascript"> 72 window.onload = function() { 73 var resource = {}; 74 resource.title = "$filename"; 75 resource.source = "$source"; 76 resource.sourcekey = "$sourcekey"; 77 resource.thumbnail = '$thumbnail'; 78 resource.author = "$author"; 79 resource.license = "$license"; 80 parent.M.core_filepicker.select_file(resource); 81 } 82 </script> 83 </head> 84 <body><noscript></noscript></body> 85 </html> 86 EOD; 87 88 header('Content-Type: text/html; charset=utf-8'); 89 die($js);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body