Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezvirtualfile.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezvirtualfile.php 9565 2002-05-23 11:42:58Z jhe $
5 //
6 // Definition of eZVirtualFile class
7 //
8 // Created on: <10-Dec-2000 15:36:36 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
38 // include_once( "classes/ezdb.php" );
39 // include_once( "classes/ezfile.php" );
40
41 class eZVirtualFile
42 {
46 function __construct( $id="" )
47 {
48 $this->UserID = 0;
49
50 if ( $id != "" )
51 {
52 $this->ID = $id;
53 $this->get( $this->ID );
54 }
55 }
56
60 function store()
61 {
62 $db =& eZDB::globalDatabase();
63 $db->begin();
64 $name = $db->escapeString( $this->Name );
65 $description = $db->escapeString( $this->Description );
66 $filename = $db->escapeString( $this->FileName );
67 $originalfilename = $db->escapeString( $this->OriginalFileName );
68
69 if ( !isset( $this->ID ) )
70 {
71 $db->lock( "eZFileManager_File" );
72 $nextID = $db->nextID( "eZFileManager_File", "ID" );
73
74 $result = $db->query( "INSERT INTO eZFileManager_File
75 ( ID, Name, Description, FileName, OriginalFileName, UserID )
76 VALUES ( '$nextID',
77 '$name',
78 '$description',
79 '$filename',
80 '$originalfilename',
81 '$this->UserID' )
82 " );
83 $db->unlock();
84 $this->ID = $nextID;
85 }
86 else
87 {
88 $result = $db->query( "UPDATE eZFileManager_File SET
89 Name='$name',
90 Description='$description',
91 FileName='$filename',
92 OriginalFileName='$originalfilename',
93 UserID='$this->UserID'
94 WHERE ID='$this->ID'
95 " );
96 }
97
98 if ( $result == false )
99 $db->rollback( );
100 else
101 $db->commit();
102 }
103
107 function delete()
108 {
109 // Delete from the database
110 $db =& eZDB::globalDatabase();
111
112 if ( isset( $this->ID ) )
113 {
114 $db->begin();
115
116 $results[] = $db->query( "DELETE FROM eZFileManager_File WHERE ID='$this->ID'" );
117 $results[] = $db->query( "DELETE FROM eZFileManager_FileFolderLink WHERE FileID='$this->ID'" );
118 $results[] = $db->query( "DELETE FROM eZFileManager_FilePermission WHERE ObjectID='$this->ID'" );
119
120 $commit = true;
121 foreach ( $results as $result )
122 {
123 if ( $result == false )
124 $commit = false;
125 }
126 if ( $commit == false )
127 $db->rollback( );
128 else
129 $db->commit();
130 }
131
132 // Delete from the filesystem
133 if ( ( file_exists( $this->filePath( true ) ) ) && $commit )
134 {
135 eZPBFile::unlink( $this->filePath( true ) );
136 }
137 }
138
142 function get( $id="" )
143 {
144 $db =& eZDB::globalDatabase();
145
146 $ret = false;
147 if ( $id != "" )
148 {
149 $db->array_query( $virtualfile_array, "SELECT * FROM eZFileManager_File WHERE ID='$id'" );
150
151 if ( count( $virtualfile_array ) > 1 )
152 {
153 die( "Error: VirtualFile's with the same ID was found in the database. This shouldent happen." );
154 }
155 else if ( count( $virtualfile_array ) == 1 )
156 {
157 $this->ID =& $virtualfile_array[0][$db->fieldName( "ID" )];
158 $this->Name =& $virtualfile_array[0][$db->fieldName( "Name" )];
159 $this->Description =& $virtualfile_array[0][$db->fieldName( "Description" )];
160 $this->FileName =& $virtualfile_array[0][$db->fieldName( "FileName" )];
161 $this->OriginalFileName =& $virtualfile_array[0][$db->fieldName( "OriginalFileName" )];
162 $this->UserID =& $virtualfile_array[0][$db->fieldName( "UserID" )];
163 $ret = true;
164 }
165 }
166 return $ret;
167 }
168
169
175 function &getAll()
176 {
177 $db =& eZDB::globalDatabase();
178
179 $return_array = array();
180 $category_array = array();
181
182 $db->array_query( $category_array, "SELECT ID, FROM eZFileManager_File ORDER BY Name" );
183
184 for ( $i = 0; $i < count( $category_array ); $i++ )
185 {
186 $return_array[$i] = new eZVirtualFile( $category_array[$i][$db->fieldName("ID")], 0 );
187 }
188
189 return $return_array;
190 }
191
197 function &search( &$queryText, $offset = 0, $limit = 30, $userID = -1 )
198 {
199 $db =& eZDB::globalDatabase();
200 $ret = false;
201 $returnArray = array();
202 if ( $userID > -1 )
203 $user = new eZUser( $userID );
204 else
205 $user =& eZUser::currentUser();
206 $groupString = "AND f.ID=p.ObjectID AND fo.ID=ffl.FolderID AND ffl.FileID=f.ID AND fp.ObjectID=fo.ID AND fp.ReadPermission='1' AND ( ( ( (p.GroupID='-1' AND fp.GroupID='-1')";
207 if ( $user )
208 {
209 foreach ( $user->groups( false ) as $group )
210 {
211 $groupString .= "OR (p.GroupID='$group' AND fp.GroupID='$group') ";
212 $groupString .= "OR (p.GroupID='-1' AND fp.GroupID='$group') ";
213 $groupString .= "OR (p.GroupID='$group' AND fp.GroupID='-1') ";
214 }
215 }
216 $groupString .= ") AND p.ReadPermission='1' ) OR ( f.UserID='$userID' ) )";
217 $query = new eZQuery( array( "f.Name", "f.Description" ), $queryText );
218 $query->setPartialCompare( true );
219 $queryString = "SELECT f.ID, f.Name as Count FROM eZFileManager_File as f";
220 if ( $user && $user->hasRootAccess() )
221 {
222 $groupString = "";
223 }
224 else
225 {
226 $queryString .= ", eZFileManager_FilePermission as p, eZFileManager_Folder as fo,
227 eZFileManager_FileFolderLink as ffl, eZFileManager_FolderPermission as fp";
228 }
229 $queryString .= " WHERE (" . $query->buildQuery() . ") $groupString ";
230 $queryString .= " GROUP BY f.ID ORDER BY f.Name";
231 $limit = array( "Limit" => $limit,
232 "Offset" => $offset );
233 $db->array_query( $fileArray, $queryString, $limit );
234 foreach ( $fileArray as $file )
235 {
236 $returnArray[] = new eZVirtualFile( $file[$db->fieldName( "ID" )] );
237 }
238 return $returnArray;
239 }
240
244 function searchCount( &$queryText, $userID = -1 )
245 {
246 $db =& eZDB::globalDatabase();
247 $ret = false;
248 $returnArray = array();
249 if ( $userID > -1 )
250 $user = new eZUser( $userID );
251 else
252 $user =& eZUser::currentUser();
253 $groupString = "AND f.ID=p.ObjectID AND fo.ID=ffl.FolderID AND ffl.FileID=f.ID AND fp.ObjectID=fo.ID AND fp.ReadPermission='1' AND ( ( ( (p.GroupID='-1' AND fp.GroupID='-1')";
254 if ( $user )
255 {
256 foreach ( $user->groups( false ) as $group )
257 {
258 $groupString .= "OR (p.GroupID='$group' AND fp.GroupID='$group') ";
259 $groupString .= "OR (p.GroupID='-1' AND fp.GroupID='$group') ";
260 $groupString .= "OR (p.GroupID='$group' AND fp.GroupID='-1') ";
261 }
262 }
263 $groupString .= ") AND p.ReadPermission='1' ) OR ( f.UserID='$userID' ) )";
264 $query = new eZQuery( array( "f.Name", "f.Description" ), $queryText );
265 $query->setPartialCompare( true );
266 $queryString = "SELECT COUNT(f.ID) as Count FROM eZFileManager_File as f";
267 if ( $user && $user->hasRootAccess() )
268 {
269 $groupString = "";
270 }
271 else
272 {
273 $queryString .= ", eZFileManager_FilePermission as p, eZFileManager_Folder as fo,
274 eZFileManager_FileFolderLink as ffl, eZFileManager_FolderPermission as fp";
275 }
276 $queryString .= " WHERE (" . $query->buildQuery() . ") $groupString ";
277 $queryString .= " GROUP BY f.ID ORDER BY f.Name";
278 $db->array_query( $fileArray, $queryString );
279
280 $ret = $fileArray[0][$db->fieldName( "Count" )];
281
282 return $ret;
283 }
284
290 static public function &getUnassigned()
291 {
292 $db =& eZDB::globalDatabase();
293
294 $db->array_query( $fileArray, "SELECT File.ID, Link.FileID
295 FROM eZFileManager_File AS File
296 LEFT JOIN eZFileManager_FileFolderLink AS Link
297 ON File.ID=Link.FileID
298 WHERE FileID IS NULL" );
299
300 foreach ( $fileArray as $file )
301 {
302 $returnArray[] = new eZVirtualFile( $file[$db->fieldName( "ID" )] );
303 }
304 return $returnArray;
305 }
306
307
311 function id()
312 {
313 return $this->ID;
314 }
315
319 function &name( $html = true )
320 {
321 $this->Name = stripslashes($this->Name);
322 if ( $html )
323 return htmlspecialchars( $this->Name );
324 else
325 return $this->Name;
326 }
327
331 function &description( $html = true )
332 {
333 $this->Description = stripslashes( $this->Description );
334 if ( $html )
335 return htmlspecialchars( $this->Description );
336 else
337 return $this->Description;
338 }
339
343 function &fileName()
344 {
345 return $this->FileName;
346 }
347
351 function &originalFileName()
352 {
353 return $this->OriginalFileName;
354 }
355
356
360 function &user( $as_object = true )
361 {
362 if ( $this->UserID != 0 )
363 {
364 $ret = $as_object ? new eZUser( $this->UserID ) : $this->UserID;
365 }
366
367 return $ret;
368 }
369
376 function isOwner( $user, $file )
377 {
378 if ( !is_a( $user, "eZUser" ) )
379 return false;
380
381 $db =& eZDB::globalDatabase();
382 $db->query_single( $res, "SELECT UserID from eZFileManager_File WHERE ID='$file'");
383 $userID = $res[$db->fieldName( "UserID" )];
384 if ( $userID == $user->id() )
385 return true;
386
387 return false;
388 }
389
390
397 function &filePath( $relative = false )
398 {
399 if ( $relative == true )
400 {
401 $path = "var/site/storage/ezfilemanager/" . $this->FileName;
402 }
403 else
404 {
405 $path = "/ezfilemanager/files/" . $this->FileName;
406 }
407
408 return $path;
409 }
410
415 function &fileSize()
416 {
417 $filepath =& $this->filePath( true );
418 $size = eZPBFile::filesize( $filepath );
419
420 return $size;
421 }
422
432 function &siFileSize()
433 {
434 $size = $this->fileSize();
435 return eZPBFile::siFileSize( $size );
436 }
437
441 function setName( $value )
442 {
443 $this->Name = $value;
444 }
445
449 function setDescription( $value )
450 {
451 $this->Description = $value;
452 }
453
457 function setOriginalFileName( $value )
458 {
459 $this->OriginalFileName = $value;
460 }
461
465 function setUser( $user )
466 {
467 if ( is_a( $user, "eZUser" ) )
468 {
469 $this->UserID = $user->id();
470 }
471 else if ( is_numeric( $user ) )
472 {
473 $this->UserID = $user;
474 }
475 }
476
481 function setFile( &$file )
482 {
483 if ( is_a( $file, "eZFile" ) )
484 {
485 $this->FileName = basename( $file->tmpName() );
486 if ( file_exists( $this->filePath( true ) ) )
487 {
488 eZPBFile::unlink( $this->filePath( true ) );
489 }
490
491 $this->OriginalFileName = $file->name();
492
493 $suffix = "";
494 if ( preg_match( "\\.([a-z]+)$", $this->OriginalFileName, $regs ) )
495 {
496 // We got a suffix, make it lowercase and store it
497 $suffix = strtolower( $regs[1] );
498 }
499
500 // the path to the catalogue
501
502 // Copy the file since we support it directly
503 $file->copy( "var/site/storage/ezfilemanager/" . basename( $file->tmpName() ) . $postfix );
504
505 $this->FileName = basename( $file->tmpName() ) . $postfix;
506
507 $name = $file->name();
508
509 $this->OriginalFileName =& $name;
510 return true;
511 }
512 return false;
513 }
514
518 function &folder( $as_object = true )
519 {
520 $db =& eZDB::globalDatabase();
521 $result = array();
522
523 $query = ( "SELECT FolderID FROM eZFileManager_FileFolderLink WHERE FileID='$this->ID'" );
524 $db->array_query( $result, $query );
525
526 foreach ( $result as $folder )
527 {
528 return $as_object ? new eZVirtualFolder( $folder[$db->fieldName( "FolderID" )] ) : $folder[$db->fieldName( "FolderID" )];
529 }
530 }
531
532
536 function removeFolders()
537 {
538 $db =& eZDB::globalDatabase();
539
540 $query = ( "DELETE FROM eZFileManager_FileFolderLink WHERE FileID='$this->ID'" );
541 $db->query( $query );
542 }
543
547 function addPageView( $pageView )
548 {
549 if ( is_a( $pageView, "eZPageView" ) )
550 {
551 $db =& eZDB::globalDatabase();
552
553 $pageViewID = $pageView->id();
554
555 $db->lock( "eZFileManager_FilePageViewLink" );
556 $nextID = $db->nextID( "eZFileManager_FilePageViewLink", "ID" );
557
558 $query = ( "INSERT INTO eZFileManager_FilePageViewLink
559 ( ID, PageViewID, FileID )
560 VALUES ( '$nextID', '$this->ID', '$pageViewID' ) " );
561
562 $result = $db->query( $query );
563 $db->unlock();
564 if ( $result == false )
565 $db->rollback( );
566 else
567 $db->commit();
568 }
569 }
570
574 function fileExists( $dir, $file )
575 {
576 $parent = eZVirtualFolder::getByName( $dir );
577 $ret = false;
578 if ( $parent )
579 {
580 $directory = new eZVirtualFolder( $parent );
581 $ret = $directory->hasFile( $file );
582 }
583 return $ret;
584 }
585
586 var $ID;
587 var $Name;
588 var $Caption;
589 var $Description;
590 var $FileName;
591 var $OriginalFileName;
592 var $UserID;
593
594 }
595
596 ?>
$i
$i
Definition: admin/adlist.php:91
$group
$group
Definition: admin/articleedit.php:799
$userID
else $userID
Definition: appointmentedit.php:121
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZPBFile\siFileSize
static & siFileSize( $size)
Definition: ezpbfile.php:220
eZPBFile\unlink
static unlink( $filename)
Definition: ezpbfile.php:352
eZPBFile\filesize
static filesize( $filename)
Definition: ezpbfile.php:339
eZQuery
Definition: ezquery.php:54
eZUser
Definition: ezuser.php:76
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVirtualFile
Definition: ezvirtualfile.php:42
eZVirtualFile\$Name
$Name
Definition: ezvirtualfile.php:587
eZVirtualFile\fileExists
fileExists( $dir, $file)
Definition: ezvirtualfile.php:574
eZVirtualFile\$Description
$Description
Definition: ezvirtualfile.php:589
eZVirtualFile\$ID
$ID
Definition: ezvirtualfile.php:586
eZVirtualFile\originalFileName
& originalFileName()
Definition: ezvirtualfile.php:351
eZVirtualFile\$OriginalFileName
$OriginalFileName
Definition: ezvirtualfile.php:591
eZVirtualFile\__construct
__construct( $id="")
Definition: ezvirtualfile.php:46
eZVirtualFile\store
store()
Definition: ezvirtualfile.php:60
eZVirtualFile\$UserID
$UserID
Definition: ezvirtualfile.php:592
eZVirtualFile\id
id()
Definition: ezvirtualfile.php:311
eZVirtualFile\fileName
& fileName()
Definition: ezvirtualfile.php:343
eZVirtualFile\fileSize
& fileSize()
Definition: ezvirtualfile.php:415
eZVirtualFile\siFileSize
& siFileSize()
Definition: ezvirtualfile.php:432
eZVirtualFile\setDescription
setDescription( $value)
Definition: ezvirtualfile.php:449
eZVirtualFile\folder
& folder( $as_object=true)
Definition: ezvirtualfile.php:518
eZVirtualFile\searchCount
searchCount(&$queryText, $userID=-1)
Definition: ezvirtualfile.php:244
eZVirtualFile\isOwner
isOwner( $user, $file)
Definition: ezvirtualfile.php:376
eZVirtualFile\setFile
setFile(&$file)
Definition: ezvirtualfile.php:481
eZVirtualFile\$FileName
$FileName
Definition: ezvirtualfile.php:590
eZVirtualFile\name
& name( $html=true)
Definition: ezvirtualfile.php:319
eZVirtualFile\setOriginalFileName
setOriginalFileName( $value)
Definition: ezvirtualfile.php:457
eZVirtualFile\search
& search(&$queryText, $offset=0, $limit=30, $userID=-1)
Definition: ezvirtualfile.php:197
eZVirtualFile\description
& description( $html=true)
Definition: ezvirtualfile.php:331
eZVirtualFile\user
& user( $as_object=true)
Definition: ezvirtualfile.php:360
eZVirtualFile\filePath
& filePath( $relative=false)
Definition: ezvirtualfile.php:397
eZVirtualFile\getAll
& getAll()
Definition: ezvirtualfile.php:175
eZVirtualFile\$Caption
$Caption
Definition: ezvirtualfile.php:588
eZVirtualFile\getUnassigned
static & getUnassigned()
Definition: ezvirtualfile.php:290
eZVirtualFile\addPageView
addPageView( $pageView)
Definition: ezvirtualfile.php:547
eZVirtualFile\setName
setName( $value)
Definition: ezvirtualfile.php:441
eZVirtualFile\setUser
setUser( $user)
Definition: ezvirtualfile.php:465
eZVirtualFile\removeFolders
removeFolders()
Definition: ezvirtualfile.php:536
eZVirtualFolder
Definition: ezvirtualfolder.php:43
eZVirtualFolder\getByName
getByName( $dir, $parent=0, $create=false, $readgroup=-1, $writegroup=-1)
Definition: ezvirtualfolder.php:107
$result
$result
Definition: companysearch.php:94
$results
$results
Definition: companysearch.php:81
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$pageView
$pageView
Definition: entryexitpages.php:87
$db
$db
Definition: ezarticle/user/authorlist.php:53
$folder
if(!isset( $FolderID)) $folder
Definition: ezfilemanager/admin/browse.php:74
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$suffix
$suffix
Definition: ezfilemanager/user/filedownload.php:168
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$dir
$dir
Definition: ezsitemanager/admin/filelist.php:87
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$category_array
$category_array
Definition: todoedit.php:604
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.