MDL-45296 phpdoc: add some missing params
[moodle.git] / files / renderer.php
blobf4e5ffae41f22ecc65f7d215693744bc187b3c41
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 ///////////////////////////////////////////////////////////////////////////
22 defined('MOODLE_INTERNAL') || die();
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
33 /**
34 * File browser render
36 * @copyright 2010 Dongsheng Cai
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 * @since Moodle 2.0
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) {
52 $html .= $path;
53 $html .= ' / ';
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);
75 } else {
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']),
80 $filedate,
81 $filesize,
82 $filetype
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();
89 return $html;
92 /**
93 * Prints the file manager and initializes all necessary libraries
95 * <pre>
96 * $fm = new form_filemanager($options);
97 * $output = get_renderer('core', 'files');
98 * echo $output->render($fm);
99 * </pre>
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);
107 $module = array(
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'),
111 'strings' => array(
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>';
133 return $html;
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
178 * @return string
180 private function fm_print_generallayout($fm) {
181 global $OUTPUT;
182 $options = $fm->options;
183 $client_id = $options->client_id;
184 $straddfile = get_string('addfile', 'repository');
185 $strmakedir = get_string('makeafolder', 'moodle');
186 $strdownload = get_string('downloadfolder', 'repository');
187 $strloading = get_string('loading', 'repository');
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');
195 $html = '
196 <div id="filemanager-'.$client_id.'" class="filemanager fm-loading">
197 <div class="fp-restrictions">
198 '.$restrictions.'
199 <span class="dnduploadnotsupported-message"> - '.$strdndnotsupported.' </span>
200 </div>
201 <div class="fp-navbar">
202 <div class="filemanager-toolbar">
203 <div class="fp-toolbar">
204 <div class="fp-btn-add">
205 <a role="button" title="'.$straddfile.'" href="#"><img src="'.$this->pix_url('a/add_file').'" alt="" /></a>
206 </div>
207 <div class="fp-btn-mkdir">
208 <a role="button" title="'.$strmakedir.'" href="#"><img src="'.$this->pix_url('a/create_folder').'" alt="" /></a>
209 </div>
210 <div class="fp-btn-download">
211 <a role="button" title="'.$strdownload.'" href="#"><img src="'.$this->pix_url('a/download_all').'" alt="" /></a>
212 </div>
213 <img class="fp-img-downloading" src="'.$this->pix_url('i/loading_small').'" alt="" />
214 </div>
215 <div class="fp-viewbar">
216 <a title="'. get_string('displayicons', 'repository') .'" class="fp-vb-icons" href="#">
217 <img alt="" src="'. $this->pix_url('fp/view_icon_active', 'theme') .'" />
218 </a>
219 <a title="'. get_string('displaydetails', 'repository') .'" class="fp-vb-details" href="#">
220 <img alt="" src="'. $this->pix_url('fp/view_list_active', 'theme') .'" />
221 </a>
222 <a title="'. get_string('displaytree', 'repository') .'" class="fp-vb-tree" href="#">
223 <img alt="" src="'. $this->pix_url('fp/view_tree_active', 'theme') .'" />
224 </a>
225 </div>
226 </div>
227 <div class="fp-pathbar">
228 <span class="fp-path-folder"><a class="fp-path-folder-name" href="#"></a></span>
229 </div>
230 </div>
231 <div class="filemanager-loading mdl-align">'.$icon_progress.'</div>
232 <div class="filemanager-container" >
233 <div class="fm-content-wrapper">
234 <div class="fp-content"></div>
235 <div class="fm-empty-container">
236 <div class="dndupload-message">'.$strdndenabledinbox.'<br/><div class="dndupload-arrow"></div></div>
237 </div>
238 <div class="dndupload-target">'.$strdroptoupload.'<br/><div class="dndupload-arrow"></div></div>
239 <div class="dndupload-progressbars"></div>
240 <div class="dndupload-uploadinprogress">'.$icon_progress.'</div>
241 </div>
242 <div class="filemanager-updating">'.$icon_progress.'</div>
243 </div>
244 </div>';
245 return $html;
249 * FileManager JS template for displaying one file in 'icon view' mode.
251 * Except for elements described in fp_js_template_iconfilename, this template may also
252 * contain element with class 'fp-contextmenu'. If context menu is available for this
253 * file, the top element will receive the additional class 'fp-hascontextmenu' and
254 * the element with class 'fp-contextmenu' will hold onclick event for displaying
255 * the context menu.
257 * @see fp_js_template_iconfilename()
258 * @return string
260 private function fm_js_template_iconfilename() {
261 $rv = '
262 <div class="fp-file">
263 <a href="#">
264 <div style="position:relative;">
265 <div class="fp-thumbnail"></div>
266 <div class="fp-reficons1"></div>
267 <div class="fp-reficons2"></div>
268 </div>
269 <div class="fp-filename-field">
270 <div class="fp-filename"></div>
271 </div>
272 </a>
273 <a class="fp-contextmenu" href="#">'.$this->pix_icon('i/menu', 'â–¶').'</a>
274 </div>';
275 return $rv;
279 * FileManager JS template for displaying file name in 'table view' and 'tree view' modes.
281 * Except for elements described in fp_js_template_listfilename, this template may also
282 * contain element with class 'fp-contextmenu'. If context menu is available for this
283 * file, the top element will receive the additional class 'fp-hascontextmenu' and
284 * the element with class 'fp-contextmenu' will hold onclick event for displaying
285 * the context menu.
287 * @todo MDL-32736 remove onclick="return false;"
288 * @see fp_js_template_listfilename()
289 * @return string
291 private function fm_js_template_listfilename() {
292 $rv = '
293 <span class="fp-filename-icon">
294 <a href="#">
295 <span class="fp-icon"></span>
296 <span class="fp-reficons1"></span>
297 <span class="fp-reficons2"></span>
298 <span class="fp-filename"></span>
299 </a>
300 <a class="fp-contextmenu" href="#" onclick="return false;">'.$this->pix_icon('i/menu', 'â–¶').'</a>
301 </span>';
302 return $rv;
306 * FileManager JS template for displaying 'Make new folder' dialog.
308 * Must be wrapped in an element, CSS for this element must define width and height of the window;
310 * Must have one input element with type="text" (for users to enter the new folder name);
312 * content of element with class 'fp-dlg-curpath' will be replaced with current path where
313 * new folder is about to be created;
314 * elements with classes 'fp-dlg-butcreate' and 'fp-dlg-butcancel' will hold onclick events;
316 * @return string
318 private function fm_js_template_mkdir() {
319 $rv = '
320 <div class="filemanager fp-mkdir-dlg" role="dialog" aria-live="assertive" aria-labelledby="fp-mkdir-dlg-title">
321 <div class="fp-mkdir-dlg-text">
322 <label id="fp-mkdir-dlg-title">' . get_string('newfoldername', 'repository') . '</label><br/>
323 <input type="text" />
324 </div>
325 <button class="fp-dlg-butcreate btn-primary btn">'.get_string('makeafolder').'</button>
326 <button class="fp-dlg-butcancel btn-cancel btn">'.get_string('cancel').'</button>
327 </div>';
328 return $rv;
332 * FileManager JS template for error/info message displayed as a separate popup window.
334 * @see fp_js_template_message()
335 * @return string
337 private function fm_js_template_message() {
338 return $this->fp_js_template_message();
342 * FileManager JS template for window with file information/actions.
344 * All content must be enclosed in one element, CSS for this class must define width and
345 * height of the window;
347 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
349 * Inside the window the elements with the following classnames must be present:
350 * 'fp-saveas', 'fp-author', 'fp-license', 'fp-path'. Inside each of them must be
351 * one input element (or select in case of fp-license and fp-path). They may also have labels.
352 * The elements will be assign with class 'uneditable' and input/select element will become
353 * disabled if they are not applicable for the particular file;
355 * There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated',
356 * 'fp-size', 'fp-dimensions', 'fp-reflist'. They will receive additional class 'fp-unknown' if
357 * information is unavailable. If there is information available, the content of embedded
358 * element with class 'fp-value' will be substituted with the value;
360 * The value of Original ('fp-original') is loaded in separate request. When it is applicable
361 * but not yet loaded the 'fp-original' element receives additional class 'fp-loading';
363 * The value of 'Aliases/Shortcuts' ('fp-reflist') is also loaded in separate request. When it
364 * is applicable but not yet loaded the 'fp-original' element receives additional class
365 * 'fp-loading'. The string explaining that XX references exist will replace content of element
366 * 'fp-refcount'. Inside '.fp-reflist .fp-value' each reference will be enclosed in <li>;
368 * Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip',
369 * 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick
370 * events (there may be several elements with class 'fp-file-cancel');
372 * When confirm button is pressed and file is being selected, the top element receives
373 * additional class 'loading'. It is removed when response from server is received.
375 * When any of the input fields is changed, the top element receives class 'fp-changed';
376 * When current file can be set as main - top element receives class 'fp-cansetmain';
377 * When current file is folder/zip/file - top element receives respectfully class
378 * 'fp-folder'/'fp-zip'/'fp-file';
380 * @return string
382 private function fm_js_template_fileselectlayout() {
383 global $OUTPUT;
384 $strloading = get_string('loading', 'repository');
385 $iconprogress = $this->pix_icon('i/loading_small', $strloading).'';
386 $rv = '
387 <div class="filemanager fp-select">
388 <div class="fp-select-loading">
389 <img src="'.$this->pix_url('i/loading_small').'" />
390 </div>
391 <form class="form-horizontal">
392 <button class="fp-file-download">'.get_string('download').'</button>
393 <button class="fp-file-delete">'.get_string('delete').'</button>
394 <button class="fp-file-setmain">'.get_string('setmainfile', 'repository').'</button>
395 <span class="fp-file-setmain-help">'.$OUTPUT->help_icon('setmainfile', 'repository').'</span>
396 <button class="fp-file-zip">'.get_string('zip', 'editor').'</button>
397 <button class="fp-file-unzip">'.get_string('unzip').'</button>
398 <div class="fp-hr"></div>
400 <div class="fp-forminset">
401 <div class="fp-saveas control-group clearfix">
402 <label class="control-label">'.get_string('name', 'repository').'</label>
403 <div class="controls">
404 <input type="text"/>
405 </div>
406 </div>
407 <div class="fp-author control-group clearfix">
408 <label class="control-label">'.get_string('author', 'repository').'</label>
409 <div class="controls">
410 <input type="text"/>
411 </div>
412 </div>
413 <div class="fp-license control-group clearfix">
414 <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
415 <div class="controls">
416 <select></select>
417 </div>
418 </div>
419 <div class="fp-path control-group clearfix">
420 <label class="control-label">'.get_string('path', 'repository').'</label>
421 <div class="controls">
422 <select></select>
423 </div>
424 </div>
425 <div class="fp-original control-group clearfix">
426 <label class="control-label">'.get_string('original', 'repository').'</label>
427 <div class="controls">
428 <span class="fp-originloading">'.$iconprogress.' '.$strloading.'</span><span class="fp-value"></span>
429 </div>
430 </div>
431 <div class="fp-reflist control-group clearfix">
432 <label class="control-label">'.get_string('referenceslist', 'repository').'</label>
433 <div class="controls">
434 <p class="fp-refcount"></p>
435 <span class="fp-reflistloading">'.$iconprogress.' '.$strloading.'</span>
436 <ul class="fp-value"></ul>
437 </div>
438 </div>
439 </div>
440 <div class="fp-select-buttons">
441 <button class="fp-file-update btn-primary btn">'.get_string('update', 'moodle').'</button>
442 <button class="fp-file-cancel btn-cancel btn">'.get_string('cancel').'</button>
443 </div>
444 </form>
445 <div class="fp-info clearfix">
446 <div class="fp-hr"></div>
447 <p class="fp-thumbnail"></p>
448 <div class="fp-fileinfo">
449 <div class="fp-datemodified">'.get_string('lastmodified', 'repository').' <span class="fp-value"></span></div>
450 <div class="fp-datecreated">'.get_string('datecreated', 'repository').' <span class="fp-value"></span></div>
451 <div class="fp-size">'.get_string('size', 'repository').' <span class="fp-value"></span></div>
452 <div class="fp-dimensions">'.get_string('dimensions', 'repository').' <span class="fp-value"></span></div>
453 </div>
454 </div>
455 </div>';
456 return $rv;
460 * FileManager JS template for popup confirm dialogue window.
462 * Must have one top element, CSS for this element must define width and height of the window;
464 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
465 * elements with classes 'fp-dlg-butconfirm' and 'fp-dlg-butcancel' will
466 * hold onclick events;
468 * @return string
470 private function fm_js_template_confirmdialog() {
471 $rv = '
472 <div class="filemanager fp-dlg">
473 <div class="fp-dlg-text"></div>
474 <button class="fp-dlg-butconfirm btn-primary btn">'.get_string('ok').'</button>
475 <button class="fp-dlg-butcancel btn-cancel btn">'.get_string('cancel').'</button>
476 </div>';
477 return $rv;
481 * Returns all FileManager JavaScript templates as an array.
483 * @return array
485 public function filemanager_js_templates() {
486 $class_methods = get_class_methods($this);
487 $templates = array();
488 foreach ($class_methods as $method_name) {
489 if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches))
490 $templates[$matches[1]] = $this->$method_name();
492 return $templates;
496 * Displays restrictions for the file manager
498 * @param form_filemanager $fm
499 * @return string
501 private function fm_print_restrictions($fm) {
502 $maxbytes = display_size($fm->options->maxbytes);
503 $strparam = (object) array('size' => $maxbytes, 'attachments' => $fm->options->maxfiles,
504 'areasize' => display_size($fm->options->areamaxbytes));
505 $hasmaxfiles = !empty($fm->options->maxfiles) && $fm->options->maxfiles > 0;
506 $hasarealimit = !empty($fm->options->areamaxbytes) && $fm->options->areamaxbytes != -1;
507 if ($hasmaxfiles && $hasarealimit) {
508 $maxsize = get_string('maxsizeandattachmentsandareasize', 'moodle', $strparam);
509 } else if ($hasmaxfiles) {
510 $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam);
511 } else if ($hasarealimit) {
512 $maxsize = get_string('maxsizeandareasize', 'moodle', $strparam);
513 } else {
514 $maxsize = get_string('maxfilesize', 'moodle', $maxbytes);
516 // TODO MDL-32020 also should say about 'File types accepted'
517 return '<span>'. $maxsize . '</span>';
521 * Template for FilePicker with general layout (not QuickUpload).
523 * Must have one top element containing everything else (recommended <div class="file-picker">),
524 * CSS for this element must define width and height of the filepicker window. Or CSS must
525 * define min-width, max-width, min-height and max-height and in this case the filepicker
526 * window will be resizeable;
528 * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode
529 * can be changed or not;
530 * Inside element with class 'fp-viewbar' there are expected elements with classes
531 * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch
532 * between the view modes, the last clicked element will have the class 'checked';
534 * Element with class 'fp-repo' is a template for displaying one repository. Other repositories
535 * will be attached as siblings (classes first/last/even/odd will be added respectfully).
536 * The currently selected repostory will have class 'active'. Contents of element with class
537 * 'fp-repo-name' will be replaced with repository name, source of image with class
538 * 'fp-repo-icon' will be replaced with repository icon;
540 * Element with class 'fp-content' is obligatory and will hold the current contents;
542 * Element with class 'fp-paging' will contain page navigation (will be deprecated soon);
544 * Element with class 'fp-path-folder' is a template for one folder in path toolbar.
545 * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
546 * Parent element will receive class 'empty' when there are no folders to be displayed;
547 * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
549 * Element with class 'fp-toolbar' will have class 'empty' if all 'Back', 'Search', 'Refresh',
550 * 'Logout', 'Manage' and 'Help' are unavailable for this repo;
552 * Inside fp-toolbar there are expected elements with classes fp-tb-back, fp-tb-search,
553 * fp-tb-refresh, fp-tb-logout, fp-tb-manage and fp-tb-help. Each of them will have
554 * class 'enabled' or 'disabled' if particular repository has this functionality.
555 * Element with class 'fp-tb-search' must contain empty form inside, it's contents will
556 * be substituted with the search form returned by repository (in the most cases it
557 * is generated with template core_repository_renderer::repository_default_searchform);
558 * Other elements must have either <a> or <button> element inside, it will hold onclick
559 * event for corresponding action; labels for fp-tb-back and fp-tb-logout may be
560 * replaced with those specified by repository;
562 * @return string
564 private function fp_js_template_generallayout() {
565 $rv = '
566 <div tabindex="0" class="file-picker fp-generallayout" role="dialog" aria-live="assertive">
567 <div class="fp-repo-area">
568 <ul class="fp-list">
569 <li class="fp-repo">
570 <a href="#"><img class="fp-repo-icon" alt=" " width="16" height="16" />&nbsp;<span class="fp-repo-name"></span></a>
571 </li>
572 </ul>
573 </div>
574 <div class="fp-repo-items" tabindex="0">
575 <div class="fp-navbar">
576 <div>
577 <div class="fp-toolbar">
578 <div class="fp-tb-back">
579 <a href="#">'.get_string('back', 'repository').'</a>
580 </div>
581 <div class="fp-tb-search">
582 <form></form>
583 </div>
584 <div class="fp-tb-refresh">
585 <a title="'. get_string('refresh', 'repository') .'" href="#">
586 <img alt="" src="'.$this->pix_url('a/refresh').'" />
587 </a>
588 </div>
589 <div class="fp-tb-logout">
590 <a title="'. get_string('logout', 'repository') .'" href="#">
591 <img alt="" src="'.$this->pix_url('a/logout').'" />
592 </a>
593 </div>
594 <div class="fp-tb-manage">
595 <a title="'. get_string('settings', 'repository') .'" href="#">
596 <img alt="" src="'.$this->pix_url('a/setting').'" />
597 </a>
598 </div>
599 <div class="fp-tb-help">
600 <a title="'. get_string('help', 'repository') .'" href="#">
601 <img alt="" src="'.$this->pix_url('a/help').'" />
602 </a>
603 </div>
604 <div class="fp-tb-message"></div>
605 </div>
606 <div class="fp-viewbar">
607 <a title="'. get_string('displayicons', 'repository') .'" class="fp-vb-icons" href="#">
608 <img alt="" src="'. $this->pix_url('fp/view_icon_active', 'theme') .'" />
609 </a>
610 <a title="'. get_string('displaydetails', 'repository') .'" class="fp-vb-details" href="#">
611 <img alt="" src="'. $this->pix_url('fp/view_list_active', 'theme') .'" />
612 </a>
613 <a title="'. get_string('displaytree', 'repository') .'" class="fp-vb-tree" href="#">
614 <img alt="" src="'. $this->pix_url('fp/view_tree_active', 'theme') .'" />
615 </a>
616 </div>
617 <div class="fp-clear-left"></div>
618 </div>
619 <div class="fp-pathbar">
620 <span class="fp-path-folder"><a class="fp-path-folder-name" href="#"></a></span>
621 </div>
622 </div>
623 <div class="fp-content"></div>
624 </div>
625 </div>';
626 return $rv;
630 * FilePicker JS template for displaying one file in 'icon view' mode.
632 * the element with class 'fp-thumbnail' will be resized to the repository thumbnail size
633 * (both width and height, unless min-width and/or min-height is set in CSS) and the content of
634 * an element will be replaced with an appropriate img;
636 * the width of element with class 'fp-filename' will be set to the repository thumbnail width
637 * (unless min-width is set in css) and the content of an element will be replaced with filename
638 * supplied by repository;
640 * top element(s) will have class fp-folder if the element is a folder;
642 * List of files will have parent <div> element with class 'fp-iconview'
644 * @return string
646 private function fp_js_template_iconfilename() {
647 $rv = '
648 <a class="fp-file" href="#" >
649 <div style="position:relative;">
650 <div class="fp-thumbnail"></div>
651 <div class="fp-reficons1"></div>
652 <div class="fp-reficons2"></div>
653 </div>
654 <div class="fp-filename-field">
655 <p class="fp-filename"></p>
656 </div>
657 </a>';
658 return $rv;
662 * FilePicker JS template for displaying file name in 'table view' and 'tree view' modes.
664 * content of the element with class 'fp-icon' will be replaced with an appropriate img;
666 * content of element with class 'fp-filename' will be replaced with filename supplied by
667 * repository;
669 * top element(s) will have class fp-folder if the element is a folder;
671 * Note that tree view and table view are the YUI widgets and therefore there are no
672 * other templates. The widgets will be wrapped in <div> with class fp-treeview or
673 * fp-tableview (respectfully).
675 * @return string
677 private function fp_js_template_listfilename() {
678 $rv = '
679 <span class="fp-filename-icon">
680 <a href="#">
681 <span class="fp-icon"></span>
682 <span class="fp-filename"></span>
683 </a>
684 </span>';
685 return $rv;
689 * FilePicker JS template for displaying link/loading progress for fetching of the next page
691 * This text is added to .fp-content AFTER .fp-iconview/.fp-treeview/.fp-tableview
693 * Must have one parent element with class 'fp-nextpage'. It will be assigned additional
694 * class 'loading' during loading of the next page (it is recommended that in this case the link
695 * becomes unavailable). Also must contain one element <a> or <button> that will hold
696 * onclick event for displaying of the next page. The event will be triggered automatically
697 * when user scrolls to this link.
699 * @return string
701 private function fp_js_template_nextpage() {
702 $rv = '
703 <div class="fp-nextpage">
704 <div class="fp-nextpage-link"><a href="#">'.get_string('more').'</a></div>
705 <div class="fp-nextpage-loading">
706 <img src="'.$this->pix_url('i/loading_small').'" />
707 </div>
708 </div>';
709 return $rv;
713 * FilePicker JS template for window appearing to select a file.
715 * All content must be enclosed in one element, CSS for this class must define width and
716 * height of the window;
718 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
720 * Inside the window the elements with the following classnames must be present:
721 * 'fp-saveas', 'fp-linktype-2', 'fp-linktype-1', 'fp-linktype-4', 'fp-setauthor',
722 * 'fp-setlicense'. Inside each of them must have one input element (or select in case of
723 * fp-setlicense). They may also have labels.
724 * The elements will be assign with class 'uneditable' and input/select element will become
725 * disabled if they are not applicable for the particular file;
727 * There may be present elements with classes 'fp-datemodified', 'fp-datecreated', 'fp-size',
728 * 'fp-license', 'fp-author', 'fp-dimensions'. They will receive additional class 'fp-unknown'
729 * if information is unavailable. If there is information available, the content of embedded
730 * element with class 'fp-value' will be substituted with the value;
732 * Elements with classes 'fp-select-confirm' and 'fp-select-cancel' will hold corresponding
733 * onclick events;
735 * When confirm button is pressed and file is being selected, the top element receives
736 * additional class 'loading'. It is removed when response from server is received.
738 * @return string
740 private function fp_js_template_selectlayout() {
741 $rv = '
742 <div class="file-picker fp-select">
743 <div class="fp-select-loading">
744 <img src="'.$this->pix_url('i/loading_small').'" />
745 </div>
746 <form class="form-horizontal">
747 <div class="fp-forminset">
748 <div class="fp-linktype-2 control-group control-radio clearfix">
749 <label class="control-label control-radio">'.get_string('makefileinternal', 'repository').'</label>
750 <div class="controls control-radio">
751 <input type="radio"/>
752 </div>
753 </div>
754 <div class="fp-linktype-1 control-group control-radio clearfix">
755 <label class="control-label control-radio">'.get_string('makefilelink', 'repository').'</label>
756 <div class="controls control-radio">
757 <input type="radio"/>
758 </div>
759 </div>
760 <div class="fp-linktype-4 control-group control-radio clearfix">
761 <label class="control-label control-radio">'.get_string('makefilereference', 'repository').'</label>
762 <div class="controls control-radio">
763 <input type="radio"/>
764 </div>
765 </div>
766 <div class="fp-saveas control-group clearfix">
767 <label class="control-label">'.get_string('saveas', 'repository').'</label>
768 <div class="controls">
769 <input type="text"/>
770 </div>
771 </div>
772 <div class="fp-setauthor control-group clearfix">
773 <label class="control-label">'.get_string('author', 'repository').'</label>
774 <div class="controls">
775 <input type="text"/>
776 </div>
777 </div>
778 <div class="fp-setlicense control-group clearfix">
779 <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
780 <div class="controls">
781 <select></select>
782 </div>
783 </div>
784 </div>
785 <div class="fp-select-buttons">
786 <button class="fp-select-confirm btn-primary btn">'.get_string('getfile', 'repository').'</button>
787 <button class="fp-select-cancel btn-cancel btn">'.get_string('cancel').'</button>
788 </div>
789 </form>
790 <div class="fp-info clearfix">
791 <div class="fp-hr"></div>
792 <p class="fp-thumbnail"></p>
793 <div class="fp-fileinfo">
794 <div class="fp-datemodified">'.get_string('lastmodified', 'repository').'<span class="fp-value"></span></div>
795 <div class="fp-datecreated">'.get_string('datecreated', 'repository').'<span class="fp-value"></span></div>
796 <div class="fp-size">'.get_string('size', 'repository').'<span class="fp-value"></span></div>
797 <div class="fp-license">'.get_string('license', 'repository').'<span class="fp-value"></span></div>
798 <div class="fp-author">'.get_string('author', 'repository').'<span class="fp-value"></span></div>
799 <div class="fp-dimensions">'.get_string('dimensions', 'repository').'<span class="fp-value"></span></div>
800 </div>
801 <div>
802 </div>';
803 return $rv;
807 * FilePicker JS template for 'Upload file' repository
809 * Content to display when user chooses 'Upload file' repository (will be nested inside
810 * element with class 'fp-content').
812 * Must contain form (enctype="multipart/form-data" method="POST")
814 * The elements with the following classnames must be present:
815 * 'fp-file', 'fp-saveas', 'fp-setauthor', 'fp-setlicense'. Inside each of them must have
816 * one input element (or select in case of fp-setlicense). They may also have labels.
818 * Element with class 'fp-upload-btn' will hold onclick event for uploading the file;
820 * Please note that some fields may be hidden using CSS if this is part of quickupload form
822 * @return string
824 private function fp_js_template_uploadform() {
825 $rv = '
826 <div class="fp-upload-form">
827 <div class="fp-content-center">
828 <form enctype="multipart/form-data" method="POST" class="form-horizontal">
829 <div class="fp-formset">
830 <div class="fp-file control-group clearfix">
831 <label class="control-label">'.get_string('attachment', 'repository').'</label>
832 <div class="controls">
833 <input type="file"/>
834 </div>
835 </div>
836 <div class="fp-saveas control-group clearfix">
837 <label class="control-label">'.get_string('saveas', 'repository').'</label>
838 <div class="controls">
839 <input type="text"/>
840 </div>
841 </div>
842 <div class="fp-setauthor control-group clearfix">
843 <label class="control-label">'.get_string('author', 'repository').'</label>
844 <div class="controls">
845 <input type="text"/>
846 </div>
847 </div>
848 <div class="fp-setlicense control-group clearfix">
849 <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
850 <div class="controls">
851 <select ></select>
852 </div>
853 </div>
854 </div>
855 </form>
856 <div class="mdl-align">
857 <button class="fp-upload-btn btn-primary btn">'.get_string('upload', 'repository').'</button>
858 </div>
859 </div>
860 </div> ';
861 return $rv;
865 * FilePicker JS template to display during loading process (inside element with class 'fp-content').
867 * @return string
869 private function fp_js_template_loading() {
870 return '
871 <div class="fp-content-loading">
872 <div class="fp-content-center">
873 <img src="'.$this->pix_url('i/loading_small').'" />
874 </div>
875 </div>';
879 * FilePicker JS template for error (inside element with class 'fp-content').
881 * must have element with class 'fp-error', its content will be replaced with error text
882 * and the error code will be assigned as additional class to this element
883 * used errors: invalidjson, nofilesavailable, norepositoriesavailable
885 * @return string
887 private function fp_js_template_error() {
888 $rv = '
889 <div class="fp-content-error" ><div class="fp-error"></div></div>';
890 return $rv;
894 * FilePicker JS template for error/info message displayed as a separate popup window.
896 * Must be wrapped in one element, CSS for this element must define
897 * width and height of the window. It will be assigned with an additional class 'fp-msg-error'
898 * or 'fp-msg-info' depending on message type;
900 * content of element with class 'fp-msg-text' will be replaced with error/info text;
902 * element with class 'fp-msg-butok' will hold onclick event
904 * @return string
906 private function fp_js_template_message() {
907 $rv = '
908 <div class="file-picker fp-msg" role="alertdialog" aria-live="assertive" aria-labelledby="fp-msg-labelledby">
909 <p class="fp-msg-text" id="fp-msg-labelledby"></p>
910 <button class="fp-msg-butok btn-primary btn">'.get_string('ok').'</button>
911 </div>';
912 return $rv;
916 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists.
918 * Must have one top element, CSS for this element must define width and height of the window;
920 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
921 * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename',
922 * 'fp-dlg-butoverwriteall', 'fp-dlg-butrenameall' and 'fp-dlg-butcancel' will
923 * hold onclick events;
925 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
926 * (Note that it may have long text)
928 * @return string
930 private function fp_js_template_processexistingfile() {
931 $rv = '
932 <div class="file-picker fp-dlg">
933 <p class="fp-dlg-text"></p>
934 <div class="fp-dlg-buttons">
935 <button class="fp-dlg-butoverwrite btn">'.get_string('overwrite', 'repository').'</button>
936 <button class="fp-dlg-butrename btn"></button>
937 <button class="fp-dlg-butcancel btn btn-cancel">'.get_string('cancel').'</button>
938 </div>
939 </div>';
940 return $rv;
944 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists (multiple-file version).
946 * Must have one top element, CSS for this element must define width and height of the window;
948 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
949 * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename' and 'fp-dlg-butcancel' will
950 * hold onclick events;
952 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
953 * (Note that it may have long text)
955 * @return string
957 private function fp_js_template_processexistingfilemultiple() {
958 $rv = '
959 <div class="file-picker fp-dlg">
960 <p class="fp-dlg-text"></p>
961 <a class="fp-dlg-butoverwrite fp-panel-button" href="#">'.get_string('overwrite', 'repository').'</a>
962 <a class="fp-dlg-butcancel fp-panel-button" href="#">'.get_string('cancel').'</a>
963 <a class="fp-dlg-butrename fp-panel-button" href="#"></a>
964 <br/>
965 <a class="fp-dlg-butoverwriteall fp-panel-button" href="#">'.get_string('overwriteall', 'repository').'</a>
966 <a class="fp-dlg-butrenameall fp-panel-button" href="#">'.get_string('renameall', 'repository').'</a>
967 </div>';
968 return $rv;
972 * FilePicker JS template for repository login form including templates for each element type
974 * Must contain one <form> element with templates for different input types inside:
975 * Elements with classes 'fp-login-popup', 'fp-login-textarea', 'fp-login-select' and
976 * 'fp-login-input' are templates for displaying respective login form elements. Inside
977 * there must be exactly one element with type <button>, <textarea>, <select> or <input>
978 * (i.e. fp-login-popup should have <button>, fp-login-textarea should have <textarea>, etc.);
979 * They may also contain the <label> element and it's content will be substituted with
980 * label;
982 * You can also define elements with classes 'fp-login-checkbox', 'fp-login-text'
983 * but if they are not found, 'fp-login-input' will be used;
985 * Element with class 'fp-login-radiogroup' will be used for group of radio inputs. Inside
986 * it should hava a template for one radio input (with class 'fp-login-radio');
988 * Element with class 'fp-login-submit' will hold on click mouse event (form submission). It
989 * will be removed if at least one popup element is present;
991 * @return string
993 private function fp_js_template_loginform() {
994 $rv = '
995 <div class="fp-login-form">
996 <div class="fp-content-center">
997 <form class="form-horizontal">
998 <div class="fp-formset">
999 <div class="fp-login-popup control-group clearfix">
1000 <div class="controls fp-popup">
1001 <button class="fp-login-popup-but btn-primary btn">'.get_string('login', 'repository').'</button>
1002 </div>
1003 </div>
1004 <div class="fp-login-textarea control-group clearfix">
1005 <div class="controls"><textarea></textarea></div>
1006 </div>
1007 <div class="fp-login-select control-group clearfix">
1008 <label class="control-label"></label>
1010 <div class="controls"><select></select></div>
1011 </div>
1012 <div class="fp-login-input control-group clearfix">
1013 <label class="control-label"></label>
1014 <div class="controls"><input/></div>
1015 </div>
1016 <div class="fp-login-radiogroup control-group clearfix">
1017 <label class="control-label"></label>
1018 <div class="controls fp-login-radio"><input /> <label></label></div>
1019 </div>
1020 </div>
1021 <p><button class="fp-login-submit btn-primary btn">'.get_string('submit', 'repository').'</button></p>
1022 </form>
1023 </div>
1024 </div>';
1025 return $rv;
1029 * Returns all FilePicker JavaScript templates as an array.
1031 * @return array
1033 public function filepicker_js_templates() {
1034 $class_methods = get_class_methods($this);
1035 $templates = array();
1036 foreach ($class_methods as $method_name) {
1037 if (preg_match('/^fp_js_template_(.*)$/', $method_name, $matches))
1038 $templates[$matches[1]] = $this->$method_name();
1040 return $templates;
1044 * Returns HTML for default repository searchform to be passed to Filepicker
1046 * This will be used as contents for search form defined in generallayout template
1047 * (form with id {TOOLSEARCHID}).
1048 * Default contents is one text input field with name="s"
1050 public function repository_default_searchform() {
1051 $searchinput = html_writer::label(get_string('searchrepo', 'repository'),
1052 'reposearch', false, array('class' => 'accesshide'));
1053 $searchinput .= html_writer::empty_tag('input', array('type' => 'text',
1054 'id' => 'reposearch', 'name' => 's', 'value' => get_string('search', 'repository')));
1055 $str = html_writer::tag('div', $searchinput, array('class' => "fp-def-search"));
1057 return $str;
1062 * Data structure representing a general moodle file tree viewer
1064 * @copyright 2010 Dongsheng Cai
1065 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1066 * @since Moodle 2.0
1068 class files_tree_viewer implements renderable {
1069 public $tree;
1070 public $path;
1071 public $context;
1074 * Constructor of moodle_file_tree_viewer class
1075 * @param file_info $file_info
1076 * @param array $options
1078 public function __construct(file_info $file_info, array $options = null) {
1079 global $CFG;
1081 //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
1082 $this->options = (array)$options;
1083 $this->context = $options['context'];
1085 $this->tree = array();
1086 $children = $file_info->get_children();
1087 $current_file_params = $file_info->get_params();
1088 $parent_info = $file_info->get_parent();
1089 $level = $parent_info;
1090 $this->path = array();
1091 while ($level) {
1092 $params = $level->get_params();
1093 $context = context::instance_by_id($params['contextid']);
1094 // $this->context is current context
1095 if ($context->id != $this->context->id or empty($params['filearea'])) {
1096 break;
1098 // unset unused parameters
1099 unset($params['component']);
1100 unset($params['filearea']);
1101 unset($params['filename']);
1102 unset($params['itemid']);
1103 $url = new moodle_url('/files/index.php', $params);
1104 $this->path[] = html_writer::link($url, $level->get_visible_name());
1105 $level = $level->get_parent();
1107 $this->path = array_reverse($this->path);
1108 if ($current_file_params['filepath'] != '/') {
1109 $this->path[] = $file_info->get_visible_name();
1112 foreach ($children as $child) {
1113 $filedate = $child->get_timemodified();
1114 $filesize = $child->get_filesize();
1115 $mimetype = $child->get_mimetype();
1116 $params = $child->get_params();
1117 unset($params['component']);
1118 unset($params['filearea']);
1119 unset($params['filename']);
1120 unset($params['itemid']);
1121 $fileitem = array(
1122 'params' => $params,
1123 'filename' => $child->get_visible_name(),
1124 'mimetype' => $child->get_mimetype(),
1125 'filedate' => $filedate ? $filedate : '',
1126 'filesize' => $filesize ? $filesize : ''
1128 $url = new moodle_url('/files/index.php', $params);
1129 if ($child->is_directory()) {
1130 $fileitem['isdir'] = true;
1131 $fileitem['url'] = $url->out(false);
1132 } else {
1133 $fileitem['url'] = $child->get_url();
1135 $this->tree[] = $fileitem;