Added feature #14247: Add a concatenator for CSS and JS (thanks to Steffen Gebert)
[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 ('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 Skaarhoj <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']) {
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.TS.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 }
237 // Create filelisting object
238 $this->filelist = t3lib_div::makeInstance('fileList');
239 $this->filelist->backPath = $BACK_PATH;
240
241 // if user never opened the list module, set the value for displayThumbs
242 if (!isset($this->MOD_SETTINGS['displayThumbs'])) {
243 $this->MOD_SETTINGS['displayThumbs'] = $BE_USER->uc['thumbnailsByDefault'];
244 }
245 $this->filelist->thumbs = $this->MOD_SETTINGS['displayThumbs'];
246
247 // Create clipboard object and initialize that
248 $this->filelist->clipObj = t3lib_div::makeInstance('t3lib_clipboard');
249 $this->filelist->clipObj->fileMode=1;
250 $this->filelist->clipObj->initializeClipboard();
251
252 $CB = t3lib_div::_GET('CB');
253 if ($this->cmd=='setCB') $CB['el'] = $this->filelist->clipObj->cleanUpCBC(array_merge(t3lib_div::_POST('CBH'),t3lib_div::_POST('CBC')),'_FILE');
254 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal';
255 $this->filelist->clipObj->setCmd($CB);
256 $this->filelist->clipObj->cleanCurrent();
257 $this->filelist->clipObj->endClipboard(); // Saves
258
259 // If the "cmd" was to delete files from the list (clipboard thing), do that:
260 if ($this->cmd=='delete') {
261 $items = $this->filelist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),'_FILE',1);
262 if (count($items)) {
263 // Make command array:
264 $FILE=array();
265 reset($items);
266 while(list(,$v)=each($items)) {
267 $FILE['delete'][]=array('data'=>$v);
268 }
269
270 // Init file processing object for deleting and pass the cmd array.
271 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
272 $fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
273 $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
274 $fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
275 $fileProcessor->start($FILE);
276 $fileProcessor->processData();
277
278 $fileProcessor->printLogErrorMessages();
279 }
280 }
281
282 if (!isset($this->MOD_SETTINGS['sort'])) {
283 // Set default sorting
284 $this->MOD_SETTINGS['sort'] = 'file';
285 $this->MOD_SETTINGS['reverse'] = 0;
286 }
287
288 // Start up filelisting object, include settings.
289 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
290 $this->filelist->start($this->id, $this->pointer, $this->MOD_SETTINGS['sort'], $this->MOD_SETTINGS['reverse'], $this->MOD_SETTINGS['clipBoard'], $this->MOD_SETTINGS['bigControlPanel']);
291
292 // Generate the list
293 $this->filelist->generateList();
294
295 // Write the footer
296 $this->filelist->writeBottom();
297
298 // Set top JavaScript:
299 $this->doc->JScode=$this->doc->wrapScriptTags('
300
301 if (top.fsMod) top.fsMod.recentIds["file"] = unescape("'.rawurlencode($this->id).'");
302 function jumpToUrl(URL) { //
303 window.location.href = URL;
304 }
305
306 '.$this->filelist->CBfunctions() // ... and add clipboard JavaScript functions
307 );
308
309 // This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
310 $this->doc->getContextMenuCode();
311
312 // Setting up the buttons and markers for docheader
313 list($buttons, $otherMarkers) = $this->filelist->getButtonsAndOtherMarkers($this->id);
314
315 // add the folder info to the marker array
316 $otherMarkers['FOLDER_INFO'] = $this->filelist->getFolderInfo();
317
318 $docHeaderButtons = array_merge($this->getButtons(), $buttons);
319
320 // Build the <body> for the module
321 $this->content = $this->doc->startPage($LANG->getLL('files'));
322
323 // Create output
324 $pageContent='';
325 $pageContent.= '<form action="'.htmlspecialchars($this->filelist->listURL()).'" method="post" name="dblistForm">';
326 $pageContent.= $this->filelist->HTMLcode;
327 $pageContent.= '<input type="hidden" name="cmd" /></form>';
328
329
330 if ($this->filelist->HTMLcode) { // Making listing options:
331
332 $pageContent.='
333
334 <!--
335 Listing options for clipboard and thumbnails
336 -->
337 <div id="typo3-listOptions">
338 ';
339
340 // Add "display bigControlPanel" checkbox:
341 $pageContent.=t3lib_BEfunc::getFuncCheck($this->id, 'SET[bigControlPanel]', $this->MOD_SETTINGS['bigControlPanel'], 'file_list.php', '', 'id="bigControlPanel"') . '<label for="bigControlPanel"> ' .$LANG->getLL('bigControlPanel', 1) . '</label><br />';
342
343 // Add "display thumbnails" checkbox:
344 $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 />';
345
346 // Add clipboard button
347 $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>';
348
349 $pageContent.='
350 </div>
351 ';
352
353
354 // Set clipboard:
355 if ($this->MOD_SETTINGS['clipBoard']) {
356 $pageContent.=$this->filelist->clipObj->printClipboard();
357 $pageContent.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_clipboard', $GLOBALS['BACK_PATH']);
358 }
359 }
360
361 $markerArray = array(
362 'CSH' => $docHeaderButtons['csh'],
363 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
364 'CONTENT' => $pageContent
365 );
366
367 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, array_merge($markerArray, $otherMarkers));
368 $this->content.= $this->doc->endPage();
369 $this->content = $this->doc->insertStylesAndJS($this->content);
370
371 } else {
372 // Create output - no access (no warning though)
373 $this->content = '';
374 $this->content .= $this->doc->startPage($LANG->getLL('files'));
375 $this->content .= $this->doc->endPage();
376 $this->content = $this->doc->insertStylesAndJS($this->content);
377 }
378
379
380 }
381
382 /**
383 * Outputting the accumulated content to screen
384 *
385 * @return void
386 */
387 function printContent() {
388 echo $this->content;
389 }
390
391 /**
392 * Create the panel of buttons for submitting the form or otherwise perform operations.
393 *
394 * @return array all available buttons as an assoc. array
395 */
396 function getButtons() {
397 global $TCA, $LANG, $BACK_PATH, $BE_USER;
398
399 $buttons = array(
400 'csh' => '',
401 'shortcut' => '',
402 'upload' => '',
403 'new' => '',
404 );
405
406 // Add shortcut
407 if ($BE_USER->mayMakeShortcut()) {
408 $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']);
409 }
410
411 // FileList Module CSH:
412 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_module', $GLOBALS['BACK_PATH'], '', TRUE);
413
414 // upload button
415 $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)).'" />';
416 $buttons['upload'] = '<a href="' . $BACK_PATH . 'file_upload.php?target=' . rawurlencode($this->id) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '" id="button-upload">' . $theIcon . '</a>';
417
418 $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)).'" />';
419 $buttons['new'] = '<a href="' . $BACK_PATH . 'file_newfolder.php?target=' . rawurlencode($this->id) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '">' . $theIcon . '</a>';
420
421 return $buttons;
422 }
423
424 }
425
426
427 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']) {
428 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']);
429 }
430
431
432
433 // Make instance:
434 $SOBE = t3lib_div::makeInstance('SC_file_list');
435 $SOBE->init();
436 $SOBE->main();
437 $SOBE->printContent();
438
439 ?>