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