作者:Combustibl
项目:cor
/**
* 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) = URLUtil::splitPath($uri);
$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;
}
作者:yheric45504
项目:owncloud8
/**
* serialize
*
* @param DAV\Server $server
* @param \DOMElement $dom
* @return void
*/
public function serialize(DAV\Server $server, \DOMElement $dom)
{
$document = $dom->ownerDocument;
$properties = $this->responseProperties;
$xresponse = $document->createElement('d:response');
$dom->appendChild($xresponse);
$uri = DAV\URLUtil::encodePath($this->href);
// Adding the baseurl to the beginning of the url
$uri = $server->getBaseUri() . $uri;
$xresponse->appendChild($document->createElement('d:href', $uri));
// The properties variable is an array containing properties, grouped by
// HTTP status
foreach ($properties as $httpStatus => $propertyGroup) {
// The 'href' is also in this array, and it's special cased.
// We will ignore it
if ($httpStatus == 'href') {
continue;
}
// If there are no properties in this group, we can also just carry on
if (!count($propertyGroup)) {
continue;
}
$xpropstat = $document->createElement('d:propstat');
$xresponse->appendChild($xpropstat);
$xprop = $document->createElement('d:prop');
$xpropstat->appendChild($xprop);
$nsList = $server->xmlNamespaces;
foreach ($propertyGroup as $propertyName => $propertyValue) {
$propName = null;
preg_match('/^{([^}]*)}(.*)$/', $propertyName, $propName);
// special case for empty namespaces
if ($propName[1] == '') {
$currentProperty = $document->createElement($propName[2]);
$xprop->appendChild($currentProperty);
$currentProperty->setAttribute('xmlns', '');
} else {
if (!isset($nsList[$propName[1]])) {
$nsList[$propName[1]] = 'x' . count($nsList);
}
// If the namespace was defined in the top-level xml namespaces, it means
// there was already a namespace declaration, and we don't have to worry about it.
if (isset($server->xmlNamespaces[$propName[1]])) {
$currentProperty = $document->createElement($nsList[$propName[1]] . ':' . $propName[2]);
} else {
$currentProperty = $document->createElementNS($propName[1], $nsList[$propName[1]] . ':' . $propName[2]);
}
$xprop->appendChild($currentProperty);
}
if (is_scalar($propertyValue)) {
$text = $document->createTextNode($propertyValue);
$currentProperty->appendChild($text);
} elseif ($propertyValue instanceof DAV\PropertyInterface) {
$propertyValue->serialize($server, $currentProperty);
} elseif (!is_null($propertyValue)) {
throw new DAV\Exception('Unknown property value type: ' . gettype($propertyValue) . ' for property: ' . $propertyName);
}
}
$xpropstat->appendChild($document->createElement('d:status', $server->httpResponse->getStatusMessage($httpStatus)));
}
}
作者:ChristophWurs
项目:pimcor
/**
* Renames the node
*
* @param string $name The new name
* @return void
*/
public function setName($name)
{
list($parentPath, ) = DAV\URLUtil::splitPath($this->path);
list(, $newName) = DAV\URLUtil::splitPath($name);
$newPath = $parentPath . '/' . $newName;
rename($this->path, $newPath);
$this->path = $newPath;
}
作者:hallnewma
项目:webmail-lit
public function getName()
{
if ($this->isLink) {
return $this->sharedItem->getName();
} else {
list(, $name) = \Sabre\DAV\URLUtil::splitPath($this->linkPath);
return $name;
}
}
作者:ChristophWurs
项目:pimcor
/**
* Handler for teh afterGetProperties event
*
* @param string $path
* @param array $properties
* @return void
*/
public function afterGetProperties($path, &$properties)
{
if (array_key_exists('{DAV:}getcontenttype', $properties[404])) {
list(, $fileName) = DAV\URLUtil::splitPath($path);
$contentType = $this->getContentType($fileName);
if ($contentType) {
$properties[200]['{DAV:}getcontenttype'] = $contentType;
unset($properties[404]['{DAV:}getcontenttype']);
}
}
}
作者:jubinpate
项目:hord
/**
* Returns a specific principal, specified by it's path.
*
* @param string $path
* @return array
*/
public function getPrincipalByPath($path)
{
list($prefix, $user) = DAV\URLUtil::splitPath($path);
if ($prefix != 'principals') {
throw new DAV\Exception\NotFound('Invalid principal prefix path ' . $prefix);
}
if ($this->_auth->hasCapability('list') && !$this->_auth->exists($user) && $user != '-system-') {
throw new DAV\Exception\NotFound('User ' . $user . ' does not exist');
}
return $this->_getUserInfo($user);
}
作者:kossamum
项目:hord
/**
* Returns the list of addressbooks for a specific user.
*
* @param string $principalUri
* @return array
*/
public function getAddressBooksForUser($principalUri)
{
list($prefix, $user) = DAV\URLUtil::splitPath($principalUri);
if ($prefix != 'principals') {
throw new DAV\Exception\NotFound('Invalid principal prefix path ' . $prefix);
}
try {
return $this->_registry->callAppMethod($this->_contacts(), 'davGetCollections', array('args' => array($user)));
} catch (Horde_Exception $e) {
throw new DAV\Exception($e->getMessage(), $e->getCode(), $e);
}
}
作者:nbe
项目:Emergence-Skeleto
public function beforeCreateFile($uri, $data)
{
list($dir, $name) = \Sabre\DAV\URLUtil::splitPath($uri);
$currentNode = null;
foreach (explode('/', trim($dir, '/')) as $pathPart) {
$parentNode = $currentNode;
$currentNode = \SiteCollection::getByHandle($pathPart, $parentNode ? $parentNode->ID : null);
if (!$currentNode) {
$currentNode = \SiteCollection::create($pathPart, $parentNode);
}
}
}
作者:MetallianFR6
项目:myroundcub
/**
* Serializes this property.
*
* It will additionally prepend the href property with the server's base uri.
*
* @param DAV\Server $server
* @param \DOMElement $dom
* @return void
*/
function serialize(DAV\Server $server, \DOMElement $dom)
{
$prefix = $server->xmlNamespaces['DAV:'];
$elem = $dom->ownerDocument->createElement($prefix . ':href');
if ($this->autoPrefix) {
$value = $server->getBaseUri() . DAV\URLUtil::encodePath($this->href);
} else {
$value = $this->href;
}
$elem->appendChild($dom->ownerDocument->createTextNode($value));
$dom->appendChild($elem);
}
作者:Romua1
项目:cor
/**
* Returns the list of groups a principal is a member of
*
* @param string $principal
* @return array
*/
public function getGroupMembership($principal)
{
list($prefix, $name) = \Sabre\DAV\URLUtil::splitPath($principal);
$group_membership = array();
if ($prefix == 'principals') {
$principal = $this->getPrincipalByPath($principal);
if (!$principal) {
throw new \Sabre\DAV\Exception('Principal not found');
}
// TODO: for now the user principal has only its own groups
return array('principals/' . $name . '/calendar-proxy-read', 'principals/' . $name . '/calendar-proxy-write');
}
return $group_membership;
}
作者:CDN-Spark
项目:ownclou
public function checkPreconditions($handleAsGET = false)
{
// chunked upload handling
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
$filePath = parent::getRequestUri();
list($path, $name) = \Sabre\DAV\URLUtil::splitPath($filePath);
$info = OC_FileChunking::decodeName($name);
if (!empty($info)) {
$filePath = $path . '/' . $info['name'];
$this->overLoadedUri = $filePath;
}
}
$result = parent::checkPreconditions($handleAsGET);
$this->overLoadedUri = null;
return $result;
}
作者:jubinpate
项目:hord
/**
* Returns a list of calendars for a principal.
*
* @param string $principalUri
* @return array
*/
public function getCalendarsForUser($principalUri)
{
list($prefix, $user) = DAV\URLUtil::splitPath($principalUri);
if ($prefix != 'principals') {
throw new DAV\Exception\NotFound('Invalid principal prefix path ' . $prefix);
}
$collections = array();
foreach ($this->_interfaces as $interface) {
try {
$collections = array_merge($collections, (array) $this->_registry->callAppMethod($interface, 'davGetCollections', array('args' => array($user))));
} catch (Horde_Exception $e) {
throw new DAV\Exception($e->getMessage(), $e->getCode(), $e);
}
}
return $collections;
}
作者:CDN-Spark
项目:ownclou
/**
* @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\DAV\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);
}
}
}
作者:noble8
项目:proyectos-UL
/**
* Renames the node
*
* @param string $name The new name
* @return void
*/
public function setName($name)
{
list($parentPath, ) = DAV\URLUtil::splitPath($this->path);
list(, $newName) = DAV\URLUtil::splitPath($name);
$newPath = $parentPath . '/' . $newName;
// We're deleting the existing resourcedata, and recreating it
// for the new path.
$resourceData = $this->getResourceData();
$this->deleteResourceData();
rename($this->path, $newPath);
$this->path = $newPath;
$this->putResourceData($resourceData);
}
作者:raz0rsdg
项目:hord
/**
* Returns the name of the node.
*
* This is used to generate the url.
*
* @return string
*/
public function getName()
{
list($dir, $base) = DAV\URLUtil::splitPath($this->_path);
return $base;
}
作者:anmol26
项目:hubzilla-yunohos
/**
* @brief Renames the directory.
*
* @todo handle duplicate directory name
*
* @throw \Sabre\DAV\Exception\Forbidden
* @param string $name The new name of the directory.
* @return void
*/
public function setName($name)
{
logger('old name ' . basename($this->red_path) . ' -> ' . $name, LOGGER_DATA);
if (!$name || !$this->auth->owner_id) {
logger('permission denied ' . $name);
throw new DAV\Exception\Forbidden('Permission denied.');
}
if (!perm_is_allowed($this->auth->owner_id, $this->auth->observer, 'write_storage')) {
logger('permission denied ' . $name);
throw new DAV\Exception\Forbidden('Permission denied.');
}
list($parent_path, ) = DAV\URLUtil::splitPath($this->red_path);
$new_path = $parent_path . '/' . $name;
$r = q("UPDATE attach SET filename = '%s' WHERE hash = '%s' AND uid = %d", dbesc($name), dbesc($this->folder_hash), intval($this->auth->owner_id));
$ch = channelx_by_n($this->auth->owner_id);
if ($ch) {
$sync = attach_export_data($ch, $this->folder_hash);
if ($sync) {
build_sync_packet($ch['channel_id'], array('file' => array($sync)));
}
}
$this->red_path = $new_path;
}
作者:samj191
项目:rep
/**
* Returns this principals name.
*
* @return string
*/
public function getName()
{
$uri = $this->principalProperties['uri'];
list(, $name) = DAV\URLUtil::splitPath($uri);
return $name;
}
作者:heldern
项目:owncloud8-extende
/**
* 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');
}
try {
if ($this->fileView->is_file($source)) {
$this->fileView->copy($source, $destination);
} else {
$this->fileView->mkdir($destination);
$dh = $this->fileView->opendir($source);
if (is_resource($dh)) {
while (($subNode = readdir($dh)) !== false) {
if ($subNode == '.' || $subNode == '..') {
continue;
}
$this->copy($source . '/' . $subNode, $destination . '/' . $subNode);
}
}
}
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
list($destinationDir, ) = \Sabre\DAV\URLUtil::splitPath($destination);
$this->markDirty($destinationDir);
}
作者:oluca
项目:owncloud-cor
/**
* @param resource $data
* @return null|string
*/
private function createFileChunked($data)
{
list($path, $name) = \Sabre\DAV\URLUtil::splitPath($this->path);
$info = OC_FileChunking::decodeName($name);
if (empty($info)) {
throw new \Sabre\DAV\Exception\NotImplemented();
}
$chunk_handler = new OC_FileChunking($info);
$bytesWritten = $chunk_handler->store($info['index'], $data);
//detect aborted upload
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
if (isset($_SERVER['CONTENT_LENGTH'])) {
$expected = $_SERVER['CONTENT_LENGTH'];
if ($bytesWritten != $expected) {
$chunk_handler->remove($info['index']);
throw new \Sabre\DAV\Exception\BadRequest('expected filesize ' . $expected . ' got ' . $bytesWritten);
}
}
}
if ($chunk_handler->isComplete()) {
// we first assembly the target file as a part file
$partFile = $path . '/' . $info['name'] . '.ocTransferId' . $info['transferid'] . '.part';
$chunk_handler->file_assemble($partFile);
// here is the final atomic rename
$targetPath = $path . '/' . $info['name'];
$renameOkay = $this->fileView->rename($partFile, $targetPath);
$fileExists = $this->fileView->file_exists($targetPath);
if ($renameOkay === false || $fileExists === false) {
\OC_Log::write('webdav', '\\OC\\Files\\Filesystem::rename() failed', \OC_Log::ERROR);
// only delete if an error occurred and the target file was already created
if ($fileExists) {
$this->fileView->unlink($targetPath);
}
throw new \Sabre\DAV\Exception('Could not rename part file assembled from chunks');
}
// allow sync clients to send the mtime along in a header
$mtime = OC_Request::hasModificationTime();
if ($mtime !== false) {
if ($this->fileView->touch($targetPath, $mtime)) {
header('X-OC-MTime: accepted');
}
}
$info = $this->fileView->getFileInfo($targetPath);
return $info->getEtag();
}
return null;
}
作者:msooo
项目:hubzill
/**
* @brief Creates the directory listing for the given path.
*
* @param string $path which should be displayed
*/
public function generateDirectoryIndex($path)
{
// (owner_id = channel_id) is visitor owner of this directory?
$is_owner = local_channel() && $this->auth->owner_id == local_channel() ? true : false;
if ($this->auth->getTimezone()) {
date_default_timezone_set($this->auth->getTimezone());
}
require_once 'include/conversation.php';
require_once 'include/text.php';
if ($this->auth->owner_nick) {
$html = profile_tabs(get_app(), $is_owner ? true : false, $this->auth->owner_nick);
}
$files = $this->server->getPropertiesForPath($path, array('{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified'), 1);
$parent = $this->server->tree->getNodeForPath($path);
$parentpath = array();
// only show parent if not leaving /cloud/; TODO how to improve this?
if ($path && $path != "cloud") {
list($parentUri) = DAV\URLUtil::splitPath($path);
$fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
$parentpath['icon'] = $this->enableAssets ? '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="' . t('parent') . '"></a>' : '';
$parentpath['path'] = $fullPath;
}
$f = array();
foreach ($files as $file) {
$ft = array();
$type = null;
// This is the current directory, we can skip it
if (rtrim($file['href'], '/') == $path) {
continue;
}
list(, $name) = DAV\URLUtil::splitPath($file['href']);
if (isset($file[200]['{DAV:}resourcetype'])) {
$type = $file[200]['{DAV:}resourcetype']->getValue();
// resourcetype can have multiple values
if (!is_array($type)) {
$type = array($type);
}
foreach ($type as $k => $v) {
// Some name mapping is preferred
switch ($v) {
case '{DAV:}collection':
$type[$k] = t('Collection');
break;
case '{DAV:}principal':
$type[$k] = t('Principal');
break;
case '{urn:ietf:params:xml:ns:carddav}addressbook':
$type[$k] = t('Addressbook');
break;
case '{urn:ietf:params:xml:ns:caldav}calendar':
$type[$k] = t('Calendar');
break;
case '{urn:ietf:params:xml:ns:caldav}schedule-inbox':
$type[$k] = t('Schedule Inbox');
break;
case '{urn:ietf:params:xml:ns:caldav}schedule-outbox':
$type[$k] = t('Schedule Outbox');
break;
case '{http://calendarserver.org/ns/}calendar-proxy-read':
$type[$k] = 'Proxy-Read';
break;
case '{http://calendarserver.org/ns/}calendar-proxy-write':
$type[$k] = 'Proxy-Write';
break;
}
}
$type = implode(', ', $type);
}
// If no resourcetype was found, we attempt to use
// the contenttype property
if (!$type && isset($file[200]['{DAV:}getcontenttype'])) {
$type = $file[200]['{DAV:}getcontenttype'];
}
if (!$type) {
$type = t('Unknown');
}
$size = isset($file[200]['{DAV:}getcontentlength']) ? (int) $file[200]['{DAV:}getcontentlength'] : '';
$lastmodified = isset($file[200]['{DAV:}getlastmodified']) ? $file[200]['{DAV:}getlastmodified']->getTime()->format('Y-m-d H:i:s') : '';
$fullPath = DAV\URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path ? $path . '/' : '') . $name, '/'));
$displayName = isset($file[200]['{DAV:}displayname']) ? $file[200]['{DAV:}displayname'] : $name;
$displayName = $this->escapeHTML($displayName);
$type = $this->escapeHTML($type);
$icon = '';
if ($this->enableAssets) {
$node = $this->server->tree->getNodeForPath(($path ? $path . '/' : '') . $name);
foreach (array_reverse($this->iconMap) as $class => $iconName) {
if ($node instanceof $class) {
$icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24"></a>';
break;
}
}
}
$parentHash = '';
$owner = $this->auth->owner_id;
$splitPath = explode('/', $fullPath);
//.........这里部分代码省略.........