Initial revision
[Packages/TYPO3.CMS.git] / typo3 / file_list.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (kasper@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 * @author Kasper Skårhøj <kasper@typo3.com>
31 * @package TYPO3
32 * @subpackage core
33 * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
34 */
35
36 unset($MCONF);
37 require ('mod/file/list/conf.php');
38 require ('init.php');
39 require ('template.php');
40 require ('sysext/lang/locallang_mod_file_list.php');
41 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
42 require_once (PATH_t3lib.'class.t3lib_extfilefunc.php');
43 require_once (PATH_t3lib.'class.t3lib_recordlist.php');
44 require_once (PATH_t3lib.'class.t3lib_clipboard.php');
45 require_once ('class.file_list.inc');
46 $BE_USER->modAccess($MCONF,1);
47
48
49
50 // ***************************
51 // Script Classes
52 // ***************************
53 class SC_file_list {
54 var $MCONF=array(); // Module configuration
55 var $MOD_MENU=array();
56 var $MOD_SETTINGS=array();
57
58 // GET vars set:
59 var $id; // "id" -> the path to list.
60 var $pointer; // Pointer to listing
61 var $table; // "Table"
62 var $imagemode; // Thumbnail mode.
63
64 var $content; // Accumulated HTML output
65 var $basicFF; // File operation object (t3lib_basicFileFunctions)
66 var $doc; // Template object
67
68
69
70 /**
71 * Initialize variables, file object
72 * Incoming GET vars include id, pointer, table, imagemode
73 *
74 * @return void
75 */
76 function init() {
77 global $TYPO3_CONF_VARS,$FILEMOUNTS;
78
79 $this->MCONF = $GLOBALS['MCONF'];
80
81 $this->id = t3lib_div::GPvar('id');
82 $this->pointer = t3lib_div::GPvar('pointer');
83 $this->table = t3lib_div::GPvar('table');
84 $this->imagemode = t3lib_div::GPvar('imagemode');
85 $this->basicFF = t3lib_div::makeInstance('t3lib_basicFileFunctions');
86 $this->basicFF->init($FILEMOUNTS,$TYPO3_CONF_VARS['BE']['fileExtensions']);
87
88 // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
89 $this->menuConfig();
90 }
91
92 /**
93 * Setting the menu/session variables
94 *
95 * @return void
96 */
97 function menuConfig() {
98 // MENU-ITEMS:
99 // If array, then it's a selector box menu
100 // If empty string it's just a variable, that'll be saved.
101 // Values NOT in this array will not be saved in the settings-array for the module.
102 $this->MOD_MENU = array(
103 'sort' => '',
104 'reverse' => '',
105 'displayThumbs' => '',
106 'clipBoard' => ''
107 );
108
109 // CLEANSE SETTINGS
110 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::GPvar('SET'), $this->MCONF['name']);
111 }
112
113 /**
114 * Main function, creating the listing
115 *
116 * @param
117 * @return
118 */
119 function main() {
120 global $BE_USER,$LANG,$BACK_PATH,$HTTP_GET_VARS,$HTTP_POST_VARS,$TYPO3_CONF_VARS,$FILEMOUNTS;
121
122 // Initialize the template object
123 $this->doc = t3lib_div::makeInstance('template');
124 $this->doc->backPath = $BACK_PATH;
125 $this->doc->docType = 'xhtml_trans';
126
127 // Validating the input "id" (the path, directory!) and checking it against the mounts of the user.
128 $this->id = $this->basicFF->is_directory($this->id);
129 $access = $this->id && $this->basicFF->checkPathAgainstMounts($this->id.'/');
130
131 // There there was access to this file path, continue, make the list
132 if ($access) {
133
134 // Create filelisting object
135 $filelist = t3lib_div::makeInstance('fileList');
136 $filelist->backPath = $BACK_PATH;
137 $filelist->thumbs = $this->MOD_SETTINGS['displayThumbs']?1:$BE_USER->uc['thumbnailsByDefault'];
138
139 // Create clipboard object and initialize that
140 $filelist->clipObj = t3lib_div::makeInstance('t3lib_clipboard');
141 $filelist->clipObj->fileMode=1;
142 $filelist->clipObj->initializeClipboard();
143
144 $CB = $HTTP_GET_VARS['CB'];
145 if (t3lib_div::GPvar('cmd')=='setCB') $CB['el'] = $filelist->clipObj->cleanUpCBC(array_merge($HTTP_POST_VARS['CBH'],$HTTP_POST_VARS['CBC']),'_FILE');
146 if (!$this->MOD_SETTINGS['clipBoard']) $CB['setP']='normal';
147 $filelist->clipObj->setCmd($CB);
148 $filelist->clipObj->cleanCurrent();
149 $filelist->clipObj->endClipboard(); // Saves
150
151 // If the "cmd" was to delete files from the list (clipboard thing), do that:
152 if (t3lib_div::GPvar('cmd')=='delete') {
153 $items = $filelist->clipObj->cleanUpCBC($HTTP_POST_VARS['CBC'],'_FILE',1);
154 if (count($items)) {
155 // Make command array:
156 $FILE=array();
157 reset($items);
158 while(list(,$v)=each($items)) {
159 $FILE['delete'][]=array('data'=>$v);
160 }
161
162 // Init file processing object for deleting and pass the cmd array.
163 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
164 $fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']);
165 $fileProcessor->init_actionPerms($BE_USER->user['fileoper_perms']);
166 $fileProcessor->dontCheckForUnique = t3lib_div::GPvar('overwriteExistingFiles') ? 1 : 0;
167 $fileProcessor->start($FILE);
168 $fileProcessor->processData();
169
170 // Redirect to the status file.
171 Header('Location: '.t3lib_div::locationHeaderUrl('status_file.php'));
172 exit;
173 }
174 }
175
176 // Start up filelisting object, include settings.
177 $this->pointer = t3lib_div::intInRange($this->pointer,0,100000);
178 $filelist->start($this->id,$this->pointer,$this->MOD_SETTINGS['sort'],$this->MOD_SETTINGS['reverse'],$this->MOD_SETTINGS['clipBoard']);
179
180 // Write the header
181 $filelist->writeTop($this->id);
182
183 // Generate the list
184 $filelist->generateList($this->id,$this->table);
185
186 // Write the footer
187 $filelist->writeBottom();
188
189 // Set top JavaScript:
190 $this->doc->JScode=$this->doc->wrapScriptTags('
191
192 if (top.fsMod) top.fsMod.recentIds["file"] = unescape("'.rawurlencode($this->id).'");
193 function jumpToUrl(URL) {
194 document.location = URL;
195 }
196
197 '.$filelist->CBfunctions() // ... and add clipboard JavaScript functions
198 );
199
200 // This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
201 $CMparts=$this->doc->getContextMenuCode();
202 $this->doc->bodyTagAdditions = $CMparts[1];
203 $this->doc->JScode.=$CMparts[0];
204 $this->doc->postCode.= $CMparts[2];
205
206
207 // Create output
208 $this->content='';
209 $this->content.=$this->doc->startPage($LANG->getLL('files'));
210 $this->content.= '<form action="'.$filelist->listURL().'" method="post" name="dblistForm">';
211 $this->content.= $filelist->HTMLcode;
212 $this->content.= '<input type="hidden" name="cmd"></form>';
213
214 if ($filelist->HTMLcode) { // Making search form:
215 // Add "display thumbnails" checkbox:
216 $this->content.=t3lib_BEfunc::getFuncCheck($this->id,'SET[displayThumbs]',$this->MOD_SETTINGS['displayThumbs'],'file_list.php','').' '.$LANG->getLL('displayThumbs',1).'<br />';
217
218 // Add clipboard button
219 $this->content.=t3lib_BEfunc::getFuncCheck($this->id,'SET[clipBoard]',$this->MOD_SETTINGS['clipBoard'],'file_list.php','').' '.$LANG->getLL('clipBoard',1);
220
221 // Set clipboard:
222 if ($this->MOD_SETTINGS['clipBoard']) $this->content.=$filelist->clipObj->printClipboard();
223 }
224
225 // Add shortcut
226 if ($BE_USER->mayMakeShortcut()) {
227 $this->content.=$this->doc->makeShortcutIcon('pointer,id,target,table',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']);
228 }
229 } else {
230 // Create output - no access (no warning though)
231 $this->content='';
232 $this->content.=$this->doc->startPage($LANG->getLL('files'));
233 }
234 }
235
236 /**
237 * Ending page and outputting content from ->content
238 */
239 function printContent() {
240 global $SOBE;
241
242 $this->content.= $this->doc->endPage();
243 echo $this->content;
244 }
245 }
246
247 // Include extension?
248 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']) {
249 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_list.php']);
250 }
251
252
253
254
255
256
257
258
259
260
261
262
263 // Make instance:
264 $SOBE = t3lib_div::makeInstance('SC_file_list');
265 $SOBE->init();
266 $SOBE->main();
267 $SOBE->printContent();
268
269
270 if ($TYPO3_CONF_VARS['BE']['compressionLevel']) {
271 new gzip_encode($TYPO3_CONF_VARS['BE']['compressionLevel']);
272 }
273 ?>