Passed
Push — master ( 32577f...c1368b )
by Robin
11:13 queued 10s
created
apps/dav/lib/Connector/Sabre/TagList.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -34,92 +34,92 @@
 block discarded – undo
34 34
  * This property contains multiple "tag" elements, each containing a tag name.
35 35
  */
36 36
 class TagList implements Element {
37
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
37
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
38 38
 
39
-	/**
40
-	 * tags
41
-	 *
42
-	 * @var array
43
-	 */
44
-	private $tags;
39
+    /**
40
+     * tags
41
+     *
42
+     * @var array
43
+     */
44
+    private $tags;
45 45
 
46
-	/**
47
-	 * @param array $tags
48
-	 */
49
-	public function __construct(array $tags) {
50
-		$this->tags = $tags;
51
-	}
46
+    /**
47
+     * @param array $tags
48
+     */
49
+    public function __construct(array $tags) {
50
+        $this->tags = $tags;
51
+    }
52 52
 
53
-	/**
54
-	 * Returns the tags
55
-	 *
56
-	 * @return array
57
-	 */
58
-	public function getTags() {
53
+    /**
54
+     * Returns the tags
55
+     *
56
+     * @return array
57
+     */
58
+    public function getTags() {
59 59
 
60
-		return $this->tags;
60
+        return $this->tags;
61 61
 
62
-	}
62
+    }
63 63
 
64
-	/**
65
-	 * The deserialize method is called during xml parsing.
66
-	 *
67
-	 * This method is called statictly, this is because in theory this method
68
-	 * may be used as a type of constructor, or factory method.
69
-	 *
70
-	 * Often you want to return an instance of the current class, but you are
71
-	 * free to return other data as well.
72
-	 *
73
-	 * You are responsible for advancing the reader to the next element. Not
74
-	 * doing anything will result in a never-ending loop.
75
-	 *
76
-	 * If you just want to skip parsing for this element altogether, you can
77
-	 * just call $reader->next();
78
-	 *
79
-	 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
80
-	 * the next element.
81
-	 *
82
-	 * @param Reader $reader
83
-	 * @return mixed
84
-	 */
85
-	static function xmlDeserialize(Reader $reader) {
86
-		$tags = [];
64
+    /**
65
+     * The deserialize method is called during xml parsing.
66
+     *
67
+     * This method is called statictly, this is because in theory this method
68
+     * may be used as a type of constructor, or factory method.
69
+     *
70
+     * Often you want to return an instance of the current class, but you are
71
+     * free to return other data as well.
72
+     *
73
+     * You are responsible for advancing the reader to the next element. Not
74
+     * doing anything will result in a never-ending loop.
75
+     *
76
+     * If you just want to skip parsing for this element altogether, you can
77
+     * just call $reader->next();
78
+     *
79
+     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
80
+     * the next element.
81
+     *
82
+     * @param Reader $reader
83
+     * @return mixed
84
+     */
85
+    static function xmlDeserialize(Reader $reader) {
86
+        $tags = [];
87 87
 
88
-		$tree = $reader->parseInnerTree();
89
-		if ($tree === null) {
90
-			return null;
91
-		}
92
-		foreach ($tree as $elem) {
93
-			if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
94
-				$tags[] = $elem['value'];
95
-			}
96
-		}
97
-		return new self($tags);
98
-	}
88
+        $tree = $reader->parseInnerTree();
89
+        if ($tree === null) {
90
+            return null;
91
+        }
92
+        foreach ($tree as $elem) {
93
+            if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
94
+                $tags[] = $elem['value'];
95
+            }
96
+        }
97
+        return new self($tags);
98
+    }
99 99
 
100
-	/**
101
-	 * The xmlSerialize metod is called during xml writing.
102
-	 *
103
-	 * Use the $writer argument to write its own xml serialization.
104
-	 *
105
-	 * An important note: do _not_ create a parent element. Any element
106
-	 * implementing XmlSerializble should only ever write what's considered
107
-	 * its 'inner xml'.
108
-	 *
109
-	 * The parent of the current element is responsible for writing a
110
-	 * containing element.
111
-	 *
112
-	 * This allows serializers to be re-used for different element names.
113
-	 *
114
-	 * If you are opening new elements, you must also close them again.
115
-	 *
116
-	 * @param Writer $writer
117
-	 * @return void
118
-	 */
119
-	function xmlSerialize(Writer $writer) {
100
+    /**
101
+     * The xmlSerialize metod is called during xml writing.
102
+     *
103
+     * Use the $writer argument to write its own xml serialization.
104
+     *
105
+     * An important note: do _not_ create a parent element. Any element
106
+     * implementing XmlSerializble should only ever write what's considered
107
+     * its 'inner xml'.
108
+     *
109
+     * The parent of the current element is responsible for writing a
110
+     * containing element.
111
+     *
112
+     * This allows serializers to be re-used for different element names.
113
+     *
114
+     * If you are opening new elements, you must also close them again.
115
+     *
116
+     * @param Writer $writer
117
+     * @return void
118
+     */
119
+    function xmlSerialize(Writer $writer) {
120 120
 
121
-		foreach ($this->tags as $tag) {
122
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag);
123
-		}
124
-	}
121
+        foreach ($this->tags as $tag) {
122
+            $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag);
123
+        }
124
+    }
125 125
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 			return null;
91 91
 		}
92 92
 		foreach ($tree as $elem) {
93
-			if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
93
+			if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') {
94 94
 				$tags[] = $elem['value'];
95 95
 			}
96 96
 		}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	function xmlSerialize(Writer $writer) {
120 120
 
121 121
 		foreach ($this->tags as $tag) {
122
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag);
122
+			$writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag);
123 123
 		}
124 124
 	}
125 125
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/FilesPlugin.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -245,7 +245,9 @@
 block discarded – undo
245 245
 	function httpGet(RequestInterface $request, ResponseInterface $response) {
246 246
 		// Only handle valid files
247 247
 		$node = $this->tree->getNodeForPath($request->getPath());
248
-		if (!($node instanceof IFile)) return;
248
+		if (!($node instanceof IFile)) {
249
+		    return;
250
+		}
249 251
 
250 252
 		// adds a 'Content-Disposition: attachment' header in case no disposition
251 253
 		// header has been set before
Please login to merge, or discard this patch.
Indentation   +462 added lines, -462 removed lines patch added patch discarded remove patch
@@ -52,470 +52,470 @@
 block discarded – undo
52 52
 
53 53
 class FilesPlugin extends ServerPlugin {
54 54
 
55
-	// namespace
56
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
57
-	const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
58
-	const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
59
-	const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
60
-	const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
61
-	const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
62
-	const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions';
63
-	const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
64
-	const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
65
-	const GETETAG_PROPERTYNAME = '{DAV:}getetag';
66
-	const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
67
-	const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
68
-	const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
69
-	const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
70
-	const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
71
-	const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
72
-	const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
73
-	const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
74
-	const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
75
-	const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
76
-	const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
77
-	const SHARE_NOTE = '{http://nextcloud.org/ns}note';
78
-
79
-	/**
80
-	 * Reference to main server object
81
-	 *
82
-	 * @var \Sabre\DAV\Server
83
-	 */
84
-	private $server;
85
-
86
-	/**
87
-	 * @var Tree
88
-	 */
89
-	private $tree;
90
-
91
-	/**
92
-	 * Whether this is public webdav.
93
-	 * If true, some returned information will be stripped off.
94
-	 *
95
-	 * @var bool
96
-	 */
97
-	private $isPublic;
98
-
99
-	/**
100
-	 * @var bool
101
-	 */
102
-	private $downloadAttachment;
103
-
104
-	/**
105
-	 * @var IConfig
106
-	 */
107
-	private $config;
108
-
109
-	/**
110
-	 * @var IRequest
111
-	 */
112
-	private $request;
113
-
114
-	/**
115
-	 * @var IPreview
116
-	 */
117
-	private $previewManager;
118
-
119
-	/**
120
-	 * @param Tree $tree
121
-	 * @param IConfig $config
122
-	 * @param IRequest $request
123
-	 * @param IPreview $previewManager
124
-	 * @param bool $isPublic
125
-	 * @param bool $downloadAttachment
126
-	 */
127
-	public function __construct(Tree $tree,
128
-								IConfig $config,
129
-								IRequest $request,
130
-								IPreview $previewManager,
131
-								$isPublic = false,
132
-								$downloadAttachment = true) {
133
-		$this->tree = $tree;
134
-		$this->config = $config;
135
-		$this->request = $request;
136
-		$this->isPublic = $isPublic;
137
-		$this->downloadAttachment = $downloadAttachment;
138
-		$this->previewManager = $previewManager;
139
-	}
140
-
141
-	/**
142
-	 * This initializes the plugin.
143
-	 *
144
-	 * This function is called by \Sabre\DAV\Server, after
145
-	 * addPlugin is called.
146
-	 *
147
-	 * This method should set up the required event subscriptions.
148
-	 *
149
-	 * @param \Sabre\DAV\Server $server
150
-	 * @return void
151
-	 */
152
-	public function initialize(\Sabre\DAV\Server $server) {
153
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
154
-		$server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
155
-		$server->protectedProperties[] = self::FILEID_PROPERTYNAME;
156
-		$server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
157
-		$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
158
-		$server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
159
-		$server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
160
-		$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
161
-		$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
162
-		$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
163
-		$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
164
-		$server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
165
-		$server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
166
-		$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
167
-		$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
168
-		$server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
169
-		$server->protectedProperties[] = self::SHARE_NOTE;
170
-
171
-		// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
172
-		$allowedProperties = ['{DAV:}getetag'];
173
-		$server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
174
-
175
-		$this->server = $server;
176
-		$this->server->on('propFind', [$this, 'handleGetProperties']);
177
-		$this->server->on('propPatch', [$this, 'handleUpdateProperties']);
178
-		$this->server->on('afterBind', [$this, 'sendFileIdHeader']);
179
-		$this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']);
180
-		$this->server->on('afterMethod:GET', [$this,'httpGet']);
181
-		$this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']);
182
-		$this->server->on('afterResponse', function($request, ResponseInterface $response) {
183
-			$body = $response->getBody();
184
-			if (is_resource($body)) {
185
-				fclose($body);
186
-			}
187
-		});
188
-		$this->server->on('beforeMove', [$this, 'checkMove']);
189
-	}
190
-
191
-	/**
192
-	 * Plugin that checks if a move can actually be performed.
193
-	 *
194
-	 * @param string $source source path
195
-	 * @param string $destination destination path
196
-	 * @throws Forbidden
197
-	 * @throws NotFound
198
-	 */
199
-	function checkMove($source, $destination) {
200
-		$sourceNode = $this->tree->getNodeForPath($source);
201
-		if (!$sourceNode instanceof Node) {
202
-			return;
203
-		}
204
-		list($sourceDir,) = \Sabre\Uri\split($source);
205
-		list($destinationDir,) = \Sabre\Uri\split($destination);
206
-
207
-		if ($sourceDir !== $destinationDir) {
208
-			$sourceNodeFileInfo = $sourceNode->getFileInfo();
209
-			if ($sourceNodeFileInfo === null) {
210
-				throw new NotFound($source . ' does not exist');
211
- 			}
212
-
213
-			if (!$sourceNodeFileInfo->isDeletable()) {
214
-				throw new Forbidden($source . " cannot be deleted");
215
-			}
216
-		}
217
-	}
218
-
219
-	/**
220
-	 * This sets a cookie to be able to recognize the start of the download
221
-	 * the content must not be longer than 32 characters and must only contain
222
-	 * alphanumeric characters
223
-	 *
224
-	 * @param RequestInterface $request
225
-	 * @param ResponseInterface $response
226
-	 */
227
-	function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
228
-		$queryParams = $request->getQueryParameters();
229
-
230
-		/**
231
-		 * this sets a cookie to be able to recognize the start of the download
232
-		 * the content must not be longer than 32 characters and must only contain
233
-		 * alphanumeric characters
234
-		 */
235
-		if (isset($queryParams['downloadStartSecret'])) {
236
-			$token = $queryParams['downloadStartSecret'];
237
-			if (!isset($token[32])
238
-				&& preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
239
-				// FIXME: use $response->setHeader() instead
240
-				setcookie('ocDownloadStarted', $token, time() + 20, '/');
241
-			}
242
-		}
243
-	}
244
-
245
-	/**
246
-	 * Add headers to file download
247
-	 *
248
-	 * @param RequestInterface $request
249
-	 * @param ResponseInterface $response
250
-	 */
251
-	function httpGet(RequestInterface $request, ResponseInterface $response) {
252
-		// Only handle valid files
253
-		$node = $this->tree->getNodeForPath($request->getPath());
254
-		if (!($node instanceof IFile)) return;
255
-
256
-		// adds a 'Content-Disposition: attachment' header in case no disposition
257
-		// header has been set before
258
-		if ($this->downloadAttachment &&
259
-			$response->getHeader('Content-Disposition') === null) {
260
-			$filename = $node->getName();
261
-			if ($this->request->isUserAgent(
262
-				[
263
-					Request::USER_AGENT_IE,
264
-					Request::USER_AGENT_ANDROID_MOBILE_CHROME,
265
-					Request::USER_AGENT_FREEBOX,
266
-				])) {
267
-				$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
268
-			} else {
269
-				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
270
-													 . '; filename="' . rawurlencode($filename) . '"');
271
-			}
272
-		}
273
-
274
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
275
-			//Add OC-Checksum header
276
-			/** @var $node File */
277
-			$checksum = $node->getChecksum();
278
-			if ($checksum !== null && $checksum !== '') {
279
-				$response->addHeader('OC-Checksum', $checksum);
280
-			}
281
-		}
282
-	}
283
-
284
-	/**
285
-	 * Adds all ownCloud-specific properties
286
-	 *
287
-	 * @param PropFind $propFind
288
-	 * @param \Sabre\DAV\INode $node
289
-	 * @return void
290
-	 */
291
-	public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
292
-
293
-		$httpRequest = $this->server->httpRequest;
294
-
295
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
296
-			/**
297
-			 * This was disabled, because it made dir listing throw an exception,
298
-			 * so users were unable to navigate into folders where one subitem
299
-			 * is blocked by the files_accesscontrol app, see:
300
-			 * https://github.com/nextcloud/files_accesscontrol/issues/65
55
+    // namespace
56
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
57
+    const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
58
+    const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
59
+    const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
60
+    const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
61
+    const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
62
+    const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions';
63
+    const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
64
+    const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
65
+    const GETETAG_PROPERTYNAME = '{DAV:}getetag';
66
+    const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
67
+    const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
68
+    const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
69
+    const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
70
+    const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
71
+    const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
72
+    const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
73
+    const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
74
+    const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
75
+    const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
76
+    const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
77
+    const SHARE_NOTE = '{http://nextcloud.org/ns}note';
78
+
79
+    /**
80
+     * Reference to main server object
81
+     *
82
+     * @var \Sabre\DAV\Server
83
+     */
84
+    private $server;
85
+
86
+    /**
87
+     * @var Tree
88
+     */
89
+    private $tree;
90
+
91
+    /**
92
+     * Whether this is public webdav.
93
+     * If true, some returned information will be stripped off.
94
+     *
95
+     * @var bool
96
+     */
97
+    private $isPublic;
98
+
99
+    /**
100
+     * @var bool
101
+     */
102
+    private $downloadAttachment;
103
+
104
+    /**
105
+     * @var IConfig
106
+     */
107
+    private $config;
108
+
109
+    /**
110
+     * @var IRequest
111
+     */
112
+    private $request;
113
+
114
+    /**
115
+     * @var IPreview
116
+     */
117
+    private $previewManager;
118
+
119
+    /**
120
+     * @param Tree $tree
121
+     * @param IConfig $config
122
+     * @param IRequest $request
123
+     * @param IPreview $previewManager
124
+     * @param bool $isPublic
125
+     * @param bool $downloadAttachment
126
+     */
127
+    public function __construct(Tree $tree,
128
+                                IConfig $config,
129
+                                IRequest $request,
130
+                                IPreview $previewManager,
131
+                                $isPublic = false,
132
+                                $downloadAttachment = true) {
133
+        $this->tree = $tree;
134
+        $this->config = $config;
135
+        $this->request = $request;
136
+        $this->isPublic = $isPublic;
137
+        $this->downloadAttachment = $downloadAttachment;
138
+        $this->previewManager = $previewManager;
139
+    }
140
+
141
+    /**
142
+     * This initializes the plugin.
143
+     *
144
+     * This function is called by \Sabre\DAV\Server, after
145
+     * addPlugin is called.
146
+     *
147
+     * This method should set up the required event subscriptions.
148
+     *
149
+     * @param \Sabre\DAV\Server $server
150
+     * @return void
151
+     */
152
+    public function initialize(\Sabre\DAV\Server $server) {
153
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
154
+        $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
155
+        $server->protectedProperties[] = self::FILEID_PROPERTYNAME;
156
+        $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
157
+        $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
158
+        $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
159
+        $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
160
+        $server->protectedProperties[] = self::SIZE_PROPERTYNAME;
161
+        $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
162
+        $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
163
+        $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
164
+        $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
165
+        $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
166
+        $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
167
+        $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
168
+        $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
169
+        $server->protectedProperties[] = self::SHARE_NOTE;
170
+
171
+        // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
172
+        $allowedProperties = ['{DAV:}getetag'];
173
+        $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
174
+
175
+        $this->server = $server;
176
+        $this->server->on('propFind', [$this, 'handleGetProperties']);
177
+        $this->server->on('propPatch', [$this, 'handleUpdateProperties']);
178
+        $this->server->on('afterBind', [$this, 'sendFileIdHeader']);
179
+        $this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']);
180
+        $this->server->on('afterMethod:GET', [$this,'httpGet']);
181
+        $this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']);
182
+        $this->server->on('afterResponse', function($request, ResponseInterface $response) {
183
+            $body = $response->getBody();
184
+            if (is_resource($body)) {
185
+                fclose($body);
186
+            }
187
+        });
188
+        $this->server->on('beforeMove', [$this, 'checkMove']);
189
+    }
190
+
191
+    /**
192
+     * Plugin that checks if a move can actually be performed.
193
+     *
194
+     * @param string $source source path
195
+     * @param string $destination destination path
196
+     * @throws Forbidden
197
+     * @throws NotFound
198
+     */
199
+    function checkMove($source, $destination) {
200
+        $sourceNode = $this->tree->getNodeForPath($source);
201
+        if (!$sourceNode instanceof Node) {
202
+            return;
203
+        }
204
+        list($sourceDir,) = \Sabre\Uri\split($source);
205
+        list($destinationDir,) = \Sabre\Uri\split($destination);
206
+
207
+        if ($sourceDir !== $destinationDir) {
208
+            $sourceNodeFileInfo = $sourceNode->getFileInfo();
209
+            if ($sourceNodeFileInfo === null) {
210
+                throw new NotFound($source . ' does not exist');
211
+                }
212
+
213
+            if (!$sourceNodeFileInfo->isDeletable()) {
214
+                throw new Forbidden($source . " cannot be deleted");
215
+            }
216
+        }
217
+    }
218
+
219
+    /**
220
+     * This sets a cookie to be able to recognize the start of the download
221
+     * the content must not be longer than 32 characters and must only contain
222
+     * alphanumeric characters
223
+     *
224
+     * @param RequestInterface $request
225
+     * @param ResponseInterface $response
226
+     */
227
+    function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
228
+        $queryParams = $request->getQueryParameters();
229
+
230
+        /**
231
+         * this sets a cookie to be able to recognize the start of the download
232
+         * the content must not be longer than 32 characters and must only contain
233
+         * alphanumeric characters
234
+         */
235
+        if (isset($queryParams['downloadStartSecret'])) {
236
+            $token = $queryParams['downloadStartSecret'];
237
+            if (!isset($token[32])
238
+                && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
239
+                // FIXME: use $response->setHeader() instead
240
+                setcookie('ocDownloadStarted', $token, time() + 20, '/');
241
+            }
242
+        }
243
+    }
244
+
245
+    /**
246
+     * Add headers to file download
247
+     *
248
+     * @param RequestInterface $request
249
+     * @param ResponseInterface $response
250
+     */
251
+    function httpGet(RequestInterface $request, ResponseInterface $response) {
252
+        // Only handle valid files
253
+        $node = $this->tree->getNodeForPath($request->getPath());
254
+        if (!($node instanceof IFile)) return;
255
+
256
+        // adds a 'Content-Disposition: attachment' header in case no disposition
257
+        // header has been set before
258
+        if ($this->downloadAttachment &&
259
+            $response->getHeader('Content-Disposition') === null) {
260
+            $filename = $node->getName();
261
+            if ($this->request->isUserAgent(
262
+                [
263
+                    Request::USER_AGENT_IE,
264
+                    Request::USER_AGENT_ANDROID_MOBILE_CHROME,
265
+                    Request::USER_AGENT_FREEBOX,
266
+                ])) {
267
+                $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
268
+            } else {
269
+                $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
270
+                                                        . '; filename="' . rawurlencode($filename) . '"');
271
+            }
272
+        }
273
+
274
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
275
+            //Add OC-Checksum header
276
+            /** @var $node File */
277
+            $checksum = $node->getChecksum();
278
+            if ($checksum !== null && $checksum !== '') {
279
+                $response->addHeader('OC-Checksum', $checksum);
280
+            }
281
+        }
282
+    }
283
+
284
+    /**
285
+     * Adds all ownCloud-specific properties
286
+     *
287
+     * @param PropFind $propFind
288
+     * @param \Sabre\DAV\INode $node
289
+     * @return void
290
+     */
291
+    public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
292
+
293
+        $httpRequest = $this->server->httpRequest;
294
+
295
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
296
+            /**
297
+             * This was disabled, because it made dir listing throw an exception,
298
+             * so users were unable to navigate into folders where one subitem
299
+             * is blocked by the files_accesscontrol app, see:
300
+             * https://github.com/nextcloud/files_accesscontrol/issues/65
301 301
 			if (!$node->getFileInfo()->isReadable()) {
302 302
 				// avoid detecting files through this means
303 303
 				throw new NotFound();
304 304
 			}
305
-			 */
306
-
307
-			$propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
308
-				return $node->getFileId();
309
-			});
310
-
311
-			$propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
312
-				return $node->getInternalFileId();
313
-			});
314
-
315
-			$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
316
-				$perms = $node->getDavPermissions();
317
-				if ($this->isPublic) {
318
-					// remove mount information
319
-					$perms = str_replace(['S', 'M'], '', $perms);
320
-				}
321
-				return $perms;
322
-			});
323
-
324
-			$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
325
-				return $node->getSharePermissions(
326
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
327
-				);
328
-			});
329
-
330
-			$propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
331
-				$ncPermissions = $node->getSharePermissions(
332
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
333
-				);
334
-				$ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
335
-				return json_encode($ocmPermissions);
336
-			});
337
-
338
-			$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
339
-				return $node->getETag();
340
-			});
341
-
342
-			$propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
343
-				$owner = $node->getOwner();
344
-				if (!$owner) {
345
-					return null;
346
-				} else {
347
-					return $owner->getUID();
348
-				}
349
-			});
350
-			$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
351
-				$owner = $node->getOwner();
352
-				if (!$owner) {
353
-					return null;
354
-				} else {
355
-					return $owner->getDisplayName();
356
-				}
357
-			});
358
-
359
-			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
360
-				return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
361
-			});
362
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
363
-				return $node->getSize();
364
-			});
365
-			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
366
-				return $node->getFileInfo()->getMountPoint()->getMountType();
367
-			});
368
-
369
-			$propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) {
370
-				return $node->getNoteFromShare(
371
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
372
-				);
373
-			});
374
-		}
375
-
376
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
377
-			$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
378
-				return $this->config->getSystemValue('data-fingerprint', '');
379
-			});
380
-		}
381
-
382
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
383
-			$propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
384
-				/** @var $node \OCA\DAV\Connector\Sabre\File */
385
-				try {
386
-					$directDownloadUrl = $node->getDirectDownload();
387
-					if (isset($directDownloadUrl['url'])) {
388
-						return $directDownloadUrl['url'];
389
-					}
390
-				} catch (StorageNotAvailableException $e) {
391
-					return false;
392
-				} catch (ForbiddenException $e) {
393
-					return false;
394
-				}
395
-				return false;
396
-			});
397
-
398
-			$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
399
-				$checksum = $node->getChecksum();
400
-				if ($checksum === null || $checksum === '') {
401
-					return null;
402
-				}
403
-
404
-				return new ChecksumList($checksum);
405
-			});
406
-
407
-			$propFind->handle(self::CREATION_TIME_PROPERTYNAME, function() use ($node) {
408
-				return $node->getFileInfo()->getCreationTime();
409
-			});
410
-
411
-			$propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function() use ($node) {
412
-				return $node->getFileInfo()->getUploadTime();
413
-			});
414
-
415
-		}
416
-
417
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
418
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
419
-				return $node->getSize();
420
-			});
421
-
422
-			$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
423
-				return $node->getFileInfo()->isEncrypted() ? '1' : '0';
424
-			});
425
-		}
426
-	}
427
-
428
-	/**
429
-	 * translate Nextcloud permissions to OCM Permissions
430
-	 *
431
-	 * @param $ncPermissions
432
-	 * @return array
433
-	 */
434
-	protected function ncPermissions2ocmPermissions($ncPermissions) {
435
-
436
-		$ocmPermissions = [];
437
-
438
-		if ($ncPermissions & Constants::PERMISSION_SHARE) {
439
-			$ocmPermissions[] = 'share';
440
-		}
441
-
442
-		if ($ncPermissions & Constants::PERMISSION_READ) {
443
-			$ocmPermissions[] = 'read';
444
-		}
445
-
446
-		if (($ncPermissions & Constants::PERMISSION_CREATE) ||
447
-			($ncPermissions & Constants::PERMISSION_UPDATE)) {
448
-			$ocmPermissions[] = 'write';
449
-		}
450
-
451
-		return $ocmPermissions;
452
-
453
-	}
454
-
455
-	/**
456
-	 * Update ownCloud-specific properties
457
-	 *
458
-	 * @param string $path
459
-	 * @param PropPatch $propPatch
460
-	 *
461
-	 * @return void
462
-	 */
463
-	public function handleUpdateProperties($path, PropPatch $propPatch) {
464
-		$node = $this->tree->getNodeForPath($path);
465
-		if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
466
-			return;
467
-		}
468
-
469
-		$propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
470
-			if (empty($time)) {
471
-				return false;
472
-			}
473
-			$node->touch($time);
474
-			return true;
475
-		});
476
-		$propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
477
-			if (empty($etag)) {
478
-				return false;
479
-			}
480
-			if ($node->setEtag($etag) !== -1) {
481
-				return true;
482
-			}
483
-			return false;
484
-		});
485
-		$propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function($time) use ($node) {
486
-			if (empty($time)) {
487
-				return false;
488
-			}
489
-			$node->setCreationTime((int) $time);
490
-			return true;
491
-		});
492
-	}
493
-
494
-	/**
495
-	 * @param string $filePath
496
-	 * @param \Sabre\DAV\INode $node
497
-	 * @throws \Sabre\DAV\Exception\BadRequest
498
-	 */
499
-	public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
500
-		// chunked upload handling
501
-		if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
502
-			list($path, $name) = \Sabre\Uri\split($filePath);
503
-			$info = \OC_FileChunking::decodeName($name);
504
-			if (!empty($info)) {
505
-				$filePath = $path . '/' . $info['name'];
506
-			}
507
-		}
508
-
509
-		// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
510
-		if (!$this->server->tree->nodeExists($filePath)) {
511
-			return;
512
-		}
513
-		$node = $this->server->tree->getNodeForPath($filePath);
514
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
515
-			$fileId = $node->getFileId();
516
-			if (!is_null($fileId)) {
517
-				$this->server->httpResponse->setHeader('OC-FileId', $fileId);
518
-			}
519
-		}
520
-	}
305
+             */
306
+
307
+            $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
308
+                return $node->getFileId();
309
+            });
310
+
311
+            $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
312
+                return $node->getInternalFileId();
313
+            });
314
+
315
+            $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
316
+                $perms = $node->getDavPermissions();
317
+                if ($this->isPublic) {
318
+                    // remove mount information
319
+                    $perms = str_replace(['S', 'M'], '', $perms);
320
+                }
321
+                return $perms;
322
+            });
323
+
324
+            $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
325
+                return $node->getSharePermissions(
326
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
327
+                );
328
+            });
329
+
330
+            $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
331
+                $ncPermissions = $node->getSharePermissions(
332
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
333
+                );
334
+                $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
335
+                return json_encode($ocmPermissions);
336
+            });
337
+
338
+            $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
339
+                return $node->getETag();
340
+            });
341
+
342
+            $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
343
+                $owner = $node->getOwner();
344
+                if (!$owner) {
345
+                    return null;
346
+                } else {
347
+                    return $owner->getUID();
348
+                }
349
+            });
350
+            $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
351
+                $owner = $node->getOwner();
352
+                if (!$owner) {
353
+                    return null;
354
+                } else {
355
+                    return $owner->getDisplayName();
356
+                }
357
+            });
358
+
359
+            $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
360
+                return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
361
+            });
362
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
363
+                return $node->getSize();
364
+            });
365
+            $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
366
+                return $node->getFileInfo()->getMountPoint()->getMountType();
367
+            });
368
+
369
+            $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) {
370
+                return $node->getNoteFromShare(
371
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
372
+                );
373
+            });
374
+        }
375
+
376
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
377
+            $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
378
+                return $this->config->getSystemValue('data-fingerprint', '');
379
+            });
380
+        }
381
+
382
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
383
+            $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
384
+                /** @var $node \OCA\DAV\Connector\Sabre\File */
385
+                try {
386
+                    $directDownloadUrl = $node->getDirectDownload();
387
+                    if (isset($directDownloadUrl['url'])) {
388
+                        return $directDownloadUrl['url'];
389
+                    }
390
+                } catch (StorageNotAvailableException $e) {
391
+                    return false;
392
+                } catch (ForbiddenException $e) {
393
+                    return false;
394
+                }
395
+                return false;
396
+            });
397
+
398
+            $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
399
+                $checksum = $node->getChecksum();
400
+                if ($checksum === null || $checksum === '') {
401
+                    return null;
402
+                }
403
+
404
+                return new ChecksumList($checksum);
405
+            });
406
+
407
+            $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function() use ($node) {
408
+                return $node->getFileInfo()->getCreationTime();
409
+            });
410
+
411
+            $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function() use ($node) {
412
+                return $node->getFileInfo()->getUploadTime();
413
+            });
414
+
415
+        }
416
+
417
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
418
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
419
+                return $node->getSize();
420
+            });
421
+
422
+            $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
423
+                return $node->getFileInfo()->isEncrypted() ? '1' : '0';
424
+            });
425
+        }
426
+    }
427
+
428
+    /**
429
+     * translate Nextcloud permissions to OCM Permissions
430
+     *
431
+     * @param $ncPermissions
432
+     * @return array
433
+     */
434
+    protected function ncPermissions2ocmPermissions($ncPermissions) {
435
+
436
+        $ocmPermissions = [];
437
+
438
+        if ($ncPermissions & Constants::PERMISSION_SHARE) {
439
+            $ocmPermissions[] = 'share';
440
+        }
441
+
442
+        if ($ncPermissions & Constants::PERMISSION_READ) {
443
+            $ocmPermissions[] = 'read';
444
+        }
445
+
446
+        if (($ncPermissions & Constants::PERMISSION_CREATE) ||
447
+            ($ncPermissions & Constants::PERMISSION_UPDATE)) {
448
+            $ocmPermissions[] = 'write';
449
+        }
450
+
451
+        return $ocmPermissions;
452
+
453
+    }
454
+
455
+    /**
456
+     * Update ownCloud-specific properties
457
+     *
458
+     * @param string $path
459
+     * @param PropPatch $propPatch
460
+     *
461
+     * @return void
462
+     */
463
+    public function handleUpdateProperties($path, PropPatch $propPatch) {
464
+        $node = $this->tree->getNodeForPath($path);
465
+        if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
466
+            return;
467
+        }
468
+
469
+        $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
470
+            if (empty($time)) {
471
+                return false;
472
+            }
473
+            $node->touch($time);
474
+            return true;
475
+        });
476
+        $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
477
+            if (empty($etag)) {
478
+                return false;
479
+            }
480
+            if ($node->setEtag($etag) !== -1) {
481
+                return true;
482
+            }
483
+            return false;
484
+        });
485
+        $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function($time) use ($node) {
486
+            if (empty($time)) {
487
+                return false;
488
+            }
489
+            $node->setCreationTime((int) $time);
490
+            return true;
491
+        });
492
+    }
493
+
494
+    /**
495
+     * @param string $filePath
496
+     * @param \Sabre\DAV\INode $node
497
+     * @throws \Sabre\DAV\Exception\BadRequest
498
+     */
499
+    public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
500
+        // chunked upload handling
501
+        if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
502
+            list($path, $name) = \Sabre\Uri\split($filePath);
503
+            $info = \OC_FileChunking::decodeName($name);
504
+            if (!empty($info)) {
505
+                $filePath = $path . '/' . $info['name'];
506
+            }
507
+        }
508
+
509
+        // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
510
+        if (!$this->server->tree->nodeExists($filePath)) {
511
+            return;
512
+        }
513
+        $node = $this->server->tree->getNodeForPath($filePath);
514
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
515
+            $fileId = $node->getFileId();
516
+            if (!is_null($fileId)) {
517
+                $this->server->httpResponse->setHeader('OC-FileId', $fileId);
518
+            }
519
+        }
520
+    }
521 521
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 		$this->server->on('propPatch', [$this, 'handleUpdateProperties']);
178 178
 		$this->server->on('afterBind', [$this, 'sendFileIdHeader']);
179 179
 		$this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']);
180
-		$this->server->on('afterMethod:GET', [$this,'httpGet']);
180
+		$this->server->on('afterMethod:GET', [$this, 'httpGet']);
181 181
 		$this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']);
182 182
 		$this->server->on('afterResponse', function($request, ResponseInterface $response) {
183 183
 			$body = $response->getBody();
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
 		if ($sourceDir !== $destinationDir) {
208 208
 			$sourceNodeFileInfo = $sourceNode->getFileInfo();
209 209
 			if ($sourceNodeFileInfo === null) {
210
-				throw new NotFound($source . ' does not exist');
210
+				throw new NotFound($source.' does not exist');
211 211
  			}
212 212
 
213 213
 			if (!$sourceNodeFileInfo->isDeletable()) {
214
-				throw new Forbidden($source . " cannot be deleted");
214
+				throw new Forbidden($source." cannot be deleted");
215 215
 			}
216 216
 		}
217 217
 	}
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
 					Request::USER_AGENT_ANDROID_MOBILE_CHROME,
265 265
 					Request::USER_AGENT_FREEBOX,
266 266
 				])) {
267
-				$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
267
+				$response->addHeader('Content-Disposition', 'attachment; filename="'.rawurlencode($filename).'"');
268 268
 			} else {
269
-				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
270
-													 . '; filename="' . rawurlencode($filename) . '"');
269
+				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\''.rawurlencode($filename)
270
+													 . '; filename="'.rawurlencode($filename).'"');
271 271
 			}
272 272
 		}
273 273
 
@@ -356,13 +356,13 @@  discard block
 block discarded – undo
356 356
 				}
357 357
 			});
358 358
 
359
-			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
359
+			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function() use ($node) {
360 360
 				return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
361 361
 			});
362 362
 			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
363 363
 				return $node->getSize();
364 364
 			});
365
-			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
365
+			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function() use ($node) {
366 366
 				return $node->getFileInfo()->getMountPoint()->getMountType();
367 367
 			});
368 368
 
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 			list($path, $name) = \Sabre\Uri\split($filePath);
503 503
 			$info = \OC_FileChunking::decodeName($name);
504 504
 			if (!empty($info)) {
505
-				$filePath = $path . '/' . $info['name'];
505
+				$filePath = $path.'/'.$info['name'];
506 506
 			}
507 507
 		}
508 508
 
Please login to merge, or discard this patch.
apps/dav/lib/Connector/LegacyDAVACL.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -60,9 +60,9 @@
 block discarded – undo
60 60
 
61 61
 	public function propFind(PropFind $propFind, INode $node) {
62 62
 		/* Overload current-user-principal */
63
-		$propFind->handle('{DAV:}current-user-principal', function () {
63
+		$propFind->handle('{DAV:}current-user-principal', function() {
64 64
 			if ($url = parent::getCurrentUserPrincipal()) {
65
-				return new Principal(Principal::HREF, $url . '/');
65
+				return new Principal(Principal::HREF, $url.'/');
66 66
 			} else {
67 67
 				return new Principal(Principal::UNAUTHENTICATED);
68 68
 			}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,9 @@
 block discarded – undo
38 38
 	public function getCurrentUserPrincipals() {
39 39
 		$principalV2 = $this->getCurrentUserPrincipal();
40 40
 
41
-		if (is_null($principalV2)) return [];
41
+		if (is_null($principalV2)) {
42
+		    return [];
43
+		}
42 44
 
43 45
 		$principalV1 = $this->convertPrincipal($principalV2, false);
44 46
 		return array_merge(
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -32,42 +32,42 @@
 block discarded – undo
32 32
 
33 33
 class LegacyDAVACL extends DavAclPlugin {
34 34
 
35
-	/**
36
-	 * @inheritdoc
37
-	 */
38
-	public function getCurrentUserPrincipals() {
39
-		$principalV2 = $this->getCurrentUserPrincipal();
35
+    /**
36
+     * @inheritdoc
37
+     */
38
+    public function getCurrentUserPrincipals() {
39
+        $principalV2 = $this->getCurrentUserPrincipal();
40 40
 
41
-		if (is_null($principalV2)) return [];
41
+        if (is_null($principalV2)) return [];
42 42
 
43
-		$principalV1 = $this->convertPrincipal($principalV2, false);
44
-		return array_merge(
45
-			[
46
-				$principalV2,
47
-				$principalV1
48
-			],
49
-			$this->getPrincipalMembership($principalV1)
50
-		);
51
-	}
43
+        $principalV1 = $this->convertPrincipal($principalV2, false);
44
+        return array_merge(
45
+            [
46
+                $principalV2,
47
+                $principalV1
48
+            ],
49
+            $this->getPrincipalMembership($principalV1)
50
+        );
51
+    }
52 52
 
53
-	private function convertPrincipal($principal, $toV2) {
54
-		list(, $name) = \Sabre\Uri\split($principal);
55
-		if ($toV2) {
56
-			return "principals/users/$name";
57
-		}
58
-		return "principals/$name";
59
-	}
53
+    private function convertPrincipal($principal, $toV2) {
54
+        list(, $name) = \Sabre\Uri\split($principal);
55
+        if ($toV2) {
56
+            return "principals/users/$name";
57
+        }
58
+        return "principals/$name";
59
+    }
60 60
 
61
-	public function propFind(PropFind $propFind, INode $node) {
62
-		/* Overload current-user-principal */
63
-		$propFind->handle('{DAV:}current-user-principal', function () {
64
-			if ($url = parent::getCurrentUserPrincipal()) {
65
-				return new Principal(Principal::HREF, $url . '/');
66
-			} else {
67
-				return new Principal(Principal::UNAUTHENTICATED);
68
-			}
69
-		});
61
+    public function propFind(PropFind $propFind, INode $node) {
62
+        /* Overload current-user-principal */
63
+        $propFind->handle('{DAV:}current-user-principal', function () {
64
+            if ($url = parent::getCurrentUserPrincipal()) {
65
+                return new Principal(Principal::HREF, $url . '/');
66
+            } else {
67
+                return new Principal(Principal::UNAUTHENTICATED);
68
+            }
69
+        });
70 70
 
71
-		return parent::propFind($propFind, $node);
72
-	}
71
+        return parent::propFind($propFind, $node);
72
+    }
73 73
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/FixBirthdayCalendarComponent.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -28,35 +28,35 @@
 block discarded – undo
28 28
 
29 29
 class FixBirthdayCalendarComponent implements IRepairStep {
30 30
 
31
-	/** @var IDBConnection */
32
-	private $connection;
33
-
34
-	/**
35
-	 * FixBirthdayCalendarComponent constructor.
36
-	 *
37
-	 * @param IDBConnection $connection
38
-	 */
39
-	public function __construct(IDBConnection $connection) {
40
-		$this->connection = $connection;
41
-	}
42
-
43
-	/**
44
-	 * @inheritdoc
45
-	 */
46
-	public function getName() {
47
-		return 'Fix component of birthday calendars';
48
-	}
49
-
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	public function run(IOutput $output) {
54
-		$query = $this->connection->getQueryBuilder();
55
-		$updated = $query->update('calendars')
56
-			->set('components', $query->createNamedParameter('VEVENT'))
57
-			->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)))
58
-			->execute();
59
-
60
-		$output->info("$updated birthday calendars updated.");
61
-	}
31
+    /** @var IDBConnection */
32
+    private $connection;
33
+
34
+    /**
35
+     * FixBirthdayCalendarComponent constructor.
36
+     *
37
+     * @param IDBConnection $connection
38
+     */
39
+    public function __construct(IDBConnection $connection) {
40
+        $this->connection = $connection;
41
+    }
42
+
43
+    /**
44
+     * @inheritdoc
45
+     */
46
+    public function getName() {
47
+        return 'Fix component of birthday calendars';
48
+    }
49
+
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    public function run(IOutput $output) {
54
+        $query = $this->connection->getQueryBuilder();
55
+        $updated = $query->update('calendars')
56
+            ->set('components', $query->createNamedParameter('VEVENT'))
57
+            ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)))
58
+            ->execute();
59
+
60
+        $output->info("$updated birthday calendars updated.");
61
+    }
62 62
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/SyncSystemAddressBook.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -31,36 +31,36 @@
 block discarded – undo
31 31
 
32 32
 class SyncSystemAddressBook extends Command {
33 33
 
34
-	/** @var SyncService */
35
-	private $syncService;
34
+    /** @var SyncService */
35
+    private $syncService;
36 36
 
37
-	/**
38
-	 * @param SyncService $syncService
39
-	 */
40
-	function __construct(SyncService $syncService) {
41
-		parent::__construct();
42
-		$this->syncService = $syncService;
43
-	}
37
+    /**
38
+     * @param SyncService $syncService
39
+     */
40
+    function __construct(SyncService $syncService) {
41
+        parent::__construct();
42
+        $this->syncService = $syncService;
43
+    }
44 44
 
45
-	protected function configure() {
46
-		$this
47
-			->setName('dav:sync-system-addressbook')
48
-			->setDescription('Synchronizes users to the system addressbook');
49
-	}
45
+    protected function configure() {
46
+        $this
47
+            ->setName('dav:sync-system-addressbook')
48
+            ->setDescription('Synchronizes users to the system addressbook');
49
+    }
50 50
 
51
-	/**
52
-	 * @param InputInterface $input
53
-	 * @param OutputInterface $output
54
-	 */
55
-	protected function execute(InputInterface $input, OutputInterface $output) {
56
-		$output->writeln('Syncing users ...');
57
-		$progress = new ProgressBar($output);
58
-		$progress->start();
59
-		$this->syncService->syncInstance(function() use ($progress) {
60
-			$progress->advance();
61
-		});
51
+    /**
52
+     * @param InputInterface $input
53
+     * @param OutputInterface $output
54
+     */
55
+    protected function execute(InputInterface $input, OutputInterface $output) {
56
+        $output->writeln('Syncing users ...');
57
+        $progress = new ProgressBar($output);
58
+        $progress->start();
59
+        $this->syncService->syncInstance(function() use ($progress) {
60
+            $progress->advance();
61
+        });
62 62
 
63
-		$progress->finish();
64
-		$output->writeln('');
65
-	}
63
+        $progress->finish();
64
+        $output->writeln('');
65
+    }
66 66
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/CreateAddressBook.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -36,43 +36,43 @@
 block discarded – undo
36 36
 
37 37
 class CreateAddressBook extends Command {
38 38
 
39
-	/** @var IUserManager */
40
-	private $userManager;
39
+    /** @var IUserManager */
40
+    private $userManager;
41 41
 
42
-	/** @var CardDavBackend */
43
-	private $cardDavBackend;
42
+    /** @var CardDavBackend */
43
+    private $cardDavBackend;
44 44
 
45
-	/**
46
-	 * @param IUserManager $userManager
47
-	 * @param CardDavBackend $cardDavBackend
48
-	 */
49
-	function __construct(IUserManager $userManager,
50
-						 CardDavBackend $cardDavBackend
51
-	) {
52
-		parent::__construct();
53
-		$this->userManager = $userManager;
54
-		$this->cardDavBackend = $cardDavBackend;
55
-	}
45
+    /**
46
+     * @param IUserManager $userManager
47
+     * @param CardDavBackend $cardDavBackend
48
+     */
49
+    function __construct(IUserManager $userManager,
50
+                            CardDavBackend $cardDavBackend
51
+    ) {
52
+        parent::__construct();
53
+        $this->userManager = $userManager;
54
+        $this->cardDavBackend = $cardDavBackend;
55
+    }
56 56
 
57
-	protected function configure() {
58
-		$this
59
-				->setName('dav:create-addressbook')
60
-				->setDescription('Create a dav addressbook')
61
-				->addArgument('user',
62
-						InputArgument::REQUIRED,
63
-						'User for whom the addressbook will be created')
64
-				->addArgument('name',
65
-						InputArgument::REQUIRED,
66
-						'Name of the addressbook');
67
-	}
57
+    protected function configure() {
58
+        $this
59
+                ->setName('dav:create-addressbook')
60
+                ->setDescription('Create a dav addressbook')
61
+                ->addArgument('user',
62
+                        InputArgument::REQUIRED,
63
+                        'User for whom the addressbook will be created')
64
+                ->addArgument('name',
65
+                        InputArgument::REQUIRED,
66
+                        'Name of the addressbook');
67
+    }
68 68
 
69
-	protected function execute(InputInterface $input, OutputInterface $output) {
70
-		$user = $input->getArgument('user');
71
-		if (!$this->userManager->userExists($user)) {
72
-			throw new \InvalidArgumentException("User <$user> in unknown.");
73
-		}
69
+    protected function execute(InputInterface $input, OutputInterface $output) {
70
+        $user = $input->getArgument('user');
71
+        if (!$this->userManager->userExists($user)) {
72
+            throw new \InvalidArgumentException("User <$user> in unknown.");
73
+        }
74 74
 
75
-		$name = $input->getArgument('name');
76
-		$this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
77
-	}
75
+        $name = $input->getArgument('name');
76
+        $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
77
+    }
78 78
 }
Please login to merge, or discard this patch.
apps/dav/lib/Capabilities.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,11 +26,11 @@
 block discarded – undo
26 26
 
27 27
 class Capabilities implements ICapability {
28 28
 
29
-	public function getCapabilities() {
30
-		return [
31
-			'dav' => [
32
-				'chunking' => '1.0',
33
-			]
34
-		];
35
-	}
29
+    public function getCapabilities() {
30
+        return [
31
+            'dav' => [
32
+                'chunking' => '1.0',
33
+            ]
34
+        ];
35
+    }
36 36
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/Sharing/FilesDropPlugin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$this->enabled = false;
65 65
 	}
66 66
 
67
-	public function beforeMethod(RequestInterface $request, ResponseInterface $response){
67
+	public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
68 68
 
69 69
 		if (!$this->enabled) {
70 70
 			return;
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		$path = array_pop($path);
79 79
 
80 80
 		$newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
81
-		$url = $request->getBaseUrl() . $newName;
81
+		$url = $request->getBaseUrl().$newName;
82 82
 		$request->setUrl($url);
83 83
 	}
84 84
 }
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -34,52 +34,52 @@
 block discarded – undo
34 34
  */
35 35
 class FilesDropPlugin extends ServerPlugin {
36 36
 
37
-	/** @var View */
38
-	private $view;
37
+    /** @var View */
38
+    private $view;
39 39
 
40
-	/** @var bool */
41
-	private $enabled = false;
40
+    /** @var bool */
41
+    private $enabled = false;
42 42
 
43
-	/**
44
-	 * @param View $view
45
-	 */
46
-	public function setView($view) {
47
-		$this->view = $view;
48
-	}
43
+    /**
44
+     * @param View $view
45
+     */
46
+    public function setView($view) {
47
+        $this->view = $view;
48
+    }
49 49
 
50
-	public function enable() {
51
-		$this->enabled = true;
52
-	}
50
+    public function enable() {
51
+        $this->enabled = true;
52
+    }
53 53
 
54 54
 
55
-	/**
56
-	 * This initializes the plugin.
57
-	 *
58
-	 * @param \Sabre\DAV\Server $server Sabre server
59
-	 *
60
-	 * @return void
61
-	 * @throws MethodNotAllowed
62
-	 */
63
-	public function initialize(\Sabre\DAV\Server $server) {
64
-		$server->on('beforeMethod:*', [$this, 'beforeMethod'], 999);
65
-		$this->enabled = false;
66
-	}
55
+    /**
56
+     * This initializes the plugin.
57
+     *
58
+     * @param \Sabre\DAV\Server $server Sabre server
59
+     *
60
+     * @return void
61
+     * @throws MethodNotAllowed
62
+     */
63
+    public function initialize(\Sabre\DAV\Server $server) {
64
+        $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999);
65
+        $this->enabled = false;
66
+    }
67 67
 
68
-	public function beforeMethod(RequestInterface $request, ResponseInterface $response){
68
+    public function beforeMethod(RequestInterface $request, ResponseInterface $response){
69 69
 
70
-		if (!$this->enabled) {
71
-			return;
72
-		}
70
+        if (!$this->enabled) {
71
+            return;
72
+        }
73 73
 
74
-		if ($request->getMethod() !== 'PUT') {
75
-			throw new MethodNotAllowed('Only PUT is allowed on files drop');
76
-		}
74
+        if ($request->getMethod() !== 'PUT') {
75
+            throw new MethodNotAllowed('Only PUT is allowed on files drop');
76
+        }
77 77
 
78
-		$path = explode('/', $request->getPath());
79
-		$path = array_pop($path);
78
+        $path = explode('/', $request->getPath());
79
+        $path = array_pop($path);
80 80
 
81
-		$newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
82
-		$url = $request->getBaseUrl() . $newName;
83
-		$request->setUrl($url);
84
-	}
81
+        $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
82
+        $url = $request->getBaseUrl() . $newName;
83
+        $request->setUrl($url);
84
+    }
85 85
 }
Please login to merge, or discard this patch.
apps/dav/lib/Upload/UploadFolder.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
 	}
41 41
 
42 42
 	function createDirectory($name) {
43
-		throw new Forbidden('Permission denied to create file (filename ' . $name . ')');
43
+		throw new Forbidden('Permission denied to create file (filename '.$name.')');
44 44
 	}
45 45
 
46 46
 	function getChild($name) {
Please login to merge, or discard this patch.
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -30,61 +30,61 @@
 block discarded – undo
30 30
 
31 31
 class UploadFolder implements ICollection {
32 32
 
33
-	/** @var Directory */
34
-	private $node;
35
-	/** @var CleanupService */
36
-	private $cleanupService;
33
+    /** @var Directory */
34
+    private $node;
35
+    /** @var CleanupService */
36
+    private $cleanupService;
37 37
 
38
-	function __construct(Directory $node, CleanupService $cleanupService) {
39
-		$this->node = $node;
40
-		$this->cleanupService = $cleanupService;
41
-	}
38
+    function __construct(Directory $node, CleanupService $cleanupService) {
39
+        $this->node = $node;
40
+        $this->cleanupService = $cleanupService;
41
+    }
42 42
 
43
-	function createFile($name, $data = null) {
44
-		// TODO: verify name - should be a simple number
45
-		$this->node->createFile($name, $data);
46
-	}
43
+    function createFile($name, $data = null) {
44
+        // TODO: verify name - should be a simple number
45
+        $this->node->createFile($name, $data);
46
+    }
47 47
 
48
-	function createDirectory($name) {
49
-		throw new Forbidden('Permission denied to create file (filename ' . $name . ')');
50
-	}
48
+    function createDirectory($name) {
49
+        throw new Forbidden('Permission denied to create file (filename ' . $name . ')');
50
+    }
51 51
 
52
-	function getChild($name) {
53
-		if ($name === '.file') {
54
-			return new FutureFile($this->node, '.file');
55
-		}
56
-		return $this->node->getChild($name);
57
-	}
52
+    function getChild($name) {
53
+        if ($name === '.file') {
54
+            return new FutureFile($this->node, '.file');
55
+        }
56
+        return $this->node->getChild($name);
57
+    }
58 58
 
59
-	function getChildren() {
60
-		$children = $this->node->getChildren();
61
-		$children[] = new FutureFile($this->node, '.file');
62
-		return $children;
63
-	}
59
+    function getChildren() {
60
+        $children = $this->node->getChildren();
61
+        $children[] = new FutureFile($this->node, '.file');
62
+        return $children;
63
+    }
64 64
 
65
-	function childExists($name) {
66
-		if ($name === '.file') {
67
-			return true;
68
-		}
69
-		return $this->node->childExists($name);
70
-	}
65
+    function childExists($name) {
66
+        if ($name === '.file') {
67
+            return true;
68
+        }
69
+        return $this->node->childExists($name);
70
+    }
71 71
 
72
-	function delete() {
73
-		$this->node->delete();
72
+    function delete() {
73
+        $this->node->delete();
74 74
 
75
-		// Background cleanup job is not needed anymore
76
-		$this->cleanupService->removeJob($this->getName());
77
-	}
75
+        // Background cleanup job is not needed anymore
76
+        $this->cleanupService->removeJob($this->getName());
77
+    }
78 78
 
79
-	function getName() {
80
-		return $this->node->getName();
81
-	}
79
+    function getName() {
80
+        return $this->node->getName();
81
+    }
82 82
 
83
-	function setName($name) {
84
-		throw new Forbidden('Permission denied to rename this folder');
85
-	}
83
+    function setName($name) {
84
+        throw new Forbidden('Permission denied to rename this folder');
85
+    }
86 86
 
87
-	function getLastModified() {
88
-		return $this->node->getLastModified();
89
-	}
87
+    function getLastModified() {
88
+        return $this->node->getLastModified();
89
+    }
90 90
 }
Please login to merge, or discard this patch.