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