diff --git a/phpgwapi/inc/class.vfs_sql.inc.php b/phpgwapi/inc/class.vfs_sql.inc.php index 0f6b896e20..4684a51948 100644 --- a/phpgwapi/inc/class.vfs_sql.inc.php +++ b/phpgwapi/inc/class.vfs_sql.inc.php @@ -25,71 +25,19 @@ /*! @class vfs - @abstract Virtual File System + @abstract Virtual File System with SQL backend @description Authors: Zone */ - /* Relative defines. Used mainly by getabsolutepath () */ - 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); - /* These are used in calls to extra_sql () */ define ('VFS_SQL_SELECT', 1); define ('VFS_SQL_DELETE', 2); define ('VFS_SQL_UPDATE', 4); - /* These are used in calls to add_journal (), and allow journal messages to be more standard */ - 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); - - /*! - @class path_class - @abstract helper class for path_parts - */ - - class path_class + class vfs extends vfs_shared { - var $mask; - var $outside; - 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; - 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; - } - - class vfs - { - var $basedir; - var $fakebase; - var $relative; var $working_id; var $working_lid; - var $attributes; - var $override_acl; - var $linked_dirs; var $meta_types; var $now; var $file_actions; @@ -100,12 +48,11 @@ */ function vfs () { + $this->vfs_shared (); $this->basedir = $GLOBALS['phpgw_info']['server']['files_dir']; - $this->fakebase = "/home"; $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'); - $this->override_acl = 0; /* File/dir attributes, each corresponding to a database field. Useful for use in loops @@ -115,25 +62,8 @@ set_attributes now uses this array(). 07-Dec-01 skeeter */ - $this->attributes = array( - 'file_id', - 'owner_id', - 'createdby_id', - 'modifiedby_id', - 'created', - 'modified', - 'size', - 'mime_type', - 'deleteable', - 'comment', - 'app', - 'directory', - 'name', - 'link_directory', - 'link_name', - 'version', - 'content' - ); + $this->attributes[] = 'deleteable'; + $this->attributes[] = 'content'; /* Decide whether to use any actual filesystem calls (fopen(), fread(), @@ -170,7 +100,6 @@ $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 (link_name IS NOT NULL or link_name != '')" . $this->extra_sql (array ('query_type' => VFS_SQL_SELECT)), __LINE__,__FILE__); } - $this->linked_dirs = array (); while ($GLOBALS['phpgw']->db->next_record ()) { @@ -178,114 +107,6 @@ } } - /*! - @function set_relative - @abstract Set path relativity - @param mask Relative bitmask (see RELATIVE_ defines) - */ - function set_relative ($data) - { - if (!is_array ($data)) - { - $data = array (); - } - - if (!$data['mask']) - { - unset ($this->relative); - } - else - { - $this->relative = $data['mask']; - } - } - - /*! - @function get_relative - @abstract Return relativity bitmask - @discussion Returns relativity bitmask, or the default of "completely relative" if unset - */ - function get_relative () - { - if (isset ($this->relative) && $this->relative) - { - return $this->relative; - } - else - { - return RELATIVE_ALL; - } - } - - /*! - @function sanitize - @abstract Removes leading .'s from 'string' - @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 - @param string string to sanitize - @result $string 'string' without it's leading .'s - */ - function sanitize ($data) - { - if (!is_array ($data)) - { - $data = array (); - } - - /* We use path_parts () just to parse the string, not translate paths */ - $p = $this->path_parts (array( - 'string' => $data['string'], - 'relatives' => array (RELATIVE_NONE) - ) - ); - - return (ereg_replace ("^\.+", '', $p->fake_name)); - } - - /*! - @function securitycheck - @abstract Security check function - @discussion Checks for basic violations such as .. - If securitycheck () fails, run your string through vfs->sanitize () - @param string string to check security of - @result Boolean True/False. True means secure, False means insecure - */ - function securitycheck ($data) - { - if (!is_array ($data)) - { - $data = array (); - } - - if (substr ($data['string'], 0, 1) == "\\" || strstr ($data['string'], "..") || strstr ($data['string'], "\\..") || strstr ($data['string'], ".\\.")) - { - return False; - } - else - { - return True; - } - } - - /*! - @function db_clean - @abstract Clean 'string' for use in database queries - @param string String to clean - @result Cleaned version of 'string' - */ - function db_clean ($data) - { - if (!is_array ($data)) - { - $data = array (); - } - - $string = ereg_replace ("'", "\'", $data['string']); - - return $string; - } - /*! @function extra_sql @abstract Return extra SQL code that should be appended to certain queries @@ -535,7 +356,7 @@ } $sql .= "$attribute"; - $sql2 .= "'" . $this->db_clean (array ('string' => $value)) . "'"; + $sql2 .= "'" . $this->clean_string (array ('string' => $value)) . "'"; } } @@ -693,14 +514,9 @@ } } - /*! - @function get_journal - @abstract Retrieve journal entries for $string - @param string File/directory to retrieve journal entries of - @param relatives Relativity array - @param type 0/False = any, 1 = 'journal', 2 = 'journal-deleted' - @result Array of arrays of journal entries - */ + /* + * See vfs_shared + */ function get_journal ($data) { if (!is_array ($data)) @@ -755,346 +571,9 @@ return $rarray; } - /*! - @function path_parts - @abstract take a real or fake pathname and return an array of its component parts - @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 - @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 - outside is boolean, True if 'relatives' contains VFS_REAL - */ - function path_parts ($data) - { - if (!is_array ($data)) - { - $data = array (); - } - - $default_values = array - ( - 'relatives' => array (RELATIVE_CURRENT), - 'object' => True, - 'nolinks' => False - ); - - $data = array_merge ($this->default_values ($data, $default_values), $data); - - $sep = SEP; - - $rarray['mask'] = RELATIVE_NONE; - - if (!($data['relatives'][0] & VFS_REAL)) - { - $rarray['outside'] = False; - $fake = True; - } - else - { - $rarray['outside'] = True; - $rarray['mask'] |= VFS_REAL; - } - - $string = $this->getabsolutepath (array( - 'string' => $data['string'], - 'mask' => array ($data['relatives'][0]), - 'fake' => $fake - ) - ); - - if ($fake) - { - $base_sep = '/'; - $base = '/'; - - $opp_base = $this->basedir . $sep; - - $rarray['fake_full_path'] = $string; - } - else - { - $base_sep = $sep; - if (ereg ("^$this->basedir" . $sep, $string)) - { - $base = $this->basedir . $sep; - } - else - { - $base = $sep; - } - - $opp_base = '/'; - - $rarray['real_full_path'] = $string; - } - - /* 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; - - $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); - - if ($fake) - { - $rarray['real_extra_path'] ? $dispsep = $sep : $dispsep = ''; - $rarray['real_full_path'] = $opp_base . $rarray['real_extra_path'] . $dispsep . $rarray['real_name']; - if ($extra_path) - { - $rarray['fake_leading_dirs'] = $base . $extra_path; - $rarray['real_leading_dirs'] = $opp_base . $extra_path; - } - elseif (strrpos ($rarray['fake_full_path'], $sep) == 0) - { - /* If there is only one $sep in the path, we don't want to strip it off */ - $rarray['fake_leading_dirs'] = $sep; - $rarray['real_leading_dirs'] = substr ($opp_base, 0, strlen ($opp_base) - 1); - } - else - { - /* These strip the ending / */ - $rarray['fake_leading_dirs'] = substr ($base, 0, strlen ($base) - 1); - $rarray['real_leading_dirs'] = substr ($opp_base, 0, strlen ($opp_base) - 1); - } - } - else - { - $rarray['fake_full_path'] = $opp_base . $rarray['fake_extra_path'] . '/' . $rarray['fake_name']; - if ($extra_path) - { - $rarray['fake_leading_dirs'] = $opp_base . $extra_path; - $rarray['real_leading_dirs'] = $base . $extra_path; - } - else - { - $rarray['fake_leading_dirs'] = substr ($opp_base, 0, strlen ($opp_base) - 1); - $rarray['real_leading_dirs'] = substr ($base, 0, strlen ($base) - 1); - } - } - - /* We check for linked dirs made with make_link (). This could be better, but it works */ - if (!$data['nolinks']) - { - reset ($this->linked_dirs); - while (list ($num, $link_info) = each ($this->linked_dirs)) - { - if (ereg ("^$link_info[directory]/$link_info[name](/|$)", $rarray['fake_full_path'])) - { - $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']); - - $p = $this->path_parts (array( - 'string' => $rarray['real_full_path'], - 'relatives' => array (RELATIVE_NONE|VFS_REAL), - 'nolinks' => True - ) - ); - - $rarray['real_leading_dirs'] = $p->real_leading_dirs; - $rarray['real_extra_path'] = $p->real_extra_path; - $rarray['real_name'] = $p->real_name; - } - } - } - - /* - We have to count it before because new keys will be added, - which would create an endless loop - */ - $count = count ($rarray); - reset ($rarray); - for ($i = 0; (list ($key, $value) = each ($rarray)) && $i != $count; $i++) - { - $rarray[$key . '_clean'] = $this->db_clean (array ('string' => $value)); - } - - if ($data['object']) - { - $robject = new path_class; - - reset ($rarray); - while (list ($key, $value) = each ($rarray)) - { - $robject->$key = $value; - } - } - - /* - echo "
fake_full_path: $rarray[fake_full_path] -
fake_leading_dirs: $rarray[fake_leading_dirs] -
fake_extra_path: $rarray[fake_extra_path] -
fake_name: $rarray[fake_name] -
real_full_path: $rarray[real_full_path] -
real_leading_dirs: $rarray[real_leading_dirs] -
real_extra_path: $rarray[real_extra_path] -
real_name: $rarray[real_name]"; - */ - - if ($data['object']) - { - return ($robject); - } - else - { - return ($rarray); - } - } - - /*! - @function getabsolutepath - @abstract get the absolute path - @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) - @result $basedir Full fake or real path - */ - function getabsolutepath ($data) - { - if (!is_array ($data)) - { - $data = array (); - } - - $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); - - /* If they supply just VFS_REAL, we assume they want current relativity */ - if ($data['mask'][0] == VFS_REAL) - { - $data['mask'][0] |= RELATIVE_CURRENT; - } - - if (!$this->securitycheck (array( - 'string' => $data['string'] - )) - ) - { - return False; - } - - if ($data['mask'][0] & RELATIVE_NONE) - { - return $data['string']; - } - - if ($data['fake']) - { - $sep = '/'; - } - else - { - $sep = SEP; - } - - /* if RELATIVE_CURRENT, retrieve the current mask */ - if ($data['mask'][0] & RELATIVE_CURRENT) - { - $mask = $data['mask'][0]; - /* Respect any additional masks by re-adding them after retrieving the current mask*/ - $data['mask'][0] = $this->get_relative () + ($mask - RELATIVE_CURRENT); - } - - if ($data['fake']) - { - $basedir = "/"; - } - else - { - $basedir = $this->basedir . $sep; - - /* This allows all requests to use /'s */ - $data['string'] = preg_replace ("|/|", $sep, $data['string']); - } - - if (($data['mask'][0] & RELATIVE_PATH) && $currentdir) - { - $basedir = $basedir . $currentdir . $sep; - } - elseif (($data['mask'][0] & RELATIVE_USER) || ($data['mask'][0] & RELATIVE_USER_APP)) - { - $basedir = $basedir . $this->fakebase . $sep; - } - - if ($data['mask'][0] & RELATIVE_CURR_USER) - { - $basedir = $basedir . $this->working_lid . $sep; - } - - if (($data['mask'][0] & RELATIVE_USER) || ($data['mask'][0] & RELATIVE_USER_APP)) - { - $basedir = $basedir . $GLOBALS['phpgw_info']['user']['account_lid'] . $sep; - } - - if ($data['mask'][0] & RELATIVE_USER_APP) - { - $basedir = $basedir . "." . $GLOBALS['phpgw_info']['flags']['currentapp'] . $sep; - } - - /* Don't add string if it's a /, just for aesthetics */ - if ($data['string'] && $data['string'] != $sep) - { - $basedir = $basedir . $data['string']; - } - - /* Let's not return // */ - while (ereg ($sep . $sep, $basedir)) - { - $basedir = ereg_replace ($sep . $sep, $sep, $basedir); - } - - $basedir = ereg_replace ($sep . '$', '', $basedir); - - return $basedir; - } - - /*! - @function acl_check - @abstract Check ACL access to $file for $GLOBALS['phpgw_info']["user"]["account_id"]; - @discussion To check the access for a file or directory, pass 'string'/'relatives'/'must_exist'. - To check the access to another user or group, pass 'owner_id'. - If 'owner_id' is present, we bypass checks on 'string'/'relatives'/'must_exist' - @param string File to check access of - @param relatives Standard relativity array - @param owner_id Owner id to check access of (see discussion above) - @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 - @result Boolean. True if access is ok, False otherwise - */ + /* + * See vfs_shared + */ function acl_check ($data) { if (!is_array ($data)) @@ -1260,122 +739,9 @@ } } - /*! - @function cd - @abstract Change directory - @discussion To cd to the files root '/', use cd ('/', False, array (RELATIVE_NONE)); - @param string default '/'. directory to cd into. if "/" and $relative is True, uses "/home/"; - @param relative default True/relative means add target to current path, else pass $relative as mask to getabsolutepath() - @param relatives Relativity array - */ - function cd ($data = '') - { - if (!is_array ($data)) - { - $noargs = 1; - $data = array (); - } - - $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) - { - $sep = SEP; - } - else - { - $sep = '/'; - } - - if ($data['relative'] == 'relative' || $data['relative'] == True) - { - /* if 'string' is "/" and 'relative' is set, we cd to the user/group home dir */ - if ($data['string'] == '/') - { - $data['relatives'][0] = RELATIVE_USER; - $basedir = $this->getabsolutepath (array( - 'string' => False, - 'mask' => array ($data['relatives'][0]), - 'fake' => True - ) - ); - } - else - { - $currentdir = $GLOBALS['phpgw']->session->appsession('vfs',''); - $basedir = $this->getabsolutepath (array( - 'string' => $currentdir . $sep . $data['string'], - 'mask' => array ($data['relatives'][0]), - 'fake' => True - ) - ); - } - } - else - { - $basedir = $this->getabsolutepath (array( - 'string' => $data['string'], - 'mask' => array ($data['relatives'][0]) - ) - ); - } - - $GLOBALS['phpgw']->session->appsession('vfs','',$basedir); - - return True; - } - - /*! - @function pwd - @abstract current working dir - @param full default True returns full fake path, else just the extra dirs (false strips the leading /) - @result $currentdir currentdir - */ - function pwd ($data = '') - { - if (!is_array ($data)) - { - $data = array (); - } - - $default_values = array - ( - 'full' => True - ); - - $data = array_merge ($this->default_values ($data, $default_values), $data); - - $currentdir = $GLOBALS['phpgw']->session->appsession('vfs',''); - - if (!$data['full']) - { - $currentdir = ereg_replace ("^/", '', $currentdir); - } - - if ($currentdir == '' && $data['full']) - { - $currentdir = '/'; - } - - $currentdir = trim ($currentdir); - - return $currentdir; - } - - /*! - @function read - @abstract return file contents - @param string filename - @param relatives Relativity array - @result $contents Contents of $file, or False if file cannot be read - */ + /* + * See vfs_shared + */ function read ($data) { if (!is_array ($data)) @@ -1434,14 +800,9 @@ return $contents; } - /*! - @function write - @abstract write to a file - @param string file name - @param relatives Relativity array - @param content content - @result Boolean True/False - */ + /* + * See vfs_shared + */ function write ($data) { if (!is_array ($data)) @@ -1554,13 +915,9 @@ } } - /*! - @function touch - @abstract Create blank file $file or set the modification time and modified by of $file to current time and user - @param string File to touch or set modifies - @param relatives Relativity array - @result Boolean True/False - */ + /* + * See vfs_shared + */ function touch ($data) { if (!is_array ($data)) @@ -1676,14 +1033,9 @@ } } - /*! - @function cp - @abstract copy file - @param from from file/directory - @param to to file/directory - @param relatives Relativity array - @result boolean True/False - */ + /* + * See vfs_shared + */ function cp ($data) { if (!is_array ($data)) @@ -1935,19 +1287,9 @@ return True; } - function copy ($data) - { - return $this->cp ($data); - } - - /*! - @function mv - @abstract move file/directory - @param from from file/directory - @param to to file/directory - @param relatives Relativity array - @result boolean True/False - */ + /* + * See vfs_shared + */ function mv ($data) { if (!is_array ($data)) @@ -2145,7 +1487,7 @@ while (list ($num, $entry) = each ($ls)) { $newdir = ereg_replace ("^$f->fake_full_path", $t->fake_full_path, $entry['directory']); - $newdir_clean = $this->db_clean (array ('string' => $newdir)); + $newdir_clean = $this->clean_string (array ('string' => $newdir)); $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( @@ -2168,22 +1510,9 @@ return True; } - /*! - @function move - @abstract shortcut to mv - */ - function move ($data) - { - return $this->mv ($data); - } - - /*! - @function rm - @abstract delete file/directory - @param string file/directory to delete - @param relatives Relativity array - @result boolean True/False - */ + /* + * See vfs_shared + */ function rm ($data) { if (!is_array ($data)) @@ -2357,22 +1686,9 @@ } } - /*! - @function delete - @abstract shortcut to rm - */ - function delete ($data) - { - return $this->rm ($data); - } - - /*! - @function mkdir - @abstract make a new directory - @param string Directory name - @param relatives Relativity array - @result boolean True on success - */ + /* + * See vfs_shared + */ function mkdir ($data) { if (!is_array ($data)) @@ -2465,16 +1781,9 @@ return True; } - /*! - @function make_link - @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 - @result Boolean True/False - */ + /* + * See vfs_shared + */ function make_link ($data) { if (!is_array ($data)) @@ -2558,15 +1867,9 @@ return True; } - /*! - @function set_attributes - @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 - @result Boolean True/False - @discussion Valid attributes are list in vfs->attributes - */ + /* + * See vfs_shared + */ function set_attributes ($data) { if (!is_array ($data)) @@ -2645,7 +1948,7 @@ $edited_comment = 1; } - $$attribute = $this->db_clean (array ('string' => $$attribute)); + $$attribute = $this->clean_string (array ('string' => $$attribute)); if ($change_attributes > 0) { @@ -2746,13 +2049,9 @@ return True; } - /*! - @function file_type - @abstract return file/dir type (MIME or other) - @param string File or directory path (/home/user/dir/dir2/dir3, /home/user/dir/dir2/file) - @param relatives Relativity array - @result MIME type, "Directory", or nothing if MIME type is not known - */ + /* + * See vfs_shared + */ function file_type ($data) { if (!is_array ($data)) @@ -2816,58 +2115,9 @@ return $mime_type; } - /*! - @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= 2) - { - for($j=1;$jget_size () - @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 - @result array of arrays. Subarrays contain full info for each file/dir. - */ + /* + * See vfs_shared + */ function ls ($data) { if (!is_array ($data)) @@ -3182,7 +2416,7 @@ $sql .= $attribute; } - $dir_clean = $this->db_clean (array ('string' => $dir)); + $dir_clean = $this->clean_string (array ('string' => $dir)); $sql .= " FROM phpgw_vfs WHERE directory LIKE '$dir_clean%'"; $sql .= $this->extra_sql (array ('query_type' => VFS_SQL_SELECT)); @@ -3236,132 +2470,9 @@ return $rarray; } - /*! - @function dir - @abstract shortcut to ls - */ - function dir ($data) - { - return $this->ls ($data); - } - - /*! - @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 ""). - @param command_line Unix-style command line with one of the commands in the $args array - @result $result The return value of the actual VFS call - */ - function command_line ($data) - { - if (!is_array ($data)) - { - $data = array (); - } - - $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) - ); - - if (!$first_space = strpos ($data['command_line'], ' ')) - { - $first_space = strlen ($data['command_line']); - } - if ((!$last_space = strrpos ($data['command_line'], ' ')) || ($last_space == $first_space)) - { - $last_space = strlen ($data['command_line']) + 1; - } - $argv[0] = substr ($data['command_line'], 0, $first_space); - if (strlen ($argv[0]) != strlen ($data['command_line'])) - { - $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'])) - { - $argv[2] = substr ($data['command_line'], $last_space + 1); - } - } - $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]) - { - $rv = $this->$func (array( - 'string' => $argv[1], - 'relatives' => $relatives - ) - ); - } - else - { - $rv = $this->$func (array( - 'from' => $argv[1], - 'to' => $argv[2], - 'relatives' => $relatives - ) - ); - } - - return ($rv); - } - - /*! - @function update_real - @abstract Update database information for file or directory 'string' - @param string File or directory to update database information for - @param relatives Relativity array - @result Boolean True/False - */ + /* + * See vfs_shared + */ function update_real ($data) { if (!is_array ($data)) @@ -3463,19 +2574,6 @@ /* Helper functions */ - 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; - } - /* This fetchs all available file system information for string (not using the database) */ function get_real_info ($data) {