作者:Kevin-Z
项目:vaneDis
/**
* This method is called before any HTTP method and validates there is enough free space to store the file
*
* @param string $uri
* @param null $data
* @throws \Sabre\DAV\Exception\InsufficientStorage
* @return bool
*/
public function checkQuota($uri, $data = null)
{
$length = $this->getLength();
if ($length) {
if (substr($uri, 0, 1) !== '/') {
$uri = '/' . $uri;
}
list($parentUri, $newName) = \Sabre\HTTP\URLUtil::splitPath($uri);
if (is_null($parentUri)) {
$parentUri = '';
}
$req = $this->server->httpRequest;
if ($req->getHeader('OC-Chunked')) {
$info = \OC_FileChunking::decodeName($newName);
$chunkHandler = new \OC_FileChunking($info);
// subtract the already uploaded size to see whether
// there is still enough space for the remaining chunks
$length -= $chunkHandler->getCurrentSize();
}
$freeSpace = $this->getFreeSpace($parentUri);
if ($freeSpace !== \OCP\Files\FileInfo::SPACE_UNKNOWN && $length > $freeSpace) {
if (isset($chunkHandler)) {
$chunkHandler->cleanup();
}
throw new \Sabre\DAV\Exception\InsufficientStorage();
}
}
return true;
}
作者:enoch8
项目:owncloud-testserve
/**
* Our PROPFIND handler
*
* Here we set a contenttype, if the node didn't already have one.
*
* @param PropFind $propFind
* @param INode $node
* @return void
*/
function propFind(PropFind $propFind, INode $node)
{
$propFind->handle('{DAV:}getcontenttype', function () use($propFind) {
list(, $fileName) = URLUtil::splitPath($propFind->getPath());
return $this->getContentType($fileName);
});
}
作者:GitHubUser423
项目:cor
private function convertPrincipal($principal, $toV2)
{
list(, $name) = URLUtil::splitPath($principal);
if ($toV2) {
return "principals/users/{$name}";
}
return "principals/{$name}";
}
作者:BlaBlaNe
项目:hubzill
/**
* Renames the node
*
* @param string $name The new name
* @return void
*/
function setName($name)
{
list($parentPath, ) = URLUtil::splitPath($this->path);
list(, $newName) = URLUtil::splitPath($name);
$newPath = $parentPath . '/' . $newName;
rename($this->path, $newPath);
$this->path = $newPath;
}
作者:sebbie4
项目:casebo
/**
* Renames the node
*
* @param string $name The new name
* @return void
*/
public function setName($name)
{
list($parentPath, ) = URLUtil::splitPath($this->path);
list(, $newName) = URLUtil::splitPath($name);
$newPath = $parentPath . '/' . $newName;
Utils::renameObject($this->nodeId, $name);
// rename($this->path,$newPath);
$this->path = $newPath;
}
作者:afterlogi
项目:da
public function getName()
{
if ($this->isLink) {
return $this->sharedNode->getName();
} else {
list(, $name) = \Sabre\HTTP\URLUtil::splitPath($this->linkPath);
return $name;
}
}
作者:evanj
项目:cor
/**
* Returns the addressbook home for a given principal
*
* @param string $principal
* @return string
*/
protected function getAddressbookHomeForPrincipal($principal)
{
if (strrpos($principal, 'principals/users', -strlen($principal)) !== FALSE) {
list(, $principalId) = URLUtil::splitPath($principal);
return self::ADDRESSBOOK_ROOT . '/users/' . $principalId;
}
if (strrpos($principal, 'principals/system', -strlen($principal)) !== FALSE) {
list(, $principalId) = URLUtil::splitPath($principal);
return self::ADDRESSBOOK_ROOT . '/system/' . $principalId;
}
throw new \LogicException('This is not supposed to happen');
}
作者:CatoT
项目:Muenchen-Transparen
function getCalendarsForUser($principalUri)
{
/** @var Termin $termin */
$termin = Termin::model()->findByPk($this->termin_id);
if (!$termin) {
return [];
}
list(, $name) = \Sabre\HTTP\URLUtil::splitPath($principalUri);
if ($name !== 'guest') {
return [];
}
return [['id' => $this->termin_id, 'uri' => $this->termin_id, 'principaluri' => $principalUri, '{DAV:}displayname' => $termin->gremium->getName(), '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => rand(0, 100000000), '{http://sabredav.org/ns}sync-token' => '0', '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new \Sabre\CalDAV\Property\SupportedCalendarComponentSet(["VEVENT", "VJOURNAL", "VTODO"]), '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp' => new \Sabre\CalDAV\Property\ScheduleCalendarTransp('opaque'), '{http://sabredav.org/ns}read-only' => '1']];
}
作者:Kevin-Z
项目:vaneDis
/**
* Renames the node
* @param string $name The new name
* @throws \Sabre\DAV\Exception\BadRequest
* @throws \Sabre\DAV\Exception\Forbidden
*/
public function setName($name)
{
// rename is only allowed if the update privilege is granted
if (!$this->info->isUpdateable()) {
throw new \Sabre\DAV\Exception\Forbidden();
}
list($parentPath, ) = \Sabre\HTTP\URLUtil::splitPath($this->path);
list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name);
// verify path of the target
$this->verifyPath();
$newPath = $parentPath . '/' . $newName;
$this->fileView->rename($this->path, $newPath);
$this->path = $newPath;
$this->refreshInfo();
}
作者:vmir
项目:SabreServe
/**
* This method returns a node for a principal.
*
* The passed array contains principal information, and is guaranteed to
* at least contain a uri item. Other properties may or may not be
* supplied by the authentication backend.
*
* @param array $principal
* @return \Sabre\DAV\INode
*/
function getChildForPrincipal(array $principal)
{
$node = parent::getChildForPrincipal($principal);
/*
* Création du carnet d'adresse par défaut s'il n'existe pas
*/
if (!$node || count($node->getChildren()) == 0) {
//No addressBook. Create default one
$principalUri = $principal["uri"];
list(, $principalId) = \Sabre\HTTP\URLUtil::splitPath($principalUri);
$name = "contacts";
$properties = ['{DAV:}displayname' => $name, '{' . \Sabre\CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => "Contacts de " . $principalId];
$this->carddavBackend->createAddressBook($principalUri, $name, $properties);
$node = parent::getChildForPrincipal($principal);
}
return $node;
}
作者:vmir
项目:SabreServe
/**
* This method returns a node for a principal.
*
* The passed array contains principal information, and is guaranteed to
* at least contain a uri item. Other properties may or may not be
* supplied by the authentication backend.
*
* @param array $principal
* @return \Sabre\DAV\INode
*/
function getChildForPrincipal(array $principal)
{
$node = parent::getChildForPrincipal($principal);
/*
* Création du calendrier par défaut s'il n'existe pas
*/
if (!$node || count($node->getChildren()) == 0) {
//No calendar. Create default one
$principalUri = $principal["uri"];
list(, $principalId) = \Sabre\HTTP\URLUtil::splitPath($principalUri);
$name = $principalId;
$properties = ['{DAV:}displayname' => $name, '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}calendar' => $name];
$this->caldavBackend->createCalendar($principalUri, $name, $properties);
$node = parent::getChildForPrincipal($principal);
}
return $node;
}
作者:Befo
项目:cda
/**
* Returns a list of principals based on a prefix.
*
* This prefix will often contain something like 'principals'. You are only
* expected to return principals that are in this base path.
*
* You are expected to return at least a 'uri' for every user, you can
* return any additional properties if you wish so. Common properties are:
* {DAV:}displayname
* {http://sabredav.org/ns}email-address - This is a custom SabreDAV
* field that's actualy injected in a number of other properties. If
* you have an email address, use this property.
*
* @param string $prefixPath
* @return array
*/
function getPrincipalsByPrefix($prefixPath)
{
$principals = [];
foreach ($this->allprincipals as $row) {
// Checking if the principal is in the prefix
list($rowPrefix) = URLUtil::splitPath($row['uri']);
if ($rowPrefix !== $prefixPath) {
continue;
}
$principal = ['uri' => $row['uri']];
foreach ($this->fieldMap as $key => $value) {
if ($row[$value['dbField']]) {
$principal[$key] = $row[$value['dbField']];
}
}
$principals[] = $principal;
}
return $principals;
}
作者:matt40
项目:cor
/**
* Returns the list of address books for a specific user.
*
* Every addressbook should have the following properties:
* id - an arbitrary unique id
* uri - the 'basename' part of the url
* principaluri - Same as the passed parameter
*
* Any additional clark-notation property may be passed besides this. Some
* common ones are :
* {DAV:}displayname
* {urn:ietf:params:xml:ns:carddav}addressbook-description
* {http://calendarserver.org/ns/}getctag
*
* @param string $principalUri
* @return array
*/
function getAddressBooksForUser($principalUri)
{
$query = $this->db->getQueryBuilder();
$query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])->from('addressbooks')->where($query->expr()->eq('principaluri', $query->createParameter('principaluri')))->setParameter('principaluri', $principalUri);
$addressBooks = [];
$result = $query->execute();
while ($row = $result->fetch()) {
$addressBooks[] = ['id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $row['principaluri'], '{DAV:}displayname' => $row['displayname'], '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0'];
}
$result->closeCursor();
// query for shared calendars
$principals = $this->principalBackend->getGroupMembership($principalUri);
$principals[] = $principalUri;
$query = $this->db->getQueryBuilder();
$result = $query->select(['a.id', 'a.uri', 'a.displayname', 'a.principaluri', 'a.description', 'a.synctoken', 's.access'])->from('dav_shares', 's')->join('s', 'addressbooks', 'a', $query->expr()->eq('s.resourceid', 'a.id'))->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri')))->andWhere($query->expr()->eq('s.type', $query->createParameter('type')))->setParameter('type', 'addressbook')->setParameter('principaluri', $principals, IQueryBuilder::PARAM_STR_ARRAY)->execute();
while ($row = $result->fetch()) {
list(, $name) = URLUtil::splitPath($row['principaluri']);
$uri = $row['uri'] . '_shared_by_' . $name;
$displayName = $row['displayname'] . "({$name})";
$addressBooks[] = ['id' => $row['id'], 'uri' => $uri, 'principaluri' => $principalUri, '{DAV:}displayname' => $displayName, '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $row['access'] === self::ACCESS_READ];
}
$result->closeCursor();
return $addressBooks;
}
作者:matte
项目:sabre-da
/**
* This method tells the tree system to pre-fetch and cache a list of
* children of a single parent.
*
* There are a bunch of operations in the WebDAV stack that request many
* children (based on uris), and sometimes fetching many at once can
* optimize this.
*
* This method returns an array with the found nodes. It's keys are the
* original paths. The result may be out of order.
*
* @param array $paths List of nodes that must be fetched.
* @return array
*/
function getMultipleNodes($paths)
{
// Finding common parents
$parents = [];
foreach ($paths as $path) {
list($parent, $node) = URLUtil::splitPath($path);
if (!isset($parents[$parent])) {
$parents[$parent] = [$node];
} else {
$parents[$parent][] = $node;
}
}
$result = [];
foreach ($parents as $parent => $children) {
$parentNode = $this->getNodeForPath($parent);
if ($parentNode instanceof IMultiGet) {
foreach ($parentNode->getMultipleChildren($children) as $childNode) {
$fullPath = $parent . '/' . $childNode->getName();
$result[$fullPath] = $childNode;
$this->cache[$fullPath] = $childNode;
}
} else {
foreach ($children as $child) {
$fullPath = $parent . '/' . $child;
$result[$fullPath] = $this->getNodeForPath($fullPath);
}
}
}
return $result;
}
作者:stwei
项目:owncloud-cor
/**
* Copies a file or directory.
*
* This method must work recursively and delete the destination
* if it exists
*
* @param string $source
* @param string $destination
* @throws \Sabre\DAV\Exception\ServiceUnavailable
* @return void
*/
public function copy($source, $destination)
{
if (!$this->fileView) {
throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
}
// this will trigger existence check
$this->getNodeForPath($source);
list($destinationDir, $destinationName) = \Sabre\HTTP\URLUtil::splitPath($destination);
try {
$this->fileView->verifyPath($destinationDir, $destinationName);
} catch (\OCP\Files\InvalidPathException $ex) {
throw new InvalidPath($ex->getMessage());
}
try {
$this->fileView->copy($source, $destination);
} catch (StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
} catch (ForbiddenException $ex) {
throw new Forbidden($ex->getMessage(), $ex->getRetry());
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}
list($destinationDir, ) = \Sabre\HTTP\URLUtil::splitPath($destination);
$this->markDirty($destinationDir);
}
作者:brunomile
项目:owncloud-cor
/**
* @param string $filePath
* @param \Sabre\DAV\INode $node
* @throws \Sabre\DAV\Exception\BadRequest
*/
public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null)
{
// chunked upload handling
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($filePath);
$info = \OC_FileChunking::decodeName($name);
if (!empty($info)) {
$filePath = $path . '/' . $info['name'];
}
}
// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
if (!$this->server->tree->nodeExists($filePath)) {
return;
}
$node = $this->server->tree->getNodeForPath($filePath);
if ($node instanceof \OC\Connector\Sabre\Node) {
$fileId = $node->getFileId();
if (!is_null($fileId)) {
$this->server->httpResponse->setHeader('OC-FileId', $fileId);
}
}
}
作者:samj191
项目:rep
/**
* Returns the addressbook home for a given principal
*
* @param string $principal
* @return string
*/
protected function getAddressbookHomeForPrincipal($principal)
{
list(, $principalId) = \Sabre\HTTP\URLUtil::splitPath($principal);
return self::ADDRESSBOOK_ROOT . '/' . $principalId;
}
作者:nikos
项目:openeclas
/**
* Use this method to create a new collection
*
* @param string $uri The new uri
* @param MkCol $mkCol
* @return array|null
*/
function createCollection($uri, MkCol $mkCol) {
list($parentUri, $newName) = URLUtil::splitPath($uri);
// Making sure the parent exists
try {
$parent = $this->tree->getNodeForPath($parentUri);
} catch (Exception\NotFound $e) {
throw new Exception\Conflict('Parent node does not exist');
}
// Making sure the parent is a collection
if (!$parent instanceof ICollection) {
throw new Exception\Conflict('Parent node is not a collection');
}
// Making sure the child does not already exist
try {
$parent->getChild($newName);
// If we got here.. it means there's already a node on that url, and we need to throw a 405
throw new Exception\MethodNotAllowed('The resource you tried to create already exists');
} catch (Exception\NotFound $e) {
// NotFound is the expected behavior.
}
if (!$this->emit('beforeBind', [$uri])) return;
if ($parent instanceof IExtendedCollection) {
/**
* If the parent is an instance of IExtendedCollection, it means that
* we can pass the MkCol object directly as it may be able to store
* properties immediately.
*/
$parent->createExtendedCollection($newName, $mkCol);
} else {
/**
* If the parent is a standard ICollection, it means only
* 'standard' collections can be created, so we should fail any
* MKCOL operation that carries extra resourcetypes.
*/
if (count($mkCol->getResourceType()) > 1) {
throw new Exception\InvalidResourceType('The {DAV:}resourcetype you specified is not supported here.');
}
$parent->createDirectory($newName);
}
// If there are any properties that have not been handled/stored,
// we ask the 'propPatch' event to handle them. This will allow for
// example the propertyStorage system to store properties upon MKCOL.
if ($mkCol->getRemainingMutations()) {
$this->emit('propPatch', [$uri, $mkCol]);
}
$success = $mkCol->commit();
if (!$success) {
$result = $mkCol->getResult();
// generateMkCol needs the href key to exist.
$result['href'] = $uri;
return $result;
}
$this->tree->markDirty($parentUri);
$this->emit('afterBind', [$uri]);
}
作者:pagee
项目:sabre-da
/**
* Returns this principals name.
*
* @return string
*/
function getName()
{
$uri = $this->principalProperties['uri'];
list(, $name) = URLUtil::splitPath($uri);
return $name;
}
作者:Bergdahl
项目:YetiForceCR
/**
* Use this method to create a new collection
*
* The {DAV:}resourcetype is specified using the resourceType array.
* At the very least it must contain {DAV:}collection.
*
* The properties array can contain a list of additional properties.
*
* @param string $uri The new uri
* @param array $resourceType The resourceType(s)
* @param array $properties A list of properties
* @return array|null
*/
function createCollection($uri, array $resourceType, array $properties)
{
list($parentUri, $newName) = URLUtil::splitPath($uri);
// Making sure {DAV:}collection was specified as resourceType
if (!in_array('{DAV:}collection', $resourceType)) {
throw new Exception\InvalidResourceType('The resourceType for this collection must at least include {DAV:}collection');
}
// Making sure the parent exists
try {
$parent = $this->tree->getNodeForPath($parentUri);
} catch (Exception\NotFound $e) {
throw new Exception\Conflict('Parent node does not exist');
}
// Making sure the parent is a collection
if (!$parent instanceof ICollection) {
throw new Exception\Conflict('Parent node is not a collection');
}
// Making sure the child does not already exist
try {
$parent->getChild($newName);
// If we got here.. it means there's already a node on that url, and we need to throw a 405
throw new Exception\MethodNotAllowed('The resource you tried to create already exists');
} catch (Exception\NotFound $e) {
// This is correct
}
if (!$this->emit('beforeBind', [$uri])) {
return;
}
// There are 2 modes of operation. The standard collection
// creates the directory, and then updates properties
// the extended collection can create it directly.
if ($parent instanceof IExtendedCollection) {
$parent->createExtendedCollection($newName, $resourceType, $properties);
} else {
// No special resourcetypes are supported
if (count($resourceType) > 1) {
throw new Exception\InvalidResourceType('The {DAV:}resourcetype you specified is not supported here.');
}
$parent->createDirectory($newName);
$rollBack = false;
$exception = null;
$errorResult = null;
if (count($properties) > 0) {
try {
$errorResult = $this->updateProperties($uri, $properties);
if (!isset($errorResult[200])) {
$rollBack = true;
}
} catch (Exception $e) {
$rollBack = true;
$exception = $e;
}
}
if ($rollBack) {
if (!$this->emit('beforeUnbind', [$uri])) {
return;
}
$this->tree->delete($uri);
// Re-throwing exception
if ($exception) {
throw $exception;
}
// Re-arranging the result so it makes sense for
// generateMultiStatus.
$newResult = ['href' => $uri];
foreach ($errorResult as $property => $code) {
if (!isset($newResult[$code])) {
$newResult[$code] = [$property => null];
} else {
$newResult[$code][$property] = null;
}
}
return $newResult;
}
}
$this->tree->markDirty($parentUri);
$this->emit('afterBind', [$uri]);
}