2001-05-25 05:34:24 +02:00
< ? php
/************************************************************************** \
* phpGroupWare API - VFS *
2002-01-16 07:36:51 +01:00
* This file written by Jason Wies ( Zone ) < zone @ phpgroupware . org > *
2001-05-25 05:34:24 +02:00
* This class handles file / dir access for phpGroupWare *
2001-06-27 09:20:12 +02:00
* Copyright ( C ) 2001 Jason Wies *
2001-05-25 05:34:24 +02:00
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
* http :// www . phpgroupware . org / api *
* ------------------------------------------------------------------------ *
* This library is free software ; you can redistribute it and / or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation ; either version 2.1 of the License , *
* or any later version . *
* This library is distributed in the hope that it will be useful , but *
* WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . *
* See the GNU Lesser General Public License for more details . *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library ; if not , write to the Free Software Foundation , *
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA *
\ **************************************************************************/
/* $Id$ */
2001-08-05 09:53:59 +02:00
/*!
@ class vfs
@ abstract Virtual File System
@ description Authors : Zone
*/
2001-05-25 05:34:24 +02:00
/* Relative defines. Used mainly by getabsolutepath () */
2001-08-10 02:03:02 +02:00
define ( 'RELATIVE_ROOT' , 1 );
define ( 'RELATIVE_USER' , 2 );
define ( 'RELATIVE_CURR_USER' , 4 );
define ( 'RELATIVE_USER_APP' , 8 );
define ( 'RELATIVE_PATH' , 16 );
define ( 'RELATIVE_NONE' , 32 );
define ( 'RELATIVE_CURRENT' , 64 );
define ( 'VFS_REAL' , 1024 );
define ( 'RELATIVE_ALL' , RELATIVE_PATH );
2001-05-25 05:34:24 +02:00
2001-07-10 23:35:23 +02:00
/* These are used in calls to extra_sql () */
2001-08-10 02:03:02 +02:00
define ( 'VFS_SQL_SELECT' , 1 );
define ( 'VFS_SQL_DELETE' , 2 );
2001-08-11 11:01:47 +02:00
define ( 'VFS_SQL_UPDATE' , 4 );
2001-07-11 07:57:04 +02:00
/* These are used in calls to add_journal (), and allow journal messages to be more standard */
2001-08-10 02:03:02 +02:00
define ( 'VFS_OPERATION_CREATED' , 1 );
define ( 'VFS_OPERATION_EDITED' , 2 );
define ( 'VFS_OPERATION_EDITED_COMMENT' , 4 );
define ( 'VFS_OPERATION_COPIED' , 8 );
define ( 'VFS_OPERATION_MOVED' , 16 );
define ( 'VFS_OPERATION_DELETED' , 32 );
2001-07-10 23:35:23 +02:00
2001-05-25 05:34:24 +02:00
/*!
@ class path_class
@ abstract helper class for path_parts
*/
class path_class
{
2001-06-18 23:18:22 +02:00
var $mask ;
var $outside ;
2001-05-25 05:34:24 +02:00
var $fake_full_path ;
var $fake_leading_dirs ;
var $fake_extra_path ;
var $fake_name ;
var $real_full_path ;
var $real_leading_dirs ;
var $real_extra_path ;
var $real_name ;
2001-06-17 09:00:34 +02:00
var $fake_full_path_clean ;
var $fake_leading_dirs_clean ;
var $fake_extra_path_clean ;
var $fake_name_clean ;
var $real_full_path_clean ;
var $real_leading_dirs_clean ;
var $real_extra_path_clean ;
var $real_name_clean ;
2001-05-25 05:34:24 +02:00
}
2001-08-11 11:01:47 +02:00
class vfs
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
var $basedir ;
var $fakebase ;
var $relative ;
var $working_id ;
var $working_lid ;
var $attributes ;
var $override_acl ;
var $linked_dirs ;
var $meta_types ;
2001-12-10 05:04:56 +01:00
var $now ;
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function vfs
@ abstract constructor , sets up variables
2001-07-10 23:35:23 +02:00
*/
2001-08-11 11:01:47 +02:00
function vfs ()
2001-05-25 05:34:24 +02:00
{
2001-09-28 22:41:36 +02:00
$this -> basedir = $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'files_dir' ];
2001-08-11 11:01:47 +02:00
$this -> fakebase = " /home " ;
2001-09-28 22:41:36 +02:00
$this -> working_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
$this -> working_lid = $GLOBALS [ 'phpgw' ] -> accounts -> id2name ( $this -> working_id );
$this -> now = date ( 'Y-m-d' );
2001-12-15 05:24:37 +01:00
$this -> override_acl = 0 ;
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
File / dir attributes , each corresponding to a database field . Useful for use in loops
If an attribute was added to the table , add it here and possibly add it to
set_attributes ()
2001-12-10 05:04:56 +01:00
set_attributes now uses this array () . 07 - Dec - 01 skeeter
2001-08-11 11:01:47 +02:00
*/
2001-09-28 22:41:36 +02:00
$this -> attributes = array (
2001-12-15 05:24:37 +01:00
'file_id' ,
'owner_id' ,
'createdby_id' ,
'modifiedby_id' ,
'created' ,
'modified' ,
'size' ,
'mime_type' ,
'deleteable' ,
'comment' ,
'app' ,
'directory' ,
'name' ,
'link_directory' ,
'link_name' ,
'version'
2001-09-28 22:41:36 +02:00
);
2001-08-11 11:01:47 +02:00
/*
These are stored in the MIME - type field and should normally be ignored .
Adding a type here will ensure it is normally ignored , but you will have to
explicitly add it to acl_check (), and to any other SELECT ' s in this file
*/
2001-09-28 22:41:36 +02:00
$this -> meta_types = array ( 'journal' , 'journal-deleted' );
2001-08-11 11:01:47 +02:00
/* We store the linked directories in an array now, so we don't have to make the SQL call again */
2002-04-08 16:23:27 +02:00
if ( $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'db_type' ] == 'mssql'
|| $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'db_type' ] == 'sybase' )
{
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " SELECT directory, name, link_directory, link_name FROM phpgw_vfs WHERE CONVERT(varchar,link_directory) != '' AND CONVERT(varchar,link_name) != '' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
}
else
{
2002-06-09 02:17:59 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " SELECT directory, name, link_directory, link_name FROM phpgw_vfs WHERE (link_directory IS NOT NULL or link_directory != '') AND (lilnk_name IS NOT NULL or link_name != '') " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2002-04-08 16:23:27 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$this -> linked_dirs = array ();
2001-09-28 22:41:36 +02:00
while ( $GLOBALS [ 'phpgw' ] -> db -> next_record ())
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$this -> linked_dirs [] = $GLOBALS [ 'phpgw' ] -> db -> Record ;
2001-08-11 11:01:47 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function set_relative
@ abstract Set path relativity
2002-01-16 07:36:51 +01:00
@ param mask Relative bitmask ( see RELATIVE_ defines )
2001-08-11 11:01:47 +02:00
*/
2002-01-16 07:36:51 +01:00
function set_relative ( $data )
2001-07-11 07:57:04 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
{
$data = array ();
}
if ( ! $data [ 'mask' ])
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
unset ( $this -> relative );
}
else
{
2002-01-16 07:36:51 +01:00
$this -> relative = $data [ 'mask' ];
2001-07-11 07:57:04 +02:00
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function get_relative
@ abstract Return relativity bitmask
@ discussion Returns relativity bitmask , or the default of " completely relative " if unset
*/
function get_relative ()
2001-07-10 23:35:23 +02:00
{
2002-02-10 05:19:43 +01:00
if ( isset ( $this -> relative ) && $this -> relative )
2001-08-11 11:01:47 +02:00
{
return $this -> relative ;
}
else
{
return RELATIVE_ALL ;
}
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
2001-09-28 22:41:36 +02:00
@ function sanitize
2002-01-16 07:36:51 +01:00
@ abstract Removes leading . 's from ' string '
2001-08-11 11:01:47 +02:00
@ discussion You should not pass all filenames through sanitize () unless you plan on rejecting
. files . Instead , pass the name through securitycheck () first , and if it fails ,
pass it through sanitize
2002-01-16 07:36:51 +01:00
@ param string string to sanitize
@ result $string 'string' without it 's leading .' s
2001-09-28 22:41:36 +02:00
*/
2002-01-16 07:36:51 +01:00
function sanitize ( $data )
2001-07-11 07:57:04 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
{
$data = array ();
}
2001-08-11 11:01:47 +02:00
/* We use path_parts () just to parse the string, not translate paths */
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( RELATIVE_NONE )
)
);
2001-09-28 22:41:36 +02:00
return ( ereg_replace ( " ^ \ .+ " , '' , $p -> fake_name ));
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function securitycheck
@ abstract Security check function
@ discussion Checks for basic violations such as ..
If securitycheck () fails , run your string through vfs -> sanitize ()
2002-01-16 07:36:51 +01:00
@ param string string to check security of
2001-08-11 11:01:47 +02:00
@ result Boolean True / False . True means secure , False means insecure
*/
2002-01-16 07:36:51 +01:00
function securitycheck ( $data )
2001-07-11 07:57:04 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
{
$data = array ();
}
if ( substr ( $data [ 'string' ], 0 , 1 ) == " \\ " || strstr ( $data [ 'string' ], " .. " ) || strstr ( $data [ 'string' ], " \\ .. " ) || strstr ( $data [ 'string' ], " . \\ . " ))
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-11 07:57:04 +02:00
}
2001-08-11 11:01:47 +02:00
else
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
return True ;
2001-07-11 07:57:04 +02:00
}
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function db_clean
2002-01-16 07:36:51 +01:00
@ abstract Clean 'string' for use in database queries
@ param string String to clean
@ result Cleaned version of 'string'
2001-08-11 11:01:47 +02:00
*/
2002-01-16 07:36:51 +01:00
function db_clean ( $data )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
{
$data = array ();
}
$string = ereg_replace ( " ' " , " \ ' " , $data [ 'string' ]);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return $string ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function extra_sql
@ abstract Return extra SQL code that should be appended to certain queries
2002-01-16 07:36:51 +01:00
@ param query_type The type of query to get extra SQL code for , in the form of a VFS_SQL define
2001-08-11 11:01:47 +02:00
@ result Extra SQL code
*/
2002-01-16 07:36:51 +01:00
function extra_sql ( $data )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
{
$data = array ( 'query_type' => VFS_SQL_SELECT );
}
if ( $data [ 'query_type' ] == VFS_SQL_SELECT || $data [ 'query_type' ] == VFS_SQL_DELETE || $data [ 'query_type' ] = VFS_SQL_UPDATE )
2001-07-13 07:12:18 +02:00
{
2001-09-28 22:41:36 +02:00
$sql = ' AND ((' ;
2001-08-11 11:01:47 +02:00
reset ( $this -> meta_types );
while ( list ( $num , $type ) = each ( $this -> meta_types ))
{
if ( $num )
2001-09-28 22:41:36 +02:00
$sql .= ' AND ' ;
2001-08-11 11:01:47 +02:00
$sql .= " mime_type != ' $type ' " ;
}
2001-09-28 22:41:36 +02:00
$sql .= ') OR mime_type IS NULL)' ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return ( $sql );
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function add_journal
@ abstract Add a journal entry after ( or before ) completing an operation ,
and increment the version number . This function should be used internally only
2002-01-16 07:36:51 +01:00
@ discussion Note that state_one and state_two are ignored for some VFS_OPERATION ' s , for others
2001-08-11 11:01:47 +02:00
they are required . They are ignored for any " custom " operation
2002-01-16 07:36:51 +01:00
The two operations that require state_two :
operation state_two
2001-08-11 11:01:47 +02:00
VFS_OPERATION_COPIED fake_full_path of copied to
VFS_OPERATION_MOVED fake_full_path of moved to
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
If deleting , you must call add_journal () before you delete the entry from the database
2002-01-16 07:36:51 +01:00
@ param string File or directory to add entry for
@ param relatives Relativity array
@ param operation The operation that was performed . Either a VFS_OPERATION define or
2001-08-11 11:01:47 +02:00
a non - integer descriptive text string
2002-01-16 07:36:51 +01:00
@ param state_one The first " state " of the file or directory . Can be a file name , size ,
2001-08-11 11:01:47 +02:00
location , whatever is appropriate for the specific operation
2002-01-16 07:36:51 +01:00
@ param state_two The second " state " of the file or directory
@ param incversion Boolean True / False . Increment the version for the file ? Note that this is
2001-08-11 11:01:47 +02:00
handled automatically for the VFS_OPERATION defines .
i . e . VFS_OPERATION_EDITED would increment the version , VFS_OPERATION_COPIED
would not
@ result Boolean True / False
*/
2002-01-16 07:36:51 +01:00
function add_journal ( $data )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'state_one' => False ,
'state_two' => False ,
'incversion' => True
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array ( 'string' => $data [ 'string' ], 'relatives' => array ( $data [ 'relatives' ][ 0 ])));
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* We check that they have some sort of access to the file other than read */
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array ( 'string' => $p -> fake_full_path , 'relatives' => array ( $p -> mask ), 'operation' => PHPGW_ACL_WRITE )) &&
! $this -> acl_check ( array ( 'string' => $p -> fake_full_path , 'relatives' => array ( $p -> mask ), 'operation' => PHPGW_ACL_EDIT )) &&
! $this -> acl_check ( array ( 'string' => $p -> fake_full_path , 'relatives' => array ( $p -> mask ), 'operation' => PHPGW_ACL_DELETE )))
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array ( 'string' => $p -> fake_full_path , 'relatives' => array ( $p -> mask ))))
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => False ,
'mime_type' => False ,
'nofiles' => True
)
);
2001-08-11 11:01:47 +02:00
$file_array = $ls_array [ 0 ];
2001-09-28 22:41:36 +02:00
$sql = 'INSERT INTO phpgw_vfs (' ;
$sql2 .= ' VALUES (' ;
2001-08-11 11:01:47 +02:00
for ( $i = 0 ; list ( $attribute , $value ) = each ( $file_array ); $i ++ )
2001-07-11 07:57:04 +02:00
{
2001-09-28 22:41:36 +02:00
if ( $attribute == 'file_id' )
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
continue ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
if ( $attribute == 'owner_id' )
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
$value = $account_id ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
if ( $attribute == 'created' )
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
$value = $this -> now ;
2001-07-11 07:57:04 +02:00
}
2001-08-24 09:44:43 +02:00
2001-09-28 22:41:36 +02:00
if ( $attribute == 'modified' && ! $modified )
2001-08-24 09:44:43 +02:00
{
unset ( $value );
}
2001-09-28 22:41:36 +02:00
if ( $attribute == 'mime_type' )
2001-07-11 07:57:04 +02:00
{
2001-09-28 22:41:36 +02:00
$value = 'journal' ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
if ( $attribute == 'comment' )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
switch ( $data [ 'operation' ])
2001-08-11 11:01:47 +02:00
{
case VFS_OPERATION_CREATED :
2001-09-28 22:41:36 +02:00
$value = 'Created' ;
2002-01-16 07:36:51 +01:00
$data [ 'incversion' ] = True ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_EDITED :
2001-09-28 22:41:36 +02:00
$value = 'Edited' ;
2002-01-16 07:36:51 +01:00
$data [ 'incversion' ] = True ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_EDITED_COMMENT :
2001-09-28 22:41:36 +02:00
$value = 'Edited comment' ;
2002-01-16 07:36:51 +01:00
$data [ 'incversion' ] = False ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_COPIED :
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'state_one' ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$data [ 'state_one' ] = $p -> fake_full_path ;
2001-08-11 11:01:47 +02:00
}
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'state_two' ])
2001-08-11 11:01:47 +02:00
{
return False ;
}
2002-01-16 07:36:51 +01:00
$value = 'Copied ' . $data [ 'state_one' ] . ' to ' . $data [ 'state_two' ];
$data [ 'incversion' ] = False ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_MOVED :
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'state_one' ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$data [ 'state_one' ] = $p -> fake_full_path ;
2001-08-11 11:01:47 +02:00
}
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'state_two' ])
2001-08-11 11:01:47 +02:00
{
return False ;
}
2002-01-16 07:36:51 +01:00
$value = 'Moved ' . $data [ 'state_one' ] . ' to ' . $data [ 'state_two' ];
$data [ 'incversion' ] = False ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_DELETED :
2001-09-28 22:41:36 +02:00
$value = 'Deleted' ;
2002-01-16 07:36:51 +01:00
$data [ 'incversion' ] = False ;
2001-08-11 11:01:47 +02:00
break ;
default :
2002-01-16 07:36:51 +01:00
$value = $data [ 'operation' ];
2001-08-11 11:01:47 +02:00
break ;
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
Let ' s increment the version for the file itself . We keep the current
version when making the journal entry , because that was the version that
was operated on . The maximum numbers for each part in the version string :
none . 99.9 . 9
*/
2002-01-16 07:36:51 +01:00
if ( $attribute == 'version' && $data [ 'incversion' ])
2001-08-11 11:01:47 +02:00
{
$version_parts = split ( " \ . " , $value );
$newnumofparts = $numofparts = count ( $version_parts );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $version_parts [ 3 ] >= 9 )
{
$version_parts [ 3 ] = 0 ;
$version_parts [ 2 ] ++ ;
$version_parts_3_update = 1 ;
}
elseif ( isset ( $version_parts [ 3 ]))
{
$version_parts [ 3 ] ++ ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $version_parts [ 2 ] >= 9 && $version_parts [ 3 ] == 0 && $version_parts_3_update )
{
$version_parts [ 2 ] = 0 ;
$version_parts [ 1 ] ++ ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $version_parts [ 1 ] > 99 )
{
$version_parts [ 1 ] = 0 ;
$version_parts [ 0 ] ++ ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
for ( $i = 0 ; $i < $newnumofparts ; $i ++ )
{
if ( ! isset ( $version_parts [ $i ]))
{
break ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $i )
{
2001-09-28 22:41:36 +02:00
$newversion .= '.' ;
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$newversion .= $version_parts [ $i ];
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'attributes' => array (
'version' => $newversion
)
)
);
2001-08-11 11:01:47 +02:00
}
2001-08-24 09:44:43 +02:00
if ( isset ( $value ))
{
if ( $i > 1 )
{
2001-09-28 22:41:36 +02:00
$sql .= ', ' ;
$sql2 .= ', ' ;
2001-08-24 09:44:43 +02:00
}
$sql .= " $attribute " ;
2002-01-16 07:36:51 +01:00
$sql2 .= " ' " . $this -> db_clean ( array ( 'string' => $value )) . " ' " ;
2001-08-24 09:44:43 +02:00
}
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
$sql .= ')' ;
$sql2 .= ')' ;
2001-08-11 11:01:47 +02:00
$sql .= $sql2 ;
2001-09-28 22:41:36 +02:00
2001-07-12 01:48:25 +02:00
/*
2001-08-11 11:01:47 +02:00
These are some special situations where we need to flush the journal entries
or move the 'journal' entries to 'journal-deleted' . Kind of hackish , but they
provide a consistent feel to the system
2001-07-12 01:48:25 +02:00
*/
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_CREATED )
2001-08-11 11:01:47 +02:00
{
$flush_path = $p -> fake_full_path ;
$deleteall = True ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_COPIED || $data [ 'operation' ] == VFS_OPERATION_MOVED )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$flush_path = $data [ 'state_two' ];
2001-08-11 11:01:47 +02:00
$deleteall = False ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $flush_path )
{
2002-01-16 07:36:51 +01:00
$flush_path_parts = $this -> path_parts ( array (
'string' => $flush_path ,
'relatives' => array ( RELATIVE_NONE )
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> flush_journal ( array (
'string' => $flush_path_parts -> fake_full_path ,
'relatives' => array ( $flush_path_parts -> mask ),
'deleteall' => $deleteall
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_COPIED )
2001-08-11 11:01:47 +02:00
{
/*
We copy it going the other way as well , so both files show the operation .
The code is a bad hack to prevent recursion . Ideally it would use VFS_OPERATION_COPIED
*/
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $data [ 'state_two' ],
'relatives' => array ( RELATIVE_NONE ),
'operation' => 'Copied ' . $data [ 'state_one' ] . ' to ' . $data [ 'state_two' ],
'state_one' => NULL ,
'state_two' => NULL ,
'incversion' => False
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_MOVED )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$state_one_path_parts = $this -> path_parts ( array (
'string' => $data [ 'state_one' ],
'relatives' => array ( RELATIVE_NONE )
)
);
2001-09-28 22:41:36 +02:00
2001-12-10 05:04:56 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET mime_type='journal-deleted' WHERE directory=' " . $state_one_path_parts -> fake_leading_dirs_clean . " ' AND name=' " . $state_one_path_parts -> fake_name_clean . " ' AND mime_type='journal' " );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
We create the file in addition to logging the MOVED operation . This is an
advantage because we can now search for 'Create' to see when a file was created
*/
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $data [ 'state_two' ],
'relatives' => array ( RELATIVE_NONE ),
'operation' => VFS_OPERATION_CREATED
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* This is the SQL query we made for THIS request, remember that one? */
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
2001-07-12 01:48:25 +02:00
/*
2001-08-11 11:01:47 +02:00
If we were to add an option of whether to keep journal entries for deleted files
or not , it would go in the if here
2001-07-12 01:48:25 +02:00
*/
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_DELETED )
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET mime_type='journal-deleted' WHERE directory=' $p->fake_leading_dirs_clean ' AND name=' $p->fake_name_clean ' AND mime_type='journal' " );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
2001-07-12 01:48:25 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function flush_journal
@ abstract Flush journal entries for $string . Used before adding $string
@ discussion flush_journal () is an internal function and should be called from add_journal () only
2002-01-16 07:36:51 +01:00
@ param string File / directory to flush journal entries of
@ param relatives Realtivity array
@ param deleteall Delete all types of journal entries , including the active Create entry .
2001-08-11 11:01:47 +02:00
Normally you only want to delete the Create entry when replacing the file
Note that this option does not effect $deleteonly
2002-01-16 07:36:51 +01:00
@ param deletedonly Only flush 'journal-deleted' entries ( created when $string was deleted )
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
2001-07-31 08:37:55 +02:00
*/
2002-01-16 07:36:51 +01:00
function flush_journal ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'deleteall' => False ,
'deletedonly' => False
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-12-10 05:04:56 +01:00
$sql = " DELETE FROM phpgw_vfs WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " ;
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'deleteall' ])
2001-08-11 11:01:47 +02:00
{
$sql .= " AND (mime_type != 'journal' AND comment != 'Created') " ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$sql .= " AND (mime_type='journal-deleted' " ;
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'deletedonly' ])
2001-08-11 11:01:47 +02:00
{
$sql .= " OR mime_type='journal' " ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$sql .= " ) " ;
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
2001-08-11 11:01:47 +02:00
if ( $query )
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
return True ;
2001-05-25 05:34:24 +02:00
}
else
{
2001-08-11 11:01:47 +02:00
return False ;
2001-05-25 05:34:24 +02:00
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function get_journal
@ abstract Retrieve journal entries for $string
2002-01-16 07:36:51 +01:00
@ param string File / directory to retrieve journal entries of
@ param relatives Relativity array
@ param type 0 / False = any , 1 = 'journal' , 2 = 'journal-deleted'
2001-08-11 11:01:47 +02:00
@ result Array of arrays of journal entries
*/
2002-01-16 07:36:51 +01:00
function get_journal ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'type' => False
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
)))
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2001-12-10 05:04:56 +01:00
$sql = " SELECT * FROM phpgw_vfs WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " ;
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'type' ] == 1 )
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
$sql .= " AND mime_type='journal' " ;
2001-05-25 05:34:24 +02:00
}
2002-01-16 07:36:51 +01:00
elseif ( $data [ 'type' ] == 2 )
2001-07-02 21:00:31 +02:00
{
2001-08-11 11:01:47 +02:00
$sql .= " AND mime_type='journal-deleted' " ;
2001-07-02 21:00:31 +02:00
}
2001-05-25 05:34:24 +02:00
else
{
2001-08-11 11:01:47 +02:00
$sql .= " AND (mime_type='journal' OR mime_type='journal-deleted') " ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
while ( $GLOBALS [ 'phpgw' ] -> db -> next_record ())
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$rarray [] = $GLOBALS [ 'phpgw' ] -> db -> Record ;
}
2001-08-11 11:01:47 +02:00
return $rarray ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function path_parts
@ abstract take a real or fake pathname and return an array of its component parts
2002-01-16 07:36:51 +01:00
@ param string full real or fake path
@ param relatives Relativity array
@ param object True returns an object instead of an array
@ param nolinks Don ' t check for links ( made with make_link ()) . Used internally to prevent recursion
2001-08-11 11:01:47 +02:00
@ result $rarray / $robject Array or object containing the fake and real component parts of the path
@ discussion Returned values are :
mask
outside
fake_full_path
fake_leading_dirs
fake_extra_path BROKEN
fake_name
real_full_path
real_leading_dirs
real_extra_path BROKEN
real_name
fake_full_path_clean
fake_leading_dirs_clean
fake_extra_path_clean BROKEN
fake_name_clean
real_full_path_clean
real_leading_dirs_clean
real_extra_path_clean BROKEN
real_name_clean
" clean " values are run through vfs -> db_clean () and
are safe for use in SQL queries that use key = 'value'
They should be used ONLY for SQL queries , so are used
mostly internally
mask is either RELATIVE_NONE or RELATIVE_NONE | VFS_REAL ,
and is used internally
2002-01-16 07:36:51 +01:00
outside is boolean , True if 'relatives' contains VFS_REAL
2001-08-11 11:01:47 +02:00
*/
2002-01-16 07:36:51 +01:00
function path_parts ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'object' => True ,
'nolinks' => False
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-08-11 11:01:47 +02:00
$sep = SEP ;
2001-09-28 22:41:36 +02:00
$rarray [ 'mask' ] = RELATIVE_NONE ;
2002-01-16 07:36:51 +01:00
if ( ! ( $data [ 'relatives' ][ 0 ] & VFS_REAL ))
2001-05-25 05:34:24 +02:00
{
2001-09-28 22:41:36 +02:00
$rarray [ 'outside' ] = False ;
2001-08-11 11:01:47 +02:00
$fake = True ;
2001-05-25 05:34:24 +02:00
}
else
{
2001-09-28 22:41:36 +02:00
$rarray [ 'outside' ] = True ;
$rarray [ 'mask' ] |= VFS_REAL ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$string = $this -> getabsolutepath ( array (
'string' => $data [ 'string' ],
'mask' => array ( $data [ 'relatives' ][ 0 ]),
'fake' => $fake
)
);
2001-12-15 05:24:37 +01:00
2001-08-11 11:01:47 +02:00
if ( $fake )
{
2001-09-28 22:41:36 +02:00
$base_sep = '/' ;
$base = '/' ;
2002-01-16 07:36:51 +01:00
$opp_base = $this -> basedir . $sep ;
2001-09-28 22:41:36 +02:00
$rarray [ 'fake_full_path' ] = $string ;
2001-08-11 11:01:47 +02:00
}
else
2001-07-09 07:09:27 +02:00
{
2002-01-16 07:36:51 +01:00
$base_sep = $sep ;
if ( ereg ( " ^ $this->basedir " . $sep , $string ))
2001-07-09 07:09:27 +02:00
{
2002-01-16 07:36:51 +01:00
$base = $this -> basedir . $sep ;
2001-08-11 11:01:47 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
$base = $sep ;
2001-07-09 07:09:27 +02:00
}
2001-09-28 22:41:36 +02:00
$opp_base = '/' ;
$rarray [ 'real_full_path' ] = $string ;
2001-07-09 07:09:27 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* This is needed because of substr's handling of negative lengths */
$baselen = strlen ( $base );
$lastslashpos = strrpos ( $string , $base_sep );
$lastslashpos < $baselen ? $length = 0 : $length = $lastslashpos - $baselen ;
2001-09-28 22:41:36 +02:00
$extra_path = $rarray [ 'fake_extra_path' ] = $rarray [ 'real_extra_path' ] = substr ( $string , strlen ( $base ), $length );
$name = $rarray [ 'fake_name' ] = $rarray [ 'real_name' ] = substr ( $string , strrpos ( $string , $base_sep ) + 1 );
2001-08-11 11:01:47 +02:00
if ( $fake )
{
2002-01-16 07:36:51 +01:00
$rarray [ 'real_extra_path' ] ? $dispsep = $sep : $dispsep = '' ;
2001-09-28 22:41:36 +02:00
$rarray [ 'real_full_path' ] = $opp_base . $rarray [ 'real_extra_path' ] . $dispsep . $rarray [ 'real_name' ];
2001-08-11 11:01:47 +02:00
if ( $extra_path )
{
2001-09-28 22:41:36 +02:00
$rarray [ 'fake_leading_dirs' ] = $base . $extra_path ;
$rarray [ 'real_leading_dirs' ] = $opp_base . $extra_path ;
2001-08-11 11:01:47 +02:00
}
2002-01-16 07:36:51 +01:00
elseif ( strrpos ( $rarray [ 'fake_full_path' ], $sep ) == 0 )
2001-08-11 11:01:47 +02:00
{
/* If there is only one $sep in the path, we don't want to strip it off */
2002-01-16 07:36:51 +01:00
$rarray [ 'fake_leading_dirs' ] = $sep ;
2001-09-28 22:41:36 +02:00
$rarray [ 'real_leading_dirs' ] = substr ( $opp_base , 0 , strlen ( $opp_base ) - 1 );
2001-08-11 11:01:47 +02:00
}
else
{
/* These strip the ending / */
2001-09-28 22:41:36 +02:00
$rarray [ 'fake_leading_dirs' ] = substr ( $base , 0 , strlen ( $base ) - 1 );
$rarray [ 'real_leading_dirs' ] = substr ( $opp_base , 0 , strlen ( $opp_base ) - 1 );
2001-08-11 11:01:47 +02:00
}
}
else
{
2001-09-28 22:41:36 +02:00
$rarray [ 'fake_full_path' ] = $opp_base . $rarray [ 'fake_extra_path' ] . '/' . $rarray [ 'fake_name' ];
2001-08-11 11:01:47 +02:00
if ( $extra_path )
{
2001-09-28 22:41:36 +02:00
$rarray [ 'fake_leading_dirs' ] = $opp_base . $extra_path ;
$rarray [ 'real_leading_dirs' ] = $base . $extra_path ;
2001-08-11 11:01:47 +02:00
}
else
{
2001-09-28 22:41:36 +02:00
$rarray [ 'fake_leading_dirs' ] = substr ( $opp_base , 0 , strlen ( $opp_base ) - 1 );
$rarray [ 'real_leading_dirs' ] = substr ( $base , 0 , strlen ( $base ) - 1 );
2001-08-11 11:01:47 +02:00
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* We check for linked dirs made with make_link (). This could be better, but it works */
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'nolinks' ])
2001-08-11 11:01:47 +02:00
{
reset ( $this -> linked_dirs );
while ( list ( $num , $link_info ) = each ( $this -> linked_dirs ))
{
2001-09-28 22:41:36 +02:00
if ( ereg ( " ^ $link_info[directory] / $link_info[name] (/| $ ) " , $rarray [ 'fake_full_path' ]))
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$rarray [ 'real_full_path' ] = ereg_replace ( " ^ $this->basedir " , '' , $rarray [ 'real_full_path' ]);
$rarray [ 'real_full_path' ] = ereg_replace ( " ^ $link_info[directory] " . SEP . " $link_info[name] " , $link_info [ 'link_directory' ] . SEP . $link_info [ 'link_name' ], $rarray [ 'real_full_path' ]);
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $rarray [ 'real_full_path' ],
'relatives' => array ( RELATIVE_NONE | VFS_REAL ),
'nolinks' => True
)
);
2001-09-28 22:41:36 +02:00
$rarray [ 'real_leading_dirs' ] = $p -> real_leading_dirs ;
$rarray [ 'real_extra_path' ] = $p -> real_extra_path ;
$rarray [ 'real_name' ] = $p -> real_name ;
2001-08-11 11:01:47 +02:00
}
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
We have to count it before because new keys will be added ,
which would create an endless loop
*/
$count = count ( $rarray );
2001-06-16 05:54:10 +02:00
reset ( $rarray );
2001-08-11 11:01:47 +02:00
for ( $i = 0 ; ( list ( $key , $value ) = each ( $rarray )) && $i != $count ; $i ++ )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
$rarray [ $key . '_clean' ] = $this -> db_clean ( array ( 'string' => $value ));
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'object' ])
2001-08-11 11:01:47 +02:00
{
$robject = new path_class ;
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
reset ( $rarray );
while ( list ( $key , $value ) = each ( $rarray ))
{
$robject -> $key = $value ;
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
echo " <br>fake_full_path: $rarray[fake_full_path]
< br > fake_leading_dirs : $rarray [ fake_leading_dirs ]
< br > fake_extra_path : $rarray [ fake_extra_path ]
< br > fake_name : $rarray [ fake_name ]
< br > real_full_path : $rarray [ real_full_path ]
< br > real_leading_dirs : $rarray [ real_leading_dirs ]
< br > real_extra_path : $rarray [ real_extra_path ]
< br > real_name : $rarray [ real_name ] " ;
*/
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'object' ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
return ( $robject );
2001-08-11 11:01:47 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
return ( $rarray );
2001-05-25 05:34:24 +02:00
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function getabsolutepath
@ abstract get the absolute path
2002-01-16 07:36:51 +01:00
@ param string defaults to False , directory / file to get path of , relative to relatives [ 0 ]
@ param mask Relativity bitmask ( see RELATIVE_ defines ) . RELATIVE_CURRENT means use $this -> relative
@ param fake Returns the " fake " path , ie / home / user / dir / file ( not always possible . use path_parts () instead )
2001-08-11 11:01:47 +02:00
@ result $basedir Full fake or real path
2001-09-28 22:41:36 +02:00
*/
2002-01-16 07:36:51 +01:00
function getabsolutepath ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'string' => False ,
'mask' => array ( RELATIVE_CURRENT ),
'fake' => True
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$currentdir = $this -> pwd ( False );
2001-08-11 11:01:47 +02:00
/* If they supply just VFS_REAL, we assume they want current relativity */
2002-01-16 07:36:51 +01:00
if ( $data [ 'mask' ][ 0 ] == VFS_REAL )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$data [ 'mask' ][ 0 ] |= RELATIVE_CURRENT ;
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> securitycheck ( array (
'string' => $data [ 'string' ]
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'mask' ][ 0 ] & RELATIVE_NONE )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
return $data [ 'string' ];
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'fake' ])
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$sep = '/' ;
2001-08-11 11:01:47 +02:00
}
else
{
$sep = SEP ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* if RELATIVE_CURRENT, retrieve the current mask */
2002-01-16 07:36:51 +01:00
if ( $data [ 'mask' ][ 0 ] & RELATIVE_CURRENT )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$mask = $data [ 'mask' ][ 0 ];
2001-08-11 11:01:47 +02:00
/* Respect any additional masks by re-adding them after retrieving the current mask*/
2002-01-16 07:36:51 +01:00
$data [ 'mask' ][ 0 ] = $this -> get_relative () + ( $mask - RELATIVE_CURRENT );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'fake' ])
2001-08-11 11:01:47 +02:00
{
$basedir = " / " ;
}
else
{
$basedir = $this -> basedir . $sep ;
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* This allows all requests to use /'s */
2002-01-16 07:36:51 +01:00
$data [ 'string' ] = preg_replace ( " |/| " , $sep , $data [ 'string' ]);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if (( $data [ 'mask' ][ 0 ] & RELATIVE_PATH ) && $currentdir )
2001-08-11 11:01:47 +02:00
{
$basedir = $basedir . $currentdir . $sep ;
}
2002-01-16 07:36:51 +01:00
elseif (( $data [ 'mask' ][ 0 ] & RELATIVE_USER ) || ( $data [ 'mask' ][ 0 ] & RELATIVE_USER_APP ))
2001-08-11 11:01:47 +02:00
{
$basedir = $basedir . $this -> fakebase . $sep ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'mask' ][ 0 ] & RELATIVE_CURR_USER )
2001-08-11 11:01:47 +02:00
{
$basedir = $basedir . $this -> working_lid . $sep ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if (( $data [ 'mask' ][ 0 ] & RELATIVE_USER ) || ( $data [ 'mask' ][ 0 ] & RELATIVE_USER_APP ))
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$basedir = $basedir . $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_lid' ] . $sep ;
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'mask' ][ 0 ] & RELATIVE_USER_APP )
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$basedir = $basedir . " . " . $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'currentapp' ] . $sep ;
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
/* Don't add string if it's a /, just for aesthetics */
if ( $data [ 'string' ] && $data [ 'string' ] != $sep )
{
$basedir = $basedir . $data [ 'string' ];
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Let's not return // */
while ( ereg ( $sep . $sep , $basedir ))
{
$basedir = ereg_replace ( $sep . $sep , $sep , $basedir );
}
2001-09-28 22:41:36 +02:00
2002-02-10 05:19:43 +01:00
$basedir = ereg_replace ( $sep . '$' , '' , $basedir );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
return $basedir ;
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function acl_check
2001-09-28 22:41:36 +02:00
@ abstract Check ACL access to $file for $GLOBALS [ 'phpgw_info' ][ " user " ][ " account_id " ];
2002-01-16 07:36:51 +01:00
@ param string File to check access of
@ param relatives Standard relativity array
@ param operation Operation to check access to . In the form of a PHPGW_ACL defines bitmask . Default is read
@ param must_exist Boolean . Set to True if 'string' must exist . Otherwise , we check the parent directory as well
2001-08-11 11:01:47 +02:00
@ result Boolean . True if access is ok , False otherwise
*/
2002-01-16 07:36:51 +01:00
function acl_check ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'operation' => PHPGW_ACL_READ ,
'must_exist' => False
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-08-11 11:01:47 +02:00
/* Accommodate special situations */
2002-01-16 07:36:51 +01:00
if ( $this -> override_acl || $data [ 'relatives' ][ 0 ] == RELATIVE_USER_APP )
2001-08-11 11:01:47 +02:00
{
return True ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Temporary, until we get symlink type files set up */
if ( $p -> outside )
{
return True ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* If the file doesn't exist, we get ownership from the parent directory */
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
))
)
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( $data [ 'must_exist' ])
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$data [ 'string' ] = $p -> fake_leading_dirs ;
$p2 = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $p -> mask )
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $p -> mask )
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
}
else
{
$p2 = $p ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Read access is always allowed here, but nothing else is */
2002-01-16 07:36:51 +01:00
if ( $data [ 'string' ] == '/' || $data [ 'string' ] == $this -> fakebase )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == PHPGW_ACL_READ )
2001-08-11 11:01:47 +02:00
{
return True ;
}
else
{
return False ;
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
We don ' t use ls () to get owner_id as we normally would ,
because ls () calls acl_check (), which would create an infinite loop
*/
2002-01-16 07:36:51 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " SELECT owner_id FROM phpgw_vfs WHERE directory=' " . $p2 -> fake_leading_dirs_clean . " ' AND name=' " . $p2 -> fake_name_clean . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-09-28 22:41:36 +02:00
$GLOBALS [ 'phpgw' ] -> db -> next_record ();
$group_id = $GLOBALS [ 'phpgw' ] -> db -> Record [ 'owner_id' ];
2001-08-11 11:01:47 +02:00
/* They always have access to their own files */
2001-12-10 05:04:56 +01:00
if ( $group_id == $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ])
2001-08-11 11:01:47 +02:00
{
return True ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Check if they're in the group. If so, they have access */
2001-12-10 05:04:56 +01:00
$memberships = $GLOBALS [ 'phpgw' ] -> accounts -> membership ( $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ]);
2001-09-28 22:41:36 +02:00
2001-08-28 10:13:35 +02:00
if ( is_array ( $memberships ))
2001-08-11 11:01:47 +02:00
{
2001-12-10 05:04:56 +01:00
@ reset ( $memberships );
2001-08-28 10:13:35 +02:00
while ( list ( $num , $group_array ) = @ each ( $memberships ))
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
if ( $group_id == $GLOBALS [ 'phpgw' ] -> accounts -> name2id ( $group_array [ 'account_name' ]))
2001-08-28 10:13:35 +02:00
{
$group_ok = 1 ;
break ;
}
2001-08-11 11:01:47 +02:00
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( ! $group_id )
2001-07-02 21:00:31 +02:00
{
2001-08-11 11:01:47 +02:00
if ( ! $group_id = $this -> account_id )
{
$group_id = 0 ;
}
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
$acl = CreateObject ( 'phpgwapi.acl' , $group_id );
2001-08-11 11:01:47 +02:00
$acl -> account_id = $group_id ;
$acl -> read_repository ();
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$rights = $acl -> get_rights ( $account_id );
2002-01-16 07:36:51 +01:00
if ( $rights & $data [ 'operation' ])
2001-07-02 21:00:31 +02:00
{
2001-08-11 11:01:47 +02:00
return True ;
2001-07-02 21:00:31 +02:00
}
2001-08-11 11:01:47 +02:00
elseif ( ! $rights && $group_ok )
2001-07-02 21:00:31 +02:00
{
return True ;
}
else
{
return False ;
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function cd
@ abstract Change directory
2001-09-28 22:41:36 +02:00
@ discussion To cd to the files root '/' , use cd ( '/' , False , array ( RELATIVE_NONE ));
2002-01-16 07:36:51 +01:00
@ param string default '/' . directory to cd into . if " / " and $relative is True , uses " /home/<working_lid> " ;
@ param relative default True / relative means add target to current path , else pass $relative as mask to getabsolutepath ()
@ param relatives Relativity array
2001-07-02 21:00:31 +02:00
*/
2002-01-16 07:36:51 +01:00
function cd ( $data = '' )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$noargs = 1 ;
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'string' => '/' ,
'relative' => True ,
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
if ( $data [ 'relatives' ][ 0 ] & VFS_REAL )
2001-07-02 21:00:31 +02:00
{
2001-08-11 11:01:47 +02:00
$sep = SEP ;
2001-07-02 21:00:31 +02:00
}
2001-08-11 11:01:47 +02:00
else
2001-07-09 07:09:27 +02:00
{
2001-09-28 22:41:36 +02:00
$sep = '/' ;
2001-07-09 07:09:27 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'relative' ] == 'relative' || $data [ 'relative' ] == True )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
/* if 'string' is "/" and 'relative' is set, we cd to the user/group home dir */
if ( $data [ 'string' ] == '/' )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$data [ 'relatives' ][ 0 ] = RELATIVE_USER ;
$basedir = $this -> getabsolutepath ( array (
'string' => False ,
'mask' => array ( $data [ 'relatives' ][ 0 ]),
'fake' => True
)
);
2001-08-11 11:01:47 +02:00
}
else
{
2001-12-10 05:04:56 +01:00
$currentdir = $GLOBALS [ 'phpgw' ] -> session -> appsession ( 'vfs' , '' );
2002-01-16 07:36:51 +01:00
$basedir = $this -> getabsolutepath ( array (
'string' => $currentdir . $sep . $data [ 'string' ],
'mask' => array ( $data [ 'relatives' ][ 0 ]),
'fake' => True
)
);
2001-08-11 11:01:47 +02:00
}
}
else
{
2002-01-16 07:36:51 +01:00
$basedir = $this -> getabsolutepath ( array (
'string' => $data [ 'string' ],
'mask' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-12-10 05:04:56 +01:00
$GLOBALS [ 'phpgw' ] -> session -> appsession ( 'vfs' , '' , $basedir );
2001-09-28 22:41:36 +02:00
2001-07-02 21:00:31 +02:00
return True ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function pwd
@ abstract current working dir
2002-01-16 07:36:51 +01:00
@ param full default True returns full fake path , else just the extra dirs ( false strips the leading / )
2001-08-11 11:01:47 +02:00
@ result $currentdir currentdir
*/
2002-01-16 07:36:51 +01:00
function pwd ( $data = '' )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
{
$data = array ();
}
$default_values = array
(
'full' => True
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-12-10 05:04:56 +01:00
$currentdir = $GLOBALS [ 'phpgw' ] -> session -> appsession ( 'vfs' , '' );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'full' ])
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$currentdir = ereg_replace ( " ^/ " , '' , $currentdir );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $currentdir == '' && $data [ 'full' ])
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$currentdir = '/' ;
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$currentdir = trim ( $currentdir );
return $currentdir ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function read
@ abstract return file contents
2002-01-16 07:36:51 +01:00
@ param string filename
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result $contents Contents of $file , or False if file cannot be read
*/
2002-01-16 07:36:51 +01:00
function read ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_READ
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
if ( $fp = fopen ( $p -> real_full_path , 'rb' ))
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
$contents = fread ( $fp , filesize ( $p -> real_full_path ));
fclose ( $fp );
2001-05-25 05:34:24 +02:00
}
else
{
2001-12-20 03:38:02 +01:00
$contents = False ;
2001-05-25 05:34:24 +02:00
}
2002-01-16 07:36:51 +01:00
2001-12-20 03:38:02 +01:00
return $contents ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function write
@ abstract write to a file
2002-01-16 07:36:51 +01:00
@ param string file name
@ param relatives Relativity array
@ param content content
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
2001-09-28 22:41:36 +02:00
*/
2002-01-16 07:36:51 +01:00
function write ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'content' => ''
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
))
)
2001-08-11 11:01:47 +02:00
{
$acl_operation = PHPGW_ACL_EDIT ;
$journal_operation = VFS_OPERATION_EDITED ;
}
else
{
$acl_operation = PHPGW_ACL_ADD ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => $acl_operation
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
umask ( 000 );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
2002-01-16 07:36:51 +01:00
If 'string' doesn ' t exist , touch () creates both the file and the database entry
If 'string' does exist , touch () sets the modification time and modified by
2001-08-11 11:01:47 +02:00
*/
2002-01-16 07:36:51 +01:00
$this -> touch ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
)
);
2001-09-28 22:41:36 +02:00
2001-12-10 05:04:56 +01:00
if ( $fp = fopen ( $p -> real_full_path , 'wb' ))
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
fwrite ( $fp , $data [ 'content' ], strlen ( $data [ 'content' ]));
2001-08-11 11:01:47 +02:00
fclose ( $fp );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'attributes' => array ( 'size' => filesize ( $p -> real_full_path ))
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $journal_operation )
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => $journal_operation
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
}
else
{
return False ;
}
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function touch
@ abstract Create blank file $file or set the modification time and modified by of $file to current time and user
2002-01-16 07:36:51 +01:00
@ param string File to touch or set modifies
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
2001-05-25 05:34:24 +02:00
*/
2002-01-16 07:36:51 +01:00
function touch ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
$currentapp = $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'currentapp' ];
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
umask ( 000 );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
PHP ' s touch function will automatically decide whether to
create the file or set the modification time
*/
2002-01-16 07:36:51 +01:00
$rr = @ touch ( $p -> real_full_path );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $p -> outside )
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
return $rr ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* We, however, have to decide this ourselves */
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
))
)
{
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_EDIT
)))
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$vr = $this -> set_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'attributes' => array (
'modifiedby_id' => $account_id ,
'modified' => $this -> now
)
)
);
2001-08-11 11:01:47 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " INSERT INTO phpgw_vfs (owner_id, directory, name) VALUES ( $this->working_id , ' $p->fake_leading_dirs_clean ', ' $p->fake_name_clean ') " , __LINE__ , __FILE__ );
$this -> set_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'attributes' => array (
'createdby_id' => $account_id ,
'created' => $this -> now ,
'size' => 0 ,
'deleteable' => 'Y' ,
'app' => $currentapp
)
)
);
$this -> correct_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
2001-09-28 22:41:36 +02:00
)
);
2001-08-11 11:01:47 +02:00
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => VFS_OPERATION_CREATED
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $rr || $vr || $query )
{
return True ;
}
else
{
return False ;
2001-07-13 07:12:18 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function cp
@ abstract copy file
2002-01-16 07:36:51 +01:00
@ param from from file / directory
@ param to to file / directory
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result boolean True / False
2001-05-25 05:34:24 +02:00
*/
2002-01-16 07:36:51 +01:00
function cp ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT , RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
2002-01-16 07:36:51 +01:00
$f = $this -> path_parts ( array (
'string' => $data [ 'from' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
$t = $this -> path_parts ( array (
'string' => $data [ 'to' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => PHPGW_ACL_READ
))
)
2001-07-02 21:00:31 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
))
)
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => PHPGW_ACL_EDIT
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
}
else
{
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
umask ( 000 );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_type ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
)) != 'Directory'
)
2001-08-11 11:01:47 +02:00
{
if ( ! copy ( $f -> real_full_path , $t -> real_full_path ))
{
return False ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $t -> outside )
{
return True ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$size = filesize ( $t -> real_full_path );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'checksubdirs' => False ,
'mime_type' => False ,
'nofiles' => True
)
);
2001-08-11 11:01:47 +02:00
$record = $ls_array [ 0 ];
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $data [ 'to' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
))
)
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET owner_id=' $this->working_id ', directory=' $t->fake_leading_dirs_clean ', name=' $t->fake_name_clean ' WHERE owner_id=' $this->working_id ' AND directory=' $t->fake_leading_dirs_clean ' AND name=' $t->fake_name_clean ' " . $this -> extra_sql ( VFS_SQL_UPDATE ), __LINE__ , __FILE__ );
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'attributes' => array (
'createdby_id' => $account_id ,
'created' => $this -> now ,
'size' => $size ,
'mime_type' => $record [ 'mime_type' ],
'deleteable' => $record [ 'deleteable' ],
'comment' => $record [ 'comment' ],
'app' => $record [ 'app' ]
)
)
);
$this -> add_journal ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => VFS_OPERATION_EDITED
2001-09-28 22:41:36 +02:00
)
);
2001-08-11 11:01:47 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
$this -> touch ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)
);
$this -> set_attributes ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'attributes' => array (
'createdby_id' => $account_id ,
'created' => $this -> now ,
'size' => $size ,
'mime_type' => $record [ 'mime_type' ],
'deleteable' => $record [ 'deleteable' ],
'comment' => $record [ 'comment' ],
'app' => $record [ 'app' ]
)
2001-09-28 22:41:36 +02:00
)
);
2001-08-11 11:01:47 +02:00
}
2002-01-16 07:36:51 +01:00
$this -> correct_attributes ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
else /* It's a directory */
{
/* First, make the initial directory */
2002-01-16 07:36:51 +01:00
$this -> mkdir ( array (
'string' => $data [ 'to' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Next, we create all the directories below the initial directory */
2002-01-16 07:36:51 +01:00
$ls = $this -> ls ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'checksubdirs' => True ,
'mime_type' => 'Directory'
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
while ( list ( $num , $entry ) = each ( $ls ))
{
2001-09-28 22:41:36 +02:00
$newdir = ereg_replace ( " ^ $f->fake_full_path " , " $t->fake_full_path " , $entry [ 'directory' ]);
2002-01-16 07:36:51 +01:00
$this -> mkdir ( array (
'string' => $newdir . '/' . $entry [ 'name' ],
'relatives' => array ( $t -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Lastly, we copy the files over */
2002-01-16 07:36:51 +01:00
$ls = $this -> ls ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
while ( list ( $num , $entry ) = each ( $ls ))
{
2001-09-28 22:41:36 +02:00
if ( $entry [ 'mime_type' ] == 'Directory' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
$newdir = ereg_replace ( " ^ $f->fake_full_path " , " $t->fake_full_path " , $entry [ 'directory' ]);
2002-01-16 07:36:51 +01:00
$this -> cp ( array (
'from' => " $entry[directory] / $entry[name] " ,
'to' => " $newdir / $entry[name] " ,
'relatives' => array ( $f -> mask , $t -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( ! $f -> outside )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => VFS_OPERATION_COPIED ,
'state_one' => NULL ,
'state_two' => $t -> fake_full_path
)
);
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2001-05-25 05:34:24 +02:00
return True ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
function copy ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
return $this -> cp ( $data );
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function mv
@ abstract move file / directory
2002-01-16 07:36:51 +01:00
@ param from from file / directory
@ param to to file / directory
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result boolean True / False
*/
2002-01-16 07:36:51 +01:00
function mv ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT , RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
2002-01-16 07:36:51 +01:00
$f = $this -> path_parts ( array (
'string' => $data [ 'from' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
$t = $this -> path_parts ( array (
'string' => $data [ 'to' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => PHPGW_ACL_READ
))
|| ! $this -> acl_check ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => PHPGW_ACL_DELETE
))
)
2001-07-02 21:00:31 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-07-02 21:00:31 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
))
)
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => PHPGW_ACL_EDIT
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
umask ( 000 );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* We can't move directories into themselves */
2002-01-16 07:36:51 +01:00
if (( $this -> file_type ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
) == 'Directory' ))
&& ereg ( " ^ $f->fake_full_path " , $t -> fake_full_path )
)
2001-06-18 23:18:22 +02:00
{
2001-09-28 22:41:36 +02:00
if (( $t -> fake_full_path == $f -> fake_full_path ) || substr ( $t -> fake_full_path , strlen ( $f -> fake_full_path ), 1 ) == '/' )
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-06-18 23:18:22 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
))
)
2001-06-18 23:18:22 +02:00
{
2001-08-11 11:01:47 +02:00
/* We get the listing now, because it will change after we update the database */
2002-01-16 07:36:51 +01:00
$ls = $this -> ls ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
))
)
2001-08-24 09:44:43 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> rm ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)
);
2001-08-24 09:44:43 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
We add the journal entry now , before we delete . This way the mime_type
field will be updated to 'journal-deleted' when the file is actually deleted
*/
if ( ! $f -> outside )
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => VFS_OPERATION_MOVED ,
'state_one' => $f -> fake_full_path ,
'state_two' => $t -> fake_full_path
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
If the from file is outside , it won ' t have a database entry ,
so we have to touch it and find the size
*/
if ( $f -> outside )
{
$size = filesize ( $f -> real_full_path );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> touch ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)
);
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET size= $size WHERE directory=' $t->fake_leading_dirs_clean ' AND name=' $t->fake_name_clean ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_UPDATE )), __LINE__ , __FILE__ );
2001-08-11 11:01:47 +02:00
}
elseif ( ! $t -> outside )
{
2002-01-16 07:36:51 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET name=' $t->fake_name_clean ', directory=' $t->fake_leading_dirs_clean ' WHERE directory=' $f->fake_leading_dirs_clean ' AND name=' $f->fake_name_clean ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_UPDATE )), __LINE__ , __FILE__ );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'attributes' => array (
'modifiedby_id' => $account_id ,
'modified' => $this -> now
)
)
);
$this -> correct_attributes ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
2001-09-28 22:41:36 +02:00
)
);
2001-08-11 11:01:47 +02:00
$rr = rename ( $f -> real_full_path , $t -> real_full_path );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
This removes the original entry from the database
The actual file is already deleted because of the rename () above
*/
if ( $t -> outside )
{
2002-01-16 07:36:51 +01:00
$this -> rm ( array (
'string' => $f -> fake_full_path ,
'relatives' => $f -> mask
)
);
2001-08-11 11:01:47 +02:00
}
2001-06-18 23:18:22 +02:00
}
else
{
2001-08-11 11:01:47 +02:00
return False ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_type ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)) == 'Directory'
)
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
/* We got $ls from above, before we renamed the directory */
while ( list ( $num , $entry ) = each ( $ls ))
2001-05-25 05:34:24 +02:00
{
2001-09-28 22:41:36 +02:00
$newdir = ereg_replace ( " ^ $f->fake_full_path " , $t -> fake_full_path , $entry [ 'directory' ]);
2002-01-16 07:36:51 +01:00
$newdir_clean = $this -> db_clean ( array ( 'string' => $newdir ));
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET directory=' $newdir_clean ' WHERE file_id=' $entry[file_id] ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_UPDATE )), __LINE__ , __FILE__ );
$this -> correct_attributes ( array (
'string' => " $newdir / $entry[name] " ,
'relatives' => array ( $t -> mask )
)
);
2001-05-25 05:34:24 +02:00
}
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => VFS_OPERATION_MOVED ,
'state_one' => $f -> fake_full_path ,
'state_two' => $t -> fake_full_path
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function move
@ abstract shortcut to mv
*/
2002-01-16 07:36:51 +01:00
function move ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
return $this -> mv ( $data );
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function rm
@ abstract delete file / directory
2002-01-16 07:36:51 +01:00
@ param string file / directory to delete
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result boolean True / False
*/
2002-01-16 07:36:51 +01:00
function rm ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_DELETE
))
)
2001-07-02 21:00:31 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
))
)
2001-08-11 11:01:47 +02:00
{
$rr = unlink ( $p -> real_full_path );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $rr )
{
return True ;
}
else
{
return False ;
}
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_type ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)) != 'Directory'
)
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => VFS_OPERATION_DELETED
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " DELETE FROM phpgw_vfs WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_DELETE )), __LINE__ , __FILE__ );
2001-08-11 11:01:47 +02:00
$rr = unlink ( $p -> real_full_path );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $query || $rr )
{
return True ;
}
else
{
return False ;
}
}
else
{
2002-01-16 07:36:51 +01:00
$ls = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* First, we cycle through the entries and delete the files */
while ( list ( $num , $entry ) = each ( $ls ))
{
2001-09-28 22:41:36 +02:00
if ( $entry [ 'mime_type' ] == 'Directory' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> rm ( array (
'string' => " $entry[directory] / $entry[name] " ,
'relatives' => array ( $p -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Now we cycle through again and delete the directories */
reset ( $ls );
while ( list ( $num , $entry ) = each ( $ls ))
{
2001-09-28 22:41:36 +02:00
if ( $entry [ 'mime_type' ] != 'Directory' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Only the best in confusing recursion */
2002-01-16 07:36:51 +01:00
$this -> rm ( array (
'string' => " $entry[directory] / $entry[name] " ,
'relatives' => array ( $p -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* If the directory is linked, we delete the placeholder directory */
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => False ,
'mime_type' => False ,
'nofiles' => True
)
);
2001-08-11 11:01:47 +02:00
$link_info = $ls_array [ 0 ];
2001-09-28 22:41:36 +02:00
if ( $link_info [ 'link_directory' ] && $link_info [ 'link_name' ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$path = $this -> path_parts ( array (
'string' => $link_info [ 'directory' ] . '/' . $link_info [ 'name' ],
'relatives' => array ( $p -> mask ),
'nolinks' => True
)
);
2001-08-11 11:01:47 +02:00
rmdir ( $path -> real_full_path );
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Last, we delete the directory itself */
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operaton' => VFS_OPERATION_DELETED
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " DELETE FROM phpgw_vfs WHERE directory=' $p->fake_leading_dirs_clean ' AND name=' $p->fake_name_clean ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_DELETE )), __LINE__ , __FILE__ );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
rmdir ( $p -> real_full_path );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
}
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function delete
@ abstract shortcut to rm
*/
2002-01-16 07:36:51 +01:00
function delete ( $data )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
return $this -> rm ( $data );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function mkdir
@ abstract make a new directory
2002-01-16 07:36:51 +01:00
@ param string Directory name
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result boolean True on success
*/
2002-01-16 07:36:51 +01:00
function mkdir ( $data )
2001-06-14 08:39:10 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
$currentapp = $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'currentapp' ];
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_ADD )
)
)
2001-06-14 08:39:10 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* We don't allow /'s in dir names, of course */
if ( ereg ( " / " , $p -> fake_name ))
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
umask ( 000 );
2001-09-28 22:41:36 +02:00
2002-02-14 03:16:14 +01:00
if ( !@ mkdir ( $p -> real_full_path , 0770 ))
2001-06-18 23:18:22 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-06-18 23:18:22 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
))
)
{
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " INSERT INTO phpgw_vfs (owner_id, name, directory) VALUES ( $this->working_id , ' $p->fake_name_clean ', ' $p->fake_leading_dirs_clean ') " , __LINE__ , __FILE__ );
$this -> set_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'attributes' => array (
'createdby_id' => $account_id ,
'size' => 4096 ,
'mime_type' => 'Directory' ,
'created' => $this -> now ,
'deleteable' => 'Y' ,
'app' => $currentapp
)
)
);
$this -> correct_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
2001-09-28 22:41:36 +02:00
)
);
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => VFS_OPERATION_CREATED
)
);
2001-06-18 23:18:22 +02:00
}
2001-08-11 11:01:47 +02:00
else
2001-06-18 23:18:22 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-06-18 23:18:22 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function make_link
2002-01-16 07:36:51 +01:00
@ abstract Make a link from virtual directory 'vdir' to real directory 'rdir'
@ discussion Making a link from 'vdir' to 'rdir' will cause path_parts () to substitute 'rdir' for the real
path variables when presented with 'vdir'
@ param vdir Virtual dir to make link from
@ param rdir Real dir to make link to
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
*/
2002-01-16 07:36:51 +01:00
function make_link ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT , RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
$currentapp = $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'currentapp' ];
2002-01-16 07:36:51 +01:00
$vp = $this -> path_parts ( array (
'string' => $data [ 'vdir' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
$rp = $this -> path_parts ( array (
'string' => $data [ 'rdir' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $vp -> fake_full_path ,
'relatives' => array ( $vp -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if (( ! $this -> file_exists ( array (
'string' => $rp -> real_full_path ,
'relatives' => array ( $rp -> mask )
)))
&& ! mkdir ( $rp -> real_full_path , 0770 ))
2001-06-16 05:54:10 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-06-16 05:54:10 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> mkdir ( array (
'string' => $vp -> fake_full_path ,
'relatives' => array ( $vp -> mask )
))
)
2001-06-16 05:54:10 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$size = $this -> get_size ( array (
'string' => $rp -> real_full_path ,
'relatives' => array ( $rp -> mask )
)
);
$this -> set_attributes ( array (
'string' => $vp -> fake_full_path ,
'relatives' => array ( $vp -> mask ),
'attributes' => array (
'link_directory' => $rp -> real_leading_dirs ,
'link_name' => $rp -> real_name ,
'size' => $size
)
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> correct_attributes ( array (
'string' => $vp -> fake_full_path ,
'relatives' => array ( $vp -> mask )
2001-09-28 22:41:36 +02:00
)
);
2001-08-11 11:01:47 +02:00
return True ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function set_attributes
2002-01-16 07:36:51 +01:00
@ abstract Update database entry for 'string' with the attributes in 'attributes'
@ param string file / directory to update
@ param relatives Relativity array
@ param attributes keyed array of attributes . key is attribute name , value is attribute value
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
@ discussion Valid attributes are :
owner_id
createdby_id
modifiedby_id
created
modified
size
mime_type
deleteable
comment
app
link_directory
link_name
version
2001-12-10 05:04:56 +01:00
name
directory
2001-08-11 11:01:47 +02:00
*/
2002-01-16 07:36:51 +01:00
function set_attributes ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'attributes' => array ()
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
This is kind of trivial , given that set_attributes () can change owner_id ,
size , etc .
*/
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_EDIT
))
)
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
))
)
{
return False ;
}
2001-12-20 03:38:02 +01:00
2001-08-11 11:01:47 +02:00
/*
2001-08-24 09:44:43 +02:00
All this voodoo just decides which attributes to update
2002-01-16 07:36:51 +01:00
depending on if the attribute was supplied in the 'attributes' array
2001-08-11 11:01:47 +02:00
*/
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => False ,
'nofiles' => True
)
);
2001-08-11 11:01:47 +02:00
$record = $ls_array [ 0 ];
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$sql = 'UPDATE phpgw_vfs SET ' ;
$change_attributes = 0 ;
reset ( $this -> attributes );
2001-12-10 05:04:56 +01:00
while ( list ( $num , $attribute ) = each ( $this -> attributes ))
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( isset ( $data [ 'attributes' ][ $attribute ]))
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
$$attribute = $data [ 'attributes' ][ $attribute ];
/*
Indicate that the EDITED_COMMENT operation needs to be journaled ,
but only if the comment changed
*/
if ( $attribute == 'comment' && $data [ 'attributes' ][ $attribute ] != $record [ $attribute ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$edited_comment = 1 ;
2001-08-11 11:01:47 +02:00
}
2002-01-16 07:36:51 +01:00
$$attribute = $this -> db_clean ( array ( 'string' => $$attribute ));
if ( $change_attributes > 0 )
2001-08-24 09:44:43 +02:00
{
2002-01-16 07:36:51 +01:00
$sql .= ', ' ;
2001-08-24 09:44:43 +02:00
}
2002-01-16 07:36:51 +01:00
$sql .= " $attribute =' " . $$attribute . " ' " ;
$change_attributes ++ ;
2001-12-10 05:04:56 +01:00
}
}
2002-01-16 07:36:51 +01:00
$sql .= " WHERE file_id=' $record[file_id] ' " ;
$sql .= $this -> extra_sql ( array ( 'query_type' => VFS_SQL_UPDATE ));
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $query )
2001-07-09 07:09:27 +02:00
{
2002-01-16 07:36:51 +01:00
if ( $edited_comment )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => VFS_OPERATION_EDITED_COMMENT
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
}
else
{
return False ;
2001-07-09 07:09:27 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function correct_attributes
2002-01-16 07:36:51 +01:00
@ abstract Set the correct attributes for 'string' ( e . g . owner )
@ param string File / directory to correct attributes of
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
2001-05-25 05:34:24 +02:00
*/
2002-01-16 07:36:51 +01:00
function correct_attributes ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
if ( $p -> fake_leading_dirs != $this -> fakebase && $p -> fake_leading_dirs != '/' )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_leading_dirs ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => False ,
'nofiles' => True
)
);
$set_attributes_array = Array (
2002-01-07 11:50:42 +01:00
'owner_id' => $ls_array [ 0 ][ 'owner_id' ]
);
2001-08-11 11:01:47 +02:00
}
elseif ( preg_match ( " +^ $this->fakebase\ /(.*) $ +U " , $p -> fake_full_path , $matches ))
{
2002-01-16 07:36:51 +01:00
$set_attributes_array = Array (
2002-01-07 11:50:42 +01:00
'owner_id' => $GLOBALS [ 'phpgw' ] -> accounts -> name2id ( $matches [ 1 ])
);
2001-05-25 05:34:24 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
$set_attributes_array = Array (
2002-01-07 11:50:42 +01:00
'owner_id' => 0
);
2001-05-25 05:34:24 +02:00
}
2001-12-15 05:24:37 +01:00
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $p -> fake_full_name ,
'relatives' => array ( $p -> mask ),
'attributes' => $set_attributes_array
)
);
2001-12-15 05:24:37 +01:00
2002-01-16 07:36:51 +01:00
return True ;
2001-12-15 05:24:37 +01:00
}
2001-08-11 11:01:47 +02:00
/*!
@ function file_type
@ abstract return file / dir type ( MIME or other )
2002-01-16 07:36:51 +01:00
@ param string File or directory path ( / home / user / dir / dir2 / dir3 , / home / user / dir / dir2 / file )
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result MIME type , " Directory " , or nothing if MIME type is not known
*/
2002-01-16 07:36:51 +01:00
function file_type ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_READ ,
'must_exist' => True
))
)
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $p -> outside )
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
if ( is_dir ( $p -> real_full_path ))
{
2001-09-28 22:41:36 +02:00
return ( 'Directory' );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
We don ' t return an empty string here , because it may still match with a database query
because of linked directories
*/
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-07-13 07:12:18 +02:00
/*
2001-08-11 11:01:47 +02:00
We don ' t use ls () because it calls file_type () to determine if it has been
passed a directory
2001-07-13 07:12:18 +02:00
*/
2001-12-20 03:38:02 +01:00
$db2 = $GLOBALS [ 'phpgw' ] -> db ;
2002-01-16 07:36:51 +01:00
$db2 -> query ( " SELECT mime_type FROM phpgw_vfs WHERE directory=' $p->fake_leading_dirs_clean ' AND name=' $p->fake_name_clean ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-20 03:38:02 +01:00
$db2 -> next_record ();
$mime_type = $db2 -> Record [ 'mime_type' ];
2001-12-15 05:24:37 +01:00
if ( ! $mime_type )
{
2002-01-16 07:36:51 +01:00
$mime_type = $this -> get_ext_mime_type ( array ( 'string' => $data [ 'string' ]));
2001-12-15 05:24:37 +01:00
{
2002-01-16 07:36:51 +01:00
$db2 -> query ( " UPDATE phpgw_vfs SET mime_type=' " . $mime_type . " ' WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-15 05:24:37 +01:00
}
}
2002-01-16 07:36:51 +01:00
2001-12-15 05:24:37 +01:00
return $mime_type ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
/*!
@ function get_ext_mime_type
@ abstract return MIME type based on file extension
@ description Authors : skeeter
Internal use only . Applications should call vfs -> file_type ()
@ param string File name , with or without leading paths
@ result MIME type based on file extension
*/
function get_ext_mime_type ( $data )
{
if ( ! is_array ( $data ))
{
$data = array ();
}
$file = basename ( $data [ 'string' ]);
$mimefile = PHPGW_API_INC . '/phpgw_mime.types' ;
$fp = fopen ( $mimefile , 'r' );
$contents = explode ( " \n " , fread ( $fp , filesize ( $mimefile )));
fclose ( $fp );
$parts = explode ( '.' , strtolower ( $file ));
$ext = $parts [( sizeof ( $parts ) - 1 )];
for ( $i = 0 ; $i < sizeof ( $contents ); $i ++ )
{
if ( ! ereg ( " ^# " , $contents [ $i ]))
{
$line = split ( " [[:space:]]+ " , $contents [ $i ]);
if ( sizeof ( $line ) >= 2 )
{
for ( $j = 1 ; $j < sizeof ( $line ); $j ++ )
{
if ( $line [ $j ] == $ext )
{
2002-02-10 05:19:43 +01:00
return $line [ 0 ];
2002-01-16 07:36:51 +01:00
}
}
}
}
}
2002-02-10 05:19:43 +01:00
return '' ;
2002-01-16 07:36:51 +01:00
}
2001-08-11 11:01:47 +02:00
/*!
@ function file_exists
@ abstract check if file / directory exists
2002-01-16 07:36:51 +01:00
@ param string file / directory to check existance of
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
2001-07-09 07:09:27 +02:00
*/
2002-01-16 07:36:51 +01:00
function file_exists ( $data )
2001-07-09 07:09:27 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $p -> outside )
{
2002-01-16 07:36:51 +01:00
$rr = file_exists ( $p -> real_full_path );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
return $rr ;
2001-12-15 05:24:37 +01:00
}
2001-09-28 22:41:36 +02:00
2001-12-20 03:38:02 +01:00
$db2 = $GLOBALS [ 'phpgw' ] -> db ;
2002-01-16 07:36:51 +01:00
$db2 -> query ( " SELECT name FROM phpgw_vfs WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-20 03:38:02 +01:00
2002-01-16 07:36:51 +01:00
if ( $db2 -> next_record ())
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
return True ;
2001-08-11 11:01:47 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
return False ;
2001-08-11 11:01:47 +02:00
}
2001-07-09 07:09:27 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function get_size
2002-01-16 07:36:51 +01:00
@ abstract Return size of 'string'
@ param string file / directory to get size of
@ param relatives Relativity array
@ param checksubdirs Boolean , recursively add the size of all sub directories as well ?
@ result Size of 'string' in bytes
2001-08-11 11:01:47 +02:00
*/
2002-01-16 07:36:51 +01:00
function get_size ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'checksubdirs' => True
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_READ ,
'must_exist' => True
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2001-07-02 22:38:49 +02:00
/*
2001-08-11 11:01:47 +02:00
WIP - this should run through all of the subfiles / directories in the directory and tally up
their sizes . Should modify ls () to be able to return a list for files outside the virtual root
2001-07-02 22:38:49 +02:00
*/
2001-08-11 11:01:47 +02:00
if ( $p -> outside )
2001-07-02 22:38:49 +02:00
{
2002-01-16 07:36:51 +01:00
$size = filesize ( $p -> real_full_path );
return $size ;
2001-07-02 22:38:49 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => $data [ 'checksubdirs' ],
'nofiles' => ! $data [ 'checksubdirs' ]
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
while ( list ( $num , $file_array ) = each ( $ls_array ))
{
/*
Make sure the file is in the directory we want , and not
some deeper nested directory with a similar name
*/
2002-01-16 07:36:51 +01:00
/*
if ( @! ereg ( '^' . $file_array [ 'directory' ], $p -> fake_full_path ))
2001-08-11 11:01:47 +02:00
{
continue ;
}
2002-01-16 07:36:51 +01:00
*/
2001-09-28 22:41:36 +02:00
$size += $file_array [ 'size' ];
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'checksubdirs' ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " SELECT size FROM phpgw_vfs WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " . $this -> extra_sql ( array ( 'query_text' => VFS_SQL_SELECT )));
2001-09-28 22:41:36 +02:00
$GLOBALS [ 'phpgw' ] -> db -> next_record ();
2002-01-16 07:36:51 +01:00
$size += $GLOBALS [ 'phpgw' ] -> db -> Record [ 0 ];
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return $size ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function checkperms
@ abstract Check if $this -> working_id has write access to create files in $dir
@ discussion Simple call to acl_check
2002-01-16 07:36:51 +01:00
@ param string Directory to check access of
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
*/
2002-01-16 07:36:51 +01:00
function checkperms ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-07-10 23:35:23 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-10 23:35:23 +02:00
}
2001-08-11 11:01:47 +02:00
else
2001-07-10 23:35:23 +02:00
{
2001-08-11 11:01:47 +02:00
return True ;
2001-07-10 23:35:23 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function ls
@ abstract get directory listing or info about a single file
@ discussion Note : The entries are not guaranteed to be returned in any logical order
Note : The size for directories does not include subfiles / subdirectories .
If you need that , use $this -> get_size ()
2002-01-16 07:36:51 +01:00
@ param string File or Directory
@ param relatives Relativity array
@ param checksubdirs Boolean , recursively list all sub directories as well ?
@ param mime_type Only return entries matching MIME - type 'mime_type' . Can be any MIME - type , " Directory " or " \ " for those without MIME types
@ param nofiles Boolean . True means you want to return just the information about the directory $dir . If $dir is a file , $nofiles is implied . This is the equivalent of 'ls -ld $dir'
@ param orderby How to order results . Note that this only works for directories inside the virtual root
2001-08-11 11:01:47 +02:00
@ result array of arrays . Subarrays contain full info for each file / dir .
*/
2002-01-16 07:36:51 +01:00
function ls ( $data )
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'checksubdirs' => True ,
'mime_type' => False ,
'nofiles' => False ,
'orderby' => 'directory'
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-08-11 11:01:47 +02:00
$dir = $p -> fake_full_path ;
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
/* If they pass us a file or 'nofiles' is set, return the info for $dir only */
if (((( $type = $this -> file_type ( array (
'string' => $dir ,
'relatives' => array ( $p -> mask )
)) != 'Directory' ))
|| ( $data [ 'nofiles' ])) && ! $p -> outside
)
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
/* SELECT all, the, attributes */
2001-09-28 22:41:36 +02:00
$sql = 'SELECT ' ;
2001-08-11 11:01:47 +02:00
reset ( $this -> attributes );
while ( list ( $num , $attribute ) = each ( $this -> attributes ))
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
if ( $num )
2001-07-13 07:12:18 +02:00
{
2001-09-28 22:41:36 +02:00
$sql .= ', ' ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-12-10 05:04:56 +01:00
$sql .= $attribute ;
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$sql .= " FROM phpgw_vfs WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT ));
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
$GLOBALS [ 'phpgw' ] -> db -> next_record ();
$record = $GLOBALS [ 'phpgw' ] -> db -> Record ;
2001-08-11 11:01:47 +02:00
/* We return an array of one array to maintain the standard */
$rarray = array ();
reset ( $this -> attributes );
while ( list ( $num , $attribute ) = each ( $this -> attributes ))
{
2002-01-16 07:36:51 +01:00
if ( $attribute == 'mime_type' && ! $record [ $attribute ])
2001-12-15 05:24:37 +01:00
{
2001-12-20 03:38:02 +01:00
$db2 = $GLOBALS [ 'phpgw' ] -> db ;
2002-01-16 07:36:51 +01:00
$record [ $attribute ] = $this -> get_ext_mime_type ( array (
'string' => $p -> fake_name_clean
)
);
2001-12-15 05:24:37 +01:00
if ( $record [ $attribute ])
{
2002-01-16 07:36:51 +01:00
$db2 -> query ( " UPDATE phpgw_vfs SET mime_type=' " . $record [ $attribute ] . " ' WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-15 05:24:37 +01:00
}
}
2002-01-16 07:36:51 +01:00
2001-08-11 11:01:47 +02:00
$rarray [ 0 ][ $attribute ] = $record [ $attribute ];
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return $rarray ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
//WIP - this should recurse using the same options the virtual part of ls () does
/* If $dir is outside the virutal root, we have to check the file system manually */
if ( $p -> outside )
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
if ( $this -> file_type ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
)) == 'Directory'
&& ! $data [ 'nofiles' ]
)
2001-08-11 11:01:47 +02:00
{
$dir_handle = opendir ( $p -> real_full_path );
while ( $filename = readdir ( $dir_handle ))
{
2001-09-28 22:41:36 +02:00
if ( $filename == '.' || $filename == '..' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$rarray [] = $this -> get_real_info ( array (
'string' => $p -> real_full_path . SEP . $filename ,
'relatives' => array ( $p -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
}
else
{
2002-01-16 07:36:51 +01:00
$rarray [] = $this -> get_real_info ( array (
'string' => $p -> real_full_path ,
'relatives' => array ( $p -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return $rarray ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* $dir's not a file, is inside the virtual root, and they want to check subdirs */
/* SELECT all, the, attributes FROM phpgw_vfs WHERE file=$dir */
2001-09-28 22:41:36 +02:00
$sql = 'SELECT ' ;
2001-08-11 11:01:47 +02:00
reset ( $this -> attributes );
while ( list ( $num , $attribute ) = each ( $this -> attributes ))
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
if ( $num )
{
$sql .= " , " ;
}
2001-09-28 22:41:36 +02:00
2001-12-10 05:04:56 +01:00
$sql .= $attribute ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$dir_clean = $this -> db_clean ( array ( 'string' => $dir ));
$sql .= " FROM phpgw_vfs WHERE directory LIKE ' $dir_clean %' " ;
$sql .= $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT ));
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'mime_type' ])
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
$sql .= " AND mime_type=' " . $data [ 'mime_type' ] . " ' " ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$sql .= ' ORDER BY ' . $data [ 'orderby' ];
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
2001-08-11 11:01:47 +02:00
$rarray = array ();
2001-09-28 22:41:36 +02:00
for ( $i = 0 ; $GLOBALS [ 'phpgw' ] -> db -> next_record (); $i ++ )
2001-07-10 23:35:23 +02:00
{
2001-09-28 22:41:36 +02:00
$record = $GLOBALS [ 'phpgw' ] -> db -> Record ;
2001-08-11 11:01:47 +02:00
/* Further checking on the directory. This makes sure /home/user/test won't match /home/user/test22 */
2002-01-16 07:36:51 +01:00
if ( @! ereg ( " ^ $dir (/| $ ) " , $record [ 'directory' ]))
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* If they want only this directory, then $dir should end without a trailing / */
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'checksubdirs' ] && ereg ( " ^ $dir / " , $record [ 'directory' ]))
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
reset ( $this -> attributes );
while ( list ( $num , $attribute ) = each ( $this -> attributes ))
{
2002-01-16 07:36:51 +01:00
if ( $attribute == 'mime_type' && ! $record [ $attribute ])
2001-12-15 05:24:37 +01:00
{
2001-12-20 03:38:02 +01:00
$db2 = $GLOBALS [ 'phpgw' ] -> db ;
2002-01-16 07:36:51 +01:00
$record [ $attribute ] = $this -> get_ext_mime_type ( array (
'string' => $p -> fake_name_clean
)
);
2001-12-15 05:24:37 +01:00
if ( $record [ $attribute ])
{
2002-01-16 07:36:51 +01:00
$db2 -> query ( " UPDATE phpgw_vfs SET mime_type=' " . $record [ $attribute ] . " ' WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-15 05:24:37 +01:00
}
}
2002-01-16 07:36:51 +01:00
2001-08-11 11:01:47 +02:00
$rarray [ $i ][ $attribute ] = $record [ $attribute ];
}
2001-07-10 23:35:23 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return $rarray ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function dir
@ abstract shortcut to ls
*/
2002-01-16 07:36:51 +01:00
function dir ( $data )
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
return $this -> ls ( $data );
2001-08-11 11:01:47 +02:00
}
2001-08-28 10:13:35 +02:00
/*!
@ function command_line
@ abstract Process and run a Unix - sytle command line
@ discussion EXPERIMENTAL . DANGEROUS . DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ' RE DOING !
This is mostly working , but the command parser needs to be improved to take
files with spaces into consideration ( those should be in " " ) .
2002-01-16 07:36:51 +01:00
@ param command_line Unix - style command line with one of the commands in the $args array
2001-08-28 10:13:35 +02:00
@ result $result The return value of the actual VFS call
*/
2002-01-16 07:36:51 +01:00
function command_line ( $data )
2001-08-28 10:13:35 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
{
$data = array ();
}
2001-08-28 10:13:35 +02:00
$args = array
(
array ( 'name' => 'mv' , 'params' => 2 ),
array ( 'name' => 'cp' , 'params' => 2 ),
array ( 'name' => 'rm' , 'params' => 1 ),
array ( 'name' => 'ls' , 'params' => - 1 ),
array ( 'name' => 'du' , 'params' => 1 , 'func' => get_size ),
array ( 'name' => 'cd' , 'params' => 1 ),
array ( 'name' => 'pwd' , 'params' => 0 ),
array ( 'name' => 'cat' , 'params' => 1 , 'func' => read ),
array ( 'name' => 'file' , 'params' => 1 , 'func' => file_type ),
array ( 'name' => 'mkdir' , 'params' => 1 ),
array ( 'name' => 'touch' , 'params' => 1 )
);
2002-01-16 07:36:51 +01:00
if ( ! $first_space = strpos ( $data [ 'command_line' ], ' ' ))
2001-08-28 10:13:35 +02:00
{
2002-01-16 07:36:51 +01:00
$first_space = strlen ( $data [ 'command_line' ]);
2001-08-28 10:13:35 +02:00
}
2002-01-16 07:36:51 +01:00
if (( ! $last_space = strrpos ( $data [ 'command_line' ], ' ' )) || ( $last_space == $first_space ))
2001-08-28 10:13:35 +02:00
{
2002-01-16 07:36:51 +01:00
$last_space = strlen ( $data [ 'command_line' ]) + 1 ;
2001-08-28 10:13:35 +02:00
}
2002-01-16 07:36:51 +01:00
$argv [ 0 ] = substr ( $data [ 'command_line' ], 0 , $first_space );
if ( strlen ( $argv [ 0 ]) != strlen ( $data [ 'command_line' ]))
2001-08-28 10:13:35 +02:00
{
2002-01-16 07:36:51 +01:00
$argv [ 1 ] = substr ( $data [ 'command_line' ], $first_space + 1 , $last_space - ( $first_space + 1 ));
if (( strlen ( $argv [ 0 ]) + 1 + strlen ( $argv [ 1 ])) != strlen ( $data [ 'command_line' ]))
2001-08-28 10:13:35 +02:00
{
2002-01-16 07:36:51 +01:00
$argv [ 2 ] = substr ( $data [ 'command_line' ], $last_space + 1 );
2001-08-28 10:13:35 +02:00
}
}
$argc = count ( $argv );
reset ( $args );
while ( list (, $arg_info ) = each ( $args ))
{
if ( $arg_info [ 'name' ] == $argv [ 0 ])
{
$command_ok = 1 ;
if (( $argc == ( $arg_info [ 'params' ] + 1 )) || ( $arg_info [ 'params' ] == - 1 ))
{
$param_count_ok = 1 ;
}
break ;
}
}
if ( ! $command_ok )
{
// return E_VFS_BAD_COMMAND;
return False ;
}
if ( ! $param_count_ok )
{
// return E_VFS_BAD_PARAM_COUNT;
return False ;
}
for ( $i = 1 ; $i != ( $arg_info [ 'params' ] + 1 ); $i ++ )
{
if ( substr ( $argv [ $i ], 0 , 1 ) == " / " )
{
$relatives [] = RELATIVE_NONE ;
}
else
{
$relatives [] = RELATIVE_ALL ;
}
}
$func = $arg_info [ 'func' ] ? $arg_info [ 'func' ] : $arg_info [ 'name' ];
if ( ! $argv [ 2 ])
{
2002-01-16 07:36:51 +01:00
$rv = $this -> $func ( array (
'string' => $argv [ 1 ],
'relatives' => $relatives
)
);
2001-08-28 10:13:35 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
$rv = $this -> $func ( array (
'from' => $argv [ 1 ],
'to' => $argv [ 2 ],
'relatives' => $relatives
)
);
2001-08-28 10:13:35 +02:00
}
return ( $rv );
}
2001-08-11 11:01:47 +02:00
/*!
@ function update_real
2002-01-16 07:36:51 +01:00
@ abstract Update database information for file or directory 'string'
@ param string File or directory to update database information for
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
*/
2002-01-16 07:36:51 +01:00
function update_real ( $data )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( file_exists ( $p -> real_full_path ))
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
if ( is_dir ( $p -> real_full_path ))
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
$dir_handle = opendir ( $p -> real_full_path );
while ( $filename = readdir ( $dir_handle ))
2001-07-13 07:12:18 +02:00
{
2001-09-28 22:41:36 +02:00
if ( $filename == '.' || $filename == '..' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$rarray [] = $this -> get_real_info ( array (
'string' => $p -> fake_full_path . '/' . $filename ,
'relatives' => array ( RELATIVE_NONE )
)
);
2001-07-13 07:12:18 +02:00
}
}
2001-08-11 11:01:47 +02:00
else
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
$rarray [] = $this -> get_real_info ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( RELATIVE_NONE )
)
);
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-24 09:44:43 +02:00
if ( ! is_array ( $rarray ))
{
$rarray = array ();
}
2001-08-11 11:01:47 +02:00
while ( list ( $num , $file_array ) = each ( $rarray ))
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
$p2 = $this -> path_parts ( array (
'string' => $file_array [ 'directory' ] . '/' . $file_array [ 'name' ],
'relatives' => array ( RELATIVE_NONE )
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Note the mime_type. This can be "Directory", which is how we create directories */
2002-01-07 11:50:42 +01:00
$set_attributes_array = Array (
'size' => $file_array [ 'size' ],
'mime_type' => $file_array [ 'mime_type' ]
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $p2 -> fake_full_path ,
'relatives' => array ( RELATIVE_NONE )
))
)
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> touch ( array (
'string' => $p2 -> fake_full_path ,
'relatives' => array ( RELATIVE_NONE )
)
);
$this -> set_attributes ( array (
'string' => $p2 -> fake_full_path ,
'relatives' => array ( RELATIVE_NONE ),
'attributes' => $set_attributes_array
)
);
}
else
{
$this -> set_attributes ( array (
'string' => $p2 -> fake_full_path ,
'relatives' => array ( RELATIVE_NONE ),
'attributes' => $set_attributes_array
)
);
2001-08-11 11:01:47 +02:00
}
2001-07-13 07:12:18 +02:00
}
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Helper functions */
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
function default_values ( $data , $default_values )
{
for ( $i = 0 ; list ( $key , $value ) = each ( $default_values ); $i ++ )
{
if ( ! isset ( $data [ $key ]))
{
$data [ $key ] = $value ;
}
}
return $data ;
}
2001-08-11 11:01:47 +02:00
/* This fetchs all available file system information for $string (not using the database) */
2002-01-16 07:36:51 +01:00
function get_real_info ( $data )
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( is_dir ( $p -> real_full_path ))
{
2001-09-28 22:41:36 +02:00
$mime_type = 'Directory' ;
2001-08-11 11:01:47 +02:00
}
2001-12-15 05:24:37 +01:00
else
{
2002-01-16 07:36:51 +01:00
$mime_type = $this -> get_ext_mime_type ( array (
'string' => $p -> fake_name
)
);
2001-12-15 05:24:37 +01:00
if ( $mime_type )
{
2002-01-16 07:36:51 +01:00
$GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET mime_type=' " . $mime_type . " ' WHERE directory=' " . $p -> fake_leading_dirs_clean . " ' AND name=' " . $p -> fake_name_clean . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-15 05:24:37 +01:00
}
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$size = filesize ( $p -> real_full_path );
2001-09-28 22:41:36 +02:00
$rarray = array (
'directory' => $p -> fake_leading_dirs ,
'name' => $p -> fake_name ,
2002-01-16 07:36:51 +01:00
'size' => $size ,
2001-09-28 22:41:36 +02:00
'mime_type' => $mime_type
);
2001-08-11 11:01:47 +02:00
return ( $rarray );
2001-07-13 07:12:18 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
?>