Blame view

sources/lib/private/connector/sabre/filesplugin.php 3.17 KB
31b7f2792   Kload   Upgrade to ownclo...
1
2
3
4
5
6
7
8
9
10
  <?php
  
  /**
   * ownCloud
   *
   * @author Thomas Müller
   * @copyright 2013 Thomas Müller <thomas.mueller@tmit.eu>
   *
   * @license AGPL3
   */
6d9380f96   Cédric Dupont   Update sources OC...
11
  class OC_Connector_Sabre_FilesPlugin extends \Sabre\DAV\ServerPlugin
31b7f2792   Kload   Upgrade to ownclo...
12
13
14
15
16
17
18
19
  {
  
  	// namespace
  	const NS_OWNCLOUD = 'http://owncloud.org/ns';
  
  	/**
  	 * Reference to main server object
  	 *
6d9380f96   Cédric Dupont   Update sources OC...
20
  	 * @var \Sabre\DAV\Server
31b7f2792   Kload   Upgrade to ownclo...
21
22
23
24
25
26
  	 */
  	private $server;
  
  	/**
  	 * This initializes the plugin.
  	 *
6d9380f96   Cédric Dupont   Update sources OC...
27
  	 * This function is called by \Sabre\DAV\Server, after
31b7f2792   Kload   Upgrade to ownclo...
28
29
30
31
  	 * addPlugin is called.
  	 *
  	 * This method should set up the required event subscriptions.
  	 *
6d9380f96   Cédric Dupont   Update sources OC...
32
  	 * @param \Sabre\DAV\Server $server
31b7f2792   Kload   Upgrade to ownclo...
33
34
  	 * @return void
  	 */
6d9380f96   Cédric Dupont   Update sources OC...
35
  	public function initialize(\Sabre\DAV\Server $server) {
31b7f2792   Kload   Upgrade to ownclo...
36
37
38
  
  		$server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc';
  		$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}id';
6d9380f96   Cédric Dupont   Update sources OC...
39
  		$server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}permissions';
31b7f2792   Kload   Upgrade to ownclo...
40
41
42
43
44
45
46
47
48
49
50
  
  		$this->server = $server;
  		$this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties'));
  		$this->server->subscribeEvent('afterCreateFile', array($this, 'sendFileIdHeader'));
  		$this->server->subscribeEvent('afterWriteContent', array($this, 'sendFileIdHeader'));
  	}
  
  	/**
  	 * Adds all ownCloud-specific properties
  	 *
  	 * @param string $path
6d9380f96   Cédric Dupont   Update sources OC...
51
  	 * @param \Sabre\DAV\INode $node
31b7f2792   Kload   Upgrade to ownclo...
52
53
54
55
  	 * @param array $requestedProperties
  	 * @param array $returnedProperties
  	 * @return void
  	 */
6d9380f96   Cédric Dupont   Update sources OC...
56
  	public function beforeGetProperties($path, \Sabre\DAV\INode $node, array &$requestedProperties, array &$returnedProperties) {
31b7f2792   Kload   Upgrade to ownclo...
57
58
  
  		if ($node instanceof OC_Connector_Sabre_Node) {
6d9380f96   Cédric Dupont   Update sources OC...
59
60
61
62
63
64
65
  			$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)]);
31b7f2792   Kload   Upgrade to ownclo...
66
67
68
69
70
  			}
  
  			/** @var $node OC_Connector_Sabre_Node */
  			$fileId = $node->getFileId();
  			if (!is_null($fileId)) {
6d9380f96   Cédric Dupont   Update sources OC...
71
72
73
74
75
76
  				$returnedProperties[200][$fileIdPropertyName] = $fileId;
  			}
  
  			$permissions = $node->getDavPermissions();
  			if (!is_null($fileId)) {
  				$returnedProperties[200][$permissionsPropertyName] = $permissions;
31b7f2792   Kload   Upgrade to ownclo...
77
78
79
80
81
82
83
  			}
  
  		}
  
  	}
  
  	/**
6d9380f96   Cédric Dupont   Update sources OC...
84
85
86
  	 * @param string $filePath
  	 * @param \Sabre\DAV\INode $node
  	 * @throws \Sabre\DAV\Exception\BadRequest
31b7f2792   Kload   Upgrade to ownclo...
87
  	 */
6d9380f96   Cédric Dupont   Update sources OC...
88
  	public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
31b7f2792   Kload   Upgrade to ownclo...
89
90
  		// chunked upload handling
  		if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
6d9380f96   Cédric Dupont   Update sources OC...
91
  			list($path, $name) = \Sabre\DAV\URLUtil::splitPath($filePath);
31b7f2792   Kload   Upgrade to ownclo...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  			$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);
  			}
  		}
  	}
  
  }