MDL-32117 EQUELLA plugin: Fixed callback parameters

This commit is contained in:
Dongsheng Cai 2012-05-18 11:48:45 +08:00 committed by Dan Poltawski
parent 7283bb95ae
commit 9225747e11
2 changed files with 32 additions and 6 deletions

View file

@ -28,9 +28,9 @@ require_login();
$json = required_param('tlelinks', PARAM_RAW); $json = required_param('tlelinks', PARAM_RAW);
$info = array_pop(json_decode($json)); $info = array_pop(json_decode($json));
$reference = clean_param($info->url, PARAM_URL); $url = clean_param($info->url, PARAM_URL);
$thumbnail = clean_param($info->thumbnail, PARAM_RAW); $thumbnail = clean_param($info->thumbnail, PARAM_URL);
$filename = basename($reference); $filename = clean_param($info->name, PARAM_FILE);
$js =<<<EOD $js =<<<EOD
<html> <html>
@ -39,7 +39,7 @@ $js =<<<EOD
window.onload = function() { window.onload = function() {
var resource = {}; var resource = {};
resource.title = "$filename"; resource.title = "$filename";
resource.reference = "$reference"; resource.source = "$url";
resource.thumbnail = '$thumbnail'; resource.thumbnail = '$thumbnail';
parent.M.core_filepicker.select_file(resource); parent.M.core_filepicker.select_file(resource);
} }

View file

@ -102,14 +102,40 @@ class repository_equella extends repository {
return base64_encode($source); return base64_encode($source);
} }
/**
* Get file from external repository by reference
* {@link repository::get_file_reference()}
* {@link repository::get_file()}
*
* @param stdClass $reference file reference db record
* @return stdClass|null|false
*/
public function get_file_by_reference($reference) {
$ref = base64_decode($reference->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 * Send equella file to browser
* *
* @param stored_file $stored_file * @param stored_file $stored_file
*/ */
public function send_file($stored_file) { public function send_file($stored_file) {
$resourceurl = base64_decode($stored_file->get_reference()); $reference = base64_decode($stored_file->get_reference());
$url = $this->appendtoken($resourceurl); $url = $this->appendtoken($reference);
header('Location: ' . $url); header('Location: ' . $url);
} }