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
|
|
|
|
*/
|
|
|
|
|
|
|
|
class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin
|
|
|
|
{
|
|
|
|
|
|
|
|
// 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
|
|
|
|
*
|
|
|
|
* @var Sabre_DAV_Server
|
|
|
|
*/
|
|
|
|
private $server;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This initializes the plugin.
|
|
|
|
*
|
|
|
|
* This function is called by Sabre_DAV_Server, after
|
|
|
|
* addPlugin is called.
|
|
|
|
*
|
|
|
|
* This method should set up the required event subscriptions.
|
|
|
|
*
|
|
|
|
* @param Sabre_DAV_Server $server
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function initialize(Sabre_DAV_Server $server) {
|
|
|
|
|
|
|
|
$server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc';
|
|
|
|
$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}id';
|
2014-05-09 19:18:43 +04:00
|
|
|
$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}perm';
|
2013-10-23 18:03:57 +04:00
|
|
|
|
|
|
|
$this->server = $server;
|
|
|
|
$this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties'));
|
2013-10-25 15:20:59 +04:00
|
|
|
$this->server->subscribeEvent('afterCreateFile', array($this, 'sendFileIdHeader'));
|
|
|
|
$this->server->subscribeEvent('afterWriteContent', array($this, 'sendFileIdHeader'));
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds all ownCloud-specific properties
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param Sabre_DAV_INode $node
|
|
|
|
* @param array $requestedProperties
|
|
|
|
* @param array $returnedProperties
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function beforeGetProperties($path, Sabre_DAV_INode $node, array &$requestedProperties, array &$returnedProperties) {
|
|
|
|
|
|
|
|
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();
|
|
|
|
if (!is_null($fileId)) {
|
|
|
|
$returnedProperties[200][$permissionsPropertyName] = $permissions;
|
2013-10-23 18:40:29 +04:00
|
|
|
}
|
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
|
2013-10-25 15:20:59 +04:00
|
|
|
* @param Sabre_DAV_INode $node
|
|
|
|
* @throws Sabre_DAV_Exception_BadRequest
|
|
|
|
*/
|
|
|
|
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'])) {
|
|
|
|
list($path, $name) = \Sabre_DAV_URLUtil::splitPath($filePath);
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|