Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezfilemanager/user/filelist.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: filelist.php 9424 2002-04-15 11:49:48Z jhe $
5 //
6 // Created on: <10-Dec-2000 16:16:20 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezlog.php" );
30
31 // include_once( "ezfilemanager/classes/ezvirtualfile.php" );
32 // include_once( "ezfilemanager/classes/ezvirtualfolder.php" );
33
34 // include_once( "ezuser/classes/ezuser.php" );
35 // include_once( "ezuser/classes/ezpermission.php" );
36 // include_once( "ezuser/classes/ezobjectpermission.php" );
37
38 $ini =& eZINI::instance( 'site.ini' );
39 $wwwDir = $ini->WWWDir;
40 $indexFile = $ini->Index;
41
42 $Language = $ini->variable( "eZFileManagerMain", "Language" );
43 $ImageDir = $ini->variable( "eZFileManagerMain", "ImageDir" );
44 $FileCat = $ini->variable( "eZFileManagerMain", "FileCat" );
45 $SyncDir = $ini->variable( "eZFileManagerMain", "SyncDir" );
46 $SectionID = $ini->variable( "eZFileManagerMain", "DefaultSection" );
47 $Limit = $ini->variable( "eZFileManagerMain", "Limit" );
48 $ShowUpFolder = $ini->variable( "eZFileManagerMain", "ShowUpFolder" ) == "enabled";
49
50 $t = new eZTemplate( "kernel/ezfilemanager/user/" . $ini->variable( "eZFileManagerMain", "TemplateDir" ),
51 "kernel/ezfilemanager/user/intl/", $Language, "filelist.php" );
52
53 $t->set_file( "file_list_page_tpl", "filelist.tpl" );
54
55 $t->setAllStrings();
56
57 $t->set_block( "file_list_page_tpl", "current_folder_tpl", "current_folder" );
58
59 // path
60 $t->set_block( "file_list_page_tpl", "path_item_tpl", "path_item" );
61 $t->set_block( "file_list_page_tpl", "write_menu_tpl", "write_menu" );
62 $t->set_block( "file_list_page_tpl", "delete_menu_tpl", "delete_menu" );
63 $t->set_block( "file_list_page_tpl", "file_list_tpl", "file_list" );
64 $t->set_block( "file_list_page_tpl", "next_tpl", "next" );
65 $t->set_block( "file_list_page_tpl", "prev_tpl", "prev" );
66
67 $t->set_block( "file_list_tpl", "file_tpl", "file" );
68
69 $t->set_block( "file_tpl", "read_tpl", "read" );
70
71 $t->set_block( "read_tpl", "description_edit_tpl", "description_edit" );
72 $t->set_block( "read_tpl", "description_tpl", "description" );
73
74 $t->set_block( "file_tpl", "write_tpl", "write" );
75 $t->set_block( "file_tpl", "no_write_tpl", "no_write" );
76
77 $t->set_block( "file_list_page_tpl", "parent_folder_tpl", "parent_folder" );
78 $t->set_block( "file_list_page_tpl", "folder_list_tpl", "folder_list" );
79 $t->set_block( "folder_list_tpl", "folder_tpl", "folder" );
80
81 $t->set_block( "folder_tpl", "folder_write_tpl", "folder_write" );
82 $t->set_block( "folder_tpl", "folder_read_tpl", "folder_read" );
83
84 $t->set_var( "read", "" );
85 $t->set_var( "description_edit", "" );
86 $t->set_var( "description", "" );
87 $t->set_var( "sync_dir", $SyncDir );
88 /*
89 echo "<pre>";
90 print_r ($t);
91 echo "</pre>";
92 exit();
93 */
94 $user =& eZUser::currentUser();
95
96 if ( isSet ( $FileUpload ) )
97 {
98
99 $category = new eZVirtualFolder( $FileCat );
100 syncDir( $SyncFileDir, $category );
101 eZHTTPTool::header( "Location: /filemanager/list/$FileCat" );
102 exit();
103 }
104
105 $folder = new eZVirtualFolder( $FolderID );
106
107 if ( $FolderID == 0 )
108 $GlobalSectionID = $ini->variable( "eZFileManagerMain", "DefaultSection" );
109 else
110 $GlobalSectionID = eZVirtualFolder::sectionIDstatic ( $FolderID );
111 // init the section
112 $sectionObject =& eZSection::globalSectionObject( $GlobalSectionID );
113 $sectionObject->setOverrideVariables();
114
115 $error = true;
116
117 // Check for read permission in the current folder.
118 if ( eZObjectPermission::hasPermission( $folder->id(), "filemanager_folder", "r", $user ) ||
119 eZVirtualFolder::isOwner( $user, $folder->id() ) )
120 {
121 $error = false;
122 }
123
124 if ( $FolderID == 0 )
125 {
126 $error = false;
127 }
128
129 $t->set_var( "write_menu", "" );
130 $t->set_var( "delete_menu", "" );
131 $t->set_var( "current_folder", "" );
132 $t->set_var( "current_folder_description", "" );
133 $t->set_var( "folder", "" );
134
135
136 if ( $folder->id() != 0 )
137 {
138 $t->set_var( "current_folder_description", $folder->description() );
139 $t->set_var( "folder_id", $folder->id() );
140 $t->set_var( "folder_name", $folder->name() );
141 $t->set_var( "folder_description", $folder->description() );
142 $t->parse( "current_folder", "current_folder_tpl" );
143
144 $parent = $folder->parent();
145 if ( is_object( $parent ) )
146 $parent = $parent->id();
147 $t->set_var( "parent_folder_id", $parent );
148 $t->set_var( "td_class_parent", "bglight" );
149 if ( $ShowUpFolder )
150 $t->parse( "parent_folder", "parent_folder_tpl" );
151 else
152 $t->set_var( "parent_folder", "" );
153 }
154 else
155 {
156 $t->set_var( "parent_folder", "" );
157 }
158
159 // path
160 $pathArray =& $folder->path();
161
162 $t->set_var( "path_item", "" );
163 $lastPath = array();
164 foreach ( $pathArray as $path )
165 {
166 $t->set_var( "folder_id", $path[0] );
167 $t->set_var( "folder_name", $path[1] );
168
169 $t->parse( "path_item", "path_item_tpl", true );
170 $lastPath = $path;
171 }
172
173 if ( count( $lastPath ) == 0 )
174 {
175 $t->set_var( "top_folder_name", '' );
176 }
177 else
178 {
179 $t->set_var( "top_folder_name", $lastPath[1] );
180 }
181
182 // Print out the folders.
183 $folderList =& $folder->getByParent( $folder );
184
185 $i = ( $folder->id() && $ShowUpFolder ) ? 1 : 0;
186 $deleteFolders = false;
187
188 foreach ( $folderList as $folderItem )
189 {
190 $t->set_var( "folder_description", $folderItem->description() );
191 $t->set_var( "folder_name", $folderItem->name() );
192 $t->set_var( "folder_id", $folderItem->id() );
193
194 $t->set_var( "folder_read", "" );
195 $t->set_var( "folder_write", "" );
196
197 $t->set_var( "td_class", ( $i % 2 ) ? "bgdark" : "bglight" );
198
199 if ( ( $user ) &&
200 ( eZObjectPermission::hasPermission( $folderItem->id(), "filemanager_folder", "w", $user ) &&
201 eZObjectPermission::hasPermission( $folder->id(), "filemanager_folder", "w", $user ) ) ||
202 ( eZVirtualFolder::isOwner( $user, $folderItem->id() ) ) )
203 {
204 $t->parse( "folder_write", "folder_write_tpl" );
205 $deleteFolders = true;
206 }
207
208 if ( eZObjectPermission::hasPermission( $folderItem->id(), "filemanager_folder", "r", $user ) ||
209 eZVirtualFolder::isOwner( $user, $folderItem->id() ) )
210 {
211 $t->parse( "folder_read", "folder_read_tpl" );
212 $t->parse( "folder", "folder_tpl", true );
213 $i++;
214 }
215 }
216
217
218 if ( count( $folderList ) > 0 )
219 {
220 $t->parse( "folder_list", "folder_list_tpl" );
221 }
222 else
223 {
224 $t->set_var( "folder_list", "No folders to display. Click new folder to create one." );
225 }
226
227 // Print out the files.
228
229 $fileList =& $folder->files( "name", $Offset, $Limit );
230
231 //for debugging
232 /*
233 if ( count($fileList) > 0 )
234 {
235 echo "<pre>";
236 print_r($fileList);
237 echo "<pre>";
238 exit();
239 }
240 */
241
242 $deleteFiles = false;
243 foreach ( $fileList as $file )
244 {
245 $filename = $file->name();
246 if ( $ini->variable( "eZFileManagerMain", "DownloadOriginalFilename" ) == "true" )
247 $originalfilename = $file->originalFileName();
248 else
249 $originalfilename = $filename;
250
251 $t->set_var( "file_id", $file->id() );
252 $t->set_var( "original_file_name_without_spaces", str_replace( " ", "%20", $originalfilename ) );
253 $t->set_var( "original_file_name", $filename );
254 $t->set_var( "file_name", $filename );
255 $t->set_var( "file_url", $filename );
256 $t->set_var( "file_description", $file->description() );
257
258 $fileOwner =& $file->user();
259 if ( $fileOwner )
260 $t->set_var( "file_owner", $fileOwner->firstName() . " " . $fileOwner->lastName() );
261
262 $filePath = $file->filePath( true );
263
264 $size = $file->siFileSize();
265 $t->set_var( "file_size", $size["size-string"] );
266 $t->set_var( "file_unit", $size["unit"] );
267
268 $t->set_var( "file_read", "" );
269 $t->set_var( "file_write", "" );
270 $t->set_var( "td_class", ( $i % 2 ) ? "bgdark" : "bglight" );
271
272 if ( eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user ) ||
273 eZVirtualFile::isOwner( $user ,$file->id() ) )
274 {
275
276 if ( $user &&
277 ( eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "w", $user ) ||
278 eZVirtualFile::isOwner( $user, $file->id() ) ) )
279 {
280 $t->parse( "description_edit", "description_edit_tpl" );
281 $t->set_var( "description", "" );
282 }
283 else
284 {
285 $t->parse( "description", "description_tpl" );
286 $t->set_var( "description_edit", "" );
287 }
288
289 $t->parse( "read", "read_tpl" );
290 $i++;
291 }
292 else
293 {
294 $t->set_var( "read", "" );
295 }
296
297 if ( $user &&
298 ( eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "w", $user ) ||
299 eZVirtualFile::isOwner( $user, $file->id() ) ) )
300 {
301 $t->parse( "write", "write_tpl" );
302 $t->set_var( "no_write", "" );
303 $deleteFiles = true;
304 }
305 else
306 {
307 $t->set_var( "write", "" );
308 $t->parse( "no_write", "no_write_tpl" );
309 }
310
311 $t->parse( "file", "file_tpl", true );
312 }
313
314 $fileNumber = $folder->countFiles();
315
316 if ( $Offset > 0 )
317 {
318 $t->set_var( "prev_offset", ( $Offset - $Limit ) > 0 ? $Offset - $Limit : 0 );
319 $t->parse( "prev", "prev_tpl" );
320 }
321 else
322 {
323 $t->set_var( "prev", "" );
324 }
325
326 if ( $fileNumber > $Offset + $Limit )
327 {
328 $t->set_var( "next_offset", $Offset + $Limit );
329 $t->parse( "next", "next_tpl" );
330 }
331 else
332 {
333 $t->set_var( "next", "" );
334 }
335
336 if ( count( $fileList ) > 0 )
337 {
338 $t->parse( "file_list", "file_list_tpl" );
339 }
340 else
341 {
342 $t->set_var( "file_list", "" );
343 }
344
345 if ( $FolderID == 0 )
346 {
347 if ( eZPermission::checkPermission( eZUser::currentUser(), "eZFileManager", "WriteToRoot" ) )
348 $t->parse( "write_menu", "write_menu_tpl" );
349 // else
350 // $t->parse( "write_menu", "" );
351 }
352 else if ( $user &&
353 ( eZObjectPermission::hasPermission( $FolderID, "filemanager_folder", 'w' ) ||
354 eZObjectPermission::hasPermission( $FolderID, "filemanager_folder", 'u' ) ||
355 eZVirtualFolder::isOwner( eZUser::currentUser(), $FolderID ) ) )
356 {
357 $t->parse( "write_menu", "write_menu_tpl" );
358 }
359
360 if ( $deleteFolders || $deleteFiles )
361 {
362 $t->parse( "delete_menu", "delete_menu_tpl" );
363 }
364
365
366 $t->set_var( "image_dir", $ImageDir );
367 $t->set_var( "main_folder_id", $FolderID );
368
369 if ( $error == false )
370 {
371 $t->pparse( "output", "file_list_page_tpl" );
372 }
373 else
374 {
375 eZHTTPTool::header( "Location: /error/403/" );
376 exit();
377 }
378
379
380 function syncDir( $root, $category )
381 {
382 global $user;
383 $dir = eZPBFile::dir( $root, false );
384
385 while ( $entry = $dir->read() )
386
387 {
388 if ( $entry != "." && $entry != ".." )
389 {
390 if ( filetype( $root . $entry ) == "dir" )
391 {
392 // check if category exists if not create it:
393 $subCategoryArray =& $category->getByParent( $category );
394
395 $sub = false;
396 foreach ( $subCategoryArray as $subCategory )
397 {
398 if ( $subCategory->name() == $entry )
399 {
400 $sub = $subCategory;
401 }
402 print( $subCategory->name() . "\n<br>" );
403 }
404
405 if ( $sub == false )
406 {
407
408 $sub = new eZVirtualFolder();
409 $sub->setUser( $user );
410 $sub->setName( $entry );
411 $sub->setParent( $category );
412 $sub->store();
413
414 //sets permissions
415 eZObjectPermission::removePermissions( $sub->id(), "filemanager_folder", "r" );
416 eZObjectPermission::removePermissions( $sub->id(), "filemanager_folder", "w" );
417 eZObjectPermission::removePermissions( $sub->id(), "filemanager_folder", "u" );
418
419 $group = new eZUserGroup( -1 );
420 eZObjectPermission::setPermission( -1, $sub->id(), "filemanager_folder", "r" );
421
422 eZObjectPermission::setPermission( 1, $sub->id(), "filemanager_folder", "w" );
423 eZObjectPermission::setPermission( 1, $sub->id(), "filemanager_folder", "u" );
424 }
425 print( "Syncing dir " . $root . $entry . "\n<br>" );
426 syncDir( $root . $entry . "/", $sub );
427 }
428 else if ( filetype( $root . $entry ) == "file" )
429 {
430 $files = $category->files( "time", 0, -1 );
431
432 $fileExists = false;
433
434 foreach ( $files as $file )
435 {
436 if ( $entry == $file->name() )
437 {
438 $fileExists = true;
439 }
440 }
441
442 if ( $fileExists == false )
443 {
444
445
446 $uploadedFile = new eZVirtualFile();
447 $uploadedFile->setUser( $user );
448 $uploadedFile->setName( $entry );
449
450 $uploadedFile->setDescription( $entry );
451 print( "adding file: " . $root . $entry . "\n<br>" );
452 $getFile = new eZFile();
453 $getFile->getFile( $root . $entry );
454
455 $uploadedFile->store();
456 $uploadedFile->setFile( $getFile );
457
458 $folder = new eZVirtualFolder( $category->id() );
459 $folder->addFile( $uploadedFile );
460 $uploadedFile->setOriginalFileName( $entry );
461 $uploadedFile->store();
462
463 eZObjectPermission::removePermissions( $uploadedFile->id(), "filemanager_file", "r" );
464 eZObjectPermission::removePermissions( $uploadedFile->id(), "filemanager_file", "w" );
465
466 eZObjectPermission::setPermission( -1, $uploadedFile->id(), "filemanager_file", "r" );
467 eZObjectPermission::setPermission( 1, $uploadedFile->id(), "filemanager_file", "w" );
468 }
469 }
470 }
471 }
472 }
473
474 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$group
$group
Definition: admin/articleedit.php:799
$files
$files
Definition: articlepreview.php:91
eZFile
Tool class which has convencience functions for files and directories.
Definition: ezfile.php:19
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZObjectPermission\hasPermission
static hasPermission( $objectID, $moduleTable, $permission, $user=false)
Definition: ezobjectpermission.php:76
eZObjectPermission\setPermission
static setPermission( $group, $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:236
eZObjectPermission\removePermissions
static removePermissions( $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:320
eZPBFile\dir
static dir( $dir, $add_sitedir=true)
Definition: ezpbfile.php:384
eZPermission\checkPermission
static checkPermission( $user, $moduleName, $permissionName)
Definition: ezpermission.php:430
eZSection\globalSectionObject
static & globalSectionObject( $sectionID)
Definition: ezsection.php:366
eZTemplate
Definition: eztemplate.php:107
eZUserGroup
Definition: ezusergroup.php:66
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVirtualFile
Definition: ezvirtualfile.php:42
eZVirtualFile\isOwner
isOwner( $user, $file)
Definition: ezvirtualfile.php:376
eZVirtualFolder
Definition: ezvirtualfolder.php:43
eZVirtualFolder\isOwner
static isOwner( $user, $folderID)
Definition: ezvirtualfolder.php:421
$Offset
$Offset
Definition: ezarticle/user/search.php:110
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$filePath
$filePath
Definition: ezfilemanager/user/filedownload.php:50
$indexFile
$indexFile
Definition: ezfilemanager/user/filelist.php:40
$Limit
$Limit
Definition: ezfilemanager/user/filelist.php:47
$fileNumber
foreach( $fileList as $file) $fileNumber
Definition: ezfilemanager/user/filelist.php:314
$wwwDir
$wwwDir
Definition: ezfilemanager/user/filelist.php:39
$folder
if(isSet( $FileUpload)) $folder
Definition: ezfilemanager/user/filelist.php:105
$SyncDir
$SyncDir
Definition: ezfilemanager/user/filelist.php:45
$ImageDir
$ImageDir
Definition: ezfilemanager/user/filelist.php:43
$lastPath
$lastPath
Definition: ezfilemanager/user/filelist.php:163
$t
$t
Definition: ezfilemanager/user/filelist.php:50
$SectionID
$SectionID
Definition: ezfilemanager/user/filelist.php:46
$user
$user
Definition: ezfilemanager/user/filelist.php:94
$pathArray
$pathArray
Definition: ezfilemanager/user/filelist.php:160
$sectionObject
$sectionObject
Definition: ezfilemanager/user/filelist.php:112
syncDir
syncDir( $root, $category)
Definition: ezfilemanager/user/filelist.php:380
$FileCat
$FileCat
Definition: ezfilemanager/user/filelist.php:44
$i
$i
Definition: ezfilemanager/user/filelist.php:185
$Language
$Language
Definition: ezfilemanager/user/filelist.php:42
$ini
$ini
Definition: ezfilemanager/user/filelist.php:38
$GlobalSectionID
else $GlobalSectionID
Definition: ezfilemanager/user/filelist.php:110
$folderList
$folderList
Definition: ezfilemanager/user/filelist.php:183
$deleteFolders
$deleteFolders
Definition: ezfilemanager/user/filelist.php:186
$deleteFiles
$deleteFiles
Definition: ezfilemanager/user/filelist.php:242
$fileList
$fileList
Definition: ezfilemanager/user/filelist.php:229
$error
$error
Definition: ezfilemanager/user/filelist.php:115
$ShowUpFolder
$ShowUpFolder
Definition: ezfilemanager/user/filelist.php:48
$dir
$dir
Definition: ezsitemanager/admin/filelist.php:87
exit
exit
Definition: folder.php:81
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.