From 4820ee5c02eb4354c412a61e62104b53a715c665 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Fri, 28 Sep 2001 20:41:36 +0000 Subject: [PATCH] Formatting (double->single ticks), use GLOBALS --- phpgwapi/inc/class.vfs_sql.inc.php | 1209 ++++++++++++++-------------- 1 file changed, 594 insertions(+), 615 deletions(-) diff --git a/phpgwapi/inc/class.vfs_sql.inc.php b/phpgwapi/inc/class.vfs_sql.inc.php index 4841c8c6a3..3d130a2231 100644 --- a/phpgwapi/inc/class.vfs_sql.inc.php +++ b/phpgwapi/inc/class.vfs_sql.inc.php @@ -80,7 +80,6 @@ var $real_name_clean; } - class vfs { var $basedir; @@ -92,56 +91,57 @@ var $override_acl; var $linked_dirs; var $meta_types; - + /*! @function vfs @abstract constructor, sets up variables */ - function vfs () { - global $phpgw, $phpgw_info; - - $this->basedir = $phpgw_info["server"]["files_dir"]; + $this->basedir = $GLOBALS['phpgw_info']['server']['files_dir']; $this->fakebase = "/home"; - $this->working_id = $phpgw_info["user"]["account_id"]; - $this->working_lid = $phpgw->accounts->id2name ($this->working_id); - $this->now = date ("Y-m-d"); + $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 If an attribute was added to the table, add it here and possibly add it to set_attributes () */ - - $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"); + + $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' + ); /* These are stored in the MIME-type field and should normally be ignored. Adding a type here will ensure it is normally ignored, but you will have to explicitly add it to acl_check (), and to any other SELECT's in this file */ - - $this->meta_types = array ("journal", "journal-deleted"); - + + $this->meta_types = array ('journal', 'journal-deleted'); + /* We store the linked directories in an array now, so we don't have to make the SQL call again */ - - $query = $phpgw->db->query ("SELECT directory, name, link_directory, link_name FROM phpgw_vfs WHERE link_directory != '' AND link_name != ''" . $this->extra_sql (VFS_SQL_SELECT)); - + + $query = $GLOBALS['phpgw']->db->query ("SELECT directory, name, link_directory, link_name FROM phpgw_vfs WHERE link_directory != '' AND link_name != ''" . $this->extra_sql (VFS_SQL_SELECT)); + $this->linked_dirs = array (); - while ($phpgw->db->next_record ()) + while ($GLOBALS['phpgw']->db->next_record ()) { - $this->linked_dirs[] = $phpgw->db->Record; + $this->linked_dirs[] = $GLOBALS['phpgw']->db->Record; } } - + /*! @function set_relative @abstract Set path relativity @param $mask Relative bitmask (see RELATIVE_ defines) */ - function set_relative ($mask) { if (!$mask) @@ -153,13 +153,12 @@ $this->relative = $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)) @@ -171,27 +170,24 @@ return RELATIVE_ALL; } } - + /*! - @function sanitize - @abstract Removes leading .'s from $string + @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 without it's leading .'s - */ - + */ function sanitize ($string) { - global $phpgw, $phpgw_info; - /* We use path_parts () just to parse the string, not translate paths */ $p = $this->path_parts ($string, array (RELATIVE_NONE)); - - return (ereg_replace ("^\.+", "", $p->fake_name)); + + return (ereg_replace ("^\.+", '', $p->fake_name)); } - + /*! @function securitycheck @abstract Security check function @@ -200,7 +196,6 @@ @param $string string to check security of @result Boolean True/False. True means secure, False means insecure */ - function securitycheck ($string) { if (substr ($string, 0, 1) == "\\" || strstr ($string, "..") || strstr ($string, "\\..") || strstr ($string, ".\\.")) @@ -212,51 +207,47 @@ 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 ($string) { $string = ereg_replace ("'", "\'", $string); - + return $string; } - + /*! @function extra_sql @abstract Return extra SQL code that should be appended to certain queries @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 */ - function extra_sql ($query_type = VFS_SQL_SELECT) { - global $phpgw, $phpgw_info; - if ($query_type == VFS_SQL_SELECT || $query_type == VFS_SQL_DELETE || $query_type = VFS_SQL_UPDATE) { - $sql = " AND (("; - + $sql = ' AND (('; + reset ($this->meta_types); while (list ($num, $type) = each ($this->meta_types)) { if ($num) - $sql .= " AND "; - + $sql .= ' AND '; + $sql .= "mime_type != '$type'"; } - - $sql .= ") OR mime_type IS NULL)"; + + $sql .= ') OR mime_type IS NULL)'; } - + return ($sql); } - + /*! @function add_journal @abstract Add a journal entry after (or before) completing an operation, @@ -267,7 +258,7 @@ $operation $state_two VFS_OPERATION_COPIED fake_full_path of copied 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 @param $string File or directory to add entry for @param $relatives Relativity array @@ -282,78 +273,77 @@ would not @result Boolean True/False */ - function add_journal ($string, $relatives = '', $operation, $state_one = False, $state_two = False, $incversion = True) { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - $account_id = $phpgw_info["user"]["account_id"]; - + $account_id = $GLOBALS['phpgw_info']['user']['account_id']; + $p = $this->path_parts ($string, array ($relatives[0])); - + /* We check that they have some sort of access to the file other than read */ - if (!$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_WRITE) && !$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_EDIT) && !$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_DELETE)) + if (!$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_WRITE) && + !$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_EDIT) && + !$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_DELETE)) { return False; } - + if (!$this->file_exists ($p->fake_full_path, array ($p->mask))) { return False; } - + $ls_array = $this->ls ($p->fake_full_path, array ($p->mask), False, False, True); $file_array = $ls_array[0]; - - $sql = "INSERT INTO phpgw_vfs ("; - $sql2 .= " VALUES ("; - + + $sql = 'INSERT INTO phpgw_vfs ('; + $sql2 .= ' VALUES ('; + for ($i = 0; list ($attribute, $value) = each ($file_array); $i++) { - if ($attribute == "file_id") + if ($attribute == 'file_id') { continue; } - - if ($attribute == "owner_id") + + if ($attribute == 'owner_id') { $value = $account_id; } - - if ($attribute == "created") + + if ($attribute == 'created') { $value = $this->now; } - if ($attribute == "modified" && !$modified) + if ($attribute == 'modified' && !$modified) { unset ($value); } - - if ($attribute == "mime_type") + + if ($attribute == 'mime_type') { - $value = "journal"; + $value = 'journal'; } - - if ($attribute == "comment") + + if ($attribute == 'comment') { switch ($operation) { case VFS_OPERATION_CREATED: - $value = "Created"; + $value = 'Created'; $incversion = True; break; case VFS_OPERATION_EDITED: - $value = "Edited"; + $value = 'Edited'; $incversion = True; break; case VFS_OPERATION_EDITED_COMMENT: - $value = "Edited comment"; + $value = 'Edited comment'; $incversion = False; break; case VFS_OPERATION_COPIED: @@ -381,7 +371,7 @@ $incversion = False; break; case VFS_OPERATION_DELETED: - $value = "Deleted"; + $value = 'Deleted'; $incversion = False; break; default: @@ -389,18 +379,18 @@ break; } } - + /* Let's increment the version for the file itself. We keep the current version when making the journal entry, because that was the version that was operated on. The maximum numbers for each part in the version string: none.99.9.9 */ - if ($attribute == "version" && $incversion) + if ($attribute == 'version' && $incversion) { $version_parts = split ("\.", $value); $newnumofparts = $numofparts = count ($version_parts); - + if ($version_parts[3] >= 9) { $version_parts[3] = 0; @@ -411,55 +401,55 @@ { $version_parts[3]++; } - + if ($version_parts[2] >= 9 && $version_parts[3] == 0 && $version_parts_3_update) { $version_parts[2] = 0; $version_parts[1]++; } - + if ($version_parts[1] > 99) { $version_parts[1] = 0; $version_parts[0]++; } - + for ($i = 0; $i < $newnumofparts; $i++) { if (!isset ($version_parts[$i])) { break; } - + if ($i) { - $newversion .= "."; + $newversion .= '.'; } - + $newversion .= $version_parts[$i]; } - - $this->set_attributes ($p->fake_full_path, array ($p->mask), array ("version" => $newversion)); + + $this->set_attributes ($p->fake_full_path, array ($p->mask), array ('version' => $newversion)); } if (isset ($value)) { if ($i > 1) { - $sql .= ", "; - $sql2 .= ", "; + $sql .= ', '; + $sql2 .= ', '; } $sql .= "$attribute"; $sql2 .= "'" . $this->db_clean ($value) . "'"; } } - - $sql .= ")"; - $sql2 .= ")"; - + + $sql .= ')'; + $sql2 .= ')'; + $sql .= $sql2; - + /* 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 @@ -470,20 +460,20 @@ $flush_path = $p->fake_full_path; $deleteall = True; } - + if ($operation == VFS_OPERATION_COPIED || $operation == VFS_OPERATION_MOVED) { $flush_path = $state_two; $deleteall = False; } - + if ($flush_path) { $flush_path_parts = $this->path_parts ($flush_path, array (RELATIVE_NONE)); - + $this->flush_journal ($flush_path_parts->fake_full_path, array ($flush_path_parts->mask), $deleteall); } - + if ($operation == VFS_OPERATION_COPIED) { /* @@ -492,35 +482,35 @@ */ $this->add_journal ($state_two, array (RELATIVE_NONE), "Copied $state_one to $state_two", NULL, NULL, False); } - + if ($operation == VFS_OPERATION_MOVED) { $state_one_path_parts = $this->path_parts ($state_one, array (RELATIVE_NONE)); - - $query = $phpgw->db->query ("UPDATE phpgw_vfs SET mime_type='journal-deleted' WHERE directory='$state_one_path_parts->fake_leading_dirs_clean' AND name='$state_one_path_parts->fake_name_clean' AND mime_type='journal'"); - + + $query = $GLOBALS['phpgw']->db->query ("UPDATE phpgw_vfs SET mime_type='journal-deleted' WHERE directory='$state_one_path_parts->fake_leading_dirs_clean' AND name='$state_one_path_parts->fake_name_clean' AND mime_type='journal'"); + /* 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 */ $this->add_journal ($state_two, array (RELATIVE_NONE), VFS_OPERATION_CREATED); } - + /* This is the SQL query we made for THIS request, remember that one? */ - $query = $phpgw->db->query ($sql, __LINE__, __FILE__); - + $query = $GLOBALS['phpgw']->db->query ($sql, __LINE__, __FILE__); + /* 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 */ if ($operation == VFS_OPERATION_DELETED) { - $query = $phpgw->db->query ("UPDATE phpgw_vfs SET mime_type='journal-deleted' WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean' AND mime_type='journal'"); + $query = $GLOBALS['phpgw']->db->query ("UPDATE phpgw_vfs SET mime_type='journal-deleted' WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean' AND mime_type='journal'"); } - + return True; } - + /*! @function flush_journal @abstract Flush journal entries for $string. Used before adding $string @@ -533,36 +523,33 @@ @param $deletedonly Only flush 'journal-deleted' entries (created when $string was deleted) @result Boolean True/False */ - function flush_journal ($string, $relatives = '', $deleteall = False, $deletedonly = False) { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($string, array ($relatives[0])); - + $sql = "DELETE FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'"; - + if (!$deleteall) { $sql .= " AND (mime_type != 'journal' AND comment != 'Created')"; } - + $sql .= " AND (mime_type='journal-deleted'"; - + if (!$deletedonly) { $sql .= " OR mime_type='journal'"; } - + $sql .= ")"; - - $query = $phpgw->db->query ($sql, __LINE__, __FILE__); - + + $query = $GLOBALS['phpgw']->db->query ($sql, __LINE__, __FILE__); + if ($query) { return True; @@ -572,7 +559,7 @@ return False; } } - + /*! @function get_journal @abstract Retrieve journal entries for $string @@ -581,25 +568,22 @@ @param $type 0/False = any, 1 = 'journal', 2 = 'journal-deleted' @result Array of arrays of journal entries */ - function get_journal ($string, $relatives = '', $type = False) { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($string, array ($relatives[0])); - + if (!$this->acl_check ($p->fake_full_path, array ($p->mask))) { return False; } - + $sql = "SELECT * FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'"; - + if ($type == 1) { $sql .= " AND mime_type='journal'"; @@ -612,17 +596,17 @@ { $sql .= " AND (mime_type='journal' OR mime_type='journal-deleted')"; } - - $query = $phpgw->db->query ($sql, __LINE__, __FILE__); - - while ($phpgw->db->next_record ()) + + $query = $GLOBALS['phpgw']->db->query ($sql, __LINE__, __FILE__); + + while ($GLOBALS['phpgw']->db->next_record ()) { - $rarray[] = $phpgw->db->Record; - } - + $rarray[] = $GLOBALS['phpgw']->db->Record; + } + return $rarray; } - + /*! @function path_parts @abstract take a real or fake pathname and return an array of its component parts @@ -658,41 +642,38 @@ and is used internally outside is boolean, True if $relatives contains VFS_REAL */ - function path_parts ($string, $relatives = '', $object = True, $nolinks = False) { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } $sep = SEP; - - $rarray["mask"] = RELATIVE_NONE; - + + $rarray['mask'] = RELATIVE_NONE; + if (!($relatives[0] & VFS_REAL)) { - $rarray["outside"] = False; + $rarray['outside'] = False; $fake = True; } else { - $rarray["outside"] = True; - $rarray["mask"] |= VFS_REAL; + $rarray['outside'] = True; + $rarray['mask'] |= VFS_REAL; } - + $string = $this->getabsolutepath ($string, array ($relatives[0]), $fake); - + if ($fake) { - $base_sep = "/"; - $base = "/"; - + $base_sep = '/'; + $base = '/'; + $opp_base = $this->basedir . $sep; - - $rarray["fake_full_path"] = $string; + + $rarray['fake_full_path'] = $string; } else { @@ -705,77 +686,77 @@ { $base = $sep; } - - $opp_base = "/"; - - $rarray["real_full_path"] = $string; + + $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); - + + $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"]; + $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; + $rarray['fake_leading_dirs'] = $base . $extra_path; + $rarray['real_leading_dirs'] = $opp_base . $extra_path; } - elseif (strrpos ($rarray["fake_full_path"], $sep) == 0) + 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); + $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); + $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"]; + $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; + $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); + $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 (!$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"])) + 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"]); - + $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 ($rarray["real_full_path"], array (RELATIVE_NONE|VFS_REAL), True, True); - - $rarray["real_leading_dirs"] = $p->real_leading_dirs; - $rarray["real_extra_path"] = $p->real_extra_path; - $rarray["real_name"] = $p->real_name; + + $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 @@ -784,20 +765,20 @@ reset ($rarray); for ($i = 0; (list ($key, $value) = each ($rarray)) && $i != $count; $i++) { - $rarray[$key . "_clean"] = $this->db_clean ($value); + $rarray[$key . '_clean'] = $this->db_clean ($value); } - + if ($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] @@ -808,7 +789,7 @@
real_extra_path: $rarray[real_extra_path]
real_name: $rarray[real_name]"; */ - + if ($object) { return ($robject); @@ -818,7 +799,7 @@ return ($rarray); } } - + /*! @function getabsolutepath @abstract get the absolute path @@ -826,44 +807,41 @@ @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 ($target = False, $relatives = '', $fake = True) { - global $phpgw, $phpgw_info; - $currentdir = $this->pwd (False); - + if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + /* If they supply just VFS_REAL, we assume they want current relativity */ if ($relatives[0] == VFS_REAL) { $relatives[0] |= RELATIVE_CURRENT; } - + if (!$this->securitycheck ($target)) { return False; } - + if ($relatives[0] & RELATIVE_NONE) { return $target; } - + if ($fake) { - $sep = "/"; + $sep = '/'; } else { $sep = SEP; } - + /* if RELATIVE_CURRENT, retrieve the current mask */ if ($relatives[0] & RELATIVE_CURRENT) { @@ -871,7 +849,7 @@ /* Respect any additional masks by re-adding them after retrieving the current mask*/ $relatives[0] = $this->get_relative () + ($mask - RELATIVE_CURRENT); } - + if ($fake) { $basedir = "/"; @@ -879,11 +857,11 @@ else { $basedir = $this->basedir . $sep; - + /* This allows all requests to use /'s */ $target = preg_replace ("|/|", $sep, $target); } - + if (($relatives[0] & RELATIVE_PATH) && $currentdir) { $basedir = $basedir . $currentdir . $sep; @@ -892,73 +870,70 @@ { $basedir = $basedir . $this->fakebase . $sep; } - + if ($relatives[0] & RELATIVE_CURR_USER) { $basedir = $basedir . $this->working_lid . $sep; } - + if (($relatives[0] & RELATIVE_USER) || ($relatives[0] & RELATIVE_USER_APP)) { - $basedir = $basedir . $phpgw_info["user"]["account_lid"] . $sep; + $basedir = $basedir . $GLOBALS['phpgw_info']['user']['account_lid'] . $sep; } - + if ($relatives[0] & RELATIVE_USER_APP) { - $basedir = $basedir . "." . $phpgw_info["flags"]["currentapp"] . $sep; + $basedir = $basedir . "." . $GLOBALS['phpgw_info']['flags']['currentapp'] . $sep; } - + /* Don't add target if it's a /, just for aesthetics */ if ($target && $target != $sep) $basedir = $basedir . $target; - + /* Let's not return // */ while (ereg ($sep . $sep, $basedir)) { $basedir = ereg_replace ($sep . $sep, $sep, $basedir); } - - $basedir = ereg_replace ("$sep$", "", $basedir); - + + $basedir = ereg_replace ("$sep$", '', $basedir); + return $basedir; } - + /*! @function acl_check - @abstract Check ACL access to $file for $phpgw_info["user"]["account_id"]; + @abstract Check ACL access to $file for $GLOBALS['phpgw_info']["user"]["account_id"]; @param $file File to check access of @param $relatives Standard relativity array @param $operation Operation to check access to. In the form of a PHPGW_ACL defines bitmask. Default is read @param $must_exist Boolean. Set to True if $file must exist. Otherwise, we check the parent directory as well @result Boolean. True if access is ok, False otherwise */ - function acl_check ($file, $relatives = '', $operation = PHPGW_ACL_READ, $must_exist = False) { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + /* Accommodate special situations */ if ($this->override_acl) { return True; } - - $account_id = $phpgw_info["user"]["account_id"]; - $account_lid = $phpgw->accounts->id2name ($phpgw_info["user"]["account_id"]); - + + $account_id = $GLOBALS['phpgw_info']['user']['account_id']; + $account_lid = $GLOBALS['phpgw']->accounts->id2name ($GLOBALS['phpgw_info']['user']['account_id']); + $p = $this->path_parts ($file, array ($relatives[0])); - + /* Temporary, until we get symlink type files set up */ if ($p->outside) { return True; } - + /* If the file doesn't exist, we get ownership from the parent directory */ if (!$this->file_exists ($p->fake_full_path, array ($p->mask))) { @@ -966,10 +941,10 @@ { return False; } - + $file = $p->fake_leading_dirs; $p2 = $this->path_parts ($file, array ($p->mask)); - + if (!$this->file_exists ($file, array ($p->mask))) { return False; @@ -979,7 +954,7 @@ { $p2 = $p; } - + /* Read access is always allowed here, but nothing else is */ if ($file == "/" || $file == $this->fakebase) { @@ -992,38 +967,38 @@ return False; } } - + /* We don't use ls () to get owner_id as we normally would, because ls () calls acl_check (), which would create an infinite loop */ - $query = $phpgw->db->query ("SELECT owner_id FROM phpgw_vfs WHERE directory='$p2->fake_leading_dirs_clean' AND name='$p2->fake_name_clean'" . $this->extra_sql (VFS_SQL_SELECT), __LINE__, __FILE__); - $phpgw->db->next_record (); - $group_id = $phpgw->db->Record["owner_id"]; - + $query = $GLOBALS['phpgw']->db->query ("SELECT owner_id FROM phpgw_vfs WHERE directory='$p2->fake_leading_dirs_clean' AND name='$p2->fake_name_clean'" . $this->extra_sql (VFS_SQL_SELECT), __LINE__, __FILE__); + $GLOBALS['phpgw']->db->next_record (); + $group_id = $GLOBALS['phpgw']->db->Record['owner_id']; + /* They always have access to their own files */ if ($group_id == $account_id) { return True; } - + /* Check if they're in the group. If so, they have access */ - $memberships = $phpgw->accounts->membership ($account_id); - + $memberships = $GLOBALS['phpgw']->accounts->membership ($account_id); + if (is_array ($memberships)) { reset ($memberships); while (list ($num, $group_array) = @each ($memberships)) { - if ($group_id == $phpgw->accounts->name2id ($group_array["account_name"])) + if ($group_id == $GLOBALS['phpgw']->accounts->name2id ($group_array['account_name'])) { $group_ok = 1; break; } } } - + if (!$group_id) { if (!$group_id = $this->account_id) @@ -1031,11 +1006,11 @@ $group_id = 0; } } - - $acl = CreateObject ("phpgwapi.acl", $group_id); + + $acl = CreateObject ('phpgwapi.acl', $group_id); $acl->account_id = $group_id; $acl->read_repository (); - + $rights = $acl->get_rights ($account_id); if ($rights & $operation) { @@ -1050,45 +1025,42 @@ return False; } } - + /*! @function cd @abstract Change directory - @discussion To cd to the files root "/", use cd ("/", False, array (RELATIVE_NONE)); - @param $target default "/". directory to cd into. if "/" and $relative is True, uses "/home/"; + @discussion To cd to the files root '/', use cd ('/', False, array (RELATIVE_NONE)); + @param $target 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 ($target = "/", $relative = True, $relatives = '') + function cd ($target = '/', $relative = True, $relatives = '') { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + if ($relatives[0] & VFS_REAL) { $sep = SEP; } else { - $sep = "/"; + $sep = '/'; } - - if ($relative == "relative" || $relative == True) + + if ($relative == 'relative' || $relative == True) { /* if $target is "/" and $relative is set, we cd to the user/group home dir */ - if ($target == "/") + if ($target == '/') { $relatives[0] = RELATIVE_USER; $basedir = $this->getabsolutepath (False, array ($relatives[0]), True); } else { - $currentdir = $phpgw->common->appsession (); + $currentdir = $GLOBALS['phpgw']->common->appsession (); $basedir = $this->getabsolutepath ($currentdir . $sep . $target, array ($relatives[0]), True); } } @@ -1096,38 +1068,35 @@ { $basedir = $this->getabsolutepath ($target, array ($relatives[0])); } - - $phpgw->common->appsession ($basedir); - + + $GLOBALS['phpgw']->common->appsession ($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 ($full = True) { - global $phpgw; - - $currentdir = $phpgw->common->appsession (); - + $currentdir = $GLOBALS['phpgw']->common->appsession (); + if (!$full) { - $currentdir = ereg_replace ("^/", "", $currentdir); + $currentdir = ereg_replace ("^/", '', $currentdir); } - - if ($currentdir == "" && $full) + + if ($currentdir == '' && $full) { - $currentdir = "/"; + $currentdir = '/'; } - + return $currentdir; } - + /*! @function read @abstract return file contents @@ -1135,29 +1104,25 @@ @param $relatives Relativity array @result $contents Contents of $file, or False if file cannot be read */ - function read ($file, $relatives = '') { - global $phpgw; - global $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($file, array ($relatives[0])); - + if (!$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_READ)) { return False; } - - if ($fp = fopen ($p->real_full_path, "rb")) + + if ($fp = fopen ($p->real_full_path, 'rb')) { $contents = fread ($fp, filesize ($p->real_full_path)); fclose ($fp); - + return $contents; } else @@ -1165,7 +1130,7 @@ return False; } } - + /*! @function write @abstract write to a file @@ -1173,20 +1138,16 @@ @param $relatives Relativity array @param $contents contents @result Boolean True/False - */ - + */ function write ($file, $relatives = '', $contents) { - global $phpgw; - global $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } $p = $this->path_parts ($file, array ($relatives[0])); - + if ($this->file_exists ($p->fake_full_path, array ($p->mask))) { $acl_operation = PHPGW_ACL_EDIT; @@ -1196,32 +1157,32 @@ { $acl_operation = PHPGW_ACL_ADD; } - + if (!$this->acl_check ($p->fake_full_path, array ($p->mask), $acl_operation)) { return False; } - + umask(000); - + /* If $file doesn't exist, touch () creates both the file and the database entry If $file does exist, touch () sets the modification time and modified by */ $this->touch ($p->fake_full_path, array ($p->mask)); - + if ($fp = fopen ($p->real_full_path, "wb")) { fwrite ($fp, $contents, strlen ($contents)); fclose ($fp); - - $this->set_attributes ($p->fake_full_path, array ($p->mask), array ("size" => $this->get_size ($p->real_full_path, array (RELATIVE_NONE|VFS_REAL)))); - + + $this->set_attributes ($p->fake_full_path, array ($p->mask), array ('size' => $this->get_size ($p->real_full_path, array (RELATIVE_NONE|VFS_REAL)))); + if ($journal_operation) { $this->add_journal ($p->fake_full_path, array ($p->mask), $journal_operation); } - + return True; } else @@ -1229,7 +1190,7 @@ return False; } } - + /*! @function touch @abstract Create blank file $file or set the modification time and modified by of $file to current time and user @@ -1237,34 +1198,31 @@ @param $relatives Relativity array @result Boolean True/False */ - function touch ($file, $relatives = '') { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - $account_id = $phpgw_info["user"]["account_id"]; - $currentapp = $phpgw_info["flags"]["currentapp"]; - + $account_id = $GLOBALS['phpgw_info']['user']['account_id']; + $currentapp = $GLOBALS['phpgw_info']['flags']['currentapp']; + $p = $this->path_parts ($file, array ($relatives[0])); - + umask (000); - + /* PHP's touch function will automatically decide whether to create the file or set the modification time */ $rr = touch ($p->real_full_path); - + if ($p->outside) { return $rr; } - + /* We, however, have to decide this ourselves */ if ($this->file_exists ($p->fake_full_path, array ($p->mask))) { @@ -1272,8 +1230,15 @@ { return False; } - - $vr = $this->set_attributes ($p->fake_full_path, array ($p->mask), array ("modifiedby_id" => $account_id, "modified" => $this->now)); + + $vr = $this->set_attributes( + $p->fake_full_path, + array ($p->mask), + array ( + 'modifiedby_id' => $account_id, + 'modified' => $this->now + ) + ); } else { @@ -1281,15 +1246,25 @@ { return False; } - - $query = $phpgw->db->query ("INSERT INTO phpgw_vfs (owner_id, directory, name) VALUES ($this->working_id, '$p->fake_leading_dirs_clean', '$p->fake_name_clean')", __LINE__, __FILE__); - - $this->set_attributes ($p->fake_full_path, array ($p->mask), array ("createdby_id" => $account_id, "created" => $this->now, "size" => 0, "deleteable" => "Y", "app" => $currentapp)); + + $query = $GLOBALS['phpgw']->db->query ("INSERT INTO phpgw_vfs (owner_id, directory, name) VALUES ($this->working_id, '$p->fake_leading_dirs_clean', '$p->fake_name_clean')", __LINE__, __FILE__); + + $this->set_attributes( + $p->fake_full_path, + array ($p->mask), + array ( + 'createdby_id' => $account_id, + 'created' => $this->now, + 'size' => 0, + 'deleteable' => 'Y', + 'app' => $currentapp + ) + ); $this->correct_attributes ($p->fake_full_path, array ($p->mask)); $this->add_journal ($p->fake_full_path, array ($p->mask), VFS_OPERATION_CREATED); } - + if ($rr || $vr || $query) { return True; @@ -1299,7 +1274,7 @@ return False; } } - + /*! @function cp @abstract copy file @@ -1308,27 +1283,23 @@ @param $relatives Relativity array @result boolean True/False */ - function cp ($from, $to, $relatives = '') { - global $phpgw; - global $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT, RELATIVE_CURRENT); } - - $account_id = $phpgw_info["user"]["account_id"]; - + + $account_id = $GLOBALS['phpgw_info']['user']['account_id']; + $f = $this->path_parts ($from, array ($relatives[0])); $t = $this->path_parts ($to, array ($relatives[1])); - + if (!$this->acl_check ($f->fake_full_path, array ($f->mask), PHPGW_ACL_READ)) { return False; } - + if ($this->file_exists ($t->fake_full_path, array ($t->mask))) { if (!$this->acl_check ($t->fake_full_path, array ($t->mask), PHPGW_ACL_EDIT)) @@ -1342,88 +1313,110 @@ { return False; } - + } - + umask(000); - - if ($this->file_type ($f->fake_full_path, array ($f->mask)) != "Directory") + + if ($this->file_type ($f->fake_full_path, array ($f->mask)) != 'Directory') { if (!copy ($f->real_full_path, $t->real_full_path)) { return False; } - + if ($t->outside) { return True; } - + $size = filesize ($t->real_full_path); - + $ls_array = $this->ls ($f->fake_full_path, array ($f->mask), False, False, True); $record = $ls_array[0]; - + if ($this->file_exists ($to, array ($relatives[1]))) { - $query = $phpgw->db->query ("UPDATE phpgw_vfs SET owner_id='$this->working_id', directory='$t->fake_leading_dirs_clean', name='$t->fake_name_clean' WHERE owner_id='$this->working_id' AND directory='$t->fake_leading_dirs_clean' AND name='$t->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__); - - $this->set_attributes ($t->fake_full_path, array ($t->mask), array ("createdby_id" => $account_id, "created" => $this->now, "size" => $size, "mime_type" => $record["mime_type"], "deleteable" => $record["deleteable"], "comment" => $record["comment"], "app" => $record["app"])); - + $query = $GLOBALS['phpgw']->db->query ("UPDATE phpgw_vfs SET owner_id='$this->working_id', directory='$t->fake_leading_dirs_clean', name='$t->fake_name_clean' WHERE owner_id='$this->working_id' AND directory='$t->fake_leading_dirs_clean' AND name='$t->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__); + + $this->set_attributes( + $t->fake_full_path, + array ($t->mask), + array ( + 'createdby_id' => $account_id, + 'created' => $this->now, + 'size' => $size, + 'mime_type' => $record['mime_type'], + 'deleteable' => $record['deleteable'], + 'comment' => $record['comment'], + 'app' => $record['app'] + ) + ); $this->add_journal ($t->fake_full_path, array ($t->mask), VFS_OPERATION_EDITED); } else { $this->touch ($t->fake_full_path, array ($t->mask)); - - $this->set_attributes ($t->fake_full_path, array ($t->mask), array ("createdby_id" => $account_id, "created" => $this->now, "size" => $size, "mime_type" => $record["mime_type"], "deleteable" => $record["deleteable"], "comment" => $record["comment"], "app" => $record["app"])); + + $this->set_attributes( + $t->fake_full_path, + array ($t->mask), + array ( + 'createdby_id' => $account_id, + 'created' => $this->now, + 'size' => $size, + 'mime_type' => $record['mime_type'], + 'deleteable' => $record['deleteable'], + 'comment' => $record['comment'], + 'app' => $record['app'] + ) + ); } - $this->correct_attributes ($t->fake_full_path, array ($t->mask)); } else /* It's a directory */ { /* First, make the initial directory */ $this->mkdir ($to, array ($relatives[1])); - + /* Next, we create all the directories below the initial directory */ - $ls = $this->ls ($f->fake_full_path, array ($f->mask), True, "Directory"); - + $ls = $this->ls ($f->fake_full_path, array ($f->mask), True, 'Directory'); + while (list ($num, $entry) = each ($ls)) { - $newdir = ereg_replace ("^$f->fake_full_path", "$t->fake_full_path", $entry["directory"]); + $newdir = ereg_replace ("^$f->fake_full_path", "$t->fake_full_path", $entry['directory']); $this->mkdir ("$newdir/$entry[name]", array ($t->mask)); } - + /* Lastly, we copy the files over */ $ls = $this->ls ($f->fake_full_path, array ($f->mask)); - + while (list ($num, $entry) = each ($ls)) { - if ($entry["mime_type"] == "Directory") + if ($entry['mime_type'] == 'Directory') { continue; } - - $newdir = ereg_replace ("^$f->fake_full_path", "$t->fake_full_path", $entry["directory"]); + + $newdir = ereg_replace ("^$f->fake_full_path", "$t->fake_full_path", $entry['directory']); $this->cp ("$entry[directory]/$entry[name]", "$newdir/$entry[name]", array ($f->mask, $t->mask)); } } - + if (!$f->outside) { $this->add_journal ($f->fake_full_path, array ($f->mask), VFS_OPERATION_COPIED, NULL, $t->fake_full_path); } - + return True; } - + function copy ($from, $to, $relatives = '') { umask (000); return $this->cp ($from, $to, $relatives); } - + /*! @function mv @abstract move file/directory @@ -1432,32 +1425,28 @@ @param $relatives Relativity array @result boolean True/False */ - function mv ($from, $to, $relatives = '') { - global $phpgw; - global $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT, RELATIVE_CURRENT); } - - $account_id = $phpgw_info["user"]["account_id"]; - + + $account_id = $GLOBALS['phpgw_info']['user']['account_id']; + $f = $this->path_parts ($from, array ($relatives[0])); $t = $this->path_parts ($to, array ($relatives[1])); - + if (!$this->acl_check ($f->fake_full_path, array ($f->mask), PHPGW_ACL_READ) || !$this->acl_check ($f->fake_full_path, array ($f->mask), PHPGW_ACL_DELETE)) { return False; } - + if (!$this->acl_check ($t->fake_full_path, array ($t->mask), PHPGW_ACL_ADD)) { return False; } - + if ($this->file_exists ($t->fake_full_path, array ($t->mask))) { if (!$this->acl_check ($t->fake_full_path, array ($t->mask), PHPGW_ACL_EDIT)) @@ -1465,28 +1454,28 @@ return False; } } - + umask (000); - + /* We can't move directories into themselves */ - if (($this->file_type ($f->fake_full_path, array ($f->mask)) == "Directory") && ereg ("^$f->fake_full_path", $t->fake_full_path)) + if (($this->file_type ($f->fake_full_path, array ($f->mask)) == 'Directory') && ereg ("^$f->fake_full_path", $t->fake_full_path)) { - if (($t->fake_full_path == $f->fake_full_path) || substr ($t->fake_full_path, strlen ($f->fake_full_path), 1) == "/") + if (($t->fake_full_path == $f->fake_full_path) || substr ($t->fake_full_path, strlen ($f->fake_full_path), 1) == '/') { return False; } } - + if ($this->file_exists ($f->fake_full_path, array ($f->mask))) { /* We get the listing now, because it will change after we update the database */ $ls = $this->ls ($f->fake_full_path, array ($f->mask)); - + if ($this->file_exists ($t->fake_full_path, array ($t->mask))) { $this->rm ($t->fake_full_path, array ($t->mask)); } - + /* 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 @@ -1495,7 +1484,7 @@ { $this->add_journal ($f->fake_full_path, array ($f->mask), VFS_OPERATION_MOVED, $f->fake_full_path, $t->fake_full_path); } - + /* If the from file is outside, it won't have a database entry, so we have to touch it and find the size @@ -1503,20 +1492,27 @@ if ($f->outside) { $size = filesize ($f->real_full_path); - + $this->touch ($t->fake_full_path, array ($t->mask)); - $query = $phpgw->db->query ("UPDATE phpgw_vfs SET size=$size WHERE directory='$t->fake_leading_dirs_clean' AND name='$t->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__); + $query = $GLOBALS['phpgw']->db->query ("UPDATE phpgw_vfs SET size=$size WHERE directory='$t->fake_leading_dirs_clean' AND name='$t->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__); } elseif (!$t->outside) { - $query = $phpgw->db->query ("UPDATE phpgw_vfs SET name='$t->fake_name_clean', directory='$t->fake_leading_dirs_clean' WHERE directory='$f->fake_leading_dirs_clean' AND name='$f->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__); + $query = $GLOBALS['phpgw']->db->query ("UPDATE phpgw_vfs SET name='$t->fake_name_clean', directory='$t->fake_leading_dirs_clean' WHERE directory='$f->fake_leading_dirs_clean' AND name='$f->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__); } - - $this->set_attributes ($t->fake_full_path, array ($t->mask), array ("modifiedby_id" => $account_id, modified => $this->now)); + + $this->set_attributes( + $t->fake_full_path, + array ($t->mask), + array ( + 'modifiedby_id' => $account_id, + 'modified' => $this->now + ) + ); $this->correct_attributes ($t->fake_full_path, array ($t->mask)); - + $rr = rename ($f->real_full_path, $t->real_full_path); - + /* This removes the original entry from the database The actual file is already deleted because of the rename () above @@ -1530,36 +1526,35 @@ { return False; } - - if ($this->file_type ($t->fake_full_path, array ($t->mask)) == "Directory") + + if ($this->file_type ($t->fake_full_path, array ($t->mask)) == 'Directory') { /* We got $ls from above, before we renamed the directory */ while (list ($num, $entry) = each ($ls)) { - $newdir = ereg_replace ("^$f->fake_full_path", $t->fake_full_path, $entry["directory"]); + $newdir = ereg_replace ("^$f->fake_full_path", $t->fake_full_path, $entry['directory']); $newdir_clean = $this->db_clean ($newdir); - - $query = $phpgw->db->query ("UPDATE phpgw_vfs SET directory='$newdir_clean' WHERE file_id='$entry[file_id]'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__); + + $query = $GLOBALS['phpgw']->db->query ("UPDATE phpgw_vfs SET directory='$newdir_clean' WHERE file_id='$entry[file_id]'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__); $this->correct_attributes ("$newdir/$entry[name]", array ($t->mask)); } } - + $this->add_journal ($t->fake_full_path, array ($t->mask), VFS_OPERATION_MOVED, $f->fake_full_path, $t->fake_full_path); - + return True; } - + /*! @function move @abstract shortcut to mv */ - function move ($from, $to, $relatives = '') { umask (000); return $this->mv ($from, $to, $relatives); } - + /*! @function rm @abstract delete file/directory @@ -1567,28 +1562,24 @@ @param $relatives Relativity array @result boolean True/False */ - function rm ($string, $relatives = '') { - global $phpgw; - global $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($string, array ($relatives[0])); - + if (!$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_DELETE)) { return False; } - + if (!$this->file_exists ($string, array ($relatives[0]))) { $rr = unlink ($p->real_full_path); - + if ($rr) { return True; @@ -1598,14 +1589,14 @@ return False; } } - - if ($this->file_type ($string, array ($relatives[0])) != "Directory") + + if ($this->file_type ($string, array ($relatives[0])) != 'Directory') { $this->add_journal ($p->fake_full_path, array ($p->mask), VFS_OPERATION_DELETED); - - $query = $phpgw->db->query ("DELETE FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_DELETE), __LINE__, __FILE__); + + $query = $GLOBALS['phpgw']->db->query ("DELETE FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_DELETE), __LINE__, __FILE__); $rr = unlink ($p->real_full_path); - + if ($query || $rr) { return True; @@ -1618,62 +1609,61 @@ else { $ls = $this->ls ($p->fake_full_path, array ($p->mask)); - + /* First, we cycle through the entries and delete the files */ while (list ($num, $entry) = each ($ls)) { - if ($entry["mime_type"] == "Directory") + if ($entry['mime_type'] == 'Directory') { continue; } - + $this->rm ("$entry[directory]/$entry[name]", array ($p->mask)); } - + /* Now we cycle through again and delete the directories */ reset ($ls); while (list ($num, $entry) = each ($ls)) { - if ($entry["mime_type"] != "Directory") + if ($entry['mime_type'] != 'Directory') { continue; } - + /* Only the best in confusing recursion */ $this->rm ("$entry[directory]/$entry[name]", array ($p->mask)); } - + /* If the directory is linked, we delete the placeholder directory */ $ls_array = $this->ls ($p->fake_full_path, array ($p->mask), False, False, True); $link_info = $ls_array[0]; - - if ($link_info["link_directory"] && $link_info["link_name"]) + + if ($link_info['link_directory'] && $link_info['link_name']) { - $path = $this->path_parts ($link_info["directory"] . "/" . $link_info["name"], array ($p->mask), True, True); + $path = $this->path_parts ($link_info['directory'] . '/' . $link_info['name'], array ($p->mask), True, True); rmdir ($path->real_full_path); } - + /* Last, we delete the directory itself */ $this->add_journal ($p->fake_full_path, array ($p->mask), VFS_OPERATION_DELETED); - - $query = $phpgw->db->query ("DELETE FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_DELETE), __LINE__, __FILE__); - + + $query = $GLOBALS['phpgw']->db->query ("DELETE FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_DELETE), __LINE__, __FILE__); + rmdir ($p->real_full_path); - + return True; } } - + /*! @function delete @abstract shortcut to rm */ - function delete ($string, $relatives = '') { return $this->rm ($string, $relatives); } - + /*! @function mkdir @abstract make a new directory @@ -1681,58 +1671,64 @@ @param $relatives Relativity array @result boolean True on success */ - function mkdir ($dir, $relatives = '') { - global $phpgw; - global $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - - $account_id = $phpgw_info["user"]["account_id"]; - $currentapp = $phpgw_info["flags"]["currentapp"]; - + + $account_id = $GLOBALS['phpgw_info']['user']['account_id']; + $currentapp = $GLOBALS['phpgw_info']['flags']['currentapp']; + $p = $this->path_parts ($dir, array ($relatives[0])); - + if (!$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_ADD)) { return False; } - + /* We don't allow /'s in dir names, of course */ if (ereg ("/", $p->fake_name)) { return False; } - + umask (000); - + if (!mkdir ($p->real_full_path, 0770)) { return False; } - + if (!$this->file_exists ($p->fake_full_path, array ($p->mask))) { - $query = $phpgw->db->query ("INSERT INTO phpgw_vfs (owner_id, name, directory) VALUES ($this->working_id, '$p->fake_name_clean', '$p->fake_leading_dirs_clean')", __LINE__, __FILE__); - - $this->set_attributes ($p->fake_full_path, array ($p->mask), array ("createdby_id" => $account_id, "size" => 4096, "mime_type" => "Directory", "created" => $this->now, deleteable => "Y", "app" => $currentapp)); + $query = $GLOBALS['phpgw']->db->query ("INSERT INTO phpgw_vfs (owner_id, name, directory) VALUES ($this->working_id, '$p->fake_name_clean', '$p->fake_leading_dirs_clean')", __LINE__, __FILE__); + $this->set_attributes( + $p->fake_full_path, + array ($p->mask), + array ( + 'createdby_id' => $account_id, + 'size' => 4096, + 'mime_type' => 'Directory', + 'created' => $this->now, + 'deleteable' => 'Y', + 'app' => $currentapp + ) + ); $this->correct_attributes ($p->fake_full_path, array ($p->mask)); - + $this->add_journal ($p->fake_full_path, array ($p->mask), VFS_OPERATION_CREATED); } else { return False; } - + return True; } - + /*! @function make_link @abstract Make a link from virtual directory $vdir to real directory $rdir @@ -1743,47 +1739,50 @@ @param $relatives Relativity array @result Boolean True/False */ - function make_link ($vdir, $rdir, $relatives = '') { - global $phpgw; - global $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT, RELATIVE_CURRENT); } - - $account_id = $phpgw_info["user"]["account_id"]; - $currentapp = $phpgw_info["flags"]["currentapp"]; - + + $account_id = $GLOBALS['phpgw_info']['user']['account_id']; + $currentapp = $GLOBALS['phpgw_info']['flags']['currentapp']; + $vp = $this->path_parts ($vdir, array ($relatives[0])); $rp = $this->path_parts ($rdir, array ($relatives[1])); - + if (!$this->acl_check ($vp->fake_full_path, array ($vp->mask), PHPGW_ACL_ADD)) { return False; } - + if ((!$this->file_exists ($rp->real_full_path, array ($rp->mask))) && !mkdir ($rp->real_full_path, 0770)) { return False; } - + if (!$this->mkdir ($vp->fake_full_path, array ($vp->mask))) { return False; } - + $size = $this->get_size ($rp->real_full_path, array ($rp->mask)); - - $this->set_attributes ($vp->fake_full_path, array ($vp->mask), array ("link_directory" => $rp->real_leading_dirs, "link_name" => $rp->real_name, "size" => $size)); - + + $this->set_attributes( + $vp->fake_full_path, + array ($vp->mask), + array ( + 'link_directory' => $rp->real_leading_dirs, + 'link_name' => $rp->real_name, + 'size' => $size + ) + ); $this->correct_attributes ($vp->fake_full_path, array ($vp->mask)); - + return True; } - + /*! @function set_attributes @abstract Update database entry for $file with the attributes in $attributes @@ -1806,12 +1805,8 @@ link_name version */ - function set_attributes ($file, $relatives = '', $attributes = '') { - global $phpgw; - global $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); @@ -1821,9 +1816,9 @@ { $attributes = array (); } - + $p = $this->path_parts ($file, array ($relatives[0])); - + /* This is kind of trivial, given that set_attributes () can change owner_id, size, etc. @@ -1832,23 +1827,28 @@ { return False; } - + if (!$this->file_exists ($file, array ($relatives[0]))) { return False; } - + /* All this voodoo just decides which attributes to update depending on if the attribute was supplied in the $attributes array */ - + $ls_array = $this->ls ($p->fake_full_path, array ($p->mask), False, False, True); $record = $ls_array[0]; - - $attribute_names = array ("owner_id", "createdby_id", "modifiedby_id", "created", "modified", "size", "mime_type", "deleteable", "comment", "app", "link_directory", "link_name", "version"); - - $sql = "UPDATE phpgw_vfs SET "; + + $attribute_names = array( + 'owner_id', 'createdby_id', 'modifiedby_id', + 'created', 'modified', 'size', 'mime_type', + 'deleteable', 'comment', 'app', + 'link_directory', 'link_name', 'version' + ); + + $sql = 'UPDATE phpgw_vfs SET '; $change_attributes = 0; while (list ($num, $attribute) = each ($attribute_names)) @@ -1856,23 +1856,23 @@ if (isset ($attributes[$attribute])) { $$attribute = $attributes[$attribute]; - + /* Indicate that the EDITED_COMMENT operation needs to be journaled, but only if the comment changed */ - if ($attribute == "comment" && $attributes[$attribute] != $record[$attribute]) + if ($attribute == 'comment' && $attributes[$attribute] != $record[$attribute]) { $edited_comment = 1; } - + $$attribute = $this->db_clean ($$attribute); if ($change_attributes > 0) { - $sql .= ", "; + $sql .= ', '; } - + $sql .= "$attribute='" . $$attribute . "'"; $change_attributes++; @@ -1881,16 +1881,16 @@ $sql .= " WHERE file_id='$record[file_id]'"; $sql .= $this->extra_sql (VFS_SQL_UPDATE); - - $query = $phpgw->db->query ($sql, __LINE__, __FILE__); - + + $query = $GLOBALS['phpgw']->db->query ($sql, __LINE__, __FILE__); + if ($query) { if ($edited_comment) { $this->add_journal ($p->fake_full_path, array ($p->mask), VFS_OPERATION_EDITED_COMMENT); } - + return True; } else @@ -1898,7 +1898,7 @@ return False; } } - + /*! @function correct_attributes @abstract Set the correct attributes for $string (e.g. owner) @@ -1906,39 +1906,36 @@ @param $relatives Relativity array @result Boolean True/False */ - function correct_attributes ($string, $relatives = '') { - global $phpgw; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($string, array ($relatives[0])); - - if ($p->fake_leading_dirs != $this->fakebase && $p->fake_leading_dirs != "/") + + if ($p->fake_leading_dirs != $this->fakebase && $p->fake_leading_dirs != '/') { $ls_array = $this->ls ($p->fake_leading_dirs, array ($p->mask), False, False, True); - $this->set_attributes ($p->fake_full_path, array ($p->mask), array ("owner_id" => $ls_array[0]["owner_id"])); - + $this->set_attributes ($p->fake_full_path, array ($p->mask), array ('owner_id' => $ls_array[0]['owner_id'])); + return True; } elseif (preg_match ("+^$this->fakebase\/(.*)$+U", $p->fake_full_path, $matches)) { - $this->set_attributes ($p->fake_full_path, array ($p->mask), array ("owner_id" => $phpgw->accounts->name2id ($matches[1]))); - + $this->set_attributes ($p->fake_full_path, array ($p->mask), array ("owner_id" => $GLOBALS['phpgw']->accounts->name2id ($matches[1]))); + return True; } else { - $this->set_attributes ($p->fake_full_name, array ($p->mask), array ("owner_id" => 0)); - + $this->set_attributes ($p->fake_full_name, array ($p->mask), array ('owner_id' => 0)); + return True; } } - + /*! @function file_type @abstract return file/dir type (MIME or other) @@ -1946,47 +1943,44 @@ @param $relatives Relativity array @result MIME type, "Directory", or nothing if MIME type is not known */ - function file_type ($file, $relatives = '') { - global $phpgw; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($file, array ($relatives[0])); - + if (!$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_READ, True)) { return False; } - + if ($p->outside) { if (is_dir ($p->real_full_path)) { - return ("Directory"); + return ('Directory'); } - + /* We don't return an empty string here, because it may still match with a database query because of linked directories */ } - + /* We don't use ls () because it calls file_type () to determine if it has been passed a directory */ - $query = $phpgw->db->query ("SELECT mime_type FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_SELECT), __LINE__, __FILE__); - $phpgw->db->next_record (); - $mime_type = $phpgw->db->Record["mime_type"]; - + $query = $GLOBALS['phpgw']->db->query ("SELECT mime_type FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_SELECT), __LINE__, __FILE__); + $GLOBALS['phpgw']->db->next_record (); + $mime_type = $GLOBALS['phpgw']->db->Record['mime_type']; + return ($mime_type); } - + /*! @function file_exists @abstract check if file/directory exists @@ -1994,28 +1988,25 @@ @param $relatives Relativity array @result Boolean True/False */ - function file_exists ($string, $relatives = '') { - global $phpgw; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($string, array ($relatives[0])); - + if ($p->outside) { $rr = file_exists ($p->real_full_path); - + return $rr; } - - $query = $phpgw->db->query ("SELECT name FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_SELECT), __LINE__, __FILE__); - - if ($phpgw->db->next_record ()) + + $query = $GLOBALS['phpgw']->db->query ("SELECT name FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_SELECT), __LINE__, __FILE__); + + if ($GLOBALS['phpgw']->db->next_record ()) { return True; } @@ -2024,7 +2015,7 @@ return False; } } - + /*! @function get_size @abstract Return size of $string @@ -2033,23 +2024,20 @@ @param $checksubdirs Boolean, recursively add the size of all sub directories as well? @result Size of $string in bytes */ - function get_size ($string, $relatives = '', $checksubdirs = True) { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($string, array ($relatives[0])); - + if (!$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_READ, True)) { return False; } - + /* 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 @@ -2057,36 +2045,36 @@ if ($p->outside) { $size = filesize ($p->real_full_path); - + return $size; } - + $ls_array = $this->ls ($p->fake_full_path, array ($p->mask), $checksubdirs, False, !$checksubdirs); - + while (list ($num, $file_array) = each ($ls_array)) { /* Make sure the file is in the directory we want, and not some deeper nested directory with a similar name */ - if (@!ereg ("^$p->fake_full_path", $file_array["directory"])) + if (@!ereg ("^$p->fake_full_path", $file_array['directory'])) { continue; } - - $size += $file_array["size"]; + + $size += $file_array['size']; } - + if ($checksubdirs) { - $query = $phpgw->db->query ("SELECT size FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_SELECT)); - $phpgw->db->next_record (); - $size += $phpgw->db->Record[0]; + $query = $GLOBALS['phpgw']->db->query ("SELECT size FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (VFS_SQL_SELECT)); + $GLOBALS['phpgw']->db->next_record (); + $size += $GLOBALS['phpgw']->db->Record[0]; } - + return $size; } - + /*! @function checkperms @abstract Check if $this->working_id has write access to create files in $dir @@ -2095,18 +2083,15 @@ @param $relatives Relativity array @result Boolean True/False */ - function checkperms ($dir, $relatives = '') { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($dir, array ($relatives[0])); - + if (!$this->acl_check ($p->fake_full_path, array ($p->mask), PHPGW_ACL_ADD)) { return False; @@ -2116,7 +2101,7 @@ return True; } } - + /*! @function ls @abstract get directory listing or info about a single file @@ -2131,45 +2116,42 @@ @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. */ - - function ls ($dir = False, $relatives = '', $checksubdirs = True, $mime_type = False, $nofiles = False, $orderby = "directory") + function ls ($dir = False, $relatives = '', $checksubdirs = True, $mime_type = False, $nofiles = False, $orderby = 'directory') { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($dir, array ($relatives[0])); $dir = $p->fake_full_path; - + /* If they pass us a file or $nofiles is set, return the info for $dir only */ - if (((($type = $this->file_type ($dir, array ($p->mask))) != "Directory") || ($nofiles)) && !$p->outside) + if (((($type = $this->file_type ($dir, array ($p->mask))) != 'Directory') || ($nofiles)) && !$p->outside) { /* SELECT all, the, attributes */ - $sql = "SELECT "; - + $sql = 'SELECT '; + reset ($this->attributes); while (list ($num, $attribute) = each ($this->attributes)) { if ($num) { - $sql .= ", "; + $sql .= ', '; } - + $sql .= "$attribute"; } - + $sql .= " FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'"; - + $sql .= $this->extra_sql (VFS_SQL_SELECT); - - $query = $phpgw->db->query ($sql, __LINE__, __FILE__); - - $phpgw->db->next_record (); - $record = $phpgw->db->Record; - + + $query = $GLOBALS['phpgw']->db->query ($sql, __LINE__, __FILE__); + + $GLOBALS['phpgw']->db->next_record (); + $record = $GLOBALS['phpgw']->db->Record; + /* We return an array of one array to maintain the standard */ $rarray = array (); reset ($this->attributes); @@ -2177,24 +2159,24 @@ { $rarray[0][$attribute] = $record[$attribute]; } - + return $rarray; } - + //WIP - this should recurse using the same options the virtual part of ls () does /* If $dir is outside the virutal root, we have to check the file system manually */ if ($p->outside) { - if ($this->file_type ($p->fake_full_path, array ($p->mask)) == "Directory" && !$nofiles) + if ($this->file_type ($p->fake_full_path, array ($p->mask)) == 'Directory' && !$nofiles) { $dir_handle = opendir ($p->real_full_path); while ($filename = readdir ($dir_handle)) { - if ($filename == "." || $filename == "..") + if ($filename == '.' || $filename == '..') { continue; } - + $rarray[] = $this->get_real_info ($p->real_full_path . SEP . $filename, array ($p->mask)); } } @@ -2202,14 +2184,14 @@ { $rarray[] = $this->get_real_info ($p->real_full_path, array ($p->mask)); } - + return $rarray; } - + /* $dir's not a file, is inside the virtual root, and they want to check subdirs */ /* SELECT all, the, attributes FROM phpgw_vfs WHERE file=$dir */ - $sql = "SELECT "; - + $sql = 'SELECT '; + reset ($this->attributes); while (list ($num, $attribute) = each ($this->attributes)) { @@ -2217,56 +2199,55 @@ { $sql .= ", "; } - + $sql .= "$attribute"; } - + $dir_clean = $this->db_clean ($dir); $sql .= " FROM phpgw_vfs WHERE directory LIKE '$dir_clean%'"; $sql .= $this->extra_sql (VFS_SQL_SELECT); - + if ($mime_type) { $sql .= " AND mime_type='$mime_type'"; } - + $sql .= " ORDER BY $orderby"; - - $query = $phpgw->db->query ($sql, __LINE__, __FILE__); - + + $query = $GLOBALS['phpgw']->db->query ($sql, __LINE__, __FILE__); + $rarray = array (); - for ($i = 0; $phpgw->db->next_record (); $i++) + for ($i = 0; $GLOBALS['phpgw']->db->next_record (); $i++) { - $record = $phpgw->db->Record; - + $record = $GLOBALS['phpgw']->db->Record; + /* Further checking on the directory. This makes sure /home/user/test won't match /home/user/test22 */ - if (!ereg ("^$dir(/|$)", $record["directory"])) + if (!ereg ("^$dir(/|$)", $record['directory'])) { continue; } - + /* If they want only this directory, then $dir should end without a trailing / */ - if (!$checksubdirs && ereg ("^$dir/", $record["directory"])) + if (!$checksubdirs && ereg ("^$dir/", $record['directory'])) { continue; } - + reset ($this->attributes); while (list ($num, $attribute) = each ($this->attributes)) { $rarray[$i][$attribute] = $record[$attribute]; } } - + return $rarray; } - + /*! @function dir @abstract shortcut to ls */ - - function dir ($dir = False, $relatives = '', $checksubdirs = True, $mime_type = False, $nofiles = False, $orderby = "directory") + function dir ($dir = False, $relatives = '', $checksubdirs = True, $mime_type = False, $nofiles = False, $orderby = 'directory') { return $this->ls ($dir, $relatives, $checksubdirs, $mime_type, $nofiles, $orderby); } @@ -2374,18 +2355,15 @@ @param $relatives Relativity array @result Boolean True/False */ - function update_real ($string, $relatives = '') { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($string, array ($relatives[0])); - + if (file_exists ($p->real_full_path)) { if (is_dir ($p->real_full_path)) @@ -2393,19 +2371,19 @@ $dir_handle = opendir ($p->real_full_path); while ($filename = readdir ($dir_handle)) { - if ($filename == "." || $filename == "..") + if ($filename == '.' || $filename == '..') { continue; } - - $rarray[] = $this->get_real_info ($p->fake_full_path . "/" . $filename, array (RELATIVE_NONE)); + + $rarray[] = $this->get_real_info ($p->fake_full_path . '/' . $filename, array (RELATIVE_NONE)); } } else { $rarray[] = $this->get_real_info ($p->fake_full_path, array (RELATIVE_NONE)); } - + if (!is_array ($rarray)) { $rarray = array (); @@ -2413,15 +2391,15 @@ while (list ($num, $file_array) = each ($rarray)) { - $p2 = $this->path_parts ($file_array["directory"] . "/" . $file_array["name"], array (RELATIVE_NONE)); - + $p2 = $this->path_parts ($file_array['directory'] . '/' . $file_array['name'], array (RELATIVE_NONE)); + /* Note the mime_type. This can be "Directory", which is how we create directories */ - $set_attributes_array = array ("size" => $file_array["size"], "mime_type" => $file_array["mime_type"]); - + $set_attributes_array = array ('size' => $file_array['size'], 'mime_type' => $file_array['mime_type']); + if (!$this->file_exists ($p2->fake_full_path, array (RELATIVE_NONE))) { $this->touch ($p2->fake_full_path, array (RELATIVE_NONE)); - + $this->set_attributes ($p2->fake_full_path, array (RELATIVE_NONE), $set_attributes_array); } else @@ -2431,33 +2409,34 @@ } } } - - + /* Helper functions */ - + /* This fetchs all available file system information for $string (not using the database) */ function get_real_info ($string, $relatives = '') { - global $phpgw, $phpgw_info; - if (!is_array ($relatives)) { $relatives = array (RELATIVE_CURRENT); } - + $p = $this->path_parts ($string, array ($relatives[0])); - + if (is_dir ($p->real_full_path)) { - $mime_type = "Directory"; + $mime_type = 'Directory'; } - + $size = filesize ($p->real_full_path); - - $rarray = array ("directory" => $p->fake_leading_dirs, "name" => $p->fake_name, "size" => $size, "mime_type" => $mime_type); - + + $rarray = array( + 'directory' => $p->fake_leading_dirs, + 'name' => $p->fake_name, + 'size' => $size, + 'mime_type' => $mime_type + ); + return ($rarray); } } - - ?> +?>