"MDL-22217, browse/download user_backup area"

This commit is contained in:
Dongsheng Cai
2010-05-02 09:50:02 +00:00
parent 1386bc0905
commit 3d65f92d1d
4 changed files with 47 additions and 1 deletions

View File

@@ -30,11 +30,13 @@ $string['add'] = 'Add';
$string['addfile'] = 'Add...';
$string['addplugin'] = 'Add a repository plugin';
$string['allowexternallinks'] = 'Allow external links';
$string['areabackup'] = 'Backups';
$string['coursebackup'] = 'Course Backups';
$string['sectionbackup'] = 'Section Backups';
$string['areacategoryintro'] = 'Category introduction';
$string['areacourseintro'] = 'Course introduction';
$string['arearoot'] = 'System';
$string['areauserdraft'] = 'Drafts';
$string['areauserbackup'] = 'User backup';
$string['areauserpersonal'] = 'Personal';
$string['areauserprofile'] = 'Profile';
$string['attachedfiles'] = 'Attached files';

View File

@@ -229,6 +229,35 @@ class file_browser {
return new file_info_stored($this, $context, $storedfile, $urlbase, get_string('areauserdraft', 'repository'), true, true, true, true);
}
private function get_file_info_user_backup($user, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
global $USER, $CFG;
$fs = get_file_storage();
// only current user can access this area
if ($context->instanceid != $USER->id) {
return null;
}
if ($USER->id != $user->id) {
return null;
}
$urlbase = $CFG->wwwroot.'/userfile.php';
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!$storedfile = $fs->get_file($context->id, $filearea, $itemid, $filepath, $filename)) {
if ($filepath === '/' and $filename === '.') {
$storedfile = new virtual_root_file($context->id, $filearea, 0);
} else {
// not found
return null;
}
}
return new file_info_stored($this, $context, $storedfile, $urlbase, get_string('areauserbackup', 'repository'), false, true, true, false);
}
private function get_file_info_coursecat($context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
global $DB, $CFG;

View File

@@ -101,6 +101,10 @@ class file_info_user extends file_info {
$children[] = $child;
}
if ($child = $this->browser->get_file_info(get_context_instance(CONTEXT_USER, $USER->id), 'user_backup', 0)) {
$children[] = $child;
}
// do not list user_draft here - it is browsable only if you know the draft itemid ;-)
return $children;

View File

@@ -90,6 +90,17 @@ switch ($filearea) {
$itemid = 0;
$forcedownload = true;
break;
case 'user_backup':
require_login();
if (isguestuser()) {
send_file_not_found();
}
if ($USER->id != $userid) {
send_file_not_found();
}
$itemid = (int)array_shift($args);
$forcedownload = true;
break;
default:
send_file_not_found();