storagePath = $storagePath; } public function getPluginName() { return 'files'; } public function getPluginInfo() { return [ 'name' => $this->getPluginName(), 'description' => 'Files support', 'link' => '' ]; } public function initialize(\Sabre\DAV\Server $server) { $this->server = $server; $this->server->on('propFind', [$this, 'propFind']); } public function propFind(\Sabre\DAV\PropFind $propFind, \Sabre\DAV\INode $node) { $propFind->handle( '{DAV:}getcontenttype', function() use ($propFind) { $mimes = new \Mimey\MimeTypes; return $mimes->getExtension(pathinfo($propFind->getPath(), PATHINFO_EXTENSION)); } ); } } class FilesCollection extends \Sabre\DAVACL\FS\HomeCollection { public $collectionName = 'files'; function getChildForPrincipal(array $principalInfo) { $owner = $principalInfo['uri']; $acl = [ [ 'privilege' => '{DAV:}read', 'principal' => $owner, 'protected' => true, ], [ 'privilege' => '{DAV:}write', 'principal' => $owner, 'protected' => true, ], ]; list(, $principalBaseName) = \Sabre\Uri\split($owner); $path = $this->storagePath.'/'.$principalBaseName; if (!is_dir($path)) { mkdir($path); } $out = new Directory($path, $acl, $owner); $out->setRelativePath($this->storagePath); return $out; } } class Directory extends \Sabre\DAVACL\FS\Collection { protected static $relativePath = null; public function getChild($name) { $path = $this->path.'/'.$name; if (!file_exists($path)) { throw new \Sabre\DAV\Exception\NotFound('File does not exist!'); } if ('.' === $name || '..' === $name) { throw new \Sabre\DAV\Exception\Forbidden('Permission denied to . and ..'); } if (is_dir($path)) { return new self($path, $this->acl, $this->owner); } else { return new \Sabre\DAVACL\FS\File($path, $this->acl, $this->owner); } } public function setRelativePath($relativePath) { self::$relativePath = $relativePath; } public static function getRelativePath() { return self::$relativePath; } private function getDirSize($path){ $totalbytes = 0; $path = realpath($path); if($path!==false && $path!='' && file_exists($path)){ foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)) as $object){ $totalbytes += $object->getSize(); } } return $totalbytes; } }