$fp = fopen($path, 'w');
$c = new curl;
$c->download(array(array('url'=>$url, 'file'=>$fp)));
- return $path;
+ return array($path, $url);
}
public function print_search($client_id) {
var repository_id = this.active_repo.id;
var title = Y.one('#newname-'+client_id).get('value');
var filesource = Y.one('#filesource-'+client_id).get('value');
- var params = {'title':title, 'file':filesource, 'savepath': this.options.savepath};
+ var params = {'title':title, 'source':filesource, 'savepath': this.options.savepath};
if (this.options.env == 'editor') {
var linkexternal = Y.one('#linkexternal-'+client_id).get('checked');
break;
case 'download':
- $filepath = $repo->get_file($fileurl, $filename, $itemid);
- if (!empty($filepath)) {
- if (!is_array($filepath)) {
- $info = repository::move_to_filepool($filepath, $filename, $itemid, $draftpath);
+ $thefile = $repo->get_file($fileurl, $filename, $itemid);
+ if (!empty($thefile)) {
+ if (!is_array($thefile)) {
+ $record = new stdclass;
+ $record->filepath = $draftpath;
+ $record->filename = $filename;
+ $record->filearea = 'user_draft';
+ $record->itemid = $itemid;
+ $record->license = '';
+ $record->author = '';
+ $record->source = $fileurl;
+ $info = repository::move_to_filepool($thefile, $record);
}
redirect($url, get_string('downloadsucc','repository'));
} else {
// this is a hack to prevent move_to_file deleteing files
// in local repository
$CFG->repository_no_delete = true;
- return $file;
+ return array($file, '');
}
public function logout() {
$c->download(array(
array('url'=>$url, 'file'=>$fp)
));
- return $path;
+ return array($path, $url);
}
/**
unlink($path);
$path = $newpath;
}
- return $path;
+ return array($path, $url);
}
/**
$gdocs = new google_docs(new google_authsub($this->subauthtoken));
$gdocs->download_file($url, $fp);
- return $path;
+ return array($path, $url);
}
public function supported_filetypes() {
* id
* url
*/
- public static function move_to_filepool($thefile, $name, $itemid, $filepath = '/', $filearea = 'user_draft') {
+ public static function move_to_filepool($thefile, $record) {
global $DB, $CFG, $USER, $OUTPUT;
- if ($filepath !== '/') {
- $filepath = trim($filepath, '/');
- $filepath = '/'.$filepath.'/';
+ if ($record->filepath !== '/') {
+ $record->filepath = trim($record->filepath, '/');
+ $record->filepath = '/'.$record->filepath.'/';
}
$context = get_context_instance(CONTEXT_USER, $USER->id);
$now = time();
- $entry = new object();
- $entry->filearea = $filearea;
- $entry->contextid = $context->id;
- $entry->filename = $name;
- $entry->filepath = $filepath;
- $entry->timecreated = $now;
- $entry->timemodified = $now;
- $entry->userid = $USER->id;
- $entry->mimetype = mimeinfo('type', $thefile);
- if(is_numeric($itemid)) {
- $entry->itemid = $itemid;
- } else {
- $entry->itemid = 0;
+
+ $record->contextid = $context->id;
+ $record->timecreated = $now;
+ $record->timemodified = $now;
+ $record->userid = $USER->id;
+ $record->mimetype = mimeinfo('type', $thefile);
+ if(!is_numeric($record->itemid)) {
+ $record->itemid = 0;
}
$fs = get_file_storage();
$browser = get_file_browser();
- if ($existingfile = $fs->get_file($context->id, $filearea, $itemid, $filepath, $name)) {
+ if ($existingfile = $fs->get_file($context->id, $record->filearea, $record->itemid, $record->filepath, $record->filename)) {
$existingfile->delete();
}
- if ($file = $fs->create_file_from_pathname($entry, $thefile)) {
+ if ($file = $fs->create_file_from_pathname($record, $thefile)) {
if (empty($CFG->repository_no_delete)) {
$delete = unlink($thefile);
unset($CFG->repository_no_delete);
$fp = fopen($path, 'w');
$c = new curl;
$c->download(array(array('url'=>$url, 'file'=>$fp)));
- return $path;
+ return array($path, $url);
}
/**
fwrite($fp,$content);
fclose($fp);
- return $path;
+ return array($path, '');
}
fwrite($fp,$content);
fclose($fp);
- return $path;
+ return array($path, '');
}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-require_once('../config.php');
-require_once('../lib/filelib.php');
-require_once('lib.php');
+require_once(dirname(dirname(__FILE__)).'/config.php');
+require_once(dirname(dirname(__FILE__)).'/lib/filelib.php');
+require_once(dirname(__FILE__).'/lib.php');
require_login();
$client_id = optional_param('client_id', '', PARAM_RAW); // client ID
$contextid = optional_param('ctx_id', SYSCONTEXTID, PARAM_INT); // context ID
$env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in editor or moodleform
-$file = optional_param('file', '', PARAM_RAW); // file to download
+$source = optional_param('source', '', PARAM_RAW); // file to download
$itemid = optional_param('itemid', 0, PARAM_INT);
-$title = optional_param('title', '', PARAM_FILE); // new file name
$page = optional_param('page', '', PARAM_RAW); // page
$maxbytes = optional_param('maxbytes', -1, PARAM_INT);
$req_path = optional_param('p', '', PARAM_RAW); // path
-$save_path = optional_param('savepath', '/', PARAM_PATH);
-$save_filearea = optional_param('filearea', 'user_draft', PARAM_TEXT);
+$saveas_filearea = optional_param('filearea', 'user_draft', PARAM_TEXT);
+$saveas_filename = optional_param('title', '', PARAM_FILE); // new file name
+$saveas_path = optional_param('saveaspath', '/', PARAM_PATH);
$search_text = optional_param('s', '', PARAM_CLEANHTML);
$linkexternal = optional_param('linkexternal', '', PARAM_ALPHA);
try {
// we have two special repoisitory type need to deal with
if ($repo->options['type'] == 'local') {
- $fileinfo = $repo->move_to_draft($file, $title, $itemid, $save_path);
+ $fileinfo = $repo->move_to_draft($source, $saveas_filename, $itemid, $saveas_path);
$info = array();
$info['client_id'] = $client_id;
$info['file'] = $fileinfo['title'];
if ($allowexternallink and $linkexternal === 'yes' and ($repo->supported_returntypes() || FILE_EXTERNAL)) {
try {
- $link = $repo->get_link($file);
+ $link = $repo->get_link($source);
} catch (repository_exception $e){
}
$info = array();
- $info['filename'] = $title;
+ $info['filename'] = $saveas_filename;
$info['type'] = 'link';
$info['url'] = $link;
die(json_encode($info));
}
// get the file location
- $filepath = $repo->get_file($file, $title, $itemid, $save_path);
- if ($filepath === false) {
+ list($thefile, $url) = $repo->get_file($source, $saveas_filename);
+ if ($thefile === false) {
$err->e = get_string('cannotdownload', 'repository');
die(json_encode($err));
}
- if (($maxbytes!==-1) && (filesize($filepath) > $maxbytes)) {
+ if (($maxbytes!==-1) && (filesize($thefile) > $maxbytes)) {
throw new file_exception('maxbytes');
}
- $info = repository::move_to_filepool($filepath, $title, $itemid, $save_path, $save_filearea);
+
+ $record = new stdclass;
+ $record->filepath = $saveas_path;
+ $record->filename = $saveas_filename;
+ $record->filearea = $saveas_filearea;
+ $record->itemid = $itemid;
+ $record->license = '';
+ $record->author = '';
+ $record->source = $url;
+
+ $info = repository::move_to_filepool($thefile, $record);
if (empty($info)) {
$info['e'] = get_string('error', 'moodle');
}
$filename = $arr[1];
$path = $this->prepare_file($file);
$this->s->getObject($bucket, $filename, $path);
- return $path;
+ return array($path, '');
}
/**
$fp = fopen($path, 'w');
$c = new curl;
$c->download(array(array('url'=>$url, 'file'=>$fp)));
- return $path;
+ return array($path, $url);
}
public function check_login() {
$this->wd->get($url, $buffer);
$fp = fopen($path, 'wb');
fwrite($fp, $buffer);
- return $path;
+ return array($path, '');
}
public function global_search() {
return false;