3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * This plugin is used to access user's private files
22 * @package repository_user
23 * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once($CFG->dirroot
. '/repository/lib.php');
29 * repository_user class is used to browse user private files
32 * @package repository_user
33 * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class repository_user
extends repository
{
39 * user plugin doesn't require login
43 public function print_login() {
44 return $this->get_listing();
50 * @param string $encodedpath
53 public function get_listing($encodedpath = '', $page = '') {
54 global $CFG, $USER, $OUTPUT;
56 $ret['dynload'] = true;
57 $ret['nosearch'] = true;
58 $ret['nologin'] = true;
59 $manageurl = new moodle_url('/user/files.php');
60 $ret['manage'] = $manageurl->out();
63 if (!empty($encodedpath)) {
64 $params = json_decode(base64_decode($encodedpath), true);
65 if (is_array($params)) {
66 $filepath = clean_param($params['filepath'], PARAM_PATH
);
67 $filename = clean_param($params['filename'], PARAM_FILE
);
74 $filearea = 'private';
77 $context = context_user
::instance($USER->id
);
80 $browser = get_file_browser();
82 if ($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
85 $params = $fileinfo->get_params();
86 while ($level && $params['component'] == 'user' && $params['filearea'] == 'private') {
87 $encodedpath = base64_encode(json_encode($level->get_params()));
88 $pathnodes[] = array('name'=>$level->get_visible_name(), 'path'=>$encodedpath);
89 $level = $level->get_parent();
90 $params = $level->get_params();
92 $ret['path'] = array_reverse($pathnodes);
95 $children = $fileinfo->get_children();
96 foreach ($children as $child) {
97 if ($child->is_directory()) {
98 $encodedpath = base64_encode(json_encode($child->get_params()));
100 'title' => $child->get_visible_name(),
101 'datemodified' => $child->get_timemodified(),
102 'datecreated' => $child->get_timecreated(),
103 'path' => $encodedpath,
105 'thumbnail' => $OUTPUT->image_url(file_folder_icon(90))->out(false)
109 $encodedpath = base64_encode(json_encode($child->get_params()));
111 'title' => $child->get_visible_name(),
112 'size' => $child->get_filesize(),
113 'datemodified' => $child->get_timemodified(),
114 'datecreated' => $child->get_timecreated(),
115 'author' => $child->get_author(),
116 'license' => $child->get_license(),
117 'isref' => $child->is_external_file(),
118 'source'=> $encodedpath,
119 'icon' => $OUTPUT->image_url(file_file_icon($child, 24))->out(false),
120 'thumbnail' => $OUTPUT->image_url(file_file_icon($child, 90))->out(false)
122 if ($child->get_status() == 666) {
123 $node['originalmissing'] = true;
125 if ($imageinfo = $child->get_imageinfo()) {
126 $fileurl = new moodle_url($child->get_url());
127 $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $child->get_timemodified()));
128 $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $child->get_timemodified()));
129 $node['image_width'] = $imageinfo['width'];
130 $node['image_height'] = $imageinfo['height'];
136 } catch (Exception
$e) {
137 throw new repository_exception('emptyfilelist', 'repository_user');
139 $ret['list'] = $list;
140 $ret['list'] = array_filter($list, array($this, 'filter'));
145 * Does this repository used to browse moodle files?
149 public function has_moodle_files() {
154 * User cannot use the external link to dropbox
158 public function supported_returntypes() {
159 return FILE_INTERNAL | FILE_REFERENCE
;
163 * Is this repository accessing private data?
167 public function contains_private_data() {