mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-22950 adding new component column to the files table, unfortunately this change requires changes in all 2.0dev code, please review all custom code that was already upgraded to 2.0; fixing multiple problems and regressions in mod/assignment
This commit is contained in:
parent
ffc3f866d5
commit
64f93798d4
@ -103,24 +103,26 @@ function bloglevelupgrade_entries($blogentries, $forum, $cm, $groupid=-1) {
|
||||
|
||||
// Copy file attachment records
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($sitecontext->id, 'blog_attachment', $blogentry->id);
|
||||
$files = $fs->get_area_files($sitecontext->id, 'blog', 'attachment', $blogentry->id);
|
||||
|
||||
if (!empty($files)) {
|
||||
foreach ($files as $storedfile) {
|
||||
$newfile = new object();
|
||||
$newfile->filearea = 'forum_attachment';
|
||||
$newfile->component = 'mod_forum';
|
||||
$newfile->filearea = 'attachment';
|
||||
$newfile->itemid = $discussion->firstpost;
|
||||
$newfile->contextid = $forumcontext->id;
|
||||
$fs->create_file_from_storedfile($newfile, $storedfile->get_id());
|
||||
}
|
||||
}
|
||||
|
||||
$files = $fs->get_area_files($sitecontext->id, 'blog_post', $blogentry->id);
|
||||
$files = $fs->get_area_files($sitecontext->id, 'blog', 'post', $blogentry->id);
|
||||
|
||||
if (!empty($files)) {
|
||||
foreach ($files as $storedfile) {
|
||||
$newfile = new object();
|
||||
$newfile->filearea = 'forum_post';
|
||||
$newfile->component = 'mod_forum';
|
||||
$newfile->filearea = 'post';
|
||||
$newfile->itemid = $discussion->firstpost;
|
||||
$newfile->contextid = $forumcontext->id;
|
||||
$fs->create_file_from_storedfile($newfile, $storedfile->get_id());
|
||||
|
@ -26,8 +26,7 @@ if (has_capability('moodle/grade:manage', $systemcontext)
|
||||
// new CFG variable for gradebook (what roles to display)
|
||||
$temp->add(new admin_setting_special_gradebookroles());
|
||||
|
||||
// enable outcomes checkbox
|
||||
$temp->add(new admin_setting_configcheckbox('enableoutcomes', get_string('enableoutcomes', 'grades'), get_string('enableoutcomes_help', 'grades'), 0));
|
||||
// enable outcomes checkbox now in subsystems area
|
||||
|
||||
$temp->add(new admin_setting_grade_profilereport());
|
||||
|
||||
|
@ -76,7 +76,7 @@
|
||||
//Print final message
|
||||
echo $OUTPUT->box(get_string("backupfinished"));
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
echo $OUTPUT->continue_button("$CFG->wwwroot/files/index.php?contextid=".$context->id."&filearea=course_backup&itemid=0");
|
||||
echo $OUTPUT->continue_button("$CFG->wwwroot/files/index.php?contextid=".$context->id."&component=backup&filearea=course&itemid=0");
|
||||
} else {
|
||||
echo $OUTPUT->box(get_string('importdataexported'));
|
||||
if (!empty($preferences->backup_destination)) {
|
||||
|
@ -2637,7 +2637,7 @@
|
||||
//Define zip destination (course dir)
|
||||
$context = get_context_instance(CONTEXT_COURSE, $preferences->backup_course);
|
||||
$fs = get_file_storage();
|
||||
$file_record = array('contextid'=>$context->id, 'filearea'=>'course_backup',
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'backup', 'filearea'=>'course',
|
||||
'itemid'=>0, 'filepath'=>'/', 'filename'=>$preferences->backup_name,
|
||||
'timecreated'=>time(), 'timemodified'=>time());
|
||||
$fs->create_file_from_pathname($file_record, $from_zip_file);
|
||||
|
@ -232,7 +232,7 @@ class backup_section_structure_step extends backup_structure_step {
|
||||
$section->set_source_alias('section', 'number');
|
||||
|
||||
// Set annotations
|
||||
$section->annotate_files(array('course_section'), 'id');
|
||||
$section->annotate_files('course', 'section', 'id');
|
||||
|
||||
return $section;
|
||||
}
|
||||
@ -311,7 +311,8 @@ class backup_course_structure_step extends backup_structure_step {
|
||||
|
||||
$course->annotate_ids('grouping', 'defaultgroupingid');
|
||||
|
||||
$course->annotate_files(array('course_summary', 'course_content'), null);
|
||||
$course->annotate_files('course', 'summary', null);
|
||||
$course->annotate_files('course', 'legacy', null);
|
||||
|
||||
// Return root element ($course)
|
||||
|
||||
@ -656,8 +657,9 @@ class backup_groups_structure_step extends backup_structure_step {
|
||||
|
||||
// Define file annotations
|
||||
|
||||
// TODO: Change "course_group_image" file area to the one finally used for group images
|
||||
$group->annotate_files(array('course_group_description', 'course_group_image'), 'id');
|
||||
//TODO: not implemented yet
|
||||
$group->annotate_files('group', 'description', 'id');
|
||||
$group->annotate_files('group', 'image', 'id');
|
||||
|
||||
// Return the root element (groups)
|
||||
return $groups;
|
||||
@ -980,7 +982,7 @@ class backup_final_files_structure_step extends backup_structure_step {
|
||||
$files = new backup_nested_element('files');
|
||||
|
||||
$file = new file_nested_element('file', array('id'), array(
|
||||
'contenthash', 'contextid', 'filearea', 'itemid',
|
||||
'contenthash', 'contextid', 'component', 'filearea', 'itemid',
|
||||
'filepath', 'filename', 'userid', 'filesize',
|
||||
'mimetype', 'status', 'timecreated', 'timemodified',
|
||||
'source', 'author', 'license', 'sortorder'));
|
||||
@ -1238,9 +1240,8 @@ class backup_annotate_all_user_files extends backup_execution_step {
|
||||
global $DB;
|
||||
|
||||
// List of fileareas we are going to annotate
|
||||
// TODO: Change "user_image" file area to the one finally used for user images
|
||||
$fileareas = array(
|
||||
'user_private', 'user_profile', 'user_image');
|
||||
// TODO: user image not implemented yet
|
||||
$fileareas = array('private', 'profile', 'image');
|
||||
|
||||
// Fetch all annotated (final) users
|
||||
$rs = $DB->get_recordset('backup_ids_temp', array(
|
||||
@ -1252,7 +1253,7 @@ class backup_annotate_all_user_files extends backup_execution_step {
|
||||
foreach ($fileareas as $filearea) {
|
||||
// We don't need to specify itemid ($userid - 4th param) as far as by
|
||||
// context we can get all the associated files. See MDL-22092
|
||||
backup_structure_dbops::annotate_files($this->get_backupid(), $userctxid, $filearea, null);
|
||||
backup_structure_dbops::annotate_files($this->get_backupid(), $userctxid, 'user', $filearea, null);
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
@ -103,13 +103,14 @@ abstract class backup_structure_dbops extends backup_dbops {
|
||||
}
|
||||
}
|
||||
|
||||
public static function annotate_files($backupid, $contextid, $filearea, $itemid) {
|
||||
public static function annotate_files($backupid, $contextid, $component, $filearea, $itemid) {
|
||||
global $DB;
|
||||
$sql = 'SELECT id
|
||||
FROM {files}
|
||||
WHERE contextid = ?
|
||||
AND component = ?
|
||||
AND filearea = ?';
|
||||
$params = array($contextid, $filearea);
|
||||
$params = array($contextid, $component, $filearea);
|
||||
|
||||
if (!is_null($itemid)) { // Add itemid to query and params if necessary
|
||||
$sql .= ' AND itemid = ?';
|
||||
|
@ -182,7 +182,7 @@ abstract class backup_helper {
|
||||
|
||||
// Extract useful information to decide
|
||||
$hasusers = (bool)$sinfo['users']->value; // Backup has users
|
||||
$isannon = (bool)$sinfo['anonymize']->value; // Backup is annonymzed
|
||||
$isannon = (bool)$sinfo['anonymize']->value; // Backup is anonymised
|
||||
$filename = $sinfo['filename']->value; // Backup filename
|
||||
$backupmode= $dinfo[0]->mode; // Backup mode backup::MODE_GENERAL/IMPORT/HUB
|
||||
$backuptype= $dinfo[0]->type; // Backup type backup::TYPE_1ACTIVITY/SECTION/COURSE
|
||||
@ -203,24 +203,28 @@ abstract class backup_helper {
|
||||
}
|
||||
|
||||
// Calculate file storage options of id being backup
|
||||
$ctxid = 0;
|
||||
$filearea = '';
|
||||
$itemid = 0;
|
||||
$ctxid = 0;
|
||||
$filearea = '';
|
||||
$component = '';
|
||||
$itemid = 0;
|
||||
switch ($backuptype) {
|
||||
case backup::TYPE_1ACTIVITY:
|
||||
$ctxid = get_context_instance(CONTEXT_MODULE, $id)->id;
|
||||
$filearea = 'activity_backup';
|
||||
$itemid = 0;
|
||||
$ctxid = get_context_instance(CONTEXT_MODULE, $id)->id;
|
||||
$component = 'backup';
|
||||
$filearea = 'activity';
|
||||
$itemid = 0;
|
||||
break;
|
||||
case backup::TYPE_1SECTION:
|
||||
$ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
|
||||
$filearea = 'section_backup';
|
||||
$itemid = $id;
|
||||
$ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
|
||||
$component = 'backup';
|
||||
$filearea = 'section';
|
||||
$itemid = $id;
|
||||
break;
|
||||
case backup::TYPE_1COURSE:
|
||||
$ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
|
||||
$filearea = 'course_backup';
|
||||
$itemid = 0;
|
||||
$ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
|
||||
$component = 'backup';
|
||||
$filearea = 'course';
|
||||
$itemid = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -228,25 +232,28 @@ abstract class backup_helper {
|
||||
// are sent to user's "user_tohub" file area. The upload process
|
||||
// will be responsible for cleaning that filearea once finished
|
||||
if ($backupmode == backup::MODE_HUB) {
|
||||
$ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
|
||||
$filearea = 'user_tohub';
|
||||
$itemid = 0;
|
||||
$ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
|
||||
$component = 'user';
|
||||
$filearea = 'tohub';
|
||||
$itemid = 0;
|
||||
}
|
||||
|
||||
// Backups without user info or withe the anoymise functionality
|
||||
// Backups without user info or with the anonymise functionality
|
||||
// enabled are sent to user's "user_backup"
|
||||
// file area. Maintenance of such area is responsibility of
|
||||
// the user via corresponding file manager frontend
|
||||
if ($backupmode == backup::MODE_GENERAL && (!$hasusers || $isannon)) {
|
||||
$ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
|
||||
$filearea = 'user_backup';
|
||||
$itemid = 0;
|
||||
$ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
|
||||
$component = 'user';
|
||||
$filearea = 'backup';
|
||||
$itemid = 0;
|
||||
}
|
||||
|
||||
// Let's send the file to file storage, everything already defined
|
||||
$fs = get_file_storage();
|
||||
$fr = array(
|
||||
'contextid' => $ctxid,
|
||||
'component' => $component,
|
||||
'filearea' => $filearea,
|
||||
'itemid' => $itemid,
|
||||
'filepath' => '/',
|
||||
@ -257,8 +264,8 @@ abstract class backup_helper {
|
||||
// If file already exists, delete if before
|
||||
// creating it again. This is BC behaviour - copy()
|
||||
// overwrites by default
|
||||
if ($fs->file_exists($fr['contextid'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename'])) {
|
||||
$pathnamehash = $fs->get_pathname_hash($fr['contextid'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename']);
|
||||
if ($fs->file_exists($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename'])) {
|
||||
$pathnamehash = $fs->get_pathname_hash($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename']);
|
||||
$sf = $fs->get_file_by_hash($pathnamehash);
|
||||
$sf->delete();
|
||||
}
|
||||
|
@ -35,8 +35,7 @@ class backup_nested_element extends base_nested_element implements processable {
|
||||
protected $params; // Unprocessed params as specified in the set_source() call
|
||||
protected $procparams;// Processed (path resolved) params array
|
||||
protected $aliases; // Define DB->final element aliases
|
||||
protected $fileannotelement; // Element to be used as itemid for file annotations
|
||||
protected $fileannotareas; // array of file areas to be searched by file annotations
|
||||
protected $fileannotations; // array of file areas to be searched by file annotations
|
||||
protected $counter; // Number of instances of this element that have been processed
|
||||
|
||||
/**
|
||||
@ -54,8 +53,7 @@ class backup_nested_element extends base_nested_element implements processable {
|
||||
$this->params = null;
|
||||
$this->procparams= null;
|
||||
$this->aliases = array();
|
||||
$this->fileannotelement = null;
|
||||
$this->fileannotareas = array();
|
||||
$this->fileannotations = array();
|
||||
$this->counter = 0;
|
||||
}
|
||||
|
||||
@ -148,21 +146,21 @@ class backup_nested_element extends base_nested_element implements processable {
|
||||
}
|
||||
}
|
||||
|
||||
public function annotate_files($areas, $elementname) {
|
||||
if (!is_array($areas)) { // Check we are passing array
|
||||
throw new base_element_struct_exception('annotate_files_requires_array_of_areas', $areas);
|
||||
}
|
||||
$annotations = $this->get_file_annotations();
|
||||
if (!empty($annotations[0])) { // Check we haven't defined file annotations already
|
||||
throw new base_element_struct_exception('annotate_files_already_defined', $this->get_name());
|
||||
public function annotate_files($component, $filearea, $elementname) {
|
||||
// note: it is possible to annotate areas ONLY in current context, ie modules may backup only from module context
|
||||
if (!array_key_exists($component, $this->fileannotations)) {
|
||||
$this->fileannotations[$component] = array();
|
||||
}
|
||||
|
||||
if ($elementname !== null) { // Check elementname is valid
|
||||
$element = $this->find_element($elementname);
|
||||
// Annotate the element
|
||||
$this->fileannotelement= $element;
|
||||
$elementname = $this->find_element($elementname); //TODO: no warning here? (skodak)
|
||||
}
|
||||
// Annotate the areas
|
||||
$this->fileannotareas = $areas;
|
||||
|
||||
if (array_key_exists($filearea, $this->fileannotations[$component])) {
|
||||
throw new base_element_struct_exception('annotate_files_duplicate_annotation', "$component/$filearea/$elementname");
|
||||
}
|
||||
|
||||
$this->fileannotations[$component][$filearea] = $elementname;
|
||||
}
|
||||
|
||||
public function annotate_ids($itemname, $elementname) {
|
||||
@ -175,10 +173,7 @@ class backup_nested_element extends base_nested_element implements processable {
|
||||
* @backup_structure and the areas to be searched
|
||||
*/
|
||||
public function get_file_annotations() {
|
||||
if (empty($this->fileannotareas)) {
|
||||
return array(null, null);
|
||||
}
|
||||
return array($this->fileannotareas, $this->fileannotelement);
|
||||
return $this->fileannotations;
|
||||
}
|
||||
|
||||
public function get_source_array() {
|
||||
|
@ -67,13 +67,15 @@ class backup_structure_processor extends base_processor {
|
||||
|
||||
public function process_nested_element(base_nested_element $nested) {
|
||||
// Proceed with all the file annotations for this element
|
||||
list($fileareas, $element) = $nested->get_file_annotations();
|
||||
if ($fileareas) { // If there are areas to search
|
||||
$backupid = $this->get_var(backup::VAR_BACKUPID);
|
||||
$contextid= $this->get_var(backup::VAR_CONTEXTID);
|
||||
$itemid = !is_null($element) ? $element->get_value() : null;
|
||||
foreach ($fileareas as $filearea) {
|
||||
backup_structure_dbops::annotate_files($backupid, $contextid, $filearea, $itemid);
|
||||
$fileannotations = $nested->get_file_annotations();
|
||||
if ($fileannotations) { // If there are areas to search
|
||||
$backupid = $this->get_var(backup::VAR_BACKUPID);
|
||||
$contextid = $this->get_var(backup::VAR_CONTEXTID);
|
||||
foreach ($fileannotations as $component=>$area) {
|
||||
foreach ($area as $filearea=>$element) {
|
||||
$itemid = !is_null($element) ? $element->get_value() : null;
|
||||
backup_structure_dbops::annotate_files($backupid, $contextid, $component, $filearea, $itemid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,14 +82,14 @@ class backup_structure_test extends UnitTestCaseUsingDatabase {
|
||||
// With two related file
|
||||
$f1_forum_data = (object)array(
|
||||
'contenthash' => 'testf1', 'contextid' => $this->contextid,
|
||||
'filearea' => 'forum_intro', 'filename' => 'tf1', 'itemid' => 0,
|
||||
'component'=>'mod_forum', 'filearea' => 'intro', 'filename' => 'tf1', 'itemid' => 0,
|
||||
'filesize' => 123, 'timecreated' => 0, 'timemodified' => 0,
|
||||
'pathnamehash' => 'testf1'
|
||||
);
|
||||
$DB->insert_record('files', $f1_forum_data);
|
||||
$f2_forum_data = (object)array(
|
||||
'contenthash' => 'tesft2', 'contextid' => $this->contextid,
|
||||
'filearea' => 'forum_intro', 'filename' => 'tf2', 'itemid' => 0,
|
||||
'component'=>'mod_forum', 'filearea' => 'intro', 'filename' => 'tf2', 'itemid' => 0,
|
||||
'filesize' => 123, 'timecreated' => 0, 'timemodified' => 0,
|
||||
'pathnamehash' => 'testf2'
|
||||
);
|
||||
@ -112,15 +112,15 @@ class backup_structure_test extends UnitTestCaseUsingDatabase {
|
||||
$p4id = $DB->insert_record('forum_posts', $post4);
|
||||
// With two related file
|
||||
$f1_post1 = (object)array(
|
||||
'contenthash' => 'testp1', 'contextid' => $this->contextid,
|
||||
'filearea' => 'forum_post', 'filename' => 'tp1', 'itemid' => $p1id,
|
||||
'contenthash' => 'testp1', 'contextid' => $this->contextid, 'component'=>'mod_forum',
|
||||
'filearea' => 'post', 'filename' => 'tp1', 'itemid' => $p1id,
|
||||
'filesize' => 123, 'timecreated' => 0, 'timemodified' => 0,
|
||||
'pathnamehash' => 'testp1'
|
||||
);
|
||||
$DB->insert_record('files', $f1_post1);
|
||||
$f1_post2 = (object)array(
|
||||
'contenthash' => 'testp2', 'contextid' => $this->contextid,
|
||||
'filearea' => 'forum_attachment', 'filename' => 'tp2', 'itemid' => $p2id,
|
||||
'contenthash' => 'testp2', 'contextid' => $this->contextid, 'component'=>'mod_forum',
|
||||
'filearea' => 'attachment', 'filename' => 'tp2', 'itemid' => $p2id,
|
||||
'filesize' => 123, 'timecreated' => 0, 'timemodified' => 0,
|
||||
'pathnamehash' => 'testp2'
|
||||
);
|
||||
@ -293,10 +293,11 @@ class backup_structure_test extends UnitTestCaseUsingDatabase {
|
||||
$rating->set_source_alias('rating', 'post_rating'); // Map the 'rating' value from DB to 'post_rating' final element
|
||||
|
||||
// Mark to detect files of type 'forum_intro' in forum (and not item id)
|
||||
$forum->annotate_files(array('forum_intro'), null);
|
||||
$forum->annotate_files('mod_forum', 'intro', null);
|
||||
|
||||
// Mark to detect file of type 'forum_post' and 'forum_attachment' in post (with itemid being post->id)
|
||||
$post->annotate_files(array('forum_post', 'forum_attachment'), 'id');
|
||||
$post->annotate_files('mod_forun', 'post', 'id');
|
||||
$post->annotate_files('mod_forum', 'attachment', 'id');
|
||||
|
||||
// Mark various elements to be annotated
|
||||
$discussion->annotate_ids('user1', 'userid');
|
||||
@ -569,30 +570,21 @@ class backup_structure_test extends UnitTestCaseUsingDatabase {
|
||||
}
|
||||
|
||||
// Try various incorrect file annotations
|
||||
$ne = new backup_nested_element('test', 'one', 'two', 'three');
|
||||
try {
|
||||
$ne->annotate_files('notanarray', null); // Incorrect first param
|
||||
$this->assertTrue(false, 'base_element_struct_exception expected');
|
||||
} catch (exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
$this->assertEqual($e->errorcode, 'annotate_files_requires_array_of_areas');
|
||||
$this->assertEqual($e->a, 'notanarray');
|
||||
}
|
||||
|
||||
$ne = new backup_nested_element('test', 'one', 'two', 'three');
|
||||
$ne->annotate_files(array('test_filearea'), null);
|
||||
$ne->annotate_files('test', 'filearea', null);
|
||||
try {
|
||||
$ne->annotate_files(array('test_filearea'), null); // Try to add annotations twice
|
||||
$ne->annotate_files('test', 'filearea', null); // Try to add annotations twice
|
||||
$this->assertTrue(false, 'base_element_struct_exception expected');
|
||||
} catch (exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
$this->assertEqual($e->errorcode, 'annotate_files_already_defined');
|
||||
$this->assertEqual($e->errorcode, 'annotate_files_duplicate_annotation');
|
||||
$this->assertEqual($e->a, 'test');
|
||||
}
|
||||
|
||||
$ne = new backup_nested_element('test', 'one', 'two', 'three');
|
||||
try {
|
||||
$ne->annotate_files(array('test_filearea'), 'four'); // Incorrect element
|
||||
$ne->annotate_files('test', 'filearea', 'four'); // Incorrect element
|
||||
$this->assertTrue(false, 'base_element_struct_exception expected');
|
||||
} catch (exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
|
@ -140,7 +140,7 @@ abstract class backup_ui_stage {
|
||||
|
||||
/**
|
||||
* Class representing the initial stage of a backup.
|
||||
*
|
||||
*
|
||||
* In this stage the user is required to set the root level settings.
|
||||
*
|
||||
* @copyright 2010 Sam Hemelryk
|
||||
@ -243,7 +243,7 @@ class backup_ui_stage_initial extends backup_ui_stage {
|
||||
*
|
||||
* During the schema stage the user is required to set the settings that relate
|
||||
* to the area that they are backing up as well as its children.
|
||||
*
|
||||
*
|
||||
* @copyright 2010 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@ -298,7 +298,7 @@ class backup_ui_stage_schema extends backup_ui_stage {
|
||||
return $changes;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates the backup_schema_form instance for this stage
|
||||
@ -439,7 +439,7 @@ class backup_ui_stage_confirmation extends backup_ui_stage {
|
||||
foreach ($task->get_settings() as $setting) {
|
||||
// For this stage only the filename setting should be editable
|
||||
if ($setting->get_name() != 'filename') {
|
||||
$form->add_fixed_setting($setting);
|
||||
$form->add_fixed_setting($setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -534,12 +534,13 @@ class backup_ui_stage_complete extends backup_ui_stage_final {
|
||||
*/
|
||||
public function display() {
|
||||
global $OUTPUT;
|
||||
|
||||
|
||||
// Get the resulting stored_file record
|
||||
$file = $this->results['backup_destination'];
|
||||
// Turn it into a url for the file browser
|
||||
$fileurl = new moodle_url('/files/index.php', array(
|
||||
'contextid' => $file->get_contextid(),
|
||||
'component' => $file->get_component(),
|
||||
'filearea' => $file->get_filearea(),
|
||||
'itemid' => $file->get_itemid(),
|
||||
'filepath' => $file->get_filepath()
|
||||
|
@ -98,11 +98,12 @@ class block_community_manager {
|
||||
|
||||
$fs = get_file_storage();
|
||||
$record->contextid = get_context_instance(CONTEXT_USER, $USER->id)->id;
|
||||
$record->filearea = 'user_backup';
|
||||
$record->component = 'user';
|
||||
$record->filearea = 'backup';
|
||||
$record->itemid = 0;
|
||||
$record->filename = 'backup_'.$course->fullname."_".$course->id.".zip";
|
||||
$record->filepath = '/';
|
||||
if (!$fs->file_exists($record->contextid, $record->filearea, 0, $record->filepath, $record->filename)) {
|
||||
if (!$fs->file_exists($record->contextid, $record->component, $record->filearea, 0, $record->filepath, $record->filename)) {
|
||||
$fs->create_file_from_pathname($record, $CFG->dataroot.'/temp/communitydownload/'.'backup_'.$course->fullname."_".$course->id.".zip");
|
||||
}
|
||||
//delete temp file
|
||||
|
@ -27,7 +27,7 @@ class block_course_summary extends block_base {
|
||||
$options = new object();
|
||||
$options->noclean = true; // Don't clean Javascripts etc
|
||||
$context = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
|
||||
$this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course_summary', NULL);
|
||||
$this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL);
|
||||
$this->content->text = format_text($this->page->course->summary, $this->page->course->summaryformat, $options);
|
||||
if ($this->page->user_is_editing()) {
|
||||
if($this->page->course->id == SITEID) {
|
||||
|
@ -1,5 +1,28 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Form for editing HTML block instances.
|
||||
*
|
||||
* @package block_html
|
||||
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
class block_html extends block_base {
|
||||
|
||||
function init() {
|
||||
@ -36,7 +59,7 @@ class block_html extends block_base {
|
||||
$this->content->footer = '';
|
||||
if (isset($this->config->text)) {
|
||||
// rewrite url
|
||||
$this->config->text['text'] = file_rewrite_pluginfile_urls($this->config->text['text'], 'pluginfile.php', $this->context->id, 'block_html', $this->instance->id);
|
||||
$this->config->text['text'] = file_rewrite_pluginfile_urls($this->config->text['text'], 'pluginfile.php', $this->context->id, 'block_html', 'content', NULL);
|
||||
$this->content->text = format_text($this->config->text['text'], $this->config->text['format'], $filteropt);
|
||||
} else {
|
||||
$this->content->text = '';
|
||||
@ -55,7 +78,7 @@ class block_html extends block_base {
|
||||
global $DB;
|
||||
|
||||
// Move embedded files into a proper filearea and adjust HTML links to match
|
||||
$data->text['text'] = file_save_draft_area_files($data->text['itemid'], $this->context->id, 'block_html', $this->instance->id, array('subdirs'=>true), $data->text['text']);
|
||||
$data->text['text'] = file_save_draft_area_files($data->text['itemid'], $this->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $data->text['text']);
|
||||
|
||||
parent::instance_config_save($data, $nolongerused);
|
||||
}
|
||||
@ -63,7 +86,7 @@ class block_html extends block_base {
|
||||
function instance_delete() {
|
||||
global $DB;
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files($this->context->id, 'block_html', $this->instance->id);
|
||||
$fs->delete_area_files($this->context->id, 'block_html');
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -121,16 +144,4 @@ class block_html extends block_base {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function send_file($context, $filearea, $itemid, $filepath, $filename) {
|
||||
$fs = get_file_storage();
|
||||
$fullpath = $context->id.'block_html'.$itemid.$filepath.$filename;
|
||||
|
||||
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
session_get_instance()->write_close();
|
||||
send_stored_file($file, 60*60, 0, false);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
/**
|
||||
* Form for editing HTML block instances.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @package block_html
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@ -50,7 +50,7 @@ class block_html_edit_form extends block_edit_form {
|
||||
} else {
|
||||
$currenttext = $block->config->text['text'];
|
||||
}
|
||||
$block->config->text['text'] = file_prepare_draft_area($draftid_editor, $block->context->id, 'block_html', $block->instance->id, array('subdirs'=>true), $currenttext);
|
||||
$block->config->text['text'] = file_prepare_draft_area($draftid_editor, $block->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $currenttext);
|
||||
$block->config->text['itemid'] = $draftid_editor;
|
||||
parent::set_data($defaults);
|
||||
}
|
||||
|
49
blocks/html/lib.php
Normal file
49
blocks/html/lib.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Form for editing HTML block instances.
|
||||
*
|
||||
* @package block_html
|
||||
* @copyright 2010 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload) {
|
||||
|
||||
if ($context->contextlevel != CONTEXT_BLOCK) {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
require_course_login($course);
|
||||
|
||||
if ($filearea !== 'content') {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filename = array_pop($args);
|
||||
$filepath = '/'.implode('/', $args);
|
||||
|
||||
if (!$file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename) or $file->is_directory()) {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
session_get_instance()->write_close();
|
||||
send_stored_file($file, 60*60, 0, $forcedownload);
|
||||
}
|
@ -19,8 +19,7 @@
|
||||
/**
|
||||
* Manage user private area files
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage repository
|
||||
* @package block_private_files
|
||||
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@ -47,12 +46,14 @@ class block_private_files extends block_base {
|
||||
|
||||
function get_content() {
|
||||
global $CFG, $USER, $PAGE, $OUTPUT;
|
||||
|
||||
if ($this->content !== NULL) {
|
||||
return $this->content;
|
||||
}
|
||||
if (empty($this->instance)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->content->text = '';
|
||||
$this->content->footer = '';
|
||||
if (isloggedin() && !isguestuser()) { // Show the block
|
||||
@ -60,16 +61,18 @@ class block_private_files extends block_base {
|
||||
$options = new stdclass;
|
||||
$options->maxbytes = -1;
|
||||
$options->maxfiles = -1;
|
||||
$options->filearea = 'user_private';
|
||||
$options->itemid = 0;
|
||||
$options->subdirs = true;
|
||||
$options->accepted_types = '*';
|
||||
$options->return_types = FILE_INTERNAL;
|
||||
$options->context = $PAGE->context;
|
||||
$options->disable_types = array('user');
|
||||
|
||||
$this->content = new stdClass;
|
||||
$this->content->text = $OUTPUT->file_manager($options);
|
||||
$this->content = new object();
|
||||
|
||||
//TODO: add capability check here!
|
||||
|
||||
//TODO: add list of available files here
|
||||
$this->content->text = $OUTPUT->single_button(new moodle_url('/blocks/private_files/edit.php'), get_string('edit'), 'get');
|
||||
;
|
||||
$this->content->footer = '';
|
||||
|
||||
|
58
blocks/private_files/edit.php
Normal file
58
blocks/private_files/edit.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Manage files in folder in private area - to be replaced by something better hopefully....
|
||||
*
|
||||
* @package block_private_files
|
||||
* @copyright 2010 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require('../../config.php');
|
||||
require_once("$CFG->dirroot/blocks/private_files/edit_form.php");
|
||||
require_once("$CFG->dirroot/repository/lib.php");
|
||||
|
||||
require_login();
|
||||
if (isguestuser()) {
|
||||
die();
|
||||
}
|
||||
//TODO: add capability check here!
|
||||
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
|
||||
$PAGE->set_url('/blocks/private/edit.php');
|
||||
|
||||
$data = new object();
|
||||
$options = array('subdirs'=>1, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
|
||||
file_prepare_standard_filemanager($data, 'files', $options, $context, 'user', 'private', 0);
|
||||
|
||||
$mform = new block_private_files_form(null, array('data'=>$data, 'options'=>$options));
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect(new moodle_url('/my/'));
|
||||
|
||||
} else if ($formdata = $mform->get_data()) {
|
||||
$formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'user', 'private', 0);
|
||||
redirect(new moodle_url('/my/'));
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->box_start('generalbox');
|
||||
$mform->display();
|
||||
echo $OUTPUT->box_end();
|
||||
echo $OUTPUT->footer();
|
43
blocks/private_files/edit_form.php
Normal file
43
blocks/private_files/edit_form.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* minimalistic edit form
|
||||
*
|
||||
* @package block_private_files
|
||||
* @copyright 2010 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/formslib.php");
|
||||
|
||||
class block_private_files_form extends moodleform {
|
||||
function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$data = $this->_customdata['data'];
|
||||
$options = $this->_customdata['options'];
|
||||
|
||||
$mform->addElement('filemanager', 'files_filemanager', get_string('files'), null, $options);
|
||||
|
||||
$this->add_action_buttons(true, get_string('submit'));
|
||||
|
||||
$this->set_data($data);
|
||||
}
|
||||
}
|
@ -94,7 +94,7 @@ if ($id) {
|
||||
$userid = $entry->userid;
|
||||
$entry->subject = clean_text($entry->subject);
|
||||
$entry->summary = clean_text($entry->summary, $entry->format);
|
||||
|
||||
|
||||
} else {
|
||||
if (!has_capability('moodle/blog:create', $sitecontext)) {
|
||||
print_error('noentry', 'blog'); // manageentries is not enough for adding
|
||||
@ -163,8 +163,8 @@ $attachmentoptions = array('subdirs'=>false, 'maxfiles'=> 99, 'maxbytes'=>$CFG->
|
||||
|
||||
$blogeditform = new blog_edit_form(null, compact('entry', 'summaryoptions', 'attachmentoptions', 'sitecontext', 'courseid', 'modid'));
|
||||
|
||||
$entry = file_prepare_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog_post', $entry->id);
|
||||
$entry = file_prepare_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog_attachment', $entry->id);
|
||||
$entry = file_prepare_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id);
|
||||
$entry = file_prepare_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id);
|
||||
|
||||
if (!empty($CFG->usetags) && !empty($entry->id)) {
|
||||
include_once($CFG->dirroot.'/tag/lib.php');
|
||||
|
@ -110,7 +110,7 @@ class blog_entry {
|
||||
$cmt->showcount = $CFG->blogshowcommentscount;
|
||||
$options->comments = $cmt;
|
||||
}
|
||||
$this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog_post', $this->id);
|
||||
$this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog', 'post', $this->id);
|
||||
|
||||
$template['body'] = format_text($this->summary, $this->summaryformat, $options);
|
||||
$template['title'] = format_string($this->subject);
|
||||
@ -369,8 +369,8 @@ class blog_entry {
|
||||
$entry->$var = $val;
|
||||
}
|
||||
|
||||
$entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog_post', $entry->id);
|
||||
$entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog_attachment', $entry->id);
|
||||
$entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id);
|
||||
$entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id);
|
||||
|
||||
if (!empty($CFG->useblogassociations)) {
|
||||
$entry->add_associations();
|
||||
@ -462,8 +462,8 @@ class blog_entry {
|
||||
*/
|
||||
public function delete_attachments() {
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files(SYSCONTEXTID, 'blog_attachment', $this->id);
|
||||
$fs->delete_area_files(SYSCONTEXTID, 'blog_post', $this->id);
|
||||
$fs->delete_area_files(SYSCONTEXTID, 'blog', 'attachment', $this->id);
|
||||
$fs->delete_area_files(SYSCONTEXTID, 'blog', 'post', $this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -480,9 +480,8 @@ class blog_entry {
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
$fs = get_file_storage();
|
||||
$browser = get_file_browser();
|
||||
|
||||
$files = $fs->get_area_files(SYSCONTEXTID, 'blog_attachment', $this->id);
|
||||
$files = $fs->get_area_files(SYSCONTEXTID, 'blog', 'attachment', $this->id);
|
||||
|
||||
$imagereturn = "";
|
||||
$output = "";
|
||||
@ -495,7 +494,7 @@ class blog_entry {
|
||||
}
|
||||
|
||||
$filename = $file->get_filename();
|
||||
$ffurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog_attachment/'.$this->id.'/'.$filename);
|
||||
$ffurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog/attachment/'.$this->id.'/'.$filename);
|
||||
$mimetype = $file->get_mimetype();
|
||||
|
||||
$icon = substr(mimeinfo_from_type("icon", $mimetype), 0, -4);
|
||||
|
@ -1626,11 +1626,6 @@ class calendar_event {
|
||||
* @var string
|
||||
*/
|
||||
protected $_description = null;
|
||||
/**
|
||||
* The filearea to use with this event
|
||||
* @var string
|
||||
*/
|
||||
protected static $filearea = 'calendar_event_description';
|
||||
/**
|
||||
* The options to use with this description editor
|
||||
* @var array
|
||||
@ -1790,7 +1785,7 @@ class calendar_event {
|
||||
}
|
||||
|
||||
// Convert file paths in the description so that things display correctly
|
||||
$this->_description = file_rewrite_pluginfile_urls($this->properties->description, 'pluginfile.php', $this->editorcontext->id, self::$filearea, $itemid);
|
||||
$this->_description = file_rewrite_pluginfile_urls($this->properties->description, 'pluginfile.php', $this->editorcontext->id, 'calendar', 'event_description', $itemid);
|
||||
// Clean the text so no nasties get through
|
||||
$this->_description = clean_text($this->_description, $this->properties->format);
|
||||
}
|
||||
@ -1883,7 +1878,8 @@ class calendar_event {
|
||||
$this->properties->description = file_save_draft_area_files(
|
||||
$editor['itemid'],
|
||||
$this->editorcontext->id,
|
||||
self::$filearea,
|
||||
'calendar',
|
||||
'event_description',
|
||||
$this->properties->id,
|
||||
$this->editoroptions,
|
||||
$editor['text'],
|
||||
@ -1914,7 +1910,7 @@ class calendar_event {
|
||||
// If the context has been set delete all associated files
|
||||
if ($usingeditor) {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($this->editorcontext->id, self::$filearea, $this->properties->id);
|
||||
$files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description', $this->properties->id);
|
||||
foreach ($files as $file) {
|
||||
$fs->create_file_from_storedfile(array('itemid'=>$eventcopyid), $file);
|
||||
}
|
||||
@ -1940,7 +1936,8 @@ class calendar_event {
|
||||
$this->properties->description = file_save_draft_area_files(
|
||||
$this->properties->description['itemid'],
|
||||
$this->editorcontext->id,
|
||||
self::$filearea,
|
||||
'calendar',
|
||||
'event_description',
|
||||
$this->properties->id,
|
||||
$this->editoroptions,
|
||||
$this->properties->description['text'],
|
||||
@ -2035,7 +2032,7 @@ class calendar_event {
|
||||
// If the context has been set delete all associated files
|
||||
if ($this->editorcontext !== null) {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($this->editorcontext->id, self::$filearea, $this->properties->id);
|
||||
$files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description', $this->properties->id);
|
||||
foreach ($files as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
@ -2133,7 +2130,7 @@ class calendar_event {
|
||||
// Just encase it has already been submitted
|
||||
$draftiddescription = file_get_submitted_draft_itemid('description');
|
||||
// Prepare the draft area, this copies existing files to the draft area as well
|
||||
$properties->description = file_prepare_draft_area($draftiddescription, $contextid, self::$filearea, $properties->id, $this->editoroptions, $properties->description);
|
||||
$properties->description = file_prepare_draft_area($draftiddescription, $contextid, 'calendar', 'event_description', $properties->id, $this->editoroptions, $properties->description);
|
||||
} else {
|
||||
$draftiddescription = 0;
|
||||
}
|
||||
|
@ -199,7 +199,7 @@
|
||||
if (!isset($category->descriptionformat)) {
|
||||
$category->descriptionformat = FORMAT_MOODLE;
|
||||
}
|
||||
$text = file_rewrite_pluginfile_urls($category->description, 'pluginfile.php', $context->id, 'category_description', $category->id);
|
||||
$text = file_rewrite_pluginfile_urls($category->description, 'pluginfile.php', $context->id, 'coursecat', 'description', null);
|
||||
echo format_text($text, $category->descriptionformat, $options);
|
||||
echo $OUTPUT->box_end();
|
||||
}
|
||||
|
@ -74,10 +74,10 @@ if (!empty($course)) {
|
||||
}
|
||||
}
|
||||
$course->allowedmods = $allowedmods;
|
||||
$course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course_summary', 0);
|
||||
$course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course', 'summary', 0);
|
||||
|
||||
} else {
|
||||
$course = file_prepare_standard_editor($course, 'summary', $editoroptions, null, 'course_summary', null);
|
||||
$course = file_prepare_standard_editor($course, 'summary', $editoroptions, null, 'course', 'summary', null);
|
||||
}
|
||||
|
||||
// first create the form
|
||||
|
@ -42,7 +42,7 @@ if ($id) {
|
||||
}
|
||||
|
||||
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true);
|
||||
$category = file_prepare_standard_editor($category, 'description', $editoroptions, $editorcontext, 'category_description', $category->id);
|
||||
$category = file_prepare_standard_editor($category, 'description', $editoroptions, $editorcontext, 'coursecat', 'description', 0);
|
||||
|
||||
$mform = new editcategory_form('editcategory.php', compact('category', 'editoroptions'));
|
||||
$mform->set_data($category);
|
||||
@ -82,7 +82,7 @@ if ($mform->is_cancelled()) {
|
||||
mark_context_dirty($newcategory->context->path);
|
||||
}
|
||||
|
||||
$newcategory = file_postupdate_standard_editor($newcategory, 'description', $editoroptions, $categorycontext, 'category_description', $newcategory->id);
|
||||
$newcategory = file_postupdate_standard_editor($newcategory, 'description', $editoroptions, $categorycontext, 'coursecat', 'description', 0);
|
||||
$DB->update_record('course_categories', $newcategory);
|
||||
fix_course_sortorder();
|
||||
|
||||
|
@ -40,7 +40,7 @@ $context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
require_capability('moodle/course:update', $context);
|
||||
|
||||
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
|
||||
$section = file_prepare_standard_editor($section, 'summary', $editoroptions, $context, 'course_section', $section->id);
|
||||
$section = file_prepare_standard_editor($section, 'summary', $editoroptions, $context, 'course', 'section', $section->id);
|
||||
$section->usedefaultname = (is_null($section->name));
|
||||
$mform = new editsection_form(null, array('course'=>$course, 'editoroptions'=>$editoroptions));
|
||||
$mform->set_data($section); // set current value
|
||||
@ -55,7 +55,7 @@ if ($mform->is_cancelled()){
|
||||
} else {
|
||||
$section->name = null;
|
||||
}
|
||||
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course_section', $section->id);
|
||||
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'section', $section->id);
|
||||
$section->summary = $data->summary;
|
||||
$section->summaryformat = $data->summaryformat;
|
||||
$DB->update_record('course_sections', $section);
|
||||
|
@ -104,7 +104,7 @@ if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing())
|
||||
echo '<div class="summary">';
|
||||
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
|
||||
$summaryformatoptions = new object();
|
||||
$summaryformatoptions->noclean = true;
|
||||
echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
|
||||
@ -231,7 +231,7 @@ while ($section <= $course->numsections) {
|
||||
echo '<div class="summary">';
|
||||
if ($thissection->summary) {
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
|
||||
$summaryformatoptions = new object();
|
||||
$summaryformatoptions->noclean = true;
|
||||
echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
|
||||
|
@ -95,7 +95,7 @@
|
||||
echo '<div class="summary">';
|
||||
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
|
||||
$summaryformatoptions = new object();
|
||||
$summaryformatoptions->noclean = true;
|
||||
echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
|
||||
@ -225,7 +225,7 @@
|
||||
}
|
||||
echo '<div class="summary">';
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
|
||||
$summaryformatoptions = new object();
|
||||
$summaryformatoptions->noclean = true;
|
||||
echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
|
||||
|
@ -62,7 +62,7 @@
|
||||
|
||||
echo $OUTPUT->box_start('generalbox info');
|
||||
|
||||
$course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course_summary', NULL);
|
||||
$course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL);
|
||||
echo format_text($course->summary, $course->summaryformat, NULL, $course->id);
|
||||
|
||||
if (!empty($CFG->coursecontact)) {
|
||||
|
103
course/lib.php
103
course/lib.php
@ -2226,7 +2226,7 @@ function print_course($course, $highlightterms = '') {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
||||
// Rewrite file URLs so that they are correct
|
||||
$course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course_summary', NULL);
|
||||
$course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL);
|
||||
|
||||
$linkcss = $course->visible ? '' : ' class="dimmed" ';
|
||||
|
||||
@ -3483,7 +3483,7 @@ function create_course($data, $editoroptions = NULL) {
|
||||
|
||||
if ($editoroptions) {
|
||||
// Save the files used in the summary editor and store
|
||||
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course_summary', 0);
|
||||
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
|
||||
$DB->set_field('course', 'summary', $data->summary, array('id'=>$newcourseid));
|
||||
$DB->set_field('course', 'summaryformat', $data->summary_format, array('id'=>$newcourseid));
|
||||
}
|
||||
@ -3548,7 +3548,7 @@ function update_course($data, $editoroptions = NULL) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $oldcourse->id);
|
||||
|
||||
if ($editoroptions) {
|
||||
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course_summary', 0);
|
||||
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
|
||||
}
|
||||
|
||||
if (!isset($data->category) or empty($data->category)) {
|
||||
@ -3631,6 +3631,9 @@ function average_number_of_courses_modules() {
|
||||
* This class pertains to course requests and contains methods associated with
|
||||
* create, approving, and removing course requests.
|
||||
*
|
||||
* Please note we do not allow embedded images here because there is no context
|
||||
* to store them with proper access control.
|
||||
*
|
||||
* @copyright 2009 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
@ -3661,22 +3664,6 @@ class course_request {
|
||||
*/
|
||||
protected static $summaryeditoroptions;
|
||||
|
||||
/**
|
||||
* The context used when working with files for the summary editor
|
||||
* This is initially set by {@link summary_editor_context()}
|
||||
* @var stdClass
|
||||
* @static
|
||||
*/
|
||||
protected static $summaryeditorcontext;
|
||||
|
||||
/**
|
||||
* The string used to identify the file area for course_requests
|
||||
* This is initially set by {@link summary_editor_context()}
|
||||
* @var string
|
||||
* @static
|
||||
*/
|
||||
protected static $summaryeditorfilearea = 'course_request_summary';
|
||||
|
||||
/**
|
||||
* Static function to prepare the summary editor for working with a course
|
||||
* request.
|
||||
@ -3692,7 +3679,7 @@ class course_request {
|
||||
if ($data === null) {
|
||||
$data = new stdClass;
|
||||
}
|
||||
$data = file_prepare_standard_editor($data, 'summary', self::summary_editor_options(), self::summary_editor_context(), self::summary_editor_filearea(), null);
|
||||
$data = file_prepare_standard_editor($data, 'summary', self::summary_editor_options());
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -3709,19 +3696,13 @@ class course_request {
|
||||
public static function create($data) {
|
||||
global $USER, $DB, $CFG;
|
||||
$data->requester = $USER->id;
|
||||
$editorused = (!empty($data->summary_editor));
|
||||
// Has summary_editor been set. If so we have come through with a editor and
|
||||
// may need to save files
|
||||
if ($editorused && empty($data->summary)) {
|
||||
// Summary is a required field so copy the text over
|
||||
$data->summary = $data->summary_editor['text'];
|
||||
}
|
||||
|
||||
// Summary is a required field so copy the text over
|
||||
$data->summary = $data->summary_editor['text'];
|
||||
$data->summaryformat = $data->summary_editor['format'];
|
||||
|
||||
$data->id = $DB->insert_record('course_request', $data);
|
||||
if ($editorused) {
|
||||
// Save any files and then update the course with the fixed data
|
||||
$data = file_postupdate_standard_editor($data, 'summary', self::summary_editor_options(), self::summary_editor_context(), self::summary_editor_filearea(), $data->id);
|
||||
$DB->update_record('course_request', $data);
|
||||
}
|
||||
|
||||
// Create a new course_request object and return it
|
||||
$request = new course_request($data);
|
||||
|
||||
@ -3750,31 +3731,11 @@ class course_request {
|
||||
public static function summary_editor_options() {
|
||||
global $CFG;
|
||||
if (self::$summaryeditoroptions === null) {
|
||||
self::$summaryeditoroptions = array('maxfiles' => 0, 'maxbytes'=>0, 'trusttext'=>true);
|
||||
self::$summaryeditoroptions = array('maxfiles' => 0, 'maxbytes'=>0);
|
||||
}
|
||||
return self::$summaryeditoroptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context to use with the summary editor
|
||||
*
|
||||
* @uses course_request::$summaryeditorcontext
|
||||
* @return stdClass The context to use
|
||||
*/
|
||||
public static function summary_editor_context() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filearea to use with the summary editor
|
||||
*
|
||||
* @uses course_request::$summaryeditorfilearea
|
||||
* @return string The filearea to use with the summary editor
|
||||
*/
|
||||
public static function summary_editor_filearea() {
|
||||
return self::$summaryeditorfilearea;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the properties for this course request object. Id is required and if
|
||||
* only id is provided then we load the rest of the properties from the database
|
||||
@ -3810,9 +3771,6 @@ class course_request {
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key) {
|
||||
if ($key === 'summary' && self::summary_editor_context() !== null) {
|
||||
return file_rewrite_pluginfile_urls($this->properties->summary, 'pluginfile.php', self::summary_editor_context()->id, self::summary_editor_filearea(), $this->properties->id);
|
||||
}
|
||||
return $this->properties->$key;
|
||||
}
|
||||
|
||||
@ -3927,13 +3885,12 @@ class course_request {
|
||||
blocks_add_default_course_blocks($course);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
// TODO: do some real enrolment here
|
||||
role_assign($CFG->creatornewroleid, $this->properties->requester, $coursecontext->id); // assing teacher role
|
||||
role_assign($CFG->creatornewroleid, $this->properties->requester, $coursecontext->id); // assign teacher role
|
||||
if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
|
||||
// if we're all or requested we're ok.
|
||||
$allowedmods = explode(',',$CFG->defaultallowedmodules);
|
||||
update_restricted_mods($course, $allowedmods);
|
||||
}
|
||||
$this->copy_summary_files_to_course($course);
|
||||
$this->delete();
|
||||
fix_course_sortorder();
|
||||
|
||||
@ -3967,36 +3924,6 @@ class course_request {
|
||||
public function delete() {
|
||||
global $DB;
|
||||
$DB->delete_records('course_request', array('id' => $this->properties->id));
|
||||
if (self::summary_editor_context() !== null) {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files(self::summary_editor_context()->id, self::summary_editor_filearea(), $this->properties->id);
|
||||
foreach ($files as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function copies all files used in the summary for the request to the
|
||||
* summary of the course.
|
||||
*
|
||||
* This function copies, original files are left associated with the request
|
||||
* and are removed only when the request is deleted
|
||||
*
|
||||
* @param stdClass $course An object representing the course to copy files to
|
||||
*/
|
||||
protected function copy_summary_files_to_course($course) {
|
||||
if (self::summary_editor_context() !== null) {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files(self::summary_editor_context()->id, self::summary_editor_filearea(), $this->properties->id);
|
||||
foreach ($files as $file) {
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
if (!$file->is_directory()) {
|
||||
$filerecord = array('contextid'=>$coursecontext->id, 'filearea'=>'course_summary', 'itemid'=>0, 'filepath'=>$file->get_filepath(), 'filename'=>$file->get_filename());
|
||||
$fs->create_file_from_storedfile($filerecord, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +79,7 @@ if (!empty($add)) {
|
||||
|
||||
if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
|
||||
$draftid_editor = file_get_submitted_draft_itemid('introeditor');
|
||||
file_prepare_draft_area($draftid_editor, null, null, null);
|
||||
file_prepare_draft_area($draftid_editor, null, null, null, null);
|
||||
$data->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ if (!empty($add)) {
|
||||
|
||||
if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
|
||||
$draftid_editor = file_get_submitted_draft_itemid('introeditor');
|
||||
$currentintro = file_prepare_draft_area($draftid_editor, $context->id, $data->modulename.'_intro', 0, array('subdirs'=>true), $data->intro);
|
||||
$currentintro = file_prepare_draft_area($draftid_editor, $context->id, 'mod_'.$data->modulename, 'intro', 0, array('subdirs'=>true), $data->intro);
|
||||
$data->introeditor = array('text'=>$currentintro, 'format'=>$data->introformat, 'itemid'=>$draftid_editor);
|
||||
}
|
||||
|
||||
@ -321,7 +321,7 @@ if ($mform->is_cancelled()) {
|
||||
// update embedded links and save files
|
||||
if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
|
||||
$fromform->intro = file_save_draft_area_files($fromform->introeditor['itemid'], $modcontext->id,
|
||||
$fromform->modulename.'_intro', 0,
|
||||
'mod_'.$fromform->modulename, 'intro', 0,
|
||||
array('subdirs'=>true), $fromform->introeditor['text']);
|
||||
$fromform->introformat = $fromform->introeditor['format'];
|
||||
unset($fromform->introeditor);
|
||||
@ -425,7 +425,7 @@ if ($mform->is_cancelled()) {
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
|
||||
if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
|
||||
$fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id,
|
||||
$fromform->modulename.'_intro', 0,
|
||||
'mod_'.$fromform->modulename, 'intro', 0,
|
||||
array('subdirs'=>true), $introeditor['text']);
|
||||
$DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id'=>$fromform->instance));
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
|
||||
if (!empty($fromform->screenshots)) {
|
||||
$screenshots = $fromform->screenshots;
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files(get_context_instance(CONTEXT_USER, $USER->id)->id, 'user_draft', $screenshots);
|
||||
$files = $fs->get_area_files(get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'draft', $screenshots);
|
||||
if (!empty($files)) {
|
||||
$courseinfo->screenshots = $courseinfo->screenshots + count($files) - 1; //minus the ./ directory
|
||||
}
|
||||
@ -179,7 +179,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
|
||||
try {
|
||||
$courseids = $xmlrpcclient->call($serverurl, $registeredhub->token, $function, $params);
|
||||
} catch (Exception $e) {
|
||||
throw new moodle_exception('errorcoursepublish', 'hub',
|
||||
throw new moodle_exception('errorcoursepublish', 'hub',
|
||||
new moodle_url('/course/view.php', array('id' => $id)), $e->getMessage());
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE,
|
||||
} else {
|
||||
//redirect to the index publis page
|
||||
redirect(new moodle_url('/course/publish/index.php',
|
||||
array('sesskey' => sesskey(), 'id' => $id, 'published' => true,
|
||||
array('sesskey' => sesskey(), 'id' => $id, 'published' => true,
|
||||
'hubname' => $hubname, 'huburl' => $huburl)));
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ if ($scales = $DB->get_records("scale", array("courseid"=>$course->id), "name AS
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
|
||||
$scale->description = file_rewrite_pluginfile_urls($scale->description, 'pluginfile.php', $systemcontext->id, 'grade_scale', $scale->id);
|
||||
$scale->description = file_rewrite_pluginfile_urls($scale->description, 'pluginfile.php', $systemcontext->id, 'grade', 'scale', $scale->id);
|
||||
|
||||
$scalemenu = make_menu_from_list($scale->scale);
|
||||
|
||||
@ -110,7 +110,7 @@ if ($scales = $DB->get_records("scale", array("courseid"=>0), "name ASC")) {
|
||||
echo $OUTPUT->heading($strstandardscales);
|
||||
foreach ($scales as $scale) {
|
||||
|
||||
$scale->description = file_rewrite_pluginfile_urls($scale->description, 'pluginfile.php', $systemcontext->id, 'grade_scale', $scale->id);
|
||||
$scale->description = file_rewrite_pluginfile_urls($scale->description, 'pluginfile.php', $systemcontext->id, 'grade', 'scale', $scale->id);
|
||||
|
||||
$scalemenu = make_menu_from_list($scale->scale);
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
/**
|
||||
* This script serves draft files of current user
|
||||
*
|
||||
* @package moodlecore
|
||||
* @package core
|
||||
* @subpackage file
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
@ -52,11 +52,17 @@ if (count($args) == 0) { // always at least user id
|
||||
}
|
||||
|
||||
$contextid = (int)array_shift($args);
|
||||
$filearea = array_shift($args);
|
||||
$component = array_shift($args);
|
||||
$filearea = array_shift($args);
|
||||
$draftid = (int)array_shift($args);
|
||||
|
||||
if ($component !== 'user' or $filearea !== 'draft') {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
$context = get_context_instance_by_id($contextid);
|
||||
if ($context->contextlevel != CONTEXT_USER) {
|
||||
print_error('invalidarguments');
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
$userid = $context->instanceid;
|
||||
@ -64,20 +70,11 @@ if ($USER->id != $userid) {
|
||||
print_error('invaliduserid');
|
||||
}
|
||||
|
||||
switch ($filearea) {
|
||||
case 'user_draft':
|
||||
$itemid = (int)array_shift($args);
|
||||
break;
|
||||
default:
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
$relativepath = '/'.implode('/', $args);
|
||||
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$fullpath = $context->id.$filearea.$itemid.$relativepath;
|
||||
$relativepath = implode('/', $args);
|
||||
$fullpath = "/$context->id/user/draft/$draftid/$relativepath";
|
||||
|
||||
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->get_filename() == '.') {
|
||||
send_file_not_found();
|
||||
|
8
file.php
8
file.php
@ -62,7 +62,7 @@ if (count($args) == 0) { // always at least courseid, may search for index.html
|
||||
}
|
||||
|
||||
$courseid = (int)array_shift($args);
|
||||
$relativepath = '/'.implode('/', $args);
|
||||
$relativepath = implode('/', $args);
|
||||
|
||||
// security: limit access to existing course subdirectories
|
||||
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
|
||||
@ -77,8 +77,8 @@ if ($course->id != SITEID) {
|
||||
|
||||
} else if ($CFG->forcelogin) {
|
||||
if (!empty($CFG->sitepolicy)
|
||||
and ($CFG->sitepolicy == $CFG->wwwroot.'/file.php'.$relativepath
|
||||
or $CFG->sitepolicy == $CFG->wwwroot.'/file.php?file='.$relativepath)) {
|
||||
and ($CFG->sitepolicy == $CFG->wwwroot.'/file.php/'.$relativepath
|
||||
or $CFG->sitepolicy == $CFG->wwwroot.'/file.php?file=/'.$relativepath)) {
|
||||
//do not require login for policy file
|
||||
} else {
|
||||
require_login(0, true, null, false);
|
||||
@ -89,7 +89,7 @@ $context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$fullpath = $context->id.'course_content0'.$relativepath;
|
||||
$fullpath = "/$context->id/course/legacy/0/$relativepath";
|
||||
|
||||
if (!$file = $fs->get_file_by_hash(sha1($fullpath))) {
|
||||
if (strrpos($fullpath, '/') !== strlen($fullpath) -1 ) {
|
||||
|
@ -1,206 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Draft files management script used when javascript not available.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require('../config.php');
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
$itemid = required_param('itemid', PARAM_INT);
|
||||
$filepath = optional_param('filepath', '/', PARAM_PATH);
|
||||
$newdirname = optional_param('newdirname', '', PARAM_FILE);
|
||||
$delete = optional_param('delete', '', PARAM_PATH);
|
||||
$subdirs = optional_param('subdirs', 0, PARAM_BOOL);
|
||||
$maxbytes = optional_param('maxbytes', 0, PARAM_INT);
|
||||
|
||||
require_login();
|
||||
if (isguestuser()) {
|
||||
print_error('noguest');
|
||||
}
|
||||
|
||||
if (!$context = get_context_instance(CONTEXT_USER, $USER->id)) {
|
||||
print_error('invalidcontext');
|
||||
}
|
||||
|
||||
$notice = '';
|
||||
|
||||
$contextid = $context->id;
|
||||
$filearea = 'user_draft';
|
||||
|
||||
$browser = get_file_browser();
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (!$subdirs) {
|
||||
$filepath = '/';
|
||||
}
|
||||
|
||||
if (!$directory = $fs->get_file($context->id, 'user_draft', $itemid, $filepath, '.')) {
|
||||
$directory = new virtual_root_file($context->id, 'user_draft', $itemid);
|
||||
$filepath = $directory->get_filepath();
|
||||
}
|
||||
$files = $fs->get_directory_files($context->id, 'user_draft', $itemid, $directory->get_filepath());
|
||||
$parent = $directory->get_parent_directory();
|
||||
|
||||
$totalbytes = 0;
|
||||
foreach ($files as $hash=>$file) {
|
||||
if (!$subdirs and $file->get_filepath() !== '/') {
|
||||
unset($files[$hash]);
|
||||
continue;
|
||||
}
|
||||
$totalbytes += $file->get_filesize();
|
||||
}
|
||||
|
||||
/// process actions
|
||||
if ($newdirname !== '' and data_submitted() and confirm_sesskey()) {
|
||||
$newdirname = $directory->get_filepath().$newdirname.'/';
|
||||
$fs->create_directory($contextid, $filearea, $itemid, $newdirname, $USER->id);
|
||||
redirect('draftfiles.php?itemid='.$itemid.'&filepath='.rawurlencode($newdirname).'&subdirs='.$subdirs.'&maxbytes='.$maxbytes);
|
||||
}
|
||||
|
||||
if (isset($_FILES['newfile']) and data_submitted() and confirm_sesskey()) {
|
||||
if (!empty($_FILES['newfile']['error'])) {
|
||||
$notice = file_get_upload_error($_FILES['newfile']['error']);
|
||||
} else {
|
||||
$file = $_FILES['newfile'];
|
||||
$newfilename = clean_param($file['name'], PARAM_FILE);
|
||||
if (is_uploaded_file($_FILES['newfile']['tmp_name'])) {
|
||||
if ($existingfile = $fs->get_file($contextid, $filearea, $itemid, $filepath, $newfilename)) {
|
||||
$existingfile->delete();
|
||||
}
|
||||
$filerecord = array('contextid'=>$contextid, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath,
|
||||
'filename'=>$newfilename, 'userid'=>$USER->id);
|
||||
$newfile = $fs->create_file_from_pathname($filerecord, $_FILES['newfile']['tmp_name']);
|
||||
redirect('draftfiles.php?itemid='.$itemid.'&filepath='.rawurlencode($filepath).'&subdirs='.$subdirs.'&maxbytes='.$maxbytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($delete !== '' and $file = $fs->get_file($contextid, $filearea, $itemid, $filepath, $delete)) {
|
||||
if (!data_submitted() or !confirm_sesskey()) {
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->notification(get_string('deletecheckwarning').': '.s($file->get_filepath().$file->get_filename()));
|
||||
$optionsno = array('itemid'=>$itemid, 'filepath'=>$filepath, 'subdirs'=>$subdirs);
|
||||
$optionsyes = array('itemid'=>$itemid, 'filepath'=>$filepath, 'delete'=>$delete, 'sesskey'=>sesskey(), 'subdirs'=>$subdirs);
|
||||
echo $OUTPUT->confirm(get_string('deletecheckfiles'), new moodle_url('draftfiles.php', $optionsyes), new moodle_url('draftfiles.php', $optionsno));
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
|
||||
} else {
|
||||
$isdir = $file->is_directory();
|
||||
$file->delete();
|
||||
if ($isdir) {
|
||||
redirect('draftfiles.php?itemid='.$itemid.'&filepath='.rawurlencode($parent->get_filepath()).'&subdirs='.$subdirs.'&maxbytes='.$maxbytes);
|
||||
} else {
|
||||
redirect('draftfiles.php?itemid='.$itemid.'&filepath='.rawurlencode($filepath).'&subdirs='.$subdirs.'&maxbytes='.$maxbytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if ($notice !== '') {
|
||||
echo $OUTPUT->notification($notice);
|
||||
}
|
||||
|
||||
echo '<div class="areafiles">';
|
||||
|
||||
$strfolder = get_string('folder');
|
||||
$strfile = get_string('file');
|
||||
$strdownload = get_string('download');
|
||||
$strdelete = get_string('delete');
|
||||
|
||||
if ($parent) {
|
||||
echo '<div class="folder">';
|
||||
echo '<a href="draftfiles.php?itemid='.$itemid.'&filepath='.$parent->get_filepath().'&subdirs='.$subdirs.'&maxbytes='.$maxbytes.'"><img src="'.$OUTPUT->pix_url('f/parent') . '" class="icon" alt="" /> '.get_string('parentfolder').'</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$filename = $file->get_filename();
|
||||
$filenameurl = rawurlencode($filename);
|
||||
$filepath = $file->get_filepath();
|
||||
$filesize = $file->get_filesize();
|
||||
$filesize = $filesize ? display_size($filesize) : '';
|
||||
|
||||
$mimetype = $file->get_mimetype();
|
||||
|
||||
if ($file->is_directory()) {
|
||||
if ($subdirs) {
|
||||
$dirname = explode('/', trim($filepath, '/'));
|
||||
$dirname = array_pop($dirname);
|
||||
echo '<div class="folder">';
|
||||
echo "<a href=\"draftfiles.php?itemid=$itemid&filepath=$filepath&subdirs=$subdirs&maxbytes=$maxbytes\"><img src=\"" . $OUTPUT->pix_url('f/folder') . "\" class=\"icon\" alt=\"$strfolder\" /> ".s($dirname)."</a> ";
|
||||
echo "<a href=\"draftfiles.php?itemid=$itemid&filepath=$filepath&delete=$filenameurl&subdirs=$subdirs&maxbytes=$maxbytes\"><img src=\"" . $OUTPUT->pix_url('t/delete') . "\" class=\"iconsmall\" alt=\"$strdelete\" /></a>";
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
} else {
|
||||
$viewurl = file_encode_url("$CFG->wwwroot/draftfile.php", "/$contextid/user_draft/$itemid".$filepath.$filename, false, false);
|
||||
echo '<div class="file">';
|
||||
echo "<a href=\"$viewurl\"><img src=\"" . $OUTPUT->pix_url(file_mimetype_icon($mimetype)) . "\" class=\"icon\" alt=\"$strfile\" /> ".s($filename)." ($filesize)</a> ";
|
||||
echo "<a href=\"draftfiles.php?itemid=$itemid&filepath=$filepath&delete=$filenameurl&subdirs=$subdirs&maxbytes=$maxbytes\"><img src=\"" . $OUTPUT->pix_url('t/delete') . "\" class=\"iconsmall\" alt=\"$strdelete\" /></a>";;
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
if ($maxbytes == 0 or $maxbytes > $totalbytes) {
|
||||
echo '<form enctype="multipart/form-data" method="post" action="draftfiles.php"><div>';
|
||||
if ($maxbytes) {
|
||||
echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxbytes-$totalbytes).'" />';
|
||||
}
|
||||
echo '<input type="hidden" name="itemid" value="'.$itemid.'" />';
|
||||
echo '<input type="hidden" name="filepath" value="'.s($filepath).'" />';
|
||||
echo '<input type="hidden" name="subdirs" value="'.$subdirs.'" />';
|
||||
echo '<input type="hidden" name="maxbytes" value="'.$maxbytes.'" />';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
echo '<input name="newfile" type="file" />';
|
||||
echo '<input type="submit" value="'.get_string('uploadafile').'" />';
|
||||
if ($maxbytes) {
|
||||
echo ' ('.get_string('maxsize', '', display_size(get_max_upload_file_size($CFG->maxbytes, $maxbytes-$totalbytes))).')';
|
||||
} else {
|
||||
echo ' ('.get_string('maxsize', '', display_size(get_max_upload_file_size($CFG->maxbytes))).')';
|
||||
}
|
||||
echo '</div></form>';
|
||||
} else {
|
||||
//TODO: notify upload limit reached here
|
||||
echo get_string('maxsize', '', display_size(get_max_upload_file_size($CFG->maxbytes, $maxbytes)));
|
||||
}
|
||||
|
||||
if ($subdirs) {
|
||||
echo '<form action="draftfiles.php" method="post"><div>';
|
||||
echo '<input type="hidden" name="itemid" value="'.$itemid.'" />';
|
||||
echo '<input type="hidden" name="filepath" value="'.s($filepath).'" />';
|
||||
echo '<input type="hidden" name="subdirs" value="'.$subdirs.'" />';
|
||||
echo '<input type="hidden" name="maxbytes" value="'.$maxbytes.'" />';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
echo '<input type="text" name="newdirname" value="" />';
|
||||
echo '<input type="submit" value="'.get_string('makeafolder').'" />';
|
||||
echo '</div></form>';
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
@ -38,8 +38,9 @@ class moodle_file_external extends external_api {
|
||||
array(
|
||||
'params' => new external_single_structure(array(
|
||||
'contextid' => new external_value(PARAM_INT, 'context id'),
|
||||
'itemid' => new external_value(PARAM_INT, 'associated id'),
|
||||
'component' => new external_value(PARAM_TEXT, 'component'),
|
||||
'filearea' => new external_value(PARAM_TEXT, 'file area'),
|
||||
'itemid' => new external_value(PARAM_INT, 'associated id'),
|
||||
'filepath' => new external_value(PARAM_RAW, 'file path'),
|
||||
'filename' => new external_value(PARAM_TEXT, 'file name'),
|
||||
)
|
||||
@ -54,7 +55,21 @@ class moodle_file_external extends external_api {
|
||||
* @return array
|
||||
*/
|
||||
public static function get_files($fileinfo) {
|
||||
|
||||
throw new coding_exception('File browsing api function is not implemented yet, sorry');
|
||||
|
||||
global $CFG, $USER, $OUTPUT;
|
||||
if (empty($fileinfo['contextid'])) {
|
||||
$context = get_system_context();
|
||||
} else {
|
||||
$context = get_context_instance_by_id($fileinfo['contextid']);
|
||||
}
|
||||
if (empty($fileinfo['component'])) {
|
||||
$fileinfo['component'] = null;
|
||||
}
|
||||
if (empty($fileinfo['filearea'])) {
|
||||
$fileinfo['filearea'] = null;
|
||||
}
|
||||
if (empty($fileinfo['itemid'])) {
|
||||
$fileinfo['itemid'] = null;
|
||||
}
|
||||
@ -64,14 +79,6 @@ class moodle_file_external extends external_api {
|
||||
if (empty($fileinfo['filepath'])) {
|
||||
$fileinfo['filepath'] = null;
|
||||
}
|
||||
if (empty($fileinfo['filearea'])) {
|
||||
$fileinfo['filearea'] = null;
|
||||
}
|
||||
if (empty($fileinfo['contextid'])) {
|
||||
$context = get_system_context();
|
||||
} else {
|
||||
$context = get_context_instance_by_id($fileinfo['contextid']);
|
||||
}
|
||||
try {
|
||||
$browser = get_file_browser();
|
||||
|
||||
@ -79,7 +86,7 @@ class moodle_file_external extends external_api {
|
||||
$return['parents'] = array();
|
||||
$return['files'] = array();
|
||||
$file = $browser->get_file_info($context, null, null, null, null);
|
||||
if ($file = $browser->get_file_info($context, $fileinfo['filearea'], $fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename'])) {
|
||||
if ($file = $browser->get_file_info($context, $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename'])) {
|
||||
$level = $file->get_parent();
|
||||
while ($level) {
|
||||
$params = $level->get_params();
|
||||
@ -93,24 +100,28 @@ class moodle_file_external extends external_api {
|
||||
$params = $child->get_params();
|
||||
if ($child->is_directory()) {
|
||||
$node = array(
|
||||
'filename' => $child->get_visible_name(),
|
||||
'filepath' => $params['filepath'],
|
||||
'filearea' => $params['filearea'],
|
||||
'itemid' => $params['itemid'],
|
||||
//TODO: this is wrong, you need to fetch info from the child node!!!!
|
||||
'contextid' => $params['contextid'],
|
||||
'url' => null,
|
||||
'isdir'=>true
|
||||
'component' => $params['component'],
|
||||
'filearea' => $params['filearea'],
|
||||
'itemid' => $params['itemid'],
|
||||
'filepath' => $params['filepath'],
|
||||
'filename' => $child->get_visible_name(),
|
||||
'url' => null,
|
||||
'isdir' =>true
|
||||
);
|
||||
$list[] = $node;
|
||||
} else {
|
||||
$node = array(
|
||||
'filename' => $child->get_visible_name(),
|
||||
'filepath' => $params['filepath'],
|
||||
'filearea' => $params['filearea'],
|
||||
'itemid' => $params['itemid'],
|
||||
//TODO: this is wrong, you need to fetch info from the child node!!!!
|
||||
'contextid' => $params['contextid'],
|
||||
'url' => $child->get_url(),
|
||||
'isdir'=>false
|
||||
'component' => $params['component'],
|
||||
'filearea' => $params['filearea'],
|
||||
'itemid' => $params['itemid'],
|
||||
'filepath' => $params['filepath'],
|
||||
'filename' => $child->get_visible_name(),
|
||||
'url' => $child->get_url(),
|
||||
'isdir' => false
|
||||
);
|
||||
$list[] = $node;
|
||||
}
|
||||
@ -134,23 +145,25 @@ class moodle_file_external extends external_api {
|
||||
new external_single_structure(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, ''),
|
||||
'filename' => new external_value(PARAM_TEXT, ''),
|
||||
'filearea' => new external_value(PARAM_TEXT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'itemid' => new external_value(PARAM_INT, '')
|
||||
'component' => new external_value(PARAM_ALPHAEXT, ''),
|
||||
'filearea' => new external_value(PARAM_ALPHAEXT, ''),
|
||||
'itemid' => new external_value(PARAM_INT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'filename' => new external_value(PARAM_TEXT, ''),
|
||||
)
|
||||
)
|
||||
),
|
||||
'files' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'filename' => new external_value(PARAM_TEXT, ''),
|
||||
'filearea' => new external_value(PARAM_TEXT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'contextid' => new external_value(PARAM_INT, ''),
|
||||
'component' => new external_value(PARAM_ALPHAEXT, ''),
|
||||
'filearea' => new external_value(PARAM_ALPHAEXT, ''),
|
||||
'itemid' => new external_value(PARAM_INT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'filename' => new external_value(PARAM_TEXT, ''),
|
||||
'isdir' => new external_value(PARAM_BOOL, ''),
|
||||
'url' => new external_value(PARAM_TEXT, ''),
|
||||
'contextid' => new external_value(PARAM_INT, '')
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -167,8 +180,9 @@ class moodle_file_external extends external_api {
|
||||
array(
|
||||
'params' => new external_single_structure(array(
|
||||
'contextid' => new external_value(PARAM_INT, 'context id'),
|
||||
'filearea' => new external_value(PARAM_ALPHAEXT, 'file area'),
|
||||
'component' => new external_value(PARAM_ALPHAEXT, 'component'),
|
||||
'itemid' => new external_value(PARAM_INT, 'associated id'),
|
||||
'filearea' => new external_value(PARAM_TEXT, 'file area'),
|
||||
'filepath' => new external_value(PARAM_RAW, 'file path'),
|
||||
'filename' => new external_value(PARAM_TEXT, 'file name'),
|
||||
'filecontent' => new external_value(PARAM_TEXT, 'file content')
|
||||
@ -215,6 +229,9 @@ class moodle_file_external extends external_api {
|
||||
file_put_contents($savedfilepath, base64_decode($fileinfo['filecontent']));
|
||||
unset($fileinfo['filecontent']);
|
||||
|
||||
$component = $fileinfo['component'];
|
||||
|
||||
//TODO: mandatory!!!
|
||||
if (!empty($fileinfo['filearea'])) {
|
||||
$filearea = $fileinfo['filearea'];
|
||||
} else {
|
||||
@ -226,7 +243,7 @@ class moodle_file_external extends external_api {
|
||||
} else {
|
||||
$filepath = '';
|
||||
}
|
||||
|
||||
|
||||
if (isset($fileinfo['itemid'])) {
|
||||
$itemid = $fileinfo['itemid'];
|
||||
} else {
|
||||
@ -238,16 +255,21 @@ class moodle_file_external extends external_api {
|
||||
$context = get_system_context();
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
// TODO: we MUST obey access control restrictions here, no messing with file_storage here, the only allowed way is to use file_browser here!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
throw new coding_exception('File upload ext api needs to be made secure first!!!!');
|
||||
|
||||
|
||||
$browser = get_file_browser();
|
||||
|
||||
// check existing file
|
||||
if ($file = $fs->get_file($context->id, $filearea, $itemid, $filepath, $filename)) {
|
||||
if ($file = $fs->get_file($context->id, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||
throw new moodle_exception('fileexist');
|
||||
}
|
||||
|
||||
$file_record = new object();
|
||||
$file_record->contextid = $context->id;
|
||||
$file_record->component = $component;
|
||||
$file_record->filearea = $filearea;
|
||||
$file_record->itemid = $itemid;
|
||||
$file_record->filepath = $filepath;
|
||||
|
90
files/filebrowser_ajax.php
Executable file
90
files/filebrowser_ajax.php
Executable file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* File manager support
|
||||
*
|
||||
* @package core
|
||||
* @subpackage file
|
||||
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define('AJAX_SCRIPT', true);
|
||||
|
||||
require('../config.php');
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
$action = optional_param('action', 'list', PARAM_ALPHA);
|
||||
|
||||
require_login();
|
||||
|
||||
$err = new stdclass;
|
||||
|
||||
if (isguestuser()) {
|
||||
$err->error = get_string('noguest');
|
||||
die(json_encode($err));
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
// used by course file tree viewer
|
||||
case 'getfiletree':
|
||||
|
||||
$contextid = required_param('contextid', PARAM_INT);
|
||||
$component = required_param('component', PARAM_ALPHAEXT);
|
||||
$filearea = required_param('filearea', PARAM_ALPHAEXT);
|
||||
$itemid = required_param('itemid', PARAM_INT);
|
||||
$filepath = required_param('filepath', PARAM_PATH);
|
||||
|
||||
$browser = get_file_browser();
|
||||
$params = $url->params();
|
||||
// fix empty value
|
||||
foreach ($params as $key=>$value) {
|
||||
if ($value==='') {
|
||||
$params[$key] = null;
|
||||
}
|
||||
}
|
||||
$fileinfo = $browser->get_file_info(get_context_instance_by_id($contextid, $component, $filearea, $itemid, $filepath));
|
||||
$children = $fileinfo->get_children();
|
||||
$tree = array();
|
||||
foreach ($children as $child) {
|
||||
$filedate = $child->get_timemodified();
|
||||
$filesize = $child->get_filesize();
|
||||
$mimetype = $child->get_mimetype();
|
||||
$params = $child->get_params();
|
||||
$url = new moodle_url('/files/index.php', $params);
|
||||
$fileitem = array(
|
||||
'params'=>$params,
|
||||
'filename'=>$child->get_visible_name(),
|
||||
'filedate'=>$filedate ? userdate($filedate) : '',
|
||||
'filesize'=>$filesize ? display_size($filesize) : '',
|
||||
);
|
||||
if ($child->is_directory()) {
|
||||
$fileitem['isdir'] = true;
|
||||
$fileitem['url'] = $url->out();
|
||||
} else {
|
||||
$fileitem['url'] = $child->get_url();
|
||||
}
|
||||
$tree[] = $fileitem;
|
||||
}
|
||||
echo json_encode($tree);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
@ -1,264 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* File manager
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file
|
||||
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require('../config.php');
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
require_login();
|
||||
|
||||
$err = new stdclass;
|
||||
|
||||
if (isguestuser()) {
|
||||
$err->error = get_string('noguest');
|
||||
die(json_encode($err));
|
||||
}
|
||||
|
||||
if (!confirm_sesskey()) {
|
||||
$err->error = get_string('invalidsesskey');
|
||||
die(json_encode($err));
|
||||
}
|
||||
|
||||
$action = optional_param('action', 'list', PARAM_ALPHA);
|
||||
$fileurl = optional_param('fileurl', '', PARAM_URL);
|
||||
$filename = optional_param('filename', '', PARAM_FILE);
|
||||
$filearea = optional_param('filearea', 'user_draft', PARAM_ALPHAEXT);
|
||||
$filepath = optional_param('filepath', '/', PARAM_PATH);
|
||||
$itemid = optional_param('itemid', -1, PARAM_INT);
|
||||
$newfilepath = optional_param('newfilepath', '/', PARAM_PATH);
|
||||
$newdirname = optional_param('newdirname', '', PARAM_FILE);
|
||||
$newfilename = optional_param('newfilename', '', PARAM_FILE);
|
||||
|
||||
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
|
||||
switch ($action) {
|
||||
// used by course file tree viewer
|
||||
case 'getfiletree':
|
||||
$browser = get_file_browser();
|
||||
$fs = get_file_storage();
|
||||
$url = new moodle_url($fileurl);
|
||||
$params = $url->params();
|
||||
// fix empty value
|
||||
foreach ($params as $key=>$value) {
|
||||
if ($value==='') {
|
||||
$params[$key] = null;
|
||||
}
|
||||
}
|
||||
$fileinfo = $browser->get_file_info(get_context_instance_by_id($params['contextid']), $params['filearea'], $params['itemid'], $params['filepath']);
|
||||
$children = $fileinfo->get_children();
|
||||
$tree = array();
|
||||
foreach ($children as $child) {
|
||||
$filedate = $child->get_timemodified();
|
||||
$filesize = $child->get_filesize();
|
||||
$mimetype = $child->get_mimetype();
|
||||
$params = $child->get_params();
|
||||
$url = new moodle_url('/files/index.php', $params);
|
||||
$fileitem = array(
|
||||
'params'=>$params,
|
||||
'filename'=>$child->get_visible_name(),
|
||||
'filedate'=>$filedate ? userdate($filedate) : '',
|
||||
'filesize'=>$filesize ? display_size($filesize) : '',
|
||||
);
|
||||
if ($child->is_directory()) {
|
||||
$fileitem['isdir'] = true;
|
||||
$fileitem['url'] = $url->out();
|
||||
|
||||
// hide empty folder
|
||||
if (!empty($params['itemid'])) {
|
||||
$itemid = $params['itemid'];
|
||||
} else {
|
||||
$itemid = false;
|
||||
}
|
||||
$draftfiles = $fs->get_area_files($params['contextid'], $params['filearea'], $itemid, 'id', false);
|
||||
if (count($draftfiles) == 0) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$fileitem['url'] = $child->get_url();
|
||||
}
|
||||
$tree[] = $fileitem;
|
||||
}
|
||||
echo json_encode($tree);
|
||||
|
||||
break;
|
||||
case 'dir':
|
||||
$data = new stdclass;
|
||||
file_get_user_area_folders($itemid, $filepath, $data, $filearea);
|
||||
echo json_encode($data);
|
||||
break;
|
||||
|
||||
case 'list':
|
||||
$data = file_get_user_area_files($itemid, $filepath, $filearea);
|
||||
echo json_encode($data);
|
||||
break;
|
||||
|
||||
case 'mkdir':
|
||||
$fs = get_file_storage();
|
||||
$fs->create_directory($user_context->id, $filearea, $itemid, file_correct_filepath(file_correct_filepath($filepath).$newdirname));
|
||||
$return = new stdclass;
|
||||
$return->filepath = $filepath;
|
||||
echo json_encode($return);
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$fs = get_file_storage();
|
||||
$filepath = file_correct_filepath($filepath);
|
||||
$return = new stdclass;
|
||||
if ($stored_file = $fs->get_file($user_context->id, $filearea, $itemid, $filepath, $filename)) {
|
||||
$parent_path = $stored_file->get_parent_directory()->get_filepath();
|
||||
if($result = $stored_file->delete()) {
|
||||
$return->filepath = $parent_path;
|
||||
echo json_encode($return);
|
||||
} else {
|
||||
echo json_encode(false);
|
||||
}
|
||||
} else {
|
||||
echo json_encode(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'setmainfile':
|
||||
$filepath = file_correct_filepath($filepath);
|
||||
// reset sort order
|
||||
file_reset_sortorder($user_context->id, $filearea, $itemid);
|
||||
// set main file
|
||||
$return = file_set_sortorder($user_context->id, $filearea, $itemid, $filepath, $filename, 1);
|
||||
echo json_encode($return);
|
||||
break;
|
||||
|
||||
case 'renamedir':
|
||||
$fs = get_file_storage();
|
||||
$fb = get_file_browser();
|
||||
$return = new stdclass;
|
||||
$fileinfo = $fb->get_file_info($user_context, $filearea, $itemid, $filepath, '.');
|
||||
if ($result = $fileinfo->delete()) {
|
||||
$newdir = $fs->create_directory($user_context->id, $filearea, $itemid, file_correct_filepath($newfilename));
|
||||
$return->filepath = $newdir->get_parent_directory()->get_filepath();
|
||||
echo json_encode($return);
|
||||
} else {
|
||||
echo json_encode(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'rename':
|
||||
$fb = get_file_browser();
|
||||
$file = $fb->get_file_info($user_context, $filearea, $itemid, $filepath, $filename);
|
||||
$file->copy_to_storage($user_context->id, $filearea, $itemid, $filepath, $newfilename);
|
||||
if ($file->delete()) {
|
||||
$return = new stdclass;
|
||||
$return->filepath = $filepath;
|
||||
echo json_encode($return);
|
||||
} else {
|
||||
echo json_encode(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'movefile':
|
||||
case 'movedir':
|
||||
$fb = get_file_browser();
|
||||
$return = new stdclass;
|
||||
if ($filepath != $newfilepath) {
|
||||
$file = $fb->get_file_info($user_context, $filearea, $itemid, $filepath, $filename);
|
||||
$file->copy_to_storage($user_context->id, $filearea, $itemid, $newfilepath, $filename);
|
||||
if ($file->delete()) {
|
||||
$return->filepath = $newfilepath;
|
||||
}
|
||||
}
|
||||
if (!isset($return->filepath)) {
|
||||
$return->filepath = '/';
|
||||
}
|
||||
echo json_encode($return);
|
||||
break;
|
||||
|
||||
case 'zip':
|
||||
$zipper = new zip_packer();
|
||||
$fs = get_file_storage();
|
||||
|
||||
$file = $fs->get_file($user_context->id, $filearea, $itemid, $filepath, '.');
|
||||
|
||||
$parent_path = $file->get_parent_directory()->get_filepath();
|
||||
|
||||
if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, $filearea, $itemid, $parent_path, $filepath.'.zip', $USER->id)) {
|
||||
$return = new stdclass;
|
||||
$return->filepath = $parent_path;
|
||||
echo json_encode($return);
|
||||
} else {
|
||||
echo json_encode(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'downloaddir':
|
||||
$zipper = new zip_packer();
|
||||
$fs = get_file_storage();
|
||||
$area = file_get_user_area_info($itemid, $filearea);
|
||||
if ($area['filecount'] == 0) {
|
||||
echo json_encode(false);
|
||||
die;
|
||||
}
|
||||
|
||||
$stored_file = $fs->get_file($user_context->id, $filearea, $itemid, $filepath, '.');
|
||||
if ($filepath === '/') {
|
||||
$parent_path = '/';
|
||||
$filename = get_string('files').'.zip';
|
||||
} else {
|
||||
$parent_path = $stored_file->get_parent_directory()->get_filepath();
|
||||
$filename = trim($filepath, '/').'.zip';
|
||||
}
|
||||
|
||||
// archive compressed file to an unused draft area
|
||||
$newdraftitemid = file_get_unused_draft_itemid();
|
||||
if ($newfile = $zipper->archive_to_storage(array($stored_file), $user_context->id, 'user_draft', $newdraftitemid, '/', $filename, $USER->id)) {
|
||||
$return = new stdclass;
|
||||
$return->fileurl = $CFG->wwwroot . '/draftfile.php/' . $user_context->id .'/user_draft/'.$newdraftitemid.'/'.$filename;
|
||||
$return->filepath = $parent_path;
|
||||
echo json_encode($return);
|
||||
} else {
|
||||
echo json_encode(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'unzip':
|
||||
$zipper = new zip_packer();
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$file = $fs->get_file($user_context->id, $filearea, $itemid, $filepath, $filename);
|
||||
|
||||
if ($newfile = $file->extract_to_storage($zipper, $user_context->id, $filearea, $itemid, $filepath, $USER->id)) {
|
||||
$return = new stdclass;
|
||||
$return->filepath = $filepath;
|
||||
echo json_encode($return);
|
||||
} else {
|
||||
echo json_encode(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'upload':
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
/**
|
||||
* Moodle file tree viewer based on YUI2 Treeview
|
||||
*
|
||||
* @package moodlecore
|
||||
* @package core
|
||||
* @subpackage file
|
||||
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
@ -26,35 +26,19 @@
|
||||
|
||||
require('../config.php');
|
||||
|
||||
$courseid = optional_param('id', 0, PARAM_INT);
|
||||
|
||||
$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
|
||||
$component = optional_param('component', '', PARAM_ALPHAEXT);
|
||||
$filearea = optional_param('filearea', '', PARAM_ALPHAEXT);
|
||||
$itemid = optional_param('itemid', -1, PARAM_INT);
|
||||
$filepath = optional_param('filepath', '', PARAM_PATH);
|
||||
$filename = optional_param('filename', '', PARAM_FILE);
|
||||
|
||||
if ($courseid) {
|
||||
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
|
||||
redirect(new moodle_url('index.php', array('contextid' => $context->id, 'itemid'=> 0, 'filearea' => 'course_content')));
|
||||
$PAGE->set_url('/files/index.php', array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename));
|
||||
|
||||
if ($component === '') {
|
||||
$component = null;
|
||||
}
|
||||
|
||||
$context = get_context_instance_by_id($contextid, MUST_EXIST);
|
||||
$PAGE->set_context($context);
|
||||
|
||||
$course = null;
|
||||
$cm = null;
|
||||
if ($context->contextlevel == CONTEXT_MODULE) {
|
||||
$cm = get_coursemodule_from_id(null, $context->instanceid, 0, false, MUST_EXIST);
|
||||
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
|
||||
} else if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
$course = $DB->get_record('course', array('id'=>$context->instanceid), '*', MUST_EXIST);
|
||||
}
|
||||
|
||||
require_login($course, false, $cm);
|
||||
require_capability('moodle/course:managefiles', $context);
|
||||
|
||||
if ($filearea === '') {
|
||||
$filearea = null;
|
||||
}
|
||||
@ -71,11 +55,21 @@ if ($filename === '') {
|
||||
$filename = null;
|
||||
}
|
||||
|
||||
list($context, $course, $cm) = get_context_info_array($contextid);
|
||||
|
||||
require_login($course, false, $cm);
|
||||
require_capability('moodle/course:managefiles', $context);
|
||||
|
||||
$browser = get_file_browser();
|
||||
|
||||
$file_info = $browser->get_file_info($context, $filearea, $itemid, $filepath, $filename);
|
||||
$file_info = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename);
|
||||
|
||||
$strfiles = get_string("files");
|
||||
|
||||
$PAGE->navbar->add($strfiles);
|
||||
$PAGE->set_title("$SITE->shortname: $strfiles");
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
|
||||
if ($context->contextlevel == CONTEXT_MODULE) {
|
||||
$PAGE->set_pagelayout('incourse');
|
||||
} else if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
@ -84,16 +78,20 @@ if ($context->contextlevel == CONTEXT_MODULE) {
|
||||
$PAGE->set_pagelayout('admin');
|
||||
}
|
||||
|
||||
$PAGE->navbar->add($strfiles);
|
||||
$PAGE->set_url("/files/index.php", $file_info->get_params());
|
||||
$PAGE->set_title("$SITE->shortname: $strfiles");
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
echo $OUTPUT->header();
|
||||
$output = $PAGE->get_renderer('core', 'files');
|
||||
|
||||
$options = array();
|
||||
$options['enabled_fileareas'] = array('section_backup', 'course_backup', 'course_content', 'user_backup');
|
||||
echo $OUTPUT->box_start();
|
||||
echo $OUTPUT->moodle_file_tree_viewer($context->id, $filearea, $itemid, $filepath, $options);
|
||||
echo $OUTPUT->box_end();
|
||||
echo $output->header();
|
||||
echo $output->box_start();
|
||||
|
||||
if ($file_info) {
|
||||
$options = array();
|
||||
//$options['visible_areas'] = array('backup'=>array('section', 'course'), 'course'=>array('legacy'), 'user'=>array('backup'));
|
||||
echo $output->files_tree_viewer($file_info, $options);
|
||||
} else {
|
||||
notify(get_string('nofilesavailable', 'repository'));
|
||||
}
|
||||
|
||||
echo $output->box_end();
|
||||
|
||||
echo $output->footer();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Author: Dongsheng Cai <dongsheng@moodle.com>
|
||||
M.core_filetree = {
|
||||
y3: null,
|
||||
api: M.cfg.wwwroot+'/files/files_ajax.php',
|
||||
api: M.cfg.wwwroot+'/files/filebrowser_ajax.php',
|
||||
request: function(url, node, cb) {
|
||||
var api = this.api + '?action=getfiletree';
|
||||
var params = [];
|
||||
|
156
files/renderer.php
Normal file
156
files/renderer.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// This file is part of Moodle - http://moodle.org/ //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// //
|
||||
// Moodle is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Moodle is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Rendering of files viewer related widgets.
|
||||
* @package core
|
||||
* @subpackage file
|
||||
* @copyright 2010 Dongsheng Cai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* File manager render
|
||||
*
|
||||
* @copyright 2010 Dongsheng Cai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class core_files_renderer extends plugin_renderer_base {
|
||||
|
||||
public function files_tree_viewer(file_info $file_info, array $options = null) {
|
||||
$tree = new files_tree_viewer($file_info, $options);
|
||||
return $this->render($tree);
|
||||
}
|
||||
|
||||
public function render_files_tree_viewer(files_tree_viewer $tree) {
|
||||
|
||||
$html = '<div>';
|
||||
foreach($tree->path as $path) {
|
||||
$html .= $path;
|
||||
$html .= ' / ';
|
||||
}
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div id="course-file-tree-view" class="filemanager-container">';
|
||||
if (empty($tree->tree)) {
|
||||
$html .= get_string('nofilesavailable', 'repository');
|
||||
} else {
|
||||
$this->page->requires->js_init_call('M.core_filetree.init');
|
||||
$html .= '<ul>';
|
||||
foreach($tree->tree as $node) {
|
||||
$link_attributes = array();
|
||||
if (!empty($node['isdir'])) {
|
||||
$class = ' class="file-tree-folder"';
|
||||
} else {
|
||||
$class = ' class="file-tree-file"';
|
||||
$link_attributes['target'] = '_blank';
|
||||
}
|
||||
$html .= '<li '.$class.'>';
|
||||
$html .= html_writer::link($node['url'], $node['filename'], $link_attributes);
|
||||
$html .= '</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Data structure representing a general moodle file tree viewer
|
||||
*
|
||||
* @copyright 2010 Dongsheng Cai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class files_tree_viewer implements renderable {
|
||||
public $tree;
|
||||
public $path;
|
||||
|
||||
/**
|
||||
* Constructor of moodle_file_tree_viewer class
|
||||
* @param file_info $file_info
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(file_info $file_info, array $options = null) {
|
||||
global $CFG;
|
||||
|
||||
//note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
$this->options = (array)$options;
|
||||
if (isset($this->options['visible_areas'])) {
|
||||
$visible_areas = (array)$this->options['visible_areas'];
|
||||
} else {
|
||||
$visible_areas = false;
|
||||
}
|
||||
|
||||
$this->tree = array();
|
||||
$children = $file_info->get_children();
|
||||
$parent_info = $file_info->get_parent();
|
||||
|
||||
$level = $parent_info;
|
||||
$this->path = array();
|
||||
while ($level) {
|
||||
$params = $level->get_params();
|
||||
$context = get_context_instance_by_id($params['contextid']);
|
||||
// lock user in course level
|
||||
if ($context->contextlevel == CONTEXT_COURSECAT or $context->contextlevel == CONTEXT_SYSTEM) {
|
||||
break;
|
||||
}
|
||||
$url = new moodle_url('/files/index.php', $params);
|
||||
$this->path[] = html_writer::link($url->out(false), $level->get_visible_name());
|
||||
$level = $level->get_parent();
|
||||
}
|
||||
$this->path = array_reverse($this->path);
|
||||
$this->path[] = $file_info->get_visible_name();
|
||||
|
||||
foreach ($children as $child) {
|
||||
$filedate = $child->get_timemodified();
|
||||
$filesize = $child->get_filesize();
|
||||
$mimetype = $child->get_mimetype();
|
||||
$params = $child->get_params();
|
||||
$url = new moodle_url('/files/index.php', $params);
|
||||
$fileitem = array(
|
||||
'params' => $params,
|
||||
'filename' => $child->get_visible_name(),
|
||||
'filedate' => $filedate ? userdate($filedate) : '',
|
||||
'filesize' => $filesize ? display_size($filesize) : ''
|
||||
);
|
||||
if ($child->is_directory()) {
|
||||
$fileitem['isdir'] = true;
|
||||
$fileitem['url'] = $url->out(false);
|
||||
if ($visible_areas !== false) {
|
||||
if (!isset($visible_areas[$params['component']][$params['filearea']])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$fileitem['url'] = $child->get_url();
|
||||
}
|
||||
$this->tree[] = $fileitem;
|
||||
}
|
||||
}
|
||||
}
|
@ -96,9 +96,9 @@ $returnurl = $gpr->get_return_url('index.php?id='.$courseid);
|
||||
$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
|
||||
|
||||
if (!empty($outcome_rec->id)) {
|
||||
$outcome_rec = file_prepare_standard_editor($outcome_rec, 'description', $editoroptions, $systemcontext, 'grade_outcome', $outcome_rec->id);
|
||||
$outcome_rec = file_prepare_standard_editor($outcome_rec, 'description', $editoroptions, $systemcontext, 'grade', 'outcome', $outcome_rec->id);
|
||||
} else {
|
||||
$outcome_rec = file_prepare_standard_editor($outcome_rec, 'description', $editoroptions, $systemcontext, 'grade_outcome', null);
|
||||
$outcome_rec = file_prepare_standard_editor($outcome_rec, 'description', $editoroptions, $systemcontext, 'grade', 'outcome', null);
|
||||
}
|
||||
|
||||
$mform = new edit_outcome_form(null, compact('gpr', 'editoroptions'));
|
||||
@ -124,10 +124,10 @@ if ($mform->is_cancelled()) {
|
||||
}
|
||||
$outcome->insert();
|
||||
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade_outcome', $outcome->id);
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'outcome', $outcome->id);
|
||||
$DB->set_field($outcome->table, 'description', $data->description, array('id'=>$outcome->id));
|
||||
} else {
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade_outcome', $id);
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'outcome', $id);
|
||||
grade_outcome::set_properties($outcome, $data);
|
||||
if (isset($data->standard)) {
|
||||
$outcome->courseid = !empty($data->standard) ? null : $courseid;
|
||||
|
@ -90,9 +90,9 @@ $returnurl = $gpr->get_return_url('index.php?id='.$courseid);
|
||||
$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
|
||||
|
||||
if (!empty($scale_rec->id)) {
|
||||
$scale_rec = file_prepare_standard_editor($scale_rec, 'description', $editoroptions, $systemcontext, 'grade_scale', $scale_rec->id);
|
||||
$scale_rec = file_prepare_standard_editor($scale_rec, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $scale_rec->id);
|
||||
} else {
|
||||
$scale_rec = file_prepare_standard_editor($scale_rec, 'description', $editoroptions, $systemcontext, 'grade_scale', null);
|
||||
$scale_rec = file_prepare_standard_editor($scale_rec, 'description', $editoroptions, $systemcontext, 'grade', 'scale', null);
|
||||
}
|
||||
$mform = new edit_scale_form(null, compact('gpr', 'editoroptions'));
|
||||
|
||||
@ -113,10 +113,10 @@ if ($mform->is_cancelled()) {
|
||||
}
|
||||
$scale->courseid = !empty($data->standard) ? 0 : $courseid;
|
||||
$scale->insert();
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade_scale', $scale->id);
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $scale->id);
|
||||
$DB->set_field($scale->table, 'description', $data->description, array('id'=>$scale->id));
|
||||
} else {
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade_scale', $id);
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $id);
|
||||
grade_scale::set_properties($scale, $data);
|
||||
if (isset($data->standard)) {
|
||||
$scale->courseid = !empty($data->standard) ? 0 : $courseid;
|
||||
|
@ -98,7 +98,7 @@ class edit_grade_form extends moodleform {
|
||||
$mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
||||
|
||||
// Feedback format is automatically converted to html if user has enabled editor
|
||||
$feedbackoptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>true);
|
||||
$feedbackoptions = array('maxfiles'=>0, 'maxbytes'=>0); //TODO: no files here for now, if ever gets implemented use component 'grade' and filearea 'feedback'
|
||||
$mform->addElement('editor', 'feedback', get_string('feedback', 'grades'), null, $feedbackoptions);
|
||||
$mform->addHelpButton('feedback', 'feedback', 'grades');
|
||||
$mform->setType('text', PARAM_RAW); // to be cleaned before display, no XSS risk
|
||||
|
@ -85,9 +85,9 @@ if ($id and $delete) {
|
||||
// Prepare the description editor: We do support files for group descriptions
|
||||
$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>false, 'context'=>$context, 'noclean'=>true);
|
||||
if (!empty($group->id)) {
|
||||
$group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'course_group_description', $group->id);
|
||||
$group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id);
|
||||
} else {
|
||||
$group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'course_group_description', null);
|
||||
$group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
|
||||
}
|
||||
|
||||
/// First create the form
|
||||
|
@ -80,9 +80,9 @@ if ($id and $delete) {
|
||||
// Prepare the description editor: We do support files for grouping descriptions
|
||||
$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>true, 'context'=>$context, 'noclean'=>true);
|
||||
if (!empty($grouping->id)) {
|
||||
$grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'course_grouping_description', $grouping->id);
|
||||
$grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'grouping', 'description', $grouping->id);
|
||||
} else {
|
||||
$grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'course_grouping_description', null);
|
||||
$grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'grouping', 'description', null);
|
||||
}
|
||||
|
||||
/// First create the form
|
||||
|
@ -148,7 +148,7 @@ function groups_create_group($data, $editform=false, $editoroptions=null) {
|
||||
$description = new stdClass;
|
||||
$description->id = $data->id;
|
||||
$description->description_editor = $data->description_editor;
|
||||
$description = file_postupdate_standard_editor($description, 'description', $editoroptions, $editoroptions['context'], 'course_group_description', $description->id);
|
||||
$description = file_postupdate_standard_editor($description, 'description', $editoroptions, $editoroptions['context'], 'group', 'description', $description->id);
|
||||
$DB->update_record('groups', $description);
|
||||
}
|
||||
}
|
||||
@ -185,7 +185,7 @@ function groups_create_grouping($data, $editoroptions=null) {
|
||||
$description = new stdClass;
|
||||
$description->id = $data->id;
|
||||
$description->description_editor = $data->description_editor;
|
||||
$description = file_postupdate_standard_editor($description, 'description', $editoroptions, $editoroptions['context'], 'course_grouping_description', $description->id);
|
||||
$description = file_postupdate_standard_editor($description, 'description', $editoroptions, $editoroptions['context'], 'grouping', 'description', $description->id);
|
||||
$DB->update_record('groupings', $description);
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ function groups_update_group($data, $editform=false) {
|
||||
|
||||
if ($editform && method_exists($editform, 'get_editor_options')) {
|
||||
$editoroptions = $editform->get_editor_options();
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $editoroptions['context'], 'course_group_description', $data->id);
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $editoroptions['context'], 'group', 'description', $data->id);
|
||||
}
|
||||
|
||||
$DB->update_record('groups', $data);
|
||||
@ -238,7 +238,7 @@ function groups_update_grouping($data, $editoroptions=null) {
|
||||
$data->timemodified = time();
|
||||
$data->name = trim($data->name);
|
||||
if ($editoroptions !== null) {
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $editoroptions['context'], 'course_grouping_description', $data->id);
|
||||
$data = file_postupdate_standard_editor($data, 'description', $editoroptions, $editoroptions['context'], 'grouping', 'description', $data->id);
|
||||
}
|
||||
$DB->update_record('groupings', $data);
|
||||
//trigger groups events
|
||||
@ -282,7 +282,7 @@ function groups_delete_group($grouporid) {
|
||||
// Delete all files associated with this group
|
||||
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, 'course_group_description', $groupid);
|
||||
$files = $fs->get_area_files($context->id, 'group', 'description', $groupid);
|
||||
foreach ($files as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
@ -323,7 +323,7 @@ function groups_delete_grouping($groupingorid) {
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $grouping->courseid);
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, 'course_grouping_description', $groupingid);
|
||||
$files = $fs->get_area_files($context->id, 'grouping', 'description', $groupingid);
|
||||
foreach ($files as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
@ -388,8 +388,6 @@ function groups_delete_groupings_groups($courseid, $showfeedback=false) {
|
||||
|
||||
// Delete all files associated with groupings for this course
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files($context->id, 'course_group_description');
|
||||
|
||||
//trigger groups events
|
||||
events_trigger('groups_groupings_groups_removed', $courseid);
|
||||
@ -427,6 +425,10 @@ function groups_delete_groups($courseid, $showfeedback=false) {
|
||||
$groupssql = "SELECT id FROM {groups} g WHERE g.courseid = ?";
|
||||
$DB->delete_records_select('event', "groupid IN ($groupssql)", array($courseid));
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files($context->id, 'group');
|
||||
|
||||
$DB->delete_records('groups', array('courseid'=>$courseid));
|
||||
|
||||
//trigger groups events
|
||||
@ -458,12 +460,12 @@ function groups_delete_groupings($courseid, $showfeedback=false) {
|
||||
// remove the groupingid from all course modules
|
||||
$DB->set_field('course_modules', 'groupingid', 0, array('course'=>$courseid));
|
||||
|
||||
$DB->delete_records('groupings', array('courseid'=>$courseid));
|
||||
|
||||
// Delete all files associated with groupings for this course
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files($context->id, 'course_grouping_description');
|
||||
$fs->delete_area_files($context->id, 'grouping');
|
||||
|
||||
$DB->delete_records('groupings', array('courseid'=>$courseid));
|
||||
|
||||
//trigger groups events
|
||||
events_trigger('groups_groupings_deleted', $courseid);
|
||||
@ -508,7 +510,7 @@ function groups_get_potential_members($courseid, $roleid = null, $cohortid = nul
|
||||
$listofcontexts = get_related_contexts_string($context);
|
||||
|
||||
list($esql, $params) = get_enrolled_sql($context);
|
||||
|
||||
|
||||
if ($roleid) {
|
||||
$params['roleid'] = $roleid;
|
||||
$where = "WHERE u.id IN (SELECT userid
|
||||
|
@ -159,7 +159,7 @@ foreach ($members as $gpgid=>$groupdata) {
|
||||
}
|
||||
$line = array();
|
||||
$name = format_string($groups[$gpid]->name);
|
||||
$description = file_rewrite_pluginfile_urls($groups[$gpid]->description, 'pluginfile.php', $context->id, 'course_group_description', $gpid);
|
||||
$description = file_rewrite_pluginfile_urls($groups[$gpid]->description, 'pluginfile.php', $context->id, 'group', 'description', $gpid);
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$jsdescription = trim(format_text($description, $groups[$gpid]->descriptionformat, $options));
|
||||
@ -184,7 +184,7 @@ foreach ($members as $gpgid=>$groupdata) {
|
||||
echo $OUTPUT->heading($strnotingrouping, 3);
|
||||
} else {
|
||||
echo $OUTPUT->heading(format_string($groupings[$gpgid]->name), 3);
|
||||
$description = file_rewrite_pluginfile_urls($groupings[$gpgid]->description, 'pluginfile.php', $context->id, 'course_grouping_description', $gpgid);
|
||||
$description = file_rewrite_pluginfile_urls($groupings[$gpgid]->description, 'pluginfile.php', $context->id, 'grouping', 'description', $gpgid);
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
echo $OUTPUT->box(format_text($description, $groupings[$gpgid]->descriptionformat, $options), 'generalbox boxwidthnarrow boxaligncenter');
|
||||
|
14
index.php
14
index.php
@ -91,7 +91,7 @@
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print Section
|
||||
if ($SITE->numsections > 0) {
|
||||
if ($SITE->numsections > 0) {
|
||||
|
||||
if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) {
|
||||
$DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case
|
||||
@ -104,7 +104,7 @@
|
||||
$section->id = $DB->insert_record('course_sections', $section);
|
||||
}
|
||||
|
||||
if (!empty($section->sequence) or !empty($section->summary) or $editing) {
|
||||
if (!empty($section->sequence) or !empty($section->summary) or $editing) {
|
||||
echo $OUTPUT->box_start('generalbox sitetopic');
|
||||
|
||||
/// If currently moving a file then show the current clipboard
|
||||
@ -116,7 +116,7 @@
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, SITEID);
|
||||
$summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course_section', $section->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id);
|
||||
$summaryformatoptions = new object();
|
||||
$summaryformatoptions->noclean = true;
|
||||
|
||||
@ -139,13 +139,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
|
||||
if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
|
||||
$frontpagelayout = $CFG->frontpageloggedin;
|
||||
} else {
|
||||
$frontpagelayout = $CFG->frontpage;
|
||||
}
|
||||
|
||||
foreach (explode(',',$frontpagelayout) as $v) {
|
||||
foreach (explode(',',$frontpagelayout) as $v) {
|
||||
switch ($v) { /// Display the main part of the front page.
|
||||
case FRONTPAGENEWS:
|
||||
if ($SITE->newsitems) { // Print forums only when needed
|
||||
@ -177,7 +177,7 @@
|
||||
}
|
||||
break;
|
||||
|
||||
case FRONTPAGECOURSELIST:
|
||||
case FRONTPAGECOURSELIST:
|
||||
if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguestuser() and empty($CFG->disablemycourses)) {
|
||||
echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('mycourses'))), array('href'=>'#skipmycourses', 'class'=>'skip-block'));
|
||||
echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header');
|
||||
@ -189,7 +189,7 @@
|
||||
echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header');
|
||||
print_courses(0);
|
||||
echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipavailablecourses'));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case FRONTPAGECATEGORYNAMES:
|
||||
|
@ -430,7 +430,7 @@ $string['statsdisable'] = 'Stats is not enabled';
|
||||
$string['statsnodata'] = 'There is no available data for that combination of course and time period';
|
||||
$string['storedfilecannotcreatefiledirs'] = 'Can not create local file pool directories, please verify permissions in dataroot.';
|
||||
$string['storedfilecannotread'] = 'Can not read file, either file does not exist or there are permission problems';
|
||||
$string['storedfilenotcreated'] = 'Can not create file "{$a->contextid}/{$a->filearea}/{$a->itemid}/{$a->filepath}/{$a->filename}"';
|
||||
$string['storedfilenotcreated'] = 'Can not create file "{$a->contextid}/{$a->component}/{$a->filearea}/{$a->itemid}/{$a->filepath}/{$a->filename}"';
|
||||
$string['storedfileproblem'] = 'Unknown exception related to local files ({$a})';
|
||||
$string['tagdisabled'] = 'Tags are disabled!';
|
||||
$string['tagnotfound'] = 'The specified tag was not found in the database';
|
||||
|
@ -110,7 +110,7 @@ $string['invalidaddformat'] = 'Invalid add format passed to portfolio_add_button
|
||||
$string['invalidbuttonproperty'] = 'Could not find that property ({$a}) of portfolio_button';
|
||||
$string['invalidconfigproperty'] = 'Could not find that config property ({$a->property} of {$a->class})';
|
||||
$string['invalidexportproperty'] = 'Could not find that export config property ({$a->property} of {$a->class})';
|
||||
$string['invalidfileareaargs'] = 'Invalid file area arguments passed to set_file_and_format_data - must contain contextid, filearea and itemid';
|
||||
$string['invalidfileareaargs'] = 'Invalid file area arguments passed to set_file_and_format_data - must contain contextid, component, filearea and itemid';
|
||||
$string['invalidformat'] = 'Something is exporting an invalid format, {$a}';
|
||||
$string['invalidinstance'] = 'Could not find that portfolio instance';
|
||||
$string['invalidpreparepackagefile'] = 'Invalid call to prepare_package_file - either single or multifiles must be set';
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20100624" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20100625" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@ -2262,13 +2262,14 @@
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="files" COMMENT="description of files, content stored in sha1 file pool" PREVIOUS="message_working" NEXT="repository">
|
||||
<TABLE NAME="files" COMMENT="description of files, content is stored in sha1 file pool" PREVIOUS="message_working" NEXT="repository">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="contenthash"/>
|
||||
<FIELD NAME="contenthash" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" COMMENT="sha1 hash of file content" PREVIOUS="id" NEXT="pathnamehash"/>
|
||||
<FIELD NAME="pathnamehash" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" COMMENT="complete file path sha1 hash - unique for each file" PREVIOUS="contenthash" NEXT="contextid"/>
|
||||
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The context id defined in context table - identifies the instance of plugin owning the file" PREVIOUS="pathnamehash" NEXT="filearea"/>
|
||||
<FIELD NAME="filearea" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" COMMENT="Like "coursefiles". "submission", "intro" and "content" (images and swf linked from summaries), etc." PREVIOUS="contextid" NEXT="itemid"/>
|
||||
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The context id defined in context table - identifies the instance of plugin owning the file" PREVIOUS="pathnamehash" NEXT="component"/>
|
||||
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" COMMENT="Full name of the component owning the area" PREVIOUS="contextid" NEXT="filearea"/>
|
||||
<FIELD NAME="filearea" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" COMMENT="Like "coursefiles". "submission", "intro" and "content" (images and swf linked from summaries), etc." PREVIOUS="component" NEXT="itemid"/>
|
||||
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Optional - some plugin specific item id (eg. forum post, blog entry or assignment submission, user id for user files)" PREVIOUS="filearea" NEXT="filepath"/>
|
||||
<FIELD NAME="filepath" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Optional - relative path to file from module content root, useful in Scorm and Resource mod - most of the mods do not need this" PREVIOUS="itemid" NEXT="filename"/>
|
||||
<FIELD NAME="filename" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The full Unicode name of this file (case sensitive) - some chars are not allowed though" PREVIOUS="filepath" NEXT="userid"/>
|
||||
@ -2289,8 +2290,8 @@
|
||||
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="contextid"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="filearea-contextid-itemid" UNIQUE="false" FIELDS="filearea, contextid, itemid" NEXT="contenthash"/>
|
||||
<INDEX NAME="contenthash" UNIQUE="false" FIELDS="contenthash" PREVIOUS="filearea-contextid-itemid" NEXT="pathnamehash"/>
|
||||
<INDEX NAME="component-filearea-contextid-itemid" UNIQUE="false" FIELDS="component, filearea, contextid, itemid" NEXT="contenthash"/>
|
||||
<INDEX NAME="contenthash" UNIQUE="false" FIELDS="contenthash" PREVIOUS="component-filearea-contextid-itemid" NEXT="pathnamehash"/>
|
||||
<INDEX NAME="pathnamehash" UNIQUE="true" FIELDS="pathnamehash" PREVIOUS="contenthash"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
|
@ -497,6 +497,7 @@ function xmldb_main_upgrade($oldversion) {
|
||||
$table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
@ -517,7 +518,7 @@ function xmldb_main_upgrade($oldversion) {
|
||||
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
|
||||
|
||||
/// Adding indexes to table files
|
||||
$table->add_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid'));
|
||||
$table->add_index('component-filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('component', 'filearea', 'contextid', 'itemid'));
|
||||
$table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash'));
|
||||
$table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash'));
|
||||
|
||||
@ -4846,6 +4847,64 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
|
||||
upgrade_main_savepoint($result, 2010062101);
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2010070300) {
|
||||
//TODO: this is a temporary hack for upgrade from PR3, to be removed later
|
||||
|
||||
// Define field component to be added to files
|
||||
$table = new xmldb_table('files');
|
||||
$field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'contextid');
|
||||
|
||||
// Conditionally upgrade from PR3
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
$index = new xmldb_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid'));
|
||||
$dbman->drop_index($table, $index);
|
||||
$index = new xmldb_index('component-filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('component', 'filearea', 'contextid', 'itemid'));
|
||||
$dbman->add_index($table, $index);
|
||||
|
||||
// Rename areas as add proper component
|
||||
$areas = $DB->get_fieldset_sql("SELECT DISTINCT filearea FROM {files}");
|
||||
if ($areas) {
|
||||
// fix incorrect itemids
|
||||
$DB->execute("UPDATE {files} SET itemid = 0 WHERE filearea = 'category_description'"); // context identifies instances
|
||||
$DB->execute("UPDATE {files} SET itemid = 0 WHERE filearea = 'user_profile'"); // context identifies instances
|
||||
$DB->execute("UPDATE {files} SET itemid = 0 WHERE filearea = 'block_html'"); // context identifies instances
|
||||
foreach ($areas as $area) {
|
||||
// rename areas
|
||||
if ($area === 'course_backup') {
|
||||
$area = 'backup_course';
|
||||
} else if ($area === 'section_backup') {
|
||||
$area = 'backup_section';
|
||||
} else if ($area === 'activity_backup') {
|
||||
$area = 'backup_activity';
|
||||
} else if ($area === 'category_description') {
|
||||
$area = 'coursecat_description';
|
||||
}
|
||||
if ($area === 'block_html') {
|
||||
$component = 'block_html';
|
||||
$filearea = 'content';
|
||||
} else {
|
||||
list($component, $filearea) = explode('_', $area, 2);
|
||||
// note this is just a hack which guesses plugin from old PRE3 files code, the whole point of adding component is to get rid of this guessing
|
||||
if (file_exists("$CFG->dirroot/mod/$component/lib.php")) {
|
||||
$component = 'mod_'.$component;
|
||||
}
|
||||
}
|
||||
$DB->execute("UPDATE {files} SET component = :component, filearea = :filearea WHERE filearea = :area", array('component'=>$component, 'filearea'=>$filearea, 'area'=>$area));
|
||||
}
|
||||
// Update all hashes
|
||||
$rs = $DB->get_recordset('files', array());
|
||||
foreach ($rs as $file) {
|
||||
$pathnamehash = sha1("/$file->contextid/$file->component/$file->filearea/$file->itemid".$file->filepath.$file->filename);
|
||||
$DB->set_field('files', 'pathnamehash', $pathnamehash, array('id'=>$file->id));
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
// Main savepoint reached
|
||||
upgrade_main_savepoint($result, 2010070300);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
|
@ -105,11 +105,13 @@ function upgrade_migrate_files_course($context, $path, $delete) {
|
||||
}
|
||||
|
||||
if (strpos($path, '/backupdata/') === 0) {
|
||||
$filearea = 'course_backup';
|
||||
$filepath = substr($path, strlen('/backupdata'));
|
||||
$component = 'backup';
|
||||
$filearea = 'course';
|
||||
$filepath = substr($path, strlen('/backupdata'));
|
||||
} else {
|
||||
$filearea = 'course_content';
|
||||
$filepath = $path;
|
||||
$component = 'course';
|
||||
$filearea = 'legacy';
|
||||
$filepath = $path;
|
||||
}
|
||||
|
||||
if ($item->isFile()) {
|
||||
@ -126,8 +128,8 @@ function upgrade_migrate_files_course($context, $path, $delete) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$fs->file_exists($context->id, $filearea, '0', $filepath, $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'filearea'=>$filearea, 'itemid'=>0, 'filepath'=>$filepath, 'filename'=>$filename,
|
||||
if (!$fs->file_exists($context->id, $component, $filearea, '0', $filepath, $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>0, 'filepath'=>$filepath, 'filename'=>$filename,
|
||||
'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime());
|
||||
if ($fs->create_file_from_pathname($file_record, $fullpathname.$item->getFilename())) {
|
||||
if ($delete_this) {
|
||||
@ -148,7 +150,7 @@ function upgrade_migrate_files_course($context, $path, $delete) {
|
||||
}
|
||||
$filepath = ($filepath.$dirname.'/');
|
||||
if ($filepath !== '/backupdata/') {
|
||||
$fs->create_directory($context->id, $filearea, 0, $filepath);
|
||||
$fs->create_directory($context->id, $component, $filearea, 0, $filepath);
|
||||
}
|
||||
|
||||
//migrate recursively all subdirectories
|
||||
@ -203,8 +205,8 @@ function upgrade_migrate_files_blog() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$fs->file_exists(SYSCONTEXTID, 'blog', $entry->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>SYSCONTEXTID, 'filearea'=>'blog_attachment', 'itemid'=>$entry->id, 'filepath'=>'/', 'filename'=>$filename,
|
||||
if (!$fs->file_exists(SYSCONTEXTID, 'blog', 'attachment', $entry->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>SYSCONTEXTID, 'component'=>'blog', 'filearea'=>'attachment', 'itemid'=>$entry->id, 'filepath'=>'/', 'filename'=>$filename,
|
||||
'timecreated'=>filectime($pathname), 'timemodified'=>filemtime($pathname), 'userid'=>$entry->userid);
|
||||
$fs->create_file_from_pathname($file_record, $pathname);
|
||||
}
|
||||
|
@ -1,575 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of files.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once("$CFG->libdir/file/file_info.php");
|
||||
require_once("$CFG->libdir/file/file_info_module.php");
|
||||
require_once("$CFG->libdir/file/file_info_stored.php");
|
||||
require_once("$CFG->libdir/file/file_info_system.php");
|
||||
require_once("$CFG->libdir/file/file_info_user.php");
|
||||
require_once("$CFG->libdir/file/file_info_coursecat.php");
|
||||
require_once("$CFG->libdir/file/file_info_course.php");
|
||||
require_once("$CFG->libdir/file/file_info_coursesection.php");
|
||||
require_once("$CFG->libdir/file/file_info_coursesectionbackup.php");
|
||||
require_once("$CFG->libdir/file/file_info_coursefile.php");
|
||||
require_once("$CFG->libdir/file/virtual_root_file.php");
|
||||
|
||||
/**
|
||||
* This class provides the main entry point for other code wishing to get
|
||||
* information about files.
|
||||
*
|
||||
* The whole file storage for a Moodle site can be seen as a huge virtual tree.
|
||||
* The spine of the tree is the tree of contexts (system, course-categories,
|
||||
* courses, modules, also users). Then, within each context, there may be any number of
|
||||
* file areas, and a file area contains folders and files. The various file_info
|
||||
* subclasses return info about the things in this tree. They should be obtained
|
||||
* from an instance of this class.
|
||||
*
|
||||
* This virtual tree is different for each user depending of his/her current permissions.
|
||||
* Some branches such as draft areas are hidden, but accessible.
|
||||
*
|
||||
* Always use this abstraction when you need to access module files from core code.
|
||||
*/
|
||||
class file_browser {
|
||||
|
||||
/**
|
||||
* Looks up file_info instance
|
||||
* @param object $context
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return file_info instance or null if not found or access not allowed
|
||||
*/
|
||||
public function get_file_info($context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
switch ($context->contextlevel) {
|
||||
case CONTEXT_SYSTEM:
|
||||
return $this->get_file_info_system($context, $filearea, $itemid, $filepath, $filename);
|
||||
case CONTEXT_USER:
|
||||
return $this->get_file_info_user($context, $filearea, $itemid, $filepath, $filename);
|
||||
case CONTEXT_COURSECAT:
|
||||
return $this->get_file_info_coursecat($context, $filearea, $itemid, $filepath, $filename);
|
||||
case CONTEXT_COURSE:
|
||||
return $this->get_file_info_course($context, $filearea, $itemid, $filepath, $filename);
|
||||
case CONTEXT_MODULE:
|
||||
return $this->get_file_info_module($context, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns info about the files at System context
|
||||
* @param object $context
|
||||
* @param string $filearea
|
||||
* @return file_info_system
|
||||
*/
|
||||
private function get_file_info_system($context, $filearea=null) {
|
||||
if (is_null($filearea)) {
|
||||
return new file_info_system($this);
|
||||
}
|
||||
//TODO: question files browsing
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns info about the files at User context
|
||||
* @param object $context
|
||||
* @param string $filearea
|
||||
* @return file_info_system
|
||||
*/
|
||||
private function get_file_info_user($context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $USER, $DB;
|
||||
if ($context->instanceid == $USER->id) {
|
||||
$user = $USER;
|
||||
} else {
|
||||
$user = $DB->get_record('user', array('id'=>$context->instanceid));
|
||||
}
|
||||
|
||||
if (isguestuser($user) or empty($user->id)) {
|
||||
// no guests or not logged in users here
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($user->deleted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_null($filearea)) {
|
||||
// access control: list areas only for myself
|
||||
if ($context->instanceid != $USER->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new file_info_user($this, $context);
|
||||
|
||||
} else {
|
||||
$methodname = "get_file_info_$filearea";
|
||||
if (method_exists($this, $methodname)) {
|
||||
return $this->$methodname($user, $context, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function get_file_info_user_private($user, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $USER, $CFG;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
// access control: only my files for now, nobody else
|
||||
if ($context->instanceid != $USER->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_null($itemid)) {
|
||||
return new file_info_user($this, $context);
|
||||
}
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
|
||||
if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($context->id, $filearea, 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/userfile.php';
|
||||
return new file_info_stored($this, $context, $storedfile, $urlbase, get_string('areauserpersonal', 'repository'), false, true, true, false);
|
||||
}
|
||||
|
||||
private function get_file_info_user_profile($user, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $USER, $CFG;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (is_null($itemid)) {
|
||||
return new file_info_user($this, $context);
|
||||
}
|
||||
|
||||
// access controll here must match user edit forms
|
||||
if ($user->id == $USER->id) {
|
||||
if (!has_capability('moodle/user:editownprofile', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (!has_capability('moodle/user:editprofile', $context) and !has_capability('moodle/user:update', $context)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
|
||||
if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($context->id, $filearea, 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/userfile.php';
|
||||
return new file_info_stored($this, $context, $storedfile, $urlbase, get_string('areauserprofile', 'repository'), false, true, true, false);
|
||||
}
|
||||
|
||||
private function get_file_info_user_draft($user, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $USER, $CFG;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
// access control: only my files
|
||||
if ($context->instanceid != $USER->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($itemid)) {
|
||||
// do not browse itemids - you most know the draftid to see what is there
|
||||
return null;
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/draftfile.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, $itemid);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (!$category = $DB->get_record('course_categories', array('id'=>$context->instanceid))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$category->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!is_null($filearea) and !in_array($filearea, array('coursecat_intro'))) {
|
||||
// file area does not exist, sorry
|
||||
$filearea = null;
|
||||
}
|
||||
|
||||
if (is_null($filearea) or is_null($itemid)) {
|
||||
return new file_info_coursecat($this, $context, $category);
|
||||
|
||||
} else {
|
||||
if ($filearea == 'coursecat_intro') {
|
||||
if (!has_capability('moodle/course:update', $context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $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('areacategoryintro', 'repository'), false, true, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function get_file_info_course($context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $DB, $COURSE;
|
||||
|
||||
if ($context->instanceid == $COURSE->id) {
|
||||
$course = $COURSE;
|
||||
} else if (!$course = $DB->get_record('course', array('id'=>$context->instanceid))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!is_null($filearea) and !in_array($filearea, array('course_summary', 'course_content', 'course_section', 'course_backup', 'section_backup'))) {
|
||||
// file area does not exist, sorry
|
||||
$filearea = null;
|
||||
}
|
||||
|
||||
if ($filearea === 'course_content' and $course->legacyfiles != 2) {
|
||||
// bad luck, legacy course files not used any more
|
||||
return null;
|
||||
}
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
|
||||
if (is_null($filearea)) {
|
||||
return new file_info_course($this, $context, $course);
|
||||
|
||||
} else {
|
||||
$methodname = "get_file_info_$filearea";
|
||||
if (method_exists($this, $methodname)) {
|
||||
return $this->$methodname($course, $context, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function get_file_info_course_summary($course, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $CFG;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (!has_capability('moodle/course:update', $context)) {
|
||||
return null;
|
||||
}
|
||||
if (is_null($itemid)) {
|
||||
return new file_info_course($this, $context, $course);
|
||||
}
|
||||
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $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('areacourseintro', 'repository'), false, true, true, false);
|
||||
|
||||
}
|
||||
|
||||
private function get_file_info_course_section($course, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (!has_capability('moodle/course:update', $context)) {
|
||||
return null;
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
|
||||
if (empty($itemid)) {
|
||||
// list all sections
|
||||
return new file_info_coursesection($this, $context, $course);
|
||||
}
|
||||
|
||||
if (!$section = $DB->get_record('course_sections', array('course'=>$course->id, 'id'=>$itemid))) {
|
||||
return null; // does not exist
|
||||
}
|
||||
|
||||
if (!$storedfile = $fs->get_file($context->id, $filearea, $itemid, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($context->id, $filearea, $itemid);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new file_info_stored($this, $context, $storedfile, $urlbase, $section->section, true, true, true, false);
|
||||
|
||||
}
|
||||
|
||||
private function get_file_info_course_backup($course, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $CFG;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (!has_capability('moodle/backup:backupcourse', $context) and !has_capability('moodle/restore:restorecourse', $context)) {
|
||||
return null;
|
||||
}
|
||||
if (is_null($itemid)) {
|
||||
return new file_info_course($this, $context, $course);
|
||||
}
|
||||
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($context->id, $filearea, 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$downloadable = has_capability('moodle/backup:downloadfile', $context);
|
||||
$uploadable = has_capability('moodle/restore:uploadfile', $context);
|
||||
return new file_info_stored($this, $context, $storedfile, $urlbase, get_string('coursebackup', 'repository'), false, $downloadable, $uploadable, false);
|
||||
|
||||
}
|
||||
|
||||
private function get_file_info_section_backup($course, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (!has_capability('moodle/backup:backupcourse', $context) and !has_capability('moodle/restore:restorecourse', $context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
if (empty($itemid)) {
|
||||
// list all sections
|
||||
return new file_info_coursesectionbackup($this, $context, $course);
|
||||
}
|
||||
|
||||
if (!$section = $DB->get_record('course_sections', array('course'=>$course->id, 'id'=>$itemid))) {
|
||||
return null; // does not exist
|
||||
}
|
||||
|
||||
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
if (!$storedfile = $fs->get_file($context->id, $filearea, $itemid, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($context->id, $filearea, $itemid);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$downloadable = has_capability('moodle/backup:downloadfile', $context);
|
||||
$uploadable = has_capability('moodle/restore:uploadfile', $context);
|
||||
return new file_info_stored($this, $context, $storedfile, $urlbase, $section->id, true, $downloadable, $uploadable, false);
|
||||
}
|
||||
|
||||
private function get_file_info_course_content($course, $context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (!has_capability('moodle/course:managefiles', $context)) {
|
||||
return null;
|
||||
}
|
||||
if (is_null($itemid)) {
|
||||
return new file_info_course($this, $context, $course);
|
||||
}
|
||||
|
||||
if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($context->id, $filearea, 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return new file_info_coursefile($this, $context, $storedfile);
|
||||
}
|
||||
|
||||
private function get_file_info_module($context, $filearea=null, $itemid=null, $filepath=null, $filename=null) {
|
||||
global $COURSE, $DB, $CFG;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (!$cm = get_coursemodule_from_id('', $context->instanceid)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($cm->course == $COURSE->id) {
|
||||
$course = $COURSE;
|
||||
} else if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
if (empty($modinfo->cms[$cm->id]->uservisible)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modname = $modinfo->cms[$cm->id]->modname;
|
||||
|
||||
$libfile = "$CFG->dirroot/mod/$modname/lib.php";
|
||||
if (!file_exists($libfile)) {
|
||||
return null;
|
||||
}
|
||||
require_once($libfile);
|
||||
|
||||
$fileinfofunction = $modname.'_get_file_areas';
|
||||
if (function_exists($fileinfofunction)) {
|
||||
$areas = $fileinfofunction($course, $cm, $context);
|
||||
} else {
|
||||
$areas = array();
|
||||
}
|
||||
if (!isset($areas[$modname.'_intro'])
|
||||
and plugin_supports('mod', $modname, FEATURE_MOD_INTRO, true)
|
||||
and has_capability('moodle/course:managefiles', $context)) {
|
||||
$areas = array_merge(array($modname.'_intro'=>get_string('moduleintro')), $areas);
|
||||
}
|
||||
|
||||
if (has_capability('moodle/backup:downloadfile', $context)) {
|
||||
$areas = array_merge(array('activity_backup'=>get_string('activitybackup', 'repository')), $areas);
|
||||
}
|
||||
|
||||
if (empty($areas)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($filearea === $modname.'_intro' || $filearea === 'activity_backup') {
|
||||
// always only itemid 0
|
||||
if (!has_capability('moodle/course:managefiles', $context)) {
|
||||
return null;
|
||||
}
|
||||
// need downloadfile cap when accessing activity_backup area
|
||||
if ($filearea === 'activity_backup' && !has_capability('moodle/backup:downloadfile', $context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $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, $areas[$filearea], false, true, true, false);
|
||||
|
||||
} else if (is_null($filearea)) {
|
||||
// modules have to decide if they want to use itemids
|
||||
return new file_info_module($this, $course, $cm, $context, $areas);
|
||||
|
||||
} else if (!array_key_exists($filearea, $areas)) {
|
||||
return null;
|
||||
|
||||
} else {
|
||||
$fileinfofunction = $modname.'_get_file_info';
|
||||
if (function_exists($fileinfofunction)) {
|
||||
return $fileinfofunction($this, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of course files.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a course context in the tree navigated by @see{file_browser}.
|
||||
*/
|
||||
class file_info_course extends file_info {
|
||||
protected $course;
|
||||
|
||||
public function __construct($browser, $context, $course) {
|
||||
global $DB;
|
||||
parent::__construct($browser, $context);
|
||||
$this->course = $course;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid'=>$this->context->id,
|
||||
'filearea' =>null,
|
||||
'itemid' =>null,
|
||||
'filepath' =>null,
|
||||
'filename' =>null);
|
||||
}
|
||||
|
||||
public function get_visible_name() {
|
||||
return ($this->course->id == SITEID) ? get_string('frontpage', 'admin') : format_string($this->course->fullname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
$children = array();
|
||||
|
||||
if ($child = $this->browser->get_file_info($this->context, 'course_summary', 0)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
if ($child = $this->browser->get_file_info($this->context, 'course_section')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
if ($child = $this->browser->get_file_info($this->context, 'section_backup')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
|
||||
if ($child = $this->browser->get_file_info($this->context, 'course_backup', 0)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
|
||||
if ($this->course->legacyfiles == 2) {
|
||||
if ($child = $this->browser->get_file_info($this->context, 'course_content', 0)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
$modinfo = get_fast_modinfo($this->course);
|
||||
foreach ($modinfo->cms as $cminfo) {
|
||||
if (empty($cminfo->uservisible)) {
|
||||
continue;
|
||||
}
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $cminfo->id);
|
||||
if ($child = $this->browser->get_file_info($modcontext)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
//TODO: error checking if get_parent_contextid() returns false
|
||||
$pcid = get_parent_contextid($this->context);
|
||||
$parent = get_context_instance_by_id($pcid);
|
||||
return $this->browser->get_file_info($parent);
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of coursefiles.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Subclass of file_info_stored for files in the course files area.
|
||||
*/
|
||||
class file_info_coursefile extends file_info_stored {
|
||||
public function __construct($browser, $context, $storedfile) {
|
||||
global $CFG;
|
||||
$urlbase = $CFG->wwwroot.'/file.php';
|
||||
parent::__construct($browser, $context, $storedfile, $urlbase, get_string('coursefiles'), false, true, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns file download url
|
||||
* @param bool $forcedownload
|
||||
* @param bool $htts force https
|
||||
* @return string url
|
||||
*/
|
||||
public function get_url($forcedownload=false, $https=false) {
|
||||
global $CFG;
|
||||
|
||||
if (!$this->is_readable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->lf->is_directory()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$filepath = $this->lf->get_filepath();
|
||||
$filename = $this->lf->get_filename();
|
||||
$courseid = $this->context->instanceid;
|
||||
|
||||
$path = '/'.$courseid.$filepath.$filename;
|
||||
|
||||
return file_encode_url($this->urlbase, $path, $forcedownload, $https);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
if (!$this->lf->is_directory()) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$fs = get_file_storage();
|
||||
|
||||
$storedfiles = $fs->get_directory_files($this->context->id, 'course_content', 0, $this->lf->get_filepath(), false, true, "filepath, filename");
|
||||
foreach ($storedfiles as $file) {
|
||||
$result[] = new file_info_coursefile($this->browser, $this->context, $file);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of course section files.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a course category context in the tree navigated by @see{file_browser}.
|
||||
*/
|
||||
class file_info_coursesection extends file_info {
|
||||
protected $course;
|
||||
|
||||
public function __construct($browser, $context, $course) {
|
||||
parent::__construct($browser, $context);
|
||||
$this->course = $course;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid'=>$this->context->id,
|
||||
'filearea' =>'course_section',
|
||||
'itemid' =>null,
|
||||
'filepath' =>null,
|
||||
'filename' =>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised visible name.
|
||||
* @return string
|
||||
*/
|
||||
public function get_visible_name() {
|
||||
$format = $this->course->format;
|
||||
$sectionsname = get_string("coursesectionsummaries");
|
||||
|
||||
return $sectionsname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
global $DB;
|
||||
|
||||
$children = array();
|
||||
|
||||
$course_sections = $DB->get_records('course_sections', array('course'=>$this->course->id), 'section');
|
||||
foreach ($course_sections as $section) {
|
||||
if ($child = $this->browser->get_file_info($this->context, 'course_section', $section->id)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
return $this->browser->get_file_info($this->context);
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of course section files.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
*/
|
||||
class file_info_coursesectionbackup extends file_info {
|
||||
protected $course;
|
||||
|
||||
public function __construct($browser, $context, $course) {
|
||||
parent::__construct($browser, $context);
|
||||
$this->course = $course;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid'=>$this->context->id,
|
||||
'filearea' =>'section_backup',
|
||||
'itemid' =>null,
|
||||
'filepath' =>null,
|
||||
'filename' =>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised visible name.
|
||||
* @return string
|
||||
*/
|
||||
public function get_visible_name() {
|
||||
$format = $this->course->format;
|
||||
$sectionsname = get_string('sectionbackup', 'repository');
|
||||
|
||||
return $sectionsname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
global $DB;
|
||||
|
||||
$children = array();
|
||||
|
||||
$course_sections = $DB->get_records('course_sections', array('course'=>$this->course->id), 'section');
|
||||
foreach ($course_sections as $section) {
|
||||
if ($child = $this->browser->get_file_info($this->context, 'section_backup', $section->id)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
return $this->browser->get_file_info($this->context);
|
||||
}
|
||||
}
|
||||
|
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of module files.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a module context in the tree navigated by @see{file_browser}.
|
||||
*/
|
||||
class file_info_module extends file_info {
|
||||
protected $course;
|
||||
protected $cm;
|
||||
protected $areas;
|
||||
|
||||
public function __construct($browser, $course, $cm, $context, $areas) {
|
||||
global $DB;
|
||||
parent::__construct($browser, $context);
|
||||
$this->course = $course;
|
||||
$this->cm = $cm;
|
||||
$this->areas = $areas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid'=>$this->context->id,
|
||||
'filearea' =>null,
|
||||
'itemid' =>null,
|
||||
'filepath' =>null,
|
||||
'filename' =>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised visible name.
|
||||
* @return string
|
||||
*/
|
||||
public function get_visible_name() {
|
||||
return $this->cm->name.' ('.get_string('modulename', $this->cm->modname).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
$children = array();
|
||||
foreach ($this->areas as $area=>$desctiption) {
|
||||
if ($child = $this->browser->get_file_info($this->context, $area, null)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
$pcid = get_parent_contextid($this->context);
|
||||
$parent = get_context_instance_by_id($pcid);
|
||||
return $this->browser->get_file_info($parent);
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of user files.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a user context in the tree navigated by @see{file_browser}.
|
||||
*/
|
||||
class file_info_user extends file_info {
|
||||
protected $user;
|
||||
|
||||
public function __construct($browser, $context) {
|
||||
global $DB, $USER;
|
||||
|
||||
parent::__construct($browser, $context);
|
||||
|
||||
$userid = $context->instanceid;
|
||||
|
||||
if ($userid == $USER->id) {
|
||||
$this->user = $USER;
|
||||
} else {
|
||||
// if context exists user record should exist too ;-)
|
||||
$this->user = $DB->get_record('user', array('id'=>$userid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid'=>$this->context->id,
|
||||
'filearea' =>null,
|
||||
'itemid' =>null,
|
||||
'filepath' =>null,
|
||||
'filename' =>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised visible name.
|
||||
* @return string
|
||||
*/
|
||||
public function get_visible_name() {
|
||||
return fullname($this->user, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
global $USER, $CFG;
|
||||
|
||||
$children = array();
|
||||
|
||||
if ($child = $this->browser->get_file_info(get_context_instance(CONTEXT_USER, $USER->id), 'user_private', 0)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
|
||||
if ($child = $this->browser->get_file_info(get_context_instance(CONTEXT_USER, $USER->id), 'user_profile', 0)) {
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
return $this->browser->get_file_info(get_context_instance(CONTEXT_SYSTEM));
|
||||
}
|
||||
}
|
228
lib/filebrowser/file_browser.php
Normal file
228
lib/filebrowser/file_browser.php
Normal file
@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of files.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/filebrowser/file_info.php");
|
||||
|
||||
// general area types
|
||||
require_once("$CFG->libdir/filebrowser/file_info_stored.php");
|
||||
require_once("$CFG->libdir/filebrowser/virtual_root_file.php");
|
||||
|
||||
// description of available areas in each context level
|
||||
require_once("$CFG->libdir/filebrowser/file_info_context_system.php");
|
||||
require_once("$CFG->libdir/filebrowser/file_info_context_user.php");
|
||||
require_once("$CFG->libdir/filebrowser/file_info_context_coursecat.php");
|
||||
require_once("$CFG->libdir/filebrowser/file_info_context_course.php");
|
||||
require_once("$CFG->libdir/filebrowser/file_info_context_module.php");
|
||||
|
||||
/**
|
||||
* This class provides the main entry point for other code wishing to get
|
||||
* information about files.
|
||||
*
|
||||
* The whole file storage for a Moodle site can be seen as a huge virtual tree.
|
||||
* The spine of the tree is the tree of contexts (system, course-categories,
|
||||
* courses, modules, also users). Then, within each context, there may be any number of
|
||||
* file areas, and a file area contains folders and files. The various file_info
|
||||
* subclasses return info about the things in this tree. They should be obtained
|
||||
* from an instance of this class.
|
||||
*
|
||||
* This virtual tree is different for each user depending of his/her current permissions.
|
||||
* Some branches such as draft areas are hidden, but accessible.
|
||||
*
|
||||
* Always use this abstraction when you need to access module files from core code.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_browser {
|
||||
|
||||
/**
|
||||
* Looks up file_info instance
|
||||
* @param object $context
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return file_info instance or null if not found or access not allowed
|
||||
*/
|
||||
public function get_file_info($context = NULL, $component = NULL, $filearea = NULL, $itemid = NULL, $filepath = NULL, $filename = NULL) {
|
||||
if (!$context) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
}
|
||||
switch ($context->contextlevel) {
|
||||
case CONTEXT_SYSTEM:
|
||||
return $this->get_file_info_context_system($context, $component, $filearea, $itemid, $filepath, $filename);
|
||||
case CONTEXT_USER:
|
||||
return $this->get_file_info_context_user($context, $component, $filearea, $itemid, $filepath, $filename);
|
||||
case CONTEXT_COURSECAT:
|
||||
return $this->get_file_info_context_coursecat($context, $component, $filearea, $itemid, $filepath, $filename);
|
||||
case CONTEXT_COURSE:
|
||||
return $this->get_file_info_context_course($context, $component, $filearea, $itemid, $filepath, $filename);
|
||||
case CONTEXT_MODULE:
|
||||
return $this->get_file_info_context_module($context, $component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns info about the files at System context
|
||||
* @param object $context
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return file_info instance or null if not found or access not allowed
|
||||
*/
|
||||
private function get_file_info_context_system($context, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
$level = new file_info_context_system($this, $context);
|
||||
return $level->get_file_info($component, $filearea, $itemid, $filepath, $filename);
|
||||
// nothing supported at this context yet
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns info about the files at User context
|
||||
* @param object $context
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return file_info instance or null if not found or access not allowed
|
||||
*/
|
||||
private function get_file_info_context_user($context, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $DB, $USER;
|
||||
if ($context->instanceid == $USER->id) {
|
||||
$user = $USER;
|
||||
} else {
|
||||
$user = $DB->get_record('user', array('id'=>$context->instanceid));
|
||||
}
|
||||
|
||||
if (isguestuser($user)) {
|
||||
// guests do not have any files
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($user->deleted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$level = new file_info_context_user($this, $context, $user);
|
||||
return $level->get_file_info($component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns info about the files at Course category context
|
||||
* @param object $context
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return file_info instance or null if not found or access not allowed
|
||||
*/
|
||||
private function get_file_info_context_coursecat($context, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $DB, $CFG;
|
||||
|
||||
if (!$category = $DB->get_record('course_categories', array('id'=>$context->instanceid))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$level = new file_info_context_coursecat($this, $context, $category);
|
||||
return $level->get_file_info($component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns info about the files at Course category context
|
||||
* @param object $context
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return file_info instance or null if not found or access not allowed
|
||||
*/
|
||||
private function get_file_info_context_course($context, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $DB, $COURSE;
|
||||
|
||||
if ($context->instanceid == $COURSE->id) {
|
||||
$course = $COURSE;
|
||||
} else if (!$course = $DB->get_record('course', array('id'=>$context->instanceid))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$level = new file_info_context_course($this, $context, $course);
|
||||
return $level->get_file_info($component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns info about the files at Course category context
|
||||
* @param object $context
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return file_info instance or null if not found or access not allowed
|
||||
*/
|
||||
private function get_file_info_context_module($context, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $COURSE, $DB, $CFG;
|
||||
|
||||
|
||||
if (!$cm = get_coursemodule_from_id('', $context->instanceid)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($cm->course == $COURSE->id) {
|
||||
$course = $COURSE;
|
||||
} else if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
if (empty($modinfo->cms[$cm->id]->uservisible)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modname = $modinfo->cms[$cm->id]->modname;
|
||||
|
||||
if (!file_exists("$CFG->dirroot/mod/$modname/lib.php")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// ok, we know that module exists, and user may access it
|
||||
|
||||
$level = new file_info_context_module($this, $context, $course, $cm, $modname);
|
||||
return $level->get_file_info($component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
}
|
@ -19,14 +19,21 @@
|
||||
/**
|
||||
* Base for all file browsing classes.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Base class for things in the tree navigated by @see{file_browser}.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class file_info {
|
||||
|
||||
@ -43,9 +50,16 @@ abstract class file_info {
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
* @return array with keys contextid, component, filearea, itemid, filepath and filename
|
||||
*/
|
||||
public abstract function get_params();
|
||||
public function get_params() {
|
||||
return array('contextid' => $this->context->id,
|
||||
'component' => null,
|
||||
'filearea' => null,
|
||||
'itemid' => null,
|
||||
'filepath' => null,
|
||||
'filename' => null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised visible name.
|
||||
@ -79,6 +93,7 @@ abstract class file_info {
|
||||
$params = $this->get_params();
|
||||
$encoded = array();
|
||||
$encoded[] = 'contextid='.$params['contextid'];
|
||||
$encoded[] = 'component='.$params['component'];
|
||||
$encoded[] = 'filearea='.$params['filearea'];
|
||||
$encoded[] = 'itemid='.(is_null($params['itemid']) ? -1 : $params['itemid']);
|
||||
$encoded[] = 'filepath='.(is_null($params['filepath']) ? '' : rawurlencode($params['filepath']));
|
||||
@ -184,7 +199,7 @@ abstract class file_info {
|
||||
* @param int id of author, default $USER->id
|
||||
* @return file_info new directory
|
||||
*/
|
||||
public function create_directory($newdirname, $userid=null) {
|
||||
public function create_directory($newdirname, $userid = NULL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -196,7 +211,7 @@ abstract class file_info {
|
||||
* @param int id of author, default $USER->id
|
||||
* @return file_info new file
|
||||
*/
|
||||
public function create_file_from_string($newfilename, $content, $userid=null) {
|
||||
public function create_file_from_string($newfilename, $content, $userid = NULL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -208,7 +223,7 @@ abstract class file_info {
|
||||
* @param int id of author, default $USER->id
|
||||
* @return file_info new file
|
||||
*/
|
||||
public function create_file_from_pathname($newfilename, $pathname, $userid=null) {
|
||||
public function create_file_from_pathname($newfilename, $pathname, $userid = NULL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -220,7 +235,7 @@ abstract class file_info {
|
||||
* @param int id of author, default $USER->id
|
||||
* @return file_info new file
|
||||
*/
|
||||
public function create_file_from_storedfile($newfilename, $fid, $userid=null) {
|
||||
public function create_file_from_storedfile($newfilename, $fid, $userid = NULL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -235,13 +250,14 @@ abstract class file_info {
|
||||
/**
|
||||
* Copy content of this file to local storage, overriding current file if needed.
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return boolean success
|
||||
*/
|
||||
public function copy_to_storage($contextid, $filearea, $itemid, $filepath, $filename) {
|
||||
public function copy_to_storage($contextid, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
return false;
|
||||
}
|
||||
|
540
lib/filebrowser/file_info_context_course.php
Normal file
540
lib/filebrowser/file_info_context_course.php
Normal file
@ -0,0 +1,540 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of course files.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Represents a course context in the tree navigated by @see{file_browser}.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_info_context_course extends file_info {
|
||||
protected $course;
|
||||
|
||||
public function __construct($browser, $context, $course) {
|
||||
parent::__construct($browser, $context);
|
||||
$this->course = $course;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return information about this specific context level
|
||||
*
|
||||
* @param $component
|
||||
* @param $filearea
|
||||
* @param $itemid
|
||||
* @param $filepath
|
||||
* @param $filename
|
||||
*/
|
||||
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $DB;
|
||||
|
||||
if (!$this->course->visible and !has_capability('moodle/course:viewhiddencourses', $this->context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($component)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$methodname = "get_area_{$component}_{$filearea}";
|
||||
|
||||
if (method_exists($this, $methodname)) {
|
||||
return $this->$methodname($itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function get_area_course_summary($itemid, $filepath, $filename) {
|
||||
global $CFG;
|
||||
|
||||
if (!has_capability('moodle/course:update', $this->context)) {
|
||||
return null;
|
||||
}
|
||||
if (is_null($itemid)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'course', 'summary', 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'course', 'summary', 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areacourseintro', 'repository'), false, true, true, false);
|
||||
}
|
||||
|
||||
|
||||
protected function get_area_course_section($itemid, $filepath, $filename) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (!has_capability('moodle/course:update', $this->context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($itemid)) {
|
||||
// list all sections
|
||||
return new file_info_area_course_section($this->browser, $this->context, $this->course, $this);
|
||||
}
|
||||
|
||||
if (!$section = $DB->get_record('course_sections', array('course'=>$this->course->id, 'id'=>$itemid))) {
|
||||
return null; // does not exist
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'course', 'section', $itemid, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'course', 'section', $itemid);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $section->section, true, true, true, false);
|
||||
}
|
||||
|
||||
|
||||
protected function get_area_course_legacy($itemid, $filepath, $filename) {
|
||||
if (!has_capability('moodle/course:managefiles', $this->context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->course->id != SITEID and $this->course->legacyfiles != 2) {
|
||||
// bad luck, legacy course files not used any more
|
||||
}
|
||||
|
||||
if (empty($itemid)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'course', 'legacy', 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, $filearea, 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return new file_info_area_course_legacy($this->browser, $this->context, $storedfile);
|
||||
}
|
||||
|
||||
protected function get_area_backup_course($itemid, $filepath, $filename) {
|
||||
global $CFG;
|
||||
|
||||
if (!has_capability('moodle/backup:backupcourse', $this->context) and !has_capability('moodle/restore:restorecourse', $this->context)) {
|
||||
return null;
|
||||
}
|
||||
if (is_null($itemid)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'backup', 'course', 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'backup', 'course', 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$downloadable = has_capability('moodle/backup:downloadfile', $this->context);
|
||||
$uploadable = has_capability('moodle/restore:uploadfile', $this->context);
|
||||
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('coursebackup', 'repository'), false, $downloadable, $uploadable, false);
|
||||
}
|
||||
|
||||
protected function get_area_backup_section($itemid, $filepath, $filename) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (!has_capability('moodle/backup:backupcourse', $this->context) and !has_capability('moodle/restore:restorecourse', $this->context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($itemid)) {
|
||||
// list all sections
|
||||
return new file_info_area_backup_section($this->browser, $this->context, $this->course, $this);
|
||||
}
|
||||
|
||||
if (!$section = $DB->get_record('course_sections', array('course'=>$this->course->id, 'id'=>$itemid))) {
|
||||
return null; // does not exist
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'backup', 'section', $itemid, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'backup', 'section', $itemid);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$downloadable = has_capability('moodle/backup:downloadfile', $this->context);
|
||||
$uploadable = has_capability('moodle/restore:uploadfile', $this->context);
|
||||
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $section->id, true, $downloadable, $uploadable, false);
|
||||
}
|
||||
|
||||
public function get_visible_name() {
|
||||
return ($this->course->id == SITEID) ? get_string('frontpage', 'admin') : format_string($this->course->fullname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
$children = array();
|
||||
|
||||
if ($child = $this->get_area_course_summary(0, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
if ($child = $this->get_area_course_section(null, null, null)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
if ($child = $this->get_area_backup_section(null, null, null)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
if ($child = $this->get_area_backup_course(0, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
if ($child = $this->get_area_course_legacy(0, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
|
||||
// now list all modules
|
||||
$modinfo = get_fast_modinfo($this->course);
|
||||
foreach ($modinfo->cms as $cminfo) {
|
||||
if (empty($cminfo->uservisible)) {
|
||||
continue;
|
||||
}
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $cminfo->id);
|
||||
if ($child = $this->browser->get_file_info($modcontext)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
//TODO: error checking if get_parent_contextid() returns false
|
||||
$pcid = get_parent_contextid($this->context);
|
||||
$parent = get_context_instance_by_id($pcid);
|
||||
return $this->browser->get_file_info($parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclass of file_info_stored for files in the course files area.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_info_area_course_legacy extends file_info_stored {
|
||||
public function __construct($browser, $context, $storedfile) {
|
||||
global $CFG;
|
||||
$urlbase = $CFG->wwwroot.'/file.php';
|
||||
parent::__construct($browser, $context, $storedfile, $urlbase, get_string('coursefiles'), false, true, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns file download url
|
||||
* @param bool $forcedownload
|
||||
* @param bool $htts force https
|
||||
* @return string url
|
||||
*/
|
||||
public function get_url($forcedownload=false, $https=false) {
|
||||
global $CFG;
|
||||
|
||||
if (!$this->is_readable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->lf->is_directory()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$filepath = $this->lf->get_filepath();
|
||||
$filename = $this->lf->get_filename();
|
||||
$courseid = $this->context->instanceid;
|
||||
|
||||
$path = '/'.$courseid.$filepath.$filename;
|
||||
|
||||
return file_encode_url($this->urlbase, $path, $forcedownload, $https);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
if (!$this->lf->is_directory()) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$fs = get_file_storage();
|
||||
|
||||
$storedfiles = $fs->get_directory_files($this->context->id, 'course', 'legacy', 0, $this->lf->get_filepath(), false, true, "filepath ASC, filename ASC");
|
||||
foreach ($storedfiles as $file) {
|
||||
$result[] = new file_info_area_course_legacy($this->browser, $this->context, $file);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a course category context in the tree navigated by @see{file_browser}.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_info_area_course_section extends file_info {
|
||||
protected $course;
|
||||
protected $courseinfo;
|
||||
|
||||
public function __construct($browser, $context, $course, file_info_context_course $courseinfo) {
|
||||
parent::__construct($browser, $context);
|
||||
$this->course = $course;
|
||||
$this->courseinfo = $courseinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid' => $this->context->id,
|
||||
'component' => 'course',
|
||||
'filearea' => 'section',
|
||||
'itemid' => null,
|
||||
'filepath' => null,
|
||||
'filename' => null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised visible name.
|
||||
* @return string
|
||||
*/
|
||||
public function get_visible_name() {
|
||||
$format = $this->course->format;
|
||||
$sectionsname = get_string("coursesectionsummaries");
|
||||
|
||||
return $sectionsname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
global $DB;
|
||||
|
||||
$children = array();
|
||||
|
||||
$course_sections = $DB->get_records('course_sections', array('course'=>$this->course->id), 'section');
|
||||
foreach ($course_sections as $section) {
|
||||
if ($child = $this->courseinfo->get_file_info('course', 'section', $section->id, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
return $this->courseinfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of course section backup area
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_info_area_backup_section extends file_info {
|
||||
protected $course;
|
||||
protected $courseinfo;
|
||||
|
||||
public function __construct($browser, $context, $course, file_info_context_course $courseinfo) {
|
||||
parent::__construct($browser, $context);
|
||||
$this->course = $course;
|
||||
$this->courseinfo = $courseinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, component, filearea, itemid, filepath and filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid' => $this->context->id,
|
||||
'component' => 'backup',
|
||||
'filearea' => 'section',
|
||||
'itemid' => null,
|
||||
'filepath' => null,
|
||||
'filename' => null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised visible name.
|
||||
* @return string
|
||||
*/
|
||||
public function get_visible_name() {
|
||||
$format = $this->course->format;
|
||||
$sectionsname = get_string('sectionbackup', 'repository');
|
||||
|
||||
return $sectionsname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
global $DB;
|
||||
|
||||
$children = array();
|
||||
|
||||
$course_sections = $DB->get_records('course_sections', array('course'=>$this->course->id), 'section');
|
||||
foreach ($course_sections as $section) {
|
||||
if ($child = $this->courseinfo->get_file_info('backup', 'section', $section->id, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
return $this->browser->get_file_info($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,23 @@
|
||||
/**
|
||||
* Utility class for browsing of curse category files.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Represents a course category context in the tree navigated by @see{file_browser}.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_info_coursecat extends file_info {
|
||||
class file_info_context_coursecat extends file_info {
|
||||
protected $category;
|
||||
|
||||
public function __construct($browser, $context, $category) {
|
||||
@ -37,17 +44,68 @@ class file_info_coursecat extends file_info {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
* Return information about this specific context level
|
||||
*
|
||||
* @param $component
|
||||
* @param $filearea
|
||||
* @param $itemid
|
||||
* @param $filepath
|
||||
* @param $filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid'=>$this->context->id,
|
||||
'filearea' =>null,
|
||||
'itemid' =>null,
|
||||
'filepath' =>null,
|
||||
'filename' =>null);
|
||||
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $DB;
|
||||
|
||||
if (!$this->category->visible and !has_capability('moodle/category:viewhiddencategories', $this->context)) {
|
||||
if (empty($component)) {
|
||||
// we can not list the category contents, so try parent, or top system
|
||||
if ($this->category->parent and $pc = $DB->get_record('course_categories', array('id'=>$this->category->parent))) {
|
||||
$parent = get_context_instance(CONTEXT_COURSECAT, $pc->id);
|
||||
return $this->browser->get_file_info($parent);
|
||||
} else {
|
||||
return $this->browser->get_file_info();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($component)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$methodname = "get_area_{$component}_{$filearea}";
|
||||
if (method_exists($this, $methodname)) {
|
||||
return $this->$methodname($itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function get_area_coursecat_description($itemid, $filepath, $filename) {
|
||||
global $CFG;
|
||||
|
||||
if (!has_capability('moodle/course:update', $this->context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_null($itemid)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'coursecat', 'description', 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'coursecat', 'description', 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areacategoryintro', 'repository'), false, true, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,14 +141,14 @@ class file_info_coursecat extends file_info {
|
||||
|
||||
$children = array();
|
||||
|
||||
if ($child = $this->browser->get_file_info($this->context, 'coursecat_intro', 0)) {
|
||||
if ($child = $this->get_area_coursecat_description(0, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
|
||||
$course_cats = $DB->get_records('course_categories', array('parent'=>$this->category->id), 'sortorder');
|
||||
$course_cats = $DB->get_records('course_categories', array('parent'=>$this->category->id), 'sortorder', 'id,visible');
|
||||
foreach ($course_cats as $category) {
|
||||
$context = get_context_instance(CONTEXT_COURSECAT, $category->id);
|
||||
if (!$category->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
|
||||
if (!$category->visible and !has_capability('moodle/category:viewhiddencategories', $context)) {
|
||||
continue;
|
||||
}
|
||||
if ($child = $this->browser->get_file_info($context)) {
|
||||
@ -98,7 +156,7 @@ class file_info_coursecat extends file_info {
|
||||
}
|
||||
}
|
||||
|
||||
$courses = $DB->get_records('course', array('category'=>$this->category->id), 'sortorder');
|
||||
$courses = $DB->get_records('course', array('category'=>$this->category->id), 'sortorder', 'id,visible');
|
||||
foreach ($courses as $course) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
|
221
lib/filebrowser/file_info_context_module.php
Normal file
221
lib/filebrowser/file_info_context_module.php
Normal file
@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of module files.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Represents a module context in the tree navigated by @see{file_browser}.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_info_context_module extends file_info {
|
||||
protected $course;
|
||||
protected $cm;
|
||||
protected $modname;
|
||||
protected $areas;
|
||||
|
||||
public function __construct($browser, $context, $course, $cm, $modname) {
|
||||
global $DB, $CFG;
|
||||
|
||||
parent::__construct($browser, $context);
|
||||
$this->course = $course;
|
||||
$this->cm = $cm;
|
||||
$this->modname = $modname;
|
||||
|
||||
include_once("$CFG->dirroot/mod/$modname/lib.php");
|
||||
|
||||
//find out all supported areas
|
||||
$functionname = 'mod_'.$modname.'_get_file_areas';
|
||||
$functionname_old = $modname.'_get_file_areas';
|
||||
|
||||
if (function_exists($functionname)) {
|
||||
$this->areas = $functionname($course, $cm, $context);
|
||||
} else if (function_exists($functionname_old)) {
|
||||
$this->areas = $functionname_old($course, $cm, $context);
|
||||
} else {
|
||||
$this->areas = array();
|
||||
}
|
||||
unset($this->areas['intro']); // hardcoded, ignore attempts to override it
|
||||
}
|
||||
|
||||
/**
|
||||
* Return information about this specific context level
|
||||
*
|
||||
* @param $component
|
||||
* @param $filearea
|
||||
* @param $itemid
|
||||
* @param $filepath
|
||||
* @param $filename
|
||||
*/
|
||||
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $USER;
|
||||
|
||||
if (!is_enrolled($this->context) and !is_viewing($this->context)) {
|
||||
// no peaking here if not enrolled or inspector
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($component)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($component == 'mod_'.$this->modname and $filearea === 'intro') {
|
||||
return $this->get_area_intro($itemid, $filepath, $filename);
|
||||
} else if ($component == 'backup' and $filearea === 'activity') {
|
||||
return $this->get_area_backup($itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
$functionname = 'mod_'.$this->modname.'_get_file_info';
|
||||
$functionname_old = $this->modname.'_get_file_info';
|
||||
|
||||
if (function_exists($functionname)) {
|
||||
return $functionname($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
|
||||
} else if (function_exists($functionname_old)) {
|
||||
return $functionname_old($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function get_area_intro($itemid, $filepath, $filename) {
|
||||
global $CFG;
|
||||
|
||||
if (!plugin_supports('mod', $this->modname, FEATURE_MOD_INTRO, true) or !has_capability('moodle/course:managefiles', $this->context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($itemid)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'mod_'.$this->modname, 'intro', 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'mod_'.$this->modname, 'intro', 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('moduleintro'), false, true, true, false);
|
||||
}
|
||||
|
||||
protected function get_area_backup($itemid, $filepath, $filename) {
|
||||
global $CFG;
|
||||
|
||||
if (!has_capability('moodle/backup:backupactivity', $this->context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($itemid)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'backup', 'activity', 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'backup', 'activity', 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$downloadable = has_capability('moodle/backup:downloadfile', $this->context);
|
||||
$uploadable = has_capability('moodle/restore:uploadfile', $this->context);
|
||||
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('activitybackup', 'repository'), false, $downloadable, $uploadable, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised visible name.
|
||||
* @return string
|
||||
*/
|
||||
public function get_visible_name() {
|
||||
return $this->cm->name.' ('.get_string('modulename', $this->cm->modname).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
$children = array();
|
||||
|
||||
if ($child = $this->get_area_backup(0, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
if ($child = $this->get_area_intro(0, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
|
||||
foreach ($this->areas as $area=>$desctiption) {
|
||||
if ($child = $this->get_file_info('mod_'.$this->modname, $area, null, null, null)) {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
$pcid = get_parent_contextid($this->context);
|
||||
$parent = get_context_instance_by_id($pcid);
|
||||
return $this->browser->get_file_info($parent);
|
||||
}
|
||||
}
|
@ -19,32 +19,42 @@
|
||||
/**
|
||||
* Utility class for browsing of system files.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Represents the system context in the tree navigated by @see{file_browser}.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_info_system extends file_info {
|
||||
public function __construct($browser) {
|
||||
parent::__construct($browser, get_context_instance(CONTEXT_SYSTEM));
|
||||
class file_info_context_system extends file_info {
|
||||
public function __construct($browser, $context) {
|
||||
parent::__construct($browser, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
* Return information about this specific part of context level
|
||||
* @param $component
|
||||
* @param $filearea
|
||||
* @param $itemid
|
||||
* @param $filepath
|
||||
* @param $filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid'=>$this->context->id,
|
||||
'filearea' =>null,
|
||||
'itemid' =>null,
|
||||
'filepath' =>null,
|
||||
'filename' =>null);
|
||||
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
|
||||
if (empty($component)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
// no components supported at this level yet
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,10 +94,10 @@ class file_info_system extends file_info {
|
||||
$children[] = $child;
|
||||
}
|
||||
|
||||
$course_cats = $DB->get_records('course_categories', array('parent'=>0), 'sortorder');
|
||||
$course_cats = $DB->get_records('course_categories', array('parent'=>0), 'sortorder', 'id,visible');
|
||||
foreach ($course_cats as $category) {
|
||||
$context = get_context_instance(CONTEXT_COURSECAT, $category->id);
|
||||
if (!$category->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
|
||||
if (!$category->visible and !has_capability('moodle/category:viewhiddencategories', $context)) {
|
||||
continue;
|
||||
}
|
||||
if ($child = $this->browser->get_file_info($context)) {
|
||||
@ -95,7 +105,7 @@ class file_info_system extends file_info {
|
||||
}
|
||||
}
|
||||
|
||||
$courses = $DB->get_records('course', array('category'=>0), 'sortorder');
|
||||
$courses = $DB->get_records('course', array('category'=>0), 'sortorder', 'id,visible');
|
||||
foreach ($courses as $course) {
|
||||
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
|
||||
continue;
|
259
lib/filebrowser/file_info_context_user.php
Normal file
259
lib/filebrowser/file_info_context_user.php
Normal file
@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for browsing of user files.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Represents a user context in the tree navigated by @see{file_browser}.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_info_context_user extends file_info {
|
||||
protected $user;
|
||||
|
||||
public function __construct($browser, $context, $user) {
|
||||
parent::__construct($browser, $context);
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return information about this specific context level
|
||||
*
|
||||
* @param $component
|
||||
* @param $filearea
|
||||
* @param $itemid
|
||||
* @param $filepath
|
||||
* @param $filename
|
||||
*/
|
||||
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $USER;
|
||||
|
||||
if (!isloggedin() or isguestuser()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($component)) {
|
||||
// access control: list areas only for myself
|
||||
if ($this->user->id != $USER->id) {
|
||||
// no list of areas for other users
|
||||
return null;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
$methodname = "get_area_{$component}_{$filearea}";
|
||||
if (method_exists($this, $methodname)) {
|
||||
return $this->$methodname($itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function get_area_user_private($itemid, $filepath, $filename) {
|
||||
global $USER, $CFG;
|
||||
|
||||
// access control: only my files, nobody else
|
||||
if ($this->user->id != $USER->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_null($itemid)) {
|
||||
// go to parent, we do not use itemids here in private area
|
||||
return $this;;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'user', 'private', 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
// root dir does not exist yet
|
||||
$storedfile = new virtual_root_file($this->context->id, 'user', 'private', 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
|
||||
//TODO: user quota from $CFG->userquota
|
||||
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserpersonal', 'repository'), false, true, true, false);
|
||||
}
|
||||
|
||||
protected function get_area_user_profile($itemid, $filepath, $filename) {
|
||||
global $USER, $CFG;
|
||||
|
||||
if (!has_capability('moodle/user:update', $this->context)) {
|
||||
// the idea here is that only admins should be able to list/modify files in user profile, the rest has to use profile page
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_null($itemid)) {
|
||||
// go to parent, we do not use itemids here in profile area
|
||||
return $this;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'user', 'profile', 0, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'user', 'profile', 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserprofile', 'repository'), false, true, true, false);
|
||||
}
|
||||
|
||||
protected function get_area_user_draft($itemid, $filepath, $filename) {
|
||||
global $USER, $CFG;
|
||||
|
||||
// access control: only my files
|
||||
if ($this->user->id != $USER->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($itemid)) {
|
||||
// do not browse itemids - you must know the draftid to see what is there
|
||||
return null;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'user', 'draft', $itemid, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'user', 'draft', $itemid);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserdraft', 'repository'), true, true, true, true);
|
||||
}
|
||||
|
||||
protected function get_area_user_backup($itemid, $filepath, $filename) {
|
||||
global $USER, $CFG;
|
||||
|
||||
// access control: only my files, nobody else - TODO: maybe we need new capability here
|
||||
if ($this->context->instanceid != $USER->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_null($itemid)) {
|
||||
// go to parent, we do not use itemids here in profile area
|
||||
return $this;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$filepath = is_null($filepath) ? '/' : $filepath;
|
||||
$filename = is_null($filename) ? '.' : $filename;
|
||||
|
||||
if (!$storedfile = $fs->get_file($this->context->id, 'user', 'backup', $itemid, $filepath, $filename)) {
|
||||
if ($filepath === '/' and $filename === '.') {
|
||||
$storedfile = new virtual_root_file($this->context->id, 'user', 'backup', 0);
|
||||
} else {
|
||||
// not found
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
||||
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserbackup', 'repository'), false, true, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised visible name.
|
||||
* @return string
|
||||
*/
|
||||
public function get_visible_name() {
|
||||
return fullname($this->user, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I add new files or directories?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_writable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is directory?
|
||||
* @return bool
|
||||
*/
|
||||
public function is_directory() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of children.
|
||||
* @return array of file_info instances
|
||||
*/
|
||||
public function get_children() {
|
||||
global $USER, $CFG;
|
||||
|
||||
$children = array();
|
||||
|
||||
if ($child = $this->get_area_user_private(0, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
/*
|
||||
if ($child = $this->get_area_user_profile(0, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
*/
|
||||
if ($child = $this->get_area_user_backup(0, '/', '.')) {
|
||||
$children[] = $child;
|
||||
}
|
||||
// do not list draft area here - it is browsable only if you know the draft itemid ;-)
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parent file_info instance
|
||||
* @return file_info or null for root
|
||||
*/
|
||||
public function get_parent() {
|
||||
return $this->browser->get_file_info();
|
||||
}
|
||||
}
|
@ -19,15 +19,22 @@
|
||||
/**
|
||||
* Utility class for browsing of stored files.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Represents an actual file or folder - a row in the file table -
|
||||
* in the tree navigated by @see{file_browser}.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_info_stored extends file_info {
|
||||
protected $lf;
|
||||
@ -38,7 +45,20 @@ class file_info_stored extends file_info {
|
||||
protected $writeaccess;
|
||||
protected $areaonly;
|
||||
|
||||
public function __construct($browser, $context, $storedfile, $urlbase, $topvisiblename, $itemidused, $readaccess, $writeaccess, $areaonly) {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param file_browser $browser
|
||||
* @param object $context
|
||||
* @param stored_file $storedfile
|
||||
* @param string $urlbase the serving script - usually the $CFG->wwwroot/.'pluginfile.php'
|
||||
* @param string $topvisiblename the human readable name of this area
|
||||
* @param string $itemidused false if itemid always 0 and not included in URL
|
||||
* @param string $readaccess allow file reading
|
||||
* @param string $writeaccess allow file write, delete
|
||||
* @param string $areaonly do not show links to parent context/area
|
||||
*/
|
||||
public function __construct(file_browser $browser, $context, $storedfile, $urlbase, $topvisiblename, $itemidused, $readaccess, $writeaccess, $areaonly) {
|
||||
parent::__construct($browser, $context);
|
||||
|
||||
$this->lf = $storedfile;
|
||||
@ -54,10 +74,11 @@ class file_info_stored extends file_info {
|
||||
* Returns list of standard virtual file/directory identification.
|
||||
* The difference from stored_file parameters is that null values
|
||||
* are allowed in all fields
|
||||
* @return array with keys contextid, filearea, itemid, filepath and filename
|
||||
* @return array with keys contextid, component, filearea, itemid, filepath and filename
|
||||
*/
|
||||
public function get_params() {
|
||||
return array('contextid'=>$this->context->id,
|
||||
'component' =>$this->lf->get_component(),
|
||||
'filearea' =>$this->lf->get_filearea(),
|
||||
'itemid' =>$this->lf->get_itemid(),
|
||||
'filepath' =>$this->lf->get_filepath(),
|
||||
@ -94,8 +115,6 @@ class file_info_stored extends file_info {
|
||||
* @return string url
|
||||
*/
|
||||
public function get_url($forcedownload=false, $https=false) {
|
||||
global $CFG;
|
||||
|
||||
if (!$this->is_readable()) {
|
||||
return null;
|
||||
}
|
||||
@ -106,15 +125,16 @@ class file_info_stored extends file_info {
|
||||
|
||||
$this->urlbase;
|
||||
$contextid = $this->lf->get_contextid();
|
||||
$component = $this->lf->get_component();
|
||||
$filearea = $this->lf->get_filearea();
|
||||
$filepath = $this->lf->get_filepath();
|
||||
$filename = $this->lf->get_filename();
|
||||
$itemid = $this->lf->get_itemid();
|
||||
|
||||
if ($this->itemidused) {
|
||||
$path = '/'.$contextid.'/'.$filearea.'/'.$itemid.$filepath.$filename;
|
||||
$path = '/'.$contextid.'/'.$component.'/'.$filearea.'/'.$itemid.$filepath.$filename;
|
||||
} else {
|
||||
$path = '/'.$contextid.'/'.$filearea.$filepath.$filename;
|
||||
$path = '/'.$contextid.'/'.$component.'/'.$filearea.$filepath.$filename;
|
||||
}
|
||||
return file_encode_url($this->urlbase, $path, $forcedownload, $https);
|
||||
}
|
||||
@ -219,7 +239,7 @@ class file_info_stored extends file_info {
|
||||
$result = array();
|
||||
$fs = get_file_storage();
|
||||
|
||||
$storedfiles = $fs->get_directory_files($this->context->id, $this->lf->get_filearea(), $this->lf->get_itemid(),
|
||||
$storedfiles = $fs->get_directory_files($this->context->id, $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(),
|
||||
$this->lf->get_filepath(), false, true, "filepath, filename");
|
||||
foreach ($storedfiles as $file) {
|
||||
$result[] = new file_info_stored($this->browser, $this->context, $file, $this->urlbase, $this->topvisiblename,
|
||||
@ -238,14 +258,14 @@ class file_info_stored extends file_info {
|
||||
if ($this->areaonly) {
|
||||
return null;
|
||||
} else if ($this->itemidused) {
|
||||
return $this->browser->get_file_info($this->context, $this->lf->get_filearea());
|
||||
return $this->browser->get_file_info($this->context, $this->lf->get_component(), $this->lf->get_filearea());
|
||||
} else {
|
||||
return $this->browser->get_file_info($this->context);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->lf->is_directory()) {
|
||||
return $this->browser->get_file_info($this->context, $this->lf->get_filearea(), $this->lf->get_itemid(), $this->lf->get_filepath(), '.');
|
||||
return $this->browser->get_file_info($this->context, $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $this->lf->get_filepath(), '.');
|
||||
}
|
||||
|
||||
$filepath = $this->lf->get_filepath();
|
||||
@ -255,7 +275,7 @@ class file_info_stored extends file_info {
|
||||
$filepath = implode('/', $dirs);
|
||||
$filepath = ($filepath === '') ? '/' : "/$filepath/";
|
||||
|
||||
return $this->browser->get_file_info($this->context, $this->lf->get_filearea(), $this->lf->get_itemid(), $filepath, '.');
|
||||
return $this->browser->get_file_info($this->context, $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $filepath, '.');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -265,7 +285,7 @@ class file_info_stored extends file_info {
|
||||
* @param int id of author, default $USER->id
|
||||
* @return file_info new directory
|
||||
*/
|
||||
public function create_directory($newdirname, $userid=null) {
|
||||
public function create_directory($newdirname, $userid = NULL) {
|
||||
if (!$this->is_writable() or !$this->lf->is_directory()) {
|
||||
return null;
|
||||
}
|
||||
@ -279,8 +299,8 @@ class file_info_stored extends file_info {
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
if ($file = $fs->create_directory($this->lf->get_contextid(), $this->lf->get_filearea(), $this->lf->get_itemid(), $filepath, $userid)) {
|
||||
return $this->browser->get_file_info($this->context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
if ($file = $fs->create_directory($this->lf->get_contextid(), $this->lf->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), $filepath, $userid)) {
|
||||
return $this->browser->get_file_info($this->context, $this->lf->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -294,7 +314,7 @@ class file_info_stored extends file_info {
|
||||
* @param int id of author, default $USER->id
|
||||
* @return file_info new file
|
||||
*/
|
||||
public function create_file_from_string($newfilename, $content, $userid=null) {
|
||||
public function create_file_from_string($newfilename, $content, $userid = NULL) {
|
||||
if (!$this->is_writable() or !$this->lf->is_directory()) {
|
||||
return null;
|
||||
}
|
||||
@ -310,12 +330,13 @@ class file_info_stored extends file_info {
|
||||
|
||||
$newrecord = new object();
|
||||
$newrecord->contextid = $this->lf->get_contextid();
|
||||
$newrecord->component = $this->lf->get_component();
|
||||
$newrecord->filearea = $this->lf->get_filearea();
|
||||
$newrecord->itemid = $this->lf->get_itemid();
|
||||
$newrecord->filepath = $this->lf->get_filepath();
|
||||
$newrecord->filename = $newfilename;
|
||||
|
||||
if ($fs->file_exists($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) {
|
||||
if ($fs->file_exists($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) {
|
||||
// file already exists, sorry
|
||||
return null;
|
||||
}
|
||||
@ -326,7 +347,7 @@ class file_info_stored extends file_info {
|
||||
$newrecord->userid = $userid;
|
||||
|
||||
if ($file = $fs->create_file_from_string($newrecord, $content)) {
|
||||
return $this->browser->get_file_info($this->context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
return $this->browser->get_file_info($this->context, $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -339,7 +360,7 @@ class file_info_stored extends file_info {
|
||||
* @param int id of author, default $USER->id
|
||||
* @return file_info new file
|
||||
*/
|
||||
public function create_file_from_pathname($newfilename, $pathname, $userid=null) {
|
||||
public function create_file_from_pathname($newfilename, $pathname, $userid = NULL) {
|
||||
if (!$this->is_writable() or !$this->lf->is_directory()) {
|
||||
return null;
|
||||
}
|
||||
@ -355,12 +376,13 @@ class file_info_stored extends file_info {
|
||||
|
||||
$newrecord = new object();
|
||||
$newrecord->contextid = $this->lf->get_contextid();
|
||||
$newrecord->component = $this->lf->get_component();
|
||||
$newrecord->filearea = $this->lf->get_filearea();
|
||||
$newrecord->itemid = $this->lf->get_itemid();
|
||||
$newrecord->filepath = $this->lf->get_filepath();
|
||||
$newrecord->filename = $newfilename;
|
||||
|
||||
if ($fs->file_exists($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) {
|
||||
if ($fs->file_exists($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) {
|
||||
// file already exists, sorry
|
||||
return null;
|
||||
}
|
||||
@ -371,7 +393,7 @@ class file_info_stored extends file_info {
|
||||
$newrecord->userid = $userid;
|
||||
|
||||
if ($file = $fs->create_file_from_pathname($newrecord, $pathname)) {
|
||||
return $this->browser->get_file_info($this->context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
return $this->browser->get_file_info($this->context, $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -384,7 +406,7 @@ class file_info_stored extends file_info {
|
||||
* @param int id of author, default $USER->id
|
||||
* @return file_info new file
|
||||
*/
|
||||
public function create_file_from_storedfile($newfilename, $fid, $userid=null) {
|
||||
public function create_file_from_storedfile($newfilename, $fid, $userid = NULL) {
|
||||
if (!$this->is_writable() or $this->lf->get_filename() !== '.') {
|
||||
return null;
|
||||
}
|
||||
@ -400,12 +422,13 @@ class file_info_stored extends file_info {
|
||||
|
||||
$newrecord = new object();
|
||||
$newrecord->contextid = $this->lf->get_contextid();
|
||||
$newrecord->component = $this->lf->get_component();
|
||||
$newrecord->filearea = $this->lf->get_filearea();
|
||||
$newrecord->itemid = $this->lf->get_itemid();
|
||||
$newrecord->filepath = $this->lf->get_filepath();
|
||||
$newrecord->filename = $newfilename;
|
||||
|
||||
if ($fs->file_exists($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) {
|
||||
if ($fs->file_exists($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) {
|
||||
// file already exists, sorry
|
||||
return null;
|
||||
}
|
||||
@ -416,7 +439,7 @@ class file_info_stored extends file_info {
|
||||
$newrecord->userid = $userid;
|
||||
|
||||
if ($file = $fs->create_file_from_storedfile($newrecord, $fid)) {
|
||||
return $this->browser->get_file_info($this->context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
return $this->browser->get_file_info($this->context, $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -433,7 +456,7 @@ class file_info_stored extends file_info {
|
||||
if ($this->is_directory()) {
|
||||
$filepath = $this->lf->get_filepath();
|
||||
$fs = get_file_storage();
|
||||
$storedfiles = $fs->get_area_files($this->context->id, $this->lf->get_filearea(), $this->lf->get_itemid(), "");
|
||||
$storedfiles = $fs->get_area_files($this->context->id, $file->get_component(), $this->lf->get_filearea(), $this->lf->get_itemid(), "");
|
||||
foreach ($storedfiles as $file) {
|
||||
if (strpos($file->get_filepath(), $filepath) === 0) {
|
||||
$file->delete();
|
||||
@ -453,16 +476,16 @@ class file_info_stored extends file_info {
|
||||
* @param string $filename
|
||||
* @return boolean success
|
||||
*/
|
||||
public function copy_to_storage($contextid, $filearea, $itemid, $filepath, $filename) {
|
||||
public function copy_to_storage($contextid, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
if (!$this->is_readable() or $this->is_directory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
if ($existing = $fs->get_file($contextid, $filearea, $itemid, $filepath, $filename)) {
|
||||
if ($existing = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||
$existing->delete();
|
||||
}
|
||||
$file_record = array('contextid'=>$contextid, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename);
|
||||
$file_record = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename);
|
||||
$fs->create_file_from_storedfile($file_record, $this->lf);
|
||||
|
||||
return true;
|
@ -19,26 +19,35 @@
|
||||
/**
|
||||
* Class simulating empty directories.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-browser
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Represents the root directory of an empty file area in the tree navigated by
|
||||
* @see{file_browser}.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filebrowser
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class virtual_root_file {
|
||||
protected $contextid;
|
||||
protected $component;
|
||||
protected $filearea;
|
||||
protected $itemid;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($contextid, $filearea, $itemid) {
|
||||
public function __construct($contextid, $component, $filearea, $itemid) {
|
||||
$this->contextid = $contextid;
|
||||
$this->component = $component;
|
||||
$this->filearea = $filearea;
|
||||
$this->itemid = $itemid;
|
||||
}
|
||||
@ -125,13 +134,14 @@ class virtual_root_file {
|
||||
* Extract file to given file path (real OS filesystem), existing files are overwrited
|
||||
* @param object $file_packer
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $pathbase
|
||||
* @param int $userid
|
||||
* @return mixed list of processed files; false if error
|
||||
*/
|
||||
public function extract_to_storage(file_packer $packer, $contextid, $filearea, $itemid, $pathbase, $userid=null) {
|
||||
public function extract_to_storage(file_packer $packer, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -157,6 +167,10 @@ class virtual_root_file {
|
||||
return $this->contextid;
|
||||
}
|
||||
|
||||
public function get_component() {
|
||||
return $this->component;
|
||||
}
|
||||
|
||||
public function get_filearea() {
|
||||
return $this->filearea;
|
||||
}
|
||||
@ -206,7 +220,22 @@ class virtual_root_file {
|
||||
}
|
||||
|
||||
public function get_pathnamehash() {
|
||||
return sha1($this->get_contextid().$this->get_filearea().$this->get_itemid().$this->get_filepath().$this->get_filename());
|
||||
return sha1('/'.$this->get_contextid().'/'.$this->get_component().'/'.$this->get_filearea().'/'.$this->get_itemid().$this->get_filepath().$this->get_filename());
|
||||
}
|
||||
|
||||
public function get_license() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_author() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_source() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_sortorder() {
|
||||
return null;
|
||||
}
|
||||
}
|
156
lib/filelib.php
156
lib/filelib.php
@ -24,14 +24,15 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/** @var string unique string constant. */
|
||||
define('BYTESERVING_BOUNDARY', 's1k2o3d4a5k6s7');
|
||||
|
||||
require_once("$CFG->libdir/file/file_exceptions.php");
|
||||
require_once("$CFG->libdir/file/file_storage.php");
|
||||
require_once("$CFG->libdir/file/file_browser.php");
|
||||
|
||||
require_once("$CFG->libdir/packer/zip_packer.php");
|
||||
require_once("$CFG->libdir/filestorage/file_exceptions.php");
|
||||
require_once("$CFG->libdir/filestorage/file_storage.php");
|
||||
require_once("$CFG->libdir/filestorage/zip_packer.php");
|
||||
require_once("$CFG->libdir/filebrowser/file_browser.php");
|
||||
|
||||
/**
|
||||
* Given a physical path to a file, returns the URL through which it can be reached in Moodle.
|
||||
@ -46,6 +47,8 @@ require_once("$CFG->libdir/packer/zip_packer.php");
|
||||
function get_file_url($path, $options=null, $type='coursefile') {
|
||||
global $CFG, $HTTPSPAGEREQUIRED;
|
||||
|
||||
//TODO: deprecate this
|
||||
|
||||
$path = str_replace('//', '/', $path);
|
||||
$path = trim($path, '/'); // no leading and trailing slashes
|
||||
|
||||
@ -104,6 +107,18 @@ function get_file_url($path, $options=null, $type='coursefile') {
|
||||
return $ffurl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a draft file url.
|
||||
*
|
||||
* @param int $draftid itemid of the draft area of current user
|
||||
* @param string $filepath must start and end with /
|
||||
* @param string $filename
|
||||
*/
|
||||
function file_draftfile_url($draftid, $filepath, $filename) {
|
||||
global $CFG, $USER;
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
return file_encode_url("$CFG->wwwroot/draftfile.php", '/'.$usercontext->id.'/user/draft/'.$draftid.$filepath.$filename, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes file serving url
|
||||
@ -156,11 +171,12 @@ function file_encode_url($urlbase, $path, $forcedownload=false, $https=false) {
|
||||
* @param string $field the name of the database field that holds the html text with embedded media
|
||||
* @param array $options editor options (like maxifiles, maxbytes etc.)
|
||||
* @param object $context context of the editor
|
||||
* @param string $component
|
||||
* @param string $filearea file area name
|
||||
* @param int $itemid item id, required if item exists
|
||||
* @return object modified data object
|
||||
*/
|
||||
function file_prepare_standard_editor($data, $field, array $options, $context=null, $filearea=null, $itemid=null) {
|
||||
function file_prepare_standard_editor($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null) {
|
||||
$options = (array)$options;
|
||||
if (!isset($options['trusttext'])) {
|
||||
$options['trusttext'] = false;
|
||||
@ -208,7 +224,7 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu
|
||||
|
||||
if ($options['maxfiles'] != 0) {
|
||||
$draftid_editor = file_get_submitted_draft_itemid($field);
|
||||
$currenttext = file_prepare_draft_area($draftid_editor, $contextid, $filearea, $itemid, $options, $data->{$field});
|
||||
$currenttext = file_prepare_draft_area($draftid_editor, $contextid, $component, $filearea, $itemid, $options, $data->{$field});
|
||||
$data->{$field.'_editor'} = array('text'=>$currenttext, 'format'=>$data->{$field.'format'}, 'itemid'=>$draftid_editor);
|
||||
} else {
|
||||
$data->{$field.'_editor'} = array('text'=>$data->{$field}, 'format'=>$data->{$field.'format'}, 'itemid'=>0);
|
||||
@ -232,11 +248,12 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu
|
||||
* @param string $field name of the database field containing the html with embedded media files
|
||||
* @param array $options editor options (trusttext, subdirs, maxfiles, maxbytes etc.)
|
||||
* @param object $context context, required for existing data
|
||||
* @param string component
|
||||
* @param string $filearea file area name
|
||||
* @param int $itemid item id, required if item exists
|
||||
* @return object modified data object
|
||||
*/
|
||||
function file_postupdate_standard_editor($data, $field, array $options, $context, $filearea=null, $itemid=null) {
|
||||
function file_postupdate_standard_editor($data, $field, array $options, $context, $component=null, $filearea=null, $itemid=null) {
|
||||
$options = (array)$options;
|
||||
if (!isset($options['trusttext'])) {
|
||||
$options['trusttext'] = false;
|
||||
@ -265,7 +282,7 @@ function file_postupdate_standard_editor($data, $field, array $options, $context
|
||||
if ($options['maxfiles'] == 0 or is_null($filearea) or is_null($itemid) or empty($editor['itemid'])) {
|
||||
$data->{$field} = $editor['text'];
|
||||
} else {
|
||||
$data->{$field} = file_save_draft_area_files($editor['itemid'], $context->id, $filearea, $itemid, $options, $editor['text'], $options['forcehttps']);
|
||||
$data->{$field} = file_save_draft_area_files($editor['itemid'], $context->id, $component, $filearea, $itemid, $options, $editor['text'], $options['forcehttps']);
|
||||
}
|
||||
$data->{$field.'format'} = $editor['format'];
|
||||
|
||||
@ -279,11 +296,12 @@ function file_postupdate_standard_editor($data, $field, array $options, $context
|
||||
* @param string $field name of data field
|
||||
* @param array $options various options
|
||||
* @param object $context context - must already exist
|
||||
* @param string $component
|
||||
* @param string $filearea file area name
|
||||
* @param int $itemid must already exist, usually means data is in db
|
||||
* @return object modified data obejct
|
||||
*/
|
||||
function file_prepare_standard_filemanager($data, $field, array $options, $context=null, $filearea=null, $itemid=null) {
|
||||
function file_prepare_standard_filemanager($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null) {
|
||||
$options = (array)$options;
|
||||
if (!isset($options['subdirs'])) {
|
||||
$options['subdirs'] = false;
|
||||
@ -296,7 +314,7 @@ function file_prepare_standard_filemanager($data, $field, array $options, $conte
|
||||
}
|
||||
|
||||
$draftid_editor = file_get_submitted_draft_itemid($field.'_filemanager');
|
||||
file_prepare_draft_area($draftid_editor, $contextid, $filearea, $itemid, $options);
|
||||
file_prepare_draft_area($draftid_editor, $contextid, $component, $filearea, $itemid, $options);
|
||||
$data->{$field.'_filemanager'} = $draftid_editor;
|
||||
|
||||
return $data;
|
||||
@ -309,11 +327,12 @@ function file_prepare_standard_filemanager($data, $field, array $options, $conte
|
||||
* @param string $field name of data field
|
||||
* @param array $options various options
|
||||
* @param object $context context - must already exist
|
||||
* @param string $component
|
||||
* @param string $filearea file area name
|
||||
* @param int $itemid must already exist, usually means data is in db
|
||||
* @return object modified data obejct
|
||||
*/
|
||||
function file_postupdate_standard_filemanager($data, $field, array $options, $context, $filearea, $itemid) {
|
||||
function file_postupdate_standard_filemanager($data, $field, array $options, $context, $component, $filearea, $itemid) {
|
||||
$options = (array)$options;
|
||||
if (!isset($options['subdirs'])) {
|
||||
$options['subdirs'] = false;
|
||||
@ -329,11 +348,11 @@ function file_postupdate_standard_filemanager($data, $field, array $options, $co
|
||||
$data->$field = '';
|
||||
|
||||
} else {
|
||||
file_save_draft_area_files($data->{$field.'_filemanager'}, $context->id, $filearea, $itemid, $options);
|
||||
file_save_draft_area_files($data->{$field.'_filemanager'}, $context->id, $component, $filearea, $itemid, $options);
|
||||
$fs = get_file_storage();
|
||||
|
||||
if ($fs->get_area_files($context->id, $filearea, $itemid)) {
|
||||
$data->$field = '1'; // TODO: this is an ugly hack
|
||||
if ($fs->get_area_files($context->id, $component, $filearea, $itemid)) {
|
||||
$data->$field = '1'; // TODO: this is an ugly hack (skodak)
|
||||
} else {
|
||||
$data->$field = '';
|
||||
}
|
||||
@ -358,11 +377,10 @@ function file_get_unused_draft_itemid() {
|
||||
}
|
||||
|
||||
$contextid = get_context_instance(CONTEXT_USER, $USER->id)->id;
|
||||
$filearea = 'user_draft';
|
||||
|
||||
$fs = get_file_storage();
|
||||
$draftitemid = rand(1, 999999999);
|
||||
while ($files = $fs->get_area_files($contextid, $filearea, $draftitemid)) {
|
||||
while ($files = $fs->get_area_files($contextid, 'user', 'draft', $draftitemid)) {
|
||||
$draftitemid = rand(1, 999999999);
|
||||
}
|
||||
|
||||
@ -378,13 +396,14 @@ function file_get_unused_draft_itemid() {
|
||||
* @global object
|
||||
* @param int &$draftitemid the id of the draft area to use, or 0 to create a new one, in which case this parameter is updated.
|
||||
* @param integer $contextid This parameter and the next two identify the file area to copy files from.
|
||||
* @param string $component
|
||||
* @param string $filearea helps indentify the file area.
|
||||
* @param integer $itemid helps identify the file area. Can be null if there are no files yet.
|
||||
* @param array $options text and file options ('subdirs'=>false, 'forcehttps'=>false)
|
||||
* @param string $text some html content that needs to have embedded links rewritten to point to the draft area.
|
||||
* @return string if $text was passed in, the rewritten $text is returned. Otherwise NULL.
|
||||
*/
|
||||
function file_prepare_draft_area(&$draftitemid, $contextid, $filearea, $itemid, array $options=null, $text=null) {
|
||||
function file_prepare_draft_area(&$draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null) {
|
||||
global $CFG, $USER;
|
||||
|
||||
$options = (array)$options;
|
||||
@ -401,9 +420,14 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $filearea, $itemid,
|
||||
if (empty($draftitemid)) {
|
||||
// create a new area and copy existing files into
|
||||
$draftitemid = file_get_unused_draft_itemid();
|
||||
$file_record = array('contextid'=>$usercontext->id, 'filearea'=>'user_draft', 'itemid'=>$draftitemid);
|
||||
if (!is_null($itemid) and $files = $fs->get_area_files($contextid, $filearea, $itemid)) {
|
||||
$file_record = array('contextid'=>$usercontext->id, 'component'=>'user', 'filearea'=>'draft', 'itemid'=>$draftitemid);
|
||||
if (!is_null($itemid) and $files = $fs->get_area_files($contextid, $component, $filearea, $itemid)) {
|
||||
foreach ($files as $file) {
|
||||
if ($file->is_directory() and $file->get_filepath() === '/') {
|
||||
// we need a way to mark the age of each draft area,
|
||||
// by not copying the root dir we force it to be created automatically with current timestamp
|
||||
continue;
|
||||
}
|
||||
if (!$options['subdirs'] and ($file->is_directory() or $file->get_filepath() !== '/')) {
|
||||
continue;
|
||||
}
|
||||
@ -419,7 +443,7 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $filearea, $itemid,
|
||||
}
|
||||
|
||||
// relink embedded files - editor can not handle @@PLUGINFILE@@ !
|
||||
return file_rewrite_pluginfile_urls($text, 'draftfile.php', $usercontext->id, 'user_draft', $draftitemid, $options);
|
||||
return file_rewrite_pluginfile_urls($text, 'draftfile.php', $usercontext->id, 'user', 'draft', $draftitemid, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,12 +453,13 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $filearea, $itemid,
|
||||
* @param string $text The content that may contain ULRs in need of rewriting.
|
||||
* @param string $file The script that should be used to serve these files. pluginfile.php, draftfile.php, etc.
|
||||
* @param integer $contextid This parameter and the next two identify the file area to use.
|
||||
* @param string $component
|
||||
* @param string $filearea helps identify the file area.
|
||||
* @param integer $itemid helps identify the file area.
|
||||
* @param array $options text and file options ('forcehttps'=>false)
|
||||
* @return string the processed text.
|
||||
*/
|
||||
function file_rewrite_pluginfile_urls($text, $file, $contextid, $filearea, $itemid, array $options=null) {
|
||||
function file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $filearea, $itemid, array $options=null) {
|
||||
global $CFG;
|
||||
|
||||
$options = (array)$options;
|
||||
@ -446,7 +471,7 @@ function file_rewrite_pluginfile_urls($text, $file, $contextid, $filearea, $item
|
||||
$file = $file . '?file=';
|
||||
}
|
||||
|
||||
$baseurl = "$CFG->wwwroot/$file/$contextid/$filearea/";
|
||||
$baseurl = "$CFG->wwwroot/$file/$contextid/$component/$filearea/";
|
||||
|
||||
if ($itemid !== null) {
|
||||
$baseurl .= "$itemid/";
|
||||
@ -478,22 +503,7 @@ function file_get_draft_area_info($draftitemid) {
|
||||
$results = array();
|
||||
|
||||
// The number of files
|
||||
$draftfiles = $fs->get_area_files($usercontext->id, 'user_draft', $draftitemid, 'id', false);
|
||||
$results['filecount'] = count($draftfiles);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
function file_get_user_area_info($draftitemid, $filearea = 'user_draft') {
|
||||
global $CFG, $USER;
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$fs = get_file_storage();
|
||||
|
||||
$results = array();
|
||||
|
||||
// The number of files
|
||||
$draftfiles = $fs->get_area_files($usercontext->id, $filearea, $draftitemid, 'id', false);
|
||||
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id', false);
|
||||
$results['filecount'] = count($draftfiles);
|
||||
|
||||
return $results;
|
||||
@ -507,14 +517,11 @@ function file_get_user_used_space() {
|
||||
global $DB, $CFG, $USER;
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$fs = get_file_storage();
|
||||
|
||||
// only count files in user context
|
||||
$conditions = array('contextid'=>$usercontext->id);
|
||||
|
||||
$totalbytes = 0;
|
||||
$files = array();
|
||||
$file_records = $DB->get_records('files', $conditions);
|
||||
//TODO: rewrite to true sql SUM(), this is goign to run out of memory if limits are hight!
|
||||
$file_records = $DB->get_records('files', "contextid = ? AND component = 'user' AND filearea != 'draft'", array($usercontext->id));
|
||||
foreach ($file_records as $file_record) {
|
||||
if ($file_record->filename === '.') {
|
||||
continue;
|
||||
@ -534,7 +541,7 @@ function file_get_user_used_space() {
|
||||
* @param string $str
|
||||
* @return string path
|
||||
*/
|
||||
function file_correct_filepath($str) {
|
||||
function file_correct_filepath($str) { //TODO: what is this? (skodak)
|
||||
if ($str == '/' or empty($str)) {
|
||||
return '/';
|
||||
} else {
|
||||
@ -546,14 +553,14 @@ function file_correct_filepath($str) {
|
||||
* Generate a folder tree of draft area of current USER recursively
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param mixed $data
|
||||
* @param mixed $data //TODO: use normal return value instead, this does not fit the rest of api here (skodak)
|
||||
*/
|
||||
function file_get_user_area_folders($draftitemid, $filepath, &$data, $filearea = 'user_draft') {
|
||||
function file_get_drafarea_folders($draftitemid, $filepath, &$data) {
|
||||
global $USER, $OUTPUT, $CFG;
|
||||
$data->children = array();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$fs = get_file_storage();
|
||||
if ($files = $fs->get_directory_files($context->id, $filearea, $draftitemid, $filepath, false)) {
|
||||
if ($files = $fs->get_directory_files($context->id, 'user', 'draft', $draftitemid, $filepath, false)) {
|
||||
foreach ($files as $file) {
|
||||
if ($file->is_directory()) {
|
||||
$item = new stdclass;
|
||||
@ -564,7 +571,7 @@ function file_get_user_area_folders($draftitemid, $filepath, &$data, $filearea =
|
||||
$item->fullname = trim(array_pop($foldername), '/');
|
||||
|
||||
$item->id = uniqid();
|
||||
file_get_user_area_folders($draftitemid, $item->filepath, $item);
|
||||
file_get_drafarea_folders($draftitemid, $item->filepath, $item);
|
||||
$data->children[] = $item;
|
||||
} else {
|
||||
continue;
|
||||
@ -580,7 +587,7 @@ function file_get_user_area_folders($draftitemid, $filepath, &$data, $filearea =
|
||||
* @param string $filepath
|
||||
* @return mixed
|
||||
*/
|
||||
function file_get_user_area_files($draftitemid, $filepath = '/', $filearea = 'user_draft') {
|
||||
function file_get_drafarea_files($draftitemid, $filepath = '/') {
|
||||
global $USER, $OUTPUT, $CFG;
|
||||
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
@ -605,7 +612,7 @@ function file_get_user_area_files($draftitemid, $filepath = '/', $filearea = 'us
|
||||
|
||||
$list = array();
|
||||
$maxlength = 12;
|
||||
if ($files = $fs->get_directory_files($context->id, $filearea, $draftitemid, $filepath, false)) {
|
||||
if ($files = $fs->get_directory_files($context->id, 'user', 'draft', $draftitemid, $filepath, false)) {
|
||||
foreach ($files as $file) {
|
||||
$item = new stdclass;
|
||||
$item->filename = $file->get_filename();
|
||||
@ -642,10 +649,8 @@ function file_get_user_area_files($draftitemid, $filepath = '/', $filearea = 'us
|
||||
$item->shortname = $item->fullname;
|
||||
}
|
||||
} else {
|
||||
$fb = get_file_browser();
|
||||
$fileinfo = $fb->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
$item->url = $fileinfo->get_url();
|
||||
$item->sortorder = $fileinfo->get_sortorder();
|
||||
// do NOT use file browser here!
|
||||
$item->url = file_draftfile_url($draftitemid, $item->filepath, $item->filename);
|
||||
}
|
||||
$list[] = $item;
|
||||
}
|
||||
@ -686,6 +691,7 @@ function file_get_submitted_draft_itemid($elname) {
|
||||
* @param integer $draftitemid the id of the draft area to use. Normally obtained
|
||||
* from file_get_submitted_draft_itemid('elementname') or similar.
|
||||
* @param integer $contextid This parameter and the next two identify the file area to save to.
|
||||
* @param string $component
|
||||
* @param string $filearea indentifies the file area.
|
||||
* @param integer $itemid helps identifies the file area.
|
||||
* @param array $options area options (subdirs=>false, maxfiles=-1, maxbytes=0)
|
||||
@ -694,7 +700,7 @@ function file_get_submitted_draft_itemid($elname) {
|
||||
* @param boolean $forcehttps force https urls.
|
||||
* @return string if $text was passed in, the rewritten $text is returned. Otherwise NULL.
|
||||
*/
|
||||
function file_save_draft_area_files($draftitemid, $contextid, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false) {
|
||||
function file_save_draft_area_files($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false) {
|
||||
global $CFG, $USER;
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
@ -711,17 +717,17 @@ function file_save_draft_area_files($draftitemid, $contextid, $filearea, $itemid
|
||||
$options['maxbytes'] = 0; // unlimited
|
||||
}
|
||||
|
||||
$draftfiles = $fs->get_area_files($usercontext->id, 'user_draft', $draftitemid, 'id');
|
||||
$oldfiles = $fs->get_area_files($contextid, $filearea, $itemid, 'id');
|
||||
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id');
|
||||
$oldfiles = $fs->get_area_files($contextid, $component, $filearea, $itemid, 'id');
|
||||
|
||||
if (count($draftfiles) < 2) {
|
||||
// means there are no files - one file means root dir only ;-)
|
||||
$fs->delete_area_files($contextid, $filearea, $itemid);
|
||||
$fs->delete_area_files($contextid, $component, $filearea, $itemid);
|
||||
|
||||
} else if (count($oldfiles) < 2) {
|
||||
$filecount = 0;
|
||||
// there were no files before - one file means root dir only ;-)
|
||||
$file_record = array('contextid'=>$contextid, 'filearea'=>$filearea, 'itemid'=>$itemid);
|
||||
$file_record = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid);
|
||||
foreach ($draftfiles as $file) {
|
||||
if (!$options['subdirs']) {
|
||||
if ($file->get_filepath() !== '/' or $file->is_directory()) {
|
||||
@ -744,17 +750,17 @@ function file_save_draft_area_files($draftitemid, $contextid, $filearea, $itemid
|
||||
|
||||
} else {
|
||||
// we have to merge old and new files - we want to keep file ids for files that were not changed
|
||||
$file_record = array('contextid'=>$contextid, 'filearea'=>$filearea, 'itemid'=>$itemid);
|
||||
$file_record = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid);
|
||||
|
||||
$newhashes = array();
|
||||
foreach ($draftfiles as $file) {
|
||||
$newhash = sha1($contextid.$filearea.$itemid.$file->get_filepath().$file->get_filename());
|
||||
$newhash = $fs->get_pathname_hash($contextid, $component, $filearea, $itemid, $file->get_filepath(), $file->get_filename());
|
||||
$newhashes[$newhash] = $file;
|
||||
}
|
||||
$filecount = 0;
|
||||
foreach ($oldfiles as $file) {
|
||||
$oldhash = $file->get_pathnamehash();
|
||||
// check if sortorder, filename, filepath, filearea, itemid and contextid changed
|
||||
// check if sortorder, filename, filepath
|
||||
if (isset($newhashes[$oldhash]) && $file->get_sortorder() == $newhashes[$oldhash]->get_sortorder()) {
|
||||
if (!$file->is_directory()) {
|
||||
$filecount++;
|
||||
@ -762,7 +768,7 @@ function file_save_draft_area_files($draftitemid, $contextid, $filearea, $itemid
|
||||
// unchanged file already there
|
||||
unset($newhashes[$oldhash]);
|
||||
} else {
|
||||
// delete files not needed any more
|
||||
// delete files not needed any more - deleted by user
|
||||
$file->delete();
|
||||
}
|
||||
}
|
||||
@ -789,8 +795,8 @@ function file_save_draft_area_files($draftitemid, $contextid, $filearea, $itemid
|
||||
}
|
||||
}
|
||||
|
||||
// purge the draft area
|
||||
$fs->delete_area_files($usercontext->id, 'user_draft', $draftitemid);
|
||||
// note: do not purge the draft area - we clean up areas later in cron,
|
||||
// the reason is that user might press submit twice and they would loose the files
|
||||
|
||||
if (is_null($text)) {
|
||||
return null;
|
||||
@ -798,9 +804,9 @@ function file_save_draft_area_files($draftitemid, $contextid, $filearea, $itemid
|
||||
|
||||
// relink embedded files if text submitted - no absolute links allowed in database!
|
||||
if ($CFG->slasharguments) {
|
||||
$draftbase = "$CFG->wwwroot/draftfile.php/$usercontext->id/user_draft/$draftitemid/";
|
||||
$draftbase = "$CFG->wwwroot/draftfile.php/$usercontext->id/user/draft/$draftitemid/";
|
||||
} else {
|
||||
$draftbase = "$CFG->wwwroot/draftfile.php?file=/$usercontext->id/user_draft/$draftitemid/";
|
||||
$draftbase = "$CFG->wwwroot/draftfile.php?file=/$usercontext->id/user/draft/$draftitemid/";
|
||||
}
|
||||
|
||||
if ($forcehttps) {
|
||||
@ -816,6 +822,7 @@ function file_save_draft_area_files($draftitemid, $contextid, $filearea, $itemid
|
||||
* Set file sort order
|
||||
* @global object $DB
|
||||
* @param integer $contextid the context id
|
||||
* @param string $component
|
||||
* @param string $filearea file area.
|
||||
* @param integer $itemid itemid.
|
||||
* @param string $filepath file path.
|
||||
@ -823,9 +830,9 @@ function file_save_draft_area_files($draftitemid, $contextid, $filearea, $itemid
|
||||
* @param integer $sortorer the sort order of file.
|
||||
* @return boolean
|
||||
*/
|
||||
function file_set_sortorder($contextid, $filearea, $itemid, $filepath, $filename, $sortorder) {
|
||||
function file_set_sortorder($contextid, $component, $filearea, $itemid, $filepath, $filename, $sortorder) {
|
||||
global $DB;
|
||||
$conditions = array('contextid'=>$contextid, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename);
|
||||
$conditions = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename);
|
||||
if ($file_record = $DB->get_record('files', $conditions)) {
|
||||
$sortorder = (int)$sortorder;
|
||||
$file_record->sortorder = $sortorder;
|
||||
@ -839,14 +846,15 @@ function file_set_sortorder($contextid, $filearea, $itemid, $filepath, $filename
|
||||
* reset file sort order number to 0
|
||||
* @global object $DB
|
||||
* @param integer $contextid the context id
|
||||
* @param string $component
|
||||
* @param string $filearea file area.
|
||||
* @param integer $itemid itemid.
|
||||
* @return boolean
|
||||
*/
|
||||
function file_reset_sortorder($contextid, $filearea, $itemid=false) {
|
||||
function file_reset_sortorder($contextid, $component, $filearea, $itemid=false) {
|
||||
global $DB;
|
||||
|
||||
$conditions = array('contextid'=>$contextid, 'filearea'=>$filearea);
|
||||
$conditions = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea);
|
||||
if ($itemid !== false) {
|
||||
$conditions['itemid'] = $itemid;
|
||||
}
|
||||
@ -2964,7 +2972,7 @@ class filetype_parser {
|
||||
public function __construct($file = '') {
|
||||
global $CFG;
|
||||
if (empty($file)) {
|
||||
$this->file = $CFG->libdir.'/file/file_types.mm';
|
||||
$this->file = $CFG->libdir.'/filestorage/file_types.mm';
|
||||
} else {
|
||||
$this->file = $file;
|
||||
}
|
||||
@ -3041,7 +3049,7 @@ class filetype_parser {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
exit('Failed to open file');
|
||||
exit('Failed to open file lib/filestorage/file_types.mm');
|
||||
}
|
||||
return $this->result;
|
||||
}
|
||||
|
@ -19,12 +19,22 @@
|
||||
/**
|
||||
* Abstraction of general file archives.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-packer
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Each file arcive type must extend this class.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class file_archive implements Iterator {
|
||||
|
||||
/** Open archive if exists, fail if does not exist. */
|
@ -18,28 +18,41 @@
|
||||
/**
|
||||
* File handling related exceptions.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Basic file related exception class
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_exception extends moodle_exception {
|
||||
function __construct($errorcode, $a=NULL, $debuginfo=null) {
|
||||
function __construct($errorcode, $a=NULL, $debuginfo = NULL) {
|
||||
parent::__construct($errorcode, '', '', $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can not create file exception
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class stored_file_creation_exception extends file_exception {
|
||||
function __construct($contextid, $filearea, $itemid, $filepath, $filename, $debuginfo=null) {
|
||||
function __construct($contextid, $component, $filearea, $itemid, $filepath, $filename, $debuginfo = NULL) {
|
||||
$a = new object();
|
||||
$a->contextid = $contextid;
|
||||
$a->component = $component;
|
||||
$a->filearea = $filearea;
|
||||
$a->itemid = $itemid;
|
||||
$a->filepath = $filepath;
|
||||
@ -50,18 +63,28 @@ class stored_file_creation_exception extends file_exception {
|
||||
|
||||
/**
|
||||
* No file access exception.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_access_exception extends file_exception {
|
||||
function __construct($debuginfo=null) {
|
||||
function __construct($debuginfo = NULL) {
|
||||
parent::__construct('nopermissions', NULL, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash file content problem exception.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_pool_content_exception extends file_exception {
|
||||
function __construct($contenthash, $debuginfo=null) {
|
||||
function __construct($contenthash, $debuginfo = NULL) {
|
||||
parent::__construct('hashpoolproblem', $contenthash, $debuginfo);
|
||||
}
|
||||
}
|
@ -19,14 +19,21 @@
|
||||
/**
|
||||
* Abstraction of general file packer.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-packer
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Abstract class for archiving of files.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class file_packer {
|
||||
|
||||
@ -34,13 +41,14 @@ abstract class file_packer {
|
||||
* Archive files and store the result in file storage
|
||||
* @param array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file)
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return mixed false if error stored file instance if ok
|
||||
*/
|
||||
public abstract function archive_to_storage($files, $contextid, $filearea, $itemid, $filepath, $filename, $userid=null);
|
||||
public abstract function archive_to_storage($files, $contextid, $component, $filearea, $itemid, $filepath, $filename, $userid = NULL);
|
||||
|
||||
/**
|
||||
* Archive files and store the result in os file
|
||||
@ -62,12 +70,13 @@ abstract class file_packer {
|
||||
* Extract file to given file path (real OS filesystem), existing files are overwrited
|
||||
* @param mixed $archivefile full pathname of zip file or stored_file instance
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @return mixed list of processed files; false if error
|
||||
*/
|
||||
public abstract function extract_to_storage($archivefile, $contextid, $filearea, $itemid, $pathbase, $userid=null);
|
||||
public abstract function extract_to_storage($archivefile, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL);
|
||||
|
||||
/**
|
||||
* Returns array of info about all files in archive
|
@ -19,13 +19,15 @@
|
||||
/**
|
||||
* Core file storage class definition.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-storage
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once("$CFG->libdir/file/stored_file.php");
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/filestorage/stored_file.php");
|
||||
|
||||
/**
|
||||
* File storage class used for low level access to stored files.
|
||||
@ -105,27 +107,29 @@ class file_storage {
|
||||
* performance and overcome db index size limits.
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return string sha1 hash
|
||||
*/
|
||||
public static function get_pathname_hash($contextid, $filearea, $itemid, $filepath, $filename) {
|
||||
return sha1($contextid.$filearea.$itemid.$filepath.$filename);
|
||||
public static function get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
return sha1("/$contextid/$component/$filearea/$itemid".$filepath.$filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this file exist?
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return bool
|
||||
*/
|
||||
public function file_exists($contextid, $filearea, $itemid, $filepath, $filename) {
|
||||
public function file_exists($contextid, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
$filepath = clean_param($filepath, PARAM_PATH);
|
||||
$filename = clean_param($filename, PARAM_FILE);
|
||||
|
||||
@ -133,7 +137,7 @@ class file_storage {
|
||||
$filename = '.';
|
||||
}
|
||||
|
||||
$pathnamehash = $this->get_pathname_hash($contextid, $filearea, $itemid, $filepath, $filename);
|
||||
$pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename);
|
||||
return $this->file_exists_by_hash($pathnamehash);
|
||||
}
|
||||
|
||||
@ -188,13 +192,14 @@ class file_storage {
|
||||
* Fetch locally stored file.
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return stored_file instance if exists, false if not
|
||||
*/
|
||||
public function get_file($contextid, $filearea, $itemid, $filepath, $filename) {
|
||||
public function get_file($contextid, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $DB;
|
||||
|
||||
$filepath = clean_param($filepath, PARAM_PATH);
|
||||
@ -204,7 +209,7 @@ class file_storage {
|
||||
$filename = '.';
|
||||
}
|
||||
|
||||
$pathnamehash = $this->get_pathname_hash($contextid, $filearea, $itemid, $filepath, $filename);
|
||||
$pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename);
|
||||
return $this->get_file_by_hash($pathnamehash);
|
||||
}
|
||||
|
||||
@ -212,16 +217,17 @@ class file_storage {
|
||||
* Returns all area files (optionally limited by itemid)
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid (all files if not specified)
|
||||
* @param string $sort
|
||||
* @param bool $includedirs
|
||||
* @return array of stored_files indexed by pathanmehash
|
||||
*/
|
||||
public function get_area_files($contextid, $filearea, $itemid=false, $sort="sortorder, itemid, filepath, filename", $includedirs = true) {
|
||||
public function get_area_files($contextid, $component, $filearea, $itemid=false, $sort="sortorder, itemid, filepath, filename", $includedirs = true) {
|
||||
global $DB;
|
||||
|
||||
$conditions = array('contextid'=>$contextid, 'filearea'=>$filearea);
|
||||
$conditions = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea);
|
||||
if ($itemid !== false) {
|
||||
$conditions['itemid'] = $itemid;
|
||||
}
|
||||
@ -241,13 +247,14 @@ class file_storage {
|
||||
* Returns array based tree structure of area files
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @return array each dir represented by dirname, subdirs, files and dirfile array elements
|
||||
*/
|
||||
public function get_area_tree($contextid, $filearea, $itemid) {
|
||||
public function get_area_tree($contextid, $component, $filearea, $itemid) {
|
||||
$result = array('dirname'=>'', 'dirfile'=>null, 'subdirs'=>array(), 'files'=>array());
|
||||
$files = $this->get_area_files($contextid, $filearea, $itemid, $sort="sortorder, itemid, filepath, filename", true);
|
||||
$files = $this->get_area_files($contextid, $component, $filearea, $itemid, $sort="sortorder, itemid, filepath, filename", true);
|
||||
// first create directory structure
|
||||
foreach ($files as $hash=>$dir) {
|
||||
if (!$dir->is_directory()) {
|
||||
@ -291,6 +298,7 @@ class file_storage {
|
||||
* Returns all files and optionally directories
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param int $filepath directory path
|
||||
@ -299,10 +307,10 @@ class file_storage {
|
||||
* @param string $sort
|
||||
* @return array of stored_files indexed by pathanmehash
|
||||
*/
|
||||
public function get_directory_files($contextid, $filearea, $itemid, $filepath, $recursive = false, $includedirs = true, $sort = "filepath, filename") {
|
||||
public function get_directory_files($contextid, $component, $filearea, $itemid, $filepath, $recursive = false, $includedirs = true, $sort = "filepath, filename") {
|
||||
global $DB;
|
||||
|
||||
if (!$directory = $this->get_file($contextid, $filearea, $itemid, $filepath, '.')) {
|
||||
if (!$directory = $this->get_file($contextid, $component, $filearea, $itemid, $filepath, '.')) {
|
||||
return array();
|
||||
}
|
||||
|
||||
@ -313,12 +321,12 @@ class file_storage {
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM {files}
|
||||
WHERE contextid = :contextid AND filearea = :filearea AND itemid = :itemid
|
||||
WHERE contextid = :contextid AND component = :component AND filearea = :filearea AND itemid = :itemid
|
||||
AND ".$DB->sql_substr("filepath", 1, $length)." = :filepath
|
||||
AND id <> :dirid
|
||||
$dirs
|
||||
ORDER BY $sort";
|
||||
$params = array('contextid'=>$contextid, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'dirid'=>$directory->get_id());
|
||||
$params = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'dirid'=>$directory->get_id());
|
||||
|
||||
$files = array();
|
||||
$dirs = array();
|
||||
@ -334,14 +342,14 @@ class file_storage {
|
||||
|
||||
} else {
|
||||
$result = array();
|
||||
$params = array('contextid'=>$contextid, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'dirid'=>$directory->get_id());
|
||||
$params = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'dirid'=>$directory->get_id());
|
||||
|
||||
$length = textlib_get_instance()->strlen($filepath);
|
||||
|
||||
if ($includedirs) {
|
||||
$sql = "SELECT *
|
||||
FROM {files}
|
||||
WHERE contextid = :contextid AND filearea = :filearea
|
||||
WHERE contextid = :contextid AND component = :component AND filearea = :filearea
|
||||
AND itemid = :itemid AND filename = '.'
|
||||
AND ".$DB->sql_substr("filepath", 1, $length)." = :filepath
|
||||
AND id <> :dirid
|
||||
@ -358,7 +366,7 @@ class file_storage {
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM {files}
|
||||
WHERE contextid = :contextid AND filearea = :filearea AND itemid = :itemid
|
||||
WHERE contextid = :contextid AND component = :component AND filearea = :filearea AND itemid = :itemid
|
||||
AND filepath = :filepath AND filename <> '.'
|
||||
ORDER BY $sort";
|
||||
|
||||
@ -375,14 +383,18 @@ class file_storage {
|
||||
* Delete all area files (optionally limited by itemid).
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea (all areas in context if not specified)
|
||||
* @param int $itemid (all files if not specified)
|
||||
* @return bool success
|
||||
*/
|
||||
public function delete_area_files($contextid, $filearea = false, $itemid = false) {
|
||||
public function delete_area_files($contextid, $component = false, $filearea = false, $itemid = false) {
|
||||
global $DB;
|
||||
|
||||
$conditions = array('contextid'=>$contextid);
|
||||
if ($component !== false) {
|
||||
$conditions['component'] = $component;
|
||||
}
|
||||
if ($filearea !== false) {
|
||||
$conditions['filearea'] = $filearea;
|
||||
}
|
||||
@ -403,13 +415,14 @@ class file_storage {
|
||||
* Recursively creates directory.
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return bool success
|
||||
*/
|
||||
public function create_directory($contextid, $filearea, $itemid, $filepath, $userid = null) {
|
||||
public function create_directory($contextid, $component, $filearea, $itemid, $filepath, $userid = null) {
|
||||
global $DB;
|
||||
|
||||
// validate all parameters, we do not want any rubbish stored in database, right?
|
||||
@ -417,8 +430,11 @@ class file_storage {
|
||||
throw new file_exception('storedfileproblem', 'Invalid contextid');
|
||||
}
|
||||
|
||||
$filearea = clean_param($filearea, PARAM_ALPHAEXT);
|
||||
if ($filearea === '') {
|
||||
if ($component === '' or $component !== clean_param($component, PARAM_ALPHAEXT)) {
|
||||
throw new file_exception('storedfileproblem', 'Invalid component');
|
||||
}
|
||||
|
||||
if ($filearea === '' or $filearea !== clean_param($filearea, PARAM_ALPHAEXT)) {
|
||||
throw new file_exception('storedfileproblem', 'Invalid filearea');
|
||||
}
|
||||
|
||||
@ -432,7 +448,7 @@ class file_storage {
|
||||
throw new file_exception('storedfileproblem', 'Invalid file path');
|
||||
}
|
||||
|
||||
$pathnamehash = $this->get_pathname_hash($contextid, $filearea, $itemid, $filepath, '.');
|
||||
$pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, '.');
|
||||
|
||||
if ($dir_info = $this->get_file_by_hash($pathnamehash)) {
|
||||
return $dir_info;
|
||||
@ -448,6 +464,7 @@ class file_storage {
|
||||
|
||||
$dir_record = new object();
|
||||
$dir_record->contextid = $contextid;
|
||||
$dir_record->component = $component;
|
||||
$dir_record->filearea = $filearea;
|
||||
$dir_record->itemid = $itemid;
|
||||
$dir_record->filepath = $filepath;
|
||||
@ -472,7 +489,7 @@ class file_storage {
|
||||
array_pop($filepath);
|
||||
$filepath = implode('/', $filepath);
|
||||
$filepath = ($filepath === '') ? '/' : "/$filepath/";
|
||||
$this->create_directory($contextid, $filearea, $itemid, $filepath, $userid);
|
||||
$this->create_directory($contextid, $component, $filearea, $itemid, $filepath, $userid);
|
||||
}
|
||||
|
||||
return $dir_info;
|
||||
@ -515,9 +532,14 @@ class file_storage {
|
||||
throw new file_exception('storedfileproblem', 'Invalid contextid');
|
||||
}
|
||||
|
||||
if ($key == 'component') {
|
||||
if ($value === '' or $value !== clean_param($value, PARAM_ALPHAEXT)) {
|
||||
throw new file_exception('storedfileproblem', 'Invalid component');
|
||||
}
|
||||
}
|
||||
|
||||
if ($key == 'filearea') {
|
||||
$value = clean_param($value, PARAM_ALPHAEXT);
|
||||
if ($value === '') {
|
||||
if ($value === '' or $value !== clean_param($value, PARAM_ALPHAEXT)) {
|
||||
throw new file_exception('storedfileproblem', 'Invalid filearea');
|
||||
}
|
||||
}
|
||||
@ -546,11 +568,11 @@ class file_storage {
|
||||
$newrecord->$key = $value;
|
||||
}
|
||||
|
||||
$newrecord->pathnamehash = $this->get_pathname_hash($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename);
|
||||
$newrecord->pathnamehash = $this->get_pathname_hash($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename);
|
||||
|
||||
if ($newrecord->filename === '.') {
|
||||
// special case - only this function supports directories ;-)
|
||||
$directory = $this->create_directory($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
|
||||
$directory = $this->create_directory($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
|
||||
// update the existing directory with the new data
|
||||
$newrecord->id = $directory->get_id();
|
||||
$DB->update_record('files', $newrecord);
|
||||
@ -564,11 +586,11 @@ class file_storage {
|
||||
}
|
||||
|
||||
if (!$newrecord->id) {
|
||||
throw new stored_file_creation_exception($newrecord->contextid, $newrecord->filearea, $newrecord->itemid,
|
||||
throw new stored_file_creation_exception($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid,
|
||||
$newrecord->filepath, $newrecord->filename);
|
||||
}
|
||||
|
||||
$this->create_directory($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
|
||||
$this->create_directory($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
|
||||
|
||||
return new stored_file($this, $newrecord);
|
||||
}
|
||||
@ -645,8 +667,11 @@ class file_storage {
|
||||
throw new file_exception('storedfileproblem', 'Invalid contextid');
|
||||
}
|
||||
|
||||
$file_record->filearea = clean_param($file_record->filearea, PARAM_ALPHAEXT);
|
||||
if ($file_record->filearea === '') {
|
||||
if ($file_record->component === '' or $file_record->component !== clean_param($file_record->component, PARAM_ALPHAEXT)) {
|
||||
throw new file_exception('storedfileproblem', 'Invalid component');
|
||||
}
|
||||
|
||||
if ($file_record->filearea === '' or $file_record->filearea !== clean_param($file_record->filearea, PARAM_ALPHAEXT)) {
|
||||
throw new file_exception('storedfileproblem', 'Invalid filearea');
|
||||
}
|
||||
|
||||
@ -679,6 +704,7 @@ class file_storage {
|
||||
$newrecord = new object();
|
||||
|
||||
$newrecord->contextid = $file_record->contextid;
|
||||
$newrecord->component = $file_record->component;
|
||||
$newrecord->filearea = $file_record->filearea;
|
||||
$newrecord->itemid = $file_record->itemid;
|
||||
$newrecord->filepath = $file_record->filepath;
|
||||
@ -695,7 +721,7 @@ class file_storage {
|
||||
|
||||
list($newrecord->contenthash, $newrecord->filesize, $newfile) = $this->add_file_to_pool($pathname);
|
||||
|
||||
$newrecord->pathnamehash = $this->get_pathname_hash($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename);
|
||||
$newrecord->pathnamehash = $this->get_pathname_hash($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename);
|
||||
|
||||
try {
|
||||
$newrecord->id = $DB->insert_record('files', $newrecord);
|
||||
@ -707,11 +733,11 @@ class file_storage {
|
||||
if ($newfile) {
|
||||
$this->deleted_file_cleanup($newrecord->contenthash);
|
||||
}
|
||||
throw new stored_file_creation_exception($newrecord->contextid, $newrecord->filearea, $newrecord->itemid,
|
||||
throw new stored_file_creation_exception($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid,
|
||||
$newrecord->filepath, $newrecord->filename);
|
||||
}
|
||||
|
||||
$this->create_directory($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
|
||||
$this->create_directory($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
|
||||
|
||||
return new stored_file($this, $newrecord);
|
||||
}
|
||||
@ -734,8 +760,11 @@ class file_storage {
|
||||
throw new file_exception('storedfileproblem', 'Invalid contextid');
|
||||
}
|
||||
|
||||
$file_record->filearea = clean_param($file_record->filearea, PARAM_ALPHAEXT);
|
||||
if ($file_record->filearea === '') {
|
||||
if ($file_record->component === '' or $file_record->component !== clean_param($file_record->component, PARAM_ALPHAEXT)) {
|
||||
throw new file_exception('storedfileproblem', 'Invalid component');
|
||||
}
|
||||
|
||||
if ($file_record->filearea === '' or $file_record->filearea !== clean_param($file_record->filearea, PARAM_ALPHAEXT)) {
|
||||
throw new file_exception('storedfileproblem', 'Invalid filearea');
|
||||
}
|
||||
|
||||
@ -768,6 +797,7 @@ class file_storage {
|
||||
$newrecord = new object();
|
||||
|
||||
$newrecord->contextid = $file_record->contextid;
|
||||
$newrecord->component = $file_record->component;
|
||||
$newrecord->filearea = $file_record->filearea;
|
||||
$newrecord->itemid = $file_record->itemid;
|
||||
$newrecord->filepath = $file_record->filepath;
|
||||
@ -784,7 +814,7 @@ class file_storage {
|
||||
|
||||
list($newrecord->contenthash, $newrecord->filesize, $newfile) = $this->add_string_to_pool($content);
|
||||
|
||||
$newrecord->pathnamehash = $this->get_pathname_hash($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename);
|
||||
$newrecord->pathnamehash = $this->get_pathname_hash($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename);
|
||||
|
||||
try {
|
||||
$newrecord->id = $DB->insert_record('files', $newrecord);
|
||||
@ -796,11 +826,11 @@ class file_storage {
|
||||
if ($newfile) {
|
||||
$this->deleted_file_cleanup($newrecord->contenthash);
|
||||
}
|
||||
throw new stored_file_creation_exception($newrecord->contextid, $newrecord->filearea, $newrecord->itemid,
|
||||
throw new stored_file_creation_exception($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid,
|
||||
$newrecord->filepath, $newrecord->filename);
|
||||
}
|
||||
|
||||
$this->create_directory($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
|
||||
$this->create_directory($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);
|
||||
|
||||
return new stored_file($this, $newrecord);
|
||||
}
|
||||
@ -1118,6 +1148,10 @@ class file_storage {
|
||||
*/
|
||||
public function cron() {
|
||||
global $CFG, $DB;
|
||||
//TODO: find out all stale draft areas (older than 1 day) and purge them
|
||||
// those are identified by time stamp of the /. root dir
|
||||
|
||||
|
||||
// remove trash pool files once a day
|
||||
// if you want to disable purging of trash put $CFG->fileslastcleanup=time(); into config.php
|
||||
if (empty($CFG->fileslastcleanup) or $CFG->fileslastcleanup < time() - 60*60*24) {
|
@ -19,13 +19,15 @@
|
||||
/**
|
||||
* Definition of a class stored_file.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-storage
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once("$CFG->libdir/file/stored_file.php");
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/filestorage/stored_file.php");
|
||||
|
||||
/**
|
||||
* Class representing local files stored in a sha1 file pool.
|
||||
@ -201,15 +203,16 @@ class stored_file {
|
||||
*
|
||||
* @param file_packer $file_packer
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $pathbase
|
||||
* @param int $userid
|
||||
* @return array|bool list of processed files; false if error
|
||||
*/
|
||||
public function extract_to_storage(file_packer $packer, $contextid, $filearea, $itemid, $pathbase, $userid = NULL) {
|
||||
public function extract_to_storage(file_packer $packer, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL) {
|
||||
$archivefile = $this->get_content_file_location();
|
||||
return $packer->extract_to_storage($archivefile, $contextid, $filearea, $itemid, $pathbase);
|
||||
return $packer->extract_to_storage($archivefile, $contextid, $component, $filearea, $itemid, $pathbase);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -282,7 +285,7 @@ class stored_file {
|
||||
}
|
||||
|
||||
if ($this->file_record->filename !== '.') {
|
||||
return $this->fs->create_directory($this->file_record->contextid, $this->file_record->filearea, $this->file_record->itemid, $this->file_record->filepath);
|
||||
return $this->fs->create_directory($this->file_record->contextid, $this->file_record->component, $this->file_record->filearea, $this->file_record->itemid, $this->file_record->filepath);
|
||||
}
|
||||
|
||||
$filepath = $this->file_record->filepath;
|
||||
@ -292,7 +295,7 @@ class stored_file {
|
||||
$filepath = implode('/', $dirs);
|
||||
$filepath = ($filepath === '') ? '/' : "/$filepath/";
|
||||
|
||||
return $this->fs->create_directory($this->file_record->contextid, $this->file_record->filearea, $this->file_record->itemid, $filepath);
|
||||
return $this->fs->create_directory($this->file_record->contextid, $this->file_record->component, $this->file_record->filearea, $this->file_record->itemid, $filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,8 +308,18 @@ class stored_file {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns file area name, the areas do not have to be unique,
|
||||
* but usually have form component_typeofarea such as forum_attachments.
|
||||
* Returns component name - this is the owner of the areas,
|
||||
* nothing else is allowed to read or modify the files directly!!
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_component() {
|
||||
return $this->file_record->component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns file area name, this divides files of one component into groups with different access control.
|
||||
* All files in one area have the same access control.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -414,7 +427,7 @@ class stored_file {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns sha1 hash of all file path components sha1("contextid/filearea/itemid/dir/dir/filename.ext").
|
||||
* Returns sha1 hash of all file path components sha1("contextid/component/filearea/itemid/dir/dir/filename.ext").
|
||||
*
|
||||
* @return string
|
||||
*/
|
@ -19,14 +19,24 @@
|
||||
/**
|
||||
* Implementation of zip file archive.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-packer
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once("$CFG->libdir/packer/file_archive.php");
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/filestorage/file_archive.php");
|
||||
|
||||
/**
|
||||
* zip file archive class.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class zip_archive extends file_archive {
|
||||
|
||||
/** Pathname of archive */
|
@ -19,17 +19,24 @@
|
||||
/**
|
||||
* Implementation of zip packer.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage file-packer
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once("$CFG->libdir/packer/file_packer.php");
|
||||
require_once("$CFG->libdir/packer/zip_archive.php");
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/filestorage/file_packer.php");
|
||||
require_once("$CFG->libdir/filestorage/zip_archive.php");
|
||||
|
||||
/**
|
||||
* Utility class - handles all zipping and unzipping operations.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage filestorage
|
||||
* @copyright 2008 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class zip_packer extends file_packer {
|
||||
|
||||
@ -37,13 +44,14 @@ class zip_packer extends file_packer {
|
||||
* Zip files and store the result in file storage
|
||||
* @param array $files array with full zip paths (including directory information) as keys (archivepath=>ospathname or archivepath/subdir=>stored_file)
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return mixed false if error stored file instance if ok
|
||||
*/
|
||||
public function archive_to_storage($files, $contextid, $filearea, $itemid, $filepath, $filename, $userid=null) {
|
||||
public function archive_to_storage($files, $contextid, $component, $filearea, $itemid, $filepath, $filename, $userid = NULL) {
|
||||
global $CFG;
|
||||
|
||||
$fs = get_file_storage();
|
||||
@ -52,7 +60,7 @@ class zip_packer extends file_packer {
|
||||
$tmpfile = tempnam($CFG->dataroot.'/temp/zip', 'zipstor');
|
||||
|
||||
if ($result = $this->archive_to_pathname($files, $tmpfile)) {
|
||||
if ($file = $fs->get_file($contextid, $filearea, $itemid, $filepath, $filename)) {
|
||||
if ($file = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||
if (!$file->delete()) {
|
||||
@unlink($tmpfile);
|
||||
return false;
|
||||
@ -60,6 +68,7 @@ class zip_packer extends file_packer {
|
||||
}
|
||||
$file_record = new object();
|
||||
$file_record->contextid = $contextid;
|
||||
$file_record->component = $component;
|
||||
$file_record->filearea = $filearea;
|
||||
$file_record->itemid = $itemid;
|
||||
$file_record->filepath = $filepath;
|
||||
@ -118,7 +127,7 @@ class zip_packer extends file_packer {
|
||||
|
||||
$baselength = strlen($file->get_filepath());
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_directory_files($file->get_contextid(), $file->get_filearea(), $file->get_itemid(),
|
||||
$files = $fs->get_directory_files($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(),
|
||||
$file->get_filepath(), true, true);
|
||||
foreach ($files as $file) {
|
||||
$path = $file->get_filepath();
|
||||
@ -257,16 +266,17 @@ class zip_packer extends file_packer {
|
||||
* Unzip file to given file path (real OS filesystem), existing files are overwrited
|
||||
* @param mixed $archivefile full pathname of zip file or stored_file instance
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @return mixed list of processed files; false if error
|
||||
*/
|
||||
public function extract_to_storage($archivefile, $contextid, $filearea, $itemid, $pathbase, $userid=null) {
|
||||
public function extract_to_storage($archivefile, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL) {
|
||||
global $CFG;
|
||||
|
||||
if (!is_string($archivefile)) {
|
||||
return $archivefile->extract_to_pathname($this, $contextid, $filearea, $itemid, $pathbase, $userid);
|
||||
return $archivefile->extract_to_pathname($this, $contextid, $component, $filearea, $itemid, $pathbase, $userid);
|
||||
}
|
||||
|
||||
check_dir_exists($CFG->dataroot.'/temp/zip', true, true);
|
||||
@ -293,7 +303,7 @@ class zip_packer extends file_packer {
|
||||
|
||||
if ($info->is_directory) {
|
||||
$newfilepath = $pathbase.$name.'/';
|
||||
$fs->create_directory($contextid, $filearea, $itemid, $newfilepath, $userid);
|
||||
$fs->create_directory($contextid, $component, $filearea, $itemid, $newfilepath, $userid);
|
||||
$processed[$name] = true;
|
||||
continue;
|
||||
}
|
||||
@ -323,7 +333,7 @@ class zip_packer extends file_packer {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file = $fs->get_file($contextid, $filearea, $itemid, $filepath, $filename)) {
|
||||
if ($file = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||
if (!$file->delete()) {
|
||||
$processed[$name] = 'Can not delete existing file'; // TODO: localise
|
||||
continue;
|
||||
@ -331,6 +341,7 @@ class zip_packer extends file_packer {
|
||||
}
|
||||
$file_record = new object();
|
||||
$file_record->contextid = $contextid;
|
||||
$file_record->component = $component;
|
||||
$file_record->filearea = $filearea;
|
||||
$file_record->itemid = $itemid;
|
||||
$file_record->filepath = $filepath;
|
||||
@ -370,7 +381,7 @@ class zip_packer extends file_packer {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file = $fs->get_file($contextid, $filearea, $itemid, $filepath, $filename)) {
|
||||
if ($file = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||
if (!$file->delete()) {
|
||||
@unlink($tmpfile);
|
||||
$processed[$name] = 'Can not delete existing file'; // TODO: localise
|
||||
@ -379,6 +390,7 @@ class zip_packer extends file_packer {
|
||||
}
|
||||
$file_record = new object();
|
||||
$file_record->contextid = $contextid;
|
||||
$file_record->component = $component;
|
||||
$file_record->filearea = $filearea;
|
||||
$file_record->itemid = $itemid;
|
||||
$file_record->filepath = $filepath;
|
@ -50,7 +50,7 @@ M.form_filemanager.init = function(Y, options) {
|
||||
};
|
||||
|
||||
Y.extend(FileManagerHelper, Y.Base, {
|
||||
api: M.cfg.wwwroot+'/files/files_ajax.php',
|
||||
api: M.cfg.wwwroot+'/repository/draftfiles_ajax.php',
|
||||
menus: {},
|
||||
initializer: function(options) {
|
||||
this.options = options;
|
||||
@ -67,10 +67,8 @@ M.form_filemanager.init = function(Y, options) {
|
||||
this.filepicker_options.maxfiles = this.maxfiles;
|
||||
this.filepicker_options.maxbytes = this.maxbytes;
|
||||
this.filepicker_options.env = 'filemanager';
|
||||
this.filepicker_options.filearea = options.filearea;
|
||||
this.filepicker_options.itemid = options.itemid;
|
||||
|
||||
this.filearea = options.filearea?options.filearea:'user_draft';
|
||||
if (options.filecount) {
|
||||
this.filecount = options.filecount;
|
||||
} else {
|
||||
@ -104,7 +102,6 @@ M.form_filemanager.init = function(Y, options) {
|
||||
scope = args['scope'];
|
||||
}
|
||||
params['sesskey'] = M.cfg.sesskey;
|
||||
params['filearea'] = this.filearea;
|
||||
params['client_id'] = this.client_id;
|
||||
params['filepath'] = this.currentpath;
|
||||
params['itemid'] = this.options.itemid?this.options.itemid:0;
|
||||
|
@ -137,7 +137,6 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
// filemanager options
|
||||
$options = new stdclass;
|
||||
$options->mainfile = $this->_options['mainfile'];
|
||||
$options->filearea = 'user_draft';
|
||||
$options->maxbytes = $this->_options['maxbytes'];
|
||||
$options->maxfiles = $this->getMaxfiles();
|
||||
$options->client_id = $client_id;
|
||||
@ -149,7 +148,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
$options->context = $PAGE->context;
|
||||
|
||||
$html = $this->_getTabs();
|
||||
$html .= $OUTPUT->file_manager($options);
|
||||
$html .= form_filemanager_render($options);
|
||||
|
||||
$html .= '<input value="'.$draftitemid.'" name="'.$elname.'" type="hidden" />';
|
||||
// label element needs 'for' attribute work
|
||||
@ -158,3 +157,183 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Data structure representing a file manager.
|
||||
*
|
||||
* @copyright 2010 Dongsheng Cai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class form_filemanaer_x {
|
||||
//TODO: do not use this abstraction (skodak)
|
||||
|
||||
public $options;
|
||||
public function __construct(stdClass $options) {
|
||||
global $CFG, $USER, $PAGE;
|
||||
require_once($CFG->dirroot. '/repository/lib.php');
|
||||
$defaults = array(
|
||||
'maxbytes'=>-1,
|
||||
'maxfiles'=>-1,
|
||||
'itemid'=>0,
|
||||
'subdirs'=>0,
|
||||
'client_id'=>uniqid(),
|
||||
'accepted_types'=>'*',
|
||||
'return_types'=>FILE_INTERNAL,
|
||||
'context'=>$PAGE->context
|
||||
);
|
||||
foreach ($defaults as $key=>$value) {
|
||||
if (empty($options->$key)) {
|
||||
$options->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
// initilise options, getting files in root path
|
||||
$this->options = file_get_drafarea_files($options->itemid, '/');
|
||||
|
||||
// calculate file count
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id', false);
|
||||
$filecount = count($files);
|
||||
$this->options->filecount = $filecount;
|
||||
|
||||
// copying other options
|
||||
foreach ($options as $name=>$value) {
|
||||
$this->options->$name = $value;
|
||||
}
|
||||
|
||||
// building file picker options
|
||||
$params = new stdclass;
|
||||
$params->accepted_types = $options->accepted_types;
|
||||
$params->return_types = $options->return_types;
|
||||
$params->context = $options->context;
|
||||
$params->env = 'filemanager';
|
||||
$params->disable_types = !empty($options->disable_types)?$options->disable_types:array();
|
||||
$filepicker_options = initialise_filepicker($params);
|
||||
$this->options->filepicker = $filepicker_options;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the file manager
|
||||
*
|
||||
* <pre>
|
||||
* $OUTPUT->file_manager($options);
|
||||
* </pre>
|
||||
*
|
||||
* @param array $options associative array with file manager options
|
||||
* options are:
|
||||
* maxbytes=>-1,
|
||||
* maxfiles=>-1,
|
||||
* itemid=>0,
|
||||
* subdirs=>false,
|
||||
* client_id=>uniqid(),
|
||||
* acepted_types=>'*',
|
||||
* return_types=>FILE_INTERNAL,
|
||||
* context=>$PAGE->context
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
function form_filemanager_render($options) {
|
||||
global $CFG, $OUTPUT, $PAGE;
|
||||
|
||||
$fm = new form_filemanaer_x($options); //TODO: this is unnecessary here, the nested options are getting too complex
|
||||
|
||||
static $filemanagertemplateloaded;
|
||||
|
||||
$html = '';
|
||||
$nonjsfilemanager = optional_param('usenonjsfilemanager', 0, PARAM_INT);
|
||||
$options = $fm->options;
|
||||
$options->usenonjs = $nonjsfilemanager;
|
||||
$straddfile = get_string('add', 'repository') . '...';
|
||||
$strmakedir = get_string('makeafolder', 'moodle');
|
||||
$strdownload = get_string('downloadfolder', 'repository');
|
||||
$strloading = get_string('loading', 'repository');
|
||||
|
||||
$icon_add_file = $OUTPUT->pix_icon('t/addfile', $straddfile).'';
|
||||
$icon_add_folder = $OUTPUT->pix_icon('t/adddir', $strmakedir).'';
|
||||
$icon_download = $OUTPUT->pix_icon('t/download', $strdownload).'';
|
||||
$icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
|
||||
|
||||
$client_id = $options->client_id;
|
||||
$itemid = $options->itemid;
|
||||
|
||||
if (empty($options->filecount)) {
|
||||
$extra = ' style="display:none"';
|
||||
} else {
|
||||
$extra = '';
|
||||
}
|
||||
|
||||
$html .= <<<FMHTML
|
||||
<div class="filemanager-loading mdl-align" id='filemanager-loading-{$client_id}'>
|
||||
$icon_progress
|
||||
</div>
|
||||
<div id="filemanager-wrapper-{$client_id}" style="display:none">
|
||||
<div class="fm-breadcrumb" id="fm-path-{$client_id}"></div>
|
||||
<div class="filemanager-toolbar">
|
||||
<button id="btnadd-{$client_id}" onclick="return false">{$icon_add_file} $straddfile</button>
|
||||
<button id="btncrt-{$client_id}" onclick="return false">{$icon_add_folder} $strmakedir</button>
|
||||
<button id="btndwn-{$client_id}" onclick="return false" {$extra}>{$icon_download} $strdownload</button>
|
||||
</div>
|
||||
<div class="filemanager-container" id="filemanager-{$client_id}">
|
||||
<ul id="draftfiles-{$client_id}" class="fm-filelist">
|
||||
<li>Loading...</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class='clearer'></div>
|
||||
FMHTML;
|
||||
if (empty($filemanagertemplateloaded)) {
|
||||
$filemanagertemplateloaded = true;
|
||||
$html .= <<<FMHTML
|
||||
<div id="fm-template" style="display:none">___fullname___ ___action___</div>
|
||||
FMHTML;
|
||||
}
|
||||
|
||||
$filemanagerurl = new moodle_url('/repository/filepicker.php', array(
|
||||
'env'=>'filemanager',
|
||||
'action'=>'embedded',
|
||||
'itemid'=>$itemid,
|
||||
'subdirs'=>'/',
|
||||
'maxbytes'=>$options->maxbytes,
|
||||
'ctx_id'=>$PAGE->context->id,
|
||||
'course'=>$PAGE->course->id,
|
||||
));
|
||||
|
||||
$module = array(
|
||||
'name'=>'form_filemanager',
|
||||
'fullpath'=>'/lib/form/filemanager.js',
|
||||
'requires' => array('core_filepicker', 'base', 'io', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview'),
|
||||
'strings' => array(array('loading', 'repository'), array('nomorefiles', 'repository'), array('confirmdeletefile', 'repository'),
|
||||
array('add', 'repository'), array('accessiblefilepicker', 'repository'), array('move', 'moodle'),
|
||||
array('cancel', 'moodle'), array('download', 'moodle'), array('ok', 'moodle'),
|
||||
array('emptylist', 'repository'), array('nofilesattached', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
|
||||
array('zip', 'editor'), array('unzip', 'moodle'), array('rename', 'moodle'), array('delete', 'moodle'),
|
||||
array('cannotdeletefile', 'error'), array('confirmdeletefile', 'repository'),
|
||||
array('nopathselected', 'repository'), array('popupblockeddownload', 'repository'),
|
||||
array('draftareanofiles', 'repository'), array('path', 'moodle'), array('setmainfile', 'repository')
|
||||
)
|
||||
);
|
||||
$PAGE->requires->js_module($module);
|
||||
$PAGE->requires->js_init_call('M.form_filemanager.init', array($options), true, $module);
|
||||
|
||||
// non javascript file manager
|
||||
if (!empty($nonjsfilemanager)) {
|
||||
$html = '<div id="nonjs-filemanager-'.$client_id.'">';
|
||||
$html .= <<<NONJS
|
||||
<object type="text/html" data="$filemanagerurl" height="160" width="600" style="border:1px solid #000">Error</object>
|
||||
NONJS;
|
||||
$html .= '</div>';
|
||||
} else {
|
||||
$url = new moodle_url($PAGE->url, array('usenonjsfilemanager'=>1));
|
||||
$html .= '<div id="nonjs-filemanager-'.$client_id.'" class="mdl-align">';
|
||||
$html .= html_writer::link($url, get_string('usenonjsfilemanager', 'repository'));
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
||||
if ($draftitemid = $submitValues[$this->_attributes['name']]) {
|
||||
$fs = get_file_storage();
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
if ($files = $fs->get_area_files($usercontext->id, 'user_draft', $draftitemid, 'id DESC', false)) {
|
||||
if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false)) {
|
||||
$file = array_shift($files);
|
||||
if ($this->_options['maxbytes'] and $file->get_filesize() > $this->_options['maxbytes']) {
|
||||
// bad luck, somebody tries to sneak in oversized file
|
||||
|
@ -11,7 +11,7 @@ require_once("$CFG->libdir/form/textarea.php");
|
||||
class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
|
||||
var $_type;
|
||||
var $_canUseHtmlEditor;
|
||||
var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0, 'filearea'=>'');
|
||||
var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0);
|
||||
function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
|
||||
parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
|
||||
// set the options, do not bother setting bogus ones
|
||||
@ -60,7 +60,6 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
|
||||
return $this->getFrozenHtml();
|
||||
} else {
|
||||
return $this->_getTabs() .
|
||||
'<input type="hidden" name="filearea" value="'. $this->_options['filearea'] .'" />'."\n".
|
||||
print_textarea($this->_canUseHtmlEditor,
|
||||
$this->_options['rows'],
|
||||
$this->_options['cols'],
|
||||
|
@ -562,7 +562,7 @@ abstract class moodleform {
|
||||
$draftid = $values[$elname];
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user_draft', $draftid, 'id DESC', false)) {
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
return false;
|
||||
}
|
||||
$file = reset($files);
|
||||
@ -612,7 +612,7 @@ abstract class moodleform {
|
||||
$draftid = $values[$elname];
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user_draft', $draftid, 'id DESC', false)) {
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
return false;
|
||||
}
|
||||
$file = reset($files);
|
||||
@ -651,7 +651,7 @@ abstract class moodleform {
|
||||
$draftid = $values[$elname];
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user_draft', $draftid, 'id DESC', false)) {
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
return null;
|
||||
}
|
||||
return $files;
|
||||
@ -659,33 +659,6 @@ abstract class moodleform {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispose form element draft files
|
||||
*
|
||||
* @global object $USER
|
||||
* @param string $elname name of element
|
||||
*/
|
||||
function dispose($elname) {
|
||||
global $USER;
|
||||
|
||||
if (!$this->is_submitted() or !$this->is_validated()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$element = $this->_form->getElement($elname);
|
||||
|
||||
if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) {
|
||||
$values = $this->_form->exportValues($elname);
|
||||
if (empty($values[$elname])) {
|
||||
return false;
|
||||
}
|
||||
$draftid = $values[$elname];
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$fs->delete_area_files($context->id, 'user_draft', $draftid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save file to local filesystem pool
|
||||
*
|
||||
@ -699,7 +672,7 @@ abstract class moodleform {
|
||||
* @param int $newuserid - new userid if required
|
||||
* @return mixed stored_file object or false if error; may throw exception if duplicate found
|
||||
*/
|
||||
function save_stored_file($elname, $newcontextid, $newfilearea, $newitemid, $newfilepath='/',
|
||||
function save_stored_file($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/',
|
||||
$newfilename=null, $overwrite=false, $newuserid=null) {
|
||||
global $USER;
|
||||
|
||||
@ -721,7 +694,7 @@ abstract class moodleform {
|
||||
}
|
||||
$draftid = $values[$elname];
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user_draft', $draftid, 'id DESC', false)) {
|
||||
if (!$files = $fs->get_area_files($context->id, 'user' ,'draft', $draftid, 'id DESC', false)) {
|
||||
return false;
|
||||
}
|
||||
$file = reset($files);
|
||||
@ -730,14 +703,14 @@ abstract class moodleform {
|
||||
}
|
||||
|
||||
if ($overwrite) {
|
||||
if ($oldfile = $fs->get_file($newcontextid, $newfilearea, $newitemid, $newfilepath, $newfilename)) {
|
||||
if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) {
|
||||
if (!$oldfile->delete()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$file_record = array('contextid'=>$newcontextid, 'filearea'=>$newfilearea, 'itemid'=>$newitemid,
|
||||
$file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid,
|
||||
'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid);
|
||||
return $fs->create_file_from_storedfile($file_record, $file);
|
||||
|
||||
@ -745,14 +718,14 @@ abstract class moodleform {
|
||||
$filename = is_null($newfilename) ? $_FILES[$elname]['name'] : $newfilename;
|
||||
|
||||
if ($overwrite) {
|
||||
if ($oldfile = $fs->get_file($newcontextid, $newfilearea, $newitemid, $newfilepath, $newfilename)) {
|
||||
if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) {
|
||||
if (!$oldfile->delete()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$file_record = array('contextid'=>$newcontextid, 'filearea'=>$newfilearea, 'itemid'=>$newitemid,
|
||||
$file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid,
|
||||
'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid);
|
||||
return $fs->create_file_from_pathname($file_record, $_FILES[$elname]['tmp_name']);
|
||||
}
|
||||
@ -784,7 +757,7 @@ abstract class moodleform {
|
||||
$draftid = $values[$elname];
|
||||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
if (!$files = $fs->get_area_files($context->id, 'user_draft', $draftid, 'id DESC', false)) {
|
||||
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
|
||||
return false;
|
||||
}
|
||||
$file = reset($files);
|
||||
|
@ -98,7 +98,7 @@ class grade_outcome extends grade_object {
|
||||
if (parent::delete($source)) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, 'grade_outcome', $this->id);
|
||||
$files = $fs->get_area_files($context->id, 'grade', 'outcome', $this->id);
|
||||
foreach ($files as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
@ -277,7 +277,7 @@ class grade_outcome extends grade_object {
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade_outcome', $this->id);
|
||||
$description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade', 'outcome', $this->id);
|
||||
return format_text($description, $this->descriptionformat, $options);
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ class grade_scale extends grade_object {
|
||||
if (parent::delete($source)) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, 'grade_scale', $this->id);
|
||||
$files = $fs->get_area_files($context->id, 'grade', 'scale', $this->id);
|
||||
foreach ($files as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
@ -314,7 +314,7 @@ class grade_scale extends grade_object {
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade_scale', $this->id);
|
||||
$description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', $systemcontext->id, 'grade', 'scale', $this->id);
|
||||
return format_text($description, $this->descriptionformat, $options);
|
||||
}
|
||||
}
|
||||
|
@ -5057,7 +5057,7 @@ function get_file_packer($mimetype='application/zip') {
|
||||
return false;
|
||||
}
|
||||
|
||||
require_once("$CFG->libdir/packer/$classname.php");
|
||||
require_once("$CFG->libdir/filestorage/$classname.php");
|
||||
$fp[$mimetype] = new $classname();
|
||||
|
||||
return $fp[$mimetype];
|
||||
@ -6905,6 +6905,7 @@ function get_core_subsystems() {
|
||||
'enrol' => 'enrol',
|
||||
'error' => NULL,
|
||||
'filepicker' => NULL,
|
||||
'files' => 'files',
|
||||
'filters' => NULL,
|
||||
'flashdetect' => NULL,
|
||||
'fonts' => NULL,
|
||||
|
@ -2669,7 +2669,7 @@ class settings_navigation extends navigation_node {
|
||||
|
||||
// Restore to this course
|
||||
if (has_capability('moodle/restore:restorecourse', $coursecontext)) {
|
||||
$url = new moodle_url('/files/index.php', array('id'=>$course->id, 'wdir'=>'/backupdata'));
|
||||
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id, 'itemid'=>0, 'component' => 'backup', 'filearea'=>'course'));
|
||||
$url = null; // Disabled until restore is implemented. MDL-21432
|
||||
$coursenode->add(get_string('restore'), $url, self::TYPE_SETTING, null, 'restore', new pix_icon('i/restore', ''));
|
||||
}
|
||||
@ -2707,7 +2707,7 @@ class settings_navigation extends navigation_node {
|
||||
|
||||
// Manage files
|
||||
if ($course->legacyfiles == 2 and has_capability('moodle/course:managefiles', $coursecontext)) {
|
||||
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id, 'itemid'=>0, 'filearea'=>'course_content'));
|
||||
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id, 'itemid'=>0, 'component' => 'course', 'filearea'=>'legacy'));
|
||||
$coursenode->add(get_string('files'), $url, self::TYPE_SETTING, null, 'coursefiles', new pix_icon('i/files', ''));
|
||||
}
|
||||
|
||||
@ -3327,7 +3327,8 @@ class settings_navigation extends navigation_node {
|
||||
|
||||
// Restore to this course
|
||||
if (has_capability('moodle/restore:restorecourse', $coursecontext)) {
|
||||
$url = new moodle_url('/files/index.php', array('id'=>$course->id, 'wdir'=>'/backupdata'));
|
||||
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id, 'itemid'=>0, 'component' => 'backup', 'filearea'=>'course'));
|
||||
|
||||
$url = null; // Disabled until restore is implemented. MDL-21432
|
||||
$frontpage->add(get_string('restore'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/restore', ''));
|
||||
}
|
||||
@ -3352,7 +3353,8 @@ class settings_navigation extends navigation_node {
|
||||
|
||||
// Manage files
|
||||
if (has_capability('moodle/course:managefiles', $this->context)) {
|
||||
$url = new moodle_url('/files/index.php', array('id'=>$course->id));
|
||||
//TODO: hide in new installs
|
||||
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id, 'itemid'=>0, 'component' => 'course', 'filearea'=>'legacy'));
|
||||
$frontpage->add(get_string('files'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/files', ''));
|
||||
}
|
||||
return $frontpage;
|
||||
|
@ -35,144 +35,6 @@ interface renderable {
|
||||
// intentionally empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Data structure representing a area file tree viewer
|
||||
*
|
||||
* @copyright 2010 Dongsheng Cai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class area_file_tree_viewer implements renderable {
|
||||
public $dir;
|
||||
public $result;
|
||||
public $filearea;
|
||||
/**
|
||||
* Constructor of area_file_tree_viewer class
|
||||
* @param int $contextid
|
||||
* @param string $area, file area
|
||||
* @param int $itemid
|
||||
* @param string $urlbase, file serving url base
|
||||
*/
|
||||
public function __construct($contextid, $area, $itemid, $urlbase='') {
|
||||
global $CFG;
|
||||
$fs = get_file_storage();
|
||||
if (empty($urlbase)) {
|
||||
$this->urlbase = "$CFG->wwwroot/pluginfile.php";
|
||||
} else {
|
||||
$this->urlbase = $urlbase;
|
||||
}
|
||||
$this->contextid = $contextid;
|
||||
$this->filearea = $area;
|
||||
$this->itemid = $itemid;
|
||||
$this->dir = $fs->get_area_tree($contextid, $area, $itemid);
|
||||
$this->tree_view_parser($this->dir);
|
||||
}
|
||||
/**
|
||||
* Pre-process file tree, generate file url
|
||||
* @param array $dir file tree
|
||||
*/
|
||||
public function tree_view_parser($dir) {
|
||||
if (empty($dir['subdirs']) and empty($dir['files'])) {
|
||||
return null;
|
||||
}
|
||||
foreach ($dir['subdirs'] as $subdir) {
|
||||
$this->tree_view_parser($subdir);
|
||||
}
|
||||
foreach ($dir['files'] as $file) {
|
||||
$path = '/'.$this->contextid.'/'.$this->filearea.'/'.$this->itemid.$file->get_filepath().$file->get_filename();
|
||||
$downloadurl = file_encode_url($this->urlbase, $path, true);
|
||||
$file->fileurl = $downloadurl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data structure representing a general moodle file tree viewer
|
||||
*
|
||||
* @copyright 2010 Dongsheng Cai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class moodle_file_tree_viewer implements renderable {
|
||||
public $tree;
|
||||
public $path;
|
||||
private $enabled_fileareas;
|
||||
/**
|
||||
* Constructor of moodle_file_tree_viewer class
|
||||
* @param int $contextid
|
||||
* @param string $area, file area
|
||||
* @param int $itemid
|
||||
* @param string $urlbase, file serving url base
|
||||
*/
|
||||
public function __construct($contextid, $filearea, $itemid, $filepath, $options=array()) {
|
||||
global $CFG, $OUTPUT;
|
||||
$this->tree = array();
|
||||
$browser = get_file_browser();
|
||||
$fs = get_file_storage();
|
||||
$fileinfo = $browser->get_file_info(get_context_instance_by_id($contextid), $filearea, $itemid, $filepath);
|
||||
$children = $fileinfo->get_children();
|
||||
$parent_info = $fileinfo->get_parent();
|
||||
if (!empty($options['enabled_fileareas']) && is_array($options['enabled_fileareas'])) {
|
||||
$this->enabled_fileareas = $options['enabled_fileareas'];
|
||||
} else {
|
||||
unset($this->enabled_fileareas);
|
||||
}
|
||||
|
||||
$level = $parent_info;
|
||||
$this->path = array();
|
||||
while ($level) {
|
||||
$params = $level->get_params();
|
||||
$context = get_context_instance_by_id($params['contextid']);
|
||||
// lock user in course level
|
||||
if ($context->contextlevel == CONTEXT_COURSECAT or $context->contextlevel == CONTEXT_SYSTEM) {
|
||||
break;
|
||||
}
|
||||
$url = new moodle_url('/files/index.php', $params);
|
||||
$this->path[] = html_writer::link($url->out(false), $level->get_visible_name());
|
||||
$level = $level->get_parent();
|
||||
}
|
||||
$this->path = array_reverse($this->path);
|
||||
$this->path[] = $fileinfo->get_visible_name();
|
||||
|
||||
foreach ($children as $child) {
|
||||
$filedate = $child->get_timemodified();
|
||||
$filesize = $child->get_filesize();
|
||||
$mimetype = $child->get_mimetype();
|
||||
$params = $child->get_params();
|
||||
$url = new moodle_url('/files/index.php', $params);
|
||||
$fileitem = array(
|
||||
'params'=>$params,
|
||||
'filename'=>$child->get_visible_name(),
|
||||
'filedate'=>$filedate ? userdate($filedate) : '',
|
||||
'filesize'=>$filesize ? display_size($filesize) : ''
|
||||
);
|
||||
if ($child->is_directory()) {
|
||||
$fileitem['isdir'] = true;
|
||||
$fileitem['url'] = $url->out(false);
|
||||
if (isset($this->enabled_fileareas)) {
|
||||
if (!in_array($params['filearea'], $this->enabled_fileareas)) {
|
||||
continue;
|
||||
} else {
|
||||
if (!empty($params['itemid'])) {
|
||||
$itemid = $params['itemid'];
|
||||
} else {
|
||||
$itemid = false;
|
||||
}
|
||||
$draftfiles = $fs->get_area_files($contextid, $params['filearea'], $itemid, 'id', false);
|
||||
if (count($draftfiles) == 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$fileitem['url'] = $child->get_url();
|
||||
}
|
||||
$this->tree[] = $fileitem;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data structure representing a file picker.
|
||||
*
|
||||
@ -187,7 +49,7 @@ class file_picker implements renderable {
|
||||
require_once($CFG->dirroot. '/repository/lib.php');
|
||||
$defaults = array(
|
||||
'accepted_types'=>'*',
|
||||
'context'=>$PAGE->context,
|
||||
'context'=>$PAGE->context, //TODO: no PAGE in components allowed!! (skodak)
|
||||
'return_types'=>FILE_INTERNAL,
|
||||
'env' => 'filepicker',
|
||||
'client_id' => uniqid(),
|
||||
@ -206,14 +68,14 @@ class file_picker implements renderable {
|
||||
$fs = get_file_storage();
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
if (empty($options->filename)) {
|
||||
if ($files = $fs->get_area_files($usercontext->id, 'user_draft', $options->itemid, 'id DESC', false)) {
|
||||
if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id DESC', false)) {
|
||||
$file = reset($files);
|
||||
}
|
||||
} else {
|
||||
$file = $fs->get_file($usercontext->id, 'user_draft', $options->itemid, $options->filepath, $options->filename);
|
||||
$file = $fs->get_file($usercontext->id, 'user', 'draft', $options->itemid, $options->filepath, $options->filename);
|
||||
}
|
||||
if (!empty($file)) {
|
||||
$options->currentfile = html_writer::link(file_encode_url($CFG->wwwroot.'/draftfile.php/', $usercontext->id.'/user_draft/'.$file->get_itemid().'/'.$file->get_filename()), $file->get_filename());
|
||||
$options->currentfile = html_writer::link(file_draftfile_url($file->get_itemid(), $file->get_filename(), $file->get_filename()), $file->get_filename());
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,63 +89,6 @@ class file_picker implements renderable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data structure representing a file manager.
|
||||
*
|
||||
* @copyright 2010 Dongsheng Cai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class file_manager implements renderable {
|
||||
public $options;
|
||||
public function __construct(stdClass $options) {
|
||||
global $CFG, $USER, $PAGE;
|
||||
require_once($CFG->dirroot. '/repository/lib.php');
|
||||
$defaults = array(
|
||||
'maxbytes'=>-1,
|
||||
'maxfiles'=>-1,
|
||||
'filearea'=>'user_draft',
|
||||
'itemid'=>0,
|
||||
'subdirs'=>0,
|
||||
'client_id'=>uniqid(),
|
||||
'accepted_types'=>'*',
|
||||
'return_types'=>FILE_INTERNAL,
|
||||
'context'=>$PAGE->context
|
||||
);
|
||||
foreach ($defaults as $key=>$value) {
|
||||
if (empty($options->$key)) {
|
||||
$options->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
// initilise options, getting files in root path
|
||||
$this->options = file_get_user_area_files($options->itemid, '/', $options->filearea);
|
||||
|
||||
// calculate file count
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$files = $fs->get_area_files($usercontext->id, $options->filearea, $options->itemid, 'id', false);
|
||||
$filecount = count($files);
|
||||
$this->options->filecount = $filecount;
|
||||
|
||||
// copying other options
|
||||
foreach ($options as $name=>$value) {
|
||||
$this->options->$name = $value;
|
||||
}
|
||||
|
||||
// building file picker options
|
||||
$params = new stdclass;
|
||||
$params->accepted_types = $options->accepted_types;
|
||||
$params->return_types = $options->return_types;
|
||||
$params->context = $options->context;
|
||||
$params->env = 'filemanager';
|
||||
$params->disable_types = !empty($options->disable_types)?$options->disable_types:array();
|
||||
$filepicker_options = initialise_filepicker($params);
|
||||
$this->options->filepicker = $filepicker_options;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data structure representing a user picture.
|
||||
*
|
||||
|
@ -1769,88 +1769,6 @@ class core_renderer extends renderer_base {
|
||||
return html_writer::tag('a', $output, $attributes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* General moodle file tree viwer
|
||||
*
|
||||
* <pre>
|
||||
* $OUTPUT->moodle_file_tree_viewer($contextid, $filearea, $itemid, $filepath);
|
||||
* </pre>
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $area
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function moodle_file_tree_viewer($contextid, $filearea, $itemid, $filepath, $options = array()) {
|
||||
$tree = new moodle_file_tree_viewer($contextid, $filearea, $itemid, $filepath, $options);
|
||||
return $this->render($tree);
|
||||
}
|
||||
public function render_moodle_file_tree_viewer(moodle_file_tree_viewer $tree) {
|
||||
$html = '<div>';
|
||||
foreach($tree->path as $path) {
|
||||
$html .= $path;
|
||||
$html .= ' / ';
|
||||
}
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div id="course-file-tree-view" class="filemanager-container">';
|
||||
if (empty($tree->tree)) {
|
||||
$html .= get_string('nofilesavailable', 'repository');
|
||||
} else {
|
||||
$this->page->requires->js_init_call('M.core_filetree.init');
|
||||
$html .= '<ul>';
|
||||
foreach($tree->tree as $node) {
|
||||
$link_attributes = array();
|
||||
if (!empty($node['isdir'])) {
|
||||
$class = ' class="file-tree-folder"';
|
||||
} else {
|
||||
$class = ' class="file-tree-file"';
|
||||
$link_attributes['target'] = '_blank';
|
||||
}
|
||||
$html .= '<li '.$class.'>';
|
||||
$html .= html_writer::link($node['url'], $node['filename'], $link_attributes);
|
||||
$html .= '</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the area file tree viewer
|
||||
*
|
||||
* <pre>
|
||||
* $OUTPUT->area_file_tree_viewer($contextid, $filearea, $itemid, $urlbase);
|
||||
* </pre>
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $area
|
||||
* @param int $itemid
|
||||
* @param string $urlbase
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function area_file_tree_viewer($contextid, $area, $itemid, $urlbase='') {
|
||||
$tree = new area_file_tree_viewer($contextid, $area, $itemid, $urlbase);
|
||||
return $this->render($tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation of area file tree viewer rendering.
|
||||
* @param area_file_tree_viewer $tree
|
||||
* @return string
|
||||
*/
|
||||
public function render_area_file_tree_viewer(area_file_tree_viewer $tree) {
|
||||
$this->page->requires->js_init_call('M.mod_folder.init_tree', array(true));
|
||||
$html = '';
|
||||
$html .= '<div id="folder_tree">';
|
||||
$html .= $this->htmllize_file_tree($tree->dir);
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation of file tree viewer items rendering.
|
||||
* @param array $dir
|
||||
@ -1929,135 +1847,6 @@ EOD;
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the file manager
|
||||
*
|
||||
* <pre>
|
||||
* $OUTPUT->file_manager($options);
|
||||
* </pre>
|
||||
*
|
||||
* @param array $options associative array with file manager options
|
||||
* options are:
|
||||
* maxbytes=>-1,
|
||||
* maxfiles=>-1,
|
||||
* filearea=>'user_draft',
|
||||
* itemid=>0,
|
||||
* subdirs=>false,
|
||||
* client_id=>uniqid(),
|
||||
* acepted_types=>'*',
|
||||
* return_types=>FILE_INTERNAL,
|
||||
* context=>$PAGE->context
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function file_manager($options) {
|
||||
$fm = new file_manager($options);
|
||||
return $this->render($fm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation of file manager rendering.
|
||||
* @param file_manager $fm
|
||||
* @return string
|
||||
*/
|
||||
public function render_file_manager(file_manager $fm) {
|
||||
global $CFG, $OUTPUT;
|
||||
static $filemanagertemplateloaded;
|
||||
$html = '';
|
||||
$nonjsfilemanager = optional_param('usenonjsfilemanager', 0, PARAM_INT);
|
||||
$options = $fm->options;
|
||||
$options->usenonjs = $nonjsfilemanager;
|
||||
$straddfile = get_string('add', 'repository') . '...';
|
||||
$strmakedir = get_string('makeafolder', 'moodle');
|
||||
$strdownload = get_string('downloadfolder', 'repository');
|
||||
$strloading = get_string('loading', 'repository');
|
||||
|
||||
$icon_add_file = $OUTPUT->pix_icon('t/addfile', $straddfile).'';
|
||||
$icon_add_folder = $OUTPUT->pix_icon('t/adddir', $strmakedir).'';
|
||||
$icon_download = $OUTPUT->pix_icon('t/download', $strdownload).'';
|
||||
$icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
|
||||
|
||||
$client_id = $options->client_id;
|
||||
$itemid = $options->itemid;
|
||||
$filearea = $options->filearea;
|
||||
|
||||
if (empty($options->filecount)) {
|
||||
$extra = ' style="display:none"';
|
||||
} else {
|
||||
$extra = '';
|
||||
}
|
||||
|
||||
$html .= <<<FMHTML
|
||||
<div class="filemanager-loading mdl-align" id='filemanager-loading-{$client_id}'>
|
||||
$icon_progress
|
||||
</div>
|
||||
<div id="filemanager-wrapper-{$client_id}" style="display:none">
|
||||
<div class="fm-breadcrumb" id="fm-path-{$client_id}"></div>
|
||||
<div class="filemanager-toolbar">
|
||||
<button id="btnadd-{$client_id}" onclick="return false">{$icon_add_file} $straddfile</button>
|
||||
<button id="btncrt-{$client_id}" onclick="return false">{$icon_add_folder} $strmakedir</button>
|
||||
<button id="btndwn-{$client_id}" onclick="return false" {$extra}>{$icon_download} $strdownload</button>
|
||||
</div>
|
||||
<div class="filemanager-container" id="filemanager-{$client_id}">
|
||||
<ul id="draftfiles-{$client_id}" class="fm-filelist">
|
||||
<li>Loading...</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class='clearer'></div>
|
||||
FMHTML;
|
||||
if (empty($filemanagertemplateloaded)) {
|
||||
$filemanagertemplateloaded = true;
|
||||
$html .= <<<FMHTML
|
||||
<div id="fm-template" style="display:none">___fullname___ ___action___</div>
|
||||
FMHTML;
|
||||
}
|
||||
|
||||
$filemanagerurl = new moodle_url('/repository/filepicker.php', array(
|
||||
'filearea'=>$filearea,
|
||||
'env'=>'filemanager',
|
||||
'action'=>'embedded',
|
||||
'itemid'=>$itemid,
|
||||
'subdirs'=>'/',
|
||||
'maxbytes'=>$options->maxbytes,
|
||||
'ctx_id'=>$this->page->context->id,
|
||||
'course'=>$this->page->course->id,
|
||||
));
|
||||
|
||||
$module = array(
|
||||
'name'=>'form_filemanager',
|
||||
'fullpath'=>'/lib/form/filemanager.js',
|
||||
'requires' => array('core_filepicker', 'base', 'io', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview'),
|
||||
'strings' => array(array('loading', 'repository'), array('nomorefiles', 'repository'), array('confirmdeletefile', 'repository'),
|
||||
array('add', 'repository'), array('accessiblefilepicker', 'repository'), array('move', 'moodle'),
|
||||
array('cancel', 'moodle'), array('download', 'moodle'), array('ok', 'moodle'),
|
||||
array('emptylist', 'repository'), array('nofilesattached', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
|
||||
array('zip', 'editor'), array('unzip', 'moodle'), array('rename', 'moodle'), array('delete', 'moodle'),
|
||||
array('cannotdeletefile', 'error'), array('confirmdeletefile', 'repository'),
|
||||
array('nopathselected', 'repository'), array('popupblockeddownload', 'repository'),
|
||||
array('draftareanofiles', 'repository'), array('path', 'moodle'), array('setmainfile', 'repository')
|
||||
)
|
||||
);
|
||||
$this->page->requires->js_module($module);
|
||||
$this->page->requires->js_init_call('M.form_filemanager.init', array($options), true, $module);
|
||||
|
||||
// non javascript file manager
|
||||
if (!empty($nonjsfilemanager)) {
|
||||
$html = '<div id="nonjs-filemanager-'.$client_id.'">';
|
||||
$html .= <<<NONJS
|
||||
<object type="text/html" data="$filemanagerurl" height="160" width="600" style="border:1px solid #000">Error</object>
|
||||
NONJS;
|
||||
$html .= '</div>';
|
||||
} else {
|
||||
$url = new moodle_url($this->page->url, array('usenonjsfilemanager'=>1));
|
||||
$html .= '<div id="nonjs-filemanager-'.$client_id.'" class="mdl-align">';
|
||||
$html .= html_writer::link($url, get_string('usenonjsfilemanager', 'repository'));
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the 'Update this Modulename' button that appears on module pages.
|
||||
*
|
||||
|
@ -376,6 +376,7 @@ abstract class portfolio_caller_base {
|
||||
* - array of file ids or stored_file objects
|
||||
* - null
|
||||
* @param int $contextid (optional), passed to {@link see file_storage::get_area_files}
|
||||
* @param string $component (optional), passed to {@link see file_storage::get_area_files}
|
||||
* @param string $filearea (optional), passed to {@link see file_storage::get_area_files}
|
||||
* @param int $itemid (optional), passed to {@link see file_storage::get_area_files}
|
||||
* @param string $sort (optional), passed to {@link see file_storage::get_area_files}
|
||||
@ -401,7 +402,7 @@ abstract class portfolio_caller_base {
|
||||
}
|
||||
}
|
||||
} else if (count($args) != 0) {
|
||||
if (count($args) < 3) {
|
||||
if (count($args) < 4) {
|
||||
throw new portfolio_caller_exception('invalidfileareaargs', 'portfolio');
|
||||
}
|
||||
$files = array_values(call_user_func_array(array($fs, 'get_area_files'), $args));
|
||||
|
@ -493,7 +493,7 @@ class portfolio_exporter {
|
||||
}
|
||||
$DB->delete_records('portfolio_tempdata', array('id' => $this->id));
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files(SYSCONTEXTID, 'portfolio_exporter', $this->id);
|
||||
$fs->delete_area_files(SYSCONTEXTID, 'portfolio', 'exporter', $this->id);
|
||||
$this->deleted = true;
|
||||
return true;
|
||||
}
|
||||
@ -805,7 +805,7 @@ class portfolio_exporter {
|
||||
*/
|
||||
public function get_tempfiles($skipfile='portfolio-export.zip') {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files(SYSCONTEXTID, 'portfolio_exporter', $this->id, '', false);
|
||||
$files = $fs->get_area_files(SYSCONTEXTID, 'portfolio', 'exporter', $this->id, '', false);
|
||||
if (empty($files)) {
|
||||
return array();
|
||||
}
|
||||
@ -831,8 +831,9 @@ class portfolio_exporter {
|
||||
public function get_base_filearea() {
|
||||
return array(
|
||||
'contextid' => SYSCONTEXTID,
|
||||
'filearea' => 'portfolio_exporter',
|
||||
'itemid' => $this->id,
|
||||
'component' => 'portfolio',
|
||||
'filearea' => 'exporter',
|
||||
'itemid' => $this->id,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1181,7 +1181,7 @@ function portfolio_existing_exports_by_plugin($userid) {
|
||||
* callback function from {@link portfolio_rewrite_pluginfile_urls}
|
||||
* looks through preg_replace matches and replaces content with whatever the active portfolio export format says
|
||||
*/
|
||||
function portfolio_rewrite_pluginfile_url_callback($contextid, $filearea, $itemid, $format, $options, $matches) {
|
||||
function portfolio_rewrite_pluginfile_url_callback($contextid, $component, $filearea, $itemid, $format, $options, $matches) {
|
||||
$matches = $matches[0]; // no internal matching
|
||||
$dom = new DomDocument();
|
||||
if (!$dom->loadXML($matches)) {
|
||||
@ -1208,8 +1208,8 @@ function portfolio_rewrite_pluginfile_url_callback($contextid, $filearea, $item
|
||||
$filename = array_pop($bits);
|
||||
$filepath = implode('/', $bits);
|
||||
}
|
||||
if (!$file = $fs->get_file($contextid, $filearea, $itemid, $filepath, $filename)) {
|
||||
debugging("Couldn\t find a file from the embedded path info context $contextid filearea $filearea itemid $itemid filepath $filepath name $filename");
|
||||
if (!$file = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||
debugging("Couldn\t find a file from the embedded path info context $contextid component $component filearea $filearea itemid $itemid filepath $filepath name $filename");
|
||||
return $matches;
|
||||
}
|
||||
if (empty($options)) {
|
||||
@ -1227,6 +1227,7 @@ function portfolio_rewrite_pluginfile_url_callback($contextid, $filearea, $item
|
||||
*
|
||||
* @param string $text the text to search through
|
||||
* @param int $contextid normal file_area arguments
|
||||
* @param string $component
|
||||
* @param string $filearea normal file_area arguments
|
||||
* @param int $itemid normal file_area arguments
|
||||
* @param portfolio_format $format the portfolio export format
|
||||
@ -1234,9 +1235,9 @@ function portfolio_rewrite_pluginfile_url_callback($contextid, $filearea, $item
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function portfolio_rewrite_pluginfile_urls($text, $contextid, $filearea, $itemid, $format, $options=null) {
|
||||
function portfolio_rewrite_pluginfile_urls($text, $contextid, $component, $filearea, $itemid, $format, $options=null) {
|
||||
$pattern = '/(<[^<]*?="@@PLUGINFILE@@\/[^>]*?(?:\/>|>.*?<\/[^>]*?>))/';
|
||||
$callback = partial('portfolio_rewrite_pluginfile_url_callback', $contextid, $filearea, $itemid, $format, $options);
|
||||
$callback = partial('portfolio_rewrite_pluginfile_url_callback', $contextid, $component, $filearea, $itemid, $format, $options);
|
||||
return preg_replace_callback($pattern, $callback, $text);
|
||||
}
|
||||
// this function has to go last, because the regexp screws up syntax highlighting in some editors
|
||||
|
@ -51,11 +51,12 @@ define('RESOURCELIB_LEGACYFILES_ACTIVE', 2);
|
||||
* @param string $filepath old file path
|
||||
* @param int $cmid migrated course module if
|
||||
* @param int $courseid
|
||||
* @param string $component
|
||||
* @param string $filearea new file area
|
||||
* @param int $itemid migrated file item id
|
||||
* @return mixed, false if not found, stored_file instance if migrated to new area
|
||||
*/
|
||||
function resourcelib_try_file_migration($filepath, $cmid, $courseid, $filearea, $itemid) {
|
||||
function resourcelib_try_file_migration($filepath, $cmid, $courseid, $component, $filearea, $itemid) {
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (stripos($filepath, '/backupdata/') === 0 or stripos($filepath, '/moddata/') === 0) {
|
||||
@ -70,13 +71,13 @@ function resourcelib_try_file_migration($filepath, $cmid, $courseid, $filearea,
|
||||
return false;
|
||||
}
|
||||
|
||||
$pathnamehash = sha1($coursecontext->id.'course_content0'.$filepath);
|
||||
$pathnamehash = sha1("/$coursecontext->id/course/legacy/0".$filepath);
|
||||
if (!$file = $fs->get_file_by_hash($pathnamehash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// copy and keep the same path, name, etc.
|
||||
$file_record = array('contextid'=>$context->id, 'filearea'=>$filearea, 'itemid'=>$itemid);
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid);
|
||||
try {
|
||||
return $fs->create_file_from_storedfile($file_record, $file);
|
||||
} catch (Exception $e) {
|
||||
|
@ -800,7 +800,7 @@ function get_real_size($size=0) {
|
||||
*/
|
||||
function redirect_if_major_upgrade_required() {
|
||||
global $CFG;
|
||||
$lastmajordbchanges = 2010061600;
|
||||
$lastmajordbchanges = 2010070300;
|
||||
if (empty($CFG->version) or (int)$CFG->version < $lastmajordbchanges or
|
||||
during_initial_install() or !empty($CFG->adminsetuppending)) {
|
||||
try {
|
||||
|
@ -28,8 +28,6 @@ if (!defined('MOODLE_INTERNAL')) {
|
||||
}
|
||||
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->libdir.'/file/file_browser.php');
|
||||
require_once($CFG->libdir.'/file/file_info_course.php');
|
||||
|
||||
require_once($CFG->dirroot.'/user/lib.php');
|
||||
require_once($CFG->dirroot.'/mod/forum/lib.php');
|
||||
@ -259,19 +257,19 @@ class file_browser_test extends filelib_test {
|
||||
}
|
||||
}
|
||||
|
||||
class test_file_info_system extends filelib_test {
|
||||
class test_file_info_context_system extends filelib_test {
|
||||
public function test_get_children() {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
|
||||
$fis = new file_info_system(new file_browser(), $context);
|
||||
$fis = new file_info_context_system(new file_browser(), $context);
|
||||
$children = $fis->get_children();
|
||||
|
||||
$found_coursecat = false;
|
||||
$context_coursecat = get_context_instance(CONTEXT_COURSECAT, $this->coursecat->id);
|
||||
$file_info_coursecat = new file_info_coursecat(new file_browser(), $context_coursecat, $this->coursecat);
|
||||
$file_info_context_coursecat = new file_info_context_coursecat(new file_browser(), $context_coursecat, $this->coursecat);
|
||||
|
||||
foreach ($children as $child) {
|
||||
if ($child == $file_info_coursecat) {
|
||||
if ($child == $file_info_context_coursecat) {
|
||||
$found_coursecat = true;
|
||||
}
|
||||
}
|
||||
@ -279,13 +277,13 @@ class test_file_info_system extends filelib_test {
|
||||
}
|
||||
}
|
||||
|
||||
class test_file_info_coursecat extends filelib_test {
|
||||
class test_file_info_context_coursecat extends filelib_test {
|
||||
private $fileinfo;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$context = get_context_instance(CONTEXT_COURSECAT, $this->coursecat->id);
|
||||
$this->fileinfo = new file_info_coursecat(new file_browser(), $context, $this->coursecat);
|
||||
$this->fileinfo = new file_info_context_coursecat(new file_browser(), $context, $this->coursecat);
|
||||
}
|
||||
|
||||
public function test_get_children() {
|
||||
@ -298,25 +296,25 @@ class test_file_info_coursecat extends filelib_test {
|
||||
$this->assertEqual('file_info_stored', get_class($children[0]));
|
||||
|
||||
$context_course = get_context_instance(CONTEXT_COURSE, $this->course->id);
|
||||
$fic = new file_info_course(new file_browser(), $context_course, $this->course);
|
||||
$fic = new file_info_context_course(new file_browser(), $context_course, $this->course);
|
||||
$this->assertEqual($fic, $children[1]);
|
||||
}
|
||||
|
||||
public function test_get_parent() {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$fis = new file_info_system(new file_browser(), $context);
|
||||
$fis = new file_info_context_system(new file_browser(), $context);
|
||||
$parent = $this->fileinfo->get_parent();
|
||||
$this->assertEqual($parent, $fis);
|
||||
}
|
||||
}
|
||||
|
||||
class test_file_info_course extends filelib_test {
|
||||
class test_file_info_context_course extends filelib_test {
|
||||
private $fileinfo;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$context = get_context_instance(CONTEXT_COURSE, $this->course->id);
|
||||
$this->fileinfo = new file_info_course(new file_browser(), $context, $this->course);
|
||||
$this->fileinfo = new file_info_context_course(new file_browser(), $context, $this->course);
|
||||
}
|
||||
|
||||
public function test_get_children() {
|
||||
@ -330,7 +328,7 @@ class test_file_info_course extends filelib_test {
|
||||
$this->assertEqual('file_info_stored', get_class($children[0]));
|
||||
|
||||
$context_course = get_context_instance(CONTEXT_COURSE, $this->course->id);
|
||||
$fics = new file_info_coursesection(new file_browser(), $context_course, $this->course);
|
||||
$fics = new file_info_area_course_section(new file_browser(), $context_course, $this->course);
|
||||
$this->assertEqual($fics, $children[1]);
|
||||
|
||||
$this->assertEqual('Backups', $children[2]->get_visible_name());
|
||||
@ -339,30 +337,30 @@ class test_file_info_course extends filelib_test {
|
||||
|
||||
$this->assertEqual('Course files', $children[3]->get_visible_name());
|
||||
$this->assertEqual('', $children[3]->get_url());
|
||||
$this->assertEqual('file_info_coursefile', get_class($children[3]));
|
||||
$this->assertEqual('file_info_area_course_legacy', get_class($children[3]));
|
||||
|
||||
}
|
||||
|
||||
public function test_get_parent() {
|
||||
$context = get_context_instance(CONTEXT_COURSECAT, $this->coursecat->id);
|
||||
$fic = new file_info_coursecat(new file_browser(), $context, $this->coursecat);
|
||||
$fic = new file_info_context_coursecat(new file_browser(), $context, $this->coursecat);
|
||||
$parent = $this->fileinfo->get_parent();
|
||||
$this->assertEqual($parent, $fic);
|
||||
}
|
||||
}
|
||||
|
||||
class test_file_info_user extends filelib_test {
|
||||
class test_file_info_context_user extends filelib_test {
|
||||
private $fileinfo;
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$context = get_context_instance(CONTEXT_USER, $this->user->id);
|
||||
$this->fileinfo = new file_info_user(new file_browser(), $context, $this->user);
|
||||
$this->fileinfo = new file_info_context_user(new file_browser(), $context, $this->user);
|
||||
}
|
||||
|
||||
public function test_get_parent() {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$fic = new file_info_system(new file_browser(), $context);
|
||||
$fic = new file_info_context_system(new file_browser(), $context);
|
||||
$parent = $this->fileinfo->get_parent();
|
||||
$this->assertEqual($parent, $fic);
|
||||
}
|
||||
@ -381,19 +379,19 @@ class test_file_info_user extends filelib_test {
|
||||
}
|
||||
}
|
||||
|
||||
class test_file_info_module extends filelib_test {
|
||||
class test_file_info_context_module extends filelib_test {
|
||||
private $fileinfo;
|
||||
|
||||
public function setup() {
|
||||
global $DB;
|
||||
parent::setup();
|
||||
$context = get_context_instance(CONTEXT_MODULE, $DB->get_field('course_modules', 'id', array('instance' => $this->module->instance)));
|
||||
$this->fileinfo = new file_info_module(new file_browser(), $this->course, $this->module->instance, $context, array());
|
||||
$this->fileinfo = new file_info_context_module(new file_browser(), $this->course, $this->module->instance, $context, array());
|
||||
}
|
||||
|
||||
public function test_get_parent() {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $this->course->id);
|
||||
$fic = new file_info_course(new file_browser(), $context, $this->course);
|
||||
$fic = new file_info_context_course(new file_browser(), $context, $this->course);
|
||||
$parent = $this->fileinfo->get_parent();
|
||||
$this->assertEqual($parent, $fic);
|
||||
}
|
||||
|
@ -701,7 +701,7 @@ class moodle_url {
|
||||
$urlbase = "$CFG->httpswwwroot/draftfile.php";
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
|
||||
return self::make_file_url($urlbase, '/'.$context->id.'/user_draft/'.$itemid.$pathname.$filename, $forcedownload);
|
||||
return self::make_file_url($urlbase, '/'.$context->id.'/user/draft/'.$itemid.$pathname.$filename, $forcedownload);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1356,7 +1356,7 @@ function format_module_intro($module, $activity, $cmid, $filter=true) {
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
$options = (object)array('noclean'=>true, 'para'=>false, 'filter'=>false);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
$intro = file_rewrite_pluginfile_urls($activity->intro, 'pluginfile.php', $context->id, $module.'_intro', null);
|
||||
$intro = file_rewrite_pluginfile_urls($activity->intro, 'pluginfile.php', $context->id, 'mod_'.$module, 'intro', null);
|
||||
return trim(format_text($intro, $activity->introformat, $options));
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,8 @@ class backup_assignment_activity_structure_step extends backup_activity_structur
|
||||
$submission->annotate_ids('user', 'teacher');
|
||||
|
||||
// Define file annotations
|
||||
$assignment->annotate_files(array('assignment_intro'), null); // This file area hasn't itemid
|
||||
$submission->annotate_files(array('assignment_submission'), 'id');
|
||||
$assignment->annotate_files('mod_assignment', 'intro', null); // This file area hasn't itemid
|
||||
$submission->annotate_files('mod_assignment', 'submission', 'id');
|
||||
|
||||
// Return the root element (assignment), wrapped into standard activity structure
|
||||
return $this->prepare_activity_structure($assignment);
|
||||
|
@ -69,7 +69,6 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||
|
||||
// migrate submitted files first
|
||||
$path = $basepath;
|
||||
$filearea = 'assignment_submission';
|
||||
$items = new DirectoryIterator($path);
|
||||
foreach ($items as $item) {
|
||||
if (!$item->isFile()) {
|
||||
@ -83,8 +82,8 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||
if ($filename === '') {
|
||||
continue;
|
||||
}
|
||||
if (!$fs->file_exists($context->id, $filearea, $submission->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'filearea'=>$filearea, 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$submission->userid);
|
||||
if (!$fs->file_exists($context->id, 'mod_assignment', 'submission', $submission->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_assignment', 'filearea'=>'submission', 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$submission->userid);
|
||||
if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) {
|
||||
unlink($path.$item->getFilename());
|
||||
}
|
||||
@ -92,10 +91,9 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||
}
|
||||
unset($items); //release file handles
|
||||
|
||||
// migrate teacher response files
|
||||
// migrate teacher response files for "upload" subtype, unfortunately we do not
|
||||
$path = $basepath.'responses/';
|
||||
if (file_exists($path)) {
|
||||
$filearea = 'assignment_response';
|
||||
$items = new DirectoryIterator($path);
|
||||
foreach ($items as $item) {
|
||||
if (!$item->isFile()) {
|
||||
@ -105,8 +103,8 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||
if ($filename === '') {
|
||||
continue;
|
||||
}
|
||||
if (!$fs->file_exists($context->id, $filearea, $submission->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'filearea'=>$filearea, 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename,
|
||||
if (!$fs->file_exists($context->id, 'mod_assignment', 'response', $submission->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_assignment', 'filearea'=>'response', 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename,
|
||||
'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime());
|
||||
if ($submission->teacher) {
|
||||
$file_record['userid'] = $submission->teacher;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user