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 $html = $this->fm_print_generallayout($fm);
107 'name'=>'form_filemanager',
108 'fullpath'=>'/lib/form/filemanager.js',
109 'requires' => array('moodle-core-notification-dialogue', 'core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'),
111 array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'),
112 array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
113 array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'),
114 array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'),
115 array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'),
116 array('confirmrenamefile', 'repository'), array('newfolder', 'repository'), array('edit', 'moodle')
119 if ($this->page
->requires
->should_create_one_time_item_now('core_file_managertemplate')) {
120 $this->page
->requires
->js_init_call('M.form_filemanager.set_templates',
121 array($this->filemanager_js_templates()), true, $module);
123 $this->page
->requires
->js_init_call('M.form_filemanager.init', array($fm->options
), true, $module);
125 // non javascript file manager
126 $html .= '<noscript>';
127 $html .= "<div><object type='text/html' data='".$fm->get_nonjsurl()."' height='160' width='600' style='border:1px solid #000'></object></div>";
128 $html .= '</noscript>';
135 * Returns html for displaying one file manager
137 * The main element in HTML must have id="filemanager-{$client_id}" and
138 * class="filemanager fm-loading";
139 * After all necessary code on the page (both html and javascript) is loaded,
140 * the class fm-loading will be removed and added class fm-loaded;
141 * The main element (class=filemanager) will be assigned the following classes:
142 * 'fm-maxfiles' - when filemanager has maximum allowed number of files;
143 * 'fm-nofiles' - when filemanager has no files at all (although there might be folders);
144 * 'fm-noitems' - when current view (folder) has no items - neither files nor folders;
145 * 'fm-updating' - when current view is being updated (usually means that loading icon is to be displayed);
146 * 'fm-nomkdir' - when 'Make folder' action is unavailable (empty($fm->options->subdirs) == true)
148 * Element with class 'filemanager-container' will be holding evens for dnd upload (dragover, etc.).
149 * It will have class:
150 * 'dndupload-ready' - when a file is being dragged over the browser
151 * 'dndupload-over' - when file is being dragged over this filepicker (additional to 'dndupload-ready')
152 * 'dndupload-uploading' - during the upload process (note that after dnd upload process is
153 * over, the file manager will refresh the files list and therefore will have for a while class
154 * fm-updating. Both waiting processes should look similar so the images don't jump for user)
156 * If browser supports Drag-and-drop, the body element will have class 'dndsupported',
157 * otherwise - 'dndnotsupported';
159 * Element with class 'fp-content' will be populated with files list;
160 * Element with class 'fp-btn-add' will hold onclick event for adding a file (opening filepicker);
161 * Element with class 'fp-btn-mkdir' will hold onclick event for adding new folder;
162 * Element with class 'fp-btn-download' will hold onclick event for download action;
164 * Element with class 'fp-path-folder' is a template for one folder in path toolbar.
165 * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
166 * Parent element will receive class 'empty' when there are no folders to be displayed;
167 * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
169 * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode
170 * can be changed or not;
171 * Inside element with class 'fp-viewbar' there are expected elements with classes
172 * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch
173 * between the view modes, the last clicked element will have the class 'checked';
175 * @param form_filemanager $fm
178 protected function fm_print_generallayout($fm) {
180 $options = $fm->options
;
181 $client_id = $options->client_id
;
182 $straddfile = get_string('addfile', 'repository');
183 $strmakedir = get_string('makeafolder', 'moodle');
184 $strdownload = get_string('downloadfolder', 'repository');
185 $strloading = get_string('loading', 'repository');
186 $strdroptoupload = get_string('droptoupload', 'moodle');
187 $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
188 $restrictions = $this->fm_print_restrictions($fm);
189 $strdndnotsupported = get_string('dndnotsupported_insentence', 'moodle').$OUTPUT->help_icon('dndnotsupported');
190 $strdndenabledinbox = get_string('dndenabled_inbox', 'moodle');
191 $loading = get_string('loading', 'repository');
192 $straddfiletext = get_string('addfiletext', 'repository');
193 $strcreatefolder = get_string('createfolder', 'repository');
194 $strdownloadallfiles = get_string('downloadallfiles', 'repository');
197 <div id="filemanager-'.$client_id.'" class="filemanager fm-loading">
198 <div class="fp-restrictions">
200 <span class="dnduploadnotsupported-message"> - '.$strdndnotsupported.' </span>
202 <div class="fp-navbar">
203 <div class="filemanager-toolbar">
204 <div class="fp-toolbar">
205 <div class="fp-btn-add">
206 <a role="button" title="' . $straddfile . '" href="#">
207 ' . $this->pix_icon('a/add_file', $straddfiletext) . '
210 <div class="fp-btn-mkdir">
211 <a role="button" title="' . $strmakedir . '" href="#">
212 ' . $this->pix_icon('a/create_folder', $strcreatefolder) . '
215 <div class="fp-btn-download">
216 <a role="button" title="' . $strdownload . '" href="#">
217 ' . $this->pix_icon('a/download_all', $strdownloadallfiles) . '
220 <span class="fp-img-downloading">
221 ' . $this->pix_icon('i/loading_small', '') . '
224 <div class="fp-viewbar">
225 <a title="'. get_string('displayicons', 'repository') .'" class="fp-vb-icons" href="#">
226 ' . $this->pix_icon('fp/view_icon_active', get_string('displayasicons', 'repository'), 'theme') . '
228 <a title="'. get_string('displaydetails', 'repository') .'" class="fp-vb-details" href="#">
229 ' . $this->pix_icon('fp/view_list_active', get_string('displayasdetails', 'repository'), 'theme') . '
231 <a title="'. get_string('displaytree', 'repository') .'" class="fp-vb-tree" href="#">
232 ' . $this->pix_icon('fp/view_tree_active', get_string('displayastree', 'repository'), 'theme') . '
236 <div class="fp-pathbar">
237 <span class="fp-path-folder"><a class="fp-path-folder-name" href="#"></a></span>
240 <div class="filemanager-loading mdl-align">'.$icon_progress.'</div>
241 <div class="filemanager-container" >
242 <div class="fm-content-wrapper">
243 <div class="fp-content"></div>
244 <div class="fm-empty-container">
245 <div class="dndupload-message">'.$strdndenabledinbox.'<br/><div class="dndupload-arrow"></div></div>
247 <div class="dndupload-target">'.$strdroptoupload.'<br/><div class="dndupload-arrow"></div></div>
248 <div class="dndupload-progressbars"></div>
249 <div class="dndupload-uploadinprogress">'.$icon_progress.'</div>
251 <div class="filemanager-updating">'.$icon_progress.'</div>
258 * FileManager JS template for displaying one file in 'icon view' mode.
260 * Except for elements described in fp_js_template_iconfilename, this template may also
261 * contain element with class 'fp-contextmenu'. If context menu is available for this
262 * file, the top element will receive the additional class 'fp-hascontextmenu' and
263 * the element with class 'fp-contextmenu' will hold onclick event for displaying
266 * @see fp_js_template_iconfilename()
269 protected function fm_js_template_iconfilename() {
271 <div class="fp-file">
273 <div style="position:relative;">
274 <div class="fp-thumbnail"></div>
275 <div class="fp-reficons1"></div>
276 <div class="fp-reficons2"></div>
278 <div class="fp-filename-field">
279 <div class="fp-filename"></div>
282 <a class="fp-contextmenu" href="#">'.$this->pix_icon('i/menu', 'â–¶').'</a>
288 * FileManager JS template for displaying file name in 'table view' and 'tree view' modes.
290 * Except for elements described in fp_js_template_listfilename, this template may also
291 * contain element with class 'fp-contextmenu'. If context menu is available for this
292 * file, the top element will receive the additional class 'fp-hascontextmenu' and
293 * the element with class 'fp-contextmenu' will hold onclick event for displaying
296 * @todo MDL-32736 remove onclick="return false;"
297 * @see fp_js_template_listfilename()
300 protected function fm_js_template_listfilename() {
302 <span class="fp-filename-icon">
304 <span class="fp-icon"></span>
305 <span class="fp-reficons1"></span>
306 <span class="fp-reficons2"></span>
307 <span class="fp-filename"></span>
309 <a class="fp-contextmenu" href="#" onclick="return false;">'.$this->pix_icon('i/menu', 'â–¶').'</a>
315 * FileManager JS template for displaying 'Make new folder' dialog.
317 * Must be wrapped in an element, CSS for this element must define width and height of the window;
319 * Must have one input element with type="text" (for users to enter the new folder name);
321 * content of element with class 'fp-dlg-curpath' will be replaced with current path where
322 * new folder is about to be created;
323 * elements with classes 'fp-dlg-butcreate' and 'fp-dlg-butcancel' will hold onclick events;
327 protected function fm_js_template_mkdir() {
329 <div class="filemanager fp-mkdir-dlg" role="dialog" aria-live="assertive" aria-labelledby="fp-mkdir-dlg-title">
330 <div class="fp-mkdir-dlg-text">
331 <label id="fp-mkdir-dlg-title">' . get_string('newfoldername', 'repository') . '</label><br/>
332 <input type="text" />
334 <button class="fp-dlg-butcreate btn-primary btn">'.get_string('makeafolder').'</button>
335 <button class="fp-dlg-butcancel btn-cancel btn">'.get_string('cancel').'</button>
341 * FileManager JS template for error/info message displayed as a separate popup window.
343 * @see fp_js_template_message()
346 protected function fm_js_template_message() {
347 return $this->fp_js_template_message();
351 * FileManager JS template for window with file information/actions.
353 * All content must be enclosed in one element, CSS for this class must define width and
354 * height of the window;
356 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
358 * Inside the window the elements with the following classnames must be present:
359 * 'fp-saveas', 'fp-author', 'fp-license', 'fp-path'. Inside each of them must be
360 * one input element (or select in case of fp-license and fp-path). They may also have labels.
361 * The elements will be assign with class 'uneditable' and input/select element will become
362 * disabled if they are not applicable for the particular file;
364 * There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated',
365 * 'fp-size', 'fp-dimensions', 'fp-reflist'. They will receive additional class 'fp-unknown' if
366 * information is unavailable. If there is information available, the content of embedded
367 * element with class 'fp-value' will be substituted with the value;
369 * The value of Original ('fp-original') is loaded in separate request. When it is applicable
370 * but not yet loaded the 'fp-original' element receives additional class 'fp-loading';
372 * The value of 'Aliases/Shortcuts' ('fp-reflist') is also loaded in separate request. When it
373 * is applicable but not yet loaded the 'fp-original' element receives additional class
374 * 'fp-loading'. The string explaining that XX references exist will replace content of element
375 * 'fp-refcount'. Inside '.fp-reflist .fp-value' each reference will be enclosed in <li>;
377 * Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip',
378 * 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick
379 * events (there may be several elements with class 'fp-file-cancel');
381 * When confirm button is pressed and file is being selected, the top element receives
382 * additional class 'loading'. It is removed when response from server is received.
384 * When any of the input fields is changed, the top element receives class 'fp-changed';
385 * When current file can be set as main - top element receives class 'fp-cansetmain';
386 * When current file is folder/zip/file - top element receives respectfully class
387 * 'fp-folder'/'fp-zip'/'fp-file';
391 protected function fm_js_template_fileselectlayout() {
393 $strloading = get_string('loading', 'repository');
394 $iconprogress = $this->pix_icon('i/loading_small', $strloading).'';
396 <div class="filemanager fp-select">
397 <div class="fp-select-loading">
398 ' . $this->pix_icon('i/loading_small', '') . '
400 <form class="form-horizontal">
401 <button class="fp-file-download">'.get_string('download').'</button>
402 <button class="fp-file-delete">'.get_string('delete').'</button>
403 <button class="fp-file-setmain">'.get_string('setmainfile', 'repository').'</button>
404 <span class="fp-file-setmain-help">'.$OUTPUT->help_icon('setmainfile', 'repository').'</span>
405 <button class="fp-file-zip">'.get_string('zip', 'editor').'</button>
406 <button class="fp-file-unzip">'.get_string('unzip').'</button>
407 <div class="fp-hr"></div>
409 <div class="fp-forminset">
410 <div class="fp-saveas control-group clearfix">
411 <label class="control-label">'.get_string('name', 'repository').'</label>
412 <div class="controls">
416 <div class="fp-author control-group clearfix">
417 <label class="control-label">'.get_string('author', 'repository').'</label>
418 <div class="controls">
422 <div class="fp-license control-group clearfix">
423 <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
424 <div class="controls">
428 <div class="fp-path control-group clearfix">
429 <label class="control-label">'.get_string('path', 'repository').'</label>
430 <div class="controls">
434 <div class="fp-original control-group clearfix">
435 <label class="control-label">'.get_string('original', 'repository').'</label>
436 <div class="controls">
437 <span class="fp-originloading">'.$iconprogress.' '.$strloading.'</span><span class="fp-value"></span>
440 <div class="fp-reflist control-group clearfix">
441 <label class="control-label">'.get_string('referenceslist', 'repository').'</label>
442 <div class="controls">
443 <p class="fp-refcount"></p>
444 <span class="fp-reflistloading">'.$iconprogress.' '.$strloading.'</span>
445 <ul class="fp-value"></ul>
449 <div class="fp-select-buttons">
450 <button class="fp-file-update btn-primary btn">'.get_string('update', 'moodle').'</button>
451 <button class="fp-file-cancel btn-cancel btn">'.get_string('cancel').'</button>
454 <div class="fp-info clearfix">
455 <div class="fp-hr"></div>
456 <p class="fp-thumbnail"></p>
457 <div class="fp-fileinfo">
458 <div class="fp-datemodified">'.get_string('lastmodified', 'repository').' <span class="fp-value"></span></div>
459 <div class="fp-datecreated">'.get_string('datecreated', 'repository').' <span class="fp-value"></span></div>
460 <div class="fp-size">'.get_string('size', 'repository').' <span class="fp-value"></span></div>
461 <div class="fp-dimensions">'.get_string('dimensions', 'repository').' <span class="fp-value"></span></div>
469 * FileManager JS template for popup confirm dialogue window.
471 * Must have one top element, CSS for this element must define width and height of the window;
473 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
474 * elements with classes 'fp-dlg-butconfirm' and 'fp-dlg-butcancel' will
475 * hold onclick events;
479 protected function fm_js_template_confirmdialog() {
481 <div class="filemanager fp-dlg">
482 <div class="fp-dlg-text"></div>
483 <button class="fp-dlg-butconfirm btn-primary btn">'.get_string('ok').'</button>
484 <button class="fp-dlg-butcancel btn-cancel btn">'.get_string('cancel').'</button>
490 * Returns all FileManager JavaScript templates as an array.
494 public function filemanager_js_templates() {
495 $class_methods = get_class_methods($this);
496 $templates = array();
497 foreach ($class_methods as $method_name) {
498 if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches))
499 $templates[$matches[1]] = $this->$method_name();
505 * Displays restrictions for the file manager
507 * @param form_filemanager $fm
510 protected function fm_print_restrictions($fm) {
511 $maxbytes = display_size($fm->options
->maxbytes
);
512 $strparam = (object) array('size' => $maxbytes, 'attachments' => $fm->options
->maxfiles
,
513 'areasize' => display_size($fm->options
->areamaxbytes
));
514 $hasmaxfiles = !empty($fm->options
->maxfiles
) && $fm->options
->maxfiles
> 0;
515 $hasarealimit = !empty($fm->options
->areamaxbytes
) && $fm->options
->areamaxbytes
!= -1;
516 if ($hasmaxfiles && $hasarealimit) {
517 $maxsize = get_string('maxsizeandattachmentsandareasize', 'moodle', $strparam);
518 } else if ($hasmaxfiles) {
519 $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam);
520 } else if ($hasarealimit) {
521 $maxsize = get_string('maxsizeandareasize', 'moodle', $strparam);
523 $maxsize = get_string('maxfilesize', 'moodle', $maxbytes);
525 // TODO MDL-32020 also should say about 'File types accepted'
526 return '<span>'. $maxsize . '</span>';
530 * Template for FilePicker with general layout (not QuickUpload).
532 * Must have one top element containing everything else (recommended <div class="file-picker">),
533 * CSS for this element must define width and height of the filepicker window. Or CSS must
534 * define min-width, max-width, min-height and max-height and in this case the filepicker
535 * window will be resizeable;
537 * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode
538 * can be changed or not;
539 * Inside element with class 'fp-viewbar' there are expected elements with classes
540 * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch
541 * between the view modes, the last clicked element will have the class 'checked';
543 * Element with class 'fp-repo' is a template for displaying one repository. Other repositories
544 * will be attached as siblings (classes first/last/even/odd will be added respectfully).
545 * The currently selected repostory will have class 'active'. Contents of element with class
546 * 'fp-repo-name' will be replaced with repository name, source of image with class
547 * 'fp-repo-icon' will be replaced with repository icon;
549 * Element with class 'fp-content' is obligatory and will hold the current contents;
551 * Element with class 'fp-paging' will contain page navigation (will be deprecated soon);
553 * Element with class 'fp-path-folder' is a template for one folder in path toolbar.
554 * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
555 * Parent element will receive class 'empty' when there are no folders to be displayed;
556 * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
558 * Element with class 'fp-toolbar' will have class 'empty' if all 'Back', 'Search', 'Refresh',
559 * 'Logout', 'Manage' and 'Help' are unavailable for this repo;
561 * Inside fp-toolbar there are expected elements with classes fp-tb-back, fp-tb-search,
562 * fp-tb-refresh, fp-tb-logout, fp-tb-manage and fp-tb-help. Each of them will have
563 * class 'enabled' or 'disabled' if particular repository has this functionality.
564 * Element with class 'fp-tb-search' must contain empty form inside, it's contents will
565 * be substituted with the search form returned by repository (in the most cases it
566 * is generated with template core_repository_renderer::repository_default_searchform);
567 * Other elements must have either <a> or <button> element inside, it will hold onclick
568 * event for corresponding action; labels for fp-tb-back and fp-tb-logout may be
569 * replaced with those specified by repository;
573 protected function fp_js_template_generallayout() {
575 <div tabindex="0" class="file-picker fp-generallayout" role="dialog" aria-live="assertive">
576 <div class="fp-repo-area">
577 <ul class="fp-list" role="tablist">
578 <li class="fp-repo" role="tab" aria-selected="false" tabindex="-1">
579 <a href="#" tabindex="-1"><img class="fp-repo-icon" alt=" " width="16" height="16" />
580 <span class="fp-repo-name"></span>
585 <div class="fp-repo-items" tabindex="0">
586 <div class="fp-navbar">
588 <div class="fp-toolbar">
589 <div class="fp-tb-back">
590 <a href="#">'.get_string('back', 'repository').'</a>
592 <div class="fp-tb-search">
595 <div class="fp-tb-refresh">
596 <a title="'. get_string('refresh', 'repository') .'" href="#">
597 ' . $this->pix_icon('a/refresh', '') . '
600 <div class="fp-tb-logout">
601 <a title="'. get_string('logout', 'repository') .'" href="#">
602 ' . $this->pix_icon('a/logout', '') . '
605 <div class="fp-tb-manage">
606 <a title="'. get_string('manageurl', 'repository') .'" href="#">
607 ' . $this->pix_icon('a/setting', '') . '
610 <div class="fp-tb-help">
611 <a title="'. get_string('help', 'repository') .'" href="#">
612 ' . $this->pix_icon('a/help', '') . '
615 <div class="fp-tb-message"></div>
617 <div class="fp-viewbar">
618 <a role="button" title="'. get_string('displayicons', 'repository') .'" class="fp-vb-icons" href="#">
619 ' . $this->pix_icon('fp/view_icon_active', '', 'theme') . '
621 <a role="button" title="'. get_string('displaydetails', 'repository') .'" class="fp-vb-details" href="#">
622 ' . $this->pix_icon('fp/view_list_active', '', 'theme') . '
624 <a role="button" title="'. get_string('displaytree', 'repository') .'" class="fp-vb-tree" href="#">
625 ' . $this->pix_icon('fp/view_tree_active', '', 'theme') . '
628 <div class="fp-clear-left"></div>
630 <div class="fp-pathbar">
631 <span class="fp-path-folder"><a class="fp-path-folder-name" href="#"></a></span>
634 <div class="fp-content"></div>
641 * FilePicker JS template for displaying one file in 'icon view' mode.
643 * the element with class 'fp-thumbnail' will be resized to the repository thumbnail size
644 * (both width and height, unless min-width and/or min-height is set in CSS) and the content of
645 * an element will be replaced with an appropriate img;
647 * the width of element with class 'fp-filename' will be set to the repository thumbnail width
648 * (unless min-width is set in css) and the content of an element will be replaced with filename
649 * supplied by repository;
651 * top element(s) will have class fp-folder if the element is a folder;
653 * List of files will have parent <div> element with class 'fp-iconview'
657 protected function fp_js_template_iconfilename() {
659 <a class="fp-file" href="#" >
660 <div style="position:relative;">
661 <div class="fp-thumbnail"></div>
662 <div class="fp-reficons1"></div>
663 <div class="fp-reficons2"></div>
665 <div class="fp-filename-field">
666 <p class="fp-filename"></p>
673 * FilePicker JS template for displaying file name in 'table view' and 'tree view' modes.
675 * content of the element with class 'fp-icon' will be replaced with an appropriate img;
677 * content of element with class 'fp-filename' will be replaced with filename supplied by
680 * top element(s) will have class fp-folder if the element is a folder;
682 * Note that tree view and table view are the YUI widgets and therefore there are no
683 * other templates. The widgets will be wrapped in <div> with class fp-treeview or
684 * fp-tableview (respectfully).
688 protected function fp_js_template_listfilename() {
690 <span class="fp-filename-icon">
692 <span class="fp-icon"></span>
693 <span class="fp-filename"></span>
700 * FilePicker JS template for displaying link/loading progress for fetching of the next page
702 * This text is added to .fp-content AFTER .fp-iconview/.fp-treeview/.fp-tableview
704 * Must have one parent element with class 'fp-nextpage'. It will be assigned additional
705 * class 'loading' during loading of the next page (it is recommended that in this case the link
706 * becomes unavailable). Also must contain one element <a> or <button> that will hold
707 * onclick event for displaying of the next page. The event will be triggered automatically
708 * when user scrolls to this link.
712 protected function fp_js_template_nextpage() {
714 <div class="fp-nextpage">
715 <div class="fp-nextpage-link"><a href="#">'.get_string('more').'</a></div>
716 <div class="fp-nextpage-loading">
717 ' . $this->pix_icon('i/loading_small', '') . '
724 * FilePicker JS template for window appearing to select a file.
726 * All content must be enclosed in one element, CSS for this class must define width and
727 * height of the window;
729 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
731 * Inside the window the elements with the following classnames must be present:
732 * 'fp-saveas', 'fp-linktype-2', 'fp-linktype-1', 'fp-linktype-4', 'fp-setauthor',
733 * 'fp-setlicense'. Inside each of them must have one input element (or select in case of
734 * fp-setlicense). They may also have labels.
735 * The elements will be assign with class 'uneditable' and input/select element will become
736 * disabled if they are not applicable for the particular file;
738 * There may be present elements with classes 'fp-datemodified', 'fp-datecreated', 'fp-size',
739 * 'fp-license', 'fp-author', 'fp-dimensions'. They will receive additional class 'fp-unknown'
740 * if information is unavailable. If there is information available, the content of embedded
741 * element with class 'fp-value' will be substituted with the value;
743 * Elements with classes 'fp-select-confirm' and 'fp-select-cancel' will hold corresponding
746 * When confirm button is pressed and file is being selected, the top element receives
747 * additional class 'loading'. It is removed when response from server is received.
751 protected function fp_js_template_selectlayout() {
753 <div class="file-picker fp-select">
754 <div class="fp-select-loading">
755 ' . $this->pix_icon('i/loading_small', '') . '
757 <form class="form-horizontal">
758 <div class="fp-forminset">
759 <div class="fp-linktype-2 control-group control-radio clearfix">
760 <label class="control-label control-radio">'.get_string('makefileinternal', 'repository').'</label>
761 <div class="controls control-radio">
762 <input type="radio"/>
765 <div class="fp-linktype-1 control-group control-radio clearfix">
766 <label class="control-label control-radio">'.get_string('makefilelink', 'repository').'</label>
767 <div class="controls control-radio">
768 <input type="radio"/>
771 <div class="fp-linktype-4 control-group control-radio clearfix">
772 <label class="control-label control-radio">'.get_string('makefilereference', 'repository').'</label>
773 <div class="controls control-radio">
774 <input type="radio"/>
777 <div class="fp-linktype-8 control-group control-radio clearfix">
778 <label class="control-label control-radio">'.get_string('makefilecontrolledlink', 'repository').'</label>
779 <div class="controls control-radio">
780 <input type="radio"/>
783 <div class="fp-saveas control-group clearfix">
784 <label class="control-label">'.get_string('saveas', 'repository').'</label>
785 <div class="controls">
789 <div class="fp-setauthor control-group clearfix">
790 <label class="control-label">'.get_string('author', 'repository').'</label>
791 <div class="controls">
795 <div class="fp-setlicense control-group clearfix">
796 <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
797 <div class="controls">
802 <div class="fp-select-buttons">
803 <button class="fp-select-confirm btn-primary btn">'.get_string('getfile', 'repository').'</button>
804 <button class="fp-select-cancel btn-cancel btn">'.get_string('cancel').'</button>
807 <div class="fp-info clearfix">
808 <div class="fp-hr"></div>
809 <p class="fp-thumbnail"></p>
810 <div class="fp-fileinfo">
811 <div class="fp-datemodified">'.get_string('lastmodified', 'repository').'<span class="fp-value"></span></div>
812 <div class="fp-datecreated">'.get_string('datecreated', 'repository').'<span class="fp-value"></span></div>
813 <div class="fp-size">'.get_string('size', 'repository').'<span class="fp-value"></span></div>
814 <div class="fp-license">'.get_string('license', 'repository').'<span class="fp-value"></span></div>
815 <div class="fp-author">'.get_string('author', 'repository').'<span class="fp-value"></span></div>
816 <div class="fp-dimensions">'.get_string('dimensions', 'repository').'<span class="fp-value"></span></div>
824 * FilePicker JS template for 'Upload file' repository
826 * Content to display when user chooses 'Upload file' repository (will be nested inside
827 * element with class 'fp-content').
829 * Must contain form (enctype="multipart/form-data" method="POST")
831 * The elements with the following classnames must be present:
832 * 'fp-file', 'fp-saveas', 'fp-setauthor', 'fp-setlicense'. Inside each of them must have
833 * one input element (or select in case of fp-setlicense). They may also have labels.
835 * Element with class 'fp-upload-btn' will hold onclick event for uploading the file;
837 * Please note that some fields may be hidden using CSS if this is part of quickupload form
841 protected function fp_js_template_uploadform() {
843 <div class="fp-upload-form">
844 <div class="fp-content-center">
845 <form enctype="multipart/form-data" method="POST" class="form-horizontal">
846 <div class="fp-formset">
847 <div class="fp-file control-group clearfix">
848 <label class="control-label">'.get_string('attachment', 'repository').'</label>
849 <div class="controls">
853 <div class="fp-saveas control-group clearfix">
854 <label class="control-label">'.get_string('saveas', 'repository').'</label>
855 <div class="controls">
859 <div class="fp-setauthor control-group clearfix">
860 <label class="control-label">'.get_string('author', 'repository').'</label>
861 <div class="controls">
865 <div class="fp-setlicense control-group clearfix">
866 <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
867 <div class="controls">
873 <div class="mdl-align">
874 <button class="fp-upload-btn btn-primary btn">'.get_string('upload', 'repository').'</button>
882 * FilePicker JS template to display during loading process (inside element with class 'fp-content').
886 protected function fp_js_template_loading() {
888 <div class="fp-content-loading">
889 <div class="fp-content-center">
890 ' . $this->pix_icon('i/loading_small', '') . '
896 * FilePicker JS template for error (inside element with class 'fp-content').
898 * must have element with class 'fp-error', its content will be replaced with error text
899 * and the error code will be assigned as additional class to this element
900 * used errors: invalidjson, nofilesavailable, norepositoriesavailable
904 protected function fp_js_template_error() {
906 <div class="fp-content-error" ><div class="fp-error"></div></div>';
911 * FilePicker JS template for error/info message displayed as a separate popup window.
913 * Must be wrapped in one element, CSS for this element must define
914 * width and height of the window. It will be assigned with an additional class 'fp-msg-error'
915 * or 'fp-msg-info' depending on message type;
917 * content of element with class 'fp-msg-text' will be replaced with error/info text;
919 * element with class 'fp-msg-butok' will hold onclick event
923 protected function fp_js_template_message() {
925 <div class="file-picker fp-msg" role="alertdialog" aria-live="assertive" aria-labelledby="fp-msg-labelledby">
926 <p class="fp-msg-text" id="fp-msg-labelledby"></p>
927 <button class="fp-msg-butok btn-primary btn">'.get_string('ok').'</button>
933 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists.
935 * Must have one top element, CSS for this element must define width and height of the window;
937 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
938 * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename',
939 * 'fp-dlg-butoverwriteall', 'fp-dlg-butrenameall' and 'fp-dlg-butcancel' will
940 * hold onclick events;
942 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
943 * (Note that it may have long text)
947 protected function fp_js_template_processexistingfile() {
949 <div class="file-picker fp-dlg">
950 <p class="fp-dlg-text"></p>
951 <div class="fp-dlg-buttons">
952 <button class="fp-dlg-butoverwrite btn">'.get_string('overwrite', 'repository').'</button>
953 <button class="fp-dlg-butrename btn"></button>
954 <button class="fp-dlg-butcancel btn btn-cancel">'.get_string('cancel').'</button>
961 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists (multiple-file version).
963 * Must have one top element, CSS for this element must define width and height of the window;
965 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
966 * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename' and 'fp-dlg-butcancel' will
967 * hold onclick events;
969 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
970 * (Note that it may have long text)
974 protected function fp_js_template_processexistingfilemultiple() {
976 <div class="file-picker fp-dlg">
977 <p class="fp-dlg-text"></p>
978 <a class="fp-dlg-butoverwrite fp-panel-button" href="#">'.get_string('overwrite', 'repository').'</a>
979 <a class="fp-dlg-butcancel fp-panel-button" href="#">'.get_string('cancel').'</a>
980 <a class="fp-dlg-butrename fp-panel-button" href="#"></a>
982 <a class="fp-dlg-butoverwriteall fp-panel-button" href="#">'.get_string('overwriteall', 'repository').'</a>
983 <a class="fp-dlg-butrenameall fp-panel-button" href="#">'.get_string('renameall', 'repository').'</a>
989 * FilePicker JS template for repository login form including templates for each element type
991 * Must contain one <form> element with templates for different input types inside:
992 * Elements with classes 'fp-login-popup', 'fp-login-textarea', 'fp-login-select' and
993 * 'fp-login-input' are templates for displaying respective login form elements. Inside
994 * there must be exactly one element with type <button>, <textarea>, <select> or <input>
995 * (i.e. fp-login-popup should have <button>, fp-login-textarea should have <textarea>, etc.);
996 * They may also contain the <label> element and it's content will be substituted with
999 * You can also define elements with classes 'fp-login-checkbox', 'fp-login-text'
1000 * but if they are not found, 'fp-login-input' will be used;
1002 * Element with class 'fp-login-radiogroup' will be used for group of radio inputs. Inside
1003 * it should hava a template for one radio input (with class 'fp-login-radio');
1005 * Element with class 'fp-login-submit' will hold on click mouse event (form submission). It
1006 * will be removed if at least one popup element is present;
1010 protected function fp_js_template_loginform() {
1012 <div class="fp-login-form">
1013 <div class="fp-content-center">
1014 <form class="form-horizontal">
1015 <div class="fp-formset">
1016 <div class="fp-login-popup control-group clearfix">
1017 <div class="controls fp-popup">
1018 <button class="fp-login-popup-but btn-primary btn">'.get_string('login', 'repository').'</button>
1021 <div class="fp-login-textarea control-group clearfix">
1022 <div class="controls"><textarea></textarea></div>
1024 <div class="fp-login-select control-group clearfix">
1025 <label class="control-label"></label>
1027 <div class="controls"><select></select></div>
1030 <div class="fp-login-input control-group clearfix">
1031 <label class="control-label"></label>
1032 <div class="controls"><input/></div>
1034 <div class="fp-login-radiogroup control-group clearfix">
1035 <label class="control-label"></label>
1036 <div class="controls fp-login-radio"><input /> <label></label></div>
1039 <p><button class="fp-login-submit btn-primary btn">'.get_string('submit', 'repository').'</button></p>
1047 * Returns all FilePicker JavaScript templates as an array.
1051 public function filepicker_js_templates() {
1052 $class_methods = get_class_methods($this);
1053 $templates = array();
1054 foreach ($class_methods as $method_name) {
1055 if (preg_match('/^fp_js_template_(.*)$/', $method_name, $matches))
1056 $templates[$matches[1]] = $this->$method_name();
1062 * Returns HTML for default repository searchform to be passed to Filepicker
1064 * This will be used as contents for search form defined in generallayout template
1065 * (form with id {TOOLSEARCHID}).
1066 * Default contents is one text input field with name="s"
1068 public function repository_default_searchform() {
1069 $searchinput = html_writer
::label(get_string('searchrepo', 'repository'),
1070 'reposearch', false, array('class' => 'accesshide'));
1071 $searchinput .= html_writer
::empty_tag('input', array('type' => 'text',
1072 'id' => 'reposearch', 'name' => 's', 'value' => get_string('search', 'repository')));
1073 $str = html_writer
::tag('div', $searchinput, array('class' => "fp-def-search"));
1080 * Data structure representing a general moodle file tree viewer
1082 * @copyright 2010 Dongsheng Cai
1083 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1086 class files_tree_viewer
implements renderable
{
1092 * Constructor of moodle_file_tree_viewer class
1093 * @param file_info $file_info
1094 * @param array $options
1096 public function __construct(file_info
$file_info, array $options = null) {
1099 //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
1100 $this->options
= (array)$options;
1101 $this->context
= $options['context'];
1103 $this->tree
= array();
1104 $children = $file_info->get_children();
1105 $current_file_params = $file_info->get_params();
1106 $parent_info = $file_info->get_parent();
1107 $level = $parent_info;
1108 $this->path
= array();
1110 $params = $level->get_params();
1111 $context = context
::instance_by_id($params['contextid']);
1112 // $this->context is current context
1113 if ($context->id
!= $this->context
->id
or empty($params['filearea'])) {
1116 // unset unused parameters
1117 unset($params['component']);
1118 unset($params['filearea']);
1119 unset($params['filename']);
1120 unset($params['itemid']);
1121 $url = new moodle_url('/files/index.php', $params);
1122 $this->path
[] = html_writer
::link($url, $level->get_visible_name());
1123 $level = $level->get_parent();
1125 $this->path
= array_reverse($this->path
);
1126 if ($current_file_params['filepath'] != '/') {
1127 $this->path
[] = $file_info->get_visible_name();
1130 foreach ($children as $child) {
1131 $filedate = $child->get_timemodified();
1132 $filesize = $child->get_filesize();
1133 $mimetype = $child->get_mimetype();
1134 $params = $child->get_params();
1135 unset($params['component']);
1136 unset($params['filearea']);
1137 unset($params['filename']);
1138 unset($params['itemid']);
1140 'params' => $params,
1141 'filename' => $child->get_visible_name(),
1142 'mimetype' => $child->get_mimetype(),
1143 'filedate' => $filedate ?
$filedate : '',
1144 'filesize' => $filesize ?
$filesize : ''
1146 $url = new moodle_url('/files/index.php', $params);
1147 if ($child->is_directory()) {
1148 $fileitem['isdir'] = true;
1149 $fileitem['url'] = $url->out(false);
1151 $fileitem['url'] = $child->get_url();
1153 $this->tree
[] = $fileitem;