"MDL-13766, improve repository module to support file manager and disable draft plugin in filemanager"

This commit is contained in:
dongsheng
2009-09-03 03:37:55 +00:00
parent 5f9087f3b2
commit a560785fae
5 changed files with 46 additions and 38 deletions
+17 -3
View File
@@ -31,7 +31,7 @@ class repository_draft extends repository {
* @param string $path not used by this plugin
* @return mixed
*/
public function get_listing($path = '', $page = '') {
public function get_listing($path = '/', $page = '') {
global $CFG, $USER, $itemid, $OUTPUT;
$ret = array();
$ret['dynload'] = true;
@@ -39,10 +39,13 @@ class repository_draft extends repository {
$ret['nologin'] = true;
$ret['draftfiles'] = true;
$list = array();
if (empty($path)) {
$path = '/';
}
$fs = get_file_storage();
$context = get_context_instance(CONTEXT_USER, $USER->id);
$files = $fs->get_area_files($context->id, 'user_draft', $itemid);
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
$files = $fs->get_directory_files($user_context->id, 'user_draft', $itemid, $path, false);
foreach ($files as $file) {
if ($file->get_filename()!='.') {
$node = array(
@@ -53,6 +56,17 @@ class repository_draft extends repository {
'thumbnail' => $OUTPUT->old_icon_url('f/text-32')
);
$list[] = $node;
} else {
$foldername = explode('/', trim($file->get_filepath(), '/'));
$foldername = trim(array_pop($foldername), '/');
$node = array(
'title' => $foldername,
'size' => 0,
'date' => '',
'children' => array(),
'thumbnail' => $OUTPUT->old_icon_url('f/folder-32')
);
$list[] = $node;
}
}
$ret['list'] = $list;
+11 -13
View File
@@ -1116,7 +1116,7 @@ abstract class repository {
* reused by sub class
* @param string filename
*/
public function prepare_file($file) {
public function prepare_file($filename) {
global $CFG;
if (!file_exists($CFG->dataroot.'/temp/download')) {
mkdir($CFG->dataroot.'/temp/download/', 0777, true);
@@ -1124,13 +1124,13 @@ abstract class repository {
if (is_dir($CFG->dataroot.'/temp/download')) {
$dir = $CFG->dataroot.'/temp/download/';
}
if (empty($file)) {
$file = uniqid('repo').'_'.time().'.tmp';
if (empty($filename)) {
$filename = uniqid('repo').'_'.time().'.tmp';
}
if (file_exists($dir.$file)) {
$file = uniqid('m').$file;
if (file_exists($dir.$filename)) {
$filename = uniqid('m').$filename;
}
return $dir.$file;
return $dir.$filename;
}
/**
@@ -1139,19 +1139,17 @@ abstract class repository {
*
* @global object $CFG
* @param string $url the url of file
* @param string $file save location
* @param string $filename save location
* @return string the location of the file
* @see curl package
*/
public function get_file($url, $file = '') {
public function get_file($url, $filename = '') {
global $CFG;
$path = $this->prepare_file($file);
$path = $this->prepare_file($filename);
$fp = fopen($path, 'w');
$c = new curl;
$c->download(array(
array('url'=>$url, 'file'=>$fp)
));
$c->download(array(array('url'=>$url, 'file'=>$fp)));
return $path;
}
@@ -1486,7 +1484,7 @@ abstract class repository {
* Show the search screen, if required
* @return null
*/
public function print_search($client_id) {
public function print_search() {
$str = '';
$str .= '<input type="hidden" name="repo_id" value="'.$this->id.'" />';
$str .= '<input type="hidden" name="ctx_id" value="'.$this->context->id.'" />';
File diff suppressed because one or more lines are too long
+3
View File
@@ -188,6 +188,9 @@ var repository_client = (function(){
}else{
support = true;
}
if (repo.type=='draft' && this.env == 'filemanager') {
continue;
}
if(repo.supported_types == '*' || support){
var li = document.createElement('li');
li.id = 'repo-'+this.client_id+'-'+repo.id;
+14 -21
View File
@@ -11,14 +11,14 @@
$action = optional_param('action', '', PARAM_ALPHA);
$callback = optional_param('callback', '', PARAM_CLEANHTML);
$client_id = optional_param('client_id', SITEID, PARAM_RAW); // client ID
$contextid = optional_param('ctx_id', SITEID, 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
$title = optional_param('title', '', PARAM_FILE); // new file name
$contextid = optional_param('ctx_id', SITEID, 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
$title = optional_param('title', '', PARAM_FILE); // new file name
$itemid = optional_param('itemid', '', PARAM_INT);
$page = optional_param('page', '', PARAM_RAW); // page
$repo_id = optional_param('repo_id', 1, PARAM_INT); // repository ID
$req_path = optional_param('p', '', PARAM_RAW); // path
$page = optional_param('page', '', PARAM_RAW); // page
$repo_id = optional_param('repo_id', 1, PARAM_INT); // repository ID
$req_path = optional_param('p', '', PARAM_RAW); // path
$save_path = optional_param('savepath', '/', PARAM_PATH);
$search_text = optional_param('s', '', PARAM_CLEANHTML);
@@ -200,7 +200,10 @@ EOD;
break;
case 'download':
try {
$filepath = $repo->get_file($file, $title, $itemid);
// $file is the specific information of file, such as url, or meta information
// $title is the file name in file pool
// $itemid and $save_path will be used by local plugin only
$filepath = $repo->get_file($file, $title, $itemid, $save_path);
if ($filepath === false) {
$err->e = get_string('cannotdownload', 'repository');
die(json_encode($err));
@@ -218,21 +221,11 @@ EOD;
$info['url'] = $CFG->httpswwwroot.'/draftfile.php/'.$fileinfo['contextid'].'/user_draft/'.$itemid.'/'.$fileinfo['title'];
echo json_encode($info);
} else if (preg_match('#(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)#', $filepath)) {
// youtube plugin return a url instead a file path
// process external link
$url = $filepath;
echo json_encode(array(
/* File picker need to know this is a link
* in order to attach title to url
*/
'type'=>'link',
'client_id'=>$client_id,
'url'=>$url,
'id'=>$url,
'file'=>$url
)
);
echo json_encode(array('type'=>'link', 'client_id'=>$client_id, 'url'=>$url, 'id'=>$url, 'file'=>$url));
} else {
// normal file path name
// move downloaded file to file pool
$info = repository::move_to_filepool($filepath, $title, $itemid, $save_path);
$info['client_id'] = $client_id;
echo json_encode($info);