diff --git a/OwnCloudPlugin.class.php b/OwnCloudPlugin.class.php index 20c252a30a30cf4721f53df8a660f5340f8050b7..0332d44284e1833077296198e24bce1599993633 100755 --- a/OwnCloudPlugin.class.php +++ b/OwnCloudPlugin.class.php @@ -170,4 +170,54 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin { return UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_ACTIVATED; } + protected function getType($id) + { + $parts = parse_url(UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_ENDPOINT); + $url = $parts['scheme'] + ."://" + .$parts['host'] + .($parts['port'] ? ":".$parts['port'] : "") + .($parts['path'] ?: ""); + if ($url[strlen($url) - 1] !== "/") { + $url .= "/"; + } + $webdav = $url . "remote.php/webdav/"; + $root = "remote.php/webdav/".$this->id; + $header = array(); + $header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken(); + $r = curl_init(); + curl_setopt($r, CURLOPT_CUSTOMREQUEST, "PROPFIND"); + curl_setopt($r, CURLOPT_URL, $webdav."/".$id); + curl_setopt($r, CURLOPT_HTTPHEADER, ($header)); + curl_setopt($r, CURLOPT_RETURNTRANSFER, 1); + $xml = curl_exec($r); + curl_close($r); + $doc = new DOMDocument(); + $doc->loadXML($xml); + + foreach ($doc->getElementsByTagNameNS("DAV:","response") as $file) { + foreach ($file->childNodes as $node) { + if ($node->tagName === "d:propstat") { + foreach ($node->childNodes as $prop) { + foreach ($prop->childNodes as $attr) { + if ($attr->tagName === "d:resourcetype") { + $file_attributes['type'] = $attr->childNodes[0] && $attr->childNodes[0]->tagName === "d:collection" ? "folder" : "file"; + } + } + } + } + } + } + return $file_attributes['type']; + } + + public function isFolder($id) + { + return $this->getType($id) == 'folder'; + } + + public function isFile($id) + { + return $this->getType($id) == 'file'; + } } diff --git a/classes/OwncloudFolder.class.php b/classes/OwncloudFolder.class.php index b723c8965438f0c8982b32c81ce2e42fe75cd81d..2c40f72de8edbac3dbc752a5ef443eb530c3b718 100644 --- a/classes/OwncloudFolder.class.php +++ b/classes/OwncloudFolder.class.php @@ -298,7 +298,8 @@ class OwncloudFolder extends VirtualFolderType { 'id' => ($this->id ? $this->id."/" : "").$file_attributes['name'], 'name' => $file_attributes['name'], 'parent_id' => $this->id, - 'range_type' => $this->plugin_id + 'range_type' => $this->plugin_id, + 'range_id' => 'OwnCloudPlugin' ), $this->plugin_id); } else { $this->files[] = (object) array(