Feature #10639: Integration of the Mass File Uploader (based on SWFUpload and Ext JS)
[Packages/TYPO3.CMS.git] / typo3 / file_list.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (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 Skaarhoj
32 *
33 * @author Kasper Skaarhoj <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 ('mod/file/list/conf.php');
54 require ('init.php');
55 require ('template.php');
56 $LANG->includeLLFile('EXT:lang/locallang_mod_file_list.xml');
57 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
58 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
59 require_once (PATH_t3lib.'class.t3lib_extfilefunc.php');
60 require_once (PATH_t3lib.'class.t3lib_recordlist.php');
61 require_once (PATH_t3lib.'class.t3lib_clipboard.php');
62 require_once (PATH_t3lib.'class.t3lib_parsehtml.php');
63 require_once ('class.file_list.inc');
64 $BE_USER->modAccess($MCONF,1);
65
66
67
68
69
70
71
72 /**
73 * Script Class for creating the list of files in the File > Filelist module
74 *
75 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
76 * @package TYPO3
77 * @subpackage core
78 */
79 class SC_file_list {
80 var $MCONF=array(); // Module configuration
81 var $MOD_MENU=array();
82 var $MOD_SETTINGS=array();
83
84
85 // Internal:
86 var $content; // Accumulated HTML output
87
88 /**
89 * File processing object
90 *
91 * @var t3lib_basicFileFunctions
92 */
93 var $basicFF;
94
95 /**
96 * Document template object
97 *
98 * @var template
99 */
100 var $doc;
101
102 // Internal, static: GPvars:
103 var $id; // "id" -> the path to list.
104 var $pointer; // Pointer to listing
105 var $table; // "Table"
106 var $imagemode; // Thumbnail mode.
107 var $cmd;
108 var $overwriteExistingFiles;
109
110
111 /**
112 * Initialize variables, file object
113 * Incoming GET vars include id, pointer, table, imagemode
114 *
115 * @return void
116 */
117 function init() {
118 global $TYPO3_CONF_VARS,$FILEMOUNTS;
119
120 // Setting GPvars:
121 $this->id = t3lib_div::_GP('id');
122 $this->pointer = t3lib_div::_GP('pointer');
123 $this->table = t3lib_div::_GP('table');
124 $this->imagemode = t3lib_div::_GP('imagemode');
125 $this->cmd = t3lib_div::_GP('cmd');
126 $this->overwriteExistingFiles = t3lib_div::_GP('overwriteExistingFiles');
127
128 // Setting module name:
129 $this->MCONF = $GLOBALS['MCONF'];
130
131 // File operation object:
132 $this->basicFF = t3lib_div::makeInstance('t3lib_basicFileFunctions');
133 $this->basicFF->init($FILEMOUNTS,$TYPO3_CONF_VARS['BE']['fileExtensions']);
134
135 // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
136 $this->menuConfig();
137 }
138
139 /**
140 * Setting the menu/session variables
141 *
142 * @return void
143 */
144 function menuConfig() {
145 // MENU-ITEMS:
146 // If array, then it's a selector box menu
147 // If empty string it's just a variable, that'll be saved.
148 // Values NOT in this array will not be saved in the settings-array for the module.
149 $this->MOD_MENU = array(
150 'sort' => '',
151 'reverse' => '',
152 'displayThumbs' => '',
153 'clipBoard' => ''
154 );
155
156 // CLEANSE SETTINGS
157 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
158 }
159
160 /**
161 * Main function, creating the listing
162 *
163 * @return void
164 */
165 function main() {
166 global $BE_USER,$LANG,$BACK_PATH,$TYPO3_CONF_VARS,$FILEMOUNTS;
167
168 // Initialize the template object
169 $this->doc = t3lib_div::makeInstance('template');
170 $this->doc->backPath = $BACK_PATH;
171 $this->doc->setModuleTemplate('templates/file_list.html');
172 $this->doc->loadPrototype();
173
174 // Validating the input "id" (the path, directory!) and checking it against the mounts of the user.
175 $this->id = $this->basicFF->is_directory($this->id);
176 $access = $this->id && $this->basicFF->checkPathAgainstMounts($this->id.'/');
177
178 // There there was access to this file path, continue, make the list
179 if ($access) {
180 // include the initialization for the flash uploader
181 if ($GLOBALS['BE_USER']->uc['enableFlashUploader']) {
182
183 $this->doc->JScodeArray['flashUploader'] = '
184 if (top.TYPO3.FileUploadWindow.isFlashAvailable()) {
185 document.observe("dom:loaded", function() {
186 // monitor the button
187 $("button-upload").observe("click", initFlashUploader);
188
189 function initFlashUploader(event) {
190 // set the page specific options for the flashUploader
191 var flashUploadOptions = {
192 uploadURL: top.TS.PATH_typo3 + "ajax.php",
193 uploadFileSizeLimit: "' . t3lib_div::getMaxUploadFileSize() . '",
194 uploadFileTypes: {
195 allow: "' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']['allow'] . '",
196 deny: "' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']['deny'] . '"
197 },
198 uploadFilePostName: "upload_1",
199 uploadPostParams: {
200 "file[upload][1][target]": "' . $this->id . '",
201 "file[upload][1][data]": 1,
202 "file[upload][1][charset]": "utf-8",
203 "ajaxID": "TYPO3_tcefile::process"
204 }
205 };
206
207 // get the flashUploaderWindow instance from the parent frame
208 var flashUploader = top.TYPO3.FileUploadWindow.getInstance(flashUploadOptions);
209 // add an additional function inside the container to show the checkbox option
210 var infoComponent = new top.Ext.Panel({
211 autoEl: { tag: "div" },
212 height: "auto",
213 bodyBorder: false,
214 border: false,
215 hideBorders: true,
216 cls: "t3-upload-window-infopanel",
217 id: "t3-upload-window-infopanel-addition",
218 html: \'<label for="overrideExistingFilesCheckbox"><input id="overrideExistingFilesCheckbox" type="checkbox" onclick="setFlashPostOptionOverwriteExistingFiles(this);" />\' + top.String.format(top.TYPO3.LLL.fileUpload.infoComponentOverrideFiles) + \'</label>\'
219 });
220 flashUploader.add(infoComponent);
221
222 // do a reload of this frame once all uploads are done
223 flashUploader.on("totalcomplete", function() {
224 window.location.reload();
225 });
226
227 // this is the callback function that delivers the additional post parameter to the flash application
228 top.setFlashPostOptionOverwriteExistingFiles = function(checkbox) {
229 var uploader = top.TYPO3.getInstance("FileUploadWindow");
230 if (uploader.isVisible()) {
231 uploader.swf.addPostParam("overwriteExistingFiles", (checkbox.checked == true ? 1 : 0));
232 }
233 };
234
235 event.stop();
236 };
237 });
238 }
239 ';
240 }
241 // Create filelisting object
242 $this->filelist = t3lib_div::makeInstance('fileList');
243 $this->filelist->backPath = $BACK_PATH;
244 $this->filelist->thumbs = $this->MOD_SETTINGS['displayThumbs']?1:$BE_USER->uc['thumbnailsByDefault'];
245
246 // Create clipboard object and initialize that
247 $this->filelist->clipObj = t3lib_div::makeInstance('t3lib_clipboard');
248 $this->filelist->clipObj->fileMode=1;
249 $this->filelist->clipObj->initializeClipboard();
250
251 $CB = t3lib_div::_GET('CB');
252 if ($this->cmd=='setCB') $CB['el'] = $this->filelist->clipObj->cleanUpCBC(array_merge(t3lib_div::_POST('CBH'),t3lib_div::_POST('CBC')),'_FILE');
253 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal';
254 $this->filelist->clipObj->setCmd($CB);
255 $this->filelist->clipObj->cleanCurrent();
256 $this->filelist->clipObj->endClipboard(); // Saves
257
258 // If the "cmd" was to delete files from the list (clipboard thing), do that:
259 if ($this->cmd=='delete') {
260 $items = $this->filelist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),'_FILE',1);
261 if (count($items)) {
262 // Make command array:
263 $FILE=array();
264 reset($items);
265 while(list(,$v)=each($items)) {
266 $FILE['delete'][]=array('data'=>$v);
267 }
268
269 // Init file processing object for deleting and pass the cmd array.
270 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
271 $fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
272 $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
273 $fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
274 $fileProcessor->start($FILE);
275 $fileProcessor->processData();
276
277 $fileProcessor->printLogErrorMessages();
278 }
279 }
280
281 if (!isset($this->MOD_SETTINGS['sort'])) {
282 // Set default sorting
283 $this->MOD_SETTINGS['sort'] = 'file';
284 $this->MOD_SETTINGS['reverse'] = 0;
285 }
286
287 // Start up filelisting object, include settings.
288 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
289 $this->filelist->start($this->id,$this->pointer,$this->MOD_SETTINGS['sort'],$this->MOD_SETTINGS['reverse'],$this->MOD_SETTINGS['clipBoard']);
290
291 // Generate the list
292 $this->filelist->generateList();
293
294 // Write the footer
295 $this->filelist->writeBottom();
296
297 // Set top JavaScript:
298 $this->doc->JScode=$this->doc->wrapScriptTags('
299
300 if (top.fsMod) top.fsMod.recentIds["file"] = unescape("'.rawurlencode($this->id).'");
301 function jumpToUrl(URL) { //
302 window.location.href = URL;
303 }
304
305 '.$this->filelist->CBfunctions() // ... and add clipboard JavaScript functions
306 );
307
308 // This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
309 $this->doc->getContextMenuCode();
310
311 // Setting up the buttons and markers for docheader
312 list($buttons, $otherMarkers) = $this->filelist->getButtonsAndOtherMarkers($this->id);
313
314 // add the folder info to the marker array
315 $otherMarkers['FOLDER_INFO'] = $this->filelist->getFolderInfo();
316
317 $docHeaderButtons = array_merge($this->getButtons(), $buttons);
318
319 // Build the <body> for the module
320 $this->content = $this->doc->startPage($LANG->getLL('files'));
321
322 // Create output
323 $pageContent='';
324 $pageContent.= '<form action="'.htmlspecialchars($this->filelist->listURL()).'" method="post" name="dblistForm">';
325 $pageContent.= $this->filelist->HTMLcode;
326 $pageContent.= '<input type="hidden" name="cmd" /></form>';
327
328
329 if ($this->filelist->HTMLcode) { // Making listing options:
330
331 $pageContent.='
332
333 <!--
334 Listing options for clipboard and thumbnails
335 -->
336 <div id="typo3-listOptions">
337 ';
338
339 // Add "display thumbnails" checkbox:
340 $pageContent.=t3lib_BEfunc::getFuncCheck($this->id,'SET[displayThumbs]',$this->MOD_SETTINGS['displayThumbs'],'file_list.php','','id="checkDisplayThumbs"').' <label for="checkDisplayThumbs">'.$LANG->getLL('displayThumbs',1).'</label><br />';
341
342 // Add clipboard button
343 $pageContent.=t3lib_BEfunc::getFuncCheck($this->id,'SET[clipBoard]',$this->MOD_SETTINGS['clipBoard'],'file_list.php','','id="checkClipBoard"').' <label for="checkClipBoard">'.$LANG->getLL('clipBoard',1).'</label>';
344
345 $pageContent.='
346 </div>
347 ';
348
349
350 // Set clipboard:
351 if ($this->MOD_SETTINGS['clipBoard']) {
352 $pageContent.=$this->filelist->clipObj->printClipboard();
353 $pageContent.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_clipboard', $GLOBALS['BACK_PATH']);
354 }
355 }
356
357 $markerArray = array(
358 'CSH' => $docHeaderButtons['csh'],
359 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
360 'CONTENT' => $pageContent
361 );
362
363 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, array_merge($markerArray, $otherMarkers));
364 $this->content.= $this->doc->endPage();
365 $this->content = $this->doc->insertStylesAndJS($this->content);
366
367 } else {
368 // Create output - no access (no warning though)
369 $this->content = '';
370 $this->content .= $this->doc->startPage($LANG->getLL('files'));
371 $this->content .= $this->doc->endPage();
372 $this->content = $this->doc->insertStylesAndJS($this->content);
373 }
374
375
376 }
377
378 /**
379 * Outputting the accumulated content to screen
380 *
381 * @return void
382 */
383 function printContent() {
384 echo $this->content;
385 }
386
387 /**
388 * Create the panel of buttons for submitting the form or otherwise perform operations.
389 *
390 * @return array all available buttons as an assoc. array
391 */
392 function getButtons() {
393 global $TCA, $LANG, $BACK_PATH, $BE_USER;
394
395 $buttons = array(
396 'csh' => '',
397 'shortcut' => '',
398 'upload' => '',
399 'new' => '',
400 );
401
402 // Add shortcut
403 if ($BE_USER->mayMakeShortcut()) {
404 $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']);
405 }
406
407 // FileList Module CSH:
408 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_module', $GLOBALS['BACK_PATH'], '', TRUE);
409
410 // upload button
411 $theIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/upload.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.upload',1)).'" alt="'.$GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.upload',1)).'" />';
412 $buttons['upload'] = '<a href="' . $BACK_PATH . 'file_upload.php?target=' . rawurlencode($this->id) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '" id="button-upload">' . $theIcon . '</a>';
413
414 $theIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/new_file.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.new',1)).'" alt="'.$GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.new',1)).'" />';
415 $buttons['new'] = '<a href="' . $BACK_PATH . 'file_newfolder.php?target=' . rawurlencode($this->id) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '">' . $theIcon . '</a>';
416
417 return $buttons;
418 }
419
420 }
421
422
423 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']) {
424 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']);
425 }
426
427
428
429 // Make instance:
430 $SOBE = t3lib_div::makeInstance('SC_file_list');
431 $SOBE->init();
432 $SOBE->main();
433 $SOBE->printContent();
434
435 ?>