weekly release 3.7dev
[moodle.git] / files / renderer.php
CommitLineData
64f93798
PS
1<?php
2///////////////////////////////////////////////////////////////////////////
3// //
4// This file is part of Moodle - http://moodle.org/ //
5// Moodle - Modular Object-Oriented Dynamic Learning Environment //
6// //
7// Moodle is free software: you can redistribute it and/or modify //
8// it under the terms of the GNU General Public License as published by //
9// the Free Software Foundation, either version 3 of the License, or //
10// (at your option) any later version. //
11// //
12// Moodle is distributed in the hope that it will be useful, //
13// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15// GNU General Public License for more details. //
16// //
17// You should have received a copy of the GNU General Public License //
18// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
19// //
20///////////////////////////////////////////////////////////////////////////
21
22defined('MOODLE_INTERNAL') || die();
23
24/**
25 * Rendering of files viewer related widgets.
26 * @package core
27 * @subpackage file
28 * @copyright 2010 Dongsheng Cai
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 * @since Moodle 2.0
31 */
32
33/**
e921afa8 34 * File browser render
64f93798
PS
35 *
36 * @copyright 2010 Dongsheng Cai
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 * @since Moodle 2.0
39 */
40class core_files_renderer extends plugin_renderer_base {
41
42 public function files_tree_viewer(file_info $file_info, array $options = null) {
43 $tree = new files_tree_viewer($file_info, $options);
44 return $this->render($tree);
45 }
46
47 public function render_files_tree_viewer(files_tree_viewer $tree) {
e0873f13 48 $html = $this->output->heading_with_help(get_string('coursefiles'), 'courselegacyfiles', 'moodle');
0b259d91
DC
49
50 $html .= $this->output->container_start('coursefilesbreadcrumb');
64f93798
PS
51 foreach($tree->path as $path) {
52 $html .= $path;
53 $html .= ' / ';
54 }
0b259d91 55 $html .= $this->output->container_end();
64f93798 56
0b259d91
DC
57 $html .= $this->output->box_start();
58 $table = new html_table();
559276b1
MG
59 $table->head = array(get_string('name'), get_string('lastmodified'), get_string('size', 'repository'), get_string('type', 'repository'));
60 $table->align = array('left', 'left', 'left', 'left');
0b259d91
DC
61 $table->width = '100%';
62 $table->data = array();
63
64 foreach ($tree->tree as $file) {
559276b1
MG
65 $filedate = $filesize = $filetype = '';
66 if ($file['filedate']) {
67 $filedate = userdate($file['filedate'], get_string('strftimedatetimeshort', 'langconfig'));
68 }
69 if (empty($file['isdir'])) {
70 if ($file['filesize']) {
71 $filesize = display_size($file['filesize']);
72 }
73 $fileicon = file_file_icon($file, 24);
74 $filetype = get_mimetype_description($file);
0b259d91 75 } else {
559276b1 76 $fileicon = file_folder_icon(24);
64f93798 77 }
559276b1
MG
78 $table->data[] = array(
79 html_writer::link($file['url'], $this->output->pix_icon($fileicon, get_string('icon')) . ' ' . $file['filename']),
80 $filedate,
81 $filesize,
82 $filetype
83 );
64f93798 84 }
0b259d91
DC
85
86 $html .= html_writer::table($table);
e921afa8 87 $html .= $this->output->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid'=>$tree->context->id)), get_string('coursefilesedit'), 'get');
0b259d91 88 $html .= $this->output->box_end();
64f93798
PS
89 return $html;
90 }
906e7d89
MG
91
92 /**
93 * Prints the file manager and initializes all necessary libraries
94 *
95 * <pre>
96 * $fm = new form_filemanager($options);
97 * $output = get_renderer('core', 'files');
98 * echo $output->render($fm);
99 * </pre>
100 *
101 * @param form_filemanager $fm File manager to render
102 * @return string HTML fragment
103 */
d1d18691 104 public function render_form_filemanager($fm) {
d1d18691 105 $html = $this->fm_print_generallayout($fm);
906e7d89
MG
106 $module = array(
107 'name'=>'form_filemanager',
108 'fullpath'=>'/lib/form/filemanager.js',
d61c96b6 109 'requires' => array('moodle-core-notification-dialogue', 'core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'),
4325db53
MG
110 'strings' => array(
111 array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'),
112 array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
9a62f779
MG
113 array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'),
114 array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'),
115 array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'),
7f60308a 116 array('confirmrenamefile', 'repository'), array('newfolder', 'repository'), array('edit', 'moodle')
906e7d89
MG
117 )
118 );
b8459bba 119 if ($this->page->requires->should_create_one_time_item_now('core_file_managertemplate')) {
906e7d89 120 $this->page->requires->js_init_call('M.form_filemanager.set_templates',
e709ddd2 121 array($this->filemanager_js_templates()), true, $module);
906e7d89
MG
122 }
123 $this->page->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module);
124
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>';
129
130
131 return $html;
132 }
133
134 /**
135 * Returns html for displaying one file manager
136 *
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)
147 *
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)
155 *
156 * If browser supports Drag-and-drop, the body element will have class 'dndsupported',
157 * otherwise - 'dndnotsupported';
158 *
e709ddd2
MG
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;
163 *
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;
168 *
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';
906e7d89
MG
174 *
175 * @param form_filemanager $fm
176 * @return string
177 */
88af0208 178 protected function fm_print_generallayout($fm) {
906e7d89
MG
179 global $OUTPUT;
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');
906e7d89
MG
186 $strdroptoupload = get_string('droptoupload', 'moodle');
187 $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';
d1d18691 188 $restrictions = $this->fm_print_restrictions($fm);
a8b418e8 189 $strdndnotsupported = get_string('dndnotsupported_insentence', 'moodle').$OUTPUT->help_icon('dndnotsupported');
906e7d89
MG
190 $strdndenabledinbox = get_string('dndenabled_inbox', 'moodle');
191 $loading = get_string('loading', 'repository');
7eac77a5
BB
192 $straddfiletext = get_string('addfiletext', 'repository');
193 $strcreatefolder = get_string('createfolder', 'repository');
194 $strdownloadallfiles = get_string('downloadallfiles', 'repository');
906e7d89 195
e709ddd2 196 $html = '
ecad7393 197<div id="filemanager-'.$client_id.'" class="filemanager fm-loading">
420e7bb2 198 <div class="fp-restrictions">
e709ddd2 199 '.$restrictions.'
a8b418e8 200 <span class="dnduploadnotsupported-message"> - '.$strdndnotsupported.' </span>
420e7bb2
BR
201 </div>
202 <div class="fp-navbar">
203 <div class="filemanager-toolbar">
420e7bb2 204 <div class="fp-toolbar">
88d366e5 205 <div class="fp-btn-add">
7eac77a5 206 <a role="button" title="' . $straddfile . '" href="#">
663640f5 207 ' . $this->pix_icon('a/add_file', $straddfiletext) . '
7eac77a5 208 </a>
88d366e5
JF
209 </div>
210 <div class="fp-btn-mkdir">
7eac77a5 211 <a role="button" title="' . $strmakedir . '" href="#">
663640f5 212 ' . $this->pix_icon('a/create_folder', $strcreatefolder) . '
7eac77a5 213 </a>
88d366e5
JF
214 </div>
215 <div class="fp-btn-download">
7eac77a5 216 <a role="button" title="' . $strdownload . '" href="#">
663640f5 217 ' . $this->pix_icon('a/download_all', $strdownloadallfiles) . '
7eac77a5 218 </a>
88d366e5 219 </div>
663640f5
DW
220 <span class="fp-img-downloading">
221 ' . $this->pix_icon('i/loading_small', '') . '
222 </span>
420e7bb2 223 </div>
88d366e5
JF
224 <div class="fp-viewbar">
225 <a title="'. get_string('displayicons', 'repository') .'" class="fp-vb-icons" href="#">
663640f5 226 ' . $this->pix_icon('fp/view_icon_active', get_string('displayasicons', 'repository'), 'theme') . '
88d366e5
JF
227 </a>
228 <a title="'. get_string('displaydetails', 'repository') .'" class="fp-vb-details" href="#">
663640f5 229 ' . $this->pix_icon('fp/view_list_active', get_string('displayasdetails', 'repository'), 'theme') . '
88d366e5
JF
230 </a>
231 <a title="'. get_string('displaytree', 'repository') .'" class="fp-vb-tree" href="#">
663640f5 232 ' . $this->pix_icon('fp/view_tree_active', get_string('displayastree', 'repository'), 'theme') . '
88d366e5 233 </a>
b4562710 234 </div>
420e7bb2
BR
235 </div>
236 <div class="fp-pathbar">
88d366e5 237 <span class="fp-path-folder"><a class="fp-path-folder-name" href="#"></a></span>
e709ddd2 238 </div>
906e7d89 239 </div>
0f0d10c5 240 <div class="filemanager-loading mdl-align">'.$icon_progress.'</div>
ecad7393 241 <div class="filemanager-container" >
e709ddd2 242 <div class="fm-content-wrapper">
420e7bb2 243 <div class="fp-content"></div>
19ef00b9 244 <div class="fm-empty-container">
1d747df1 245 <div class="dndupload-message">'.$strdndenabledinbox.'<br/><div class="dndupload-arrow"></div></div>
e709ddd2 246 </div>
1d747df1 247 <div class="dndupload-target">'.$strdroptoupload.'<br/><div class="dndupload-arrow"></div></div>
ead25632 248 <div class="dndupload-progressbars"></div>
e709ddd2 249 <div class="dndupload-uploadinprogress">'.$icon_progress.'</div>
906e7d89 250 </div>
e709ddd2 251 <div class="filemanager-updating">'.$icon_progress.'</div>
906e7d89 252 </div>
420e7bb2 253</div>';
00bc0844 254 return $html;
e709ddd2
MG
255 }
256
257 /**
258 * FileManager JS template for displaying one file in 'icon view' mode.
259 *
23b83009
MG
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
264 * the context menu.
265 *
e709ddd2
MG
266 * @see fp_js_template_iconfilename()
267 * @return string
268 */
88af0208 269 protected function fm_js_template_iconfilename() {
420e7bb2
BR
270 $rv = '
271<div class="fp-file">
272 <a href="#">
9a62f779 273 <div style="position:relative;">
88d366e5 274 <div class="fp-thumbnail"></div>
0f0d10c5
BR
275 <div class="fp-reficons1"></div>
276 <div class="fp-reficons2"></div>
277 </div>
278 <div class="fp-filename-field">
88d366e5 279 <div class="fp-filename"></div>
9a62f779 280 </div>
0f0d10c5 281 </a>
88d366e5 282 <a class="fp-contextmenu" href="#">'.$this->pix_icon('i/menu', '▶').'</a>
23b83009 283</div>';
88d366e5 284 return $rv;
e709ddd2
MG
285 }
286
287 /**
288 * FileManager JS template for displaying file name in 'table view' and 'tree view' modes.
289 *
23b83009
MG
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
294 * the context menu.
295 *
296 * @todo MDL-32736 remove onclick="return false;"
e709ddd2
MG
297 * @see fp_js_template_listfilename()
298 * @return string
299 */
88af0208 300 protected function fm_js_template_listfilename() {
420e7bb2 301 $rv = '
a9352f1f 302<span class="fp-filename-icon">
0f0d10c5 303 <a href="#">
88d366e5 304 <span class="fp-icon"></span>
99f374c4
RT
305 <span class="fp-reficons1"></span>
306 <span class="fp-reficons2"></span>
88d366e5 307 <span class="fp-filename"></span>
0f0d10c5 308 </a>
88d366e5 309 <a class="fp-contextmenu" href="#" onclick="return false;">'.$this->pix_icon('i/menu', '▶').'</a>
420e7bb2 310</span>';
88d366e5 311 return $rv;
e709ddd2
MG
312 }
313
694beb54
MG
314 /**
315 * FileManager JS template for displaying 'Make new folder' dialog.
316 *
317 * Must be wrapped in an element, CSS for this element must define width and height of the window;
318 *
319 * Must have one input element with type="text" (for users to enter the new folder name);
320 *
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;
324 *
325 * @return string
326 */
88af0208 327 protected function fm_js_template_mkdir() {
420e7bb2 328 $rv = '
1641bee2 329<div class="filemanager fp-mkdir-dlg" role="dialog" aria-live="assertive" aria-labelledby="fp-mkdir-dlg-title">
e06bfd3d 330 <div class="fp-mkdir-dlg-text">
1641bee2 331 <label id="fp-mkdir-dlg-title">' . get_string('newfoldername', 'repository') . '</label><br/>
e06bfd3d
MN
332 <input type="text" />
333 </div>
00bc0844
JF
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>
694beb54 336</div>';
88d366e5 337 return $rv;
694beb54
MG
338 }
339
340 /**
341 * FileManager JS template for error/info message displayed as a separate popup window.
342 *
343 * @see fp_js_template_message()
344 * @return string
345 */
88af0208 346 protected function fm_js_template_message() {
694beb54
MG
347 return $this->fp_js_template_message();
348 }
349
e709ddd2
MG
350 /**
351 * FileManager JS template for window with file information/actions.
352 *
55089a9d
MG
353 * All content must be enclosed in one element, CSS for this class must define width and
354 * height of the window;
e709ddd2
MG
355 *
356 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
357 *
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;
363 *
e0ff0867 364 * There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated',
9dbdf31f
MG
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;
e709ddd2 368 *
9a62f779
MG
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';
371 *
9dbdf31f
MG
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>;
376 *
e709ddd2
MG
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');
380 *
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.
383 *
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';
388 *
389 * @return string
390 */
88af0208 391 protected function fm_js_template_fileselectlayout() {
0fb7a8a3 392 global $OUTPUT;
9a62f779 393 $strloading = get_string('loading', 'repository');
88d366e5 394 $iconprogress = $this->pix_icon('i/loading_small', $strloading).'';
420e7bb2
BR
395 $rv = '
396<div class="filemanager fp-select">
397 <div class="fp-select-loading">
663640f5 398 ' . $this->pix_icon('i/loading_small', '') . '
420e7bb2 399 </div>
88d366e5
JF
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>
420e7bb2 407 <div class="fp-hr"></div>
88d366e5
JF
408
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">
413 <input type="text"/>
414 </div>
415 </div>
416 <div class="fp-author control-group clearfix">
417 <label class="control-label">'.get_string('author', 'repository').'</label>
418 <div class="controls">
419 <input type="text"/>
420 </div>
421 </div>
422 <div class="fp-license control-group clearfix">
423 <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
424 <div class="controls">
425 <select></select>
426 </div>
427 </div>
428 <div class="fp-path control-group clearfix">
429 <label class="control-label">'.get_string('path', 'repository').'</label>
430 <div class="controls">
431 <select></select>
432 </div>
433 </div>
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>
438 </div>
439 </div>
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>
446 </div>
447 </div>
448 </div>
af9c48cb 449 <div class="fp-select-buttons">
00bc0844
JF
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>
af9c48cb 452 </div>
4214bc63 453 </form>
c0739778 454 <div class="fp-info clearfix">
af9c48cb 455 <div class="fp-hr"></div>
88d366e5 456 <p class="fp-thumbnail"></p>
af9c48cb 457 <div class="fp-fileinfo">
88d366e5
JF
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>
af9c48cb 462 </div>
420e7bb2 463 </div>
e709ddd2 464</div>';
88d366e5 465 return $rv;
e709ddd2
MG
466 }
467
9a62f779
MG
468 /**
469 * FileManager JS template for popup confirm dialogue window.
470 *
471 * Must have one top element, CSS for this element must define width and height of the window;
472 *
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;
476 *
477 * @return string
478 */
88af0208 479 protected function fm_js_template_confirmdialog() {
420e7bb2
BR
480 $rv = '
481<div class="filemanager fp-dlg">
88d366e5 482 <div class="fp-dlg-text"></div>
00bc0844
JF
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>
9a62f779 485</div>';
88d366e5 486 return $rv;
9a62f779
MG
487 }
488
e709ddd2
MG
489 /**
490 * Returns all FileManager JavaScript templates as an array.
491 *
492 * @return array
493 */
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();
500 }
501 return $templates;
906e7d89
MG
502 }
503
504 /**
505 * Displays restrictions for the file manager
506 *
507 * @param form_filemanager $fm
508 * @return string
509 */
88af0208 510 protected function fm_print_restrictions($fm) {
906e7d89 511 $maxbytes = display_size($fm->options->maxbytes);
21e3ea77
FM
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) {
906e7d89 519 $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam);
21e3ea77
FM
520 } else if ($hasarealimit) {
521 $maxsize = get_string('maxsizeandareasize', 'moodle', $strparam);
522 } else {
523 $maxsize = get_string('maxfilesize', 'moodle', $maxbytes);
906e7d89
MG
524 }
525 // TODO MDL-32020 also should say about 'File types accepted'
21e3ea77 526 return '<span>'. $maxsize . '</span>';
906e7d89 527 }
64f93798 528
d1d18691
MG
529 /**
530 * Template for FilePicker with general layout (not QuickUpload).
531 *
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;
536 *
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';
542 *
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;
548 *
549 * Element with class 'fp-content' is obligatory and will hold the current contents;
550 *
551 * Element with class 'fp-paging' will contain page navigation (will be deprecated soon);
552 *
e709ddd2 553 * Element with class 'fp-path-folder' is a template for one folder in path toolbar.
d1d18691 554 * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully.
d1d18691 555 * Parent element will receive class 'empty' when there are no folders to be displayed;
e709ddd2 556 * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name;
d1d18691
MG
557 *
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;
560 *
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;
570 *
571 * @return string
572 */
88af0208 573 protected function fp_js_template_generallayout() {
d1d18691 574 $rv = '
2eaaae00 575<div tabindex="0" class="file-picker fp-generallayout" role="dialog" aria-live="assertive">
e88d5641 576 <div class="fp-repo-area">
5aeadf0b
AG
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" />&nbsp;
580 <span class="fp-repo-name"></span>
581 </a>
88d366e5 582 </li>
e88d5641 583 </ul>
d1d18691 584 </div>
ee4ab975 585 <div class="fp-repo-items" tabindex="0">
0f0d10c5 586 <div class="fp-navbar">
420e7bb2 587 <div>
88d366e5
JF
588 <div class="fp-toolbar">
589 <div class="fp-tb-back">
590 <a href="#">'.get_string('back', 'repository').'</a>
591 </div>
592 <div class="fp-tb-search">
593 <form></form>
594 </div>
595 <div class="fp-tb-refresh">
596 <a title="'. get_string('refresh', 'repository') .'" href="#">
663640f5 597 ' . $this->pix_icon('a/refresh', '') . '
88d366e5
JF
598 </a>
599 </div>
600 <div class="fp-tb-logout">
601 <a title="'. get_string('logout', 'repository') .'" href="#">
663640f5 602 ' . $this->pix_icon('a/logout', '') . '
88d366e5
JF
603 </a>
604 </div>
605 <div class="fp-tb-manage">
5823a27e 606 <a title="'. get_string('manageurl', 'repository') .'" href="#">
663640f5 607 ' . $this->pix_icon('a/setting', '') . '
88d366e5
JF
608 </a>
609 </div>
610 <div class="fp-tb-help">
611 <a title="'. get_string('help', 'repository') .'" href="#">
663640f5 612 ' . $this->pix_icon('a/help', '') . '
88d366e5
JF
613 </a>
614 </div>
615 <div class="fp-tb-message"></div>
420e7bb2 616 </div>
88d366e5 617 <div class="fp-viewbar">
a34f0a43 618 <a role="button" title="'. get_string('displayicons', 'repository') .'" class="fp-vb-icons" href="#">
663640f5 619 ' . $this->pix_icon('fp/view_icon_active', '', 'theme') . '
88d366e5 620 </a>
a34f0a43 621 <a role="button" title="'. get_string('displaydetails', 'repository') .'" class="fp-vb-details" href="#">
663640f5 622 ' . $this->pix_icon('fp/view_list_active', '', 'theme') . '
88d366e5 623 </a>
a34f0a43 624 <a role="button" title="'. get_string('displaytree', 'repository') .'" class="fp-vb-tree" href="#">
663640f5 625 ' . $this->pix_icon('fp/view_tree_active', '', 'theme') . '
88d366e5 626 </a>
b4562710 627 </div>
6077e381 628 <div class="fp-clear-left"></div>
e88d5641
BR
629 </div>
630 <div class="fp-pathbar">
88d366e5 631 <span class="fp-path-folder"><a class="fp-path-folder-name" href="#"></a></span>
0f0d10c5 632 </div>
d1d18691 633 </div>
88d366e5 634 <div class="fp-content"></div>
d1d18691 635 </div>
d1d18691 636</div>';
88d366e5 637 return $rv;
d1d18691
MG
638 }
639
640 /**
e709ddd2 641 * FilePicker JS template for displaying one file in 'icon view' mode.
d1d18691
MG
642 *
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;
646 *
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;
650 *
e709ddd2
MG
651 * top element(s) will have class fp-folder if the element is a folder;
652 *
653 * List of files will have parent <div> element with class 'fp-iconview'
654 *
d1d18691
MG
655 * @return string
656 */
88af0208 657 protected function fp_js_template_iconfilename() {
420e7bb2
BR
658 $rv = '
659<a class="fp-file" href="#" >
1778f310 660 <div style="position:relative;">
88d366e5 661 <div class="fp-thumbnail"></div>
1778f310
MG
662 <div class="fp-reficons1"></div>
663 <div class="fp-reficons2"></div>
664 </div>
0f0d10c5 665 <div class="fp-filename-field">
88d366e5 666 <p class="fp-filename"></p>
0f0d10c5 667 </div>
e88d5641 668</a>';
88d366e5 669 return $rv;
d1d18691
MG
670 }
671
672 /**
673 * FilePicker JS template for displaying file name in 'table view' and 'tree view' modes.
674 *
675 * content of the element with class 'fp-icon' will be replaced with an appropriate img;
676 *
677 * content of element with class 'fp-filename' will be replaced with filename supplied by
678 * repository;
679 *
e709ddd2
MG
680 * top element(s) will have class fp-folder if the element is a folder;
681 *
d1d18691
MG
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).
685 *
686 * @return string
687 */
88af0208 688 protected function fp_js_template_listfilename() {
a9352f1f
BR
689 $rv = '
690<span class="fp-filename-icon">
691 <a href="#">
88d366e5
JF
692 <span class="fp-icon"></span>
693 <span class="fp-filename"></span>
a9352f1f
BR
694 </a>
695</span>';
88d366e5 696 return $rv;
d1d18691
MG
697 }
698
699 /**
700 * FilePicker JS template for displaying link/loading progress for fetching of the next page
701 *
702 * This text is added to .fp-content AFTER .fp-iconview/.fp-treeview/.fp-tableview
703 *
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.
709 *
710 * @return string
711 */
88af0208 712 protected function fp_js_template_nextpage() {
420e7bb2 713 $rv = '
88d366e5 714<div class="fp-nextpage">
420e7bb2
BR
715 <div class="fp-nextpage-link"><a href="#">'.get_string('more').'</a></div>
716 <div class="fp-nextpage-loading">
663640f5 717 ' . $this->pix_icon('i/loading_small', '') . '
420e7bb2 718 </div>
d1d18691 719</div>';
88d366e5 720 return $rv;
d1d18691
MG
721 }
722
723 /**
e709ddd2 724 * FilePicker JS template for window appearing to select a file.
d1d18691 725 *
55089a9d
MG
726 * All content must be enclosed in one element, CSS for this class must define width and
727 * height of the window;
d1d18691
MG
728 *
729 * Thumbnail image will be added as content to the element with class 'fp-thumbnail';
730 *
731 * Inside the window the elements with the following classnames must be present:
55089a9d
MG
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.
d1d18691
MG
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;
737 *
738 * There may be present elements with classes 'fp-datemodified', 'fp-datecreated', 'fp-size',
e709ddd2
MG
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;
d1d18691
MG
742 *
743 * Elements with classes 'fp-select-confirm' and 'fp-select-cancel' will hold corresponding
744 * onclick events;
745 *
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.
748 *
749 * @return string
750 */
88af0208 751 protected function fp_js_template_selectlayout() {
420e7bb2
BR
752 $rv = '
753<div class="file-picker fp-select">
754 <div class="fp-select-loading">
663640f5 755 ' . $this->pix_icon('i/loading_small', '') . '
420e7bb2 756 </div>
88d366e5
JF
757 <form class="form-horizontal">
758 <div class="fp-forminset">
0d5bfb9c
JF
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">
88d366e5
JF
762 <input type="radio"/>
763 </div>
764 </div>
0d5bfb9c
JF
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">
88d366e5
JF
768 <input type="radio"/>
769 </div>
770 </div>
0d5bfb9c
JF
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">
88d366e5
JF
774 <input type="radio"/>
775 </div>
776 </div>
151b0f94
DW
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"/>
781 </div>
782 </div>
88d366e5
JF
783 <div class="fp-saveas control-group clearfix">
784 <label class="control-label">'.get_string('saveas', 'repository').'</label>
785 <div class="controls">
786 <input type="text"/>
787 </div>
788 </div>
789 <div class="fp-setauthor control-group clearfix">
790 <label class="control-label">'.get_string('author', 'repository').'</label>
791 <div class="controls">
792 <input type="text"/>
793 </div>
794 </div>
795 <div class="fp-setlicense control-group clearfix">
796 <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
797 <div class="controls">
798 <select></select>
799 </div>
800 </div>
801 </div>
802 <div class="fp-select-buttons">
00bc0844
JF
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>
af9c48cb 805 </div>
420e7bb2 806 </form>
c0739778 807 <div class="fp-info clearfix">
af9c48cb 808 <div class="fp-hr"></div>
88d366e5 809 <p class="fp-thumbnail"></p>
af9c48cb 810 <div class="fp-fileinfo">
0d5bfb9c 811 <div class="fp-datemodified">'.get_string('lastmodified', 'repository').'<span class="fp-value"></span></div>
88d366e5
JF
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>
0d5bfb9c 814 <div class="fp-license">'.get_string('license', 'repository').'<span class="fp-value"></span></div>
88d366e5
JF
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>
af9c48cb 817 </div>
04e57ab0 818 </div>
d1d18691 819</div>';
88d366e5 820 return $rv;
d1d18691
MG
821 }
822
823 /**
824 * FilePicker JS template for 'Upload file' repository
825 *
826 * Content to display when user chooses 'Upload file' repository (will be nested inside
827 * element with class 'fp-content').
828 *
829 * Must contain form (enctype="multipart/form-data" method="POST")
830 *
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.
834 *
835 * Element with class 'fp-upload-btn' will hold onclick event for uploading the file;
836 *
837 * Please note that some fields may be hidden using CSS if this is part of quickupload form
838 *
839 * @return string
840 */
88af0208 841 protected function fp_js_template_uploadform() {
420e7bb2 842 $rv = '
88d366e5 843<div class="fp-upload-form">
0f0d10c5 844 <div class="fp-content-center">
88d366e5
JF
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">
850 <input type="file"/>
851 </div>
852 </div>
853 <div class="fp-saveas control-group clearfix">
854 <label class="control-label">'.get_string('saveas', 'repository').'</label>
855 <div class="controls">
856 <input type="text"/>
857 </div>
858 </div>
859 <div class="fp-setauthor control-group clearfix">
860 <label class="control-label">'.get_string('author', 'repository').'</label>
861 <div class="controls">
862 <input type="text"/>
863 </div>
864 </div>
865 <div class="fp-setlicense control-group clearfix">
866 <label class="control-label">'.get_string('chooselicense', 'repository').'</label>
867 <div class="controls">
868 <select ></select>
869 </div>
870 </div>
871 </div>
420e7bb2 872 </form>
88d366e5 873 <div class="mdl-align">
00bc0844 874 <button class="fp-upload-btn btn-primary btn">'.get_string('upload', 'repository').'</button>
88d366e5 875 </div>
420e7bb2 876 </div>
d1d18691 877</div> ';
88d366e5 878 return $rv;
d1d18691
MG
879 }
880
881 /**
882 * FilePicker JS template to display during loading process (inside element with class 'fp-content').
883 *
884 * @return string
885 */
88af0208 886 protected function fp_js_template_loading() {
420e7bb2 887 return '
0f0d10c5
BR
888<div class="fp-content-loading">
889 <div class="fp-content-center">
663640f5 890 ' . $this->pix_icon('i/loading_small', '') . '
0f0d10c5 891 </div>
d1d18691
MG
892</div>';
893 }
894
895 /**
896 * FilePicker JS template for error (inside element with class 'fp-content').
897 *
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
901 *
902 * @return string
903 */
88af0208 904 protected function fp_js_template_error() {
420e7bb2 905 $rv = '
88d366e5
JF
906<div class="fp-content-error" ><div class="fp-error"></div></div>';
907 return $rv;
d1d18691
MG
908 }
909
910 /**
911 * FilePicker JS template for error/info message displayed as a separate popup window.
912 *
9a62f779 913 * Must be wrapped in one element, CSS for this element must define
d1d18691
MG
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;
916 *
917 * content of element with class 'fp-msg-text' will be replaced with error/info text;
918 *
919 * element with class 'fp-msg-butok' will hold onclick event
920 *
921 * @return string
922 */
88af0208 923 protected function fp_js_template_message() {
420e7bb2 924 $rv = '
f26cc2be 925<div class="file-picker fp-msg" role="alertdialog" aria-live="assertive" aria-labelledby="fp-msg-labelledby">
88d366e5 926 <p class="fp-msg-text" id="fp-msg-labelledby"></p>
00bc0844 927 <button class="fp-msg-butok btn-primary btn">'.get_string('ok').'</button>
420e7bb2 928</div>';
88d366e5 929 return $rv;
d1d18691
MG
930 }
931
932 /**
933 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists.
934 *
9a62f779 935 * Must have one top element, CSS for this element must define width and height of the window;
d1d18691
MG
936 *
937 * content of element with class 'fp-dlg-text' will be replaced with dialog text;
d0b2d445
DS
938 * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename',
939 * 'fp-dlg-butoverwriteall', 'fp-dlg-butrenameall' and 'fp-dlg-butcancel' will
d1d18691
MG
940 * hold onclick events;
941 *
942 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
943 * (Note that it may have long text)
944 *
945 * @return string
946 */
88af0208 947 protected function fp_js_template_processexistingfile() {
420e7bb2
BR
948 $rv = '
949<div class="file-picker fp-dlg">
88d366e5 950 <p class="fp-dlg-text"></p>
af9c48cb 951 <div class="fp-dlg-buttons">
00bc0844
JF
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>
af9c48cb 955 </div>
d1d18691 956</div>';
88d366e5 957 return $rv;
d1d18691 958 }
0f0d10c5 959
d0b2d445
DS
960 /**
961 * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists (multiple-file version).
962 *
963 * Must have one top element, CSS for this element must define width and height of the window;
964 *
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;
968 *
969 * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string
970 * (Note that it may have long text)
971 *
972 * @return string
973 */
88af0208 974 protected function fp_js_template_processexistingfilemultiple() {
d0b2d445
DS
975 $rv = '
976<div class="file-picker fp-dlg">
88d366e5
JF
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>
b8a22d22 981 <br/>
88d366e5
JF
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>
d0b2d445 984</div>';
88d366e5 985 return $rv;
d0b2d445
DS
986 }
987
d1d18691
MG
988 /**
989 * FilePicker JS template for repository login form including templates for each element type
990 *
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
997 * label;
998 *
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;
1001 *
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');
1004 *
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;
1007 *
1008 * @return string
1009 */
88af0208 1010 protected function fp_js_template_loginform() {
d1d18691
MG
1011 $rv = '
1012<div class="fp-login-form">
420e7bb2 1013 <div class="fp-content-center">
88d366e5
JF
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">
00bc0844 1018 <button class="fp-login-popup-but btn-primary btn">'.get_string('login', 'repository').'</button>
88d366e5
JF
1019 </div>
1020 </div>
1021 <div class="fp-login-textarea control-group clearfix">
1022 <div class="controls"><textarea></textarea></div>
1023 </div>
1024 <div class="fp-login-select control-group clearfix">
1025 <label class="control-label"></label>
1026
1027 <div class="controls"><select></select></div>
f209d5e1 1028 </div>';
f209d5e1 1029 $rv .= '
88d366e5
JF
1030 <div class="fp-login-input control-group clearfix">
1031 <label class="control-label"></label>
1032 <div class="controls"><input/></div>
1033 </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>
1037 </div>
1038 </div>
00bc0844 1039 <p><button class="fp-login-submit btn-primary btn">'.get_string('submit', 'repository').'</button></p>
420e7bb2
BR
1040 </form>
1041 </div>
d1d18691 1042</div>';
88d366e5 1043 return $rv;
d1d18691
MG
1044 }
1045
1046 /**
1047 * Returns all FilePicker JavaScript templates as an array.
1048 *
1049 * @return array
1050 */
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();
1057 }
1058 return $templates;
1059 }
1060
1061 /**
1062 * Returns HTML for default repository searchform to be passed to Filepicker
1063 *
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"
1067 */
1068 public function repository_default_searchform() {
4bde1152
RW
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"));
1074
d1d18691
MG
1075 return $str;
1076 }
1077}
64f93798
PS
1078
1079/**
1080 * Data structure representing a general moodle file tree viewer
1081 *
1082 * @copyright 2010 Dongsheng Cai
1083 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1084 * @since Moodle 2.0
1085 */
1086class files_tree_viewer implements renderable {
1087 public $tree;
1088 public $path;
e921afa8 1089 public $context;
64f93798
PS
1090
1091 /**
1092 * Constructor of moodle_file_tree_viewer class
1093 * @param file_info $file_info
1094 * @param array $options
1095 */
1096 public function __construct(file_info $file_info, array $options = null) {
1097 global $CFG;
1098
1099 //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
64f93798 1100 $this->options = (array)$options;
e921afa8
DC
1101 $this->context = $options['context'];
1102
64f93798
PS
1103 $this->tree = array();
1104 $children = $file_info->get_children();
0b259d91 1105 $current_file_params = $file_info->get_params();
64f93798 1106 $parent_info = $file_info->get_parent();
64f93798
PS
1107 $level = $parent_info;
1108 $this->path = array();
1109 while ($level) {
1110 $params = $level->get_params();
d197ea43 1111 $context = context::instance_by_id($params['contextid']);
0b259d91
DC
1112 // $this->context is current context
1113 if ($context->id != $this->context->id or empty($params['filearea'])) {
64f93798
PS
1114 break;
1115 }
e921afa8
DC
1116 // unset unused parameters
1117 unset($params['component']);
1118 unset($params['filearea']);
0b259d91 1119 unset($params['filename']);
e921afa8 1120 unset($params['itemid']);
64f93798 1121 $url = new moodle_url('/files/index.php', $params);
e921afa8 1122 $this->path[] = html_writer::link($url, $level->get_visible_name());
64f93798
PS
1123 $level = $level->get_parent();
1124 }
1125 $this->path = array_reverse($this->path);
0b259d91
DC
1126 if ($current_file_params['filepath'] != '/') {
1127 $this->path[] = $file_info->get_visible_name();
1128 }
64f93798
PS
1129
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();
0b259d91
DC
1135 unset($params['component']);
1136 unset($params['filearea']);
1137 unset($params['filename']);
1138 unset($params['itemid']);
64f93798
PS
1139 $fileitem = array(
1140 'params' => $params,
1141 'filename' => $child->get_visible_name(),
559276b1
MG
1142 'mimetype' => $child->get_mimetype(),
1143 'filedate' => $filedate ? $filedate : '',
1144 'filesize' => $filesize ? $filesize : ''
64f93798 1145 );
e921afa8 1146 $url = new moodle_url('/files/index.php', $params);
64f93798
PS
1147 if ($child->is_directory()) {
1148 $fileitem['isdir'] = true;
1149 $fileitem['url'] = $url->out(false);
64f93798
PS
1150 } else {
1151 $fileitem['url'] = $child->get_url();
1152 }
1153 $this->tree[] = $fileitem;
1154 }
1155 }
1156}