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