MDL-22591, user_private plugin, disable it from private file block, hide user_private area from local plugin

This commit is contained in:
Dongsheng Cai
2010-05-31 03:03:21 +00:00
parent 838447cadc
commit 6bf197b34c
12 changed files with 368 additions and 9 deletions
@@ -66,6 +66,7 @@ class block_private_files extends block_base {
$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);
+1
View File
@@ -191,6 +191,7 @@ class file_manager implements renderable {
$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;
}
+20 -7
View File
@@ -637,7 +637,9 @@ abstract class repository {
$sql .= ' AND (i.userid = 0 or i.userid = ?)';
$params[] = $args['userid'];
}
if (!empty($args['disable_types']) && is_array($args['disable_types'])) {
$sql .= ' AND r.type NOT IN ("'.implode('","', $args['disable_types']).'")';
}
foreach ($contexts as $context) {
if (empty($firstcontext)) {
$firstcontext = true;
@@ -1815,6 +1817,10 @@ function initialise_filepicker($args) {
} else {
$context = $args->context;
}
$disable_types = array();
if (!empty($args->disable_types)) {
$disable_types = $args->disable_types;
}
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
@@ -1823,7 +1829,8 @@ function initialise_filepicker($args) {
'context'=>array($user_context, get_system_context()),
'currentcontext'=> $context,
'accepted_types'=>$args->accepted_types,
'return_types'=>$args->return_types
'return_types'=>$args->return_types,
'disable_types'=>$disable_types
));
$return->repositories = array();
@@ -1854,12 +1861,18 @@ function repository_setup_default_plugins() {
global $OUTPUT;
//if the plugin type has no multiple instance (e.g. has no instance option name)
//repository_type::create will create an instance automatically
$local_plugin = new repository_type('local', array(), true);
$local_plugin_id = $local_plugin->create(true);
$upload_plugin = new repository_type('upload', array(), true);
$upload_plugin_id = $upload_plugin->create(true);
$user_plugin = new repository_type('user', array(), true);
$upload_plugin->create(true);
$recent_plugin = new repository_type('recent', array(), true);
$recent_plugin_id = $upload_plugin->create(true);
$upload_plugin->create(true);
$upload_plugin = new repository_type('upload', array(), true);
$upload_plugin->create(true);
$local_plugin = new repository_type('local', array(), true);
$local_plugin->create(true);
echo $OUTPUT->notification(get_string('setupdefaultplugins', 'repository'), 'notifysuccess');
return true;
}
+7 -1
View File
@@ -108,7 +108,13 @@ class repository_local extends repository {
$children = $fileinfo->get_children();
foreach ($children as $child) {
if ($child->is_directory()) {
$encodedpath = base64_encode(serialize($child->get_params()));
$params = $child->get_params();
$encodedpath = base64_encode(serialize($params));
// hide user_private area from local plugin, user should
// use private file plugin to access private files
if ($params['filearea'] == 'user_private') {
continue;
}
$node = array(
'title' => $child->get_visible_name(),
'size' => 0,
+1 -1
View File
@@ -228,7 +228,7 @@ switch ($action) {
// We have two special repoisitory type need to deal with
// local and recent plugins don't added new files to moodle, just add new records to database
// so we don't check user quota and maxbytes here
if ($repo->options['type'] == 'local' || $repo->options['type'] == 'recent' ) {
if (in_array($repo->options['type'], array('local', 'recent', 'user'))) {
try {
$fileinfo = $repo->copy_to_area($source, $saveas_filearea, $itemid, $saveas_path, $saveas_filename);
} catch (Exception $e) {
+31
View File
@@ -0,0 +1,31 @@
<?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/>.
$capabilities = array(
'repository/user:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW,
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
)
);
+27
View File
@@ -0,0 +1,27 @@
<?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/>.
function xmldb_repository_user_install() {
global $CFG;
$result = true;
require_once($CFG->dirroot.'/repository/lib.php');
$user_plugin = new repository_type('user', array(), true);
if(!$id = $user_plugin->create(true)) {
$result = false;
}
return $result;
}
+35
View File
@@ -0,0 +1,35 @@
<?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/>.
function xmldb_repository_user_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of database_manager methods
/// }
return $result;
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

+31
View File
@@ -0,0 +1,31 @@
<?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/>.
/**
* Strings for component 'repository_user', language 'en', branch 'MOODLE_20_STABLE'
*
* @package repository_user
* @copyright 2010 Dongsheng Cai
* @author Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['configplugin'] = 'Configuration for user private files repository';
$string['repositorydesc'] = 'Files in user private area';
$string['repositoryname'] = 'Private files';
$string['emptyfilelist'] = 'There are no files to show';
$string['user:view'] = 'View user private files';
+196
View File
@@ -0,0 +1,196 @@
<?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/>.
/**
* repository_user class is used to browse user private files
*
* @since 2.0
* @package moodlecore
* @subpackage repository
* @copyright 2010 Dongsheng Cai
* @author Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repository_user extends repository {
/**
* initialize user plugin
* @param int $repositoryid
* @param int $context
* @param array $options
*/
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
parent::__construct($repositoryid, $context, $options);
}
/**
* user plugin doesn't require login
* @return mixed
*/
public function print_login() {
return $this->get_listing();
}
/**
* Not supported by File API yet
* @param string $search_text
* @return mixed
*/
public function search($search_text) {
return array();
}
/**
* Get file listing
*
* @param string $encodedpath
* @return mixed
*/
public function get_listing($encodedpath = '') {
global $CFG, $USER, $OUTPUT;
$ret = array();
$ret['dynload'] = true;
$ret['nosearch'] = true;
$ret['nologin'] = true;
$list = array();
if (!empty($encodedpath)) {
$params = unserialize(base64_decode($encodedpath));
if (is_array($params)) {
$itemid = $params['itemid'];
$filename = $params['filename'];
$filearea = $params['filearea'];
$filepath = $params['filepath'];
$context = get_context_instance_by_id($params['contextid']);
}
} else {
$itemid = 0;
$filename = null;
$filearea = 'user_private';
$filepath = '/';
$context = get_context_instance(CONTEXT_USER, $USER->id);
}
try {
$browser = get_file_browser();
if ($fileinfo = $browser->get_file_info($context, $filearea, $itemid, $filepath, $filename)) {
$pathnodes = array();
$level = $fileinfo;
$params = $fileinfo->get_params();
while ($level && $params['filearea'] == 'user_private') {
$encodedpath = base64_encode(serialize($level->get_params()));
$pathnodes[] = array('name'=>$level->get_visible_name(), 'path'=>$encodedpath);
$level = $level->get_parent();
$params = $level->get_params();
}
$ret['path'] = array_reverse($pathnodes);
// build file tree
$children = $fileinfo->get_children();
foreach ($children as $child) {
if ($child->is_directory()) {
$encodedpath = base64_encode(serialize($child->get_params()));
$node = array(
'title' => $child->get_visible_name(),
'size' => 0,
'date' => '',
'path' => $encodedpath,
'children'=>array(),
'thumbnail' => $OUTPUT->pix_url('f/folder-32') . ''
);
$list[] = $node;
} else {
$encodedpath = base64_encode(serialize($child->get_params()));
$icon = 'f/'.str_replace('.gif', '', mimeinfo('icon', $child->get_visible_name())).'-32';
$node = array(
'title' => $child->get_visible_name(),
'size' => 0,
'date' => '',
'source'=> $encodedpath,
'thumbnail' => $OUTPUT->pix_url($icon) . '',
);
$list[] = $node;
}
}
}
} catch (Exception $e) {
throw new repository_exception('emptyfilelist', 'repository_user');
}
$ret['list'] = $list;
return $ret;
}
/**
* Set repository name
*
* @return string repository name
*/
public function get_name(){
return get_string('areauserpersonal', 'repository');;
}
/**
* User file don't support to link to external links
*
* @return int
*/
public function supported_returntypes() {
return FILE_INTERNAL;
}
/**
* Copy a file to file area
*
* @global object $USER
* @global object $DB
* @param string $encoded The metainfo of file, it is base64 encoded php seriablized data
* @param string $new_filename The intended name of file
* @param string $new_itemid itemid
* @param string $new_filepath the new path in draft area
* @return array The information of file
*/
public function copy_to_area($encoded, $new_filearea='user_draft', $new_itemid = '', $new_filepath = '/', $new_filename = '') {
global $USER, $DB;
$info = array();
$browser = get_file_browser();
$params = unserialize(base64_decode($encoded));
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
// the final file
$contextid = $params['contextid'];
$filearea = $params['filearea'];
$filepath = $params['filepath'];
$filename = $params['filename'];
$fileitemid = $params['itemid'];
$context = get_context_instance_by_id($contextid);
try {
$file_info = $browser->get_file_info($context, $filearea, $fileitemid, $filepath, $filename);
$file_info->copy_to_storage($user_context->id, $new_filearea, $new_itemid, $new_filepath, $new_filename);
} catch (Exception $e) {
throw $e;
}
$info['itemid'] = $new_itemid;
$info['title'] = $new_filename;
$info['contextid'] = $user_context->id;
$info['filesize'] = $file_info->get_filesize();
return $info;
}
}
+18
View File
@@ -0,0 +1,18 @@
<?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/>.
$plugin->version = 2010052700;