Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / filelist / mod1 / file_list.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Web>File: File listing
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 77: class SC_file_list
41 * 103: function init()
42 * 130: function menuConfig()
43 * 151: function main()
44 * 325: function printContent()
45 *
46 * TOTAL FUNCTIONS: 4
47 * (This index is automatically created/updated by the extension "extdeveval")
48 *
49 */
50
51
52 unset($MCONF);
53 require ('conf.php');
54 require ($BACK_PATH . 'init.php');
55 require ($BACK_PATH . 'template.php');
56 $LANG->includeLLFile('EXT:lang/locallang_mod_file_list.xml');
57 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
58 require_once ($BACK_PATH . 'class.file_list.inc');
59 $BE_USER->modAccess($MCONF,1);
60
61
62
63
64
65
66
67 /**
68 * Script Class for creating the list of files in the File > Filelist module
69 *
70 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
71 * @package TYPO3
72 * @subpackage core
73 */
74 class SC_file_list {
75 var $MCONF=array(); // Module configuration
76 var $MOD_MENU=array();
77 var $MOD_SETTINGS=array();
78
79
80 // Internal:
81 var $content; // Accumulated HTML output
82
83 /**
84 * File processing object
85 *
86 * @var t3lib_basicFileFunctions
87 */
88 var $basicFF;
89
90 /**
91 * Document template object
92 *
93 * @var template
94 */
95 var $doc;
96
97 // Internal, static: GPvars:
98 var $id; // "id" -> the path to list.
99 var $pointer; // Pointer to listing
100 var $table; // "Table"
101 var $imagemode; // Thumbnail mode.
102 var $cmd;
103 var $overwriteExistingFiles;
104
105
106 /**
107 * Initialize variables, file object
108 * Incoming GET vars include id, pointer, table, imagemode
109 *
110 * @return void
111 */
112 function init() {
113 global $TYPO3_CONF_VARS,$FILEMOUNTS;
114
115 // Setting GPvars:
116 $this->id = t3lib_div::_GP('id');
117 $this->pointer = t3lib_div::_GP('pointer');
118 $this->table = t3lib_div::_GP('table');
119 $this->imagemode = t3lib_div::_GP('imagemode');
120 $this->cmd = t3lib_div::_GP('cmd');
121 $this->overwriteExistingFiles = t3lib_div::_GP('overwriteExistingFiles');
122
123 // Setting module name:
124 $this->MCONF = $GLOBALS['MCONF'];
125
126 // File operation object:
127 $this->basicFF = t3lib_div::makeInstance('t3lib_basicFileFunctions');
128 $this->basicFF->init($FILEMOUNTS,$TYPO3_CONF_VARS['BE']['fileExtensions']);
129
130 // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
131 $this->menuConfig();
132 }
133
134 /**
135 * Setting the menu/session variables
136 *
137 * @return void
138 */
139 function menuConfig() {
140 // MENU-ITEMS:
141 // If array, then it's a selector box menu
142 // If empty string it's just a variable, that'll be saved.
143 // Values NOT in this array will not be saved in the settings-array for the module.
144 $this->MOD_MENU = array(
145 'sort' => '',
146 'reverse' => '',
147 'displayThumbs' => '',
148 'clipBoard' => '',
149 'bigControlPanel' => ''
150 );
151
152 // CLEANSE SETTINGS
153 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
154 }
155
156 /**
157 * Main function, creating the listing
158 *
159 * @return void
160 */
161 function main() {
162 global $BE_USER,$LANG,$BACK_PATH,$TYPO3_CONF_VARS,$FILEMOUNTS;
163
164 // Initialize the template object
165 $this->doc = t3lib_div::makeInstance('template');
166 $this->doc->backPath = $BACK_PATH;
167 $this->doc->setModuleTemplate('templates/file_list.html');
168 $this->doc->getPageRenderer()->loadPrototype();
169
170 // Validating the input "id" (the path, directory!) and checking it against the mounts of the user.
171 $this->id = $this->basicFF->is_directory($this->id);
172 $access = $this->id && $this->basicFF->checkPathAgainstMounts($this->id.'/');
173
174 // There there was access to this file path, continue, make the list
175 if ($access) {
176 // include the initialization for the flash uploader
177 if ($GLOBALS['BE_USER']->uc['enableFlashUploader'] == 1) {
178
179 $this->doc->JScodeArray['flashUploader'] = '
180 if (top.TYPO3.FileUploadWindow.isFlashAvailable()) {
181 document.observe("dom:loaded", function() {
182 // monitor the button
183 $("button-upload").observe("click", initFlashUploader);
184
185 function initFlashUploader(event) {
186 // set the page specific options for the flashUploader
187 var flashUploadOptions = {
188 uploadURL: top.TYPO3.configuration.PATH_typo3 + "ajax.php",
189 uploadFileSizeLimit: "' . t3lib_div::getMaxUploadFileSize() . '",
190 uploadFileTypes: {
191 allow: "' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']['allow'] . '",
192 deny: "' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']['deny'] . '"
193 },
194 uploadFilePostName: "upload_1",
195 uploadPostParams: {
196 "file[upload][1][target]": "' . $this->id . '",
197 "file[upload][1][data]": 1,
198 "file[upload][1][charset]": "utf-8",
199 "ajaxID": "TYPO3_tcefile::process"
200 }
201 };
202
203 // get the flashUploaderWindow instance from the parent frame
204 var flashUploader = top.TYPO3.FileUploadWindow.getInstance(flashUploadOptions);
205 // add an additional function inside the container to show the checkbox option
206 var infoComponent = new top.Ext.Panel({
207 autoEl: { tag: "div" },
208 height: "auto",
209 bodyBorder: false,
210 border: false,
211 hideBorders: true,
212 cls: "t3-upload-window-infopanel",
213 id: "t3-upload-window-infopanel-addition",
214 html: \'<label for="overrideExistingFilesCheckbox"><input id="overrideExistingFilesCheckbox" type="checkbox" onclick="setFlashPostOptionOverwriteExistingFiles(this);" />\' + top.String.format(top.TYPO3.LLL.fileUpload.infoComponentOverrideFiles) + \'</label>\'
215 });
216 flashUploader.add(infoComponent);
217
218 // do a reload of this frame once all uploads are done
219 flashUploader.on("totalcomplete", function() {
220 window.location.reload();
221 });
222
223 // this is the callback function that delivers the additional post parameter to the flash application
224 top.setFlashPostOptionOverwriteExistingFiles = function(checkbox) {
225 var uploader = top.TYPO3.getInstance("FileUploadWindow");
226 if (uploader.isVisible()) {
227 uploader.swf.addPostParam("overwriteExistingFiles", (checkbox.checked == true ? 1 : 0));
228 }
229 };
230
231 event.stop();
232 };
233 });
234 }
235 ';
236 } elseif ($GLOBALS['BE_USER']->uc['enableFlashUploader'] == 2) {
237
238 $this->doc->JScodeArray['flashUploader'] = '
239 Ext.onReady(function() {
240 // monitor the button
241 $("button-upload").observe("click", function(event) {
242 event.stop();
243 top.TYPO3.configuration.FileUpload.targetDirectory = "'.$this->id.'";
244 // set window object to reload on finish.
245 top.TYPO3.PluploadWindow.reloadWindow = window;
246 top.TYPO3.PluploadWindow.show();
247
248 });
249 });
250 ';
251
252 }
253 // Create filelisting object
254 $this->filelist = t3lib_div::makeInstance('fileList');
255 $this->filelist->backPath = $BACK_PATH;
256
257 // Apply predefined values for hidden checkboxes
258 // Set predefined value for DisplayBigControlPanel:
259 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'activated') {
260 $this->MOD_SETTINGS['bigControlPanel'] = TRUE;
261 } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'deactivated') {
262 $this->MOD_SETTINGS['bigControlPanel'] = FALSE;
263 }
264
265 // Set predefined value for DisplayThumbnails:
266 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'activated') {
267 $this->MOD_SETTINGS['displayThumbs'] = TRUE;
268 } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'deactivated') {
269 $this->MOD_SETTINGS['displayThumbs'] = FALSE;
270 }
271
272 // Set predefined value for Clipboard:
273 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'activated') {
274 $this->MOD_SETTINGS['clipBoard'] = TRUE;
275 } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'deactivated') {
276 $this->MOD_SETTINGS['clipBoard'] = FALSE;
277 }
278
279 // if user never opened the list module, set the value for displayThumbs
280 if (!isset($this->MOD_SETTINGS['displayThumbs'])) {
281 $this->MOD_SETTINGS['displayThumbs'] = $BE_USER->uc['thumbnailsByDefault'];
282 }
283 $this->filelist->thumbs = $this->MOD_SETTINGS['displayThumbs'];
284
285 // Create clipboard object and initialize that
286 $this->filelist->clipObj = t3lib_div::makeInstance('t3lib_clipboard');
287 $this->filelist->clipObj->fileMode=1;
288 $this->filelist->clipObj->initializeClipboard();
289
290 $CB = t3lib_div::_GET('CB');
291 if ($this->cmd=='setCB') $CB['el'] = $this->filelist->clipObj->cleanUpCBC(array_merge(t3lib_div::_POST('CBH'),t3lib_div::_POST('CBC')),'_FILE');
292 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal';
293 $this->filelist->clipObj->setCmd($CB);
294 $this->filelist->clipObj->cleanCurrent();
295 $this->filelist->clipObj->endClipboard(); // Saves
296
297 // If the "cmd" was to delete files from the list (clipboard thing), do that:
298 if ($this->cmd=='delete') {
299 $items = $this->filelist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),'_FILE',1);
300 if (count($items)) {
301 // Make command array:
302 $FILE=array();
303 foreach ($items as $v) {
304 $FILE['delete'][]=array('data'=>$v);
305 }
306
307 // Init file processing object for deleting and pass the cmd array.
308 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
309 $fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
310 $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
311 $fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
312 $fileProcessor->start($FILE);
313 $fileProcessor->processData();
314
315 $fileProcessor->printLogErrorMessages();
316 }
317 }
318
319 if (!isset($this->MOD_SETTINGS['sort'])) {
320 // Set default sorting
321 $this->MOD_SETTINGS['sort'] = 'file';
322 $this->MOD_SETTINGS['reverse'] = 0;
323 }
324
325 // Start up filelisting object, include settings.
326 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
327 $this->filelist->start($this->id, $this->pointer, $this->MOD_SETTINGS['sort'], $this->MOD_SETTINGS['reverse'], $this->MOD_SETTINGS['clipBoard'], $this->MOD_SETTINGS['bigControlPanel']);
328
329 // Generate the list
330 $this->filelist->generateList();
331
332 // Write the footer
333 $this->filelist->writeBottom();
334
335 // Set top JavaScript:
336 $this->doc->JScode=$this->doc->wrapScriptTags('
337
338 if (top.fsMod) top.fsMod.recentIds["file"] = unescape("'.rawurlencode($this->id).'");
339 function jumpToUrl(URL) { //
340 window.location.href = URL;
341 }
342
343 '.$this->filelist->CBfunctions() // ... and add clipboard JavaScript functions
344 );
345
346 // This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
347 $this->doc->getContextMenuCode();
348
349 // Setting up the buttons and markers for docheader
350 list($buttons, $otherMarkers) = $this->filelist->getButtonsAndOtherMarkers($this->id);
351
352 // add the folder info to the marker array
353 $otherMarkers['FOLDER_INFO'] = $this->filelist->getFolderInfo();
354
355 $docHeaderButtons = array_merge($this->getButtons(), $buttons);
356
357 // Build the <body> for the module
358
359 // Create output
360 $pageContent='';
361 $pageContent.= '<form action="'.htmlspecialchars($this->filelist->listURL()).'" method="post" name="dblistForm">';
362 $pageContent.= $this->filelist->HTMLcode;
363 $pageContent.= '<input type="hidden" name="cmd" /></form>';
364
365
366 if ($this->filelist->HTMLcode) { // Making listing options:
367
368 $pageContent.='
369
370 <!--
371 Listing options for extended view, clipboard and thumbnails
372 -->
373 <div id="typo3-listOptions">
374 ';
375
376 // Add "display bigControlPanel" checkbox:
377 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'selectable') {
378 $pageContent .= t3lib_BEfunc::getFuncCheck(
379 $this->id,
380 'SET[bigControlPanel]',
381 $this->MOD_SETTINGS['bigControlPanel'],
382 'file_list.php',
383 '',
384 'id="bigControlPanel"'
385 ) . '<label for="bigControlPanel"> ' . $GLOBALS['LANG']->getLL('bigControlPanel', TRUE) . '</label><br />';
386 }
387
388 // Add "display thumbnails" checkbox:
389 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'selectable') {
390 $pageContent .= t3lib_BEfunc::getFuncCheck(
391 $this->id,
392 'SET[displayThumbs]',
393 $this->MOD_SETTINGS['displayThumbs'],
394 'file_list.php',
395 '',
396 'id="checkDisplayThumbs"'
397 ) . ' <label for="checkDisplayThumbs">' . $GLOBALS['LANG']->getLL('displayThumbs', TRUE) . '</label><br />';
398 }
399
400 // Add "clipboard" checkbox:
401 if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'selectable') {
402 $pageContent .= t3lib_BEfunc::getFuncCheck(
403 $this->id,
404 'SET[clipBoard]',
405 $this->MOD_SETTINGS['clipBoard'],
406 'file_list.php',
407 '',
408 'id="checkClipBoard"'
409 ) . ' <label for="checkClipBoard">' . $GLOBALS['LANG']->getLL('clipBoard', TRUE) . '</label>';
410 }
411
412 $pageContent.='
413 </div>
414 ';
415
416
417 // Set clipboard:
418 if ($this->MOD_SETTINGS['clipBoard']) {
419 $pageContent.=$this->filelist->clipObj->printClipboard();
420 $pageContent.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_clipboard', $GLOBALS['BACK_PATH']);
421 }
422 }
423
424 $markerArray = array(
425 'CSH' => $docHeaderButtons['csh'],
426 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
427 'CONTENT' => $pageContent
428 );
429
430 $this->content = $this->doc->moduleBody(array(), $docHeaderButtons, array_merge($markerArray, $otherMarkers));
431 // Renders the module page
432 $this->content = $this->doc->render(
433 $LANG->getLL('files'),
434 $this->content
435 );
436
437 } else {
438 // Create output - no access (no warning though)
439 $this->content = $this->doc->render(
440 $LANG->getLL('files'),
441 ''
442 );
443 }
444
445
446 }
447
448 /**
449 * Outputting the accumulated content to screen
450 *
451 * @return void
452 */
453 function printContent() {
454 echo $this->content;
455 }
456
457 /**
458 * Create the panel of buttons for submitting the form or otherwise perform operations.
459 *
460 * @return array all available buttons as an assoc. array
461 */
462 function getButtons() {
463 global $TCA, $LANG, $BACK_PATH, $BE_USER;
464
465 $buttons = array(
466 'csh' => '',
467 'shortcut' => '',
468 'upload' => '',
469 'new' => '',
470 );
471
472 // Add shortcut
473 if ($BE_USER->mayMakeShortcut()) {
474 $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']);
475 }
476
477 // FileList Module CSH:
478 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_module', $GLOBALS['BACK_PATH'], '', TRUE);
479
480 // upload button
481 $buttons['upload'] = '<a href="' . $BACK_PATH . 'file_upload.php?target=' . rawurlencode($this->id) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '" id="button-upload" title="'.$GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.upload',1)).'">' .
482 t3lib_iconWorks::getSpriteIcon('actions-edit-upload') .
483 '</a>';
484
485 $buttons['new'] = '<a href="' . $BACK_PATH . 'file_newfolder.php?target=' . rawurlencode($this->id) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '" title="'.$GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.new',1)).'">' .
486 t3lib_iconWorks::getSpriteIcon('actions-document-new') .
487 '</a>';
488
489 return $buttons;
490 }
491
492 }
493
494
495 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_list.php'])) {
496 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/file_list.php']);
497 }
498
499
500
501 // Make instance:
502 $SOBE = t3lib_div::makeInstance('SC_file_list');
503 $SOBE->init();
504 $SOBE->main();
505 $SOBE->printContent();
506
507 ?>