Cleanup: Updated copyright notices
[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 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
58 require_once (PATH_t3lib.'class.t3lib_extfilefunc.php');
59 require_once (PATH_t3lib.'class.t3lib_recordlist.php');
60 require_once (PATH_t3lib.'class.t3lib_clipboard.php');
61 require_once (PATH_t3lib.'class.t3lib_parsehtml.php');
62 require_once ('class.file_list.inc');
63 $BE_USER->modAccess($MCONF,1);
64
65
66
67
68
69
70
71 /**
72 * Script Class for creating the list of files in the File > Filelist module
73 *
74 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
75 * @package TYPO3
76 * @subpackage core
77 */
78 class SC_file_list {
79 var $MCONF=array(); // Module configuration
80 var $MOD_MENU=array();
81 var $MOD_SETTINGS=array();
82
83
84 // Internal:
85 var $content; // Accumulated HTML output
86
87 /**
88 * File processing object
89 *
90 * @var t3lib_basicFileFunctions
91 */
92 var $basicFF;
93
94 /**
95 * Document template object
96 *
97 * @var template
98 */
99 var $doc;
100
101 // Internal, static: GPvars:
102 var $id; // "id" -> the path to list.
103 var $pointer; // Pointer to listing
104 var $table; // "Table"
105 var $imagemode; // Thumbnail mode.
106 var $cmd;
107 var $overwriteExistingFiles;
108
109
110 /**
111 * Initialize variables, file object
112 * Incoming GET vars include id, pointer, table, imagemode
113 *
114 * @return void
115 */
116 function init() {
117 global $TYPO3_CONF_VARS,$FILEMOUNTS;
118
119 // Setting GPvars:
120 $this->id = t3lib_div::_GP('id');
121 $this->pointer = t3lib_div::_GP('pointer');
122 $this->table = t3lib_div::_GP('table');
123 $this->imagemode = t3lib_div::_GP('imagemode');
124 $this->cmd = t3lib_div::_GP('cmd');
125 $this->overwriteExistingFiles = t3lib_div::_GP('overwriteExistingFiles');
126
127 // Setting module name:
128 $this->MCONF = $GLOBALS['MCONF'];
129
130 // File operation object:
131 $this->basicFF = t3lib_div::makeInstance('t3lib_basicFileFunctions');
132 $this->basicFF->init($FILEMOUNTS,$TYPO3_CONF_VARS['BE']['fileExtensions']);
133
134 // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
135 $this->menuConfig();
136 }
137
138 /**
139 * Setting the menu/session variables
140 *
141 * @return void
142 */
143 function menuConfig() {
144 // MENU-ITEMS:
145 // If array, then it's a selector box menu
146 // If empty string it's just a variable, that'll be saved.
147 // Values NOT in this array will not be saved in the settings-array for the module.
148 $this->MOD_MENU = array(
149 'sort' => '',
150 'reverse' => '',
151 'displayThumbs' => '',
152 'clipBoard' => ''
153 );
154
155 // CLEANSE SETTINGS
156 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
157 }
158
159 /**
160 * Main function, creating the listing
161 *
162 * @return void
163 */
164 function main() {
165 global $BE_USER,$LANG,$BACK_PATH,$TYPO3_CONF_VARS,$FILEMOUNTS;
166
167 // Initialize the template object
168 $this->doc = t3lib_div::makeInstance('template');
169 $this->doc->backPath = $BACK_PATH;
170 $this->doc->setModuleTemplate('templates/file_list.html');
171
172 // Validating the input "id" (the path, directory!) and checking it against the mounts of the user.
173 $this->id = $this->basicFF->is_directory($this->id);
174 $access = $this->id && $this->basicFF->checkPathAgainstMounts($this->id.'/');
175
176 // There there was access to this file path, continue, make the list
177 if ($access) {
178
179 // Create filelisting object
180 $this->filelist = t3lib_div::makeInstance('fileList');
181 $this->filelist->backPath = $BACK_PATH;
182 $this->filelist->thumbs = $this->MOD_SETTINGS['displayThumbs']?1:$BE_USER->uc['thumbnailsByDefault'];
183
184 // Create clipboard object and initialize that
185 $this->filelist->clipObj = t3lib_div::makeInstance('t3lib_clipboard');
186 $this->filelist->clipObj->fileMode=1;
187 $this->filelist->clipObj->initializeClipboard();
188
189 $CB = t3lib_div::_GET('CB');
190 if ($this->cmd=='setCB') $CB['el'] = $this->filelist->clipObj->cleanUpCBC(array_merge(t3lib_div::_POST('CBH'),t3lib_div::_POST('CBC')),'_FILE');
191 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal';
192 $this->filelist->clipObj->setCmd($CB);
193 $this->filelist->clipObj->cleanCurrent();
194 $this->filelist->clipObj->endClipboard(); // Saves
195
196 // If the "cmd" was to delete files from the list (clipboard thing), do that:
197 if ($this->cmd=='delete') {
198 $items = $this->filelist->clipObj->cleanUpCBC(t3lib_div::_POST('CBC'),'_FILE',1);
199 if (count($items)) {
200 // Make command array:
201 $FILE=array();
202 reset($items);
203 while(list(,$v)=each($items)) {
204 $FILE['delete'][]=array('data'=>$v);
205 }
206
207 // Init file processing object for deleting and pass the cmd array.
208 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
209 $fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
210 $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
211 $fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
212 $fileProcessor->start($FILE);
213 $fileProcessor->processData();
214
215 $fileProcessor->printLogErrorMessages();
216 }
217 }
218
219 if (!isset($this->MOD_SETTINGS['sort'])) {
220 // Set default sorting
221 $this->MOD_SETTINGS['sort'] = 'file';
222 $this->MOD_SETTINGS['reverse'] = 0;
223 }
224
225 // Start up filelisting object, include settings.
226 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
227 $this->filelist->start($this->id,$this->pointer,$this->MOD_SETTINGS['sort'],$this->MOD_SETTINGS['reverse'],$this->MOD_SETTINGS['clipBoard']);
228
229 // Generate the list
230 $this->filelist->generateList();
231
232 // Write the footer
233 $this->filelist->writeBottom();
234
235 // Set top JavaScript:
236 $this->doc->JScode=$this->doc->wrapScriptTags('
237
238 if (top.fsMod) top.fsMod.recentIds["file"] = unescape("'.rawurlencode($this->id).'");
239 function jumpToUrl(URL) { //
240 window.location.href = URL;
241 }
242
243 '.$this->filelist->CBfunctions() // ... and add clipboard JavaScript functions
244 );
245
246 // This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
247 $this->doc->getContextMenuCode();
248
249 // Setting up the buttons and markers for docheader
250 list($buttons, $otherMarkers) = $this->filelist->getButtonsAndOtherMarkers($this->id);
251
252 // add the folder info to the marker array
253 $otherMarkers['FOLDER_INFO'] = $this->filelist->getFolderInfo();
254
255 $docHeaderButtons = array_merge($this->getButtons(), $buttons);
256
257 // Build the <body> for the module
258 $this->content = $this->doc->startPage($LANG->getLL('files'));
259
260 // Create output
261 $pageContent='';
262 $pageContent.= '<form action="'.htmlspecialchars($this->filelist->listURL()).'" method="post" name="dblistForm">';
263 $pageContent.= $this->filelist->HTMLcode;
264 $pageContent.= '<input type="hidden" name="cmd" /></form>';
265
266
267 if ($this->filelist->HTMLcode) { // Making listing options:
268
269 $pageContent.='
270
271 <!--
272 Listing options for clipboard and thumbnails
273 -->
274 <div id="typo3-listOptions">
275 ';
276
277 // Add "display thumbnails" checkbox:
278 $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 />';
279
280 // Add clipboard button
281 $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>';
282
283 $pageContent.='
284 </div>
285 ';
286
287
288 // Set clipboard:
289 if ($this->MOD_SETTINGS['clipBoard']) {
290 $pageContent.=$this->filelist->clipObj->printClipboard();
291 $pageContent.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_clipboard', $GLOBALS['BACK_PATH']);
292 }
293 }
294
295 $markerArray = array(
296 'CSH' => $docHeaderButtons['csh'],
297 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
298 'CONTENT' => $pageContent
299 );
300
301 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, array_merge($markerArray, $otherMarkers));
302 $this->content.= $this->doc->endPage();
303 $this->content = $this->doc->insertStylesAndJS($this->content);
304
305 } else {
306 // Create output - no access (no warning though)
307 $this->content = '';
308 $this->content .= $this->doc->startPage($LANG->getLL('files'));
309 $this->content .= $this->doc->endPage();
310 $this->content = $this->doc->insertStylesAndJS($this->content);
311 }
312
313
314 }
315
316 /**
317 * Outputting the accumulated content to screen
318 *
319 * @return void
320 */
321 function printContent() {
322 echo $this->content;
323 }
324
325 /**
326 * Create the panel of buttons for submitting the form or otherwise perform operations.
327 *
328 * @return array all available buttons as an assoc. array
329 */
330 function getButtons() {
331 global $TCA, $LANG, $BACK_PATH, $BE_USER;
332
333 $buttons = array(
334 'csh' => '',
335 'shortcut' => '',
336 'upload' => '',
337 'new' => '',
338 );
339
340 // Add shortcut
341 if ($BE_USER->mayMakeShortcut()) {
342 $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']);
343 }
344
345 // FileList Module CSH:
346 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'filelist_module', $GLOBALS['BACK_PATH'], '', TRUE);
347
348 // upload button
349 $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.php:cm.upload',1)).'" alt="" />';
350 $buttons['upload'] = '<a href="'.$BACK_PATH.'file_upload.php?target='.rawurlencode($this->id).'&returnUrl='.rawurlencode($this->filelist->listURL()).'">'.$theIcon.'</a>';
351
352 $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.php:cm.new',1)).'" alt="" />';
353 $buttons['new'] = '<a href="'.$BACK_PATH.'file_newfolder.php?target='.rawurlencode($this->id).'&returnUrl='.rawurlencode($this->filelist->listURL()).'">'.$theIcon.'</a>';
354
355 return $buttons;
356 }
357
358 }
359
360
361 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']) {
362 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']);
363 }
364
365
366
367 // Make instance:
368 $SOBE = t3lib_div::makeInstance('SC_file_list');
369 $SOBE->init();
370 $SOBE->main();
371 $SOBE->printContent();
372
373 ?>