Passed
Push — master ( 2ec5d2...37782b )
by Morris
66:43 queued 51:42
created
apps/files/appinfo/routes.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -31,78 +31,78 @@
 block discarded – undo
31 31
 
32 32
 $application = new Application();
33 33
 $application->registerRoutes(
34
-	$this,
35
-	[
36
-		'routes' => [
37
-			[
38
-				'name' => 'API#getThumbnail',
39
-				'url' => '/api/v1/thumbnail/{x}/{y}/{file}',
40
-				'verb' => 'GET',
41
-				'requirements' => ['file' => '.+']
42
-			],
43
-			[
44
-				'name' => 'API#updateFileTags',
45
-				'url' => '/api/v1/files/{path}',
46
-				'verb' => 'POST',
47
-				'requirements' => ['path' => '.+'],
48
-			],
49
-			[
50
-				'name' => 'API#getRecentFiles',
51
-				'url' => '/api/v1/recent/',
52
-				'verb' => 'GET'
53
-			],
54
-			[
55
-				'name' => 'API#updateFileSorting',
56
-				'url' => '/api/v1/sorting',
57
-				'verb' => 'POST'
58
-			],
59
-			[
60
-				'name' => 'API#showHiddenFiles',
61
-				'url' => '/api/v1/showhidden',
62
-				'verb' => 'POST'
63
-			],
64
-			[
65
-				'name' => 'API#showGridView',
66
-				'url' => '/api/v1/showgridview',
67
-				'verb' => 'POST'
68
-			],
69
-			[
70
-				'name' => 'API#getGridView',
71
-				'url' => '/api/v1/showgridview',
72
-				'verb' => 'GET'
73
-			],
74
-			[
75
-				'name' => 'view#index',
76
-				'url' => '/',
77
-				'verb' => 'GET',
78
-			],
79
-			[
80
-				'name' => 'settings#setMaxUploadSize',
81
-				'url' => '/settings/maxUpload',
82
-				'verb' => 'POST',
83
-			],
84
-			[
85
-				'name' => 'ajax#getStorageStats',
86
-				'url' => '/ajax/getstoragestats.php',
87
-				'verb' => 'GET',
88
-			],
89
-			[
90
-				'name' => 'API#toggleShowFolder',
91
-				'url' => '/api/v1/toggleShowFolder/{key}',
92
-				'verb' => 'POST'
93
-			],
94
-			[
95
-				'name' => 'API#getNodeType',
96
-				'url' => '/api/v1/quickaccess/get/NodeType',
97
-				'verb' => 'GET',
98
-			],
99
-		]
100
-	]
34
+    $this,
35
+    [
36
+        'routes' => [
37
+            [
38
+                'name' => 'API#getThumbnail',
39
+                'url' => '/api/v1/thumbnail/{x}/{y}/{file}',
40
+                'verb' => 'GET',
41
+                'requirements' => ['file' => '.+']
42
+            ],
43
+            [
44
+                'name' => 'API#updateFileTags',
45
+                'url' => '/api/v1/files/{path}',
46
+                'verb' => 'POST',
47
+                'requirements' => ['path' => '.+'],
48
+            ],
49
+            [
50
+                'name' => 'API#getRecentFiles',
51
+                'url' => '/api/v1/recent/',
52
+                'verb' => 'GET'
53
+            ],
54
+            [
55
+                'name' => 'API#updateFileSorting',
56
+                'url' => '/api/v1/sorting',
57
+                'verb' => 'POST'
58
+            ],
59
+            [
60
+                'name' => 'API#showHiddenFiles',
61
+                'url' => '/api/v1/showhidden',
62
+                'verb' => 'POST'
63
+            ],
64
+            [
65
+                'name' => 'API#showGridView',
66
+                'url' => '/api/v1/showgridview',
67
+                'verb' => 'POST'
68
+            ],
69
+            [
70
+                'name' => 'API#getGridView',
71
+                'url' => '/api/v1/showgridview',
72
+                'verb' => 'GET'
73
+            ],
74
+            [
75
+                'name' => 'view#index',
76
+                'url' => '/',
77
+                'verb' => 'GET',
78
+            ],
79
+            [
80
+                'name' => 'settings#setMaxUploadSize',
81
+                'url' => '/settings/maxUpload',
82
+                'verb' => 'POST',
83
+            ],
84
+            [
85
+                'name' => 'ajax#getStorageStats',
86
+                'url' => '/ajax/getstoragestats.php',
87
+                'verb' => 'GET',
88
+            ],
89
+            [
90
+                'name' => 'API#toggleShowFolder',
91
+                'url' => '/api/v1/toggleShowFolder/{key}',
92
+                'verb' => 'POST'
93
+            ],
94
+            [
95
+                'name' => 'API#getNodeType',
96
+                'url' => '/api/v1/quickaccess/get/NodeType',
97
+                'verb' => 'GET',
98
+            ],
99
+        ]
100
+    ]
101 101
 );
102 102
 
103 103
 /** @var $this \OC\Route\Router */
104 104
 
105 105
 $this->create('files_ajax_download', 'ajax/download.php')
106
-	->actionInclude('files/ajax/download.php');
106
+    ->actionInclude('files/ajax/download.php');
107 107
 $this->create('files_ajax_list', 'ajax/list.php')
108
-	->actionInclude('files/ajax/list.php');
108
+    ->actionInclude('files/ajax/list.php');
Please login to merge, or discard this patch.
apps/files/lib/Controller/ApiController.php 1 patch
Indentation   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -54,278 +54,278 @@
 block discarded – undo
54 54
  * @package OCA\Files\Controller
55 55
  */
56 56
 class ApiController extends Controller {
57
-	/** @var TagService */
58
-	private $tagService;
59
-	/** @var IManager * */
60
-	private $shareManager;
61
-	/** @var IPreview */
62
-	private $previewManager;
63
-	/** IUserSession */
64
-	private $userSession;
65
-	/** IConfig */
66
-	private $config;
67
-	/** @var Folder */
68
-	private $userFolder;
57
+    /** @var TagService */
58
+    private $tagService;
59
+    /** @var IManager * */
60
+    private $shareManager;
61
+    /** @var IPreview */
62
+    private $previewManager;
63
+    /** IUserSession */
64
+    private $userSession;
65
+    /** IConfig */
66
+    private $config;
67
+    /** @var Folder */
68
+    private $userFolder;
69 69
 
70
-	/**
71
-	 * @param string $appName
72
-	 * @param IRequest $request
73
-	 * @param IUserSession $userSession
74
-	 * @param TagService $tagService
75
-	 * @param IPreview $previewManager
76
-	 * @param IManager $shareManager
77
-	 * @param IConfig $config
78
-	 * @param Folder $userFolder
79
-	 */
80
-	public function __construct($appName,
81
-								IRequest $request,
82
-								IUserSession $userSession,
83
-								TagService $tagService,
84
-								IPreview $previewManager,
85
-								IManager $shareManager,
86
-								IConfig $config,
87
-								Folder $userFolder) {
88
-		parent::__construct($appName, $request);
89
-		$this->userSession = $userSession;
90
-		$this->tagService = $tagService;
91
-		$this->previewManager = $previewManager;
92
-		$this->shareManager = $shareManager;
93
-		$this->config = $config;
94
-		$this->userFolder = $userFolder;
95
-	}
70
+    /**
71
+     * @param string $appName
72
+     * @param IRequest $request
73
+     * @param IUserSession $userSession
74
+     * @param TagService $tagService
75
+     * @param IPreview $previewManager
76
+     * @param IManager $shareManager
77
+     * @param IConfig $config
78
+     * @param Folder $userFolder
79
+     */
80
+    public function __construct($appName,
81
+                                IRequest $request,
82
+                                IUserSession $userSession,
83
+                                TagService $tagService,
84
+                                IPreview $previewManager,
85
+                                IManager $shareManager,
86
+                                IConfig $config,
87
+                                Folder $userFolder) {
88
+        parent::__construct($appName, $request);
89
+        $this->userSession = $userSession;
90
+        $this->tagService = $tagService;
91
+        $this->previewManager = $previewManager;
92
+        $this->shareManager = $shareManager;
93
+        $this->config = $config;
94
+        $this->userFolder = $userFolder;
95
+    }
96 96
 
97
-	/**
98
-	 * Gets a thumbnail of the specified file
99
-	 *
100
-	 * @since API version 1.0
101
-	 *
102
-	 * @NoAdminRequired
103
-	 * @NoCSRFRequired
104
-	 * @StrictCookieRequired
105
-	 *
106
-	 * @param int $x
107
-	 * @param int $y
108
-	 * @param string $file URL-encoded filename
109
-	 * @return DataResponse|FileDisplayResponse
110
-	 */
111
-	public function getThumbnail($x, $y, $file) {
112
-		if ($x < 1 || $y < 1) {
113
-			return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
114
-		}
97
+    /**
98
+     * Gets a thumbnail of the specified file
99
+     *
100
+     * @since API version 1.0
101
+     *
102
+     * @NoAdminRequired
103
+     * @NoCSRFRequired
104
+     * @StrictCookieRequired
105
+     *
106
+     * @param int $x
107
+     * @param int $y
108
+     * @param string $file URL-encoded filename
109
+     * @return DataResponse|FileDisplayResponse
110
+     */
111
+    public function getThumbnail($x, $y, $file) {
112
+        if ($x < 1 || $y < 1) {
113
+            return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
114
+        }
115 115
 
116
-		try {
117
-			$file = $this->userFolder->get($file);
118
-			if ($file instanceof Folder) {
119
-				throw new NotFoundException();
120
-			}
116
+        try {
117
+            $file = $this->userFolder->get($file);
118
+            if ($file instanceof Folder) {
119
+                throw new NotFoundException();
120
+            }
121 121
 
122
-			/** @var File $file */
123
-			$preview = $this->previewManager->getPreview($file, $x, $y, true);
122
+            /** @var File $file */
123
+            $preview = $this->previewManager->getPreview($file, $x, $y, true);
124 124
 
125
-			return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
126
-		} catch (NotFoundException $e) {
127
-			return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
128
-		} catch (\Exception $e) {
129
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
130
-		}
131
-	}
125
+            return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
126
+        } catch (NotFoundException $e) {
127
+            return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
128
+        } catch (\Exception $e) {
129
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
130
+        }
131
+    }
132 132
 
133
-	/**
134
-	 * Updates the info of the specified file path
135
-	 * The passed tags are absolute, which means they will
136
-	 * replace the actual tag selection.
137
-	 *
138
-	 * @NoAdminRequired
139
-	 *
140
-	 * @param string $path path
141
-	 * @param array|string $tags array of tags
142
-	 * @return DataResponse
143
-	 */
144
-	public function updateFileTags($path, $tags = null) {
145
-		$result = [];
146
-		// if tags specified or empty array, update tags
147
-		if (!is_null($tags)) {
148
-			try {
149
-				$this->tagService->updateFileTags($path, $tags);
150
-			} catch (\OCP\Files\NotFoundException $e) {
151
-				return new DataResponse([
152
-					'message' => $e->getMessage()
153
-				], Http::STATUS_NOT_FOUND);
154
-			} catch (\OCP\Files\StorageNotAvailableException $e) {
155
-				return new DataResponse([
156
-					'message' => $e->getMessage()
157
-				], Http::STATUS_SERVICE_UNAVAILABLE);
158
-			} catch (\Exception $e) {
159
-				return new DataResponse([
160
-					'message' => $e->getMessage()
161
-				], Http::STATUS_NOT_FOUND);
162
-			}
163
-			$result['tags'] = $tags;
164
-		}
165
-		return new DataResponse($result);
166
-	}
133
+    /**
134
+     * Updates the info of the specified file path
135
+     * The passed tags are absolute, which means they will
136
+     * replace the actual tag selection.
137
+     *
138
+     * @NoAdminRequired
139
+     *
140
+     * @param string $path path
141
+     * @param array|string $tags array of tags
142
+     * @return DataResponse
143
+     */
144
+    public function updateFileTags($path, $tags = null) {
145
+        $result = [];
146
+        // if tags specified or empty array, update tags
147
+        if (!is_null($tags)) {
148
+            try {
149
+                $this->tagService->updateFileTags($path, $tags);
150
+            } catch (\OCP\Files\NotFoundException $e) {
151
+                return new DataResponse([
152
+                    'message' => $e->getMessage()
153
+                ], Http::STATUS_NOT_FOUND);
154
+            } catch (\OCP\Files\StorageNotAvailableException $e) {
155
+                return new DataResponse([
156
+                    'message' => $e->getMessage()
157
+                ], Http::STATUS_SERVICE_UNAVAILABLE);
158
+            } catch (\Exception $e) {
159
+                return new DataResponse([
160
+                    'message' => $e->getMessage()
161
+                ], Http::STATUS_NOT_FOUND);
162
+            }
163
+            $result['tags'] = $tags;
164
+        }
165
+        return new DataResponse($result);
166
+    }
167 167
 
168
-	/**
169
-	 * @param \OCP\Files\Node[] $nodes
170
-	 * @return array
171
-	 */
172
-	private function formatNodes(array $nodes) {
173
-		return array_values(array_map(function (Node $node) {
174
-			/** @var \OC\Files\Node\Node $shareTypes */
175
-			$shareTypes = $this->getShareTypes($node);
176
-			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
177
-			$parts = explode('/', dirname($node->getPath()), 4);
178
-			if (isset($parts[3])) {
179
-				$file['path'] = '/' . $parts[3];
180
-			} else {
181
-				$file['path'] = '/';
182
-			}
183
-			if (!empty($shareTypes)) {
184
-				$file['shareTypes'] = $shareTypes;
185
-			}
186
-			return $file;
187
-		}, $nodes));
188
-	}
168
+    /**
169
+     * @param \OCP\Files\Node[] $nodes
170
+     * @return array
171
+     */
172
+    private function formatNodes(array $nodes) {
173
+        return array_values(array_map(function (Node $node) {
174
+            /** @var \OC\Files\Node\Node $shareTypes */
175
+            $shareTypes = $this->getShareTypes($node);
176
+            $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
177
+            $parts = explode('/', dirname($node->getPath()), 4);
178
+            if (isset($parts[3])) {
179
+                $file['path'] = '/' . $parts[3];
180
+            } else {
181
+                $file['path'] = '/';
182
+            }
183
+            if (!empty($shareTypes)) {
184
+                $file['shareTypes'] = $shareTypes;
185
+            }
186
+            return $file;
187
+        }, $nodes));
188
+    }
189 189
 
190
-	/**
191
-	 * Returns a list of recently modifed files.
192
-	 *
193
-	 * @NoAdminRequired
194
-	 *
195
-	 * @return DataResponse
196
-	 */
197
-	public function getRecentFiles() {
198
-		$nodes = $this->userFolder->getRecent(100);
199
-		$files = $this->formatNodes($nodes);
200
-		return new DataResponse(['files' => $files]);
201
-	}
190
+    /**
191
+     * Returns a list of recently modifed files.
192
+     *
193
+     * @NoAdminRequired
194
+     *
195
+     * @return DataResponse
196
+     */
197
+    public function getRecentFiles() {
198
+        $nodes = $this->userFolder->getRecent(100);
199
+        $files = $this->formatNodes($nodes);
200
+        return new DataResponse(['files' => $files]);
201
+    }
202 202
 
203
-	/**
204
-	 * Return a list of share types for outgoing shares
205
-	 *
206
-	 * @param Node $node file node
207
-	 *
208
-	 * @return int[] array of share types
209
-	 */
210
-	private function getShareTypes(Node $node) {
211
-		$userId = $this->userSession->getUser()->getUID();
212
-		$shareTypes = [];
213
-		$requestedShareTypes = [
214
-			\OCP\Share::SHARE_TYPE_USER,
215
-			\OCP\Share::SHARE_TYPE_GROUP,
216
-			\OCP\Share::SHARE_TYPE_LINK,
217
-			\OCP\Share::SHARE_TYPE_REMOTE,
218
-			\OCP\Share::SHARE_TYPE_EMAIL,
219
-			\OCP\Share::SHARE_TYPE_ROOM
220
-		];
221
-		foreach ($requestedShareTypes as $requestedShareType) {
222
-			// one of each type is enough to find out about the types
223
-			$shares = $this->shareManager->getSharesBy(
224
-				$userId,
225
-				$requestedShareType,
226
-				$node,
227
-				false,
228
-				1
229
-			);
230
-			if (!empty($shares)) {
231
-				$shareTypes[] = $requestedShareType;
232
-			}
233
-		}
234
-		return $shareTypes;
235
-	}
203
+    /**
204
+     * Return a list of share types for outgoing shares
205
+     *
206
+     * @param Node $node file node
207
+     *
208
+     * @return int[] array of share types
209
+     */
210
+    private function getShareTypes(Node $node) {
211
+        $userId = $this->userSession->getUser()->getUID();
212
+        $shareTypes = [];
213
+        $requestedShareTypes = [
214
+            \OCP\Share::SHARE_TYPE_USER,
215
+            \OCP\Share::SHARE_TYPE_GROUP,
216
+            \OCP\Share::SHARE_TYPE_LINK,
217
+            \OCP\Share::SHARE_TYPE_REMOTE,
218
+            \OCP\Share::SHARE_TYPE_EMAIL,
219
+            \OCP\Share::SHARE_TYPE_ROOM
220
+        ];
221
+        foreach ($requestedShareTypes as $requestedShareType) {
222
+            // one of each type is enough to find out about the types
223
+            $shares = $this->shareManager->getSharesBy(
224
+                $userId,
225
+                $requestedShareType,
226
+                $node,
227
+                false,
228
+                1
229
+            );
230
+            if (!empty($shares)) {
231
+                $shareTypes[] = $requestedShareType;
232
+            }
233
+        }
234
+        return $shareTypes;
235
+    }
236 236
 
237
-	/**
238
-	 * Change the default sort mode
239
-	 *
240
-	 * @NoAdminRequired
241
-	 *
242
-	 * @param string $mode
243
-	 * @param string $direction
244
-	 * @return Response
245
-	 */
246
-	public function updateFileSorting($mode, $direction) {
247
-		$allowedMode = ['name', 'size', 'mtime'];
248
-		$allowedDirection = ['asc', 'desc'];
249
-		if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
250
-			$response = new Response();
251
-			$response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
252
-			return $response;
253
-		}
254
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
255
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
256
-		return new Response();
257
-	}
237
+    /**
238
+     * Change the default sort mode
239
+     *
240
+     * @NoAdminRequired
241
+     *
242
+     * @param string $mode
243
+     * @param string $direction
244
+     * @return Response
245
+     */
246
+    public function updateFileSorting($mode, $direction) {
247
+        $allowedMode = ['name', 'size', 'mtime'];
248
+        $allowedDirection = ['asc', 'desc'];
249
+        if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
250
+            $response = new Response();
251
+            $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
252
+            return $response;
253
+        }
254
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
255
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
256
+        return new Response();
257
+    }
258 258
 
259
-	/**
260
-	 * Toggle default for showing/hiding hidden files
261
-	 *
262
-	 * @NoAdminRequired
263
-	 *
264
-	 * @param bool $show
265
-	 */
266
-	public function showHiddenFiles($show) {
267
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
268
-		return new Response();
269
-	}
259
+    /**
260
+     * Toggle default for showing/hiding hidden files
261
+     *
262
+     * @NoAdminRequired
263
+     *
264
+     * @param bool $show
265
+     */
266
+    public function showHiddenFiles($show) {
267
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
268
+        return new Response();
269
+    }
270 270
 
271
-	/**
272
-	 * Toggle default for files grid view
273
-	 *
274
-	 * @NoAdminRequired
275
-	 *
276
-	 * @param bool $show
277
-	 */
278
-	public function showGridView($show) {
279
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
280
-		return new Response();
281
-	}
271
+    /**
272
+     * Toggle default for files grid view
273
+     *
274
+     * @NoAdminRequired
275
+     *
276
+     * @param bool $show
277
+     */
278
+    public function showGridView($show) {
279
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
280
+        return new Response();
281
+    }
282 282
 
283
-	/**
284
-	 * Get default settings for the grid view
285
-	 *
286
-	 * @NoAdminRequired
287
-	 */
288
-	public function getGridView() {
289
-		$status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '1') === '1';
290
-		return new JSONResponse(['gridview' => $status]);
291
-	}
283
+    /**
284
+     * Get default settings for the grid view
285
+     *
286
+     * @NoAdminRequired
287
+     */
288
+    public function getGridView() {
289
+        $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '1') === '1';
290
+        return new JSONResponse(['gridview' => $status]);
291
+    }
292 292
 
293
-	/**
294
-	 * Toggle default for showing/hiding xxx folder
295
-	 *
296
-	 * @NoAdminRequired
297
-	 *
298
-	 * @param bool $show 
299
-	 * @param bool $key the key of the folder
300
-	 *
301
-	 * @return Response
302
-	 */
303
-	public function toggleShowFolder(int $show, string $key) {
304
-		// ensure the edited key exists
305
-		$navItems = \OCA\Files\App::getNavigationManager()->getAll();
306
-		foreach ($navItems as $item) {
307
-			// check if data is valid
308
-			if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
309
-				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
310
-				return new Response();
311
-			}
312
-		}
313
-		$response = new Response();
314
-		$response->setStatus(Http::STATUS_FORBIDDEN);
315
-		return $response;
316
-	}
293
+    /**
294
+     * Toggle default for showing/hiding xxx folder
295
+     *
296
+     * @NoAdminRequired
297
+     *
298
+     * @param bool $show 
299
+     * @param bool $key the key of the folder
300
+     *
301
+     * @return Response
302
+     */
303
+    public function toggleShowFolder(int $show, string $key) {
304
+        // ensure the edited key exists
305
+        $navItems = \OCA\Files\App::getNavigationManager()->getAll();
306
+        foreach ($navItems as $item) {
307
+            // check if data is valid
308
+            if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
309
+                $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
310
+                return new Response();
311
+            }
312
+        }
313
+        $response = new Response();
314
+        $response->setStatus(Http::STATUS_FORBIDDEN);
315
+        return $response;
316
+    }
317 317
 
318
-	/**
319
-	 * Get sorting-order for custom sorting
320
-	 *
321
-	 * @NoAdminRequired
322
-	 *
323
-	 * @param String
324
-	 * @return String
325
-	 */
326
-	public function getNodeType($folderpath) {
327
-		$node = $this->userFolder->get($folderpath);
328
-		return $node->getType();
329
-	}
318
+    /**
319
+     * Get sorting-order for custom sorting
320
+     *
321
+     * @NoAdminRequired
322
+     *
323
+     * @param String
324
+     * @return String
325
+     */
326
+    public function getNodeType($folderpath) {
327
+        $node = $this->userFolder->get($folderpath);
328
+        return $node->getType();
329
+    }
330 330
 
331 331
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/ShareController.php 1 patch
Indentation   +578 added lines, -579 removed lines patch added patch discarded remove patch
@@ -73,587 +73,586 @@
 block discarded – undo
73 73
  */
74 74
 class ShareController extends AuthPublicShareController {
75 75
 
76
-	/** @var IConfig */
77
-	protected $config;
78
-	/** @var IUserManager */
79
-	protected $userManager;
80
-	/** @var ILogger */
81
-	protected $logger;
82
-	/** @var \OCP\Activity\IManager */
83
-	protected $activityManager;
84
-	/** @var IPreview */
85
-	protected $previewManager;
86
-	/** @var IRootFolder */
87
-	protected $rootFolder;
88
-	/** @var FederatedShareProvider */
89
-	protected $federatedShareProvider;
90
-	/** @var EventDispatcherInterface */
91
-	protected $eventDispatcher;
92
-	/** @var IL10N */
93
-	protected $l10n;
94
-	/** @var Defaults */
95
-	protected $defaults;
96
-	/** @var ShareManager */
97
-	protected $shareManager;
98
-
99
-	/** @var Share\IShare */
100
-	protected $share;
101
-
102
-	/**
103
-	 * @param string $appName
104
-	 * @param IRequest $request
105
-	 * @param IConfig $config
106
-	 * @param IURLGenerator $urlGenerator
107
-	 * @param IUserManager $userManager
108
-	 * @param ILogger $logger
109
-	 * @param \OCP\Activity\IManager $activityManager
110
-	 * @param \OCP\Share\IManager $shareManager
111
-	 * @param ISession $session
112
-	 * @param IPreview $previewManager
113
-	 * @param IRootFolder $rootFolder
114
-	 * @param FederatedShareProvider $federatedShareProvider
115
-	 * @param EventDispatcherInterface $eventDispatcher
116
-	 * @param IL10N $l10n
117
-	 * @param Defaults $defaults
118
-	 */
119
-	public function __construct(string $appName,
120
-								IRequest $request,
121
-								IConfig $config,
122
-								IURLGenerator $urlGenerator,
123
-								IUserManager $userManager,
124
-								ILogger $logger,
125
-								\OCP\Activity\IManager $activityManager,
126
-								ShareManager $shareManager,
127
-								ISession $session,
128
-								IPreview $previewManager,
129
-								IRootFolder $rootFolder,
130
-								FederatedShareProvider $federatedShareProvider,
131
-								EventDispatcherInterface $eventDispatcher,
132
-								IL10N $l10n,
133
-								Defaults $defaults) {
134
-		parent::__construct($appName, $request, $session, $urlGenerator);
135
-
136
-		$this->config = $config;
137
-		$this->userManager = $userManager;
138
-		$this->logger = $logger;
139
-		$this->activityManager = $activityManager;
140
-		$this->previewManager = $previewManager;
141
-		$this->rootFolder = $rootFolder;
142
-		$this->federatedShareProvider = $federatedShareProvider;
143
-		$this->eventDispatcher = $eventDispatcher;
144
-		$this->l10n = $l10n;
145
-		$this->defaults = $defaults;
146
-		$this->shareManager = $shareManager;
147
-	}
148
-
149
-	/**
150
-	 * @PublicPage
151
-	 * @NoCSRFRequired
152
-	 *
153
-	 * Show the authentication page
154
-	 * The form has to submit to the authenticate method route
155
-	 */
156
-	public function showAuthenticate(): TemplateResponse {
157
-		$templateParameters = ['share' => $this->share];
158
-
159
-		$event = new GenericEvent(null, $templateParameters);
160
-		$this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $event);
161
-
162
-		$response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
163
-		if ($this->share->getSendPasswordByTalk()) {
164
-			$csp = new ContentSecurityPolicy();
165
-			$csp->addAllowedConnectDomain('*');
166
-			$csp->addAllowedMediaDomain('blob:');
167
-			$csp->allowEvalScript(true);
168
-			$response->setContentSecurityPolicy($csp);
169
-		}
170
-
171
-		return $response;
172
-	}
173
-
174
-	/**
175
-	 * The template to show when authentication failed
176
-	 */
177
-	protected function showAuthFailed(): TemplateResponse {
178
-		$templateParameters = ['share' => $this->share, 'wrongpw' => true];
179
-
180
-		$event = new GenericEvent(null, $templateParameters);
181
-		$this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $event);
182
-
183
-		$response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
184
-		if ($this->share->getSendPasswordByTalk()) {
185
-			$csp = new ContentSecurityPolicy();
186
-			$csp->addAllowedConnectDomain('*');
187
-			$csp->addAllowedMediaDomain('blob:');
188
-			$csp->allowEvalScript(true);
189
-			$response->setContentSecurityPolicy($csp);
190
-		}
191
-
192
-		return $response;
193
-	}
194
-
195
-	protected function verifyPassword(string $password): bool {
196
-		return $this->shareManager->checkPassword($this->share, $password);
197
-	}
198
-
199
-	protected function getPasswordHash(): string {
200
-		return $this->share->getPassword();
201
-	}
202
-
203
-	public function isValidToken(): bool {
204
-		try {
205
-			$this->share = $this->shareManager->getShareByToken($this->getToken());
206
-		} catch (ShareNotFound $e) {
207
-			return false;
208
-		}
209
-
210
-		return true;
211
-	}
212
-
213
-	protected function isPasswordProtected(): bool {
214
-		return $this->share->getPassword() !== null;
215
-	}
216
-
217
-	protected function authSucceeded() {
218
-		// For share this was always set so it is still used in other apps
219
-		$this->session->set('public_link_authenticated', (string)$this->share->getId());
220
-	}
221
-
222
-	protected function authFailed() {
223
-		$this->emitAccessShareHook($this->share, 403, 'Wrong password');
224
-	}
225
-
226
-	/**
227
-	 * throws hooks when a share is attempted to be accessed
228
-	 *
229
-	 * @param \OCP\Share\IShare|string $share the Share instance if available,
230
-	 * otherwise token
231
-	 * @param int $errorCode
232
-	 * @param string $errorMessage
233
-	 * @throws \OC\HintException
234
-	 * @throws \OC\ServerNotAvailableException
235
-	 */
236
-	protected function emitAccessShareHook($share, $errorCode = 200, $errorMessage = '') {
237
-		$itemType = $itemSource = $uidOwner = '';
238
-		$token = $share;
239
-		$exception = null;
240
-		if($share instanceof \OCP\Share\IShare) {
241
-			try {
242
-				$token = $share->getToken();
243
-				$uidOwner = $share->getSharedBy();
244
-				$itemType = $share->getNodeType();
245
-				$itemSource = $share->getNodeId();
246
-			} catch (\Exception $e) {
247
-				// we log what we know and pass on the exception afterwards
248
-				$exception = $e;
249
-			}
250
-		}
251
-		\OC_Hook::emit(Share::class, 'share_link_access', [
252
-			'itemType' => $itemType,
253
-			'itemSource' => $itemSource,
254
-			'uidOwner' => $uidOwner,
255
-			'token' => $token,
256
-			'errorCode' => $errorCode,
257
-			'errorMessage' => $errorMessage,
258
-		]);
259
-		if(!is_null($exception)) {
260
-			throw $exception;
261
-		}
262
-	}
263
-
264
-	/**
265
-	 * Validate the permissions of the share
266
-	 *
267
-	 * @param Share\IShare $share
268
-	 * @return bool
269
-	 */
270
-	private function validateShare(\OCP\Share\IShare $share) {
271
-		return $share->getNode()->isReadable() && $share->getNode()->isShareable();
272
-	}
273
-
274
-	/**
275
-	 * @PublicPage
276
-	 * @NoCSRFRequired
277
-	 *
278
-
279
-	 * @param string $path
280
-	 * @return TemplateResponse
281
-	 * @throws NotFoundException
282
-	 * @throws \Exception
283
-	 */
284
-	public function showShare($path = ''): TemplateResponse {
285
-		\OC_User::setIncognitoMode(true);
286
-
287
-		// Check whether share exists
288
-		try {
289
-			$share = $this->shareManager->getShareByToken($this->getToken());
290
-		} catch (ShareNotFound $e) {
291
-			$this->emitAccessShareHook($this->getToken(), 404, 'Share not found');
292
-			throw new NotFoundException();
293
-		}
294
-
295
-		if (!$this->validateShare($share)) {
296
-			throw new NotFoundException();
297
-		}
298
-		// We can't get the path of a file share
299
-		try {
300
-			if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
301
-				$this->emitAccessShareHook($share, 404, 'Share not found');
302
-				throw new NotFoundException();
303
-			}
304
-		} catch (\Exception $e) {
305
-			$this->emitAccessShareHook($share, 404, 'Share not found');
306
-			throw $e;
307
-		}
308
-
309
-		$shareTmpl = [];
310
-		$shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
311
-		$shareTmpl['owner'] = $share->getShareOwner();
312
-		$shareTmpl['filename'] = $share->getNode()->getName();
313
-		$shareTmpl['directory_path'] = $share->getTarget();
314
-		$shareTmpl['note'] = $share->getNote();
315
-		$shareTmpl['mimetype'] = $share->getNode()->getMimetype();
316
-		$shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
317
-		$shareTmpl['dirToken'] = $this->getToken();
318
-		$shareTmpl['sharingToken'] = $this->getToken();
319
-		$shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
320
-		$shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
321
-		$shareTmpl['dir'] = '';
322
-		$shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
323
-		$shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
324
-
325
-		// Show file list
326
-		$hideFileList = false;
327
-		if ($share->getNode() instanceof \OCP\Files\Folder) {
328
-			/** @var \OCP\Files\Folder $rootFolder */
329
-			$rootFolder = $share->getNode();
330
-
331
-			try {
332
-				$folderNode = $rootFolder->get($path);
333
-			} catch (\OCP\Files\NotFoundException $e) {
334
-				$this->emitAccessShareHook($share, 404, 'Share not found');
335
-				throw new NotFoundException();
336
-			}
337
-
338
-			$shareTmpl['dir'] = $rootFolder->getRelativePath($folderNode->getPath());
339
-
340
-			/*
76
+    /** @var IConfig */
77
+    protected $config;
78
+    /** @var IUserManager */
79
+    protected $userManager;
80
+    /** @var ILogger */
81
+    protected $logger;
82
+    /** @var \OCP\Activity\IManager */
83
+    protected $activityManager;
84
+    /** @var IPreview */
85
+    protected $previewManager;
86
+    /** @var IRootFolder */
87
+    protected $rootFolder;
88
+    /** @var FederatedShareProvider */
89
+    protected $federatedShareProvider;
90
+    /** @var EventDispatcherInterface */
91
+    protected $eventDispatcher;
92
+    /** @var IL10N */
93
+    protected $l10n;
94
+    /** @var Defaults */
95
+    protected $defaults;
96
+    /** @var ShareManager */
97
+    protected $shareManager;
98
+
99
+    /** @var Share\IShare */
100
+    protected $share;
101
+
102
+    /**
103
+     * @param string $appName
104
+     * @param IRequest $request
105
+     * @param IConfig $config
106
+     * @param IURLGenerator $urlGenerator
107
+     * @param IUserManager $userManager
108
+     * @param ILogger $logger
109
+     * @param \OCP\Activity\IManager $activityManager
110
+     * @param \OCP\Share\IManager $shareManager
111
+     * @param ISession $session
112
+     * @param IPreview $previewManager
113
+     * @param IRootFolder $rootFolder
114
+     * @param FederatedShareProvider $federatedShareProvider
115
+     * @param EventDispatcherInterface $eventDispatcher
116
+     * @param IL10N $l10n
117
+     * @param Defaults $defaults
118
+     */
119
+    public function __construct(string $appName,
120
+                                IRequest $request,
121
+                                IConfig $config,
122
+                                IURLGenerator $urlGenerator,
123
+                                IUserManager $userManager,
124
+                                ILogger $logger,
125
+                                \OCP\Activity\IManager $activityManager,
126
+                                ShareManager $shareManager,
127
+                                ISession $session,
128
+                                IPreview $previewManager,
129
+                                IRootFolder $rootFolder,
130
+                                FederatedShareProvider $federatedShareProvider,
131
+                                EventDispatcherInterface $eventDispatcher,
132
+                                IL10N $l10n,
133
+                                Defaults $defaults) {
134
+        parent::__construct($appName, $request, $session, $urlGenerator);
135
+
136
+        $this->config = $config;
137
+        $this->userManager = $userManager;
138
+        $this->logger = $logger;
139
+        $this->activityManager = $activityManager;
140
+        $this->previewManager = $previewManager;
141
+        $this->rootFolder = $rootFolder;
142
+        $this->federatedShareProvider = $federatedShareProvider;
143
+        $this->eventDispatcher = $eventDispatcher;
144
+        $this->l10n = $l10n;
145
+        $this->defaults = $defaults;
146
+        $this->shareManager = $shareManager;
147
+    }
148
+
149
+    /**
150
+     * @PublicPage
151
+     * @NoCSRFRequired
152
+     *
153
+     * Show the authentication page
154
+     * The form has to submit to the authenticate method route
155
+     */
156
+    public function showAuthenticate(): TemplateResponse {
157
+        $templateParameters = ['share' => $this->share];
158
+
159
+        $event = new GenericEvent(null, $templateParameters);
160
+        $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $event);
161
+
162
+        $response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
163
+        if ($this->share->getSendPasswordByTalk()) {
164
+            $csp = new ContentSecurityPolicy();
165
+            $csp->addAllowedConnectDomain('*');
166
+            $csp->addAllowedMediaDomain('blob:');
167
+            $csp->allowEvalScript(true);
168
+            $response->setContentSecurityPolicy($csp);
169
+        }
170
+
171
+        return $response;
172
+    }
173
+
174
+    /**
175
+     * The template to show when authentication failed
176
+     */
177
+    protected function showAuthFailed(): TemplateResponse {
178
+        $templateParameters = ['share' => $this->share, 'wrongpw' => true];
179
+
180
+        $event = new GenericEvent(null, $templateParameters);
181
+        $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts::publicShareAuth', $event);
182
+
183
+        $response = new TemplateResponse('core', 'publicshareauth', $templateParameters, 'guest');
184
+        if ($this->share->getSendPasswordByTalk()) {
185
+            $csp = new ContentSecurityPolicy();
186
+            $csp->addAllowedConnectDomain('*');
187
+            $csp->addAllowedMediaDomain('blob:');
188
+            $csp->allowEvalScript(true);
189
+            $response->setContentSecurityPolicy($csp);
190
+        }
191
+
192
+        return $response;
193
+    }
194
+
195
+    protected function verifyPassword(string $password): bool {
196
+        return $this->shareManager->checkPassword($this->share, $password);
197
+    }
198
+
199
+    protected function getPasswordHash(): string {
200
+        return $this->share->getPassword();
201
+    }
202
+
203
+    public function isValidToken(): bool {
204
+        try {
205
+            $this->share = $this->shareManager->getShareByToken($this->getToken());
206
+        } catch (ShareNotFound $e) {
207
+            return false;
208
+        }
209
+
210
+        return true;
211
+    }
212
+
213
+    protected function isPasswordProtected(): bool {
214
+        return $this->share->getPassword() !== null;
215
+    }
216
+
217
+    protected function authSucceeded() {
218
+        // For share this was always set so it is still used in other apps
219
+        $this->session->set('public_link_authenticated', (string)$this->share->getId());
220
+    }
221
+
222
+    protected function authFailed() {
223
+        $this->emitAccessShareHook($this->share, 403, 'Wrong password');
224
+    }
225
+
226
+    /**
227
+     * throws hooks when a share is attempted to be accessed
228
+     *
229
+     * @param \OCP\Share\IShare|string $share the Share instance if available,
230
+     * otherwise token
231
+     * @param int $errorCode
232
+     * @param string $errorMessage
233
+     * @throws \OC\HintException
234
+     * @throws \OC\ServerNotAvailableException
235
+     */
236
+    protected function emitAccessShareHook($share, $errorCode = 200, $errorMessage = '') {
237
+        $itemType = $itemSource = $uidOwner = '';
238
+        $token = $share;
239
+        $exception = null;
240
+        if($share instanceof \OCP\Share\IShare) {
241
+            try {
242
+                $token = $share->getToken();
243
+                $uidOwner = $share->getSharedBy();
244
+                $itemType = $share->getNodeType();
245
+                $itemSource = $share->getNodeId();
246
+            } catch (\Exception $e) {
247
+                // we log what we know and pass on the exception afterwards
248
+                $exception = $e;
249
+            }
250
+        }
251
+        \OC_Hook::emit(Share::class, 'share_link_access', [
252
+            'itemType' => $itemType,
253
+            'itemSource' => $itemSource,
254
+            'uidOwner' => $uidOwner,
255
+            'token' => $token,
256
+            'errorCode' => $errorCode,
257
+            'errorMessage' => $errorMessage,
258
+        ]);
259
+        if(!is_null($exception)) {
260
+            throw $exception;
261
+        }
262
+    }
263
+
264
+    /**
265
+     * Validate the permissions of the share
266
+     *
267
+     * @param Share\IShare $share
268
+     * @return bool
269
+     */
270
+    private function validateShare(\OCP\Share\IShare $share) {
271
+        return $share->getNode()->isReadable() && $share->getNode()->isShareable();
272
+    }
273
+
274
+    /**
275
+     * @PublicPage
276
+     * @NoCSRFRequired
277
+     *
278
+     * @param string $path
279
+     * @return TemplateResponse
280
+     * @throws NotFoundException
281
+     * @throws \Exception
282
+     */
283
+    public function showShare($path = ''): TemplateResponse {
284
+        \OC_User::setIncognitoMode(true);
285
+
286
+        // Check whether share exists
287
+        try {
288
+            $share = $this->shareManager->getShareByToken($this->getToken());
289
+        } catch (ShareNotFound $e) {
290
+            $this->emitAccessShareHook($this->getToken(), 404, 'Share not found');
291
+            throw new NotFoundException();
292
+        }
293
+
294
+        if (!$this->validateShare($share)) {
295
+            throw new NotFoundException();
296
+        }
297
+        // We can't get the path of a file share
298
+        try {
299
+            if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
300
+                $this->emitAccessShareHook($share, 404, 'Share not found');
301
+                throw new NotFoundException();
302
+            }
303
+        } catch (\Exception $e) {
304
+            $this->emitAccessShareHook($share, 404, 'Share not found');
305
+            throw $e;
306
+        }
307
+
308
+        $shareTmpl = [];
309
+        $shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
310
+        $shareTmpl['owner'] = $share->getShareOwner();
311
+        $shareTmpl['filename'] = $share->getNode()->getName();
312
+        $shareTmpl['directory_path'] = $share->getTarget();
313
+        $shareTmpl['note'] = $share->getNote();
314
+        $shareTmpl['mimetype'] = $share->getNode()->getMimetype();
315
+        $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
316
+        $shareTmpl['dirToken'] = $this->getToken();
317
+        $shareTmpl['sharingToken'] = $this->getToken();
318
+        $shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
319
+        $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
320
+        $shareTmpl['dir'] = '';
321
+        $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
322
+        $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
323
+
324
+        // Show file list
325
+        $hideFileList = false;
326
+        if ($share->getNode() instanceof \OCP\Files\Folder) {
327
+            /** @var \OCP\Files\Folder $rootFolder */
328
+            $rootFolder = $share->getNode();
329
+
330
+            try {
331
+                $folderNode = $rootFolder->get($path);
332
+            } catch (\OCP\Files\NotFoundException $e) {
333
+                $this->emitAccessShareHook($share, 404, 'Share not found');
334
+                throw new NotFoundException();
335
+            }
336
+
337
+            $shareTmpl['dir'] = $rootFolder->getRelativePath($folderNode->getPath());
338
+
339
+            /*
341 340
 			 * The OC_Util methods require a view. This just uses the node API
342 341
 			 */
343
-			$freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath());
344
-			if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) {
345
-				$freeSpace = max($freeSpace, 0);
346
-			} else {
347
-				$freeSpace = (INF > 0) ? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
348
-			}
349
-
350
-			$hideFileList = !($share->getPermissions() & \OCP\Constants::PERMISSION_READ);
351
-			$maxUploadFilesize = $freeSpace;
352
-
353
-			$folder = new Template('files', 'list', '');
354
-			$folder->assign('dir', $rootFolder->getRelativePath($folderNode->getPath()));
355
-			$folder->assign('dirToken', $this->getToken());
356
-			$folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
357
-			$folder->assign('isPublic', true);
358
-			$folder->assign('hideFileList', $hideFileList);
359
-			$folder->assign('publicUploadEnabled', 'no');
360
-			$folder->assign('showgridview', true);
361
-			$folder->assign('uploadMaxFilesize', $maxUploadFilesize);
362
-			$folder->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize));
363
-			$folder->assign('freeSpace', $freeSpace);
364
-			$folder->assign('usedSpacePercent', 0);
365
-			$folder->assign('trash', false);
366
-			$shareTmpl['folder'] = $folder->fetchPage();
367
-		}
368
-
369
-		$shareTmpl['hideFileList'] = $hideFileList;
370
-		$shareTmpl['shareOwner'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
371
-		$shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', ['token' => $this->getToken()]);
372
-		$shareTmpl['shareUrl'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $this->getToken()]);
373
-		$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
374
-		$shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
375
-		$shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024);
376
-		$shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024);
377
-		$shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null);
378
-		$shareTmpl['previewURL'] = $shareTmpl['downloadURL'];
379
-		$ogPreview = '';
380
-		if ($shareTmpl['previewSupported']) {
381
-			$shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'files_sharing.PublicPreview.getPreview',
382
-				['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 'token' => $shareTmpl['dirToken']]);
383
-			$ogPreview = $shareTmpl['previewImage'];
384
-
385
-			// We just have direct previews for image files
386
-			if ($share->getNode()->getMimePart() === 'image') {
387
-				$shareTmpl['previewURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.publicpreview.directLink', ['token' => $this->getToken()]);
388
-
389
-				$ogPreview = $shareTmpl['previewURL'];
390
-
391
-				//Whatapp is kind of picky about their size requirements
392
-				if ($this->request->isUserAgent(['/^WhatsApp/'])) {
393
-					$ogPreview = $this->urlGenerator->linkToRouteAbsolute('files_sharing.PublicPreview.getPreview', [
394
-						'token' => $this->getToken(),
395
-						'x' => 256,
396
-						'y' => 256,
397
-						'a' => true,
398
-					]);
399
-				}
400
-			}
401
-		} else {
402
-			$shareTmpl['previewImage'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-fb.png'));
403
-			$ogPreview = $shareTmpl['previewImage'];
404
-		}
405
-
406
-		// Load files we need
407
-		\OCP\Util::addScript('files', 'file-upload');
408
-		\OCP\Util::addStyle('files_sharing', 'publicView');
409
-		\OCP\Util::addScript('files_sharing', 'public');
410
-		\OCP\Util::addScript('files_sharing', 'templates');
411
-		\OCP\Util::addScript('files_sharing', 'public_note');
412
-		\OCP\Util::addScript('files', 'fileactions');
413
-		\OCP\Util::addScript('files', 'fileactionsmenu');
414
-		\OCP\Util::addScript('files', 'jquery.fileupload');
415
-		\OCP\Util::addScript('files_sharing', 'files_drop');
416
-
417
-		if (isset($shareTmpl['folder'])) {
418
-			// JS required for folders
419
-			\OCP\Util::addStyle('files', 'merged');
420
-			\OCP\Util::addScript('files', 'filesummary');
421
-			\OCP\Util::addScript('files', 'templates');
422
-			\OCP\Util::addScript('files', 'breadcrumb');
423
-			\OCP\Util::addScript('files', 'fileinfomodel');
424
-			\OCP\Util::addScript('files', 'newfilemenu');
425
-			\OCP\Util::addScript('files', 'files');
426
-			\OCP\Util::addScript('files', 'filemultiselectmenu');
427
-			\OCP\Util::addScript('files', 'filelist');
428
-			\OCP\Util::addScript('files', 'keyboardshortcuts');
429
-		}
430
-
431
-		// OpenGraph Support: http://ogp.me/
432
-		\OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $shareTmpl['filename']]);
433
-		\OCP\Util::addHeader('meta', ['property' => "og:description", 'content' => $this->defaults->getName() . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')]);
434
-		\OCP\Util::addHeader('meta', ['property' => "og:site_name", 'content' => $this->defaults->getName()]);
435
-		\OCP\Util::addHeader('meta', ['property' => "og:url", 'content' => $shareTmpl['shareUrl']]);
436
-		\OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]);
437
-		\OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $ogPreview]);
438
-
439
-		$this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts');
440
-
441
-		$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
442
-		$csp->addAllowedFrameDomain('\'self\'');
443
-
444
-		$response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl);
445
-		$response->setHeaderTitle($shareTmpl['filename']);
446
-		$response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']]));
447
-		$response->setHeaderActions([
448
-			new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $shareTmpl['downloadURL'], 0),
449
-			new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $shareTmpl['downloadURL'], 10, $shareTmpl['fileSize']),
450
-			new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $shareTmpl['previewURL']),
451
-			new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $shareTmpl['owner'], $shareTmpl['displayName'], $shareTmpl['filename']),
452
-		]);
453
-
454
-		$response->setContentSecurityPolicy($csp);
455
-
456
-		$this->emitAccessShareHook($share);
457
-
458
-		return $response;
459
-	}
460
-
461
-	/**
462
-	 * @PublicPage
463
-	 * @NoCSRFRequired
464
-	 *
465
-	 * @param string $token
466
-	 * @param string $files
467
-	 * @param string $path
468
-	 * @param string $downloadStartSecret
469
-	 * @return void|\OCP\AppFramework\Http\Response
470
-	 * @throws NotFoundException
471
-	 */
472
-	public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') {
473
-		\OC_User::setIncognitoMode(true);
474
-
475
-		$share = $this->shareManager->getShareByToken($token);
476
-
477
-		if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) {
478
-			return new \OCP\AppFramework\Http\DataResponse('Share is read-only');
479
-		}
480
-
481
-		$files_list = null;
482
-		if (!is_null($files)) { // download selected files
483
-			$files_list = json_decode($files);
484
-			// in case we get only a single file
485
-			if ($files_list === null) {
486
-				$files_list = [$files];
487
-			}
488
-			// Just in case $files is a single int like '1234'
489
-			if (!is_array($files_list)) {
490
-				$files_list = [$files_list];
491
-			}
492
-		}
493
-
494
-
495
-		if (!$this->validateShare($share)) {
496
-			throw new NotFoundException();
497
-		}
498
-
499
-		$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
500
-		$originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
501
-
502
-
503
-		// Single file share
504
-		if ($share->getNode() instanceof \OCP\Files\File) {
505
-			// Single file download
506
-			$this->singleFileDownloaded($share, $share->getNode());
507
-		}
508
-		// Directory share
509
-		else {
510
-			/** @var \OCP\Files\Folder $node */
511
-			$node = $share->getNode();
512
-
513
-			// Try to get the path
514
-			if ($path !== '') {
515
-				try {
516
-					$node = $node->get($path);
517
-				} catch (NotFoundException $e) {
518
-					$this->emitAccessShareHook($share, 404, 'Share not found');
519
-					return new NotFoundResponse();
520
-				}
521
-			}
522
-
523
-			$originalSharePath = $userFolder->getRelativePath($node->getPath());
524
-
525
-			if ($node instanceof \OCP\Files\File) {
526
-				// Single file download
527
-				$this->singleFileDownloaded($share, $share->getNode());
528
-			} else if (!empty($files_list)) {
529
-				$this->fileListDownloaded($share, $files_list, $node);
530
-			} else {
531
-				// The folder is downloaded
532
-				$this->singleFileDownloaded($share, $share->getNode());
533
-			}
534
-		}
535
-
536
-		/* FIXME: We should do this all nicely in OCP */
537
-		OC_Util::tearDownFS();
538
-		OC_Util::setupFS($share->getShareOwner());
539
-
540
-		/**
541
-		 * this sets a cookie to be able to recognize the start of the download
542
-		 * the content must not be longer than 32 characters and must only contain
543
-		 * alphanumeric characters
544
-		 */
545
-		if (!empty($downloadStartSecret)
546
-			&& !isset($downloadStartSecret[32])
547
-			&& preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) {
548
-
549
-			// FIXME: set on the response once we use an actual app framework response
550
-			setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/');
551
-		}
552
-
553
-		$this->emitAccessShareHook($share);
554
-
555
-		$server_params = array( 'head' => $this->request->getMethod() === 'HEAD' );
556
-
557
-		/**
558
-		 * Http range requests support
559
-		 */
560
-		if (isset($_SERVER['HTTP_RANGE'])) {
561
-			$server_params['range'] = $this->request->getHeader('Range');
562
-		}
563
-
564
-		// download selected files
565
-		if (!is_null($files) && $files !== '') {
566
-			// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
567
-			// after dispatching the request which results in a "Cannot modify header information" notice.
568
-			OC_Files::get($originalSharePath, $files_list, $server_params);
569
-			exit();
570
-		} else {
571
-			// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
572
-			// after dispatching the request which results in a "Cannot modify header information" notice.
573
-			OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $server_params);
574
-			exit();
575
-		}
576
-	}
577
-
578
-	/**
579
-	 * create activity for every downloaded file
580
-	 *
581
-	 * @param Share\IShare $share
582
-	 * @param array $files_list
583
-	 * @param \OCP\Files\Folder $node
584
-	 */
585
-	protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) {
586
-		foreach ($files_list as $file) {
587
-			$subNode = $node->get($file);
588
-			$this->singleFileDownloaded($share, $subNode);
589
-		}
590
-
591
-	}
592
-
593
-	/**
594
-	 * create activity if a single file was downloaded from a link share
595
-	 *
596
-	 * @param Share\IShare $share
597
-	 */
598
-	protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) {
599
-
600
-		$fileId = $node->getId();
601
-
602
-		$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
603
-		$userNodeList = $userFolder->getById($fileId);
604
-		$userNode = $userNodeList[0];
605
-		$ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
606
-		$userPath = $userFolder->getRelativePath($userNode->getPath());
607
-		$ownerPath = $ownerFolder->getRelativePath($node->getPath());
608
-
609
-		$parameters = [$userPath];
610
-
611
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
612
-			if ($node instanceof \OCP\Files\File) {
613
-				$subject = Downloads::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED;
614
-			} else {
615
-				$subject = Downloads::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED;
616
-			}
617
-			$parameters[] = $share->getSharedWith();
618
-		} else {
619
-			if ($node instanceof \OCP\Files\File) {
620
-				$subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
621
-			} else {
622
-				$subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
623
-			}
624
-		}
625
-
626
-		$this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath);
627
-
628
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
629
-			$parameters[0] = $ownerPath;
630
-			$this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath);
631
-		}
632
-	}
633
-
634
-	/**
635
-	 * publish activity
636
-	 *
637
-	 * @param string $subject
638
-	 * @param array $parameters
639
-	 * @param string $affectedUser
640
-	 * @param int $fileId
641
-	 * @param string $filePath
642
-	 */
643
-	protected function publishActivity($subject,
644
-										array $parameters,
645
-										$affectedUser,
646
-										$fileId,
647
-										$filePath) {
648
-
649
-		$event = $this->activityManager->generateEvent();
650
-		$event->setApp('files_sharing')
651
-			->setType('public_links')
652
-			->setSubject($subject, $parameters)
653
-			->setAffectedUser($affectedUser)
654
-			->setObject('files', $fileId, $filePath);
655
-		$this->activityManager->publish($event);
656
-	}
342
+            $freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath());
343
+            if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) {
344
+                $freeSpace = max($freeSpace, 0);
345
+            } else {
346
+                $freeSpace = (INF > 0) ? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
347
+            }
348
+
349
+            $hideFileList = !($share->getPermissions() & \OCP\Constants::PERMISSION_READ);
350
+            $maxUploadFilesize = $freeSpace;
351
+
352
+            $folder = new Template('files', 'list', '');
353
+            $folder->assign('dir', $rootFolder->getRelativePath($folderNode->getPath()));
354
+            $folder->assign('dirToken', $this->getToken());
355
+            $folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
356
+            $folder->assign('isPublic', true);
357
+            $folder->assign('hideFileList', $hideFileList);
358
+            $folder->assign('publicUploadEnabled', 'no');
359
+            $folder->assign('showgridview', true);
360
+            $folder->assign('uploadMaxFilesize', $maxUploadFilesize);
361
+            $folder->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize));
362
+            $folder->assign('freeSpace', $freeSpace);
363
+            $folder->assign('usedSpacePercent', 0);
364
+            $folder->assign('trash', false);
365
+            $shareTmpl['folder'] = $folder->fetchPage();
366
+        }
367
+
368
+        $shareTmpl['hideFileList'] = $hideFileList;
369
+        $shareTmpl['shareOwner'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
370
+        $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', ['token' => $this->getToken()]);
371
+        $shareTmpl['shareUrl'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $this->getToken()]);
372
+        $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
373
+        $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
374
+        $shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024);
375
+        $shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024);
376
+        $shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null);
377
+        $shareTmpl['previewURL'] = $shareTmpl['downloadURL'];
378
+        $ogPreview = '';
379
+        if ($shareTmpl['previewSupported']) {
380
+            $shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'files_sharing.PublicPreview.getPreview',
381
+                ['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 'token' => $shareTmpl['dirToken']]);
382
+            $ogPreview = $shareTmpl['previewImage'];
383
+
384
+            // We just have direct previews for image files
385
+            if ($share->getNode()->getMimePart() === 'image') {
386
+                $shareTmpl['previewURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.publicpreview.directLink', ['token' => $this->getToken()]);
387
+
388
+                $ogPreview = $shareTmpl['previewURL'];
389
+
390
+                //Whatapp is kind of picky about their size requirements
391
+                if ($this->request->isUserAgent(['/^WhatsApp/'])) {
392
+                    $ogPreview = $this->urlGenerator->linkToRouteAbsolute('files_sharing.PublicPreview.getPreview', [
393
+                        'token' => $this->getToken(),
394
+                        'x' => 256,
395
+                        'y' => 256,
396
+                        'a' => true,
397
+                    ]);
398
+                }
399
+            }
400
+        } else {
401
+            $shareTmpl['previewImage'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-fb.png'));
402
+            $ogPreview = $shareTmpl['previewImage'];
403
+        }
404
+
405
+        // Load files we need
406
+        \OCP\Util::addScript('files', 'file-upload');
407
+        \OCP\Util::addStyle('files_sharing', 'publicView');
408
+        \OCP\Util::addScript('files_sharing', 'public');
409
+        \OCP\Util::addScript('files_sharing', 'templates');
410
+        \OCP\Util::addScript('files_sharing', 'public_note');
411
+        \OCP\Util::addScript('files', 'fileactions');
412
+        \OCP\Util::addScript('files', 'fileactionsmenu');
413
+        \OCP\Util::addScript('files', 'jquery.fileupload');
414
+        \OCP\Util::addScript('files_sharing', 'files_drop');
415
+
416
+        if (isset($shareTmpl['folder'])) {
417
+            // JS required for folders
418
+            \OCP\Util::addStyle('files', 'merged');
419
+            \OCP\Util::addScript('files', 'filesummary');
420
+            \OCP\Util::addScript('files', 'templates');
421
+            \OCP\Util::addScript('files', 'breadcrumb');
422
+            \OCP\Util::addScript('files', 'fileinfomodel');
423
+            \OCP\Util::addScript('files', 'newfilemenu');
424
+            \OCP\Util::addScript('files', 'files');
425
+            \OCP\Util::addScript('files', 'filemultiselectmenu');
426
+            \OCP\Util::addScript('files', 'filelist');
427
+            \OCP\Util::addScript('files', 'keyboardshortcuts');
428
+        }
429
+
430
+        // OpenGraph Support: http://ogp.me/
431
+        \OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $shareTmpl['filename']]);
432
+        \OCP\Util::addHeader('meta', ['property' => "og:description", 'content' => $this->defaults->getName() . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')]);
433
+        \OCP\Util::addHeader('meta', ['property' => "og:site_name", 'content' => $this->defaults->getName()]);
434
+        \OCP\Util::addHeader('meta', ['property' => "og:url", 'content' => $shareTmpl['shareUrl']]);
435
+        \OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]);
436
+        \OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $ogPreview]);
437
+
438
+        $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts');
439
+
440
+        $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
441
+        $csp->addAllowedFrameDomain('\'self\'');
442
+
443
+        $response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl);
444
+        $response->setHeaderTitle($shareTmpl['filename']);
445
+        $response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']]));
446
+        $response->setHeaderActions([
447
+            new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $shareTmpl['downloadURL'], 0),
448
+            new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $shareTmpl['downloadURL'], 10, $shareTmpl['fileSize']),
449
+            new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $shareTmpl['previewURL']),
450
+            new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $shareTmpl['owner'], $shareTmpl['displayName'], $shareTmpl['filename']),
451
+        ]);
452
+
453
+        $response->setContentSecurityPolicy($csp);
454
+
455
+        $this->emitAccessShareHook($share);
456
+
457
+        return $response;
458
+    }
459
+
460
+    /**
461
+     * @PublicPage
462
+     * @NoCSRFRequired
463
+     *
464
+     * @param string $token
465
+     * @param string $files
466
+     * @param string $path
467
+     * @param string $downloadStartSecret
468
+     * @return void|\OCP\AppFramework\Http\Response
469
+     * @throws NotFoundException
470
+     */
471
+    public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') {
472
+        \OC_User::setIncognitoMode(true);
473
+
474
+        $share = $this->shareManager->getShareByToken($token);
475
+
476
+        if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) {
477
+            return new \OCP\AppFramework\Http\DataResponse('Share is read-only');
478
+        }
479
+
480
+        $files_list = null;
481
+        if (!is_null($files)) { // download selected files
482
+            $files_list = json_decode($files);
483
+            // in case we get only a single file
484
+            if ($files_list === null) {
485
+                $files_list = [$files];
486
+            }
487
+            // Just in case $files is a single int like '1234'
488
+            if (!is_array($files_list)) {
489
+                $files_list = [$files_list];
490
+            }
491
+        }
492
+
493
+
494
+        if (!$this->validateShare($share)) {
495
+            throw new NotFoundException();
496
+        }
497
+
498
+        $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
499
+        $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
500
+
501
+
502
+        // Single file share
503
+        if ($share->getNode() instanceof \OCP\Files\File) {
504
+            // Single file download
505
+            $this->singleFileDownloaded($share, $share->getNode());
506
+        }
507
+        // Directory share
508
+        else {
509
+            /** @var \OCP\Files\Folder $node */
510
+            $node = $share->getNode();
511
+
512
+            // Try to get the path
513
+            if ($path !== '') {
514
+                try {
515
+                    $node = $node->get($path);
516
+                } catch (NotFoundException $e) {
517
+                    $this->emitAccessShareHook($share, 404, 'Share not found');
518
+                    return new NotFoundResponse();
519
+                }
520
+            }
521
+
522
+            $originalSharePath = $userFolder->getRelativePath($node->getPath());
523
+
524
+            if ($node instanceof \OCP\Files\File) {
525
+                // Single file download
526
+                $this->singleFileDownloaded($share, $share->getNode());
527
+            } else if (!empty($files_list)) {
528
+                $this->fileListDownloaded($share, $files_list, $node);
529
+            } else {
530
+                // The folder is downloaded
531
+                $this->singleFileDownloaded($share, $share->getNode());
532
+            }
533
+        }
534
+
535
+        /* FIXME: We should do this all nicely in OCP */
536
+        OC_Util::tearDownFS();
537
+        OC_Util::setupFS($share->getShareOwner());
538
+
539
+        /**
540
+         * this sets a cookie to be able to recognize the start of the download
541
+         * the content must not be longer than 32 characters and must only contain
542
+         * alphanumeric characters
543
+         */
544
+        if (!empty($downloadStartSecret)
545
+            && !isset($downloadStartSecret[32])
546
+            && preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) {
547
+
548
+            // FIXME: set on the response once we use an actual app framework response
549
+            setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/');
550
+        }
551
+
552
+        $this->emitAccessShareHook($share);
553
+
554
+        $server_params = array( 'head' => $this->request->getMethod() === 'HEAD' );
555
+
556
+        /**
557
+         * Http range requests support
558
+         */
559
+        if (isset($_SERVER['HTTP_RANGE'])) {
560
+            $server_params['range'] = $this->request->getHeader('Range');
561
+        }
562
+
563
+        // download selected files
564
+        if (!is_null($files) && $files !== '') {
565
+            // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
566
+            // after dispatching the request which results in a "Cannot modify header information" notice.
567
+            OC_Files::get($originalSharePath, $files_list, $server_params);
568
+            exit();
569
+        } else {
570
+            // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
571
+            // after dispatching the request which results in a "Cannot modify header information" notice.
572
+            OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $server_params);
573
+            exit();
574
+        }
575
+    }
576
+
577
+    /**
578
+     * create activity for every downloaded file
579
+     *
580
+     * @param Share\IShare $share
581
+     * @param array $files_list
582
+     * @param \OCP\Files\Folder $node
583
+     */
584
+    protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) {
585
+        foreach ($files_list as $file) {
586
+            $subNode = $node->get($file);
587
+            $this->singleFileDownloaded($share, $subNode);
588
+        }
589
+
590
+    }
591
+
592
+    /**
593
+     * create activity if a single file was downloaded from a link share
594
+     *
595
+     * @param Share\IShare $share
596
+     */
597
+    protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) {
598
+
599
+        $fileId = $node->getId();
600
+
601
+        $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
602
+        $userNodeList = $userFolder->getById($fileId);
603
+        $userNode = $userNodeList[0];
604
+        $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
605
+        $userPath = $userFolder->getRelativePath($userNode->getPath());
606
+        $ownerPath = $ownerFolder->getRelativePath($node->getPath());
607
+
608
+        $parameters = [$userPath];
609
+
610
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
611
+            if ($node instanceof \OCP\Files\File) {
612
+                $subject = Downloads::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED;
613
+            } else {
614
+                $subject = Downloads::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED;
615
+            }
616
+            $parameters[] = $share->getSharedWith();
617
+        } else {
618
+            if ($node instanceof \OCP\Files\File) {
619
+                $subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
620
+            } else {
621
+                $subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
622
+            }
623
+        }
624
+
625
+        $this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath);
626
+
627
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
628
+            $parameters[0] = $ownerPath;
629
+            $this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath);
630
+        }
631
+    }
632
+
633
+    /**
634
+     * publish activity
635
+     *
636
+     * @param string $subject
637
+     * @param array $parameters
638
+     * @param string $affectedUser
639
+     * @param int $fileId
640
+     * @param string $filePath
641
+     */
642
+    protected function publishActivity($subject,
643
+                                        array $parameters,
644
+                                        $affectedUser,
645
+                                        $fileId,
646
+                                        $filePath) {
647
+
648
+        $event = $this->activityManager->generateEvent();
649
+        $event->setApp('files_sharing')
650
+            ->setType('public_links')
651
+            ->setSubject($subject, $parameters)
652
+            ->setAffectedUser($affectedUser)
653
+            ->setObject('files', $fileId, $filePath);
654
+        $this->activityManager->publish($event);
655
+    }
657 656
 
658 657
 
659 658
 }
Please login to merge, or discard this patch.