mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-32117 EQUELLA plugin: Fixed file downloading redirect issue
This commit is contained in:
parent
9225747e11
commit
36f8060a6b
@ -32,7 +32,7 @@ class repository_equella extends repository {
|
|||||||
|
|
||||||
if (isset($this->options['mimetypes'])) {
|
if (isset($this->options['mimetypes'])) {
|
||||||
$mt = $this->options['mimetypes'];
|
$mt = $this->options['mimetypes'];
|
||||||
if (!empty($mt) && !in_array('*', $mt)) {
|
if (!empty($mt) && is_array($mt) && !in_array('*', $mt)) {
|
||||||
$this->mimetypes = array_unique(array_map(array($this, 'toMimeType'), $mt));
|
$this->mimetypes = array_unique(array_map(array($this, 'toMimeType'), $mt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ class repository_equella extends repository {
|
|||||||
*/
|
*/
|
||||||
public function get_listing($path = null, $page = null) {
|
public function get_listing($path = null, $page = null) {
|
||||||
global $CFG, $COURSE;
|
global $CFG, $COURSE;
|
||||||
$callbackurl = $CFG->wwwroot . '/repository/equella/callback.php?repo_id=' . $this->id;
|
$callbackurl = new moodle_url('/repository/equella/callback.php', array('repo_id'=>$this->id));
|
||||||
|
|
||||||
$mimetypesstr = '';
|
$mimetypesstr = '';
|
||||||
$restrict = '';
|
$restrict = '';
|
||||||
@ -102,6 +102,29 @@ class repository_equella extends repository {
|
|||||||
return base64_encode($source);
|
return base64_encode($source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download a file, this function can be overridden by subclass. {@link curl}
|
||||||
|
*
|
||||||
|
* @param string $url the url of file
|
||||||
|
* @param string $filename save location
|
||||||
|
* @return string the location of the file
|
||||||
|
*/
|
||||||
|
public function get_file($url, $filename = '') {
|
||||||
|
global $CFG, $USER;
|
||||||
|
$cookiename = uniqid('', true) . '.cookie';
|
||||||
|
$dir = make_temp_directory('repository/equella/' . $USER->id);
|
||||||
|
$cookiepathname = $dir . '/' . $cookiename;
|
||||||
|
$path = $this->prepare_file($filename);
|
||||||
|
$fp = fopen($path, 'w');
|
||||||
|
$c = new curl(array('cookie'=>$cookiepathname));
|
||||||
|
$c->download(array(array('url'=>$url, 'file'=>$fp)), array('CURLOPT_FOLLOWLOCATION'=>true));
|
||||||
|
// Close file handler.
|
||||||
|
fclose($fp);
|
||||||
|
// delete cookie jar
|
||||||
|
unlink($cookiepathname);
|
||||||
|
return array('path'=>$path, 'url'=>$url);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file from external repository by reference
|
* Get file from external repository by reference
|
||||||
* {@link repository::get_file_reference()}
|
* {@link repository::get_file_reference()}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user