PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/repository/equella/callback.php

https://github.com/raymanuk/moodle
PHP | 81 lines | 48 code | 11 blank | 22 comment | 5 complexity | 1adfa3d556fc2045a05bd5c73bd126cc MD5 | raw file
  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. * Callback for equella repository.
  18. *
  19. * @since Moodle 2.3
  20. * @package repository_equella
  21. * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
  25. $json = required_param('tlelinks', PARAM_RAW);
  26. require_login();
  27. $decodedinfo = json_decode($json);
  28. $info = array_pop($decodedinfo);
  29. $url = '';
  30. if (isset($info->url)) {
  31. $url = s(clean_param($info->url, PARAM_URL));
  32. }
  33. $filename = '';
  34. if (isset($info->name)) {
  35. $filename = s(clean_param($info->name, PARAM_FILE));
  36. }
  37. $thumbnail = '';
  38. if (isset($info->thumbnail)) {
  39. $thumbnail = s(clean_param($info->thumbnail, PARAM_URL));
  40. }
  41. $author = '';
  42. if (isset($info->owner)) {
  43. $author = s(clean_param($info->owner, PARAM_NOTAGS));
  44. }
  45. $license = '';
  46. if (isset($info->license)) {
  47. $license = s(clean_param($info->license, PARAM_ALPHAEXT));
  48. }
  49. $source = base64_encode(json_encode(array('url'=>$url,'filename'=>$filename)));
  50. $js =<<<EOD
  51. <html>
  52. <head>
  53. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  54. <script type="text/javascript">
  55. window.onload = function() {
  56. var resource = {};
  57. resource.title = "$filename";
  58. resource.source = "$source";
  59. resource.thumbnail = '$thumbnail';
  60. resource.author = "$author";
  61. resource.license = "$license";
  62. parent.M.core_filepicker.select_file(resource);
  63. }
  64. </script>
  65. </head>
  66. <body><noscript></noscript></body>
  67. </html>
  68. EOD;
  69. header('Content-Type: text/html; charset=utf-8');
  70. die($js);