1) phpgw --> egw

2) fixed problem I came across while debuging: $p->fake_full_name --> $p->fake_full_path
3) some improvement dont set empty mime_type
This commit is contained in:
Ralf Becker 2005-07-22 17:59:09 +00:00
parent 7b1229e29a
commit 5cbbbb7d29
3 changed files with 994 additions and 1040 deletions

View File

@ -1,31 +1,31 @@
<?php <?php
/**************************************************************************\ /**************************************************************************\
* eGroupWare API - VFS base class * * eGroupWare API - VFS base class *
* This file written by Jason Wies (Zone) <zone@phpgroupware.org> * * This file written by Jason Wies (Zone) <zone@phpgroupware.org> *
* This class handles file/dir access for eGroupWare * * This class handles file/dir access for eGroupWare *
* Copyright (C) 2001 Jason Wies * * Copyright (C) 2001 Jason Wies *
* -------------------------------------------------------------------------* * -------------------------------------------------------------------------*
* This library is part of the eGroupWare API * * This library is part of the eGroupWare API *
* http://www.egroupware.org/api * * http://www.egroupware.org/api *
* ------------------------------------------------------------------------ * * ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it * * 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 * * under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, * * the Free Software Foundation; either version 2.1 of the License, *
* or any later version. * * or any later version. *
* This library is distributed in the hope that it will be useful, but * * This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of * * WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. * * See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License * * 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, * * along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/ \**************************************************************************/
/* $Id$ */ /* $Id$ */
if (empty ($GLOBALS['phpgw_info']['server']['file_repository'])) if (empty ($GLOBALS['egw_info']['server']['file_repository']))
{ {
$GLOBALS['phpgw_info']['server']['file_repository'] = 'sql'; $GLOBALS['egw_info']['server']['file_repository'] = 'sql';
} }
/* Relative defines. Used mainly by getabsolutepath () */ /* Relative defines. Used mainly by getabsolutepath () */
@ -47,10 +47,10 @@
define ('VFS_OPERATION_MOVED', 16); define ('VFS_OPERATION_MOVED', 16);
define ('VFS_OPERATION_DELETED', 32); define ('VFS_OPERATION_DELETED', 32);
/*! /**
* @class path_class * * helper class for path_parts
* @abstract helper class for path_parts * *
*/ */
class path_class class path_class
{ {
var $mask; var $mask;
@ -73,11 +73,11 @@
var $real_name_clean; var $real_name_clean;
} }
/*! /**
* @class vfs_shared * * Base class for Virtual File System classes
* @abstract Base class for Virtual File System classes * *
* @author Zone * * @author Zone
*/ */
class vfs_shared class vfs_shared
{ {
/* /*
@ -142,12 +142,12 @@
'version', /* Version of file. May be 0 */ 'version', /* Version of file. May be 0 */
); );
/*! /**
* @function vfs_shared * * constructor
* @abstract constructor * *
* @description All derived classes should call this function in their * * All derived classes should call this function in their
* constructor ($this->vfs_shared()) * constructor ($this->vfs_shared())
*/ */
function vfs_shared () function vfs_shared ()
{ {
} }
@ -185,16 +185,16 @@
function add_journal ($data) {} function add_journal ($data) {}
function flush_journal ($data) {} function flush_journal ($data) {}
/*! /**
* @function get_journal * * Get journal entries for a location
* @abstract Get journal entries for a location * *
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @optional type [0|1|2] * * type [0|1|2]
* 0 = any journal entries * 0 = any journal entries
* 1 = current journal entries * 1 = current journal entries
* 2 = deleted journal entries * 2 = deleted journal entries
* @result Array of arrays of journal entries * * @return Array of arrays of journal entries
* The keys will vary depending on the implementation, * The keys will vary depending on the implementation,
* with most attributes in this->attributes being valid, * with most attributes in this->attributes being valid,
* and these keys being mandatory: * and these keys being mandatory:
@ -203,7 +203,7 @@
* comment - Human readable comment describing the action * comment - Human readable comment describing the action
* version - May be 0 if the derived class does not support * version - May be 0 if the derived class does not support
* versioning * versioning
*/ */
function get_journal ($data) { return array(array()); } function get_journal ($data) { return array(array()); }
/* /*
@ -222,24 +222,24 @@
* acl_check() - Check access for a user to a given * acl_check() - Check access for a user to a given
*/ */
/*! /**
* @function acl_check * * Check access for a user to a given location
* @abstract Check access for a user to a given location * *
* @discussion If $this->override_acl is set, always return True * * If $this->override_acl is set, always return True
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @required operation Operation to check access for. Any combination * * operation Operation to check access for. Any combination
* of the PHPGW_ACL_* defines, for example: * of the EGW_ACL_* defines, for example:
* PHPGW_ACL_READ * EGW_ACL_READ
* PHPGW_ACL_READ|PHPGW_ACL_WRITE * EGW_ACL_READ|EGW_ACL_WRITE
* @optional owner_id phpGW ID to check access for. * * owner_id phpGW ID to check access for.
* Default: $GLOBALS['phpgw_info']['user']['account_id'] * * Default: $GLOBALS['egw_info']['user']['account_id']
* @optional must_exist If set, string must exist, and acl_check() must * * must_exist If set, string must exist, and acl_check() must
* return False if it doesn't. If must_exist isn't * return False if it doesn't. If must_exist isn't
* passed, and string doesn't exist, check the owner_id's * passed, and string doesn't exist, check the owner_id's
* access to the parent directory, if it exists. * access to the parent directory, if it exists.
* @result Boolean. True if access is ok, False otherwise. * * @return Boolean. True if access is ok, False otherwise.
*/ */
function acl_check ($data) { return True; } function acl_check ($data) { return True; }
/* /*
@ -267,26 +267,26 @@
* mkdir - Create directory * mkdir - Create directory
*/ */
/*! /**
* @function read * * Retreive file contents
* @abstract Retreive file contents * *
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @result String. Contents of 'string', or False on error. * * @return String. Contents of 'string', or False on error.
*/ */
function read ($data) { return False; } function read ($data) { return False; }
/*! /**
@function view * Views the specified file (does not return!)
@abstract Views the specified file (does not return!) *
@param string filename * @param string filename
@param relatives Relativity array * @param relatives Relativity array
@result None (doesnt return) * @return None (doesnt return)
@discussion By default this function just reads the file and * By default this function just reads the file and
outputs it too the browser, after setting the content-type header * outputs it too the browser, after setting the content-type header
appropriately. For some other VFS implementations though, there * appropriately. For some other VFS implementations though, there
may be some more sensible way of viewing the file. * may be some more sensible way of viewing the file.
*/ */
function view($data) function view($data)
{ {
@ -296,10 +296,10 @@
); );
$data = array_merge ($this->default_values ($data, $default_values), $data); $data = array_merge ($this->default_values ($data, $default_values), $data);
$GLOBALS['phpgw_info']['flags']['noheader'] = true; $GLOBALS['egw_info']['flags']['noheader'] = true;
$GLOBALS['phpgw_info']['flags']['nonavbar'] = true; $GLOBALS['egw_info']['flags']['nonavbar'] = true;
$GLOBALS['phpgw_info']['flags']['noappheader'] = true; $GLOBALS['egw_info']['flags']['noappheader'] = true;
$GLOBALS['phpgw_info']['flags']['noappfooter'] = true; $GLOBALS['egw_info']['flags']['noappfooter'] = true;
$ls_array = $this->ls (array ( $ls_array = $this->ls (array (
'string' => $data['string'], 'string' => $data['string'],
'relatives' => $data['relatives'], 'relatives' => $data['relatives'],
@ -326,62 +326,62 @@
exit(); exit();
} }
/*! /**
* @function write * * Store file contents
* @abstract Store file contents * *
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function write ($data) { return False; } function write ($data) { return False; }
/*! /**
* @function touch * * Create a file if it doesn't exist.
* @abstract Create a file if it doesn't exist. * *
* Optionally, update the modified time and * Optionally, update the modified time and
* modified user if the file exists. * modified user if the file exists.
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function touch ($data) { return False; } function touch ($data) { return False; }
/*! /**
* @function cp * * Copy location
* @abstract Copy location * *
* @required from Path to location to copy from * * from Path to location to copy from
* @required to Path to location to copy to * * to Path to location to copy to
* @optional relatives Relativity array (default: RELATIVE_CURRENT, RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT, RELATIVE_CURRENT)
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function cp ($data) { return False; } function cp ($data) { return False; }
/*! /**
* @function mv * * Move location
* @abstract Move location * *
* @required from Path to location to move from * * from Path to location to move from
* @required to Path to location to move to * * to Path to location to move to
* @optional relatives Relativity array (default: RELATIVE_CURRENT, RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT, RELATIVE_CURRENT)
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function mv ($data) { return False; } function mv ($data) { return False; }
/*! /**
* @function rm * * Delete location
* @abstract Delete location * *
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function rm ($data) { return False; } function rm ($data) { return False; }
/*! /**
* @function mkdir * * Create directory
* @abstract Create directory * *
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function mkdir ($data) { return False; } function mkdir ($data) { return False; }
/* /*
@ -401,56 +401,56 @@
* ls - Return detailed information for location(s) * ls - Return detailed information for location(s)
*/ */
/*! /**
* @function set_attributes * * Set attributes for a location
* @abstract Set attributes for a location * *
* @discussion Valid attributes are listed in vfs->attributes, * * Valid attributes are listed in vfs->attributes,
* which may be extended by each derived class * which may be extended by each derived class
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @optional attributes Keyed array of attributes. Key is attribute * * attributes Keyed array of attributes. Key is attribute
* name, value is attribute value. * name, value is attribute value.
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function set_attributes ($data) { return False; } function set_attributes ($data) { return False; }
/*! /**
* @function file_exists * * Check if a location (file or directory) exists
* @abstract Check if a location (file or directory) exists * *
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @result Boolean. True if file exists, False otherwise. * * @return Boolean. True if file exists, False otherwise.
*/ */
function file_exists ($data) { return False; } function file_exists ($data) { return False; }
/*! /**
* @function get_size * * Determine size of location
* @abstract Determine size of location * *
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @optional checksubdirs Boolean. If set, include the size of * * checksubdirs Boolean. If set, include the size of
* all subdirectories recursively. * all subdirectories recursively.
* @result Integer. Size of location in bytes. * * @return Integer. Size of location in bytes.
*/ */
function get_size ($data) { return 0; } function get_size ($data) { return 0; }
/*! /**
* @function ls * * Return detailed information for location(s)
* @abstract Return detailed information for location(s) * *
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @optional checksubdirs Boolean. If set, return information for all * * checksubdirs Boolean. If set, return information for all
* subdirectories recursively. * subdirectories recursively.
* @optional mime String. Only return information for locations with MIME type * * mime String. Only return information for locations with MIME type
* specified. VFS classes must recogize these special types: * specified. VFS classes must recogize these special types:
* "Directory" - Location is a directory * "Directory" - Location is a directory
* " " - Location doesn't not have a MIME type * " " - Location doesn't not have a MIME type
* @optional nofiles Boolean. If set and 'string' is a directory, return * * nofiles Boolean. If set and 'string' is a directory, return
* information about the directory, not the files in it. * information about the directory, not the files in it.
* @result Array of arrays of file information. * * @return Array of arrays of file information.
* Keys may vary depending on the implementation, but must include * Keys may vary depending on the implementation, but must include
* at least those attributes listed in $this->attributes. * at least those attributes listed in $this->attributes.
*/ */
function ls ($data) { return array(array()); } function ls ($data) { return array(array()); }
/* /*
@ -480,14 +480,14 @@
* make_link - Create a real to virtual directory link * make_link - Create a real to virtual directory link
*/ */
/*! /**
* @function make_link * * Create a real to virtual directory link
* @abstract Create a real to virtual directory link * *
* @required rdir Real directory to make link from/to * * rdir Real directory to make link from/to
* @required vdir Virtual directory to make link to/from * * vdir Virtual directory to make link to/from
* @optional relatives Relativity array (default: RELATIVE_CURRENT, RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT, RELATIVE_CURRENT)
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function make_link ($data) { return False; } function make_link ($data) { return False; }
/* /*
@ -503,46 +503,46 @@
* extract - Dearchives a file or set of files of a compressed file * extract - Dearchives a file or set of files of a compressed file
*/ */
/*! /**
* @function update_real * * Ensure that information about a location is up-to-date
* @abstract Ensure that information about a location is up-to-date * *
* @discussion Some VFS backends store information about locations * * Some VFS backends store information about locations
* in a secondary location, for example in a database * in a secondary location, for example in a database
* or in a cache file. update_real() can be called to * or in a cache file. update_real() can be called to
* ensure that the information in the secondary location * ensure that the information in the secondary location
* is up-to-date. * is up-to-date.
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function update_real ($data) { return False; } function update_real ($data) { return False; }
/*! /**
* @function compress * * Creates an archive from a file or a set of files
* @abstract Creates an archive from a file or a set of files * *
* @required files File names to be stored in archive (array) * * files File names to be stored in archive (array)
* @required name Name of archive * * name Name of archive
* @optional type The type of compression, can be 'zip'(default)or 'gz' * * type The type of compression, can be 'zip'(default)or 'gz'
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* Note: the last item is the relativity of the dest archive * * Note: the last item is the relativity of the dest archive
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function compress ($data) { return False; } function compress ($data) { return False; }
/*! /**
* @function extract * * Extracts a file (or files) from archive
* @abstract Extracts a file (or files) from archive * *
* @required name Name of archive * * name Name of archive
* @required dest The destination path of files to be extracted * * dest The destination path of files to be extracted
* @optional type The type of compression, can be 'zip' or 'gz'. If * * type The type of compression, can be 'zip' or 'gz'. If
* not specified, uses according to the extension * * not specified, uses according to the extension
* @optional files Files to be extracted from archive * * files Files to be extracted from archive
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* Note: the first item is the relativity of the archive, the last of * * Note: the first item is the relativity of the archive, the last of
* the dest dir * * the dest dir
* @result Boolean. True on success, False otherwise. * * @return Boolean. True on success, False otherwise.
*/ */
function extract ($data) { return False; } function extract ($data) { return False; }
@ -610,14 +610,14 @@
/* PRIVATE functions */ /* PRIVATE functions */
/*! /**
* @function securitycheck * * Check if location string is ok to use in VFS functions
* @abstract Check if location string is ok to use in VFS functions * *
* @discussion Checks for basic violations such as .. * * Checks for basic violations such as ..
* If securitycheck () fails, run your string through $this->sanitize () * If securitycheck () fails, run your string through $this->sanitize ()
* @required string Path to location * * string Path to location
* @result Boolean. True if string is ok, False otherwise. * * @return Boolean. True if string is ok, False otherwise.
*/ */
function securitycheck ($data) function securitycheck ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -635,17 +635,17 @@
} }
} }
/*! /**
* @function sanitize * * Remove any possible security problems from a location
* @abstract Remove any possible security problems from a location * *
* string (i.e. remove leading '..') * string (i.e. remove leading '..')
* @discussion You should not pass all filenames through sanitize () * * You should not pass all filenames through sanitize ()
* unless you plan on rejecting .files. Instead, pass * unless you plan on rejecting .files. Instead, pass
* the name through securitycheck () first, and if it fails, * the name through securitycheck () first, and if it fails,
* pass it through sanitize. * pass it through sanitize.
* @required string Path to location * * string Path to location
* @result String. 'string' with any security problems fixed. * * @return String. 'string' with any security problems fixed.
*/ */
function sanitize ($data) function sanitize ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -663,16 +663,16 @@
return (ereg_replace ("^\.+", '', $p->fake_name)); return (ereg_replace ("^\.+", '', $p->fake_name));
} }
/*! /**
* @function clean_string * * Clean location string. This function is used if
* @abstract Clean location string. This function is used if * *
* any special characters need to be escaped or removed * any special characters need to be escaped or removed
* before accessing a database, network protocol, etc. * before accessing a database, network protocol, etc.
* The default is to escape characters before doing an SQL * The default is to escape characters before doing an SQL
* query. * query.
* @required string Location string to clean * * string Location string to clean
* @result String. Cleaned version of 'string'. * * @return String. Cleaned version of 'string'.
*/ */
function clean_string ($data) function clean_string ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -680,24 +680,24 @@
$data = array (); $data = array ();
} }
$string = $GLOBALS['phpgw']->db->db_addslashes ($data['string']); $string = $GLOBALS['egw']->db->db_addslashes ($data['string']);
return $string; return $string;
} }
/*! /**
* @function getabsolutepath * * Translate a location string depending on the
* @abstract Translate a location string depending on the * *
* relativity. This is the only function that is * relativity. This is the only function that is
* directly concerned with relativity. * directly concerned with relativity.
* @optional string Path to location, relative to mask[0]. * * string Path to location, relative to mask[0].
* Defaults to empty string. * * Defaults to empty string.
* @optional mask Relativity array (default: RELATIVE_CURRENT) * * mask Relativity array (default: RELATIVE_CURRENT)
* @optional fake Boolean. If set, returns the 'fake' path, * * fake Boolean. If set, returns the 'fake' path,
* i.e. /home/user/dir/file. This is not always * i.e. /home/user/dir/file. This is not always
* possible, use path_parts() instead. * possible, use path_parts() instead.
* @result String. Full fake or real path, or False on error. * * @return String. Full fake or real path, or False on error.
*/ */
function getabsolutepath ($data) function getabsolutepath ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -780,12 +780,12 @@
if (($data['mask'][0] & RELATIVE_USER) || ($data['mask'][0] & RELATIVE_USER_APP)) if (($data['mask'][0] & RELATIVE_USER) || ($data['mask'][0] & RELATIVE_USER_APP))
{ {
$basedir = $basedir . $GLOBALS['phpgw_info']['user']['account_lid'] . $sep; $basedir = $basedir . $GLOBALS['egw_info']['user']['account_lid'] . $sep;
} }
if ($data['mask'][0] & RELATIVE_USER_APP) if ($data['mask'][0] & RELATIVE_USER_APP)
{ {
$basedir = $basedir . "." . $GLOBALS['phpgw_info']['flags']['currentapp'] . $sep; $basedir = $basedir . "." . $GLOBALS['egw_info']['flags']['currentapp'] . $sep;
} }
/* Don't add string if it's a /, just for aesthetics */ /* Don't add string if it's a /, just for aesthetics */
@ -805,14 +805,14 @@
return $basedir; return $basedir;
} }
/*! /**
* @function get_ext_mime_type * * Return MIME type based on file extension
* @abstract Return MIME type based on file extension * *
* @description Internal use only. Applications should call vfs->file_type () * * Internal use only. Applications should call vfs->file_type ()
* @author skeeter * * @author skeeter
* @required string Real path to file, with or without leading paths * * string Real path to file, with or without leading paths
* @result String. MIME type based on file extension. * * @return String. MIME type based on file extension.
*/ */
function get_ext_mime_type ($data) function get_ext_mime_type ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -821,7 +821,7 @@
} }
$file=basename($data['string']); $file=basename($data['string']);
$mimefile=PHPGW_API_INC.'/phpgw_mime.types'; $mimefile=EGW_API_INC.'/phpgw_mime.types';
$fp=fopen($mimefile,'r'); $fp=fopen($mimefile,'r');
$contents = explode("\n",fread($fp,filesize($mimefile))); $contents = explode("\n",fread($fp,filesize($mimefile)));
fclose($fp); fclose($fp);
@ -852,14 +852,14 @@
/* PUBLIC functions (mandatory) */ /* PUBLIC functions (mandatory) */
/*! /**
* @function set_relative * * Sets the current relativity, the relativity used
* @abstract Sets the current relativity, the relativity used * *
* when RELATIVE_CURRENT is passed to a function * when RELATIVE_CURRENT is passed to a function
* @optional mask Relative bitmask. If not set, relativity * * mask Relative bitmask. If not set, relativity
* will be returned to the default. * will be returned to the default.
* @result Void * * @return Void
*/ */
function set_relative ($data) function set_relative ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -877,13 +877,13 @@
} }
} }
/*! /**
* @function get_relative * * Return the current relativity
* @abstract Return the current relativity * *
* @discussion Returns relativity bitmask, or the default * * Returns relativity bitmask, or the default
* of "completely relative" if unset * of "completely relative" if unset
* @result Integer. One of the RELATIVE_* defines. * * @return Integer. One of the RELATIVE_* defines.
*/ */
function get_relative () function get_relative ()
{ {
if (isset ($this->relative) && $this->relative) if (isset ($this->relative) && $this->relative)
@ -896,19 +896,19 @@
} }
} }
/*! /**
* @function path_parts * * Return information about the component parts of a location string
* @abstract Return information about the component parts of a location string * *
* @discussion Most VFS functions call path_parts() with their 'string' and * * Most VFS functions call path_parts() with their 'string' and
* 'relatives' arguments before doing their work, in order to * 'relatives' arguments before doing their work, in order to
* determine the file/directory to work on. * determine the file/directory to work on.
* @required string Path to location * * string Path to location
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
* @optional object If set, return an object instead of an array * * object If set, return an object instead of an array
* @optional nolinks Don't check for linked directories (made with * * nolinks Don't check for linked directories (made with
* make_link()). Used internally to prevent recursion. * make_link()). Used internally to prevent recursion.
* @result Array or object. Contains the fake and real component parts of the path. * * @return Array or object. Contains the fake and real component parts of the path.
* @discussion Returned values are: * * Returned values are:
* mask * mask
* outside * outside
* fake_full_path * fake_full_path
@ -934,7 +934,7 @@
* mask is either RELATIVE_NONE or RELATIVE_NONE|VFS_REAL, * mask is either RELATIVE_NONE or RELATIVE_NONE|VFS_REAL,
* and is used internally * and is used internally
* outside is boolean, True if 'relatives' contains VFS_REAL * outside is boolean, True if 'relatives' contains VFS_REAL
*/ */
function path_parts ($data) function path_parts ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -1084,8 +1084,8 @@
} }
/* /*
We have to count it before because new keys will be added, We have to count it before because new keys will be added,
which would create an endless loop which would create an endless loop
*/ */
$count = count ($rarray); $count = count ($rarray);
reset ($rarray); reset ($rarray);
@ -1096,7 +1096,7 @@
if ($data['object']) if ($data['object'])
{ {
$robject = new path_class; $robject =& new path_class;
reset ($rarray); reset ($rarray);
while (list ($key, $value) = each ($rarray)) while (list ($key, $value) = each ($rarray))
@ -1126,23 +1126,23 @@
} }
} }
/*! /**
* @function cd * * Change current directory. This function is used to store the
* @abstract Change current directory. This function is used to store the * *
* current directory in a standard way, so that it may be accessed * current directory in a standard way, so that it may be accessed
* throughout phpGroupWare to provide a consistent view for the user. * throughout phpGroupWare to provide a consistent view for the user.
* @discussion To cd to the root '/', use: * * To cd to the root '/', use:
* cd (array( * cd (array(
* 'string' => '/', * 'string' => '/',
* 'relative' => False, * 'relative' => False,
* 'relatives' => array (RELATIVE_NONE) * 'relatives' => array (RELATIVE_NONE)
* )); * ));
* @optional string Directory location to cd into. Default is '/'. * * string Directory location to cd into. Default is '/'.
* @optional relative If set, add target to current path. * * relative If set, add target to current path.
* Else, pass 'relative' as mask to getabsolutepath() * Else, pass 'relative' as mask to getabsolutepath()
* Default is True. * Default is True.
* @optional relatives Relativity array (default: RELATIVE_CURRENT) * * relatives Relativity array (default: RELATIVE_CURRENT)
*/ */
function cd ($data = '') function cd ($data = '')
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -1184,7 +1184,7 @@
} }
else else
{ {
$currentdir = $GLOBALS['phpgw']->session->appsession('vfs',''); $currentdir = $GLOBALS['egw']->session->appsession('vfs','');
$basedir = $this->getabsolutepath (array( $basedir = $this->getabsolutepath (array(
'string' => $currentdir . $sep . $data['string'], 'string' => $currentdir . $sep . $data['string'],
'mask' => array ($data['relatives'][0]), 'mask' => array ($data['relatives'][0]),
@ -1202,19 +1202,19 @@
); );
} }
$GLOBALS['phpgw']->session->appsession('vfs','',$basedir); $GLOBALS['egw']->session->appsession('vfs','',$basedir);
return True; return True;
} }
/*! /**
* @function pwd * * Return current directory
* @abstract Return current directory * *
* @optional full If set, return full fake path, else just * * full If set, return full fake path, else just
* the extra dirs (False strips the leading /). * the extra dirs (False strips the leading /).
* Default is True. * Default is True.
* @result String. The current directory. * * @return String. The current directory.
*/ */
function pwd ($data = '') function pwd ($data = '')
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -1229,7 +1229,7 @@
$data = array_merge ($this->default_values ($data, $default_values), $data); $data = array_merge ($this->default_values ($data, $default_values), $data);
$currentdir = $GLOBALS['phpgw']->session->appsession('vfs',''); $currentdir = $GLOBALS['egw']->session->appsession('vfs','');
if (!$data['full']) if (!$data['full'])
{ {
@ -1246,54 +1246,54 @@
return $currentdir; return $currentdir;
} }
/*! /**
* @function copy * * shortcut to cp
* @abstract shortcut to cp * *
*/ */
function copy ($data) function copy ($data)
{ {
return $this->cp ($data); return $this->cp ($data);
} }
/*! /**
* @function move * * shortcut to mv
* @abstract shortcut to mv * *
*/ */
function move ($data) function move ($data)
{ {
return $this->mv ($data); return $this->mv ($data);
} }
/*! /**
* @function delete * * shortcut to rm
* @abstract shortcut to rm * *
*/ */
function delete ($data) function delete ($data)
{ {
return $this->rm ($data); return $this->rm ($data);
} }
/*! /**
* @function dir * * shortcut to ls
* @abstract shortcut to ls * *
*/ */
function dir ($data) function dir ($data)
{ {
return $this->ls ($data); return $this->ls ($data);
} }
/*! /**
* @function command_line * * Process and run a Unix-sytle command line
* @abstract Process and run a Unix-sytle command line * *
* @discussion EXPERIMENTAL. DANGEROUS. DO NOT USE THIS UNLESS YOU * * EXPERIMENTAL. DANGEROUS. DO NOT USE THIS UNLESS YOU
* KNOW WHAT YOU'RE DOING! * KNOW WHAT YOU'RE DOING!
* This is mostly working, but the command parser needs * * This is mostly working, but the command parser needs
* to be improved to take files with spaces into * to be improved to take files with spaces into
* consideration (those should be in ""). * consideration (those should be in "").
* @required command_line Unix-style command line with one of the * * command_line Unix-style command line with one of the
* commands in the $args array * commands in the $args array
* @result The return value of the actual VFS call * * @return The return value of the actual VFS call
*/ */
function command_line ($data) function command_line ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -1412,4 +1412,4 @@
} }
include (PHPGW_API_INC . '/class.vfs_' . $GLOBALS['phpgw_info']['server']['file_repository'] . '.inc.php'); include (EGW_API_INC . '/class.vfs_' . $GLOBALS['egw_info']['server']['file_repository'] . '.inc.php');

File diff suppressed because it is too large Load Diff

View File

@ -1,33 +1,33 @@
<?php <?php
/**************************************************************************\ /**************************************************************************\
* eGroupWare API - VFS * * eGroupWare API - VFS *
* This file written by Jason Wies (Zone) <zone@phpgroupware.org> * * This file written by Jason Wies (Zone) <zone@phpgroupware.org> *
* This class handles file/dir access for eGroupWare * * This class handles file/dir access for eGroupWare *
* Copyright (C) 2001 Jason Wies * * Copyright (C) 2001 Jason Wies *
* Database layer reworked 2005/09/20 by RalfBecker-AT-outdoor-training.de * * Database layer reworked 2005/09/20 by RalfBecker-AT-outdoor-training.de *
* -------------------------------------------------------------------------* * -------------------------------------------------------------------------*
* This library is part of the eGroupWare API * * This library is part of the eGroupWare API *
* ------------------------------------------------------------------------ * * ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it * * 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 * * under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, * * the Free Software Foundation; either version 2.1 of the License, *
* or any later version. * * or any later version. *
* This library is distributed in the hope that it will be useful, but * * This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of * * WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. * * See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License * * 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, * * along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/ \**************************************************************************/
/* $Id$ */ /* $Id$ */
/*! /**
@class vfs * Virtual File System with SQL backend
@abstract Virtual File System with SQL backend *
@description Authors: Zone * Authors: Zone
*/ */
/* These are used in calls to extra_sql () */ /* These are used in calls to extra_sql () */
define ('VFS_SQL_SELECT', 1); define ('VFS_SQL_SELECT', 1);
@ -44,24 +44,24 @@
var $vfs_table = 'egw_vfs'; var $vfs_table = 'egw_vfs';
var $vfs_column_prefix = 'vfs_'; var $vfs_column_prefix = 'vfs_';
/*! /**
@function vfs * constructor, sets up variables
@abstract constructor, sets up variables *
*/ */
function vfs () function vfs ()
{ {
$this->vfs_shared (); $this->vfs_shared ();
$this->basedir = $GLOBALS['phpgw_info']['server']['files_dir']; $this->basedir = $GLOBALS['egw_info']['server']['files_dir'];
$this->working_id = $GLOBALS['phpgw_info']['user']['account_id']; $this->working_id = $GLOBALS['egw_info']['user']['account_id'];
$this->working_lid = $GLOBALS['phpgw_info']['user']['account_lid']; $this->working_lid = $GLOBALS['egw_info']['user']['account_lid'];
$this->now = date ('Y-m-d'); $this->now = date ('Y-m-d');
/* /*
File/dir attributes, each corresponding to a database field. Useful for use in loops 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 If an attribute was added to the table, add it here and possibly add it to
set_attributes () set_attributes ()
set_attributes now uses this array(). 07-Dec-01 skeeter set_attributes now uses this array(). 07-Dec-01 skeeter
*/ */
$this->attributes[] = 'deleteable'; $this->attributes[] = 'deleteable';
@ -74,34 +74,34 @@
$this->attributes[$this->vfs_column_prefix.$attr] = $attr; $this->attributes[$this->vfs_column_prefix.$attr] = $attr;
} }
/* /*
Decide whether to use any actual filesystem calls (fopen(), fread(), Decide whether to use any actual filesystem calls (fopen(), fread(),
unlink(), rmdir(), touch(), etc.). If not, then we're working completely unlink(), rmdir(), touch(), etc.). If not, then we're working completely
in the database. in the database.
*/ */
$this->file_actions = $GLOBALS['phpgw_info']['server']['file_store_contents'] == 'filesystem' || $this->file_actions = $GLOBALS['egw_info']['server']['file_store_contents'] == 'filesystem' ||
!$GLOBALS['phpgw_info']['server']['file_store_contents']; !$GLOBALS['egw_info']['server']['file_store_contents'];
// test if the files-dir is inside the document-root, and refuse working if so // test if the files-dir is inside the document-root, and refuse working if so
// //
if ($this->file_actions && $this->in_docroot($this->basedir)) if ($this->file_actions && $this->in_docroot($this->basedir))
{ {
$GLOBALS['phpgw']->common->phpgw_header(); $GLOBALS['egw']->common->egw_header();
if ($GLOBALS['phpgw_info']['flags']['noheader']) if ($GLOBALS['egw_info']['flags']['noheader'])
{ {
echo parse_navbar(); echo parse_navbar();
} }
echo '<p align="center"><font color="red"><b>'.lang('Path to user and group files HAS TO BE OUTSIDE of the webservers document-root!!!')."</b></font></p>\n"; echo '<p align="center"><font color="red"><b>'.lang('Path to user and group files HAS TO BE OUTSIDE of the webservers document-root!!!')."</b></font></p>\n";
$GLOBALS['phpgw']->common->phpgw_exit(); $GLOBALS['egw']->common->egw_exit();
} }
/* /*
These are stored in the MIME-type field and should normally be ignored. 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 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 explicitly add it to acl_check (), and to any other SELECT's in this file
*/ */
$this->meta_types = array ('journal', 'journal-deleted'); $this->meta_types = array ('journal', 'journal-deleted');
$this->db = clone($GLOBALS['phpgw']->db); $this->db = clone($GLOBALS['egw']->db);
$this->db->set_app('phpgwapi'); $this->db->set_app('phpgwapi');
/* We store the linked directories in an array now, so we don't have to make the SQL call again */ /* We store the linked directories in an array now, so we don't have to make the SQL call again */
@ -137,13 +137,13 @@
$this->grants = $GLOBALS['egw']->acl->get_grants('filemanager'); $this->grants = $GLOBALS['egw']->acl->get_grants('filemanager');
} }
/*! /**
@function in_docroot * test if $path lies within the webservers document-root
@abstract test if $path lies within the webservers document-root *
*/ */
function in_docroot($path) function in_docroot($path)
{ {
$docroots = array(PHPGW_SERVER_ROOT,$_SERVER['DOCUMENT_ROOT']); $docroots = array(EGW_SERVER_ROOT,$_SERVER['DOCUMENT_ROOT']);
foreach ($docroots as $docroot) foreach ($docroots as $docroot)
{ {
@ -162,12 +162,12 @@
return False; return False;
} }
/*! /**
@function extra_sql * Return extra SQL code that should be appended (AND'ed) to certain queries
@abstract Return extra SQL code that should be appended (AND'ed) to certain queries *
@param query_type The type of query to get extra SQL code for, in the form of a VFS_SQL define * @param query_type The type of query to get extra SQL code for, in the form of a VFS_SQL define
@result Extra SQL code * @return Extra SQL code
*/ */
function extra_sql ($data) function extra_sql ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -182,31 +182,31 @@
return ''; return '';
} }
/*! /**
@function add_journal * Add a journal entry after (or before) completing an operation,
@abstract Add a journal entry after (or before) completing an operation, *
and increment the version number. This function should be used internally only * * and increment the version number. This function should be used internally only
@discussion Note that state_one and state_two are ignored for some VFS_OPERATION's, for others * Note that state_one and state_two are ignored for some VFS_OPERATION's, for others
they are required. They are ignored for any "custom" operation * * they are required. They are ignored for any "custom" operation
The two operations that require state_two: * * The two operations that require state_two:
operation state_two * * operation * state_two
VFS_OPERATION_COPIED fake_full_path of copied to * * VFS_OPERATION_COPIED fake_full_path of copied to
VFS_OPERATION_MOVED fake_full_path of moved to * * VFS_OPERATION_MOVED * fake_full_path of moved to
If deleting, you must call add_journal () before you delete the entry from the database * * If deleting, you must call add_journal () before you delete the entry from the database
@param string File or directory to add entry for * @param string File or directory to add entry for
@param relatives Relativity array * @param relatives Relativity array
@param operation The operation that was performed. Either a VFS_OPERATION define or * @param operation The operation that was performed. Either a VFS_OPERATION define or
a non-integer descriptive text string * * a non-integer descriptive text string
@param state_one The first "state" of the file or directory. Can be a file name, size, * @param state_one The first "state" of the file or directory. Can be a file name, size,
location, whatever is appropriate for the specific operation * * location, whatever is appropriate for the specific operation
@param state_two The second "state" of the file or directory * @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 * @param incversion Boolean True/False. Increment the version for the file? Note that this is
handled automatically for the VFS_OPERATION defines. * * handled automatically for the VFS_OPERATION defines.
i.e. VFS_OPERATION_EDITED would increment the version, VFS_OPERATION_COPIED * * i.e. VFS_OPERATION_EDITED would increment the version, VFS_OPERATION_COPIED
would not * * would not
@result Boolean True/False * @return Boolean True/False
*/ */
function add_journal ($data) function add_journal ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -224,14 +224,14 @@
$data = array_merge ($this->default_values ($data, $default_values), $data); $data = array_merge ($this->default_values ($data, $default_values), $data);
$account_id = $GLOBALS['phpgw_info']['user']['account_id']; $account_id = $GLOBALS['egw_info']['user']['account_id'];
$p = $this->path_parts (array ('string' => $data['string'], 'relatives' => array ($data['relatives'][0]))); $p = $this->path_parts (array ('string' => $data['string'], 'relatives' => array ($data['relatives'][0])));
/* We check that they have some sort of access to the file other than read */ /* We check that they have some sort of access to the file other than read */
if (!$this->acl_check (array ('string' => $p->fake_full_path, 'relatives' => array ($p->mask), 'operation' => PHPGW_ACL_WRITE)) && if (!$this->acl_check (array ('string' => $p->fake_full_path, 'relatives' => array ($p->mask), 'operation' => EGW_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' => EGW_ACL_EDIT)) &&
!$this->acl_check (array ('string' => $p->fake_full_path, 'relatives' => array ($p->mask), 'operation' => PHPGW_ACL_DELETE))) !$this->acl_check (array ('string' => $p->fake_full_path, 'relatives' => array ($p->mask), 'operation' => EGW_ACL_DELETE)))
{ {
return False; return False;
} }
@ -330,10 +330,10 @@
} }
/* /*
Let's increment the version for the file itself. We keep the current 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 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: was operated on. The maximum numbers for each part in the version string:
none.99.9.9 none.99.9.9
*/ */
if ($attribute == 'version' && $data['incversion']) if ($attribute == 'version' && $data['incversion'])
{ {
@ -394,9 +394,9 @@
} }
} }
/* /*
These are some special situations where we need to flush the journal entries 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 or move the 'journal' entries to 'journal-deleted'. Kind of hackish, but they
provide a consistent feel to the system provide a consistent feel to the system
*/ */
if ($data['operation'] == VFS_OPERATION_CREATED) if ($data['operation'] == VFS_OPERATION_CREATED)
{ {
@ -429,8 +429,8 @@
if ($data['operation'] == VFS_OPERATION_COPIED) if ($data['operation'] == VFS_OPERATION_COPIED)
{ {
/* /*
We copy it going the other way as well, so both files show the operation. 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 The code is a bad hack to prevent recursion. Ideally it would use VFS_OPERATION_COPIED
*/ */
$this->add_journal (array( $this->add_journal (array(
'string' => $data['state_two'], 'string' => $data['state_two'],
@ -458,8 +458,8 @@
),__LINE__,__FILE__); ),__LINE__,__FILE__);
/* /*
We create the file in addition to logging the MOVED operation. This is an 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 advantage because we can now search for 'Create' to see when a file was created
*/ */
$this->add_journal (array( $this->add_journal (array(
'string' => $data['state_two'], 'string' => $data['state_two'],
@ -473,8 +473,8 @@
$this->db->insert($this->vfs_table,$to_write,false, __LINE__, __FILE__); $this->db->insert($this->vfs_table,$to_write,false, __LINE__, __FILE__);
/* /*
If we were to add an option of whether to keep journal entries for deleted files 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 or not, it would go in the if here
*/ */
if ($data['operation'] == VFS_OPERATION_DELETED) if ($data['operation'] == VFS_OPERATION_DELETED)
{ {
@ -490,18 +490,18 @@
return True; return True;
} }
/*! /**
@function flush_journal * Flush journal entries for $string. Used before adding $string
@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 * flush_journal () is an internal function and should be called from add_journal () only
@param string File/directory to flush journal entries of * @param string File/directory to flush journal entries of
@param relatives Realtivity array * @param relatives Realtivity array
@param deleteall Delete all types of journal entries, including the active Create entry. * @param deleteall Delete all types of journal entries, including the active Create entry.
Normally you only want to delete the Create entry when replacing the file * * Normally you only want to delete the Create entry when replacing the file
Note that this option does not effect $deleteonly * * Note that this option does not effect $deleteonly
@param deletedonly Only flush 'journal-deleted' entries (created when $string was deleted) * @param deletedonly Only flush 'journal-deleted' entries (created when $string was deleted)
@result Boolean True/False * @return Boolean True/False
*/ */
function flush_journal ($data) function flush_journal ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -611,7 +611,7 @@
$default_values = array $default_values = array
( (
'relatives' => array (RELATIVE_CURRENT), 'relatives' => array (RELATIVE_CURRENT),
'operation' => PHPGW_ACL_READ, 'operation' => EGW_ACL_READ,
'must_exist' => False 'must_exist' => False
); );
@ -640,7 +640,7 @@
/* Read access is always allowed here, but nothing else is */ /* Read access is always allowed here, but nothing else is */
if ($data['string'] == '/' || $data['string'] == $this->fakebase) if ($data['string'] == '/' || $data['string'] == $this->fakebase)
{ {
if ($data['operation'] == PHPGW_ACL_READ) if ($data['operation'] == EGW_ACL_READ)
{ {
return True; return True;
} }
@ -685,8 +685,8 @@
} }
/* /*
We don't use ls () to get owner_id as we normally would, We don't use ls () to get owner_id as we normally would,
because ls () calls acl_check (), which would create an infinite loop because ls () calls acl_check (), which would create an infinite loop
*/ */
$this->db->select($this->vfs_table,'vfs_owner_id',array( $this->db->select($this->vfs_table,'vfs_owner_id',array(
'vfs_directory' => $p2->fake_leading_dirs, 'vfs_directory' => $p2->fake_leading_dirs,
@ -709,44 +709,13 @@
$owner_id = 0; $owner_id = 0;
} }
$user_id = $GLOBALS['phpgw_info']['user']['account_id']; $user_id = $GLOBALS['egw_info']['user']['account_id'];
//echo "user=$user_id, "; //echo "user=$user_id, ";
/* They always have access to their own files */ /* They always have access to their own files */
if ($owner_id == $user_id) if ($owner_id == $user_id)
{ {
return True; return True;
} }
/* RalfBecker 2005/03/07 using ACL standard function acl::get_grants() now
// Check if they're in the group
$memberships = $GLOBALS['phpgw']->accounts->membership ($user_id);
if (is_array ($memberships))
{
foreach ($memberships as $group_array)
{
if ($owner_id == $group_array['account_id'])
{
$group_ok = 1;
break;
}
}
}
$acl = CreateObject ('phpgwapi.acl', $owner_id);
$acl->account_id = $owner_id;
$acl->read_repository ();
$rights = $acl->get_rights ($user_id);
// Add privileges from the groups this user belongs to
if (is_array ($memberships))
{
foreach ($memberships as $group_array)
{
$rights |= $acl->get_rights ($group_array['account_id']);
}
}
*/
$rights = $this->grants[$owner_id]; $rights = $this->grants[$owner_id];
//echo "rights=$rights, "; //echo "rights=$rights, ";
if ($rights & $data['operation']) if ($rights & $data['operation'])
@ -755,7 +724,7 @@
} }
elseif (!$rights && $group_ok) elseif (!$rights && $group_ok)
{ {
return $GLOBALS['phpgw_info']['server']['acl_default'] == 'grant'; return $GLOBALS['egw_info']['server']['acl_default'] == 'grant';
} }
else else
{ {
@ -789,7 +758,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'operation' => PHPGW_ACL_READ 'operation' => EGW_ACL_READ
)) ))
) )
{ {
@ -852,12 +821,12 @@
)) ))
) )
{ {
$acl_operation = PHPGW_ACL_EDIT; $acl_operation = EGW_ACL_EDIT;
$journal_operation = VFS_OPERATION_EDITED; $journal_operation = VFS_OPERATION_EDITED;
} }
else else
{ {
$acl_operation = PHPGW_ACL_ADD; $acl_operation = EGW_ACL_ADD;
} }
if (!$this->acl_check (array( if (!$this->acl_check (array(
@ -873,8 +842,8 @@
umask(0177); umask(0177);
/* /*
If 'string' doesn't exist, touch () creates both the file and the database entry 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 If 'string' does exist, touch () sets the modification time and modified by
*/ */
$this->touch (array( $this->touch (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
@ -952,8 +921,8 @@
$data = array_merge ($this->default_values ($data, $default_values), $data); $data = array_merge ($this->default_values ($data, $default_values), $data);
$account_id = $GLOBALS['phpgw_info']['user']['account_id']; $account_id = $GLOBALS['egw_info']['user']['account_id'];
$currentapp = $GLOBALS['phpgw_info']['flags']['currentapp']; $currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
$p = $this->path_parts (array( $p = $this->path_parts (array(
'string' => $data['string'], 'string' => $data['string'],
@ -966,8 +935,8 @@
if ($this->file_actions) if ($this->file_actions)
{ {
/* /*
PHP's touch function will automatically decide whether to PHP's touch function will automatically decide whether to
create the file or set the modification time create the file or set the modification time
*/ */
$rr = @touch ($p->real_full_path); $rr = @touch ($p->real_full_path);
@ -987,7 +956,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'operation' => PHPGW_ACL_EDIT 'operation' => EGW_ACL_EDIT
))) )))
{ {
return False; return False;
@ -1008,7 +977,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'operation' => PHPGW_ACL_ADD 'operation' => EGW_ACL_ADD
)) ))
) )
{ {
@ -1068,7 +1037,7 @@
$data = array_merge ($this->default_values ($data, $default_values), $data); $data = array_merge ($this->default_values ($data, $default_values), $data);
$account_id = $GLOBALS['phpgw_info']['user']['account_id']; $account_id = $GLOBALS['egw_info']['user']['account_id'];
$f = $this->path_parts (array( $f = $this->path_parts (array(
'string' => $data['from'], 'string' => $data['from'],
@ -1085,7 +1054,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $f->fake_full_path, 'string' => $f->fake_full_path,
'relatives' => array ($f->mask), 'relatives' => array ($f->mask),
'operation' => PHPGW_ACL_READ 'operation' => EGW_ACL_READ
)) ))
) )
{ {
@ -1101,7 +1070,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $t->fake_full_path, 'string' => $t->fake_full_path,
'relatives' => array ($t->mask), 'relatives' => array ($t->mask),
'operation' => PHPGW_ACL_EDIT 'operation' => EGW_ACL_EDIT
)) ))
) )
{ {
@ -1113,7 +1082,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $t->fake_full_path, 'string' => $t->fake_full_path,
'relatives' => array ($t->mask), 'relatives' => array ($t->mask),
'operation' => PHPGW_ACL_ADD 'operation' => EGW_ACL_ADD
)) ))
) )
{ {
@ -1181,18 +1150,6 @@
)) ))
) )
{ {
/* RalfBecker 2004/09/19: for my undetstanding the query does nothing, as it only sets rows already containing these values !!!
$query = $this->db->update($this->vfs_table,array(
'owner_id' => $this->working_id,
'directory' => $t->fake_leading_dirs,
'name' => $t->fake_name,
),array(
'owner_id' => $this->working_id,
'directory' => $t->fake_leading_dirs,
'name' => $t->fake_name,
$this->extra_sql(VFS_SQL_UPDATE)
), __LINE__, __FILE__);
*/
$set_attributes_array = array ( $set_attributes_array = array (
'createdby_id' => $account_id, 'createdby_id' => $account_id,
'created' => $this->now, 'created' => $this->now,
@ -1336,7 +1293,7 @@
$data = array_merge ($this->default_values ($data, $default_values), $data); $data = array_merge ($this->default_values ($data, $default_values), $data);
$account_id = $GLOBALS['phpgw_info']['user']['account_id']; $account_id = $GLOBALS['egw_info']['user']['account_id'];
$f = $this->path_parts (array( $f = $this->path_parts (array(
'string' => $data['from'], 'string' => $data['from'],
@ -1353,12 +1310,12 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $f->fake_full_path, 'string' => $f->fake_full_path,
'relatives' => array ($f->mask), 'relatives' => array ($f->mask),
'operation' => PHPGW_ACL_READ 'operation' => EGW_ACL_READ
)) ))
|| !$this->acl_check (array( || !$this->acl_check (array(
'string' => $f->fake_full_path, 'string' => $f->fake_full_path,
'relatives' => array ($f->mask), 'relatives' => array ($f->mask),
'operation' => PHPGW_ACL_DELETE 'operation' => EGW_ACL_DELETE
)) ))
) )
{ {
@ -1368,7 +1325,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $t->fake_full_path, 'string' => $t->fake_full_path,
'relatives' => array ($t->mask), 'relatives' => array ($t->mask),
'operation' => PHPGW_ACL_ADD 'operation' => EGW_ACL_ADD
)) ))
) )
{ {
@ -1384,7 +1341,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $t->fake_full_path, 'string' => $t->fake_full_path,
'relatives' => array ($t->mask), 'relatives' => array ($t->mask),
'operation' => PHPGW_ACL_EDIT 'operation' => EGW_ACL_EDIT
)) ))
) )
{ {
@ -1435,8 +1392,8 @@
} }
/* /*
We add the journal entry now, before we delete. This way the mime_type 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 field will be updated to 'journal-deleted' when the file is actually deleted
*/ */
if (!$f->outside) if (!$f->outside)
{ {
@ -1451,8 +1408,8 @@
} }
/* /*
If the from file is outside, it won't have a database entry, If the from file is outside, it won't have a database entry,
so we have to touch it and find the size so we have to touch it and find the size
*/ */
if ($f->outside) if ($f->outside)
{ {
@ -1503,8 +1460,8 @@
} }
/* /*
This removes the original entry from the database This removes the original entry from the database
The actual file is already deleted because of the rename () above The actual file is already deleted because of the rename () above
*/ */
if ($t->outside) if ($t->outside)
{ {
@ -1584,7 +1541,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'operation' => PHPGW_ACL_DELETE 'operation' => EGW_ACL_DELETE
)) ))
) )
{ {
@ -1751,8 +1708,8 @@
$data = array_merge ($this->default_values ($data, $default_values), $data); $data = array_merge ($this->default_values ($data, $default_values), $data);
$account_id = $GLOBALS['phpgw_info']['user']['account_id']; $account_id = $GLOBALS['egw_info']['user']['account_id'];
$currentapp = $GLOBALS['phpgw_info']['flags']['currentapp']; $currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
$p = $this->path_parts (array( $p = $this->path_parts (array(
'string' => $data['string'], 'string' => $data['string'],
@ -1763,10 +1720,10 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'operation' => PHPGW_ACL_ADD) 'operation' => EGW_ACL_ADD)
) )
) )
{//echo "!acl_check('$p->fake_full_path',PHPGW_ACL_ADD)"; {//echo "!acl_check('$p->fake_full_path',EGW_ACL_ADD)";
return False; return False;
} }
@ -1875,7 +1832,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $vp->fake_full_path, 'string' => $vp->fake_full_path,
'relatives' => array ($vp->mask), 'relatives' => array ($vp->mask),
'operation' => PHPGW_ACL_ADD 'operation' => EGW_ACL_ADD
)) ))
) )
{ {
@ -1951,13 +1908,13 @@
); );
/* /*
This is kind of trivial, given that set_attributes () can change owner_id, This is kind of trivial, given that set_attributes () can change owner_id,
size, etc. size, etc.
*/ */
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'operation' => PHPGW_ACL_EDIT 'operation' => EGW_ACL_EDIT
)) ))
) )
{ {
@ -1974,8 +1931,8 @@
} }
/* /*
All this voodoo just decides which attributes to update All this voodoo just decides which attributes to update
depending on if the attribute was supplied in the 'attributes' array depending on if the attribute was supplied in the 'attributes' array
*/ */
$ls_array = $this->ls (array( $ls_array = $this->ls (array(
@ -1993,8 +1950,8 @@
if (isset ($data['attributes'][$attribute])) if (isset ($data['attributes'][$attribute]))
{ {
/* /*
Indicate that the EDITED_COMMENT operation needs to be journaled, Indicate that the EDITED_COMMENT operation needs to be journaled,
but only if the comment changed but only if the comment changed
*/ */
if ($attribute == 'comment' && $data['attributes'][$attribute] != $record[$attribute]) if ($attribute == 'comment' && $data['attributes'][$attribute] != $record[$attribute])
{ {
@ -2027,13 +1984,13 @@
return True; return True;
} }
/*! /**
@function correct_attributes * Set the correct attributes for 'string' (e.g. owner)
@abstract Set the correct attributes for 'string' (e.g. owner) *
@param string File/directory to correct attributes of * @param string File/directory to correct attributes of
@param relatives Relativity array * @param relatives Relativity array
@result Boolean True/False * @return Boolean True/False
*/ */
function correct_attributes ($data) function correct_attributes ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -2070,7 +2027,7 @@
elseif (preg_match ("+^$this->fakebase\/(.*)$+U", $p->fake_full_path, $matches)) elseif (preg_match ("+^$this->fakebase\/(.*)$+U", $p->fake_full_path, $matches))
{ {
$set_attributes_array = Array( $set_attributes_array = Array(
'owner_id' => $GLOBALS['phpgw']->accounts->name2id ($matches[1]) 'owner_id' => $GLOBALS['egw']->accounts->name2id ($matches[1])
); );
} }
else else
@ -2081,7 +2038,7 @@
} }
$this->set_attributes (array( $this->set_attributes (array(
'string' => $p->fake_full_name, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'attributes' => $set_attributes_array 'attributes' => $set_attributes_array
) )
@ -2116,7 +2073,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'operation' => PHPGW_ACL_READ, 'operation' => EGW_ACL_READ,
'must_exist' => True 'must_exist' => True
)) ))
) )
@ -2132,14 +2089,14 @@
} }
/* /*
We don't return an empty string here, because it may still match with a database query We don't return an empty string here, because it may still match with a database query
because of linked directories because of linked directories
*/ */
} }
/* /*
We don't use ls () because it calls file_type () to determine if it has been We don't use ls () because it calls file_type () to determine if it has been
passed a directory passed a directory
*/ */
$db2 = clone($this->db); $db2 = clone($this->db);
$db2->select($this->vfs_table,'vfs_mime_type',array( $db2->select($this->vfs_table,'vfs_mime_type',array(
@ -2149,18 +2106,15 @@
), __LINE__, __FILE__); ), __LINE__, __FILE__);
$db2->next_record (); $db2->next_record ();
$mime_type = $db2->Record['vfs_mime_type']; $mime_type = $db2->Record['vfs_mime_type'];
if(!$mime_type) if(!$mime_type && ($mime_type = $this->get_ext_mime_type (array ('string' => $data['string']))))
{ {
$mime_type = $this->get_ext_mime_type (array ('string' => $data['string'])); $db2->update($this->vfs_table,array(
{ 'vfs_mime_type' => $mime_type
$db2->update($this->vfs_table,array( ),array(
'vfs_mime_type' => $mime_type 'vfs_directory' => $p->fake_leading_dirs,
),array( 'vfs_name' => $p->fake_name,
'vfs_directory' => $p->fake_leading_dirs, $this->extra_sql(array ('query_type' => VFS_SQL_SELECT))
'vfs_name' => $p->fake_name, ), __LINE__, __FILE__);
$this->extra_sql(array ('query_type' => VFS_SQL_SELECT))
), __LINE__, __FILE__);
}
} }
return $mime_type; return $mime_type;
} }
@ -2232,7 +2186,7 @@
if (!$this->acl_check (array( if (!$this->acl_check (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'operation' => PHPGW_ACL_READ, 'operation' => EGW_ACL_READ,
'must_exist' => True 'must_exist' => True
)) ))
) )
@ -2241,8 +2195,8 @@
} }
/* /*
WIP - this should run through all of the subfiles/directories in the directory and tally up 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 their sizes. Should modify ls () to be able to return a list for files outside the virtual root
*/ */
if ($p->outside) if ($p->outside)
{ {
@ -2259,8 +2213,8 @@
)) as $file_array) )) as $file_array)
{ {
/* /*
Make sure the file is in the directory we want, and not Make sure the file is in the directory we want, and not
some deeper nested directory with a similar name some deeper nested directory with a similar name
*/ */
/* /*
if (@!ereg ('^' . $file_array['directory'], $p->fake_full_path)) if (@!ereg ('^' . $file_array['directory'], $p->fake_full_path))
@ -2286,14 +2240,14 @@
return $size; return $size;
} }
/*! /**
@function checkperms * Check if $this->working_id has write access to create files in $dir
@abstract Check if $this->working_id has write access to create files in $dir *
@discussion Simple call to acl_check * Simple call to acl_check
@param string Directory to check access of * @param string Directory to check access of
@param relatives Relativity array * @param relatives Relativity array
@result Boolean True/False * @return Boolean True/False
*/ */
function checkperms ($data) function checkperms ($data)
{ {
if (!is_array ($data)) if (!is_array ($data))
@ -2317,7 +2271,7 @@
return $this->acl_check (array( return $this->acl_check (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'operation' => PHPGW_ACL_ADD 'operation' => EGW_ACL_ADD
)); ));
} }