Commit | Line | Data |
---|---|---|
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 | ||
22 | defined('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 | */ | |
40 | class 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(); | |
276943d4 DC |
59 | $table->head = array(get_string('filename', 'backup'), get_string('size'), get_string('modified')); |
60 | $table->align = array('left', 'right', 'right'); | |
0b259d91 DC |
61 | $table->width = '100%'; |
62 | $table->data = array(); | |
63 | ||
64 | foreach ($tree->tree as $file) { | |
65 | if (!empty($file['isdir'])) { | |
66 | $table->data[] = array( | |
67 | html_writer::link($file['url'], $this->output->pix_icon('f/folder', 'icon') . ' ' . $file['filename']), | |
0b259d91 | 68 | '', |
276943d4 | 69 | $file['filedate'], |
0b259d91 DC |
70 | ); |
71 | } else { | |
72 | $table->data[] = array( | |
73 | html_writer::link($file['url'], $this->output->pix_icon('f/'.mimeinfo('icon', $file['filename']), get_string('icon')) . ' ' . $file['filename']), | |
276943d4 | 74 | $file['filesize'], |
0b259d91 | 75 | $file['filedate'], |
0b259d91 | 76 | ); |
64f93798 | 77 | } |
64f93798 | 78 | } |
0b259d91 DC |
79 | |
80 | $html .= html_writer::table($table); | |
e921afa8 | 81 | $html .= $this->output->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid'=>$tree->context->id)), get_string('coursefilesedit'), 'get'); |
0b259d91 | 82 | $html .= $this->output->box_end(); |
64f93798 PS |
83 | return $html; |
84 | } | |
906e7d89 MG |
85 | |
86 | /** | |
87 | * Prints the file manager and initializes all necessary libraries | |
88 | * | |
89 | * <pre> | |
90 | * $fm = new form_filemanager($options); | |
91 | * $output = get_renderer('core', 'files'); | |
92 | * echo $output->render($fm); | |
93 | * </pre> | |
94 | * | |
95 | * @param form_filemanager $fm File manager to render | |
96 | * @return string HTML fragment | |
97 | */ | |
d1d18691 | 98 | public function render_form_filemanager($fm) { |
906e7d89 | 99 | static $filemanagertemplateloaded; |
d1d18691 | 100 | $html = $this->fm_print_generallayout($fm); |
906e7d89 MG |
101 | $module = array( |
102 | 'name'=>'form_filemanager', | |
103 | 'fullpath'=>'/lib/form/filemanager.js', | |
104 | 'requires' => array('core_filepicker', 'base', 'io-base', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview', 'core_dndupload'), | |
105 | 'strings' => array(array('loading', 'repository'), array('nomorefiles', 'repository'), array('confirmdeletefile', 'repository'), | |
106 | array('add', 'repository'), array('accessiblefilepicker', 'repository'), array('move', 'moodle'), | |
107 | array('cancel', 'moodle'), array('download', 'moodle'), array('ok', 'moodle'), | |
108 | array('emptylist', 'repository'), array('nofilesattached', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'), | |
109 | array('zip', 'editor'), array('unzip', 'moodle'), array('rename', 'moodle'), array('delete', 'moodle'), | |
110 | array('cannotdeletefile', 'error'), array('confirmdeletefile', 'repository'), | |
111 | array('nopathselected', 'repository'), array('popupblockeddownload', 'repository'), | |
112 | array('draftareanofiles', 'repository'), array('path', 'moodle'), array('setmainfile', 'repository'), | |
113 | array('moving', 'repository'), array('files', 'moodle'), array('serverconnection', 'error') | |
114 | ) | |
115 | ); | |
116 | if (empty($filemanagertemplateloaded)) { | |
117 | $filemanagertemplateloaded = true; | |
118 | $this->page->requires->js_init_call('M.form_filemanager.set_templates', | |
e709ddd2 | 119 | array($this->filemanager_js_templates()), true, $module); |
906e7d89 MG |
120 | } |
121 | $this->page->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module); | |
122 | ||
123 | // non javascript file manager | |
124 | $html .= '<noscript>'; | |
125 | $html .= "<div><object type='text/html' data='".$fm->get_nonjsurl()."' height='160' width='600' style='border:1px solid #000'></object></div>"; | |
126 | $html .= '</noscript>'; | |
127 | ||
128 | ||
129 | return $html; | |
130 | } | |
131 | ||
132 | /** | |
133 | * Returns html for displaying one file manager | |
134 | * | |
135 | * The main element in HTML must have id="filemanager-{$client_id}" and | |
136 | * class="filemanager fm-loading"; | |
137 | * After all necessary code on the page (both html and javascript) is loaded, | |
138 | * the class fm-loading will be removed and added class fm-loaded; | |
139 | * The main element (class=filemanager) will be assigned the following classes: | |
140 | * 'fm-maxfiles' - when filemanager has maximum allowed number of files; | |
141 | * 'fm-nofiles' - when filemanager has no files at all (although there might be folders); | |
142 | * 'fm-noitems' - when current view (folder) has no items - neither files nor folders; | |
143 | * 'fm-updating' - when current view is being updated (usually means that loading icon is to be displayed); | |
144 | * 'fm-nomkdir' - when 'Make folder' action is unavailable (empty($fm->options->subdirs) == true) | |
145 | * | |
146 | * Element with class 'filemanager-container' will be holding evens for dnd upload (dragover, etc.). | |
147 | * It will have class: | |
148 | * 'dndupload-ready' - when a file is being dragged over the browser | |
149 | * 'dndupload-over' - when file is being dragged over this filepicker (additional to 'dndupload-ready') | |
150 | * 'dndupload-uploading' - during the upload process (note that after dnd upload process is | |
151 | * over, the file manager will refresh the files list and therefore will have for a while class | |
152 | * fm-updating. Both waiting processes should look similar so the images don't jump for user) | |
153 | * | |
154 | * If browser supports Drag-and-drop, the body element will have class 'dndsupported', | |
155 | * otherwise - 'dndnotsupported'; | |
156 | * | |
e709ddd2 MG |
157 | * Element with class 'fp-content' will be populated with files list; |
158 | * Element with class 'fp-btn-add' will hold onclick event for adding a file (opening filepicker); | |
159 | * Element with class 'fp-btn-mkdir' will hold onclick event for adding new folder; | |
160 | * Element with class 'fp-btn-download' will hold onclick event for download action; | |
161 | * | |
162 | * Element with class 'fp-path-folder' is a template for one folder in path toolbar. | |
163 | * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully. | |
164 | * Parent element will receive class 'empty' when there are no folders to be displayed; | |
165 | * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name; | |
166 | * | |
167 | * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode | |
168 | * can be changed or not; | |
169 | * Inside element with class 'fp-viewbar' there are expected elements with classes | |
170 | * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch | |
171 | * between the view modes, the last clicked element will have the class 'checked'; | |
906e7d89 MG |
172 | * |
173 | * @param form_filemanager $fm | |
174 | * @return string | |
175 | */ | |
d1d18691 | 176 | private function fm_print_generallayout($fm) { |
906e7d89 MG |
177 | global $OUTPUT; |
178 | $options = $fm->options; | |
179 | $client_id = $options->client_id; | |
180 | $straddfile = get_string('addfile', 'repository'); | |
181 | $strmakedir = get_string('makeafolder', 'moodle'); | |
182 | $strdownload = get_string('downloadfolder', 'repository'); | |
183 | $strloading = get_string('loading', 'repository'); | |
184 | $strnofilesattached = get_string('nofilesattached', 'repository'); | |
185 | $strdroptoupload = get_string('droptoupload', 'moodle'); | |
186 | $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).''; | |
d1d18691 | 187 | $restrictions = $this->fm_print_restrictions($fm); |
906e7d89 MG |
188 | $strdndenabled = get_string('dndenabled_insentence', 'moodle').$OUTPUT->help_icon('dndenabled'); |
189 | $strdndenabledinbox = get_string('dndenabled_inbox', 'moodle'); | |
190 | $loading = get_string('loading', 'repository'); | |
191 | ||
e709ddd2 MG |
192 | $html = ' |
193 | <div id="filemanager-'.$client_id.'" class="filemanager fm-loading"> | |
194 | <div class="filemanager-loading mdl-align">'.$icon_progress.'</div> | |
195 | <div class="fp-pathbar"> | |
196 | <span class="{!}fp-path-folder"><a class="{!}fp-path-folder-name"></a><span>/</span></span> | |
197 | </div> | |
906e7d89 | 198 | <div class="filemanager-toolbar"> |
e709ddd2 MG |
199 | <input type="button" class="{!}fp-btn-add" value="'.$straddfile.'" /> |
200 | <input type="button" class="{!}fp-btn-mkdir" value="'.$strmakedir.'" /> | |
201 | <input type="button" class="{!}fp-btn-download" value="'.$strdownload.'" /> | |
202 | '.$restrictions.' | |
203 | <span class="dndupload-message"> - '.$strdndenabled.' </span> | |
204 | <div class="{!}fp-viewbar" style="float:none;"> | |
205 | <span class=""><button class="{!}fp-vb-icons">'.get_string('iconview', 'repository').'</button></span> | |
206 | <span class=""><button class="{!}fp-vb-tree">'.get_string('listview', 'repository').'</button></span> | |
207 | <span class=""><button class="{!}fp-vb-details">'.get_string('detailview', 'repository').'</button></span> | |
208 | </div> | |
906e7d89 MG |
209 | </div> |
210 | <div class="filemanager-container" > | |
e709ddd2 MG |
211 | <div class="fm-content-wrapper"> |
212 | <ul class="fp-content"></ul> | |
213 | <div class="fm-empty-container mdl-align">'.$strnofilesattached.' | |
214 | <span class="dndupload-message">'.$strdndenabledinbox.'</span> | |
215 | </div> | |
216 | <div class="dndupload-target">'.$strdroptoupload.'</div> | |
217 | <div class="dndupload-uploadinprogress">'.$icon_progress.'</div> | |
906e7d89 | 218 | </div> |
e709ddd2 | 219 | <div class="filemanager-updating">'.$icon_progress.'</div> |
906e7d89 MG |
220 | </div> |
221 | </div> | |
222 | <div class="clearer"></div> | |
e709ddd2 MG |
223 | '; |
224 | return preg_replace('/\{\!\}/', '', $html); | |
225 | } | |
226 | ||
227 | /** | |
228 | * FileManager JS template for displaying one file in 'icon view' mode. | |
229 | * | |
230 | * @see fp_js_template_iconfilename() | |
231 | * @return string | |
232 | */ | |
233 | private function fm_js_template_iconfilename() { | |
234 | return $this->fp_js_template_iconfilename(); | |
235 | } | |
236 | ||
237 | /** | |
238 | * FileManager JS template for displaying file name in 'table view' and 'tree view' modes. | |
239 | * | |
240 | * @see fp_js_template_listfilename() | |
241 | * @return string | |
242 | */ | |
243 | private function fm_js_template_listfilename() { | |
244 | return $this->fp_js_template_listfilename(); | |
245 | } | |
246 | ||
247 | /** | |
248 | * FileManager JS template for window with file information/actions. | |
249 | * | |
250 | * All content must be enclosed in an element with class 'fp-select', CSS for this class | |
251 | * must define width and height of the window; | |
252 | * | |
253 | * Thumbnail image will be added as content to the element with class 'fp-thumbnail'; | |
254 | * | |
255 | * Inside the window the elements with the following classnames must be present: | |
256 | * 'fp-saveas', 'fp-author', 'fp-license', 'fp-path'. Inside each of them must be | |
257 | * one input element (or select in case of fp-license and fp-path). They may also have labels. | |
258 | * The elements will be assign with class 'uneditable' and input/select element will become | |
259 | * disabled if they are not applicable for the particular file; | |
260 | * | |
261 | * There may be present elements with classes 'fp-origpath', 'fp-datemodified', 'fp-datecreated', | |
262 | * 'fp-size', 'fp-dimensions'. They will receive additional class 'fp-unknown' if information | |
263 | * is unavailable. If there is information available, the content of embedded element | |
264 | * with class 'fp-value' will be substituted with the value; | |
265 | * | |
266 | * Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip', | |
267 | * 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick | |
268 | * events (there may be several elements with class 'fp-file-cancel'); | |
269 | * | |
270 | * When confirm button is pressed and file is being selected, the top element receives | |
271 | * additional class 'loading'. It is removed when response from server is received. | |
272 | * | |
273 | * When any of the input fields is changed, the top element receives class 'fp-changed'; | |
274 | * When current file can be set as main - top element receives class 'fp-cansetmain'; | |
275 | * When current file is folder/zip/file - top element receives respectfully class | |
276 | * 'fp-folder'/'fp-zip'/'fp-file'; | |
277 | * | |
278 | * @return string | |
279 | */ | |
280 | private function fm_js_template_fileselectlayout() { | |
281 | $rv = '<div class="{!}fp-select"> | |
282 | <div class="fp-select-loading"> | |
283 | <img src="'.$this->pix_url('i/loading').'" /> | |
284 | <p>'.get_string('loading', 'repository').'</p> | |
285 | </div> | |
286 | <form> | |
287 | <p class="{!}fp-thumbnail"></p> | |
288 | <table width="100%"> | |
289 | <tr class="{!}fp-saveas"><td class="mdl-right"><label>'.get_string('name', 'moodle').'</label>:</td> | |
290 | <td class="mdl-left"><input type="text"/></td></tr> | |
291 | <tr class="{!}fp-author"><td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td> | |
292 | <td class="mdl-left"><input type="text" /></td></tr> | |
293 | <tr class="{!}fp-license"><td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td> | |
294 | <td class="mdl-left"><select></select></td></tr> | |
295 | <tr class="{!}fp-path"><td class="mdl-right"><label>'.get_string('path', 'moodle').'</label>:</td> | |
296 | <td class="mdl-left"><select></select></td></tr> | |
297 | <tr class="{!}fp-origpath"><td class="mdl-right"><label>'.get_string('originalpath', 'moodle').'</label>:</td> | |
298 | <td class="mdl-left"><span class="fp-value"/></td></tr> | |
299 | </table> | |
300 | <p><button class="{!}fp-file-update" >'.get_string('update', 'moodle').'</button> | |
301 | <button class="{!}fp-file-download" >'.get_string('download').'</button> | |
302 | <button class="{!}fp-file-delete" >'.get_string('delete').'</button> | |
303 | <button class="{!}fp-file-zip" >'.get_string('zip', 'editor').'</button> | |
304 | <button class="{!}fp-file-unzip" >'.get_string('unzip').'</button> | |
305 | <button class="{!}fp-file-setmain" >'.get_string('setmainfile', 'repository').'</button> | |
306 | <button class="{!}fp-file-cancel" >'.get_string('cancel').'</button> | |
307 | </p> | |
308 | </form> | |
309 | <div class="{!}fp-datemodified">'.get_string('lastmodified', 'moodle').': <span class="fp-value"/></div> | |
310 | <div class="{!}fp-datecreated">'.get_string('datecreated', 'repository').': <span class="fp-value"/></div> | |
311 | <div class="{!}fp-size">'.get_string('size', 'repository').': <span class="fp-value"/></div> | |
312 | <div class="{!}fp-dimensions">'.get_string('dimensions', 'repository').': <span class="fp-value"/></div> | |
313 | </div>'; | |
314 | return preg_replace('/\{\!\}/', '', $rv); | |
315 | } | |
316 | ||
317 | /** | |
318 | * Returns all FileManager JavaScript templates as an array. | |
319 | * | |
320 | * @return array | |
321 | */ | |
322 | public function filemanager_js_templates() { | |
323 | $class_methods = get_class_methods($this); | |
324 | $templates = array(); | |
325 | foreach ($class_methods as $method_name) { | |
326 | if (preg_match('/^fm_js_template_(.*)$/', $method_name, $matches)) | |
327 | $templates[$matches[1]] = $this->$method_name(); | |
328 | } | |
329 | return $templates; | |
906e7d89 MG |
330 | } |
331 | ||
332 | /** | |
333 | * Displays restrictions for the file manager | |
334 | * | |
335 | * @param form_filemanager $fm | |
336 | * @return string | |
337 | */ | |
d1d18691 | 338 | private function fm_print_restrictions($fm) { |
906e7d89 MG |
339 | $maxbytes = display_size($fm->options->maxbytes); |
340 | if (empty($options->maxfiles) || $options->maxfiles == -1) { | |
341 | $maxsize = get_string('maxfilesize', 'moodle', $maxbytes); | |
342 | //$string['maxfilesize'] = 'Maximum size for new files: {$a}'; | |
343 | } else { | |
344 | $strparam = (object)array('size' => $maxbytes, 'attachments' => $options->maxfiles); | |
345 | $maxsize = get_string('maxsizeandattachments', 'moodle', $strparam); | |
346 | //$string['maxsizeandattachments'] = 'Maximum size for new files: {$a->size}, maximum attachments: {$a->attachments}'; | |
347 | } | |
348 | // TODO MDL-32020 also should say about 'File types accepted' | |
349 | return '<span>'. $maxsize. '</span>'; | |
350 | } | |
64f93798 | 351 | |
d1d18691 MG |
352 | /** |
353 | * Template for FilePicker with general layout (not QuickUpload). | |
354 | * | |
355 | * Must have one top element containing everything else (recommended <div class="file-picker">), | |
356 | * CSS for this element must define width and height of the filepicker window. Or CSS must | |
357 | * define min-width, max-width, min-height and max-height and in this case the filepicker | |
358 | * window will be resizeable; | |
359 | * | |
360 | * Element with class 'fp-viewbar' will have the class 'enabled' or 'disabled' when view mode | |
361 | * can be changed or not; | |
362 | * Inside element with class 'fp-viewbar' there are expected elements with classes | |
363 | * 'fp-vb-icons', 'fp-vb-tree' and 'fp-vb-details'. They will handle onclick events to switch | |
364 | * between the view modes, the last clicked element will have the class 'checked'; | |
365 | * | |
366 | * Element with class 'fp-repo' is a template for displaying one repository. Other repositories | |
367 | * will be attached as siblings (classes first/last/even/odd will be added respectfully). | |
368 | * The currently selected repostory will have class 'active'. Contents of element with class | |
369 | * 'fp-repo-name' will be replaced with repository name, source of image with class | |
370 | * 'fp-repo-icon' will be replaced with repository icon; | |
371 | * | |
372 | * Element with class 'fp-content' is obligatory and will hold the current contents; | |
373 | * | |
374 | * Element with class 'fp-paging' will contain page navigation (will be deprecated soon); | |
375 | * | |
e709ddd2 | 376 | * Element with class 'fp-path-folder' is a template for one folder in path toolbar. |
d1d18691 | 377 | * It will hold mouse click event and will be assigned classes first/last/even/odd respectfully. |
d1d18691 | 378 | * Parent element will receive class 'empty' when there are no folders to be displayed; |
e709ddd2 | 379 | * The content of subelement with class 'fp-path-folder-name' will be substituted with folder name; |
d1d18691 MG |
380 | * |
381 | * Element with class 'fp-toolbar' will have class 'empty' if all 'Back', 'Search', 'Refresh', | |
382 | * 'Logout', 'Manage' and 'Help' are unavailable for this repo; | |
383 | * | |
384 | * Inside fp-toolbar there are expected elements with classes fp-tb-back, fp-tb-search, | |
385 | * fp-tb-refresh, fp-tb-logout, fp-tb-manage and fp-tb-help. Each of them will have | |
386 | * class 'enabled' or 'disabled' if particular repository has this functionality. | |
387 | * Element with class 'fp-tb-search' must contain empty form inside, it's contents will | |
388 | * be substituted with the search form returned by repository (in the most cases it | |
389 | * is generated with template core_repository_renderer::repository_default_searchform); | |
390 | * Other elements must have either <a> or <button> element inside, it will hold onclick | |
391 | * event for corresponding action; labels for fp-tb-back and fp-tb-logout may be | |
392 | * replaced with those specified by repository; | |
393 | * | |
394 | * @return string | |
395 | */ | |
396 | private function fp_js_template_generallayout() { | |
397 | $rv = ' | |
398 | <div class="file-picker fp-generallayout"> | |
399 | <div> | |
400 | <div class="{!}fp-viewbar" style="float:none;"> | |
401 | <span class=""><button class="{!}fp-vb-icons">'.get_string('iconview', 'repository').'</button></span> | |
402 | <span class=""><button class="{!}fp-vb-tree">'.get_string('listview', 'repository').'</button></span> | |
403 | <span class=""><button class="{!}fp-vb-details">'.get_string('detailview', 'repository').'</button></span> | |
404 | </div> | |
405 | </div> | |
406 | <div style="vertical-align:top;"> | |
407 | <div style="width:200px;height:400px;display:inline-block;overflow:auto;"> | |
408 | <ul class="fp-list"> | |
409 | <li class="{!}fp-repo"><img class="{!}fp-repo-icon" width="16" height="16" /> <span class="{!}fp-repo-name"></span></li> | |
410 | </ul> | |
411 | </div> | |
412 | <div style="width:480px;height:400px;display:inline-block;vertical-align:top;"> | |
413 | <div class="{!}fp-toolbar"> | |
414 | <div class="{!}fp-tb-back"><a>'.get_string('back', 'repository').'</a></div> | |
415 | <div class="{!}fp-tb-search"> | |
416 | <img src="'.$this->pix_url('a/search').'" /> | |
417 | <form/> | |
418 | </div> | |
419 | <div class="{!}fp-tb-refresh"><a><img src="'.$this->pix_url('a/refresh').'" />'.get_string('refresh', 'repository').'</a></div> | |
420 | <div class="{!}fp-tb-logout"><img src="'.$this->pix_url('a/logout').'" /><a></a></div> | |
421 | <div class="{!}fp-tb-manage"><a><img src="'.$this->pix_url('a/setting').'" /> '.get_string('manageurl', 'repository').'</a></div> | |
422 | <div class="{!}fp-tb-help"><a><img src="'.$this->pix_url('a/help').'" /> '.get_string('help').'</a></div> | |
423 | </div> | |
424 | <div class="fp-pathbar" style="background:#ddffdd"> | |
425 | <span class="{!}fp-path-folder"><a class="{!}fp-path-folder-name"></a><span>/</span></span> | |
426 | </div> | |
427 | <div class="{!}fp-content"></div> | |
428 | </div> | |
429 | </div> | |
430 | </div>'; | |
431 | return preg_replace('/\{\!\}/', '', $rv); | |
432 | } | |
433 | ||
434 | /** | |
e709ddd2 | 435 | * FilePicker JS template for displaying one file in 'icon view' mode. |
d1d18691 MG |
436 | * |
437 | * the element with class 'fp-thumbnail' will be resized to the repository thumbnail size | |
438 | * (both width and height, unless min-width and/or min-height is set in CSS) and the content of | |
439 | * an element will be replaced with an appropriate img; | |
440 | * | |
441 | * the width of element with class 'fp-filename' will be set to the repository thumbnail width | |
442 | * (unless min-width is set in css) and the content of an element will be replaced with filename | |
443 | * supplied by repository; | |
444 | * | |
e709ddd2 MG |
445 | * top element(s) will have class fp-folder if the element is a folder; |
446 | * | |
447 | * List of files will have parent <div> element with class 'fp-iconview' | |
448 | * | |
d1d18691 MG |
449 | * @return string |
450 | */ | |
e709ddd2 MG |
451 | private function fp_js_template_iconfilename() { |
452 | $rv = '<div class="fp-file"> | |
d1d18691 MG |
453 | <div class="{!}fp-thumbnail"></div> |
454 | <div class="{!}fp-filename"></div> | |
e709ddd2 | 455 | </div>'; |
d1d18691 MG |
456 | return preg_replace('/\{\!\}/', '', $rv); |
457 | } | |
458 | ||
459 | /** | |
460 | * FilePicker JS template for displaying file name in 'table view' and 'tree view' modes. | |
461 | * | |
462 | * content of the element with class 'fp-icon' will be replaced with an appropriate img; | |
463 | * | |
464 | * content of element with class 'fp-filename' will be replaced with filename supplied by | |
465 | * repository; | |
466 | * | |
e709ddd2 MG |
467 | * top element(s) will have class fp-folder if the element is a folder; |
468 | * | |
d1d18691 MG |
469 | * Note that tree view and table view are the YUI widgets and therefore there are no |
470 | * other templates. The widgets will be wrapped in <div> with class fp-treeview or | |
471 | * fp-tableview (respectfully). | |
472 | * | |
473 | * @return string | |
474 | */ | |
475 | private function fp_js_template_listfilename() { | |
e709ddd2 | 476 | $rv = '<span><span class="{!}fp-icon"></span> <span class="{!}fp-filename"></span></span>'; |
d1d18691 MG |
477 | return preg_replace('/\{\!\}/', '', $rv); |
478 | } | |
479 | ||
480 | /** | |
481 | * FilePicker JS template for displaying link/loading progress for fetching of the next page | |
482 | * | |
483 | * This text is added to .fp-content AFTER .fp-iconview/.fp-treeview/.fp-tableview | |
484 | * | |
485 | * Must have one parent element with class 'fp-nextpage'. It will be assigned additional | |
486 | * class 'loading' during loading of the next page (it is recommended that in this case the link | |
487 | * becomes unavailable). Also must contain one element <a> or <button> that will hold | |
488 | * onclick event for displaying of the next page. The event will be triggered automatically | |
489 | * when user scrolls to this link. | |
490 | * | |
491 | * @return string | |
492 | */ | |
493 | private function fp_js_template_nextpage() { | |
494 | $rv = '<div class="{!}fp-nextpage"> | |
495 | <div class="fp-nextpage-link"><a href="#">'.get_string('more').'</a></div> | |
496 | <div class="fp-nextpage-loading"> | |
497 | <img src="'.$this->pix_url('i/loading').'" /> | |
498 | <p>'.get_string('loading', 'repository').'</p> | |
499 | </div> | |
500 | </div>'; | |
501 | return preg_replace('/\{\!\}/', '', $rv); | |
502 | } | |
503 | ||
504 | /** | |
e709ddd2 | 505 | * FilePicker JS template for window appearing to select a file. |
d1d18691 MG |
506 | * |
507 | * All content must be enclosed in an element with class 'fp-select', CSS for this class | |
508 | * must define width and height of the window; | |
509 | * | |
510 | * Thumbnail image will be added as content to the element with class 'fp-thumbnail'; | |
511 | * | |
512 | * Inside the window the elements with the following classnames must be present: | |
513 | * 'fp-saveas', 'fp-linkexternal', 'fp-setauthor', 'fp-setlicense'. Inside each of them must have | |
514 | * one input element (or select in case of fp-setlicense). They may also have labels. | |
515 | * The elements will be assign with class 'uneditable' and input/select element will become | |
516 | * disabled if they are not applicable for the particular file; | |
517 | * | |
518 | * There may be present elements with classes 'fp-datemodified', 'fp-datecreated', 'fp-size', | |
e709ddd2 MG |
519 | * 'fp-license', 'fp-author', 'fp-dimensions'. They will receive additional class 'fp-unknown' |
520 | * if information is unavailable. If there is information available, the content of embedded | |
521 | * element with class 'fp-value' will be substituted with the value; | |
d1d18691 MG |
522 | * |
523 | * Elements with classes 'fp-select-confirm' and 'fp-select-cancel' will hold corresponding | |
524 | * onclick events; | |
525 | * | |
526 | * When confirm button is pressed and file is being selected, the top element receives | |
527 | * additional class 'loading'. It is removed when response from server is received. | |
528 | * | |
529 | * @return string | |
530 | */ | |
531 | private function fp_js_template_selectlayout() { | |
532 | $rv = '<div class="{!}fp-select"> | |
533 | <div class="fp-select-loading"> | |
534 | <img src="'.$this->pix_url('i/loading').'" /> | |
535 | <p>'.get_string('loading', 'repository').'</p> | |
536 | </div> | |
537 | <form> | |
538 | <p class="{!}fp-thumbnail"></p> | |
539 | <table width="100%"> | |
540 | <tr class="{!}fp-saveas"><td class="mdl-right"><label>'.get_string('saveas', 'repository').'</label>:</td> | |
541 | <td class="mdl-left"><input type="text"/></td></tr> | |
542 | <tr class="{!}fp-linkexternal"><td></td> | |
543 | <td class="mdl-left"><input type="checkbox"/><label>'.get_string('linkexternal', 'repository').'</label></td></tr> | |
544 | <tr class="{!}fp-setauthor"><td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td> | |
545 | <td class="mdl-left"><input type="text" /></td></tr> | |
546 | <tr class="{!}fp-setlicense"><td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td> | |
547 | <td class="mdl-left"><select></select></td></tr> | |
548 | </table> | |
549 | <p><button class="{!}fp-select-confirm" >'.get_string('getfile', 'repository').'</button> | |
550 | <button class="{!}fp-select-cancel" >'.get_string('cancel').'</button></p> | |
551 | </form> | |
552 | <div class="{!}fp-datemodified">'.get_string('lastmodified', 'moodle').': <span class="fp-value"/></div> | |
553 | <div class="{!}fp-datecreated">'.get_string('datecreated', 'repository').': <span class="fp-value"/></div> | |
554 | <div class="{!}fp-size">'.get_string('size', 'repository').': <span class="fp-value"/></div> | |
555 | <div class="{!}fp-license">'.get_string('license', 'moodle').': <span class="fp-value"/></div> | |
556 | <div class="{!}fp-author">'.get_string('author', 'repository').': <span class="fp-value"/></div> | |
557 | <div class="{!}fp-dimensions">'.get_string('dimensions', 'repository').': <span class="fp-value"/></div> | |
558 | </div>'; | |
559 | return preg_replace('/\{\!\}/', '', $rv); | |
560 | } | |
561 | ||
562 | /** | |
563 | * FilePicker JS template for 'Upload file' repository | |
564 | * | |
565 | * Content to display when user chooses 'Upload file' repository (will be nested inside | |
566 | * element with class 'fp-content'). | |
567 | * | |
568 | * Must contain form (enctype="multipart/form-data" method="POST") | |
569 | * | |
570 | * The elements with the following classnames must be present: | |
571 | * 'fp-file', 'fp-saveas', 'fp-setauthor', 'fp-setlicense'. Inside each of them must have | |
572 | * one input element (or select in case of fp-setlicense). They may also have labels. | |
573 | * | |
574 | * Element with class 'fp-upload-btn' will hold onclick event for uploading the file; | |
575 | * | |
576 | * Please note that some fields may be hidden using CSS if this is part of quickupload form | |
577 | * | |
578 | * @return string | |
579 | */ | |
580 | private function fp_js_template_uploadform() { | |
581 | $rv = '<div class="fp-upload-form mdl-align"> | |
582 | <form enctype="multipart/form-data" method="POST"> | |
583 | <table width="100%"> | |
584 | <tr class="{!}fp-file"> | |
585 | <td class="mdl-right"><label>'.get_string('attachment', 'repository').'</label>:</td> | |
586 | <td class="mdl-left"><input type="file"/></td> | |
587 | </tr> | |
588 | <tr class="{!}fp-saveas"> | |
589 | <td class="mdl-right"><label>'.get_string('saveas', 'repository').'</label>:</td> | |
590 | <td class="mdl-left"><input type="text"/></td> | |
591 | </tr> | |
592 | <tr class="{!}fp-setauthor"> | |
593 | <td class="mdl-right"><label>'.get_string('author', 'repository').'</label>:</td> | |
594 | <td class="mdl-left"><input type="text"/></td> | |
595 | </tr> | |
596 | <tr class="{!}fp-setlicense"> | |
597 | <td class="mdl-right"><label>'.get_string('chooselicense', 'repository').'</label>:</td> | |
598 | <td class="mdl-left"><select/></td> | |
599 | </tr> | |
600 | </table> | |
601 | </form> | |
602 | <div><button class="{!}fp-upload-btn">'.get_string('upload', 'repository').'</button></div> | |
603 | </div> '; | |
604 | return preg_replace('/\{\!\}/', '', $rv); | |
605 | } | |
606 | ||
607 | /** | |
608 | * FilePicker JS template to display during loading process (inside element with class 'fp-content'). | |
609 | * | |
610 | * @return string | |
611 | */ | |
612 | private function fp_js_template_loading() { | |
613 | return '<div style="text-align:center"> | |
614 | <img src="'.$this->pix_url('i/loading').'" /> | |
615 | <p>'.get_string('loading', 'repository').'</p> | |
616 | </div>'; | |
617 | } | |
618 | ||
619 | /** | |
620 | * FilePicker JS template for error (inside element with class 'fp-content'). | |
621 | * | |
622 | * must have element with class 'fp-error', its content will be replaced with error text | |
623 | * and the error code will be assigned as additional class to this element | |
624 | * used errors: invalidjson, nofilesavailable, norepositoriesavailable | |
625 | * | |
626 | * @return string | |
627 | */ | |
628 | private function fp_js_template_error() { | |
629 | $rv = '<div class="{!}fp-error" />'; | |
630 | return preg_replace('/\{\!\}/', '', $rv); | |
631 | } | |
632 | ||
633 | /** | |
634 | * FilePicker JS template for error/info message displayed as a separate popup window. | |
635 | * | |
636 | * Must be wrapped in an element with class 'fp-msg', CSS for this element must define | |
637 | * width and height of the window. It will be assigned with an additional class 'fp-msg-error' | |
638 | * or 'fp-msg-info' depending on message type; | |
639 | * | |
640 | * content of element with class 'fp-msg-text' will be replaced with error/info text; | |
641 | * | |
642 | * element with class 'fp-msg-butok' will hold onclick event | |
643 | * | |
644 | * @return string | |
645 | */ | |
646 | private function fp_js_template_message() { | |
647 | $rv = '<div class="{!}fp-msg"> | |
648 | <div class="{!}fp-msg-text"></div> | |
649 | <div><button class="{!}fp-msg-butok">'.get_string('ok').'</button></div> | |
650 | </div>'; | |
651 | return preg_replace('/\{\!\}/', '', $rv); | |
652 | } | |
653 | ||
654 | /** | |
655 | * FilePicker JS template for popup dialogue window asking for action when file with the same name already exists. | |
656 | * | |
657 | * Must be wrapped in an element with class 'fp-dlg', CSS for this element must define width | |
658 | * and height of the window; | |
659 | * | |
660 | * content of element with class 'fp-dlg-text' will be replaced with dialog text; | |
661 | * elements with classes 'fp-dlg-butoverwrite', 'fp-dlg-butrename' and 'fp-dlg-butcancel' will | |
662 | * hold onclick events; | |
663 | * | |
664 | * content of element with class 'fp-dlg-butrename' will be substituted with appropriate string | |
665 | * (Note that it may have long text) | |
666 | * | |
667 | * @return string | |
668 | */ | |
669 | private function fp_js_template_processexistingfile() { | |
670 | $rv = '<div class="{!}fp-dlg"><div class="{!}fp-dlg-text"></div> | |
671 | <div class="fp-dlg-but"><button class="{!}fp-dlg-butoverwrite" >'.get_string('overwrite', 'repository').'</button></div> | |
672 | <div class="fp-dlg-but"><button class="{!}fp-dlg-butrename" /></div> | |
673 | <div class="fp-dlg-but"><button class="{!}fp-dlg-butcancel" >'.get_string('cancel').'</button></div> | |
674 | </div>'; | |
675 | return preg_replace('/\{\!\}/', '', $rv); | |
676 | } | |
677 | ||
678 | /** | |
679 | * FilePicker JS template for repository login form including templates for each element type | |
680 | * | |
681 | * Must contain one <form> element with templates for different input types inside: | |
682 | * Elements with classes 'fp-login-popup', 'fp-login-textarea', 'fp-login-select' and | |
683 | * 'fp-login-input' are templates for displaying respective login form elements. Inside | |
684 | * there must be exactly one element with type <button>, <textarea>, <select> or <input> | |
685 | * (i.e. fp-login-popup should have <button>, fp-login-textarea should have <textarea>, etc.); | |
686 | * They may also contain the <label> element and it's content will be substituted with | |
687 | * label; | |
688 | * | |
689 | * You can also define elements with classes 'fp-login-checkbox', 'fp-login-text' | |
690 | * but if they are not found, 'fp-login-input' will be used; | |
691 | * | |
692 | * Element with class 'fp-login-radiogroup' will be used for group of radio inputs. Inside | |
693 | * it should hava a template for one radio input (with class 'fp-login-radio'); | |
694 | * | |
695 | * Element with class 'fp-login-submit' will hold on click mouse event (form submission). It | |
696 | * will be removed if at least one popup element is present; | |
697 | * | |
698 | * @return string | |
699 | */ | |
700 | private function fp_js_template_loginform() { | |
701 | $rv = ' | |
702 | <div class="fp-login-form"> | |
703 | <form> | |
704 | <table width="100%"> | |
705 | <tr class="{!}fp-login-popup"> | |
706 | <td colspan="2"> | |
707 | <label>'.get_string('popup', 'repository').'</label> | |
708 | <p class="fp-popup"><button class="{!}fp-login-popup-but">'.get_string('login', 'repository').'</button></p> | |
709 | </td> | |
710 | </tr> | |
711 | <tr class="{!}fp-login-textarea"> | |
712 | <td colspan="2"><p><textarea></textarea></p></td> | |
713 | </tr> | |
714 | <tr class="{!}fp-login-select"> | |
715 | <td align="right"><label></label></td> | |
716 | <td align="left"><select></select></td> | |
717 | </tr> | |
718 | <tr class="{!}fp-login-input"> | |
719 | <td align="right" width="30%" valign="center"><label /></td> | |
720 | <td align="left"><input/></td> | |
721 | </tr> | |
722 | <tr class="{!}fp-login-radiogroup"> | |
723 | <td align="right" width="30%" valign="top"><label /></td> | |
724 | <td align="left" valign="top"> | |
725 | <p class="{!}fp-login-radio"><input /> <label /></p> | |
726 | </td> | |
727 | </tr> | |
728 | </table> | |
729 | <p><button class="{!}fp-login-submit">'.get_string('submit', 'repository').'</button></p> | |
730 | </form> | |
731 | </div>'; | |
732 | return preg_replace('/\{\!\}/', '', $rv); | |
733 | } | |
734 | ||
735 | /** | |
736 | * Returns all FilePicker JavaScript templates as an array. | |
737 | * | |
738 | * @return array | |
739 | */ | |
740 | public function filepicker_js_templates() { | |
741 | $class_methods = get_class_methods($this); | |
742 | $templates = array(); | |
743 | foreach ($class_methods as $method_name) { | |
744 | if (preg_match('/^fp_js_template_(.*)$/', $method_name, $matches)) | |
745 | $templates[$matches[1]] = $this->$method_name(); | |
746 | } | |
747 | return $templates; | |
748 | } | |
749 | ||
750 | /** | |
751 | * Returns HTML for default repository searchform to be passed to Filepicker | |
752 | * | |
753 | * This will be used as contents for search form defined in generallayout template | |
754 | * (form with id {TOOLSEARCHID}). | |
755 | * Default contents is one text input field with name="s" | |
756 | */ | |
757 | public function repository_default_searchform() { | |
758 | $str = '<label>'.get_string('keyword', 'repository').': </label><br/><input name="s" value="" /><br/>'; | |
759 | return $str; | |
760 | } | |
761 | } | |
64f93798 PS |
762 | |
763 | /** | |
764 | * Data structure representing a general moodle file tree viewer | |
765 | * | |
766 | * @copyright 2010 Dongsheng Cai | |
767 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
768 | * @since Moodle 2.0 | |
769 | */ | |
770 | class files_tree_viewer implements renderable { | |
771 | public $tree; | |
772 | public $path; | |
e921afa8 | 773 | public $context; |
64f93798 PS |
774 | |
775 | /** | |
776 | * Constructor of moodle_file_tree_viewer class | |
777 | * @param file_info $file_info | |
778 | * @param array $options | |
779 | */ | |
780 | public function __construct(file_info $file_info, array $options = null) { | |
781 | global $CFG; | |
782 | ||
783 | //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
64f93798 | 784 | $this->options = (array)$options; |
e921afa8 DC |
785 | $this->context = $options['context']; |
786 | ||
64f93798 PS |
787 | $this->tree = array(); |
788 | $children = $file_info->get_children(); | |
0b259d91 | 789 | $current_file_params = $file_info->get_params(); |
64f93798 | 790 | $parent_info = $file_info->get_parent(); |
64f93798 PS |
791 | $level = $parent_info; |
792 | $this->path = array(); | |
793 | while ($level) { | |
794 | $params = $level->get_params(); | |
795 | $context = get_context_instance_by_id($params['contextid']); | |
0b259d91 DC |
796 | // $this->context is current context |
797 | if ($context->id != $this->context->id or empty($params['filearea'])) { | |
64f93798 PS |
798 | break; |
799 | } | |
e921afa8 DC |
800 | // unset unused parameters |
801 | unset($params['component']); | |
802 | unset($params['filearea']); | |
0b259d91 | 803 | unset($params['filename']); |
e921afa8 | 804 | unset($params['itemid']); |
64f93798 | 805 | $url = new moodle_url('/files/index.php', $params); |
e921afa8 | 806 | $this->path[] = html_writer::link($url, $level->get_visible_name()); |
64f93798 PS |
807 | $level = $level->get_parent(); |
808 | } | |
809 | $this->path = array_reverse($this->path); | |
0b259d91 DC |
810 | if ($current_file_params['filepath'] != '/') { |
811 | $this->path[] = $file_info->get_visible_name(); | |
812 | } | |
64f93798 PS |
813 | |
814 | foreach ($children as $child) { | |
815 | $filedate = $child->get_timemodified(); | |
816 | $filesize = $child->get_filesize(); | |
817 | $mimetype = $child->get_mimetype(); | |
818 | $params = $child->get_params(); | |
0b259d91 DC |
819 | unset($params['component']); |
820 | unset($params['filearea']); | |
821 | unset($params['filename']); | |
822 | unset($params['itemid']); | |
64f93798 PS |
823 | $fileitem = array( |
824 | 'params' => $params, | |
825 | 'filename' => $child->get_visible_name(), | |
826 | 'filedate' => $filedate ? userdate($filedate) : '', | |
827 | 'filesize' => $filesize ? display_size($filesize) : '' | |
828 | ); | |
e921afa8 | 829 | $url = new moodle_url('/files/index.php', $params); |
64f93798 PS |
830 | if ($child->is_directory()) { |
831 | $fileitem['isdir'] = true; | |
832 | $fileitem['url'] = $url->out(false); | |
64f93798 PS |
833 | } else { |
834 | $fileitem['url'] = $child->get_url(); | |
835 | } | |
836 | $this->tree[] = $fileitem; | |
837 | } | |
838 | } | |
839 | } |