current_user = $user; $this->folder_path = $folderpath; return true; } public function setFolderPath($folder){ $this->folder_path = $folder; } public function setCurrentUser($user){ $this->current_user = $user; } protected function _getRoot($user, $folderpath, $visbility){ $folder_array = explode('/', $this->folder_path); $sql = $vfsdb->prepare("SELECT id FROM files WHERE parent=0 AND type='DIRECTORY' and owner = %s " . $visibility . ";", $this->owner); $root_db = $vfsdb->doQuery($sql); $root_ar = $root_db->fetch_array(MYSQLI_ASSOC); $root_id = $root_ar["id"]; return $root_id; } public function getId($user = NULL, $folder = NULL){ global $vfsuser; if ( is_null($user) ) $user = $this->current_user; if ( is_null($folder) ) $folder = $this->folder_path; $this->userid = $vfsuser->getUserId(); # checks if the current user is the actual owner if ( $vfsuser->isLoggedIn() && $_SESSION["userid"] == $this->userid ) $visibility = ""; else $visibility = " AND visibility='PUBLIC'"; $tmp_length = count($folder); if ( empty($folder[$tmp_length-1]) ) $length = $tmp_length-1; else $length = $tmp_length; $parentdir = $this->_getRoot($user, $folder, $visibility); if ( empty($folder[0]) ) return $parentdir; for ( $i=0; $i<$length, $i++ ) { $sql = $vfsdb->prepare("SELECT id, parent FROM files WHERE owner = %d AND parent = %d AND name = %s ".$visibility. ";", $this->userid, $parentdir, $folder[$i]); $parentdir_db = $vfsdb->doQuery($sql); $prim_id = $parentdir_db->fetch_array(MYSQLI_ASSOC); if ( $parentdir != $prim_id["parent"] ) return false; $parentdir = $prim_id["parent"]; } # returns the primary key from the last entry in the $folder array return $parentdir; } }