2 ///////////////////////////////////////////////////////////////////////////
4 // This file is part of Moodle - http://moodle.org/ //
5 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
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. //
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. //
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/>. //
20 ///////////////////////////////////////////////////////////////////////////
22 defined('MOODLE_INTERNAL') ||
die();
25 * Rendering of files viewer related widgets.
28 * @copyright 2010 Dongsheng Cai
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 * @copyright 2010 Dongsheng Cai
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class core_files_renderer
extends plugin_renderer_base
{
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);
47 public function render_files_tree_viewer(files_tree_viewer
$tree) {
48 $html = $this->output
->heading_with_help(get_string('coursefiles'), 'courselegacyfiles', 'moodle');
50 $html .= $this->output
->container_start('coursefilesbreadcrumb');
51 foreach($tree->path
as $path) {
55 $html .= $this->output
->container_end();
57 $html .= $this->output
->box_start();
58 $table = new html_table();
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');
61 $table->width
= '100%';
62 $table->data
= array();
64 foreach ($tree->tree
as $file) {
65 $filedate = $filesize = $filetype = '';
66 if ($file['filedate']) {
67 $filedate = userdate($file['filedate'], get_string('strftimedatetimeshort', 'langconfig'));
69 if (empty($file['isdir'])) {
70 if ($file['filesize']) {
71 $filesize = display_size($file['filesize']);
73 $fileicon = file_file_icon($file, 24);
74 $filetype = get_mimetype_description($file);
76 $fileicon = file_folder_icon(24);
78 $table->data
[] = array(
79 html_writer
::link($file['url'], $this->output
->pix_icon($fileicon, get_string('icon')) . ' ' . $file['filename']),
86 $html .= html_writer
::table($table);
87 $html .= $this->output
->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid'=>$tree->context
->id
)), get_string('coursefilesedit'), 'get');
88 $html .= $this->output
->box_end();
93 * Prints the file manager and initializes all necessary libraries
96 * $fm = new form_filemanager($options);
97 * $output = get_renderer('core', 'files');
98 * echo $output->render($fm);
101 * @param form_filemanager $fm File manager to render
102 * @return string HTML fragment
104 public function render_form_filemanager($fm) {
105 static $filemanagertemplateloaded;
106 $html = $this->fm_print_generallayout($fm);
108 'name'=>'form_filemanager',
109 'fullpath'=>'/lib/form/filemanager.js',
110 'requires' => array('moodle-core-notification-dialogue', 'core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'),
112 array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'),
113 array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
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'), array('newfolder', 'repository'), array('edit', 'moodle')
120 if (empty($filemanagertemplateloaded)) {
121 $filemanagertemplateloaded = true;
122 $this->page
->requires
->js_init_call('M.form_filemanager.set_templates',
123 array($this->filemanager_js_templates()), true, $module);
125 $this->page
->requires
->js_init_call('M.form_filemanager.init', array($fm->options
), true, $module);
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>';
137 * Returns html for displaying one file manager
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)
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)
158 * If browser supports Drag-and-drop, the body element will have class 'dndsupported',
159 * otherwise - 'dndnotsupported';
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;
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;
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';
177 * @param form_filemanager $fm
180 private function fm_print_generallayout($fm) {
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');
188 $strdroptoupload = get_string('droptoupload', 'moodle');
189 $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
190 $restrictions = $this->fm_print_restrictions($fm);
191 $strdndnotsupported = get_string('dndnotsupported_insentence', 'moodle').$OUTPUT->help_icon('dndnotsupported');
192 $strdndenabledinbox = get_string('dndenabled_inbox', 'moodle');
193 $loading = get_string('loading', 'repository');
196 <div id="filemanager-'.$client_id.'" class="filemanager fm-loading">
197 <div class="fp-restrictions">
199 <span class="dnduploadnotsupported-message"> - '.$strdndnotsupported.' </span>
201 <div class="fp-navbar">
202 <div class="filemanager-toolbar">
203 <div class="fp-toolbar">
204 <div class="{!}fp-btn-add"><a role="button" href="#"><img src="'.$this->pix_url('a/add_file').'" alt="'.$straddfile.'" /></a></div>
205 <div class="{!}fp-btn-mkdir"><a role="button" href="#"><img src="'.$this->pix_url('a/create_folder').'" alt="'.$strmakedir.'" /></a></div>
206 <div class="{!}fp-btn-download"><a role="button" href="#"><img src="'.$this->pix_url('a/download_all').'" alt="'.$strdownload.'" /></a></div>
208 <div class="{!}fp-viewbar">
209 <a title="'. get_string('displayicons', 'repository') .'" class="{!}fp-vb-icons" href="#"><img alt="" src="'. $this->pix_url('fp/view_icon_active', 'theme') .'" /></a>
210 <a title="'. get_string('displaydetails', 'repository') .'" class="{!}fp-vb-details" href="#"><img alt="" src="'. $this->pix_url('fp/view_list_active', 'theme') .'" /></a>
211 <a title="'. get_string('displaytree', 'repository') .'" class="{!}fp-vb-tree" href="#"><img alt="" src="'. $this->pix_url('fp/view_tree_active', 'theme') .'" /></a>
214 <div class="fp-pathbar">
215 <span class="{!}fp-path-folder"><a class="{!}fp-path-folder-name" href="#"></a></span>
218 <div class="filemanager-loading mdl-align">'.$icon_progress.'</div>
219 <div class="filemanager-container" >
220 <div class="fm-content-wrapper">
221 <div class="fp-content"></div>
222 <div class="fm-empty-container">
223 <div class="dndupload-message">'.$strdndenabledinbox.'<br/><div class="dndupload-arrow"></div></div>
225 <div class="dndupload-target">'.$strdroptoupload.'<br/><div class="dndupload-arrow"></div></div>
226 <div class="dndupload-progressbars"></div>
227 <div class="dndupload-uploadinprogress">'.$icon_progress.'</div>
229 <div class="filemanager-updating">'.$icon_progress.'</div>
232 return preg_replace('/\{\!\}/', '', $html);
236 * FileManager JS template for displaying one file in 'icon view' mode.
238 * Except for elements described in fp_js_template_iconfilename, this template may also
239 * contain element with class 'fp-contextmenu'. If context menu is available for this
240 * file, the top element will receive the additional class 'fp-hascontextmenu' and
241 * the element with class 'fp-contextmenu' will hold onclick event for displaying
244 * @see fp_js_template_iconfilename()
247 private function fm_js_template_iconfilename() {
249 <div class="fp-file">
251 <div style="position:relative;">
252 <div class="{!}fp-thumbnail"></div>
253 <div class="fp-reficons1"></div>
254 <div class="fp-reficons2"></div>
256 <div class="fp-filename-field">
257 <div class="{!}fp-filename"></div>
260 <a class="{!}fp-contextmenu" href="#">'.$this->pix_icon('i/menu', 'â–¶').'</a>
262 return preg_replace('/\{\!\}/', '', $rv);
266 * FileManager JS template for displaying file name in 'table view' and 'tree view' modes.
268 * Except for elements described in fp_js_template_listfilename, this template may also
269 * contain element with class 'fp-contextmenu'. If context menu is available for this
270 * file, the top element will receive the additional class 'fp-hascontextmenu' and
271 * the element with class 'fp-contextmenu' will hold onclick event for displaying
274 * @todo MDL-32736 remove onclick="return false;"
275 * @see fp_js_template_listfilename()
278 private function fm_js_template_listfilename() {
280 <span class="fp-filename-icon">
282 <span class="{!}fp-icon"></span>
283 <span class="fp-reficons1"></span>
284 <span class="fp-reficons2"></span>
285 <span class="{!}fp-filename"></span>
287 <a class="{!}fp-contextmenu" href="#" onclick="return false;">'.$this->pix_icon('i/menu', 'â–¶').'</a>
289 return preg_replace('/\{\!\}/', '', $rv);
293 * FileManager JS template for displaying 'Make new folder' dialog.
295 * Must be wrapped in an element, CSS for this element must define width and height of the window;
297 * Must have one input element with type="text" (for users to enter the new folder name);
299 * content of element with class 'fp-dlg-curpath' will be replaced with current path where
300 * new folder is about to be created;
301 * elements with classes 'fp-dlg-butcreate' and 'fp-dlg-butcancel' will hold onclick events;
305 private function fm_js_template_mkdir() {
307 <div class="filemanager fp-mkdir-dlg" role="dialog" aria-live="assertive" aria-labelledby="fp-mkdir-dlg-title">
308 <div class="fp-mkdir-dlg-text">
309 <label id="fp-mkdir-dlg-title">' . get_string('newfoldername', 'repository') . '</label><br/>
310 <input type="text" />
312 <button class="{!}fp-dlg-butcreate">'.get_string('makeafolder').'</button>
313 <button class="{!}fp-dlg-butcancel">'.get_string('cancel').'</button>
315 return preg_replace('/\{\!\}/', '', $rv);
319 * FileManager JS template for error/info message displayed as a separate popup window.
321 * @see fp_js_template_message()
324 private function fm_js_template_message() {
325 return $this->fp_js_template_message();
329 * FileManager JS template for window with file information/actions.
331 * All content must be enclosed in one element, CSS for this class must define width and
332 * height of the window;
334 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
336 * Inside the window the elements with the following classnames must be present:
337 * 'fp-saveas', 'fp-author', 'fp-license', 'fp-path'. Inside each of them must be
338 * one input element (or select in case of fp-license and fp-path). They may also have labels.
339 * The elements will be assign with class 'uneditable' and input/select element will become
340 * disabled if they are not applicable for the particular file;
342 * There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated',
343 * 'fp-size', 'fp-dimensions', 'fp-reflist'. They will receive additional class 'fp-unknown' if
344 * information is unavailable. If there is information available, the content of embedded
345 * element with class 'fp-value' will be substituted with the value;
347 * The value of Original ('fp-original') is loaded in separate request. When it is applicable
348 * but not yet loaded the 'fp-original' element receives additional class 'fp-loading';
350 * The value of 'Aliases/Shortcuts' ('fp-reflist') is also loaded in separate request. When it
351 * is applicable but not yet loaded the 'fp-original' element receives additional class
352 * 'fp-loading'. The string explaining that XX references exist will replace content of element
353 * 'fp-refcount'. Inside '.fp-reflist .fp-value' each reference will be enclosed in <li>;
355 * Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip',
356 * 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick
357 * events (there may be several elements with class 'fp-file-cancel');
359 * When confirm button is pressed and file is being selected, the top element receives
360 * additional class 'loading'. It is removed when response from server is received.
362 * When any of the input fields is changed, the top element receives class 'fp-changed';
363 * When current file can be set as main - top element receives class 'fp-cansetmain';
364 * When current file is folder/zip/file - top element receives respectfully class
365 * 'fp-folder'/'fp-zip'/'fp-file';
369 private function fm_js_template_fileselectlayout() {
371 $strloading = get_string('loading', 'repository');
372 $icon_progress = $this->pix_icon('i/loading_small', $strloading).'';
374 <div class="filemanager fp-select">
375 <div class="fp-select-loading">
376 <img src="'.$this->pix_url('i/loading_small').'" />
379 <button class="{!}fp-file-download">'.get_string('download').'</button>
380 <button class="{!}fp-file-delete">'.get_string('delete').'</button>
381 <button class="{!}fp-file-setmain">'.get_string('setmainfile', 'repository').'</button><span class="fp-file-setmain-help">'.$OUTPUT->help_icon('setmainfile', 'repository').'</span>
382 <button class="{!}fp-file-zip">'.get_string('zip', 'editor').'</button>
383 <button class="{!}fp-file-unzip">'.get_string('unzip').'</button>
384 <div class="fp-hr"></div>
386 <tr class="{!}fp-saveas"><td class="mdl-right"><label>'.get_string('name', 'moodle').'</label>:</td>
387 <td class="mdl-left"><input type="text"/></td></tr>
388 <tr class="{!}fp-author"><td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td>
389 <td class="mdl-left"><input type="text"/></td></tr>
390 <tr class="{!}fp-license"><td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td>
391 <td class="mdl-left"><select></select></td></tr>
392 <tr class="{!}fp-path"><td class="mdl-right"><label>'.get_string('path', 'moodle').'</label>:</td>
393 <td class="mdl-left"><select></select></td></tr>
394 <tr class="{!}fp-original"><td class="mdl-right"><label>'.get_string('original', 'repository').'</label>:</td>
395 <td class="mdl-left"><span class="fp-originloading">'.$icon_progress.' '.$strloading.'</span><span class="fp-value"></span></td></tr>
396 <tr class="{!}fp-reflist"><td class="mdl-right"><label>'.get_string('referenceslist', 'repository').'</label>:</td>
397 <td class="mdl-left"><p class="{!}fp-refcount"></p><span class="fp-reflistloading">'.$icon_progress.' '.$strloading.'</span><ul class="fp-value"></ul></td></tr>
399 <div class="fp-select-buttons">
400 <button class="{!}fp-file-update">'.get_string('update', 'moodle').'</button>
401 <button class="{!}fp-file-cancel">'.get_string('cancel').'</button>
404 <div class="fp-info clearfix">
405 <div class="fp-hr"></div>
406 <p class="{!}fp-thumbnail"></p>
407 <div class="fp-fileinfo">
408 <div class="{!}fp-datemodified">'.get_string('lastmodified', 'moodle').': <span class="fp-value"></span></div>
409 <div class="{!}fp-datecreated">'.get_string('datecreated', 'repository').': <span class="fp-value"></span></div>
410 <div class="{!}fp-size">'.get_string('size', 'repository').': <span class="fp-value"></span></div>
411 <div class="{!}fp-dimensions">'.get_string('dimensions', 'repository').': <span class="fp-value"></span></div>
415 return preg_replace('/\{\!\}/', '', $rv);
419 * FileManager JS template for popup confirm dialogue window.
421 * Must have one top element, CSS for this element must define width and height of the window;
423 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
424 * elements with classes 'fp-dlg-butconfirm' and 'fp-dlg-butcancel' will
425 * hold onclick events;
429 private function fm_js_template_confirmdialog() {
431 <div class="filemanager fp-dlg">
432 <div class="{!}fp-dlg-text"></div>
433 <button class="{!}fp-dlg-butconfirm">'.get_string('ok').'</button>
434 <button class="{!}fp-dlg-butcancel">'.get_string('cancel').'</button>
436 return preg_replace('/\{\!\}/', '', $rv);
440 * Returns all FileManager JavaScript templates as an array.
444 public function filemanager_js_templates() {
445 $class_methods = get_class_methods($this);
446 $templates = array();
447 foreach ($class_methods as $method_name) {
448 if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches))
449 $templates[$matches[1]] = $this->$method_name();
455 * Displays restrictions for the file manager
457 * @param form_filemanager $fm
460 private function fm_print_restrictions($fm) {
461 $maxbytes = display_size($fm->options
->maxbytes
);
462 $strparam = (object) array('size' => $maxbytes, 'attachments' => $fm->options
->maxfiles
,
463 'areasize' => display_size($fm->options
->areamaxbytes
));
464 $hasmaxfiles = !empty($fm->options
->maxfiles
) && $fm->options
->maxfiles
> 0;
465 $hasarealimit = !empty($fm->options
->areamaxbytes
) && $fm->options
->areamaxbytes
!= -1;
466 if ($hasmaxfiles && $hasarealimit) {
467 $maxsize = get_string('maxsizeandattachmentsandareasize', 'moodle', $strparam);
468 } else if ($hasmaxfiles) {
469 $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam);
470 } else if ($hasarealimit) {
471 $maxsize = get_string('maxsizeandareasize', 'moodle', $strparam);
473 $maxsize = get_string('maxfilesize', 'moodle', $maxbytes);
475 // TODO MDL-32020 also should say about 'File types accepted'
476 return '<span>'. $maxsize . '</span>';
480 * Template for FilePicker with general layout (not QuickUpload).
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;
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';
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;
499 * Element with class 'fp-content' is obligatory and will hold the current contents;
501 * Element with class 'fp-paging' will contain page navigation (will be deprecated soon);
503 * Element with class 'fp-path-folder' is a template for one folder in path toolbar.
504 * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
505 * Parent element will receive class 'empty' when there are no folders to be displayed;
506 * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
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;
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;
523 private function fp_js_template_generallayout() {
525 <div tabindex="0" class="file-picker fp-generallayout" role="dialog" aria-live="assertive">
526 <div class="fp-repo-area">
528 <li class="{!}fp-repo"><a href="#"><img class="{!}fp-repo-icon" alt=" " width="16" height="16" /> <span class="{!}fp-repo-name"></span></a></li>
531 <div class="fp-repo-items" tabindex="0">
532 <div class="fp-navbar">
534 <div class="{!}fp-toolbar">
535 <div class="{!}fp-tb-back"><a href="#">'.get_string('back', 'repository').'</a></div>
536 <div class="{!}fp-tb-search"><form></form></div>
537 <div class="{!}fp-tb-refresh"><a href="#"><img alt="'. get_string('refresh', 'repository') .'" src="'.$this->pix_url('a/refresh').'" /></a></div>
538 <div class="{!}fp-tb-logout"><a href="#"><img alt="'. get_string('logout', 'repository') .'" src="'.$this->pix_url('a/logout').'" /></a></div>
539 <div class="{!}fp-tb-manage"><a href="#"><img alt="'. get_string('settings', 'repository') .'" src="'.$this->pix_url('a/setting').'" /></a></div>
540 <div class="{!}fp-tb-help"><a href="#"><img alt="'. get_string('help', 'repository') .'" src="'.$this->pix_url('a/help').'" /></a></div>
541 <div class="{!}fp-tb-message"></div>
543 <div class="{!}fp-viewbar">
544 <a title="'. get_string('displayicons', 'repository') .'" class="{!}fp-vb-icons" href="#"><img alt="" src="'. $this->pix_url('fp/view_icon_active', 'theme') .'" /></a>
545 <a title="'. get_string('displaydetails', 'repository') .'" class="{!}fp-vb-details" href="#"><img alt="" src="'. $this->pix_url('fp/view_list_active', 'theme') .'" /></a>
546 <a title="'. get_string('displaytree', 'repository') .'" class="{!}fp-vb-tree" href="#"><img alt="" src="'. $this->pix_url('fp/view_tree_active', 'theme') .'" /></a>
548 <div class="fp-clear-left"></div>
550 <div class="fp-pathbar">
551 <span class="{!}fp-path-folder"><a class="{!}fp-path-folder-name" href="#"></a></span>
554 <div class="{!}fp-content"></div>
557 return preg_replace('/\{\!\}/', '', $rv);
561 * FilePicker JS template for displaying one file in 'icon view' mode.
563 * the element with class 'fp-thumbnail' will be resized to the repository thumbnail size
564 * (both width and height, unless min-width and/or min-height is set in CSS) and the content of
565 * an element will be replaced with an appropriate img;
567 * the width of element with class 'fp-filename' will be set to the repository thumbnail width
568 * (unless min-width is set in css) and the content of an element will be replaced with filename
569 * supplied by repository;
571 * top element(s) will have class fp-folder if the element is a folder;
573 * List of files will have parent <div> element with class 'fp-iconview'
577 private function fp_js_template_iconfilename() {
579 <a class="fp-file" href="#" >
580 <div style="position:relative;">
581 <div class="{!}fp-thumbnail"></div>
582 <div class="fp-reficons1"></div>
583 <div class="fp-reficons2"></div>
585 <div class="fp-filename-field">
586 <p class="{!}fp-filename"></p>
589 return preg_replace('/\{\!\}/', '', $rv);
593 * FilePicker JS template for displaying file name in 'table view' and 'tree view' modes.
595 * content of the element with class 'fp-icon' will be replaced with an appropriate img;
597 * content of element with class 'fp-filename' will be replaced with filename supplied by
600 * top element(s) will have class fp-folder if the element is a folder;
602 * Note that tree view and table view are the YUI widgets and therefore there are no
603 * other templates. The widgets will be wrapped in <div> with class fp-treeview or
604 * fp-tableview (respectfully).
608 private function fp_js_template_listfilename() {
610 <span class="fp-filename-icon">
612 <span class="{!}fp-icon"></span>
613 <span class="{!}fp-filename"></span>
616 return preg_replace('/\{\!\}/', '', $rv);
620 * FilePicker JS template for displaying link/loading progress for fetching of the next page
622 * This text is added to .fp-content AFTER .fp-iconview/.fp-treeview/.fp-tableview
624 * Must have one parent element with class 'fp-nextpage'. It will be assigned additional
625 * class 'loading' during loading of the next page (it is recommended that in this case the link
626 * becomes unavailable). Also must contain one element <a> or <button> that will hold
627 * onclick event for displaying of the next page. The event will be triggered automatically
628 * when user scrolls to this link.
632 private function fp_js_template_nextpage() {
634 <div class="{!}fp-nextpage">
635 <div class="fp-nextpage-link"><a href="#">'.get_string('more').'</a></div>
636 <div class="fp-nextpage-loading">
637 <img src="'.$this->pix_url('i/loading_small').'" />
640 return preg_replace('/\{\!\}/', '', $rv);
644 * FilePicker JS template for window appearing to select a file.
646 * All content must be enclosed in one element, CSS for this class must define width and
647 * height of the window;
649 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
651 * Inside the window the elements with the following classnames must be present:
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.
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;
658 * There may be present elements with classes 'fp-datemodified', 'fp-datecreated', 'fp-size',
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;
663 * Elements with classes 'fp-select-confirm' and 'fp-select-cancel' will hold corresponding
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.
671 private function fp_js_template_selectlayout() {
673 <div class="file-picker fp-select">
674 <div class="fp-select-loading">
675 <img src="'.$this->pix_url('i/loading_small').'" />
679 <tr class="{!}fp-linktype-2">
680 <td class="mdl-right"></td>
681 <td class="mdl-left"><input type="radio"/><label> '.get_string('makefileinternal', 'repository').'</label></td></tr>
682 <tr class="{!}fp-linktype-1">
683 <td class="mdl-right"></td>
684 <td class="mdl-left"><input type="radio"/><label> '.get_string('makefilelink', 'repository').'</label></td></tr>
685 <tr class="{!}fp-linktype-4">
686 <td class="mdl-right"></td>
687 <td class="mdl-left"><input type="radio"/><label> '.get_string('makefilereference', 'repository').'</label></td></tr>
688 <tr class="{!}fp-saveas">
689 <td class="mdl-right"><label>'.get_string('saveas', 'repository').'</label>:</td>
690 <td class="mdl-left"><input type="text"/></td></tr>
691 <tr class="{!}fp-setauthor">
692 <td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td>
693 <td class="mdl-left"><input type="text" /></td></tr>
694 <tr class="{!}fp-setlicense">
695 <td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td>
696 <td class="mdl-left"><select></select></td></tr>
698 <div class="fp-select-buttons">
699 <button class="{!}fp-select-confirm">'.get_string('getfile', 'repository').'</button>
700 <button class="{!}fp-select-cancel">'.get_string('cancel').'</button>
703 <div class="fp-info clearfix">
704 <div class="fp-hr"></div>
705 <p class="{!}fp-thumbnail"></p>
706 <div class="fp-fileinfo">
707 <div class="{!}fp-datemodified">'.get_string('lastmodified', 'moodle').': <span class="fp-value"></span></div>
708 <div class="{!}fp-datecreated">'.get_string('datecreated', 'repository').': <span class="fp-value"></span></div>
709 <div class="{!}fp-size">'.get_string('size', 'repository').': <span class="fp-value"></span></div>
710 <div class="{!}fp-license">'.get_string('license', 'moodle').': <span class="fp-value"></span></div>
711 <div class="{!}fp-author">'.get_string('author', 'repository').': <span class="fp-value"></span></div>
712 <div class="{!}fp-dimensions">'.get_string('dimensions', 'repository').': <span class="fp-value"></span></div>
716 return preg_replace('/\{\!\}/', '', $rv);
720 * FilePicker JS template for 'Upload file' repository
722 * Content to display when user chooses 'Upload file' repository (will be nested inside
723 * element with class 'fp-content').
725 * Must contain form (enctype="multipart/form-data" method="POST")
727 * The elements with the following classnames must be present:
728 * 'fp-file', 'fp-saveas', 'fp-setauthor', 'fp-setlicense'. Inside each of them must have
729 * one input element (or select in case of fp-setlicense). They may also have labels.
731 * Element with class 'fp-upload-btn' will hold onclick event for uploading the file;
733 * Please note that some fields may be hidden using CSS if this is part of quickupload form
737 private function fp_js_template_uploadform() {
739 <div class="fp-upload-form mdl-align">
740 <div class="fp-content-center">
741 <form enctype="multipart/form-data" method="POST">
743 <tr class="{!}fp-file">
744 <td class="mdl-right"><label>'.get_string('attachment', 'repository').'</label>:</td>
745 <td class="mdl-left"><input type="file"/></td></tr>
746 <tr class="{!}fp-saveas">
747 <td class="mdl-right"><label>'.get_string('saveas', 'repository').'</label>:</td>
748 <td class="mdl-left"><input type="text"/></td></tr>
749 <tr class="{!}fp-setauthor">
750 <td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td>
751 <td class="mdl-left"><input type="text"/></td></tr>
752 <tr class="{!}fp-setlicense">
753 <td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td>
754 <td class="mdl-left"><select></select></td></tr>
757 <div><button class="{!}fp-upload-btn">'.get_string('upload', 'repository').'</button></div>
760 return preg_replace('/\{\!\}/', '', $rv);
764 * FilePicker JS template to display during loading process (inside element with class 'fp-content').
768 private function fp_js_template_loading() {
770 <div class="fp-content-loading">
771 <div class="fp-content-center">
772 <img src="'.$this->pix_url('i/loading_small').'" />
778 * FilePicker JS template for error (inside element with class 'fp-content').
780 * must have element with class 'fp-error', its content will be replaced with error text
781 * and the error code will be assigned as additional class to this element
782 * used errors: invalidjson, nofilesavailable, norepositoriesavailable
786 private function fp_js_template_error() {
788 <div class="fp-content-error" ><div class="{!}fp-error"></div></div>';
789 return preg_replace('/\{\!\}/', '', $rv);
793 * FilePicker JS template for error/info message displayed as a separate popup window.
795 * Must be wrapped in one element, CSS for this element must define
796 * width and height of the window. It will be assigned with an additional class 'fp-msg-error'
797 * or 'fp-msg-info' depending on message type;
799 * content of element with class 'fp-msg-text' will be replaced with error/info text;
801 * element with class 'fp-msg-butok' will hold onclick event
805 private function fp_js_template_message() {
807 <div class="file-picker fp-msg" role="alertdialog" aria-live="assertive" aria-labelledby="fp-msg-labelledby">
808 <p class="{!}fp-msg-text" id="fp-msg-labelledby"></p>
809 <button class="{!}fp-msg-butok">'.get_string('ok').'</button>
811 return preg_replace('/\{\!\}/', '', $rv);
815 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists.
817 * Must have one top element, CSS for this element must define width and height of the window;
819 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
820 * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename',
821 * 'fp-dlg-butoverwriteall', 'fp-dlg-butrenameall' and 'fp-dlg-butcancel' will
822 * hold onclick events;
824 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
825 * (Note that it may have long text)
829 private function fp_js_template_processexistingfile() {
831 <div class="file-picker fp-dlg">
832 <p class="{!}fp-dlg-text"></p>
833 <div class="fp-dlg-buttons">
834 <button class="{!}fp-dlg-butoverwrite">'.get_string('overwrite', 'repository').'</button>
835 <button class="{!}fp-dlg-butrename"></button>
836 <button class="{!}fp-dlg-butcancel">'.get_string('cancel').'</button>
839 return preg_replace('/\{\!\}/', '', $rv);
843 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists (multiple-file version).
845 * Must have one top element, CSS for this element must define width and height of the window;
847 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
848 * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename' and 'fp-dlg-butcancel' will
849 * hold onclick events;
851 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
852 * (Note that it may have long text)
856 private function fp_js_template_processexistingfilemultiple() {
858 <div class="file-picker fp-dlg">
859 <p class="{!}fp-dlg-text"></p>
860 <a class="{!}fp-dlg-butoverwrite fp-panel-button" href="#">'.get_string('overwrite', 'repository').'</a>
861 <a class="{!}fp-dlg-butcancel fp-panel-button" href="#">'.get_string('cancel').'</a>
862 <a class="{!}fp-dlg-butrename fp-panel-button" href="#"></a>
864 <a class="{!}fp-dlg-butoverwriteall fp-panel-button" href="#">'.get_string('overwriteall', 'repository').'</a>
865 <a class="{!}fp-dlg-butrenameall fp-panel-button" href="#">'.get_string('renameall', 'repository').'</a>
867 return preg_replace('/\{\!\}/', '', $rv);
871 * FilePicker JS template for repository login form including templates for each element type
873 * Must contain one <form> element with templates for different input types inside:
874 * Elements with classes 'fp-login-popup', 'fp-login-textarea', 'fp-login-select' and
875 * 'fp-login-input' are templates for displaying respective login form elements. Inside
876 * there must be exactly one element with type <button>, <textarea>, <select> or <input>
877 * (i.e. fp-login-popup should have <button>, fp-login-textarea should have <textarea>, etc.);
878 * They may also contain the <label> element and it's content will be substituted with
881 * You can also define elements with classes 'fp-login-checkbox', 'fp-login-text'
882 * but if they are not found, 'fp-login-input' will be used;
884 * Element with class 'fp-login-radiogroup' will be used for group of radio inputs. Inside
885 * it should hava a template for one radio input (with class 'fp-login-radio');
887 * Element with class 'fp-login-submit' will hold on click mouse event (form submission). It
888 * will be removed if at least one popup element is present;
892 private function fp_js_template_loginform() {
894 <div class="fp-login-form">
895 <div class="fp-content-center">
898 <tr class="{!}fp-login-popup">
900 <label>'.get_string('popup', 'repository').'</label>
901 <p class="fp-popup"><button class="{!}fp-login-popup-but">'.get_string('login', 'repository').'</button></p></td></tr>
902 <tr class="{!}fp-login-textarea">
903 <td colspan="2"><p><textarea></textarea></p></td></tr>
904 <tr class="{!}fp-login-select">
905 <td align="right"><label></label></td>
906 <td align="left"><select></select></td></tr>
907 <tr class="{!}fp-login-input">
908 <td class="label"><label></label></td>
909 <td class="input"><input/></td></tr>
910 <tr class="{!}fp-login-radiogroup">
911 <td align="right" width="30%" valign="top"><label></label></td>
912 <td align="left" valign="top"><p class="{!}fp-login-radio"><input /> <label></label></p></td></tr>
914 <p><button class="{!}fp-login-submit">'.get_string('submit', 'repository').'</button></p>
918 return preg_replace('/\{\!\}/', '', $rv);
922 * Returns all FilePicker JavaScript templates as an array.
926 public function filepicker_js_templates() {
927 $class_methods = get_class_methods($this);
928 $templates = array();
929 foreach ($class_methods as $method_name) {
930 if (preg_match('/^fp_js_template_(.*)$/', $method_name, $matches))
931 $templates[$matches[1]] = $this->$method_name();
937 * Returns HTML for default repository searchform to be passed to Filepicker
939 * This will be used as contents for search form defined in generallayout template
940 * (form with id {TOOLSEARCHID}).
941 * Default contents is one text input field with name="s"
943 public function repository_default_searchform() {
944 $searchinput = html_writer
::label(get_string('searchrepo', 'repository'),
945 'reposearch', false, array('class' => 'accesshide'));
946 $searchinput .= html_writer
::empty_tag('input', array('type' => 'text',
947 'id' => 'reposearch', 'name' => 's', 'value' => get_string('search', 'repository')));
948 $str = html_writer
::tag('div', $searchinput, array('class' => "fp-def-search"));
955 * Data structure representing a general moodle file tree viewer
957 * @copyright 2010 Dongsheng Cai
958 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
961 class files_tree_viewer
implements renderable
{
967 * Constructor of moodle_file_tree_viewer class
968 * @param file_info $file_info
969 * @param array $options
971 public function __construct(file_info
$file_info, array $options = null) {
974 //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
975 $this->options
= (array)$options;
976 $this->context
= $options['context'];
978 $this->tree
= array();
979 $children = $file_info->get_children();
980 $current_file_params = $file_info->get_params();
981 $parent_info = $file_info->get_parent();
982 $level = $parent_info;
983 $this->path
= array();
985 $params = $level->get_params();
986 $context = context
::instance_by_id($params['contextid']);
987 // $this->context is current context
988 if ($context->id
!= $this->context
->id
or empty($params['filearea'])) {
991 // unset unused parameters
992 unset($params['component']);
993 unset($params['filearea']);
994 unset($params['filename']);
995 unset($params['itemid']);
996 $url = new moodle_url('/files/index.php', $params);
997 $this->path
[] = html_writer
::link($url, $level->get_visible_name());
998 $level = $level->get_parent();
1000 $this->path
= array_reverse($this->path
);
1001 if ($current_file_params['filepath'] != '/') {
1002 $this->path
[] = $file_info->get_visible_name();
1005 foreach ($children as $child) {
1006 $filedate = $child->get_timemodified();
1007 $filesize = $child->get_filesize();
1008 $mimetype = $child->get_mimetype();
1009 $params = $child->get_params();
1010 unset($params['component']);
1011 unset($params['filearea']);
1012 unset($params['filename']);
1013 unset($params['itemid']);
1015 'params' => $params,
1016 'filename' => $child->get_visible_name(),
1017 'mimetype' => $child->get_mimetype(),
1018 'filedate' => $filedate ?
$filedate : '',
1019 'filesize' => $filesize ?
$filesize : ''
1021 $url = new moodle_url('/files/index.php', $params);
1022 if ($child->is_directory()) {
1023 $fileitem['isdir'] = true;
1024 $fileitem['url'] = $url->out(false);
1026 $fileitem['url'] = $child->get_url();
1028 $this->tree
[] = $fileitem;