2013-10-23 18:03:57 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Thomas Müller
|
|
|
|
* @copyright 2013 Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL3
|
|
|
|
*/
|
|
|
|
|
2014-01-09 17:25:48 +04:00
|
|
|
class OC_Connector_Sabre_FilesPlugin extends \Sabre\DAV\ServerPlugin
|
2013-10-23 18:03:57 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
// namespace
|
2013-10-24 16:40:43 +04:00
|
|
|
const NS_OWNCLOUD = 'http://owncloud.org/ns';
|
2013-10-23 18:03:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to main server object
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* @var \Sabre\DAV\Server
|
2013-10-23 18:03:57 +04:00
|
|
|
*/
|
|
|
|
private $server;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This initializes the plugin.
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* This function is called by \Sabre\DAV\Server, after
|
2013-10-23 18:03:57 +04:00
|
|
|
* addPlugin is called.
|
|
|
|
*
|
|
|
|
* This method should set up the required event subscriptions.
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* @param \Sabre\DAV\Server $server
|
2013-10-23 18:03:57 +04:00
|
|
|
* @return void
|
|
|
|
*/
|
2014-01-09 17:25:48 +04:00
|
|
|
public function initialize(\Sabre\DAV\Server $server) {
|
2013-10-23 18:03:57 +04:00
|
|
|
|
|
|
|
$server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc';
|
|
|
|
$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}id';
|
2014-07-21 15:39:01 +04:00
|
|
|
$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}permissions';
|
2014-08-29 13:39:02 +04:00
|
|
|
$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}size';
|
2013-10-23 18:03:57 +04:00
|
|
|
|
|
|
|
$this->server = $server;
|
|
|
|
$this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties'));
|
2014-08-18 20:39:16 +04:00
|
|
|
$this->server->subscribeEvent('afterBind', array($this, 'sendFileIdHeader'));
|
2013-10-25 15:20:59 +04:00
|
|
|
$this->server->subscribeEvent('afterWriteContent', array($this, 'sendFileIdHeader'));
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds all ownCloud-specific properties
|
|
|
|
*
|
|
|
|
* @param string $path
|
2014-01-09 17:25:48 +04:00
|
|
|
* @param \Sabre\DAV\INode $node
|
2013-10-23 18:03:57 +04:00
|
|
|
* @param array $requestedProperties
|
|
|
|
* @param array $returnedProperties
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-01-09 17:25:48 +04:00
|
|
|
public function beforeGetProperties($path, \Sabre\DAV\INode $node, array &$requestedProperties, array &$returnedProperties) {
|
2013-10-23 18:03:57 +04:00
|
|
|
|
|
|
|
if ($node instanceof OC_Connector_Sabre_Node) {
|
|
|
|
|
2014-05-02 19:37:16 +04:00
|
|
|
$fileIdPropertyName = '{' . self::NS_OWNCLOUD . '}id';
|
|
|
|
$permissionsPropertyName = '{' . self::NS_OWNCLOUD . '}permissions';
|
|
|
|
if (array_search($fileIdPropertyName, $requestedProperties)) {
|
|
|
|
unset($requestedProperties[array_search($fileIdPropertyName, $requestedProperties)]);
|
|
|
|
}
|
|
|
|
if (array_search($permissionsPropertyName, $requestedProperties)) {
|
|
|
|
unset($requestedProperties[array_search($permissionsPropertyName, $requestedProperties)]);
|
2013-10-24 16:40:43 +04:00
|
|
|
}
|
2013-10-23 18:03:57 +04:00
|
|
|
|
|
|
|
/** @var $node OC_Connector_Sabre_Node */
|
2013-10-23 18:40:29 +04:00
|
|
|
$fileId = $node->getFileId();
|
|
|
|
if (!is_null($fileId)) {
|
2014-05-02 19:37:16 +04:00
|
|
|
$returnedProperties[200][$fileIdPropertyName] = $fileId;
|
|
|
|
}
|
|
|
|
|
|
|
|
$permissions = $node->getDavPermissions();
|
2014-08-29 13:39:02 +04:00
|
|
|
if (!is_null($permissions)) {
|
2014-05-02 19:37:16 +04:00
|
|
|
$returnedProperties[200][$permissionsPropertyName] = $permissions;
|
2013-10-23 18:40:29 +04:00
|
|
|
}
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|
|
|
|
|
2014-08-29 13:39:02 +04:00
|
|
|
if ($node instanceof OC_Connector_Sabre_Directory) {
|
|
|
|
$sizePropertyName = '{' . self::NS_OWNCLOUD . '}size';
|
|
|
|
|
|
|
|
/** @var $node OC_Connector_Sabre_Directory */
|
|
|
|
$returnedProperties[200][$sizePropertyName] = $node->getSize();
|
|
|
|
}
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|
|
|
|
|
2013-10-25 15:20:59 +04:00
|
|
|
/**
|
2014-05-12 00:51:30 +04:00
|
|
|
* @param string $filePath
|
2014-01-09 17:25:48 +04:00
|
|
|
* @param \Sabre\DAV\INode $node
|
|
|
|
* @throws \Sabre\DAV\Exception\BadRequest
|
2013-10-25 15:20:59 +04:00
|
|
|
*/
|
2014-01-09 17:25:48 +04:00
|
|
|
public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
|
2013-11-25 18:35:26 +04:00
|
|
|
// chunked upload handling
|
|
|
|
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
|
2014-01-09 17:25:48 +04:00
|
|
|
list($path, $name) = \Sabre\DAV\URLUtil::splitPath($filePath);
|
2013-11-25 18:35:26 +04:00
|
|
|
$info = OC_FileChunking::decodeName($name);
|
|
|
|
if (!empty($info)) {
|
|
|
|
$filePath = $path . '/' . $info['name'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 19:14:08 +04:00
|
|
|
// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
|
2013-11-25 18:35:26 +04:00
|
|
|
if (!$this->server->tree->nodeExists($filePath)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-20 19:14:08 +04:00
|
|
|
$node = $this->server->tree->getNodeForPath($filePath);
|
2013-10-25 15:20:59 +04:00
|
|
|
if ($node instanceof OC_Connector_Sabre_Node) {
|
|
|
|
$fileId = $node->getFileId();
|
|
|
|
if (!is_null($fileId)) {
|
|
|
|
$this->server->httpResponse->setHeader('OC-FileId', $fileId);
|
|
|
|
}
|
2014-08-29 14:09:33 +04:00
|
|
|
$eTag = $node->getETag();
|
|
|
|
if (!is_null($eTag)) {
|
|
|
|
$this->server->httpResponse->setHeader('OC-ETag', $eTag);
|
|
|
|
}
|
2013-10-25 15:20:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|