[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/repository/equella/ -> callback.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1