MDL-31641 filemanager - display help message when drag and drop upload is not supported
[moodle.git] / files / renderer.php
CommitLineData
64f93798
PS
1<?php
2///////////////////////////////////////////////////////////////////////////
3// //
4// This file is part of Moodle - http://moodle.org/ //
5// Moodle - Modular Object-Oriented Dynamic Learning Environment //
6// //
7// Moodle is free software: you can redistribute it and/or modify //
8// it under the terms of the GNU General Public License as published by //
9// the Free Software Foundation, either version 3 of the License, or //
10// (at your option) any later version. //
11// //
12// Moodle is distributed in the hope that it will be useful, //
13// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15// GNU General Public License for more details. //
16// //
17// You should have received a copy of the GNU General Public License //
18// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
19// //
20///////////////////////////////////////////////////////////////////////////
21
22defined('MOODLE_INTERNAL') || die();
23
24/**
25 * Rendering of files viewer related widgets.
26 * @package core
27 * @subpackage file
28 * @copyright 2010 Dongsheng Cai
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 * @since Moodle 2.0
31 */
32
33/**
e921afa8 34 * File browser render
64f93798
PS
35 *
36 * @copyright 2010 Dongsheng Cai
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 * @since Moodle 2.0
39 */
40class core_files_renderer extends plugin_renderer_base {
41
42 public function files_tree_viewer(file_info $file_info, array $options = null) {
43 $tree = new files_tree_viewer($file_info, $options);
44 return $this->render($tree);
45 }
46
47 public function render_files_tree_viewer(files_tree_viewer $tree) {
e0873f13 48 $html = $this->output->heading_with_help(get_string('coursefiles'), 'courselegacyfiles', 'moodle');
0b259d91
DC
49
50 $html .= $this->output->container_start('coursefilesbreadcrumb');
64f93798
PS
51 foreach($tree->path as $path) {
52 $html .= $path;
53 $html .= ' / ';
54 }
0b259d91 55 $html .= $this->output->container_end();
64f93798 56
0b259d91
DC
57 $html .= $this->output->box_start();
58 $table = new html_table();
559276b1
MG
59 $table->head = array(get_string('name'), get_string('lastmodified'), get_string('size', 'repository'), get_string('type', 'repository'));
60 $table->align = array('left', 'left', 'left', 'left');
0b259d91
DC
61 $table->width = '100%';
62 $table->data = array();
63
64 foreach ($tree->tree as $file) {
559276b1
MG
65 $filedate = $filesize = $filetype = '';
66 if ($file['filedate']) {
67 $filedate = userdate($file['filedate'], get_string('strftimedatetimeshort', 'langconfig'));
68 }
69 if (empty($file['isdir'])) {
70 if ($file['filesize']) {
71 $filesize = display_size($file['filesize']);
72 }
73 $fileicon = file_file_icon($file, 24);
74 $filetype = get_mimetype_description($file);
0b259d91 75 } else {
559276b1 76 $fileicon = file_folder_icon(24);
64f93798 77 }
559276b1
MG
78 $table->data[] = array(
79 html_writer::link($file['url'], $this->output->pix_icon($fileicon, get_string('icon')) . ' ' . $file['filename']),
80 $filedate,
81 $filesize,
82 $filetype
83 );
64f93798 84 }
0b259d91
DC
85
86 $html .= html_writer::table($table);
e921afa8 87 $html .= $this->output->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid'=>$tree->context->id)), get_string('coursefilesedit'), 'get');
0b259d91 88 $html .= $this->output->box_end();
64f93798
PS
89 return $html;
90 }
906e7d89
MG
91
92 /**
93 * Prints the file manager and initializes all necessary libraries
94 *
95 * <pre>
96 * $fm = new form_filemanager($options);
97 * $output = get_renderer('core', 'files');
98 * echo $output->render($fm);
99 * </pre>
100 *
101 * @param form_filemanager $fm File manager to render
102 * @return string HTML fragment
103 */
d1d18691 104 public function render_form_filemanager($fm) {
906e7d89 105 static $filemanagertemplateloaded;
d1d18691 106 $html = $this->fm_print_generallayout($fm);
906e7d89
MG
107 $module = array(
108 'name'=>'form_filemanager',
109 'fullpath'=>'/lib/form/filemanager.js',
b73a7519 110 'requires' => array('core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'),
4325db53
MG
111 'strings' => array(
112 array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'),
113 array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
9a62f779
MG
114 array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'),
115 array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'),
116 array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'),
117 array('confirmrenamefile', 'repository')
906e7d89
MG
118 )
119 );
120 if (empty($filemanagertemplateloaded)) {
121 $filemanagertemplateloaded = true;
122 $this->page->requires->js_init_call('M.form_filemanager.set_templates',
e709ddd2 123 array($this->filemanager_js_templates()), true, $module);
906e7d89
MG
124 }
125 $this->page->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module);
126
127 // non javascript file manager
128 $html .= '<noscript>';
129 $html .= "<div><object type='text/html' data='".$fm->get_nonjsurl()."' height='160' width='600' style='border:1px solid #000'></object></div>";
130 $html .= '</noscript>';
131
132
133 return $html;
134 }
135
136 /**
137 * Returns html for displaying one file manager
138 *
139 * The main element in HTML must have id="filemanager-{$client_id}" and
140 * class="filemanager fm-loading";
141 * After all necessary code on the page (both html and javascript) is loaded,
142 * the class fm-loading will be removed and added class fm-loaded;
143 * The main element (class=filemanager) will be assigned the following classes:
144 * 'fm-maxfiles' - when filemanager has maximum allowed number of files;
145 * 'fm-nofiles' - when filemanager has no files at all (although there might be folders);
146 * 'fm-noitems' - when current view (folder) has no items - neither files nor folders;
147 * 'fm-updating' - when current view is being updated (usually means that loading icon is to be displayed);
148 * 'fm-nomkdir' - when 'Make folder' action is unavailable (empty($fm->options->subdirs) == true)
149 *
150 * Element with class 'filemanager-container' will be holding evens for dnd upload (dragover, etc.).
151 * It will have class:
152 * 'dndupload-ready' - when a file is being dragged over the browser
153 * 'dndupload-over' - when file is being dragged over this filepicker (additional to 'dndupload-ready')
154 * 'dndupload-uploading' - during the upload process (note that after dnd upload process is
155 * over, the file manager will refresh the files list and therefore will have for a while class
156 * fm-updating. Both waiting processes should look similar so the images don't jump for user)
157 *
158 * If browser supports Drag-and-drop, the body element will have class 'dndsupported',
159 * otherwise - 'dndnotsupported';
160 *
e709ddd2
MG
161 * Element with class 'fp-content' will be populated with files list;
162 * Element with class 'fp-btn-add' will hold onclick event for adding a file (opening filepicker);
163 * Element with class 'fp-btn-mkdir' will hold onclick event for adding new folder;
164 * Element with class 'fp-btn-download' will hold onclick event for download action;
165 *
166 * Element with class 'fp-path-folder' is a template for one folder in path toolbar.
167 * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
168 * Parent element will receive class 'empty' when there are no folders to be displayed;
169 * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
170 *
171 * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode
172 * can be changed or not;
173 * Inside element with class 'fp-viewbar' there are expected elements with classes
174 * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch
175 * between the view modes, the last clicked element will have the class 'checked';
906e7d89
MG
176 *
177 * @param form_filemanager $fm
178 * @return string
179 */
d1d18691 180 private function fm_print_generallayout($fm) {
906e7d89
MG
181 global $OUTPUT;
182 $options = $fm->options;
183 $client_id = $options->client_id;
184 $straddfile = get_string('addfile', 'repository');
185 $strmakedir = get_string('makeafolder', 'moodle');
186 $strdownload = get_string('downloadfolder', 'repository');
187 $strloading = get_string('loading', 'repository');
906e7d89
MG
188 $strdroptoupload = get_string('droptoupload', 'moodle');
189 $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
d1d18691 190 $restrictions = $this->fm_print_restrictions($fm);
db529c23 191 $strdndnotsupported = get_string('dndnotsupported_insentence', 'moodle').$OUTPUT->help_icon('dndnotsupported');
906e7d89
MG
192 $strdndenabledinbox = get_string('dndenabled_inbox', 'moodle');
193 $loading = get_string('loading', 'repository');
194
e709ddd2 195 $html = '
b73a7519 196<div id="filemanager-'.$client_id.'" class="filemanager fm-loading">
420e7bb2 197 <div class="fp-restrictions">
e709ddd2 198 '.$restrictions.'
db529c23 199 <span class="dnduploadnotsupported-message"> - '.$strdndnotsupported.' </span>
420e7bb2
BR
200 </div>
201 <div class="fp-navbar">
202 <div class="filemanager-toolbar">
420e7bb2
BR
203 <div class="fp-toolbar">
204 <div class="{!}fp-btn-add"><a href="#"><img src="'.$this->pix_url('a/add_file').'" /> '.$straddfile.'</a></div>
205 <div class="{!}fp-btn-mkdir"><a href="#"><img src="'.$this->pix_url('a/create_folder').'" /> '.$strmakedir.'</a></div>
0f0d10c5 206 <div class="{!}fp-btn-download"><a href="#"><img src="'.$this->pix_url('a/download_all').'" /> '.$strdownload.'</a></div>
420e7bb2 207 </div>
b4562710
BR
208 <div class="{!}fp-viewbar">
209 <a class="{!}fp-vb-icons" href="#"></a>
210 <a class="{!}fp-vb-details" href="#"></a>
211 <a class="{!}fp-vb-tree" href="#"></a>
212 </div>
420e7bb2
BR
213 </div>
214 <div class="fp-pathbar">
0f0d10c5 215 <span class="{!}fp-path-folder"><a class="{!}fp-path-folder-name" href="#"></a></span>
e709ddd2 216 </div>
906e7d89 217 </div>
0f0d10c5 218 <div class="filemanager-loading mdl-align">'.$icon_progress.'</div>
b73a7519 219 <div class="filemanager-container" >
e709ddd2 220 <div class="fm-content-wrapper">
420e7bb2 221 <div class="fp-content"></div>
a2c2ab3e 222 <div class="fm-empty-container">
03e40341 223 <div class="dndupload-message">'.$strdndenabledinbox.'<br/><div class="dndupload-arrow"></div></div>
e709ddd2 224 </div>
03e40341 225 <div class="dndupload-target">'.$strdroptoupload.'<br/><div class="dndupload-arrow"></div></div>
e709ddd2 226 <div class="dndupload-uploadinprogress">'.$icon_progress.'</div>
906e7d89 227 </div>
e709ddd2 228 <div class="filemanager-updating">'.$icon_progress.'</div>
906e7d89 229 </div>
420e7bb2 230</div>';
e709ddd2
MG
231 return preg_replace('/\{\!\}/', '', $html);
232 }
233
234 /**
235 * FileManager JS template for displaying one file in 'icon view' mode.
236 *
23b83009
MG
237 * Except for elements described in fp_js_template_iconfilename, this template may also
238 * contain element with class 'fp-contextmenu'. If context menu is available for this
239 * file, the top element will receive the additional class 'fp-hascontextmenu' and
240 * the element with class 'fp-contextmenu' will hold onclick event for displaying
241 * the context menu.
242 *
e709ddd2
MG
243 * @see fp_js_template_iconfilename()
244 * @return string
245 */
246 private function fm_js_template_iconfilename() {
420e7bb2
BR
247 $rv = '
248<div class="fp-file">
249 <a href="#">
9a62f779 250 <div style="position:relative;">
0f0d10c5
BR
251 <div class="{!}fp-thumbnail"></div>
252 <div class="fp-reficons1"></div>
253 <div class="fp-reficons2"></div>
254 </div>
255 <div class="fp-filename-field">
256 <div class="{!}fp-filename"></div>
9a62f779 257 </div>
0f0d10c5 258 </a>
23b83009
MG
259 <a class="{!}fp-contextmenu" href="#">'.$this->pix_icon('i/menu', '▶').'</a>
260</div>';
261 return preg_replace('/\{\!\}/', '', $rv);
e709ddd2
MG
262 }
263
264 /**
265 * FileManager JS template for displaying file name in 'table view' and 'tree view' modes.
266 *
23b83009
MG
267 * Except for elements described in fp_js_template_listfilename, this template may also
268 * contain element with class 'fp-contextmenu'. If context menu is available for this
269 * file, the top element will receive the additional class 'fp-hascontextmenu' and
270 * the element with class 'fp-contextmenu' will hold onclick event for displaying
271 * the context menu.
272 *
273 * @todo MDL-32736 remove onclick="return false;"
e709ddd2
MG
274 * @see fp_js_template_listfilename()
275 * @return string
276 */
277 private function fm_js_template_listfilename() {
420e7bb2 278 $rv = '
a9352f1f 279<span class="fp-filename-icon">
0f0d10c5 280 <a href="#">
420e7bb2 281 <span class="{!}fp-icon"></span>
99f374c4
RT
282 <span class="fp-reficons1"></span>
283 <span class="fp-reficons2"></span>
420e7bb2 284 <span class="{!}fp-filename"></span>
0f0d10c5 285 </a>
420e7bb2
BR
286 <a class="{!}fp-contextmenu" href="#" onclick="return false;">'.$this->pix_icon('i/menu', '▶').'</a>
287</span>';
23b83009 288 return preg_replace('/\{\!\}/', '', $rv);
e709ddd2
MG
289 }
290
694beb54
MG
291 /**
292 * FileManager JS template for displaying 'Make new folder' dialog.
293 *
294 * Must be wrapped in an element, CSS for this element must define width and height of the window;
295 *
296 * Must have one input element with type="text" (for users to enter the new folder name);
297 *
298 * content of element with class 'fp-dlg-curpath' will be replaced with current path where
299 * new folder is about to be created;
300 * elements with classes 'fp-dlg-butcreate' and 'fp-dlg-butcancel' will hold onclick events;
301 *
302 * @return string
303 */
304 private function fm_js_template_mkdir() {
420e7bb2 305 $rv = '
5e117466 306<div class="filemanager fp-mkdir-dlg">
7c3e6652 307 <div class="fp-mkdir-dlg-text">'.get_string('newfoldername','repository').'<br/><input type="text" /></div>
af9c48cb
BR
308 <button class="{!}fp-dlg-butcreate">'.get_string('makeafolder').'</button>
309 <button class="{!}fp-dlg-butcancel">'.get_string('cancel').'</button>
694beb54
MG
310</div>';
311 return preg_replace('/\{\!\}/', '', $rv);
312 }
313
314 /**
315 * FileManager JS template for error/info message displayed as a separate popup window.
316 *
317 * @see fp_js_template_message()
318 * @return string
319 */
320 private function fm_js_template_message() {
321 return $this->fp_js_template_message();
322 }
323
e709ddd2
MG
324 /**
325 * FileManager JS template for window with file information/actions.
326 *
55089a9d
MG
327 * All content must be enclosed in one element, CSS for this class must define width and
328 * height of the window;
e709ddd2
MG
329 *
330 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
331 *
332 * Inside the window the elements with the following classnames must be present:
333 * 'fp-saveas', 'fp-author', 'fp-license', 'fp-path'. Inside each of them must be
334 * one input element (or select in case of fp-license and fp-path). They may also have labels.
335 * The elements will be assign with class 'uneditable' and input/select element will become
336 * disabled if they are not applicable for the particular file;
337 *
e0ff0867 338 * There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated',
9dbdf31f
MG
339 * 'fp-size', 'fp-dimensions', 'fp-reflist'. They will receive additional class 'fp-unknown' if
340 * information is unavailable. If there is information available, the content of embedded
341 * element with class 'fp-value' will be substituted with the value;
e709ddd2 342 *
9a62f779
MG
343 * The value of Original ('fp-original') is loaded in separate request. When it is applicable
344 * but not yet loaded the 'fp-original' element receives additional class 'fp-loading';
345 *
9dbdf31f
MG
346 * The value of 'Aliases/Shortcuts' ('fp-reflist') is also loaded in separate request. When it
347 * is applicable but not yet loaded the 'fp-original' element receives additional class
348 * 'fp-loading'. The string explaining that XX references exist will replace content of element
349 * 'fp-refcount'. Inside '.fp-reflist .fp-value' each reference will be enclosed in <li>;
350 *
e709ddd2
MG
351 * Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip',
352 * 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick
353 * events (there may be several elements with class 'fp-file-cancel');
354 *
355 * When confirm button is pressed and file is being selected, the top element receives
356 * additional class 'loading'. It is removed when response from server is received.
357 *
358 * When any of the input fields is changed, the top element receives class 'fp-changed';
359 * When current file can be set as main - top element receives class 'fp-cansetmain';
360 * When current file is folder/zip/file - top element receives respectfully class
361 * 'fp-folder'/'fp-zip'/'fp-file';
362 *
363 * @return string
364 */
365 private function fm_js_template_fileselectlayout() {
9a62f779
MG
366 $strloading = get_string('loading', 'repository');
367 $icon_progress = $this->pix_icon('i/loading_small', $strloading).'';
420e7bb2
BR
368 $rv = '
369<div class="filemanager fp-select">
370 <div class="fp-select-loading">
a2c2ab3e 371 <img src="'.$this->pix_url('i/loading_small').'" />
420e7bb2
BR
372 </div>
373 <form>
af9c48cb
BR
374 <button class="{!}fp-file-download">'.get_string('download').'</button>
375 <button class="{!}fp-file-delete">'.get_string('delete').'</button>
376 <button class="{!}fp-file-setmain">'.get_string('setmainfile', 'repository').'</button>
377 <button class="{!}fp-file-zip">'.get_string('zip', 'editor').'</button>
378 <button class="{!}fp-file-unzip">'.get_string('unzip').'</button>
420e7bb2
BR
379 <div class="fp-hr"></div>
380 <table>
381 <tr class="{!}fp-saveas"><td class="mdl-right"><label>'.get_string('name', 'moodle').'</label>:</td>
382 <td class="mdl-left"><input type="text"/></td></tr>
383 <tr class="{!}fp-author"><td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td>
6077e381 384 <td class="mdl-left"><input type="text"/></td></tr>
420e7bb2
BR
385 <tr class="{!}fp-license"><td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td>
386 <td class="mdl-left"><select></select></td></tr>
387 <tr class="{!}fp-path"><td class="mdl-right"><label>'.get_string('path', 'moodle').'</label>:</td>
388 <td class="mdl-left"><select></select></td></tr>
389 <tr class="{!}fp-original"><td class="mdl-right"><label>'.get_string('original', 'repository').'</label>:</td>
6077e381 390 <td class="mdl-left"><span class="fp-originloading">'.$icon_progress.' '.$strloading.'</span><span class="fp-value"></span></td></tr>
9dbdf31f 391 <tr class="{!}fp-reflist"><td class="mdl-right"><label>'.get_string('referenceslist', 'repository').'</label>:</td>
6077e381 392 <td class="mdl-left"><p class="{!}fp-refcount"></p><span class="fp-reflistloading">'.$icon_progress.' '.$strloading.'</span><ul class="fp-value"></ul></td></tr>
420e7bb2 393 </table>
af9c48cb
BR
394 <div class="fp-select-buttons">
395 <button class="{!}fp-file-update">'.get_string('update', 'moodle').'</button>
396 <button class="{!}fp-file-cancel">'.get_string('cancel').'</button>
397 </div>
4214bc63 398 </form>
af9c48cb
BR
399 <div class="fp-info">
400 <div class="fp-hr"></div>
401 <p class="{!}fp-thumbnail"></p>
402 <div class="fp-fileinfo">
403 <div class="{!}fp-datemodified">'.get_string('lastmodified', 'moodle').': <span class="fp-value"></span></div>
404 <div class="{!}fp-datecreated">'.get_string('datecreated', 'repository').': <span class="fp-value"></span></div>
405 <div class="{!}fp-size">'.get_string('size', 'repository').': <span class="fp-value"></span></div>
406 <div class="{!}fp-dimensions">'.get_string('dimensions', 'repository').': <span class="fp-value"></span></div>
407 </div>
420e7bb2 408 </div>
e709ddd2
MG
409</div>';
410 return preg_replace('/\{\!\}/', '', $rv);
411 }
412
9a62f779
MG
413 /**
414 * FileManager JS template for popup confirm dialogue window.
415 *
416 * Must have one top element, CSS for this element must define width and height of the window;
417 *
418 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
419 * elements with classes 'fp-dlg-butconfirm' and 'fp-dlg-butcancel' will
420 * hold onclick events;
421 *
422 * @return string
423 */
424 private function fm_js_template_confirmdialog() {
420e7bb2
BR
425 $rv = '
426<div class="filemanager fp-dlg">
427 <div class="{!}fp-dlg-text"></div>
13429b95 428 <button class="{!}fp-dlg-butconfirm">'.get_string('ok').'</button>
af9c48cb 429 <button class="{!}fp-dlg-butcancel">'.get_string('cancel').'</button>
9a62f779
MG
430</div>';
431 return preg_replace('/\{\!\}/', '', $rv);
432 }
433
e709ddd2
MG
434 /**
435 * Returns all FileManager JavaScript templates as an array.
436 *
437 * @return array
438 */
439 public function filemanager_js_templates() {
440 $class_methods = get_class_methods($this);
441 $templates = array();
442 foreach ($class_methods as $method_name) {
443 if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches))
444 $templates[$matches[1]] = $this->$method_name();
445 }
446 return $templates;
906e7d89
MG
447 }
448
449 /**
450 * Displays restrictions for the file manager
451 *
452 * @param form_filemanager $fm
453 * @return string
454 */
d1d18691 455 private function fm_print_restrictions($fm) {
906e7d89 456 $maxbytes = display_size($fm->options->maxbytes);
789c8b81 457 if (empty($fm->options->maxfiles) || $fm->options->maxfiles == -1) {
906e7d89 458 $maxsize = get_string('maxfilesize', 'moodle', $maxbytes);
906e7d89 459 } else {
789c8b81 460 $strparam = (object)array('size' => $maxbytes, 'attachments' => $fm->options->maxfiles);
906e7d89 461 $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam);
906e7d89
MG
462 }
463 // TODO MDL-32020 also should say about 'File types accepted'
464 return '<span>'. $maxsize. '</span>';
465 }
64f93798 466
d1d18691
MG
467 /**
468 * Template for FilePicker with general layout (not QuickUpload).
469 *
470 * Must have one top element containing everything else (recommended <div class="file-picker">),
471 * CSS for this element must define width and height of the filepicker window. Or CSS must
472 * define min-width, max-width, min-height and max-height and in this case the filepicker
473 * window will be resizeable;
474 *
475 * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode
476 * can be changed or not;
477 * Inside element with class 'fp-viewbar' there are expected elements with classes
478 * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch
479 * between the view modes, the last clicked element will have the class 'checked';
480 *
481 * Element with class 'fp-repo' is a template for displaying one repository. Other repositories
482 * will be attached as siblings (classes first/last/even/odd will be added respectfully).
483 * The currently selected repostory will have class 'active'. Contents of element with class
484 * 'fp-repo-name' will be replaced with repository name, source of image with class
485 * 'fp-repo-icon' will be replaced with repository icon;
486 *
487 * Element with class 'fp-content' is obligatory and will hold the current contents;
488 *
489 * Element with class 'fp-paging' will contain page navigation (will be deprecated soon);
490 *
e709ddd2 491 * Element with class 'fp-path-folder' is a template for one folder in path toolbar.
d1d18691 492 * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
d1d18691 493 * Parent element will receive class 'empty' when there are no folders to be displayed;
e709ddd2 494 * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
d1d18691
MG
495 *
496 * Element with class 'fp-toolbar' will have class 'empty' if all 'Back', 'Search', 'Refresh',
497 * 'Logout', 'Manage' and 'Help' are unavailable for this repo;
498 *
499 * Inside fp-toolbar there are expected elements with classes fp-tb-back, fp-tb-search,
500 * fp-tb-refresh, fp-tb-logout, fp-tb-manage and fp-tb-help. Each of them will have
501 * class 'enabled' or 'disabled' if particular repository has this functionality.
502 * Element with class 'fp-tb-search' must contain empty form inside, it's contents will
503 * be substituted with the search form returned by repository (in the most cases it
504 * is generated with template core_repository_renderer::repository_default_searchform);
505 * Other elements must have either <a> or <button> element inside, it will hold onclick
506 * event for corresponding action; labels for fp-tb-back and fp-tb-logout may be
507 * replaced with those specified by repository;
508 *
509 * @return string
510 */
511 private function fp_js_template_generallayout() {
512 $rv = '
513<div class="file-picker fp-generallayout">
e88d5641
BR
514 <div class="fp-repo-area">
515 <ul class="fp-list">
6077e381 516 <li class="{!}fp-repo"><a href="#"><img class="{!}fp-repo-icon" width="16" height="16" />&nbsp;<span class="{!}fp-repo-name"></span></a></li>
e88d5641 517 </ul>
d1d18691 518 </div>
e88d5641 519 <div class="fp-repo-items">
0f0d10c5 520 <div class="fp-navbar">
420e7bb2 521 <div>
420e7bb2
BR
522 <div class="{!}fp-toolbar">
523 <div class="{!}fp-tb-back"><a href="#">'.get_string('back', 'repository').'</a></div>
6077e381 524 <div class="{!}fp-tb-search"><form></form></div>
420e7bb2
BR
525 <div class="{!}fp-tb-refresh"><a href="#"><img src="'.$this->pix_url('a/refresh').'" /></a></div>
526 <div class="{!}fp-tb-logout"><img src="'.$this->pix_url('a/logout').'" /><a href="#"></a></div>
527 <div class="{!}fp-tb-manage"><a href="#"><img src="'.$this->pix_url('a/setting').'" /> '.get_string('manageurl', 'repository').'</a></div>
528 <div class="{!}fp-tb-help"><a href="#"><img src="'.$this->pix_url('a/help').'" /> '.get_string('help').'</a></div>
cd029574 529 <div class="{!}fp-tb-message"></div>
420e7bb2 530 </div>
b4562710
BR
531 <div class="{!}fp-viewbar">
532 <a class="{!}fp-vb-icons" href="#"></a>
533 <a class="{!}fp-vb-details" href="#"></a>
534 <a class="{!}fp-vb-tree" href="#"></a>
535 </div>
6077e381 536 <div class="fp-clear-left"></div>
e88d5641
BR
537 </div>
538 <div class="fp-pathbar">
0f0d10c5
BR
539 <span class="{!}fp-path-folder"><a class="{!}fp-path-folder-name" href="#"></a></span>
540 </div>
d1d18691 541 </div>
e88d5641 542 <div class="{!}fp-content"></div>
d1d18691 543 </div>
d1d18691
MG
544</div>';
545 return preg_replace('/\{\!\}/', '', $rv);
546 }
547
548 /**
e709ddd2 549 * FilePicker JS template for displaying one file in 'icon view' mode.
d1d18691
MG
550 *
551 * the element with class 'fp-thumbnail' will be resized to the repository thumbnail size
552 * (both width and height, unless min-width and/or min-height is set in CSS) and the content of
553 * an element will be replaced with an appropriate img;
554 *
555 * the width of element with class 'fp-filename' will be set to the repository thumbnail width
556 * (unless min-width is set in css) and the content of an element will be replaced with filename
557 * supplied by repository;
558 *
e709ddd2
MG
559 * top element(s) will have class fp-folder if the element is a folder;
560 *
561 * List of files will have parent <div> element with class 'fp-iconview'
562 *
d1d18691
MG
563 * @return string
564 */
e709ddd2 565 private function fp_js_template_iconfilename() {
420e7bb2
BR
566 $rv = '
567<a class="fp-file" href="#" >
1778f310
MG
568 <div style="position:relative;">
569 <div class="{!}fp-thumbnail"></div>
570 <div class="fp-reficons1"></div>
571 <div class="fp-reficons2"></div>
572 </div>
0f0d10c5
BR
573 <div class="fp-filename-field">
574 <p class="{!}fp-filename"></p>
575 </div>
e88d5641 576</a>';
d1d18691
MG
577 return preg_replace('/\{\!\}/', '', $rv);
578 }
579
580 /**
581 * FilePicker JS template for displaying file name in 'table view' and 'tree view' modes.
582 *
583 * content of the element with class 'fp-icon' will be replaced with an appropriate img;
584 *
585 * content of element with class 'fp-filename' will be replaced with filename supplied by
586 * repository;
587 *
e709ddd2
MG
588 * top element(s) will have class fp-folder if the element is a folder;
589 *
d1d18691
MG
590 * Note that tree view and table view are the YUI widgets and therefore there are no
591 * other templates. The widgets will be wrapped in <div> with class fp-treeview or
592 * fp-tableview (respectfully).
593 *
594 * @return string
595 */
596 private function fp_js_template_listfilename() {
a9352f1f
BR
597 $rv = '
598<span class="fp-filename-icon">
599 <a href="#">
600 <span class="{!}fp-icon"></span>
601 <span class="{!}fp-filename"></span>
602 </a>
603</span>';
d1d18691
MG
604 return preg_replace('/\{\!\}/', '', $rv);
605 }
606
607 /**
608 * FilePicker JS template for displaying link/loading progress for fetching of the next page
609 *
610 * This text is added to .fp-content AFTER .fp-iconview/.fp-treeview/.fp-tableview
611 *
612 * Must have one parent element with class 'fp-nextpage'. It will be assigned additional
613 * class 'loading' during loading of the next page (it is recommended that in this case the link
614 * becomes unavailable). Also must contain one element <a> or <button> that will hold
615 * onclick event for displaying of the next page. The event will be triggered automatically
616 * when user scrolls to this link.
617 *
618 * @return string
619 */
620 private function fp_js_template_nextpage() {
420e7bb2
BR
621 $rv = '
622<div class="{!}fp-nextpage">
623 <div class="fp-nextpage-link"><a href="#">'.get_string('more').'</a></div>
624 <div class="fp-nextpage-loading">
a2c2ab3e 625 <img src="'.$this->pix_url('i/loading_small').'" />
420e7bb2 626 </div>
d1d18691
MG
627</div>';
628 return preg_replace('/\{\!\}/', '', $rv);
629 }
630
631 /**
e709ddd2 632 * FilePicker JS template for window appearing to select a file.
d1d18691 633 *
55089a9d
MG
634 * All content must be enclosed in one element, CSS for this class must define width and
635 * height of the window;
d1d18691
MG
636 *
637 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
638 *
639 * Inside the window the elements with the following classnames must be present:
55089a9d
MG
640 * 'fp-saveas', 'fp-linktype-2', 'fp-linktype-1', 'fp-linktype-4', 'fp-setauthor',
641 * 'fp-setlicense'. Inside each of them must have one input element (or select in case of
642 * fp-setlicense). They may also have labels.
d1d18691
MG
643 * The elements will be assign with class 'uneditable' and input/select element will become
644 * disabled if they are not applicable for the particular file;
645 *
646 * There may be present elements with classes 'fp-datemodified', 'fp-datecreated', 'fp-size',
e709ddd2
MG
647 * 'fp-license', 'fp-author', 'fp-dimensions'. They will receive additional class 'fp-unknown'
648 * if information is unavailable. If there is information available, the content of embedded
649 * element with class 'fp-value' will be substituted with the value;
d1d18691
MG
650 *
651 * Elements with classes 'fp-select-confirm' and 'fp-select-cancel' will hold corresponding
652 * onclick events;
653 *
654 * When confirm button is pressed and file is being selected, the top element receives
655 * additional class 'loading'. It is removed when response from server is received.
656 *
657 * @return string
658 */
659 private function fp_js_template_selectlayout() {
420e7bb2
BR
660 $rv = '
661<div class="file-picker fp-select">
662 <div class="fp-select-loading">
a2c2ab3e 663 <img src="'.$this->pix_url('i/loading_small').'" />
420e7bb2
BR
664 </div>
665 <form>
420e7bb2 666 <table>
420e7bb2 667 <tr class="{!}fp-linktype-2">
a2c2ab3e 668 <td class="mdl-right"></td>
0f0d10c5 669 <td class="mdl-left"><input type="radio"/><label>&nbsp;'.get_string('makefileinternal', 'repository').'</label></td></tr>
420e7bb2 670 <tr class="{!}fp-linktype-1">
a2c2ab3e 671 <td class="mdl-right"></td>
0f0d10c5 672 <td class="mdl-left"><input type="radio"/><label>&nbsp;'.get_string('makefilelink', 'repository').'</label></td></tr>
420e7bb2 673 <tr class="{!}fp-linktype-4">
a2c2ab3e 674 <td class="mdl-right"></td>
0f0d10c5 675 <td class="mdl-left"><input type="radio"/><label>&nbsp;'.get_string('makefilereference', 'repository').'</label></td></tr>
420e7bb2
BR
676 <tr class="{!}fp-saveas">
677 <td class="mdl-right"><label>'.get_string('saveas', 'repository').'</label>:</td>
678 <td class="mdl-left"><input type="text"/></td></tr>
679 <tr class="{!}fp-setauthor">
680 <td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td>
681 <td class="mdl-left"><input type="text" /></td></tr>
682 <tr class="{!}fp-setlicense">
683 <td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td>
684 <td class="mdl-left"><select></select></td></tr>
685 </table>
af9c48cb
BR
686 <div class="fp-select-buttons">
687 <button class="{!}fp-select-confirm">'.get_string('getfile', 'repository').'</button>
688 <button class="{!}fp-select-cancel">'.get_string('cancel').'</button>
689 </div>
420e7bb2 690 </form>
af9c48cb
BR
691 <div class="fp-info">
692 <div class="fp-hr"></div>
693 <p class="{!}fp-thumbnail"></p>
694 <div class="fp-fileinfo">
695 <div class="{!}fp-datemodified">'.get_string('lastmodified', 'moodle').': <span class="fp-value"></span></div>
696 <div class="{!}fp-datecreated">'.get_string('datecreated', 'repository').': <span class="fp-value"></span></div>
697 <div class="{!}fp-size">'.get_string('size', 'repository').': <span class="fp-value"></span></div>
698 <div class="{!}fp-license">'.get_string('license', 'moodle').': <span class="fp-value"></span></div>
699 <div class="{!}fp-author">'.get_string('author', 'repository').': <span class="fp-value"></span></div>
700 <div class="{!}fp-dimensions">'.get_string('dimensions', 'repository').': <span class="fp-value"></span></div>
701 </div>
702 <div>
d1d18691
MG
703</div>';
704 return preg_replace('/\{\!\}/', '', $rv);
705 }
706
707 /**
708 * FilePicker JS template for 'Upload file' repository
709 *
710 * Content to display when user chooses 'Upload file' repository (will be nested inside
711 * element with class 'fp-content').
712 *
713 * Must contain form (enctype="multipart/form-data" method="POST")
714 *
715 * The elements with the following classnames must be present:
716 * 'fp-file', 'fp-saveas', 'fp-setauthor', 'fp-setlicense'. Inside each of them must have
717 * one input element (or select in case of fp-setlicense). They may also have labels.
718 *
719 * Element with class 'fp-upload-btn' will hold onclick event for uploading the file;
720 *
721 * Please note that some fields may be hidden using CSS if this is part of quickupload form
722 *
723 * @return string
724 */
725 private function fp_js_template_uploadform() {
420e7bb2
BR
726 $rv = '
727<div class="fp-upload-form mdl-align">
0f0d10c5 728 <div class="fp-content-center">
420e7bb2
BR
729 <form enctype="multipart/form-data" method="POST">
730 <table >
731 <tr class="{!}fp-file">
732 <td class="mdl-right"><label>'.get_string('attachment', 'repository').'</label>:</td>
733 <td class="mdl-left"><input type="file"/></td></tr>
734 <tr class="{!}fp-saveas">
735 <td class="mdl-right"><label>'.get_string('saveas', 'repository').'</label>:</td>
736 <td class="mdl-left"><input type="text"/></td></tr>
737 <tr class="{!}fp-setauthor">
738 <td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td>
739 <td class="mdl-left"><input type="text"/></td></tr>
740 <tr class="{!}fp-setlicense">
741 <td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td>
6077e381 742 <td class="mdl-left"><select></select></td></tr>
420e7bb2
BR
743 </table>
744 </form>
745 <div><button class="{!}fp-upload-btn">'.get_string('upload', 'repository').'</button></div>
746 </div>
d1d18691
MG
747</div> ';
748 return preg_replace('/\{\!\}/', '', $rv);
749 }
750
751 /**
752 * FilePicker JS template to display during loading process (inside element with class 'fp-content').
753 *
754 * @return string
755 */
756 private function fp_js_template_loading() {
420e7bb2 757 return '
0f0d10c5
BR
758<div class="fp-content-loading">
759 <div class="fp-content-center">
a2c2ab3e 760 <img src="'.$this->pix_url('i/loading_small').'" />
0f0d10c5 761 </div>
d1d18691
MG
762</div>';
763 }
764
765 /**
766 * FilePicker JS template for error (inside element with class 'fp-content').
767 *
768 * must have element with class 'fp-error', its content will be replaced with error text
769 * and the error code will be assigned as additional class to this element
770 * used errors: invalidjson, nofilesavailable, norepositoriesavailable
771 *
772 * @return string
773 */
774 private function fp_js_template_error() {
420e7bb2 775 $rv = '
6077e381 776<div class="fp-content-error" ><div class="{!}fp-error"></div></div>';
d1d18691
MG
777 return preg_replace('/\{\!\}/', '', $rv);
778 }
779
780 /**
781 * FilePicker JS template for error/info message displayed as a separate popup window.
782 *
9a62f779 783 * Must be wrapped in one element, CSS for this element must define
d1d18691
MG
784 * width and height of the window. It will be assigned with an additional class 'fp-msg-error'
785 * or 'fp-msg-info' depending on message type;
786 *
787 * content of element with class 'fp-msg-text' will be replaced with error/info text;
788 *
789 * element with class 'fp-msg-butok' will hold onclick event
790 *
791 * @return string
792 */
793 private function fp_js_template_message() {
420e7bb2
BR
794 $rv = '
795<div class="file-picker fp-msg">
796 <p class="{!}fp-msg-text"></p>
af9c48cb 797 <button class="{!}fp-msg-butok">'.get_string('ok').'</button>
420e7bb2 798</div>';
d1d18691
MG
799 return preg_replace('/\{\!\}/', '', $rv);
800 }
801
802 /**
803 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists.
804 *
9a62f779 805 * Must have one top element, CSS for this element must define width and height of the window;
d1d18691
MG
806 *
807 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
d0b2d445
DS
808 * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename',
809 * 'fp-dlg-butoverwriteall', 'fp-dlg-butrenameall' and 'fp-dlg-butcancel' will
d1d18691
MG
810 * hold onclick events;
811 *
812 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
813 * (Note that it may have long text)
814 *
815 * @return string
816 */
817 private function fp_js_template_processexistingfile() {
420e7bb2
BR
818 $rv = '
819<div class="file-picker fp-dlg">
820 <p class="{!}fp-dlg-text"></p>
af9c48cb
BR
821 <div class="fp-dlg-buttons">
822 <button class="{!}fp-dlg-butoverwrite">'.get_string('overwrite', 'repository').'</button>
823 <button class="{!}fp-dlg-butrename"></button>
824 <button class="{!}fp-dlg-butcancel">'.get_string('cancel').'</button>
825 </div>
d1d18691
MG
826</div>';
827 return preg_replace('/\{\!\}/', '', $rv);
828 }
0f0d10c5 829
d0b2d445
DS
830 /**
831 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists (multiple-file version).
832 *
833 * Must have one top element, CSS for this element must define width and height of the window;
834 *
835 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
836 * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename' and 'fp-dlg-butcancel' will
837 * hold onclick events;
838 *
839 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
840 * (Note that it may have long text)
841 *
842 * @return string
843 */
844 private function fp_js_template_processexistingfilemultiple() {
845 $rv = '
846<div class="file-picker fp-dlg">
847 <p class="{!}fp-dlg-text"></p>
848 <a class="{!}fp-dlg-butoverwrite fp-panel-button" href="#">'.get_string('overwrite', 'repository').'</a>
d0b2d445
DS
849 <a class="{!}fp-dlg-butcancel fp-panel-button" href="#">'.get_string('cancel').'</a>
850 <a class="{!}fp-dlg-butrename fp-panel-button" href="#"></a>
b8a22d22
DS
851 <br/>
852 <a class="{!}fp-dlg-butoverwriteall fp-panel-button" href="#">'.get_string('overwriteall', 'repository').'</a>
d0b2d445
DS
853 <a class="{!}fp-dlg-butrenameall fp-panel-button" href="#">'.get_string('renameall', 'repository').'</a>
854</div>';
855 return preg_replace('/\{\!\}/', '', $rv);
856 }
857
d1d18691
MG
858 /**
859 * FilePicker JS template for repository login form including templates for each element type
860 *
861 * Must contain one <form> element with templates for different input types inside:
862 * Elements with classes 'fp-login-popup', 'fp-login-textarea', 'fp-login-select' and
863 * 'fp-login-input' are templates for displaying respective login form elements. Inside
864 * there must be exactly one element with type <button>, <textarea>, <select> or <input>
865 * (i.e. fp-login-popup should have <button>, fp-login-textarea should have <textarea>, etc.);
866 * They may also contain the <label> element and it's content will be substituted with
867 * label;
868 *
869 * You can also define elements with classes 'fp-login-checkbox', 'fp-login-text'
870 * but if they are not found, 'fp-login-input' will be used;
871 *
872 * Element with class 'fp-login-radiogroup' will be used for group of radio inputs. Inside
873 * it should hava a template for one radio input (with class 'fp-login-radio');
874 *
875 * Element with class 'fp-login-submit' will hold on click mouse event (form submission). It
876 * will be removed if at least one popup element is present;
877 *
878 * @return string
879 */
880 private function fp_js_template_loginform() {
881 $rv = '
882<div class="fp-login-form">
420e7bb2
BR
883 <div class="fp-content-center">
884 <form>
885 <table >
886 <tr class="{!}fp-login-popup">
887 <td colspan="2">
888 <label>'.get_string('popup', 'repository').'</label>
889 <p class="fp-popup"><button class="{!}fp-login-popup-but">'.get_string('login', 'repository').'</button></p></td></tr>
890 <tr class="{!}fp-login-textarea">
891 <td colspan="2"><p><textarea></textarea></p></td></tr>
892 <tr class="{!}fp-login-select">
893 <td align="right"><label></label></td>
894 <td align="left"><select></select></td></tr>
895 <tr class="{!}fp-login-input">
6077e381 896 <td class="label"><label></label></td>
420e7bb2
BR
897 <td class="input"><input/></td></tr>
898 <tr class="{!}fp-login-radiogroup">
6077e381
BR
899 <td align="right" width="30%" valign="top"><label></label></td>
900 <td align="left" valign="top"><p class="{!}fp-login-radio"><input /> <label></label></p></td></tr>
420e7bb2
BR
901 </table>
902 <p><button class="{!}fp-login-submit">'.get_string('submit', 'repository').'</button></p>
903 </form>
904 </div>
d1d18691
MG
905</div>';
906 return preg_replace('/\{\!\}/', '', $rv);
907 }
908
909 /**
910 * Returns all FilePicker JavaScript templates as an array.
911 *
912 * @return array
913 */
914 public function filepicker_js_templates() {
915 $class_methods = get_class_methods($this);
916 $templates = array();
917 foreach ($class_methods as $method_name) {
918 if (preg_match('/^fp_js_template_(.*)$/', $method_name, $matches))
919 $templates[$matches[1]] = $this->$method_name();
920 }
921 return $templates;
922 }
923
924 /**
925 * Returns HTML for default repository searchform to be passed to Filepicker
926 *
927 * This will be used as contents for search form defined in generallayout template
928 * (form with id {TOOLSEARCHID}).
929 * Default contents is one text input field with name="s"
930 */
931 public function repository_default_searchform() {
7c3e6652 932 $str = '<div class="fp-def-search"><input name="s" value='.get_string('search', 'repository').' /></div>';
d1d18691
MG
933 return $str;
934 }
935}
64f93798
PS
936
937/**
938 * Data structure representing a general moodle file tree viewer
939 *
940 * @copyright 2010 Dongsheng Cai
941 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
942 * @since Moodle 2.0
943 */
944class files_tree_viewer implements renderable {
945 public $tree;
946 public $path;
e921afa8 947 public $context;
64f93798
PS
948
949 /**
950 * Constructor of moodle_file_tree_viewer class
951 * @param file_info $file_info
952 * @param array $options
953 */
954 public function __construct(file_info $file_info, array $options = null) {
955 global $CFG;
956
957 //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
64f93798 958 $this->options = (array)$options;
e921afa8
DC
959 $this->context = $options['context'];
960
64f93798
PS
961 $this->tree = array();
962 $children = $file_info->get_children();
0b259d91 963 $current_file_params = $file_info->get_params();
64f93798 964 $parent_info = $file_info->get_parent();
64f93798
PS
965 $level = $parent_info;
966 $this->path = array();
967 while ($level) {
968 $params = $level->get_params();
969 $context = get_context_instance_by_id($params['contextid']);
0b259d91
DC
970 // $this->context is current context
971 if ($context->id != $this->context->id or empty($params['filearea'])) {
64f93798
PS
972 break;
973 }
e921afa8
DC
974 // unset unused parameters
975 unset($params['component']);
976 unset($params['filearea']);
0b259d91 977 unset($params['filename']);
e921afa8 978 unset($params['itemid']);
64f93798 979 $url = new moodle_url('/files/index.php', $params);
e921afa8 980 $this->path[] = html_writer::link($url, $level->get_visible_name());
64f93798
PS
981 $level = $level->get_parent();
982 }
983 $this->path = array_reverse($this->path);
0b259d91
DC
984 if ($current_file_params['filepath'] != '/') {
985 $this->path[] = $file_info->get_visible_name();
986 }
64f93798
PS
987
988 foreach ($children as $child) {
989 $filedate = $child->get_timemodified();
990 $filesize = $child->get_filesize();
991 $mimetype = $child->get_mimetype();
992 $params = $child->get_params();
0b259d91
DC
993 unset($params['component']);
994 unset($params['filearea']);
995 unset($params['filename']);
996 unset($params['itemid']);
64f93798
PS
997 $fileitem = array(
998 'params' => $params,
999 'filename' => $child->get_visible_name(),
559276b1
MG
1000 'mimetype' => $child->get_mimetype(),
1001 'filedate' => $filedate ? $filedate : '',
1002 'filesize' => $filesize ? $filesize : ''
64f93798 1003 );
e921afa8 1004 $url = new moodle_url('/files/index.php', $params);
64f93798
PS
1005 if ($child->is_directory()) {
1006 $fileitem['isdir'] = true;
1007 $fileitem['url'] = $url->out(false);
64f93798
PS
1008 } else {
1009 $fileitem['url'] = $child->get_url();
1010 }
1011 $this->tree[] = $fileitem;
1012 }
1013 }
1014}