diff --git a/repository/equella/callback.php b/repository/equella/callback.php index 63fc07654a2..c5867edfe10 100644 --- a/repository/equella/callback.php +++ b/repository/equella/callback.php @@ -28,9 +28,9 @@ require_login(); $json = required_param('tlelinks', PARAM_RAW); $info = array_pop(json_decode($json)); -$reference = clean_param($info->url, PARAM_URL); -$thumbnail = clean_param($info->thumbnail, PARAM_RAW); -$filename = basename($reference); +$url = clean_param($info->url, PARAM_URL); +$thumbnail = clean_param($info->thumbnail, PARAM_URL); +$filename = clean_param($info->name, PARAM_FILE); $js =<< @@ -39,7 +39,7 @@ $js =<<reference); + $url = $this->appendtoken($ref); + + // we use this cache to get the correct file size + $cachedfilepath = cache_file::get($url, array('ttl' => 0)); + if ($cachedfilepath === false) { + // Cache the file. + $path = $this->get_file($url); + $cachedfilepath = cache_file::create_from_file($url, $path['path']); + } + + $fileinfo = new stdClass; + $fileinfo->filepath = $cachedfilepath; + + return $fileinfo; + } + /** * Send equella file to browser * * @param stored_file $stored_file */ public function send_file($stored_file) { - $resourceurl = base64_decode($stored_file->get_reference()); - $url = $this->appendtoken($resourceurl); + $reference = base64_decode($stored_file->get_reference()); + $url = $this->appendtoken($reference); header('Location: ' . $url); }