mirror of
https://github.com/moodle/moodle.git
synced 2025-07-25 00:02:18 +02:00
"MDL-22217, browse/download user_backup area"
This commit is contained in:
@@ -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';
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
|
11
userfile.php
11
userfile.php
@@ -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();
|
||||
|
Reference in New Issue
Block a user