Followup to #11148: Remove static require_once() to t3lib and tslib and use autoloadi...
[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 );
150
151 // CLEANSE SETTINGS
152 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
153 }
154
155 /**
156 * Main function, creating the listing
157 *
158 * @return void
159 */
160 function main() {
161 global $BE_USER,$LANG,$BACK_PATH,$TYPO3_CONF_VARS,$FILEMOUNTS;
162
163 // Initialize the template object
164 $this->doc = t3lib_div::makeInstance('template');
165 $this->doc->backPath = $BACK_PATH;
166 $this->doc->setModuleTemplate('templates/file_list.html');
167 $this->doc->loadPrototype();
168
169 // Validating the input "id" (the path, directory!) and checking it against the mounts of the user.
170 $this->id = $this->basicFF->is_directory($this->id);
171 $access = $this->id && $this->basicFF->checkPathAgainstMounts($this->id.'/');
172
173 // There there was access to this file path, continue, make the list
174 if ($access) {
175 // include the initialization for the flash uploader
176 if ($GLOBALS['BE_USER']->uc['enableFlashUploader']) {
177
178 $this->doc->JScodeArray['flashUploader'] = '
179 if (top.TYPO3.FileUploadWindow.isFlashAvailable()) {
180 document.observe("dom:loaded", function() {
181 // monitor the button
182 $("button-upload").observe("click", initFlashUploader);
183
184 function initFlashUploader(event) {
185 // set the page specific options for the flashUploader
186 var flashUploadOptions = {
187 uploadURL: top.TS.PATH_typo3 + "ajax.php",
188 uploadFileSizeLimit: "' . t3lib_div::getMaxUploadFileSize() . '",
189 uploadFileTypes: {
190 allow: "' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']['allow'] . '",
191 deny: "' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']['deny'] . '"
192 },
193 uploadFilePostName: "upload_1",
194 uploadPostParams: {
195 "file[upload][1][target]": "' . $this->id . '",
196 "file[upload][1][data]": 1,
197 "file[upload][1][charset]": "utf-8",
198 "ajaxID": "TYPO3_tcefile::process"
199 }
200 };
201
202 // get the flashUploaderWindow instance from the parent frame
203 var flashUploader = top.TYPO3.FileUploadWindow.getInstance(flashUploadOptions);
204 // add an additional function inside the container to show the checkbox option
205 var infoComponent = new top.Ext.Panel({
206 autoEl: { tag: "div" },
207 height: "auto",
208 bodyBorder: false,
209 border: false,
210 hideBorders: true,
211 cls: "t3-upload-window-infopanel",
212 id: "t3-upload-window-infopanel-addition",
213 html: \'<label for="overrideExistingFilesCheckbox"><input id="overrideExistingFilesCheckbox" type="checkbox" onclick="setFlashPostOptionOverwriteExistingFiles(this);" />\' + top.String.format(top.TYPO3.LLL.fileUpload.infoComponentOverrideFiles) + \'</label>\'
214 });
215 flashUploader.add(infoComponent);
216
217 // do a reload of this frame once all uploads are done
218 flashUploader.on("totalcomplete", function() {
219 window.location.reload();
220 });
221
222 // this is the callback function that delivers the additional post parameter to the flash application
223 top.setFlashPostOptionOverwriteExistingFiles = function(checkbox) {
224 var uploader = top.TYPO3.getInstance("FileUploadWindow");
225 if (uploader.isVisible()) {
226 uploader.swf.addPostParam("overwriteExistingFiles", (checkbox.checked == true ? 1 : 0));
227 }
228 };
229
230 event.stop();
231 };
232 });
233 }
234 ';
235 }
236 // Create filelisting object
237 $this->filelist = t3lib_div::makeInstance('fileList');
238 $this->filelist->backPath = $BACK_PATH;
239 $this->filelist->thumbs = $this->MOD_SETTINGS['displayThumbs']?1:$BE_USER->uc['thumbnailsByDefault'];
240
241 // Create clipboard object and initialize that
242 $this->filelist->clipObj = t3lib_div::makeInstance('t3lib_clipboard');
243 $this->filelist->clipObj->fileMode=1;
244 $this->filelist->clipObj->initializeClipboard();
245
246 $CB = t3lib_div::_GET('CB');
247 if ($this->cmd=='setCB') $CB['el'] = $this->filelist->clipObj->cleanUpCBC(array_merge(t3lib_div::_POST('CBH'),t3lib_div::_POST('CBC')),'_FILE');
248 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal';
249 $this->filelist->clipObj->setCmd($CB);
250 $this->filelist->clipObj->cleanCurrent();
251 $this->filelist->clipObj->endClipboard(); // Saves
252
253 // If the "cmd" was to delete files from the list (clipboard thing), do that:
254 if ($this->cmd=='delete') {
255 $items = $this->filelist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),'_FILE',1);
256 if (count($items)) {
257 // Make command array:
258 $FILE=array();
259 reset($items);
260 while(list(,$v)=each($items)) {
261 $FILE['delete'][]=array('data'=>$v);
262 }
263
264 // Init file processing object for deleting and pass the cmd array.
265 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
266 $fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
267 $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
268 $fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
269 $fileProcessor->start($FILE);
270 $fileProcessor->processData();
271
272 $fileProcessor->printLogErrorMessages();
273 }
274 }
275
276 if (!isset($this->MOD_SETTINGS['sort'])) {
277 // Set default sorting
278 $this->MOD_SETTINGS['sort'] = 'file';
279 $this->MOD_SETTINGS['reverse'] = 0;
280 }
281
282 // Start up filelisting object, include settings.
283 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
284 $this->filelist->start($this->id,$this->pointer,$this->MOD_SETTINGS['sort'],$this->MOD_SETTINGS['reverse'],$this->MOD_SETTINGS['clipBoard']);
285
286 // Generate the list
287 $this->filelist->generateList();
288
289 // Write the footer
290 $this->filelist->writeBottom();
291
292 // Set top JavaScript:
293 $this->doc->JScode=$this->doc->wrapScriptTags('
294
295 if (top.fsMod) top.fsMod.recentIds["file"] = unescape("'.rawurlencode($this->id).'");
296 function jumpToUrl(URL) { //
297 window.location.href = URL;
298 }
299
300 '.$this->filelist->CBfunctions() // ... and add clipboard JavaScript functions
301 );
302
303 // This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
304 $this->doc->getContextMenuCode();
305
306 // Setting up the buttons and markers for docheader
307 list($buttons, $otherMarkers) = $this->filelist->getButtonsAndOtherMarkers($this->id);
308
309 // add the folder info to the marker array
310 $otherMarkers['FOLDER_INFO'] = $this->filelist->getFolderInfo();
311
312 $docHeaderButtons = array_merge($this->getButtons(), $buttons);
313
314 // Build the <body> for the module
315 $this->content = $this->doc->startPage($LANG->getLL('files'));
316
317 // Create output
318 $pageContent='';
319 $pageContent.= '<form action="'.htmlspecialchars($this->filelist->listURL()).'" method="post" name="dblistForm">';
320 $pageContent.= $this->filelist->HTMLcode;
321 $pageContent.= '<input type="hidden" name="cmd" /></form>';
322
323
324 if ($this->filelist->HTMLcode) { // Making listing options:
325
326 $pageContent.='
327
328 <!--
329 Listing options for clipboard and thumbnails
330 -->
331 <div id="typo3-listOptions">
332 ';
333
334 // Add "display thumbnails" checkbox:
335 $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 />';
336
337 // Add clipboard button
338 $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>';
339
340 $pageContent.='
341 </div>
342 ';
343
344
345 // Set clipboard:
346 if ($this->MOD_SETTINGS['clipBoard']) {
347 $pageContent.=$this->filelist->clipObj->printClipboard();
348 $pageContent.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_clipboard', $GLOBALS['BACK_PATH']);
349 }
350 }
351
352 $markerArray = array(
353 'CSH' => $docHeaderButtons['csh'],
354 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
355 'CONTENT' => $pageContent
356 );
357
358 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, array_merge($markerArray, $otherMarkers));
359 $this->content.= $this->doc->endPage();
360 $this->content = $this->doc->insertStylesAndJS($this->content);
361
362 } else {
363 // Create output - no access (no warning though)
364 $this->content = '';
365 $this->content .= $this->doc->startPage($LANG->getLL('files'));
366 $this->content .= $this->doc->endPage();
367 $this->content = $this->doc->insertStylesAndJS($this->content);
368 }
369
370
371 }
372
373 /**
374 * Outputting the accumulated content to screen
375 *
376 * @return void
377 */
378 function printContent() {
379 echo $this->content;
380 }
381
382 /**
383 * Create the panel of buttons for submitting the form or otherwise perform operations.
384 *
385 * @return array all available buttons as an assoc. array
386 */
387 function getButtons() {
388 global $TCA, $LANG, $BACK_PATH, $BE_USER;
389
390 $buttons = array(
391 'csh' => '',
392 'shortcut' => '',
393 'upload' => '',
394 'new' => '',
395 );
396
397 // Add shortcut
398 if ($BE_USER->mayMakeShortcut()) {
399 $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']);
400 }
401
402 // FileList Module CSH:
403 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_module', $GLOBALS['BACK_PATH'], '', TRUE);
404
405 // upload button
406 $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)).'" />';
407 $buttons['upload'] = '<a href="' . $BACK_PATH . 'file_upload.php?target=' . rawurlencode($this->id) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '" id="button-upload">' . $theIcon . '</a>';
408
409 $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)).'" />';
410 $buttons['new'] = '<a href="' . $BACK_PATH . 'file_newfolder.php?target=' . rawurlencode($this->id) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '">' . $theIcon . '</a>';
411
412 return $buttons;
413 }
414
415 }
416
417
418 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']) {
419 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']);
420 }
421
422
423
424 // Make instance:
425 $SOBE = t3lib_div::makeInstance('SC_file_list');
426 $SOBE->init();
427 $SOBE->main();
428 $SOBE->printContent();
429
430 ?>