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